From 22d673c448edcd06734ff7c8197366747ad6504b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 22 Mar 2013 11:15:11 -0500 Subject: add the option to specify the profile from the command line --- tools/indicator-loader.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index d275c43..ccc60ea 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -29,6 +29,15 @@ License along with this library. If not, see #include #endif +static gchar * profile = "desktop"; +static gchar * title = 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" @@ -144,12 +153,14 @@ load_module (const gchar * name, GtkWidget * menu) else if (g_str_has_suffix(name, ".indicator")) { GError *error = NULL; - io = INDICATOR_OBJECT(indicator_ng_new(name, &error)); + 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); } #endif else @@ -184,6 +195,18 @@ destroy (gpointer data) int main (int argc, char ** argv) { + /* Parse the command line options */ + GError * error; + 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"); @@ -203,6 +226,8 @@ main (int argc, char ** argv) } 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); @@ -212,6 +237,9 @@ main (int argc, char ** argv) gtk_main(); + /* cleanup */ g_hash_table_destroy (entry_to_menuitem); + g_free (title); + g_option_context_free (context); return 0; } -- cgit v1.2.3 From 98cae790d2d583d55d682d92c3ee03b768c05257 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 22 Mar 2013 11:18:53 -0500 Subject: introduce tab damage for consistency with the rest of indicator-loader.c --- tools/indicator-loader.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c index ccc60ea..5d889bf 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -33,10 +33,10 @@ static gchar * profile = "desktop"; static gchar * title = NULL; static GOptionEntry entries[] = -{ +{ { "profile", 'p', 0, G_OPTION_ARG_STRING, &profile, "Profile [default: 'desktop']", NULL }, { NULL } -}; +}; static GHashTable * entry_to_menuitem = NULL; @@ -237,9 +237,9 @@ main (int argc, char ** argv) gtk_main(); - /* cleanup */ + /* cleanup */ g_hash_table_destroy (entry_to_menuitem); - g_free (title); - g_option_context_free (context); + g_free (title); + g_option_context_free (context); return 0; } -- cgit v1.2.3 From f25cc3399d89cc58a032ed2dffee2125c1962f6e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 22 Mar 2013 14:57:55 -0500 Subject: init the GError pointer to NULL --- 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 5d889bf..5659dea 100644 --- a/tools/indicator-loader.c +++ b/tools/indicator-loader.c @@ -196,7 +196,7 @@ int main (int argc, char ** argv) { /* Parse the command line options */ - GError * error; + GError * error = NULL; GOptionContext * context; context = g_option_context_new ("/path/to/file.indicator"); g_option_context_add_main_entries (context, entries, NULL); -- cgit v1.2.3