From cc19423ef4f8d060d7dfa7ab7eb0655e67be3efa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 30 Jun 2009 15:51:10 -0500 Subject: Trying to flesh out the add function some more, but this commit doesn't build as apparently switches have to have integers now. This takes half of the fun out of C if you can't use crazy function pointers everywhere! Where's the sport in readable code? --- src/indicator-sus.c | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/indicator-sus.c b/src/indicator-sus.c index 4e7d4b2..9368300 100644 --- a/src/indicator-sus.c +++ b/src/indicator-sus.c @@ -30,6 +30,7 @@ GtkLabel * get_label (void) { GtkLabel * returnval = GTK_LABEL(gtk_label_new("Ted Gould")); + gtk_widget_show(GTK_WIDGET(returnval)); return returnval; } @@ -40,29 +41,45 @@ get_icon (void) } static void -menu_add (GtkContainer * source, GtkWidget * addee, GtkMenu * addto, guint positionoffset) +child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, guint (*posfunc) (void)) { - GList * location = g_list_find(GTK_MENU_SHELL(source)->children, addee); - guint position = g_list_position(GTK_MENU_SHELL(source)->children, location); + position += posfunc(); + + DbusmenuGtkClient * client = NULL; + gchar * errorstr = NULL; + switch (posfunc) { + case status_menu_pos_offset: + client = status_client; + errorstr = "Status"; + break; + case users_menu_pos_offset: + client = users_client; + errorstr = "Users"; + break; + case session_menu_pos_offset: + client = session_client; + errorstr = "Session"; + break; + default: + g_warning("Child Added called with an unknown position function!"); + return; + } + + GtkMenuItem * widget = dbusmenu_gtkclient_menuitem_get(client, child); - position += positionoffset; - g_debug("Adding a widget: %d", position); + if (widget == NULL) { + g_warning("Had a menu item added to the %s menu, but yet it didn't have a GtkWidget with it. Can't add that to a menu now can we? You need to figure this @#$# out!", errorstr); + return; + } - gtk_menu_insert(addto, addee, position); - gtk_widget_show(addee); + gtk_menu_insert(main_menu, GTK_WIDGET(widget), position); + gtk_widget_show(GTK_WIDGET(widget)); gtk_widget_hide(loading_item); return; } -static void -child_added (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint position, guint (*posfunc) (void)) -{ - menu_add(NULL, NULL, NULL, 0); - -} - static void child_moved (DbusmenuMenuitem * parent, DbusmenuMenuitem * child, guint newpos, guint oldpos, guint (*posfunc) (void)) { -- cgit v1.2.3