diff options
author | Charles Kerr <charles.kerr@canonical.com> | 2012-09-12 06:58:57 +0000 |
---|---|---|
committer | Tarmac <Unknown> | 2012-09-12 06:58:57 +0000 |
commit | 667fbafcfaf6c5368cf201ea7a435bc7ad5a4188 (patch) | |
tree | ec56a4f7aec66aac5f7ed70ca3c2079d0f74be88 /tools | |
parent | b1beb2ccbcc04f6615b75375821c51ef4828ee24 (diff) | |
parent | 00d05564fe963f53d8f56601f0b2dad2834b9b00 (diff) | |
download | libayatana-indicator-667fbafcfaf6c5368cf201ea7a435bc7ad5a4188.tar.gz libayatana-indicator-667fbafcfaf6c5368cf201ea7a435bc7ad5a4188.tar.bz2 libayatana-indicator-667fbafcfaf6c5368cf201ea7a435bc7ad5a4188.zip |
In libindicator, remove the cloak/decloak code in IndicatorObject to address Bug #1045372.
In indicator-loader, support hiding & re-showing IndicatorObjectEntries by caching their menuitems and using gtk_widget_hide / gtk_widget_show.
In tests/test-loader and tests/dummy-indicator-visible.c, support hiding & re-showing IndicatorObjectEntries by caching their parent widgetry instead of using gtk_widget_destroy().. Fixes: https://bugs.launchpad.net/bugs/1045372. Approved by Lars Uebernickel, jenkins.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/indicator-loader.c | 59 |
1 files changed, 36 insertions, 23 deletions
diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index 10952dc..560fc45 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -25,6 +25,8 @@ License along with this library. If not, see #include <gtk/gtk.h> #include <libindicator/indicator-object.h> +static GHashTable * entry_to_menuitem = NULL; + #define ENTRY_DATA_NAME "indicator-custom-entry-data" static void @@ -40,20 +42,18 @@ activate_entry (GtkWidget * widget, gpointer user_data) return; } -static void -entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) +static GtkWidget* +create_menu_item (IndicatorObjectEntry * entry) { - g_debug("Signal: Entry Added"); + GtkWidget * hbox; + GtkWidget * menuitem; - if (entry->parent_object == NULL) { - g_warning("Entry '%p' does not have a parent object", entry); - } + menuitem = gtk_menu_item_new(); - GtkWidget * menuitem = gtk_menu_item_new(); #if GTK_CHECK_VERSION(3,0,0) - GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3); + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3); #else - GtkWidget * hbox = gtk_hbox_new(FALSE, 3); + hbox = gtk_hbox_new(FALSE, 3); #endif if (entry->image != NULL) { @@ -69,26 +69,34 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu)); } - g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(activate_entry), io); - - gtk_menu_shell_append(GTK_MENU_SHELL(user_data), menuitem); - gtk_widget_show(menuitem); - - g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry); - - return; + return menuitem; } static void -entry_removed_cb (GtkWidget * widget, gpointer userdata) +entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) { - gpointer data = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME); + GtkWidget * menuitem; + + g_debug("Signal: Entry Added"); - if (data != userdata) { - return; + if (entry->parent_object == NULL) { + g_warning("Entry '%p' does not have a parent object", entry); } - gtk_widget_destroy(widget); + menuitem = g_hash_table_lookup (entry_to_menuitem, entry); + if (menuitem == NULL) { + g_debug ("This is the first time this entry's been added -- creating a new menuitem for it"); + menuitem = create_menu_item (entry); + g_hash_table_insert (entry_to_menuitem, entry, menuitem); + + g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry); + g_signal_connect (G_OBJECT(menuitem), "activate", G_CALLBACK(activate_entry), io); + + gtk_menu_shell_append (GTK_MENU_SHELL(user_data), menuitem); + + } + gtk_widget_show (menuitem); + return; } @@ -97,7 +105,9 @@ entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user { g_debug("Signal: Entry Removed"); - gtk_container_foreach(GTK_CONTAINER(user_data), entry_removed_cb, entry); + GtkWidget * menuitem = g_hash_table_lookup (entry_to_menuitem, entry); + if (menuitem != NULL) + gtk_widget_hide (menuitem); return; } @@ -162,6 +172,8 @@ main (int argc, char ** argv) gtk_init(&argc, &argv); + entry_to_menuitem = g_hash_table_new (g_direct_hash, g_direct_equal); + if (argc != 2) { g_error("Need filename"); return 1; @@ -183,5 +195,6 @@ main (int argc, char ** argv) gtk_main(); + g_hash_table_destroy (entry_to_menuitem); return 0; } |