From f753b6b03be3585bb9f96b276afffa0164a9a9e3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Mar 2011 09:01:20 -0600 Subject: Use the 'basename' parameter --- libdbusmenu-glib/enum-types.c.in | 2 +- libdbusmenu-glib/enum-types.h.in | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-glib/enum-types.c.in b/libdbusmenu-glib/enum-types.c.in index 9395f5f..40f1759 100644 --- a/libdbusmenu-glib/enum-types.c.in +++ b/libdbusmenu-glib/enum-types.c.in @@ -31,7 +31,7 @@ License version 3 and version 2.1 along with this program. If not, see /*** END file-header ***/ /*** BEGIN file-production ***/ -#include "@filename@" +#include "@basename@" /*** END file-production ***/ /*** BEGIN value-header ***/ diff --git a/libdbusmenu-glib/enum-types.h.in b/libdbusmenu-glib/enum-types.h.in index 488b615..5758438 100644 --- a/libdbusmenu-glib/enum-types.h.in +++ b/libdbusmenu-glib/enum-types.h.in @@ -44,13 +44,16 @@ G_END_DECLS /*** BEGIN file-production ***/ /* Enumerations from file: "@filename@" */ -#include "@filename@" +#include "@basename@" + /*** END file-production ***/ /*** BEGIN value-header ***/ + GType @enum_name@_get_type (void) G_GNUC_CONST; const gchar * @enum_name@_get_nick (@EnumName@ value) G_GNUC_CONST; @EnumName@ @enum_name@_get_value_from_nick (const gchar * nick) G_GNUC_CONST; + /** DBUSMENU_TYPE_@ENUMSHORT@: -- cgit v1.2.3 From 761849e55ee1a6b6597e81f00dc20f7a8397e67f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Mar 2011 11:41:48 -0600 Subject: Signal handler for theme directories changing. --- libdbusmenu-gtk/client.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 50978ff..d3d0533 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -54,6 +54,7 @@ static void new_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint po static void delete_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, DbusmenuGtkClient * gtkclient); static void move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint old, DbusmenuGtkClient * gtkclient); static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); +static void theme_dir_changed (DbusmenuClient * client, GStrv theme_dirs, gpointer userdata); static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); @@ -96,6 +97,7 @@ dbusmenu_gtkclient_init (DbusmenuGtkClient *self) /* TODO: I think these can be handled in the class... */ g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM, G_CALLBACK(new_menuitem), NULL); g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE, G_CALLBACK(item_activate), NULL); + g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_ICON_THEME_DIRS_CHANGED, G_CALLBACK(theme_dir_changed), NULL); return; } @@ -124,6 +126,16 @@ dbusmenu_gtkclient_finalize (GObject *object) return; } +/* Called when the theme directories are changed by the + server part of things. */ +static void +theme_dir_changed (DbusmenuClient * client, GStrv theme_dirs, gpointer userdata) +{ + + + return; +} + /* Structure for passing data to swap_agroup */ typedef struct _swap_agroup_t swap_agroup_t; struct _swap_agroup_t { -- cgit v1.2.3 From 3d56637921acae3410b1889ddc2f7dba16b46e80 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Mar 2011 11:47:23 -0600 Subject: Making a private variable and making a lifecycle for it. --- libdbusmenu-gtk/client.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index d3d0533..b0355c9 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -38,6 +38,7 @@ License version 3 and version 2.1 along with this program. If not, see /* Private */ struct _DbusmenuGtkClientPrivate { + GStrv old_themedirs; GtkAccelGroup * agroup; }; @@ -55,6 +56,7 @@ static void delete_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, Dbusm static void move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint old, DbusmenuGtkClient * gtkclient); static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); static void theme_dir_changed (DbusmenuClient * client, GStrv theme_dirs, gpointer userdata); +static void remove_theme_dirs (GtkIconTheme * theme, GStrv dirs); static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); @@ -90,6 +92,7 @@ dbusmenu_gtkclient_init (DbusmenuGtkClient *self) DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(self); priv->agroup = NULL; + priv->old_themedirs = NULL; dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPARATOR, new_item_seperator); @@ -113,6 +116,12 @@ dbusmenu_gtkclient_dispose (GObject *object) priv->agroup = NULL; } + if (priv->old_themedirs) { + remove_theme_dirs(gtk_icon_theme_get_default(), priv->old_themedirs); + g_strfreev(priv->old_themedirs); + priv->old_themedirs = NULL; + } + G_OBJECT_CLASS (dbusmenu_gtkclient_parent_class)->dispose (object); return; } @@ -126,6 +135,14 @@ dbusmenu_gtkclient_finalize (GObject *object) return; } +/* Unregister this list of theme directories */ +static void +remove_theme_dirs (GtkIconTheme * theme, GStrv dirs) +{ + + return; +} + /* Called when the theme directories are changed by the server part of things. */ static void -- cgit v1.2.3 From 59336ca7d7d4706bbe122446f6a1179a12f9ba55 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Mar 2011 12:04:43 -0600 Subject: Fleshing out the change functions, but it infact creates more functions. Whoa! --- libdbusmenu-gtk/client.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b0355c9..c998517 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -42,6 +42,8 @@ struct _DbusmenuGtkClientPrivate { GtkAccelGroup * agroup; }; +GHashTable * theme_dir_db = NULL; + #define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) (DBUSMENU_GTKCLIENT(o)->priv) #define USE_FALLBACK_PROP "use-fallback" @@ -135,10 +137,32 @@ dbusmenu_gtkclient_finalize (GObject *object) return; } +static void +theme_dir_ref (GtkIconTheme * theme, GHashTable * db, const gchar * dir) +{ + + return; +} + +static void +theme_dir_unref (GtkIconTheme * theme, GHashTable * db, const gchar * dir) +{ + + return; +} + /* Unregister this list of theme directories */ static void remove_theme_dirs (GtkIconTheme * theme, GStrv dirs) { + g_return_if_fail(GTK_ICON_THEME(theme)); + g_return_if_fail(dirs != NULL); + + int dir; + + for (dir = 0; dirs[dir] != NULL; dir++) { + theme_dir_unref(theme, theme_dir_db, dirs[dir]); + } return; } @@ -148,7 +172,28 @@ remove_theme_dirs (GtkIconTheme * theme, GStrv dirs) static void theme_dir_changed (DbusmenuClient * client, GStrv theme_dirs, gpointer userdata) { + DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(client); + GtkIconTheme * theme = gtk_icon_theme_get_default(); + + /* Ref the new directories */ + if (theme_dirs != NULL) { + int dir; + for (dir = 0; theme_dirs[dir] != NULL; dir++) { + theme_dir_ref(theme, theme_dir_db, theme_dirs[dir]); + } + } + /* Unref the old ones */ + if (priv->old_themedirs) { + remove_theme_dirs(theme, priv->old_themedirs); + g_strfreev(priv->old_themedirs); + priv->old_themedirs = NULL; + } + + /* Copy the new to the old */ + if (theme_dirs != NULL) { + priv->old_themedirs = g_strdupv(theme_dirs); + } return; } -- cgit v1.2.3 From 911ce51574b4771318d5af94a239a4d41e6001a3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Mar 2011 12:37:14 -0600 Subject: Build the theme directory database when we build objects --- libdbusmenu-gtk/client.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index c998517..88671f7 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -96,6 +96,22 @@ dbusmenu_gtkclient_init (DbusmenuGtkClient *self) priv->agroup = NULL; priv->old_themedirs = NULL; + /* We either build the theme db or we get a reference + to it. This way when all clients die the hashtable + will be free'd as well. */ + if (theme_dir_db == NULL) { + theme_dir_db = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + + /* NOTE: We're adding an extra ref here because there + is no way to clear the pointer when the hash table + dies, so it's safer to keep the hash table around + forever than not know if it's free'd or not. Patch + submitted to GLib. */ + g_hash_table_ref(theme_dir_db); + } else { + g_hash_table_ref(theme_dir_db); + } + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPARATOR, new_item_seperator); @@ -124,6 +140,12 @@ dbusmenu_gtkclient_dispose (GObject *object) priv->old_themedirs = NULL; } + if (theme_dir_db != NULL) { + g_hash_table_unref(theme_dir_db); + } else { + g_assert_not_reached(); + } + G_OBJECT_CLASS (dbusmenu_gtkclient_parent_class)->dispose (object); return; } -- cgit v1.2.3 From 0108ac16f1db0c6e7cbc46e0f61c1267bdf607a3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Mar 2011 17:22:56 -0600 Subject: Stealing the code from indicator-application to ref and unref theme directories. --- libdbusmenu-gtk/client.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 88671f7..fd266df 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -159,16 +159,90 @@ dbusmenu_gtkclient_finalize (GObject *object) return; } +/* Add a theme directory to the table and the theme's list of available + themes to use. */ static void theme_dir_ref (GtkIconTheme * theme, GHashTable * db, const gchar * dir) { + g_return_if_fail(db != NULL); + g_return_if_fail(theme != NULL); + g_return_if_fail(dir != NULL); + + int count = 0; + if ((count = GPOINTER_TO_INT(g_hash_table_lookup(db, dir))) != 0) { + /* It exists so what we need to do is increase the ref + count of this dir. */ + count++; + } else { + /* It doesn't exist, so we need to add it to the table + and to the search path. */ + gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(), dir); + g_debug("\tAppending search path: %s", dir); + count = 1; + } + + g_hash_table_insert(db, g_strdup(dir), GINT_TO_POINTER(count)); return; } +/* Unreference the theme directory, and if it's count goes to zero then + we need to remove it from the search path. */ static void theme_dir_unref (GtkIconTheme * theme, GHashTable * db, const gchar * dir) { + g_return_if_fail(db != NULL); + g_return_if_fail(theme != NULL); + g_return_if_fail(dir != NULL); + + /* Grab the count for this dir */ + int count = GPOINTER_TO_INT(g_hash_table_lookup(db, dir)); + + /* Is this a simple deprecation, if so, we can just lower the + number and move on. */ + if (count > 1) { + count--; + g_hash_table_insert(db, g_strdup(dir), GINT_TO_POINTER(count)); + return; + } + + /* Try to remove it from the hash table, this makes sure + that it existed */ + if (!g_hash_table_remove(db, dir)) { + g_warning("Unref'd a directory that wasn't in the theme dir hash table."); + return; + } + + gchar ** paths; + gint path_count; + + gtk_icon_theme_get_search_path(theme, &paths, &path_count); + + gint i; + gboolean found = FALSE; + for (i = 0; i < path_count; i++) { + if (found) { + /* If we've already found the right entry */ + paths[i - 1] = paths[i]; + } else { + /* We're still looking, is this the one? */ + if (!g_strcmp0(paths[i], dir)) { + found = TRUE; + /* We're freeing this here as it won't be captured by the + g_strfreev() below as it's out of the array. */ + g_free(paths[i]); + } + } + } + + /* If we found one we need to reset the path to + accomidate the changes */ + if (found) { + paths[path_count - 1] = NULL; /* Clear the last one */ + gtk_icon_theme_set_search_path(theme, (const gchar **)paths, path_count - 1); + } + + g_strfreev(paths); return; } -- cgit v1.2.3 From 639d982ed6fb70b09cd72e19a73d16a5e2f78db3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 7 Mar 2011 10:46:22 -0600 Subject: Switching to using the extended lookup and getting the key and value --- libdbusmenu-glib/menuitem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index f7867e4..8534370 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1183,14 +1183,16 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro gboolean replaced = FALSE; gboolean remove = FALSE; - gpointer currentval = g_hash_table_lookup(priv->properties, property); + gchar * hash_key = NULL; + GVariant * hash_variant = NULL; + gboolean inhash = g_hash_table_lookup_extended(priv->properties, property, (gpointer *)&hash_key, (gpointer *)&hash_variant); if (value != NULL) { /* NOTE: We're only marking this as replaced if this is true but we're actually replacing it no matter. This is so that the variant passed in sticks around which the caller may expect. They shouldn't, but it's low cost to remove bugs. */ - if (currentval == NULL || !g_variant_equal((GVariant*)currentval, value)) { + if (inhash || !g_variant_equal(hash_variant, value)) { replaced = TRUE; } @@ -1204,7 +1206,7 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro bad value */ g_hash_table_insert(priv->properties, lprop, value); } else { - if (currentval != NULL) { + if (inhash) { /* So the question you should be asking if you're paying attention is "Why not just do the remove here?" It's a good question with an interesting answer. Bascially it's the same reason as above, @@ -1220,7 +1222,7 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro becuse it has been unref'd when replaced in the hash table. But the fact that there was a value is the imporant part. */ - if (currentval == NULL || replaced) { + if (!inhash || replaced) { GVariant * signalval = value; if (signalval == NULL) { -- cgit v1.2.3 From b0af2cb938c23b980bd39ec3094d6d04e0996e25 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 7 Mar 2011 10:48:13 -0600 Subject: Steal earlier instead of later so that signal handlers don't find the value in the hashtable --- libdbusmenu-glib/menuitem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 8534370..950889b 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1215,6 +1215,7 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro it) after the signal emition */ remove = TRUE; replaced = TRUE; + g_hash_table_steal(priv->properties, property); } } @@ -1235,7 +1236,8 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro } if (remove) { - g_hash_table_remove(priv->properties, property); + g_free(hash_key); + g_variant_unref(hash_variant); } return TRUE; -- cgit v1.2.3 From d5e89f9a0144e0df6ba0cb45a97a1a598c96d8f1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 7 Mar 2011 12:19:14 -0600 Subject: Putting in a protection and fixing the truth --- libdbusmenu-glib/menuitem.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 950889b..2e5a345 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1180,19 +1180,23 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro } } - gboolean replaced = FALSE; gboolean remove = FALSE; gchar * hash_key = NULL; GVariant * hash_variant = NULL; gboolean inhash = g_hash_table_lookup_extended(priv->properties, property, (gpointer *)&hash_key, (gpointer *)&hash_variant); + if (inhash && hash_variant == NULL) { + g_warning("The property '%s' is in the hash with a NULL variant", property); + inhash = FALSE; + } + if (value != NULL) { /* NOTE: We're only marking this as replaced if this is true but we're actually replacing it no matter. This is so that the variant passed in sticks around which the caller may expect. They shouldn't, but it's low cost to remove bugs. */ - if (inhash || !g_variant_equal(hash_variant, value)) { + if (!inhash || !g_variant_equal(hash_variant, value)) { replaced = TRUE; } -- cgit v1.2.3 -- cgit v1.2.3 From 3ff07dc2e4582f3f6ef7fcbb57122a8a0a22caa6 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 8 Mar 2011 11:16:35 -0500 Subject: pass on mnemonics and markup from label --- libdbusmenu-gtk/parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index cf2003f..71df266 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -425,7 +425,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) // (like empathy), so watch the label especially for that. dbusmenu_menuitem_property_set (mi, "label", - gtk_label_get_text (GTK_LABEL (label))); + gtk_label_get_label (GTK_LABEL (label))); pdata->label = label; g_signal_connect (G_OBJECT (label), @@ -670,7 +670,7 @@ label_notify_cb (GtkWidget *widget, { dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_LABEL, - gtk_label_get_text (GTK_LABEL (widget))); + gtk_label_get_label (GTK_LABEL (widget))); } } -- cgit v1.2.3 From 7b868b0d9426cf060347d01da12a48b3b2bab82b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 8 Mar 2011 11:55:34 -0500 Subject: wrap PropertiesChanged arguments in a variant --- libdbusmenu-glib/server.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index ca39ea3..a41e6ce 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -511,7 +511,7 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) GVariantBuilder params; g_variant_builder_init(¶ms, G_VARIANT_TYPE_TUPLE); g_variant_builder_add_value(¶ms, g_variant_new_string(DBUSMENU_INTERFACE)); - GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("TextDirection"), g_variant_new_string(dbusmenu_text_direction_get_nick(priv->text_direction))); + GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("TextDirection"), g_variant_new_variant(g_variant_new_string(dbusmenu_text_direction_get_nick(priv->text_direction)))); g_variant_builder_add_value(¶ms, g_variant_new_array(NULL, &dict, 1)); g_variant_builder_add_value(¶ms, g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0)); GVariant * vparams = g_variant_builder_end(¶ms); @@ -535,7 +535,7 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) GVariantBuilder params; g_variant_builder_init(¶ms, G_VARIANT_TYPE_TUPLE); g_variant_builder_add_value(¶ms, g_variant_new_string(DBUSMENU_INTERFACE)); - GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("Status"), g_variant_new_string(dbusmenu_status_get_nick(instatus))); + GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("Status"), g_variant_new_variant(g_variant_new_string(dbusmenu_status_get_nick(instatus)))); g_variant_builder_add_value(¶ms, g_variant_new_array(NULL, &dict, 1)); g_variant_builder_add_value(¶ms, g_variant_new_array(G_VARIANT_TYPE_STRING, NULL, 0)); GVariant * vparams = g_variant_builder_end(¶ms); @@ -1773,7 +1773,7 @@ dbusmenu_server_set_icon_paths (DbusmenuServer * server, GStrv icon_paths) g_variant_builder_add_value(¶ms, g_variant_new_string(DBUSMENU_INTERFACE)); GVariant * items = NULL; if (priv->icon_dirs != NULL) { - GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("IconThemePath"), g_variant_new_strv((const gchar * const *)priv->icon_dirs, -1)); + GVariant * dict = g_variant_new_dict_entry(g_variant_new_string("IconThemePath"), g_variant_new_variant(g_variant_new_strv((const gchar * const *)priv->icon_dirs, -1))); items = g_variant_new_array(NULL, &dict, 1); } else { items = g_variant_new_array(G_VARIANT_TYPE("{sv}"), NULL, 0); -- cgit v1.2.3 From b75477d3520217942159625e9dfac3001a4b5d49 Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Tue, 8 Mar 2011 23:00:45 +0000 Subject: Ensure we set the CACHED_MENUITEM data on GtkWidget's --- libdbusmenu-gtk/parser.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index cf2003f..b0a5cfd 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -219,6 +219,7 @@ new_menuitem (GtkWidget * widget) pdata->widget = widget; g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget); + g_object_set_data(G_OBJECT(widget), CACHED_MENUITEM, item); return item; } @@ -311,6 +312,10 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) /* Oops, let's tell our parents about us */ if (peek == NULL) { + if (dbusmenu_menuitem_get_parent(thisitem) != NULL) { + dbusmenu_menuitem_unparent(thisitem); + } + gint pos = get_child_position (widget); if (pos >= 0) dbusmenu_menuitem_child_add_position (recurse->parent, -- cgit v1.2.3 From 415011b666e92ec899b2c53c80708fdfc1d90322 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 9 Mar 2011 08:26:36 -0500 Subject: sanitize label text to strip pango markup --- libdbusmenu-gtk/parser.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 71df266..2d42de5 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -340,6 +340,23 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) return; } +static gchar * +sanitize_label_text (const gchar * label) +{ + /* Label contains underscores, which we like, and pango markup, + which we don't. */ + gchar * sanitized = NULL; + GError * error = NULL; + if (pango_parse_markup (label, -1, 0, NULL, &sanitized, NULL, &error)) { + return sanitized; + } + else { + g_warning ("Could not parse '%s': %s", label, error->message); + g_error_free (error); + return g_strdup (label); + } +} + /* Turn a widget into a dbusmenu item depending on the type of GTK object that it is. */ static DbusmenuMenuitem * @@ -423,9 +440,9 @@ construct_dbusmenu_for_widget (GtkWidget * widget) { // Sometimes, an app will directly find and modify the label // (like empathy), so watch the label especially for that. - dbusmenu_menuitem_property_set (mi, - "label", - gtk_label_get_label (GTK_LABEL (label))); + gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (label))); + dbusmenu_menuitem_property_set (mi, "label", text); + g_free (text); pdata->label = label; g_signal_connect (G_OBJECT (label), @@ -668,9 +685,11 @@ label_notify_cb (GtkWidget *widget, if (pspec->name == g_intern_static_string ("label")) { + gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (widget))); dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_LABEL, - gtk_label_get_label (GTK_LABEL (widget))); + text); + g_free (text); } } @@ -724,9 +743,11 @@ action_notify_cb (GtkAction *action, } else if (pspec->name == g_intern_static_string ("label")) { + gchar * text = sanitize_label_text (gtk_action_get_label (action)); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, - gtk_action_get_label (action)); + text); + g_free (text); } } -- cgit v1.2.3 -- cgit v1.2.3 From 49ce3e92dd5e30a514813a9e9e8e38087a5e73bd Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 9 Mar 2011 15:02:07 -0500 Subject: respect use-underline and use-markup of labels in menu items --- libdbusmenu-gtk/parser.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 8954d64..a890543 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -362,6 +362,32 @@ sanitize_label_text (const gchar * label) } } +static gchar * +sanitize_label (GtkLabel * label) +{ + gchar * text; + + if (gtk_label_get_use_markup (label)) { + text = sanitize_label_text (gtk_label_get_label (label)); + } + else { + text = g_strdup (gtk_label_get_label (label)); + } + + if (!gtk_label_get_use_underline (label)) { + /* Insert extra underscores */ + GRegex * regex = g_regex_new ("_", 0, 0, NULL); + gchar * escaped = g_regex_replace_literal (regex, text, -1, 0, "__", 0, NULL); + + g_regex_unref (regex); + g_free (text); + + text = escaped; + } + + return text; +} + /* Turn a widget into a dbusmenu item depending on the type of GTK object that it is. */ static DbusmenuMenuitem * @@ -445,7 +471,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) { // Sometimes, an app will directly find and modify the label // (like empathy), so watch the label especially for that. - gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (label))); + gchar * text = sanitize_label (GTK_LABEL (label)); dbusmenu_menuitem_property_set (mi, "label", text); g_free (text); @@ -690,7 +716,7 @@ label_notify_cb (GtkWidget *widget, if (pspec->name == g_intern_static_string ("label")) { - gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (widget))); + gchar * text = sanitize_label (GTK_LABEL (widget)); dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_LABEL, text); -- cgit v1.2.3 From b50608f6000958965cf899ba6af1e2da52979051 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 9 Mar 2011 14:26:21 -0600 Subject: Check to ensure that layout_props isn't NULL. Atleast we shouldn't crash. --- libdbusmenu-glib/client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index c95b161..61253e2 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -1823,6 +1823,7 @@ static void update_layout (DbusmenuClient * client) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + g_return_if_fail(priv->layout_props != NULL); if (priv->menuproxy == NULL) { return; -- cgit v1.2.3 From 02b4e66962229f0d2ed48732466c6258b3b9a20a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 9 Mar 2011 16:52:46 -0600 Subject: Add a function to get the cached menu item --- libdbusmenu-gtk/parser.c | 19 +++++++++++++++++++ libdbusmenu-gtk/parser.h | 1 + 2 files changed, 20 insertions(+) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index a890543..1b032bb 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -109,6 +109,25 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) return recurse.parent; } +/** + * dbusmenu_gtk_parse_get_cached_item: + * @widget: A #GtkMenuItem that may have a cached #DbusmenuMenuitem from the parser + * + * The Dbusmenu GTK parser adds cached items on the various + * menu items throughout the tree. Sometimes it can be useful + * to get that cached item to use directly. This function + * will retrieve it for you. + * + * Return value: (transfer none): A pointer to the cached item + * or NULL if it isn't there. + */ +DbusmenuMenuitem * +dbusmenu_gtk_parse_get_cached_item (GtkWidget * widget) +{ + g_return_val_if_fail(GTK_IS_MENU_ITEM(widget), NULL); + return DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM)); +} + static void parse_data_free (gpointer data) { diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h index 8187a8e..97fa9c6 100644 --- a/libdbusmenu-gtk/parser.h +++ b/libdbusmenu-gtk/parser.h @@ -35,6 +35,7 @@ License version 3 and version 2.1 along with this program. If not, see G_BEGIN_DECLS DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget); +DbusmenuMenuitem * dbusmenu_gtk_parse_get_cached_item (GtkWidget * widget); /** SECTION:parser -- cgit v1.2.3 From 8b44761d80a2c9ccdd7482feeabd3bcb5396387b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 9 Mar 2011 16:53:26 -0600 Subject: Add to documentation as well --- docs/libdbusmenu-gtk/reference/libdbusmenu-gtk-sections.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/libdbusmenu-gtk/reference/libdbusmenu-gtk-sections.txt b/docs/libdbusmenu-gtk/reference/libdbusmenu-gtk-sections.txt index 77101f7..efffeaa 100644 --- a/docs/libdbusmenu-gtk/reference/libdbusmenu-gtk-sections.txt +++ b/docs/libdbusmenu-gtk/reference/libdbusmenu-gtk-sections.txt @@ -73,5 +73,6 @@ dbusmenu_menuitem_property_get_shortcut
parser dbusmenu_gtk_parse_menu_structure +dbusmenu_gtk_parse_get_cached_item
-- cgit v1.2.3 From ec307704b44db4f65f3534f23cfdf517c883a9e1 Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Thu, 10 Mar 2011 00:43:07 +0000 Subject: Fix various memory leaks --- libdbusmenu-glib/client.c | 11 ++++++----- libdbusmenu-gtk/client.c | 4 ++++ libdbusmenu-gtk/menuitem.c | 7 +------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 61253e2..5ca52f4 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -1213,7 +1213,9 @@ menuproxy_signal_cb (GDBusProxy * proxy, gchar * sender, gchar * signal, GVarian while (g_variant_iter_next(&properties, "s", &property)) { /* g_debug("Removing property '%s' on %d", property, id); */ dbusmenu_menuitem_property_remove(menuitem, property); + g_free(property); } + g_variant_unref(ritem); } GVariantIter items; @@ -1304,12 +1306,11 @@ menuitem_get_properties_replace_cb (GVariant * properties, GError * error, gpoin have_error = TRUE; } - GList * current_props = NULL; + GList * current_props = dbusmenu_menuitem_properties_list(DBUSMENU_MENUITEM(data)); + GList * tmp = NULL; - for (current_props = dbusmenu_menuitem_properties_list(DBUSMENU_MENUITEM(data)); - current_props != NULL && have_error == FALSE; - current_props = g_list_next(current_props)) { - dbusmenu_menuitem_property_remove(DBUSMENU_MENUITEM(data), (const gchar *)current_props->data); + for (tmp = current_props; tmp != NULL && have_error == FALSE; tmp = g_list_next(tmp)) { + dbusmenu_menuitem_property_remove(DBUSMENU_MENUITEM(data), (const gchar *)tmp->data); } g_list_free(current_props); diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 50978ff..b7b201d 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -697,6 +697,7 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu if (gmi != NULL) { dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + g_object_unref(gmi); } else { return FALSE; } @@ -870,6 +871,9 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant } else { gtk_image_set_from_pixbuf(GTK_IMAGE(gtkimage), image); } + if (image) { + g_object_unref(image); + } } } diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 370dbf2..b3358fe 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -119,12 +119,7 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * g_error_free(error); } - error = NULL; - g_input_stream_close(input, NULL, &error); - if (error != NULL) { - g_warning("Unable to close input stream: %s", error->message); - g_error_free(error); - } + g_object_unref(input); g_free(icondata); return icon; -- cgit v1.2.3 From a97646cd0857bc60433490542ec1b98daf9fe7a2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 10:11:04 -0600 Subject: On initially getting the proxy we need to check the theme directories to boot strap. --- libdbusmenu-glib/client.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index c95b161..6a62f9e 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -1056,10 +1056,25 @@ menuproxy_build_cb (GObject * object, GAsyncResult * res, gpointer user_data) } priv->text_direction = dbusmenu_text_direction_get_value_from_nick(g_variant_get_string(str, NULL)); + g_object_notify(G_OBJECT(user_data), DBUSMENU_CLIENT_PROP_TEXT_DIRECTION); g_variant_unref(textdir); } + /* Get the icon theme directories if available */ + GVariant * icon_dirs = g_dbus_proxy_get_cached_property(priv->menuproxy, "IconThemePath"); + if (icon_dirs != NULL) { + if (priv->icon_dirs != NULL) { + g_strfreev(priv->icon_dirs); + priv->icon_dirs = NULL; + } + + priv->icon_dirs = g_variant_dup_strv(icon_dirs, NULL); + g_signal_emit(G_OBJECT(client), signals[ICON_THEME_DIRS], 0, priv->icon_dirs, TRUE); + + g_variant_unref(icon_dirs); + } + /* If we get here, we don't need the DBus proxy */ if (priv->dbusproxy != 0) { g_bus_unwatch_name(priv->dbusproxy); -- cgit v1.2.3 From 4701338925eb99eff5c2dd7ef05815855aae5a87 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 10:13:58 -0600 Subject: Also check the status when we get the proxy, not part of this bug, but it'll come along soon enough. --- libdbusmenu-glib/client.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 6a62f9e..b9c50ee 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -1061,6 +1061,20 @@ menuproxy_build_cb (GObject * object, GAsyncResult * res, gpointer user_data) g_variant_unref(textdir); } + /* Check the status if available */ + GVariant * status = g_dbus_proxy_get_cached_property(priv->menuproxy, "Status"); + if (textdir != NULL) { + GVariant * str = status; + if (g_variant_is_of_type(str, G_VARIANT_TYPE_VARIANT)) { + str = g_variant_get_variant(str); + } + + priv->status = dbusmenu_status_get_value_from_nick(g_variant_get_string(str, NULL)); + g_object_notify(G_OBJECT(user_data), DBUSMENU_CLIENT_PROP_STATUS); + + g_variant_unref(status); + } + /* Get the icon theme directories if available */ GVariant * icon_dirs = g_dbus_proxy_get_cached_property(priv->menuproxy, "IconThemePath"); if (icon_dirs != NULL) { -- cgit v1.2.3 From bbadbf77efa2c3f322c4812677438129bbfef2f8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 10:15:08 -0600 Subject: Check the theme directories on build so we can insure we're up-to-date --- libdbusmenu-gtk/client.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index fd266df..de7a752 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -120,6 +120,8 @@ dbusmenu_gtkclient_init (DbusmenuGtkClient *self) g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE, G_CALLBACK(item_activate), NULL); g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_ICON_THEME_DIRS_CHANGED, G_CALLBACK(theme_dir_changed), NULL); + theme_dir_changed(DBUSMENU_CLIENT(self), dbusmenu_client_get_icon_paths(DBUSMENU_CLIENT(self)), NULL); + return; } -- cgit v1.2.3 From 00bb1b2c40694705e4ff7e5e62096a36eff35a38 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 10:41:48 -0600 Subject: Commenting out the Python tests as they don't test what we want --- tests/Makefile.am | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 61b3e69..a2c0716 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -17,10 +17,16 @@ TESTS = \ test-gtk-objects-test \ test-gtk-label \ test-gtk-shortcut \ - test-gtk-shortcut-python \ test-gtk-reorder \ test-gtk-submenu \ - test-gtk-parser-test \ + test-gtk-parser-test + +# The Python test only work on the system copy of +# dbusmenu, so while they can be usefule they're not +# good tests of what you're currently building. Handy +# to check GI support though. FIXME! +PYTHON_TESTS = \ + test-gtk-shortcut-python \ test-glib-simple-items.py check_PROGRAMS = \ -- cgit v1.2.3 From 3ea5943b251a97096da2f191c9706b18d346464e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 10:51:04 -0600 Subject: Ignoring a bunch of files that are annoying --- .bzrignore | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.bzrignore b/.bzrignore index 837b948..ea8b315 100644 --- a/.bzrignore +++ b/.bzrignore @@ -232,3 +232,25 @@ enum-types.c enum-types.h libdbusmenu_glib_la-enum-types.lo stamp-enum-types +libdbusmenu-0.3.100 +docs/libdbusmenu-glib/reference/gtkdoc-in-srcdir +docs/libdbusmenu-glib/reference/html/api-index-deprecated.html +docs/libdbusmenu-glib/reference/html/libdbusmenu-glib-Types.html +docs/libdbusmenu-glib/reference/tmpl/types.sgml +docs/libdbusmenu-gtk/reference/gtkdoc-in-srcdir +docs/libdbusmenu-gtk/reference/html/annotation-glossary.html +docs/libdbusmenu-gtk/reference/html/api-index-deprecated.html +docs/libdbusmenu-gtk/reference/html/libdbusmenu-gtk-DbusmenuGtkSerializableMenuItem.html +docs/libdbusmenu-gtk/reference/html/libdbusmenu-gtk-parser.html +docs/libdbusmenu-gtk/reference/tmpl/parser.sgml +docs/libdbusmenu-gtk/reference/tmpl/parser.sgml.bak +docs/libdbusmenu-gtk/reference/tmpl/serializablemenuitem.sgml.bak +libdbusmenu-glib/Dbusmenu-0.4.gir +libdbusmenu-glib/Dbusmenu-0.4.typelib +libdbusmenu-glib/Dbusmenu-0.4.vapi +po/libdbusmenu.pot +tests/test-gtk-shortcut-python +tests/test-gtk-submenu +tests/test-gtk-submenu-client +tests/test-gtk-submenu-server +tests/test-json-01.output.json -- cgit v1.2.3 From 5df1c8111987669e7f450141b50f056dc30cb4f9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 10 Mar 2011 10:52:05 -0600 Subject: 0.3.101 --- configure.ac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 98f7cc7..8cfa421 100644 --- a/configure.ac +++ b/configure.ac @@ -1,11 +1,11 @@ -AC_INIT(libdbusmenu, 0.3.100, ted@canonical.com) +AC_INIT(libdbusmenu, 0.3.101, ted@canonical.com) AC_COPYRIGHT([Copyright 2009,2010 Canonical]) AC_PREREQ(2.62) AM_CONFIG_HEADER(config.h) -AM_INIT_AUTOMAKE(libdbusmenu, 0.3.100, [-Wno-portability]) +AM_INIT_AUTOMAKE(libdbusmenu, 0.3.101, [-Wno-portability]) AM_MAINTAINER_MODE @@ -134,7 +134,7 @@ AC_PATH_PROG([XSLT_PROC], [xsltproc]) ########################### LIBDBUSMENU_CURRENT=3 -LIBDBUSMENU_REVISION=8 +LIBDBUSMENU_REVISION=9 LIBDBUSMENU_AGE=0 AC_SUBST(LIBDBUSMENU_CURRENT) -- cgit v1.2.3