[Xfce4-commits] <xfce4-appfinder:nick/xfrun4-merge> Fix a bunch of todo items.
Nick Schermer
noreply at xfce.org
Wed Jun 8 21:38:01 CEST 2011
Updating branch refs/heads/nick/xfrun4-merge
to 749194f75934c5f1bea570de2f547b60b49dca3a (commit)
from 5d515666c77416ee5df600c57da3492a8d7b18c8 (commit)
commit 749194f75934c5f1bea570de2f547b60b49dca3a
Author: Nick Schermer <nick at xfce.org>
Date: Wed Jun 8 21:36:32 2011 +0200
Fix a bunch of todo items.
src/appfinder-category-model.c | 32 +++++++-
src/appfinder-category-model.h | 2 +
src/appfinder-model.c | 195 +++++++++++++++++++++++++++++++++++-----
src/appfinder-model.h | 8 ++
src/appfinder-window.c | 28 +++++-
src/main.c | 3 +-
6 files changed, 239 insertions(+), 29 deletions(-)
diff --git a/src/appfinder-category-model.c b/src/appfinder-category-model.c
index 781dda8..957029f 100644
--- a/src/appfinder-category-model.c
+++ b/src/appfinder-category-model.c
@@ -404,7 +404,7 @@ xfce_appfinder_category_model_set_categories (XfceAppfinderCategoryModel *model,
GtkTreePath *path;
GtkTreeIter iter;
- g_debug ("insert %d categories", g_slist_length (categories));
+ APPFINDER_DEBUG ("insert %d categories", g_slist_length (categories));
/* remove shortcuts after hard-coded before inserting */
li = g_slist_nth (model->categories, 3);
@@ -451,3 +451,33 @@ xfce_appfinder_category_model_row_separator_func (GtkTreeModel *tree_model,
return (item->directory == NULL);
}
+
+
+
+void
+xfce_appfinder_category_model_icon_theme_changed (XfceAppfinderCategoryModel *model)
+{
+ Categoryitem *item;
+ GSList *li;
+ gint idx;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+
+ g_return_if_fail (XFCE_IS_APPFINDER_CATEGORY_MODEL (model));
+
+ for (li = model->categories, idx = 0; li != NULL; li = li->next, idx++)
+ {
+ item = li->data;
+
+ if (item->pixbuf != NULL)
+ {
+ g_object_unref (G_OBJECT (item->pixbuf));
+ item->pixbuf = NULL;
+
+ path = gtk_tree_path_new_from_indices (idx, -1);
+ ITER_INIT (iter, model->stamp, li);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
+ }
+ }
+}
diff --git a/src/appfinder-category-model.h b/src/appfinder-category-model.h
index 73ffdf5..31e6c8a 100644
--- a/src/appfinder-category-model.h
+++ b/src/appfinder-category-model.h
@@ -55,6 +55,8 @@ gboolean xfce_appfinder_category_model_row_separator_func (Gt
GtkTreeIter *iter,
gpointer user_data);
+void xfce_appfinder_category_model_icon_theme_changed (XfceAppfinderCategoryModel *model);
+
G_END_DECLS
#endif /* !__XFCE_APPFINDER_CATEGORY_MODEL_H__ */
diff --git a/src/appfinder-model.c b/src/appfinder-model.c
index dd6e31f..0d49e5c 100644
--- a/src/appfinder-model.c
+++ b/src/appfinder-model.c
@@ -220,7 +220,7 @@ xfce_appfinder_model_finalize (GObject *object)
g_object_unref (G_OBJECT (model->command_icon_large));
g_object_unref (G_OBJECT (model->command_icon_small));
- g_debug ("model cleared");
+ APPFINDER_DEBUG ("model cleared");
(*G_OBJECT_CLASS (xfce_appfinder_model_parent_class)->finalize) (object);
}
@@ -538,7 +538,7 @@ xfce_appfinder_model_collect_idle (gpointer user_data)
g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), FALSE);
g_return_val_if_fail (model->items == NULL, FALSE);
- g_debug ("insert idle start");
+ APPFINDER_DEBUG ("insert idle start");
GDK_THREADS_ENTER ();
@@ -579,7 +579,7 @@ xfce_appfinder_model_collect_idle (gpointer user_data)
GDK_THREADS_LEAVE ();
- g_debug ("insert idle end");
+ APPFINDER_DEBUG ("insert idle end");
return FALSE;
}
@@ -637,12 +637,14 @@ xfce_appfinder_model_item_free (gpointer data)
{
ModelItem *item = data;
+ if (item->item != NULL)
+ g_object_unref (G_OBJECT (item->item));
if (item->icon_small != NULL)
g_object_unref (G_OBJECT (item->icon_small));
if (item->icon_large != NULL)
g_object_unref (G_OBJECT (item->icon_large));
if (item->categories != NULL)
- g_ptr_array_free (item->categories, TRUE);
+ g_ptr_array_unref (item->categories);
g_free (item->abstract);
g_free (item->key);
g_free (item->command);
@@ -692,6 +694,79 @@ xfce_appfinder_model_item_key (GarconMenuItem *item)
+static ModelItem *
+xfce_appfinder_model_item_new (GarconMenuItem *menu_item)
+{
+ ModelItem *item;
+ const gchar *command, *p;
+
+ g_return_val_if_fail (GARCON_IS_MENU_ITEM (menu_item), NULL);
+
+ item = g_slice_new0 (ModelItem);
+ item->item = g_object_ref (G_OBJECT (menu_item));
+ item->visible = TRUE;
+
+ command = garcon_menu_item_get_command (menu_item);
+ if (G_LIKELY (command != NULL))
+ {
+ p = strchr (command, ' ');
+ if (p != NULL)
+ item->command = g_strndup (command, p - command);
+ else
+ item->command = g_strdup (command);
+ }
+
+ return item;
+}
+
+
+
+static void
+xfce_appfinder_model_item_changed (GarconMenuItem *menu_item,
+ XfceAppfinderModel *model)
+{
+ GSList *li;
+ ModelItem *item;
+ gint idx;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GPtrArray *categories;
+
+ /* lookup the item in the list */
+ for (li = model->items, idx = 0; li != NULL; li = li->next, idx++)
+ {
+ item = li->data;
+ if (item->item == menu_item)
+ {
+ categories = g_ptr_array_ref (item->categories);
+ g_object_ref (G_OBJECT (menu_item));
+
+ APPFINDER_DEBUG ("update item %s", garcon_menu_item_get_desktop_id (menu_item));
+
+ g_hash_table_remove (model->items_hash, item->command);
+ xfce_appfinder_model_item_free (item);
+
+ item = xfce_appfinder_model_item_new (menu_item);
+ item->categories = categories;
+ li->data = item;
+
+ if (G_LIKELY (item->command != NULL))
+ g_hash_table_insert (model->items_hash, item->command, item);
+
+ g_object_unref (G_OBJECT (menu_item));
+
+ path = gtk_tree_path_new_from_indices (idx, -1);
+ ITER_INIT (iter, model->stamp, li);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
+
+ break;
+ }
+ }
+}
+
+
+
static gboolean
xfce_appfinder_model_ptr_array_strcmp (GPtrArray *array,
const gchar *str1)
@@ -724,7 +799,6 @@ xfce_appfinder_model_collect_items (XfceAppfinderModel *model,
ModelItem *item;
gboolean has_items = FALSE;
const gchar *desktop_id;
- const gchar *command, *p;
g_return_val_if_fail (GARCON_IS_MENU (menu), FALSE);
@@ -751,32 +825,24 @@ xfce_appfinder_model_collect_items (XfceAppfinderModel *model,
item = g_hash_table_lookup (model->collect_desktop_ids, desktop_id);
if (G_LIKELY (item == NULL))
{
- item = g_slice_new0 (ModelItem);
- item->visible = TRUE;
- item->item = li->data;
-
- command = garcon_menu_item_get_command (li->data);
- if (G_LIKELY (command != NULL))
- {
- p = strchr (command, ' ');
- if (p != NULL)
- item->command = g_strndup (command, p - command);
- else
- item->command = g_strdup (command);
- }
+ item = xfce_appfinder_model_item_new (li->data);
item->categories = g_ptr_array_new_with_free_func (g_free);
g_ptr_array_add (item->categories, g_strdup (category));
model->collect_items = g_slist_prepend (model->collect_items, item);
g_hash_table_insert (model->collect_desktop_ids, (gchar *) desktop_id, item);
- g_hash_table_insert (model->items_hash, item->command, item);
+ if (G_LIKELY (item->command != NULL))
+ g_hash_table_insert (model->items_hash, item->command, item);
+
+ g_signal_connect (G_OBJECT (item->item), "changed",
+ G_CALLBACK (xfce_appfinder_model_item_changed), model);
}
else if (!xfce_appfinder_model_ptr_array_strcmp (item->categories, category))
{
/* add category to existing item */
g_ptr_array_add (item->categories, g_strdup (category));
- g_debug ("%s is in %d categories", desktop_id, item->categories->len);
+ APPFINDER_DEBUG ("%s is in %d categories", desktop_id, item->categories->len);
}
has_items = TRUE;
@@ -834,6 +900,18 @@ xfce_appfinder_model_collect_history (XfceAppfinderModel *model,
+static void
+xfce_appfinder_model_menu_changed (GarconMenu *menu,
+ XfceAppfinderModel *model)
+{
+ g_return_if_fail (GARCON_IS_MENU (menu));
+ g_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
+
+
+}
+
+
+
static gpointer
xfce_appfinder_model_collect_thread (gpointer user_data)
{
@@ -844,8 +922,9 @@ xfce_appfinder_model_collect_thread (gpointer user_data)
g_return_val_if_fail (GARCON_IS_MENU (model->menu), NULL);
g_return_val_if_fail (model->collect_items == NULL, NULL);
+ g_return_val_if_fail (model->collect_desktop_ids == NULL, NULL);
- g_debug ("collect thread start");
+ APPFINDER_DEBUG ("collect thread start");
/* load menu data */
if (G_LIKELY (model->menu != NULL))
@@ -891,7 +970,13 @@ xfce_appfinder_model_collect_thread (gpointer user_data)
model, xfce_appfinder_model_collect_idle_destroy);
}
- g_debug ("collect thread end");
+ if (G_LIKELY (model->menu != NULL))
+ {
+ g_signal_connect (G_OBJECT (model->menu), "reload-required",
+ G_CALLBACK (xfce_appfinder_model_menu_changed), model);
+ }
+
+ APPFINDER_DEBUG ("collect thread end");
return NULL;
}
@@ -1127,7 +1212,7 @@ xfce_appfinder_model_load_pixbuf (const gchar *icon_name,
GdkPixbuf *pixbuf = NULL;
GdkPixbuf *scaled;
- g_debug ("load icon %s at %dpx", icon_name, size);
+ APPFINDER_DEBUG ("load icon %s at %dpx", icon_name, size);
if (icon_name != NULL)
{
@@ -1183,7 +1268,7 @@ xfce_appfinder_model_save_command (XfceAppfinderModel *model,
contents = g_string_new (NULL);
- g_debug ("saving history");
+ APPFINDER_DEBUG ("saving history");
/* store all the custom commands */
for (li = model->items; li != NULL; li = li->next)
@@ -1229,6 +1314,8 @@ xfce_appfinder_model_get_icon_for_command (XfceAppfinderModel *model,
ModelItem *item;
const gchar *icon_name;
+ g_return_val_if_fail (XFCE_IS_APPFINDER_MODEL (model), NULL);
+
if (IS_STRING (command))
{
item = g_hash_table_lookup (model->items_hash, command);
@@ -1247,3 +1334,63 @@ xfce_appfinder_model_get_icon_for_command (XfceAppfinderModel *model,
return NULL;
}
+
+
+
+void
+xfce_appfinder_model_icon_theme_changed (XfceAppfinderModel *model)
+{
+ ModelItem *item;
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ gint idx;
+ gboolean item_changed;
+ GSList *li;
+
+ g_return_if_fail (XFCE_IS_APPFINDER_MODEL (model));
+
+ APPFINDER_DEBUG ("icon theme changed");
+
+ /* reload the command icons */
+ if (model->command_icon_small != NULL)
+ g_object_unref (G_OBJECT (model->command_icon_small));
+ model->command_icon_small = xfce_appfinder_model_load_pixbuf (GTK_STOCK_EXECUTE, ICON_SMALL);
+
+ if (model->command_icon_large != NULL)
+ g_object_unref (G_OBJECT (model->command_icon_large));
+ model->command_icon_large = xfce_appfinder_model_load_pixbuf (GTK_STOCK_EXECUTE, ICON_LARGE);
+
+ /* update the model items */
+ for (li = model->items, idx = 0; li != NULL; li = li->next, idx++)
+ {
+ item = li->data;
+ item_changed = FALSE;
+
+ if (item->icon_small != NULL)
+ {
+ g_object_unref (G_OBJECT (item->icon_small));
+ item->icon_small = NULL;
+ item_changed = TRUE;
+ }
+ if (item->icon_large != NULL)
+ {
+ g_object_unref (G_OBJECT (item->icon_large));
+ item->icon_large = NULL;
+ item_changed = TRUE;
+ }
+
+ if (item->item == NULL)
+ {
+ item->icon_small = g_object_ref (G_OBJECT (model->command_icon_small));
+ item->icon_large = g_object_ref (G_OBJECT (model->command_icon_large));
+ }
+
+ if (item_changed && item->visible)
+ {
+ path = gtk_tree_path_new_from_indices (idx, -1);
+ ITER_INIT (iter, model->stamp, li);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
+ }
+ }
+}
diff --git a/src/appfinder-model.h b/src/appfinder-model.h
index 13dcfa0..a4b018b 100644
--- a/src/appfinder-model.h
+++ b/src/appfinder-model.h
@@ -44,6 +44,12 @@ G_STMT_START { \
} G_STMT_END
#define IS_STRING(str) ((str) != NULL && *(str) != '\0')
+#ifdef DEBUG
+#define APPFINDER_DEBUG(...) g_print ("xfce4-appfinder: "); g_print (__VA_ARGS__); g_print ("\n")
+#else
+#define APPFINDER_DEBUG(...) G_STMT_START{ (void)0; }G_STMT_END
+#endif
+
enum
{
XFCE_APPFINDER_MODEL_COLUMN_ABSTRACT,
@@ -84,6 +90,8 @@ gboolean xfce_appfinder_model_save_command (XfceAppfinderMode
GdkPixbuf *xfce_appfinder_model_get_icon_for_command (XfceAppfinderModel *model,
const gchar *command);
+void xfce_appfinder_model_icon_theme_changed (XfceAppfinderModel *model);
+
G_END_DECLS
#endif /* !__XFCE_APPFINDER_MODEL_H__ */
diff --git a/src/appfinder-window.c b/src/appfinder-window.c
index afe8a31..68dfbfd 100644
--- a/src/appfinder-window.c
+++ b/src/appfinder-window.c
@@ -64,6 +64,7 @@ static void xfce_appfinder_window_category_changed (GtkTreeSelecti
XfceAppfinderWindow *window);
static void xfce_appfinder_window_item_changed (XfceAppfinderWindow *window);
static void xfce_appfinder_window_row_activated (XfceAppfinderWindow *window);
+static void xfce_appfinder_window_icon_theme_changed (XfceAppfinderWindow *window);
static void xfce_appfinder_window_execute (XfceAppfinderWindow *window);
@@ -145,6 +146,7 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
GtkWidget *button;
GtkTreePath *path;
GtkEntryCompletion *completion;
+ GtkIconTheme *icon_theme;
window->last_window_height = 400;
@@ -314,9 +316,11 @@ xfce_appfinder_window_init (XfceAppfinderWindow *window)
image = gtk_image_new_from_stock (GTK_STOCK_EXECUTE, GTK_ICON_SIZE_BUTTON);
gtk_button_set_image (GTK_BUTTON (button), image);
- gtk_widget_show (image);
- g_debug ("constructed window");
+ icon_theme = gtk_icon_theme_get_for_screen (gtk_window_get_screen (GTK_WINDOW (window)));
+ g_signal_connect_swapped (G_OBJECT (icon_theme), "changed", G_CALLBACK (xfce_appfinder_window_icon_theme_changed), window);
+
+ APPFINDER_DEBUG ("constructed window");
}
@@ -598,6 +602,24 @@ xfce_appfinder_window_row_activated (XfceAppfinderWindow *window)
+static void
+xfce_appfinder_window_icon_theme_changed (XfceAppfinderWindow *window)
+{
+ if (window->icon_find != NULL)
+ g_object_unref (G_OBJECT (window->icon_find));
+ window->icon_find = xfce_appfinder_model_load_pixbuf (GTK_STOCK_FIND, ICON_LARGE);
+
+ /* drop cached pixbufs */
+ xfce_appfinder_model_icon_theme_changed (window->model);
+ xfce_appfinder_category_model_icon_theme_changed (window->category_model);
+
+ /* update state */
+ xfce_appfinder_window_entry_changed (window);
+ xfce_appfinder_window_item_changed (window);
+}
+
+
+
static gboolean
xfce_appfinder_window_execute_command (const gchar *cmd,
GdkScreen *screen,
@@ -726,7 +748,7 @@ xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window,
GtkWidget *parent;
GtkEntryCompletion *completion;
- g_debug ("set expand = %s", expanded ? "true" : "false");
+ APPFINDER_DEBUG ("set expand = %s", expanded ? "true" : "false");
/* force window geomentry */
if (expanded)
diff --git a/src/main.c b/src/main.c
index 0e8c0a9..5750b82 100644
--- a/src/main.c
+++ b/src/main.c
@@ -28,6 +28,7 @@
#include <libxfce4util/libxfce4util.h>
#include <garcon/garcon.h>
+#include <src/appfinder-model.h>
#include <src/appfinder-window.h>
@@ -101,7 +102,7 @@ main (gint argc, gchar **argv)
xfce_appfinder_window_set_expanded (XFCE_APPFINDER_WINDOW (window), opt_finder);
gtk_widget_show (window);
- g_debug ("enter mainloop");
+ APPFINDER_DEBUG ("enter mainloop");
gtk_main ();
More information about the Xfce4-commits
mailing list