From 93650be784700d574f25eb28114784d88d767ced Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 24 Nov 2009 10:04:28 -0600 Subject: Adding a small little tool to load an indicator from the command line. --- tools/indicator-loader.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tools/indicator-loader.c (limited to 'tools/indicator-loader.c') diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c new file mode 100644 index 0000000..7963656 --- /dev/null +++ b/tools/indicator-loader.c @@ -0,0 +1,74 @@ + +#include +#include + +static void +entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) +{ + g_debug("Signal: Entry Added"); + return; +} + +static void +entry_removed (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data) +{ + g_debug("Signal: Entry Removed"); + return; +} + +static gboolean +load_module (const gchar * name, GtkWidget * menu) +{ + g_debug("Looking at Module: %s", name); + g_return_val_if_fail(name != NULL, FALSE); + + if (!g_str_has_suffix(name, G_MODULE_SUFFIX)) { + return FALSE; + } + + g_debug("Loading Module: %s", name); + + /* Build the object for the module */ + IndicatorObject * io = indicator_object_new_from_file(name); + + /* 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); + + /* Work on the entries */ + GList * entries = indicator_object_get_entries(io); + GList * entry = NULL; + + for (entry = entries; entry != NULL; entry = g_list_next(entry)) { + IndicatorObjectEntry * entrydata = (IndicatorObjectEntry *)entry->data; + entry_added(io, entrydata, menu); + } + + g_list_free(entries); + + return TRUE; +} + +int +main (int argc, char ** argv) +{ + gtk_init(&argc, &argv); + + 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); + gtk_container_add(GTK_CONTAINER(window), menubar); + + gtk_main(); + + return 0; +} -- cgit v1.2.3