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(+) (limited to 'libdbusmenu-gtk/client.c') 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