aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.bzrignore1
-rw-r--r--debian/changelog6
-rw-r--r--tools/Makefile.am22
-rw-r--r--tools/indicator-loader.c106
4 files changed, 134 insertions, 1 deletions
diff --git a/.bzrignore b/.bzrignore
index 19ee10d..f11a31f 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -134,3 +134,4 @@ tests/service-manager-connect-service
tests/service-manager-connect-tester
tests/session.conf
tests/service-manager-connect.service
+tools/indicator-loader
diff --git a/debian/changelog b/debian/changelog
index 8a6a66b..bda1693 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+libindicator (0.3.0~dev-0ubuntu1~ppa6~tl1) UNRELEASED; urgency=low
+
+ * Adding a new tool to load indicators from the command line.
+
+ -- Ted Gould <ted@ubuntu.com> Tue, 24 Nov 2009 10:28:21 -0600
+
libindicator (0.3.0~dev-0ubuntu1~ppa5) karmic; urgency=low
* debian/control: Adding a depend for the -dev package on the
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 9de44fc..5e5ef8d 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1 +1,21 @@
-#Something
+
+libexec_PROGRAMS = \
+ indicator-loader
+
+#############################
+# Indicator Loader
+#############################
+
+indicator_loader_SOURCES = \
+ indicator-loader.c
+
+indicator_loader_CFLAGS = \
+ -Wall -Werror \
+ $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) \
+ -DBUILD_DIR="\"$(builddir)\""
+
+indicator_loader_LDADD = \
+ $(LIBINDICATOR_LIBS) \
+ -L$(top_builddir)/libindicator/.libs \
+ -lindicator
+
diff --git a/tools/indicator-loader.c b/tools/indicator-loader.c
new file mode 100644
index 0000000..feb0344
--- /dev/null
+++ b/tools/indicator-loader.c
@@ -0,0 +1,106 @@
+
+#include <gtk/gtk.h>
+#include <libindicator/indicator-object.h>
+
+static void
+entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data)
+{
+ g_debug("Signal: Entry Added");
+
+ GtkWidget * menuitem = gtk_menu_item_new();
+ GtkWidget * hbox = gtk_hbox_new(FALSE, 3);
+
+ 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->menu != NULL) {
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(entry->menu));
+ }
+
+ gtk_menu_shell_append(GTK_MENU_SHELL(user_data), menuitem);
+ gtk_widget_show(menuitem);
+
+ 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;
+}
+
+static void
+destroy (gpointer data)
+{
+ gtk_main_quit();
+ return;
+}
+
+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);
+ 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();
+
+ return 0;
+}