From 083af7d38b02485ff47a40c0e5d515837c0de831 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 23:46:11 -0500 Subject: in indicator-loader, show =all= the profiles --- tools/indicator-loader.c | 426 +++++++++++++++++++++++++++-------------------- 1 file changed, 247 insertions(+), 179 deletions(-) diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index ff3a71b..833e8ea 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -1,248 +1,316 @@ /* -A small test loader for loading indicators in test suites -and during development of them. - -Copyright 2009 Canonical Ltd. - -Authors: - Ted Gould - -This library is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -version 3.0 as published by the Free Software Foundation. - -This library 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 version 3.0 for more details. - -You should have received a copy of the GNU General Public -License along with this library. If not, see -. -*/ - + * A small test loader for loading indicators in test suites + * and during development of them. + * + * Copyright 2009 Canonical Ltd. + * + * Authors: + * Ted Gould + * Lars Uebernickel + * Charles Kerr + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 3.0 as published by the Free Software Foundation. + * + * This library 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 version 3.0 for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library. If not, see + * . + */ #include -#include #include - +#include #if GTK_MAJOR_VERSION == 3 -#include + #include #endif -static gchar * profile = "desktop"; -static gchar * title = NULL; +static GHashTable * entry_to_menu_item = NULL; -static GOptionEntry entries[] = -{ - { "profile", 'p', 0, G_OPTION_ARG_STRING, &profile, "Profile [default: 'desktop']", NULL }, - { NULL } -}; - -static GHashTable * entry_to_menuitem = NULL; - -#define ENTRY_DATA_NAME "indicator-custom-entry-data" +G_DEFINE_QUARK (indicator_loader, entry_data) static void activate_entry (GtkWidget * widget, gpointer user_data) { - g_return_if_fail(INDICATOR_IS_OBJECT(user_data)); - gpointer entry = g_object_get_data(G_OBJECT(widget), ENTRY_DATA_NAME); - if (entry == NULL) { - g_debug("Activation on: (null)"); - } - - indicator_object_entry_activate(INDICATOR_OBJECT(user_data), (IndicatorObjectEntry *)entry, gtk_get_current_event_time()); - return; + gpointer entry; + + g_return_if_fail (INDICATOR_IS_OBJECT(user_data)); + + entry = g_object_get_qdata (G_OBJECT(widget), entry_data_quark()); + + if (entry == NULL) + { + g_debug("Activation on: (null)"); + } + else + { + indicator_object_entry_activate (INDICATOR_OBJECT(user_data), + entry, + gtk_get_current_event_time()); + } } static GtkWidget* create_menu_item (IndicatorObjectEntry * entry) { - GtkWidget * hbox; - GtkWidget * menuitem; + GtkWidget * menu_item; + GtkWidget * hbox; - menuitem = gtk_menu_item_new(); + menu_item = gtk_menu_item_new(); -#if GTK_CHECK_VERSION(3,0,0) - hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3); +#if GTK_CHECK_VERSION (3,0,0) + hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); #else - hbox = gtk_hbox_new(FALSE, 3); + hbox = gtk_hbox_new (FALSE, 3); #endif - if (entry->image != NULL) { - gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0); - } - if (entry->label != NULL) { - gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0); - } - gtk_container_add(GTK_CONTAINER(menuitem), hbox); - gtk_widget_show(hbox); + if (entry->image != NULL) + gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0); + if (entry->label != NULL) + gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0); + + gtk_container_add (GTK_CONTAINER(menu_item), hbox); + gtk_widget_show (hbox); - if (entry->menu != NULL) { - gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu)); - } + if (entry->menu != NULL) + gtk_menu_item_set_submenu (GTK_MENU_ITEM(menu_item), GTK_WIDGET(entry->menu)); - return menuitem; + return menu_item; } static void entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) { - GtkWidget * menuitem; + GtkWidget * menu_item; - g_debug("Signal: Entry Added"); + g_debug ("Signal: Entry Added"); - if (entry->parent_object == NULL) { - g_warning("Entry '%p' does not have a parent object", entry); - } + if (entry->parent_object == NULL) + { + g_warning("Entry '%p' does not have a parent object", entry); + } - 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); + menu_item = g_hash_table_lookup (entry_to_menu_item, entry); - g_object_set_data(G_OBJECT(menuitem), ENTRY_DATA_NAME, entry); - g_signal_connect (G_OBJECT(menuitem), "activate", G_CALLBACK(activate_entry), io); + if (menu_item == NULL) + { + g_debug ("This is the first time this entry's been added -- creating a new menuitem for it"); + menu_item = create_menu_item (entry); + g_hash_table_insert (entry_to_menu_item, entry, menu_item); - gtk_menu_shell_append (GTK_MENU_SHELL(user_data), menuitem); + g_object_set_qdata (G_OBJECT(menu_item), entry_data_quark(), entry); + g_signal_connect (G_OBJECT(menu_item), "activate", G_CALLBACK(activate_entry), io); - } - gtk_widget_show (menuitem); + gtk_menu_shell_append (GTK_MENU_SHELL(user_data), menu_item); + } - return; + gtk_widget_show (menu_item); } static void entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) { - g_debug("Signal: Entry Removed"); + g_debug("Signal: Entry Removed"); - GtkWidget * menuitem = g_hash_table_lookup (entry_to_menuitem, entry); - if (menuitem != NULL) - gtk_widget_hide (menuitem); - - return; + GtkWidget * menuitem = g_hash_table_lookup (entry_to_menu_item, entry); + if (menuitem != NULL) + gtk_widget_hide (menuitem); } static void menu_show (IndicatorObject * io, IndicatorObjectEntry * entry, guint timestamp, gpointer user_data) { - if (entry != NULL) { - g_debug("Show Menu: %s", entry->label != NULL ? gtk_label_get_text(entry->label) : "No Label"); - } else { - g_debug("Show Menu: (null)"); - } - return; + if (entry == NULL) + g_debug("Show Menu: (null)"); + else + g_debug("Show Menu: %s", entry->label != NULL ? gtk_label_get_text(entry->label) : "No Label"); } -static gboolean -load_module (const gchar * name, GtkWidget * menu) +/*** +**** +***/ + +static IndicatorObject * +load_module (const gchar * file_name) { - g_debug("Looking at Module: %s", name); - g_return_val_if_fail(name != NULL, FALSE); + IndicatorObject * io = NULL; - g_debug("Loading Module: %s", name); + if (file_name && g_str_has_suffix (file_name, G_MODULE_SUFFIX)) + { + io = indicator_object_new_from_file (file_name); + + if (io == NULL) + g_warning ("could not load indicator from '%s'", file_name); + } + + return io; +} + +static IndicatorObject * +load_profile (const char * file_name, const char * profile) +{ + IndicatorObject * io = NULL; - /* Build the object for the module */ - IndicatorObject *io; - if (g_str_has_suffix(name, G_MODULE_SUFFIX)) { - io = indicator_object_new_from_file(name); - } #if GTK_MAJOR_VERSION == 3 - else { - GError *error = NULL; - - io = INDICATOR_OBJECT (indicator_ng_new_for_profile (name, profile, &error)); - if (!io) { - g_warning ("could not load indicator from '%s': %s", name, error->message); - g_error_free (error); - return FALSE; - } - - title = g_strdup_printf ("%s %s", profile, name); - } -#else - else - return FALSE; + + GError * error = NULL; + + io = INDICATOR_OBJECT (indicator_ng_new_for_profile (file_name, profile, &error)); + if (error != NULL) + { + g_warning ("could not load indicator from '%s': %s", file_name, error->message); + g_error_free (error); + } + #endif - /* Connect to it's signals */ - g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menu); - g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menu); - g_signal_connect(G_OBJECT(io), INDICATOR_OBJECT_SIGNAL_MENU_SHOW, G_CALLBACK(menu_show), NULL); + return io; +} + +/*** +**** +***/ - /* Work on the entries */ - GList * entries = indicator_object_get_entries(io); - GList * entry = NULL; +static void +add_indicator_to_menu (GtkMenuShell * menu_shell, IndicatorObject * io) +{ + GList * entries; + GList * entry; - for (entry = entries; entry != NULL; entry = g_list_next(entry)) { - IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data; - entry_added(io, entrydata, menu); - } + g_return_if_fail (INDICATOR_IS_OBJECT (io)); - g_list_free(entries); + /* connect to its signals */ + g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menu_shell); + g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menu_shell); + g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_MENU_SHOW, G_CALLBACK(menu_show), NULL); - return TRUE; + /* process the entries */ + entries = indicator_object_get_entries(io); + for (entry=entries; entry!=NULL; entry=entry->next) + entry_added (io, entry->data, menu_shell); + g_list_free (entries); } static void -destroy (gpointer data) +add_menu_to_grid (GtkGrid * grid, int top, const char * text_, GtkWidget * menu) { - gtk_main_quit(); - return; + gchar * text; + GtkWidget * label; + + text = g_strdup_printf ("%s:", text_); + label = gtk_label_new (text); + g_free (text); + + gtk_grid_attach (GTK_GRID(grid), label, 0, top, 1, 1); + gtk_grid_attach (GTK_GRID(grid), menu, 1, top, 1, 1); + + g_object_set (label, "halign", GTK_ALIGN_START, + "hexpand", FALSE, + "margin-right", 6, + "valign", GTK_ALIGN_CENTER, + NULL); + + g_object_set (menu, "halign", GTK_ALIGN_START, + "hexpand", TRUE, + NULL); } +/*** +**** +***/ + int main (int argc, char ** argv) { - /* Parse the command line options */ - GError * error = NULL; - GOptionContext * context; - context = g_option_context_new ("/path/to/file.indicator"); - g_option_context_add_main_entries (context, entries, NULL); - g_option_context_add_group (context, gtk_get_option_group (TRUE)); - if (!g_option_context_parse (context, &argc, &argv, &error)) { - g_print ("option parsing failed: %s\n", error->message); - g_error_free (error); - return 1; - } - - /* Make sure we don't proxy to ourselves */ - g_unsetenv("UBUNTU_MENUPROXY"); - - gtk_init(&argc, &argv); - ido_init (); - - entry_to_menuitem = g_hash_table_new (g_direct_hash, g_direct_equal); - - if (argc != 2) { - g_error("Need filename"); - return 1; - } - - GtkWidget * menubar = gtk_menu_bar_new(); - if (!load_module(argv[1], menubar)) { - g_error("Unable to load module"); - return 1; - } - - GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - if (title != NULL) - gtk_window_set_title (GTK_WINDOW(window), title); - g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); - - gtk_container_add(GTK_CONTAINER(window), menubar); - - gtk_widget_show(menubar); - gtk_widget_show(window); - - gtk_main(); - - /* cleanup */ - g_hash_table_destroy (entry_to_menuitem); - g_free (title); - g_option_context_free (context); - return 0; + const gchar * file_name; + gchar * base_name; + GtkWidget * window; + GtkWidget * grid; + + /* make sure we don't proxy to ourselves */ + g_unsetenv ("UBUNTU_MENUPROXY"); + + gtk_init (&argc, &argv); + ido_init (); + + entry_to_menu_item = g_hash_table_new (g_direct_hash, g_direct_equal); + if (argc != 2) + { + base_name = g_path_get_basename (argv[0]); + g_warning ("Use: %s filename", base_name); + g_free (base_name); + return 0; + } + + file_name = argv[1]; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + base_name = g_path_get_basename (file_name); + gtk_window_set_title (GTK_WINDOW(window), base_name); + g_free (base_name); + g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL); + grid = g_object_new (GTK_TYPE_GRID, "margin", 4, + "column-spacing", 6, + "row-spacing", 12, + NULL); + gtk_container_add (GTK_CONTAINER(window), grid); + + /* if it's an old-style indicator... */ + if (g_str_has_suffix (file_name, G_MODULE_SUFFIX)) + { + IndicatorObject * io = load_module (file_name); + GtkWidget * menu = gtk_menu_bar_new (); + add_indicator_to_menu (GTK_MENU_SHELL(menu), io); + base_name = g_path_get_basename (file_name); + add_menu_to_grid (GTK_GRID(grid), 0, base_name, menu); + g_free (base_name); + } + else /* treat it as a GMenu indicator's keyfile */ + { + GError * error; + GKeyFile * key_file; + gchar ** groups; + int i; + int menu_count = 0; + + key_file = g_key_file_new (); + error = NULL; + g_key_file_load_from_file (key_file, file_name, G_KEY_FILE_NONE, &error); + if (error != NULL) + { + g_warning ("parsing '%s' failed: %s", file_name, error->message); + g_error_free (error); + return 1; + } + + groups = g_key_file_get_groups (key_file, NULL); + for (i=0; groups && groups[i]; i++) + { + const gchar * const profile = groups[i]; + IndicatorObject * io; + + if (!g_strcmp0 (profile, "Indicator Service")) + continue; + + io = load_profile (file_name, profile); + if (io != NULL) + { + GtkWidget * menu = gtk_menu_bar_new (); + add_indicator_to_menu (GTK_MENU_SHELL(menu), io); + add_menu_to_grid (GTK_GRID(grid), menu_count++, profile, menu); + } + } + } + + gtk_widget_show_all (window); + gtk_main (); + + /* cleanup */ + g_hash_table_destroy (entry_to_menu_item); + return 0; } -- cgit v1.2.3 From 7f619929c6dc8f4a08810fad2dacf8f9b4e56da9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 25 Jul 2013 23:56:05 -0500 Subject: plug a keyfile leak --- tools/indicator-loader.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index 833e8ea..4995420 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -305,6 +305,9 @@ main (int argc, char ** argv) add_menu_to_grid (GTK_GRID(grid), menu_count++, profile, menu); } } + + g_strfreev (groups); + g_key_file_free (key_file); } gtk_widget_show_all (window); -- cgit v1.2.3 From 5acc284da4dd662812e69b33704743d12959c9f5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 26 Jul 2013 01:28:09 -0500 Subject: copyediting: fix linewraps --- tools/indicator-loader.c | 68 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index 4995420..a9e63a9 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -60,6 +60,7 @@ create_menu_item (IndicatorObjectEntry * entry) { GtkWidget * menu_item; GtkWidget * hbox; + gpointer w; menu_item = gtk_menu_item_new(); @@ -69,22 +70,24 @@ create_menu_item (IndicatorObjectEntry * entry) hbox = gtk_hbox_new (FALSE, 3); #endif - if (entry->image != NULL) - gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET(entry->image), FALSE, FALSE, 0); - if (entry->label != NULL) - gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET(entry->label), FALSE, FALSE, 0); + if ((w = entry->image)) + gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET(w), FALSE, FALSE, 0); + if ((w = entry->label)) + gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET(w), FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER(menu_item), hbox); gtk_widget_show (hbox); - if (entry->menu != NULL) - gtk_menu_item_set_submenu (GTK_MENU_ITEM(menu_item), GTK_WIDGET(entry->menu)); + if ((w = entry->menu)) + gtk_menu_item_set_submenu (GTK_MENU_ITEM(menu_item), GTK_WIDGET(w)); return menu_item; } static void -entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) +entry_added (IndicatorObject * io, + IndicatorObjectEntry * entry, + gpointer user_data) { GtkWidget * menu_item; @@ -99,12 +102,12 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d if (menu_item == NULL) { - g_debug ("This is the first time this entry's been added -- creating a new menuitem for it"); + g_debug ("creating a menuitem for new entry %p", entry); menu_item = create_menu_item (entry); g_hash_table_insert (entry_to_menu_item, entry, menu_item); g_object_set_qdata (G_OBJECT(menu_item), entry_data_quark(), entry); - g_signal_connect (G_OBJECT(menu_item), "activate", G_CALLBACK(activate_entry), io); + g_signal_connect (menu_item, "activate", G_CALLBACK(activate_entry), io); gtk_menu_shell_append (GTK_MENU_SHELL(user_data), menu_item); } @@ -113,9 +116,11 @@ entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_d } static void -entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) +entry_removed (IndicatorObject * io, + IndicatorObjectEntry * entry, + gpointer user_data) { - g_debug("Signal: Entry Removed"); + g_debug ("Signal: Entry Removed"); GtkWidget * menuitem = g_hash_table_lookup (entry_to_menu_item, entry); if (menuitem != NULL) @@ -123,12 +128,21 @@ entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user } static void -menu_show (IndicatorObject * io, IndicatorObjectEntry * entry, guint timestamp, gpointer user_data) +menu_show (IndicatorObject * io, + IndicatorObjectEntry * entry, + guint timestamp, + gpointer user_data) { + const char * text; + if (entry == NULL) - g_debug("Show Menu: (null)"); + text = "(null)"; + else if (entry->label == NULL) + text = "(no label)"; else - g_debug("Show Menu: %s", entry->label != NULL ? gtk_label_get_text(entry->label) : "No Label"); + text = gtk_label_get_text (entry->label); + + g_debug ("Show Menu: %s", text); } /*** @@ -160,10 +174,13 @@ load_profile (const char * file_name, const char * profile) GError * error = NULL; - io = INDICATOR_OBJECT (indicator_ng_new_for_profile (file_name, profile, &error)); + io = INDICATOR_OBJECT (indicator_ng_new_for_profile (file_name, + profile, + &error)); if (error != NULL) { - g_warning ("could not load indicator from '%s': %s", file_name, error->message); + g_warning ("couldn't load profile '%s' from '%s': %s", + profile, file_name, error->message); g_error_free (error); } @@ -185,9 +202,12 @@ add_indicator_to_menu (GtkMenuShell * menu_shell, IndicatorObject * io) g_return_if_fail (INDICATOR_IS_OBJECT (io)); /* connect to its signals */ - g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, G_CALLBACK(entry_added), menu_shell); - g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, G_CALLBACK(entry_removed), menu_shell); - g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_MENU_SHOW, G_CALLBACK(menu_show), NULL); + g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_ENTRY_ADDED, + G_CALLBACK(entry_added), menu_shell); + g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_ENTRY_REMOVED, + G_CALLBACK(entry_removed), menu_shell); + g_signal_connect (io, INDICATOR_OBJECT_SIGNAL_MENU_SHOW, + G_CALLBACK(menu_show), NULL); /* process the entries */ entries = indicator_object_get_entries(io); @@ -197,7 +217,10 @@ add_indicator_to_menu (GtkMenuShell * menu_shell, IndicatorObject * io) } static void -add_menu_to_grid (GtkGrid * grid, int top, const char * text_, GtkWidget * menu) +add_menu_to_grid (GtkGrid * grid, + int top, + const char * text_, + GtkWidget * menu) { gchar * text; GtkWidget * label; @@ -238,7 +261,6 @@ main (int argc, char ** argv) gtk_init (&argc, &argv); ido_init (); - entry_to_menu_item = g_hash_table_new (g_direct_hash, g_direct_equal); if (argc != 2) { base_name = g_path_get_basename (argv[0]); @@ -247,6 +269,8 @@ main (int argc, char ** argv) return 0; } + entry_to_menu_item = g_hash_table_new (g_direct_hash, g_direct_equal); + file_name = argv[1]; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); @@ -283,7 +307,7 @@ main (int argc, char ** argv) g_key_file_load_from_file (key_file, file_name, G_KEY_FILE_NONE, &error); if (error != NULL) { - g_warning ("parsing '%s' failed: %s", file_name, error->message); + g_warning ("loading '%s' failed: %s", file_name, error->message); g_error_free (error); return 1; } -- cgit v1.2.3 From f842a8080f56f43e28249d033aece4aed2685504 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 26 Jul 2013 01:58:55 -0500 Subject: more copyediting. why am I awake? --- tools/indicator-loader.c | 96 ++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index a9e63a9..f04132e 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -26,7 +26,7 @@ #include #include #include -#if GTK_MAJOR_VERSION == 3 +#if GTK_CHECK_VERSION (3,0,0) #include #endif @@ -71,9 +71,9 @@ create_menu_item (IndicatorObjectEntry * entry) #endif if ((w = entry->image)) - gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET(w), FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET(w), FALSE, FALSE, 0); if ((w = entry->label)) - gtk_box_pack_start(GTK_BOX (hbox), GTK_WIDGET(w), FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET(w), FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER(menu_item), hbox); gtk_widget_show (hbox); @@ -93,10 +93,7 @@ entry_added (IndicatorObject * io, g_debug ("Signal: Entry Added"); - if (entry->parent_object == NULL) - { - g_warning("Entry '%p' does not have a parent object", entry); - } + g_warn_if_fail (entry->parent_object != NULL); menu_item = g_hash_table_lookup (entry_to_menu_item, entry); @@ -120,11 +117,12 @@ entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) { + GtkWidget * w; + g_debug ("Signal: Entry Removed"); - GtkWidget * menuitem = g_hash_table_lookup (entry_to_menu_item, entry); - if (menuitem != NULL) - gtk_widget_hide (menuitem); + if ((w = g_hash_table_lookup (entry_to_menu_item, entry))) + gtk_widget_hide (w); } static void @@ -170,7 +168,7 @@ load_profile (const char * file_name, const char * profile) { IndicatorObject * io = NULL; -#if GTK_MAJOR_VERSION == 3 +#if GTK_CHECK_VERSION (3,0,0) GError * error = NULL; @@ -239,8 +237,8 @@ add_menu_to_grid (GtkGrid * grid, NULL); g_object_set (menu, "halign", GTK_ALIGN_START, - "hexpand", TRUE, - NULL); + "hexpand", TRUE, + NULL); } /*** @@ -250,17 +248,11 @@ add_menu_to_grid (GtkGrid * grid, int main (int argc, char ** argv) { + int menu_count = 0; const gchar * file_name; gchar * base_name; - GtkWidget * window; GtkWidget * grid; - /* make sure we don't proxy to ourselves */ - g_unsetenv ("UBUNTU_MENUPROXY"); - - gtk_init (&argc, &argv); - ido_init (); - if (argc != 2) { base_name = g_path_get_basename (argv[0]); @@ -269,20 +261,20 @@ main (int argc, char ** argv) return 0; } + /* make sure we don't proxy to ourselves */ + g_unsetenv ("UBUNTU_MENUPROXY"); + + gtk_init (&argc, &argv); + ido_init (); + entry_to_menu_item = g_hash_table_new (g_direct_hash, g_direct_equal); file_name = argv[1]; - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - base_name = g_path_get_basename (file_name); - gtk_window_set_title (GTK_WINDOW(window), base_name); - g_free (base_name); - g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL); grid = g_object_new (GTK_TYPE_GRID, "margin", 4, "column-spacing", 6, "row-spacing", 12, NULL); - gtk_container_add (GTK_CONTAINER(window), grid); /* if it's an old-style indicator... */ if (g_str_has_suffix (file_name, G_MODULE_SUFFIX)) @@ -291,16 +283,13 @@ main (int argc, char ** argv) GtkWidget * menu = gtk_menu_bar_new (); add_indicator_to_menu (GTK_MENU_SHELL(menu), io); base_name = g_path_get_basename (file_name); - add_menu_to_grid (GTK_GRID(grid), 0, base_name, menu); + add_menu_to_grid (GTK_GRID(grid), menu_count++, base_name, menu); g_free (base_name); } else /* treat it as a GMenu indicator's keyfile */ { GError * error; GKeyFile * key_file; - gchar ** groups; - int i; - int menu_count = 0; key_file = g_key_file_new (); error = NULL; @@ -309,33 +298,46 @@ main (int argc, char ** argv) { g_warning ("loading '%s' failed: %s", file_name, error->message); g_error_free (error); - return 1; } - - groups = g_key_file_get_groups (key_file, NULL); - for (i=0; groups && groups[i]; i++) + else { - const gchar * const profile = groups[i]; - IndicatorObject * io; + gchar ** groups; + int i; - if (!g_strcmp0 (profile, "Indicator Service")) - continue; - - io = load_profile (file_name, profile); - if (io != NULL) + groups = g_key_file_get_groups (key_file, NULL); + for (i=0; groups && groups[i]; i++) { - GtkWidget * menu = gtk_menu_bar_new (); - add_indicator_to_menu (GTK_MENU_SHELL(menu), io); - add_menu_to_grid (GTK_GRID(grid), menu_count++, profile, menu); + const gchar * const profile = groups[i]; + IndicatorObject * io; + + if (!g_strcmp0 (profile, "Indicator Service")) + continue; + + if ((io = load_profile (file_name, profile))) + { + GtkWidget * menu = gtk_menu_bar_new (); + add_indicator_to_menu (GTK_MENU_SHELL(menu), io); + add_menu_to_grid (GTK_GRID(grid), menu_count++, profile, menu); + } } + + g_strfreev (groups); } - g_strfreev (groups); g_key_file_free (key_file); } - gtk_widget_show_all (window); - gtk_main (); + if (menu_count > 0) + { + GtkWidget * window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + base_name = g_path_get_basename (file_name); + gtk_window_set_title (GTK_WINDOW(window), base_name); + g_free (base_name); + g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL); + gtk_container_add (GTK_CONTAINER(window), grid); + gtk_widget_show_all (window); + gtk_main (); + } /* cleanup */ g_hash_table_destroy (entry_to_menu_item); -- cgit v1.2.3 From e430061e28eafe90e423201b528265071815771b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 26 Jul 2013 12:32:08 -0500 Subject: explicitly set UBUNTU_MENUPROXY to 0 --- tools/indicator-loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index f04132e..153cca7 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -262,7 +262,7 @@ main (int argc, char ** argv) } /* make sure we don't proxy to ourselves */ - g_unsetenv ("UBUNTU_MENUPROXY"); + g_setenv ("UBUNTU_MENUPROXY", "0", TRUE); gtk_init (&argc, &argv); ido_init (); -- cgit v1.2.3