summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEduard Roccatello <eduard@roccatello.it>2005-05-15 21:07:18 +0000
committerEduard Roccatello <eduard@roccatello.it>2005-05-15 21:07:18 +0000
commitcca14d74dcec51dd4598ff0c5ffa96a8cceb0564 (patch)
tree9a1602327af89ab815875ce33dada21cf4a1c83c /src
parentcd15ef845448d4a5348504060658f33e8f3cb7a2 (diff)
downloadxfce4-appfinder-cca14d74dcec51dd4598ff0c5ffa96a8cceb0564.tar.gz
Appfinder widgetized - Please Test
(Old svn revision: 14456)
Diffstat (limited to 'src')
-rw-r--r--src/xfce4-appfinder.c691
-rw-r--r--src/xfce4-appfinder.h90
2 files changed, 781 insertions, 0 deletions
diff --git a/src/xfce4-appfinder.c b/src/xfce4-appfinder.c
new file mode 100644
index 0000000..8dfe187
--- /dev/null
+++ b/src/xfce4-appfinder.c
@@ -0,0 +1,691 @@
+/* xfce4-appfinder
+ *
+ * Copyright (C) 2004-2005 Eduard Roccatello (eduard@xfce.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * This application is dedicated to DarkAngel (ILY!).
+ */
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+#include <string.h>
+
+#include "inline-icon.h"
+#include "xfce4-appfinder.h"
+
+enum {
+ APPLICATION_ACTIVATE_SIGNAL,
+ APPLICATION_RIGHT_CLICK_SIGNAL,
+ LAST_SIGNAL
+};
+
+static void xfce_appfinder_class_init (XfceAppfinderClass *klass);
+
+static void xfce_appfinder_init (XfceAppfinder *appfinder);
+
+void xfce_appfinder_load_desktop (gpointer desktopData);
+
+GtkWidget* create_categories_treeview (void);
+
+GtkWidget* create_applications_treeview (void);
+
+GtkListStore* load_desktop_resources (gint category,
+ gchar *pattern);
+
+gboolean xfce_appfinder_list_add (XfceDesktopEntry *dentry,
+ GtkListStore *store,
+ GPatternSpec *psearch,
+ GPatternSpec *pcat);
+
+static void build_desktop_paths (void);
+
+gchar * get_path_from_name (gchar *name);
+
+void callbackApplicationActivate (GtkTreeView *treeview,
+ GtkTreePath *path,
+ GtkTreeViewColumn *col,
+ gpointer appfinder);
+
+gboolean callbackCategoryTreeClick (GtkTreeSelection *selection,
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean path_currently_selected,
+ gpointer userdata);
+
+gboolean callbackApplicationRightClick (GtkWidget *treeview,
+ GdkEventButton *event,
+ gpointer appfinder);
+
+static gint xfce_appfinder_signals[LAST_SIGNAL] = { 0 };
+static gchar **desktop_entries_paths;
+static gint desktop_path_number = 0;
+static gint showedcat = APPFINDER_ALL;
+
+/* What to search for in .desktop files */
+static const char *dotDesktopKeys [] =
+{
+ "Name",
+ "Comment",
+ "Icon",
+ "Categories",
+ "OnlyShowIn",
+ "Exec",
+ "Terminal",
+ NULL
+};
+
+static const char *dotDesktopCategories [] =
+{
+ "All",
+ "Core",
+ "Development",
+ "Office",
+ "Graphics",
+ "Network",
+ "AudioVideo",
+ "Game",
+ "Education",
+ "System",
+ "Filemanager",
+ "Utility",
+ NULL
+};
+
+GType
+xfce_appfinder_get_type ()
+{
+ static GType appfinder_type = 0;
+
+ if (!appfinder_type)
+ {
+ static const GTypeInfo appfinder_info =
+ {
+ sizeof(XfceAppfinderClass),
+ NULL,
+ NULL,
+ (GClassInitFunc) xfce_appfinder_class_init,
+ NULL,
+ NULL,
+ sizeof(XfceAppfinder),
+ 0,
+ (GInstanceInitFunc) xfce_appfinder_init,
+ };
+
+ appfinder_type = g_type_register_static (GTK_TYPE_VBOX, "XfceAppfinder", &appfinder_info, 0);
+ }
+
+ return appfinder_type;
+}
+
+static void
+xfce_appfinder_class_init (XfceAppfinderClass *class)
+{
+ GtkObjectClass *object_class;
+
+ object_class = (GtkObjectClass*) class;
+
+ xfce_appfinder_signals[APPLICATION_ACTIVATE_SIGNAL] = g_signal_new("application-activate",
+ G_TYPE_FROM_CLASS(object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+
+ xfce_appfinder_signals[APPLICATION_RIGHT_CLICK_SIGNAL] = g_signal_new("application-right-click",
+ G_TYPE_FROM_CLASS(object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER);
+ class->xfce_appfinder = NULL;
+}
+
+static void
+xfce_appfinder_init (XfceAppfinder *appfinder)
+{
+ xfce_appfinder_load_desktop (appfinder->desktopData);
+
+ appfinder->hpaned = GTK_WIDGET(gtk_hpaned_new ());
+ gtk_paned_set_position (GTK_PANED(appfinder->hpaned), 100);
+ gtk_container_add(GTK_CONTAINER(appfinder), appfinder->hpaned);
+
+ appfinder->categoriesTree = create_categories_treeview();
+ gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(GTK_TREE_VIEW(appfinder->categoriesTree)), callbackCategoryTreeClick, appfinder, NULL);
+ gtk_paned_pack1(GTK_PANED(appfinder->hpaned), appfinder->categoriesTree, TRUE, TRUE);
+
+ appfinder->appScroll = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(appfinder->appScroll), GTK_SHADOW_IN);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(appfinder->appScroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_paned_pack2(GTK_PANED(appfinder->hpaned), appfinder->appScroll, TRUE, TRUE);
+
+ appfinder->appsTree = create_applications_treeview();
+ g_signal_connect(appfinder->appsTree, "row-activated", G_CALLBACK(callbackApplicationActivate), (gpointer) appfinder);
+ g_signal_connect(appfinder->appsTree, "button-press-event", G_CALLBACK(callbackApplicationRightClick), (gpointer) appfinder);
+
+ gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(appfinder->appScroll), appfinder->appsTree);
+ gtk_widget_show_all(GTK_WIDGET(appfinder));
+}
+
+void
+callbackApplicationActivate (GtkTreeView *treeview,
+ GtkTreePath *path,
+ GtkTreeViewColumn *col,
+ gpointer appfinder)
+{
+ gchar *filePath = NULL;
+ gchar *name = NULL;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+
+ model = gtk_tree_view_get_model(treeview);
+ if (gtk_tree_model_get_iter(model, &iter, path))
+ {
+ /* we fetch the name of the application to run */
+ gtk_tree_model_get(model, &iter, APPLICATION_TREE_TEXT, &name, -1);
+ if (name)
+ {
+ filePath = get_path_from_name (name);
+ g_free(name);
+ }
+ }
+ if (filePath)
+ {
+ g_signal_emit (G_OBJECT (appfinder), xfce_appfinder_signals[APPLICATION_ACTIVATE_SIGNAL], 0, filePath);
+ g_free(filePath);
+ }
+}
+
+GtkWidget*
+xfce_appfinder_new ()
+{
+ return GTK_WIDGET (g_object_new(xfce_appfinder_get_type(), NULL));
+}
+
+void
+xfce_appfinder_load_desktop (gpointer desktopData)
+{
+ build_desktop_paths ();
+}
+
+GtkWidget*
+create_categories_treeview (void)
+{
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GtkWidget *view;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ gint i = 0;
+
+ store = gtk_list_store_new(CATEGORY_TREE_COLS, G_TYPE_STRING);
+
+ while(dotDesktopCategories[i])
+ {
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter, CATEGORY_TREE_TEXT, _(dotDesktopCategories[i++]), -1);
+ }
+
+ view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_column_set_title(col, _("Categories"));
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_column_pack_start(col, renderer, TRUE);
+ gtk_tree_view_column_set_attributes(col, renderer,
+ "text", CATEGORY_TREE_TEXT,
+ NULL);
+
+ gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
+
+ return view;
+}
+
+GtkWidget*
+create_applications_treeview (void)
+{
+ GtkTreeViewColumn *col;
+ GtkCellRenderer *renderer;
+ GtkWidget *view;
+
+ view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(load_desktop_resources(0, NULL)));
+
+ col = gtk_tree_view_column_new();
+ gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(view), FALSE);
+
+ renderer = gtk_cell_renderer_pixbuf_new();
+ gtk_tree_view_column_pack_start(col, renderer, FALSE);
+ gtk_tree_view_column_set_attributes(col, renderer,
+ "pixbuf", APPLICATION_TREE_ICON,
+ NULL);
+
+ renderer = gtk_cell_renderer_text_new();
+ gtk_tree_view_column_pack_start(col, renderer, TRUE);
+ gtk_tree_view_column_set_attributes(col, renderer,
+ "text", APPLICATION_TREE_TEXT,
+ NULL);
+
+ gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
+
+ return view;
+}
+
+/**
+ * This function handles all the searches into desktop files
+ *
+ * @param category - the category to search for (defined into the array in the header)
+ * @param pattern - the pattern of the text to search for (set to NULL if any text is ok)
+ * @returns GtkListStore * - a pointer to a new list store with the items
+ */
+GtkListStore*
+load_desktop_resources (gint category, gchar *pattern)
+{
+ XfceDesktopEntry *dentry;
+ GtkListStore *store;
+ GPatternSpec *psearch = NULL;
+ GPatternSpec *pcat = NULL;
+ gchar *tmp = NULL;
+ gchar *filename = NULL;
+ gchar *fullpath = NULL;
+ GDir *dir;
+ gint n = desktop_path_number - 1;
+ gint i = 0; /* A counter for general use */
+
+ store = gtk_list_store_new(APPLICATION_TREE_COLS, GDK_TYPE_PIXBUF, G_TYPE_STRING);
+
+ if (pattern != NULL)
+ {
+ tmp = g_strconcat("*", g_utf8_casefold(pattern, -1), "*", NULL);
+ psearch = g_pattern_spec_new (tmp);
+ g_free(tmp);
+ }
+
+ if (category != APPFINDER_ALL)
+ {
+ tmp = g_strconcat("*", g_utf8_casefold(dotDesktopCategories[category], -1), "*", NULL);
+ pcat = g_pattern_spec_new (tmp);
+ g_free(tmp);
+ }
+
+ while (desktop_entries_paths[i]!=NULL)
+ {
+ if ((dir = g_dir_open (desktop_entries_paths[i], 0, NULL))!=NULL)
+ {
+ while ((filename = (gchar *)g_dir_read_name(dir))!=NULL)
+ {
+ fullpath = g_build_filename(desktop_entries_paths[i], filename, NULL);
+ if (g_str_has_suffix(filename, ".desktop"))
+ {
+ dentry = xfce_desktop_entry_new (fullpath, dotDesktopKeys, 7);
+ if (!XFCE_IS_DESKTOP_ENTRY(dentry))
+ {
+ continue;
+ }
+ xfce_appfinder_list_add (dentry, store, psearch, pcat);
+ g_object_unref (dentry);
+ g_free(fullpath);
+ }
+ else if (g_file_test(fullpath, G_FILE_TEST_IS_DIR))
+ {
+ desktop_entries_paths[n] = fullpath;
+ desktop_entries_paths[n] = NULL;
+ }
+ }
+ g_dir_close(dir);
+ }
+ i++;
+ }
+
+ if (psearch)
+ {
+ g_pattern_spec_free (psearch);
+ }
+
+ if (pcat)
+ {
+ g_pattern_spec_free (pcat);
+ }
+
+ return store;
+
+}
+
+gboolean
+xfce_appfinder_list_add (XfceDesktopEntry *dentry, GtkListStore *store, GPatternSpec *psearch, GPatternSpec *pcat)
+{
+ GtkTreeIter iter;
+ GdkPixbuf *icon = NULL;
+ gchar *name = NULL;
+ gchar *img = NULL;
+ gchar *dcat = NULL;
+ gchar *comment = NULL;
+
+ if (!(xfce_desktop_entry_get_string (dentry, "Name", TRUE, &name) && name))
+ {
+ return FALSE;
+ }
+
+ if (pcat)
+ {
+ if (!(xfce_desktop_entry_get_string (dentry, "Categories", TRUE, &dcat) && dcat))
+ {
+ return FALSE;
+ }
+
+ if (g_pattern_match_string (pcat, g_utf8_casefold(dcat, -1)) == FALSE)
+ {
+ g_free(dcat);
+ return FALSE;
+ }
+ }
+
+ if (psearch)
+ {
+ xfce_desktop_entry_get_string (dentry, "Comment", TRUE, &comment);
+ if (!(comment && g_pattern_match_string (psearch, g_utf8_casefold(comment, -1))) &&
+ !g_pattern_match_string (psearch, name))
+ {
+ return FALSE;
+ }
+ }
+
+ if (xfce_desktop_entry_get_string (dentry, "Icon", TRUE, &img) && img)
+ {
+ icon = xfce_themed_icon_load(img, 24);
+ g_free(img);
+ }
+ else
+ {
+ icon = NULL;
+ }
+
+ gtk_list_store_append(store, &iter);
+ gtk_list_store_set(store, &iter,
+ APPLICATION_TREE_ICON, icon,
+ APPLICATION_TREE_TEXT, name,
+ -1);
+
+ g_free(name);
+ if (icon)
+ {
+ g_object_unref (icon);
+ }
+
+ return TRUE;
+}
+
+static void
+build_desktop_paths (void)
+{
+ const gchar *kdedir;
+ gchar **applications;
+ gint napplications;
+ gchar **apps;
+ gint napps;
+ gchar **applnk;
+ gint napplnk;
+ gint i, n;
+
+ applications = xfce_resource_lookup_all (XFCE_RESOURCE_DATA, "applications/");
+ for (napplications = 0; applications[napplications] != NULL; ++napplications);
+
+ apps = xfce_resource_lookup_all (XFCE_RESOURCE_DATA, "apps/");
+ for (napps = 0; apps[napps] != NULL; ++napps);
+
+ applnk = xfce_resource_lookup_all (XFCE_RESOURCE_DATA, "applnk/");
+ for (napplnk = 0; applnk[napplnk] != NULL; ++napplnk);
+
+ desktop_entries_paths = g_new0 (gchar *, 2 * napplications + napps + napplnk + 6);
+ i = 0;
+
+ desktop_entries_paths[i++] = xfce_get_homefile (".kde", "share", "apps", NULL);
+ desktop_entries_paths[i++] = xfce_get_homefile (".kde", "share", "applnk", NULL);
+ if ((kdedir = g_getenv("KDEDIR")) != NULL)
+ {
+ desktop_entries_paths[i++] = g_build_filename (kdedir, "share", "applications", "kde", NULL);
+ }
+
+ /* FreeBSD Gnome stuff */
+ desktop_entries_paths[i++] = g_build_filename ("/usr", "X11R6", "share", "gnome", "applications", NULL);
+
+ /* /usr/global stuff */
+ desktop_entries_paths[i++] = g_build_filename ("/usr", "global", "share", "applications", NULL);
+
+ for (n = 0; n < napplications; ++n)
+ {
+ desktop_entries_paths[i++] = applications[n];
+ desktop_entries_paths[i++] = g_build_filename (applications[n], "kde", NULL);
+ }
+ g_free (applications);
+
+ for (n = 0; n < napps; ++i, ++n)
+ {
+ desktop_entries_paths[i] = apps[n];
+ }
+ g_free (apps);
+
+ for (n = 0; n < napplnk; ++i, ++n)
+ {
+ desktop_entries_paths[i] = applnk[n];
+ }
+ g_free (applnk);
+
+ g_print ("\nPATHS:\n");
+ for (n = 0; desktop_entries_paths[n] != NULL; ++n)
+ {
+ g_print (" %s\n", desktop_entries_paths[n]);
+ }
+ desktop_path_number = n;
+ g_print ("\n\n");
+}
+
+gchar *get_path_from_name(gchar *name)
+{
+ GDir *dir;
+ XfceDesktopEntry *dentry;
+ gboolean found = FALSE;
+ gchar *filename;
+ gchar *dname;
+ gchar *filepath = NULL;
+ gint i = 0;
+
+ g_return_val_if_fail(name!=NULL, NULL);
+
+ while (desktop_entries_paths[i])
+ {
+ if ((dir = g_dir_open (desktop_entries_paths[i], 0, NULL)) == NULL)
+ {
+ i++;
+ continue;
+ }
+
+ while (!found && ((filename = (gchar *)g_dir_read_name(dir)) != NULL))
+ {
+ filepath = g_build_filename(desktop_entries_paths[i], filename, NULL);
+ if (g_file_test(filepath, G_FILE_TEST_IS_DIR) ||
+ !XFCE_IS_DESKTOP_ENTRY(dentry = xfce_desktop_entry_new (filepath, dotDesktopKeys, 7))) {
+ continue;
+ }
+
+ if (xfce_desktop_entry_get_string (dentry, "Name", TRUE, &dname) && dname) {
+ if (strcmp(dname, name)==0)
+ found = TRUE;
+ g_free(dname);
+ }
+ }
+ g_dir_close(dir);
+ if (found)
+ return g_strdup(filepath);
+ i++;
+ }
+ return NULL;
+}
+
+gboolean
+callbackCategoryTreeClick (GtkTreeSelection *selection,
+ GtkTreeModel *model,
+ GtkTreePath *path,
+ gboolean path_currently_selected,
+ gpointer userdata)
+{
+ int next = showedcat;
+ int i = 0;
+ GtkTreeIter iter;
+ gchar *name = NULL;
+ XfceAppfinder *af = userdata;
+
+ if (!path_currently_selected && gtk_tree_model_get_iter(model, &iter, path))
+ {
+ gtk_tree_model_get(model, &iter, CATEGORY_TREE_TEXT, &name, -1);
+ if (name)
+ {
+ while (dotDesktopCategories[i])
+ {
+ if (strcmp(_(dotDesktopCategories[i]), name) == 0)
+ {
+ next = i;
+ break;
+ }
+ i++;
+ }
+ g_free(name);
+ }
+ }
+
+ if (next != showedcat)
+ {
+ showedcat = next;
+ gtk_list_store_clear (GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(af->appsTree))));
+ gtk_tree_view_set_model (GTK_TREE_VIEW(af->appsTree), GTK_TREE_MODEL(load_desktop_resources(showedcat, NULL)));
+
+ /* Ok there are no items in the list. Write a message and disable the treeview */
+ if (!gtk_tree_model_get_iter_first (gtk_tree_view_get_model (GTK_TREE_VIEW(af->appsTree)), &iter))
+ {
+ gtk_list_store_append(GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(af->appsTree))), &iter);
+ gtk_list_store_set(GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(af->appsTree))),
+ &iter, APPLICATION_TREE_ICON, xfce_inline_icon_at_size (default_icon_data_48_48, 24, 24),
+ APPLICATION_TREE_TEXT, _("No items available"), -1);
+ gtk_widget_set_sensitive(af->appsTree, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(af->appsTree, TRUE);
+ }
+ }
+
+ return TRUE; /* allow selection state to change */
+}
+
+void
+xfce_appfinder_search (XfceAppfinder *appfinder, gchar *pattern)
+{
+ GtkTreeIter iter;
+ gchar *text = g_utf8_strdown(pattern, -1);
+ showedcat = APPFINDER_ALL;
+
+ gtk_list_store_clear (GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(appfinder->appsTree))));
+ gtk_tree_view_set_model (GTK_TREE_VIEW(appfinder->appsTree), GTK_TREE_MODEL(load_desktop_resources (APPFINDER_ALL, text)));
+
+ /* No application found. Tell the user about it */
+ if (!gtk_tree_model_get_iter_first (gtk_tree_view_get_model (GTK_TREE_VIEW(appfinder->appsTree)), &iter))
+ {
+ gtk_list_store_append(GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(appfinder->appsTree))), &iter);
+ gtk_list_store_set(GTK_LIST_STORE(gtk_tree_view_get_model (GTK_TREE_VIEW(appfinder->appsTree))),
+ &iter, APPLICATION_TREE_ICON, xfce_inline_icon_at_size (default_icon_data_48_48, 24, 24),
+ APPLICATION_TREE_TEXT, _("Sorry, no match for searched text."), -1);
+ gtk_widget_set_sensitive(appfinder->appsTree, FALSE);
+ }
+ else
+ {
+ gtk_widget_set_sensitive(appfinder->appsTree, TRUE);
+ }
+
+ gtk_tree_selection_unselect_all (gtk_tree_view_get_selection(GTK_TREE_VIEW(appfinder->categoriesTree)));
+
+ if (text)
+ {
+ g_free(text);
+ }
+
+}
+
+void
+xfce_appfinder_clean (XfceAppfinder *appfinder)
+{
+ showedcat = APPFINDER_ALL;
+ gtk_list_store_clear (GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(appfinder->appsTree))));
+ gtk_tree_view_set_model (GTK_TREE_VIEW(appfinder->appsTree), GTK_TREE_MODEL(load_desktop_resources (APPFINDER_ALL, NULL)));
+}
+
+void
+xfce_appfinder_view_categories (XfceAppfinder *appfinder, gboolean visible)
+{
+ if (!visible)
+ gtk_widget_hide(appfinder->categoriesTree);
+ else
+ gtk_widget_show_all(appfinder->categoriesTree);
+}
+
+gboolean
+callbackApplicationRightClick (GtkWidget *treeview, GdkEventButton *event, gpointer appfinder)
+{
+ GtkTreeSelection *selection;
+ GtkTreePath *treepath;
+ GtkTreeModel *treemodel;
+ GtkTreeIter iter;
+ gchar *name = NULL;
+ gchar *filePath = NULL;
+
+ /* 3 is for right button */
+ if (event->button == 3)
+ {
+ selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
+ gtk_tree_selection_unselect_all(selection);
+ if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(treeview), event->x, event->y, &treepath, NULL, NULL, NULL))
+ {
+ gtk_tree_selection_select_path (selection, treepath);
+ treemodel = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
+ gtk_tree_model_get_iter (treemodel, &iter, treepath);
+ gtk_tree_model_get(treemodel, &iter, APPLICATION_TREE_TEXT, &name, -1);
+
+ if (name)
+ {
+ filePath = get_path_from_name (name);
+ g_free(name);
+ }
+
+ if (filePath)
+ {
+ g_signal_emit (G_OBJECT (appfinder), xfce_appfinder_signals[APPLICATION_RIGHT_CLICK_SIGNAL], 0, filePath);
+ g_free(filePath);
+ }
+
+ return TRUE;
+ }
+ }
+ /* If hasn't been clicked with right button let's propagate the event */
+ return FALSE;
+}
+
diff --git a/src/xfce4-appfinder.h b/src/xfce4-appfinder.h
new file mode 100644
index 0000000..25f1b91
--- /dev/null
+++ b/src/xfce4-appfinder.h
@@ -0,0 +1,90 @@
+/* xfce4-appfinder
+ *
+ * Copyright (C) 2004-2005 Eduard Roccatello (eduard@xfce.org)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * This application is dedicated to DarkAngel (ILY!).
+ */
+
+#ifndef __XFCE4_APPFINDER_H__
+#define __XFCE4_APPFINDER_H__
+
+#include <gdk/gdk.h>
+#include <gtk/gtkvbox.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#define XFCE_APPFINDER(obj) GTK_CHECK_CAST (obj, xfce_appfinder_get_type(), XfceAppfinder)
+#define XFCE_APPFINDER_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, xfce_appfinder_get_type(), XfceAppfinderClass)
+#define IS_XFCE_APPFINDER(obj) GTK_CHECK_TYPE (obj, xfce_appfinder_get_type())
+#define APPFINDER_ALL 0
+
+typedef struct _XfceAppfinder XfceAppfinder;
+typedef struct _XfceAppfinderClass XfceAppfinderClass;
+
+struct _XfceAppfinder
+{
+ gpointer desktopData;
+ GtkVBox vbox;
+
+ GtkWidget *hpaned;
+ GtkWidget *rightvbox;
+
+ GtkWidget *searchbox;
+ GtkWidget *searchlabel;
+ GtkWidget *searchentry;
+
+ GtkWidget *categoriesTree;
+ GtkWidget *appsTree;
+ GtkWidget *appScroll;
+};
+
+struct _XfceAppfinderClass
+{
+ GtkVBoxClass parent_class;
+
+ void (* xfce_appfinder) (XfceAppfinder *appfinder);
+};
+
+enum
+{
+ CATEGORY_TREE_TEXT = 0,
+ CATEGORY_TREE_COLS
+};
+
+enum
+{
+ APPLICATION_TREE_ICON = 0,
+ APPLICATION_TREE_TEXT,
+ APPLICATION_TREE_COLS
+};
+
+GtkType xfce_appfinder_get_type (void);
+GtkWidget* xfce_appfinder_new (void);
+void xfce_appfinder_search (XfceAppfinder *appfinder,
+ gchar *pattern);
+void xfce_appfinder_view_categories (XfceAppfinder *appfinder,
+ gboolean visible);
+void xfce_appfinder_clean (XfceAppfinder *appfinder);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __XFCE4_APPFINDER_H__ */