From e6a8b5ceaa942985c67663da288a68346fea8a38 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 12:05:07 -0500 Subject: Putting in a sorting function to make sure that the individual indicators are always below the server that they're associated with. --- src/app-menu-item.c | 6 ++++++ src/app-menu-item.h | 1 + src/indicator-messages.c | 44 +++++++++++++++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 1ab2ba8..d6d3e4a 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -267,3 +267,9 @@ app_menu_item_get_count (AppMenuItem * appitem) return priv->unreadcount; } +IndicateListenerServer * +app_menu_item_get_server (AppMenuItem * appitem) { + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); + + return priv->server; +} diff --git a/src/app-menu-item.h b/src/app-menu-item.h index 3a9a4e5..5e012e7 100644 --- a/src/app-menu-item.h +++ b/src/app-menu-item.h @@ -54,6 +54,7 @@ struct _AppMenuItem { GType app_menu_item_get_type (void); AppMenuItem * app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server); guint app_menu_item_get_count (AppMenuItem * appitem); +IndicateListenerServer * app_menu_item_get_server (AppMenuItem * appitem); G_END_DECLS diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 9a4ce6f..0d20468 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -94,8 +94,8 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha g_hash_table_insert(serverHash, servername, menuitem); gtk_menu_shell_prepend(menushell, GTK_WIDGET(menuitem)); - gtk_widget_show(menuitem); - gtk_widget_show(main_menu); + gtk_widget_show(GTK_WIDGET(menuitem)); + gtk_widget_show(GTK_WIDGET(main_menu)); return; } @@ -119,7 +119,7 @@ server_count_changed (AppMenuItem * appitem, guint count, gpointer data) if (count != 0) { g_debug("Setting image to 'new'"); showing_new_icon = TRUE; - gtk_image_set_from_icon_name(main_image, "indicator-messages-new", DESIGN_TEAM_SIZE); + gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages-new", DESIGN_TEAM_SIZE); return; } @@ -140,7 +140,7 @@ server_count_changed (AppMenuItem * appitem, guint count, gpointer data) if (!we_have_indicators) { g_debug("Setting image to boring"); showing_new_icon = FALSE; - gtk_image_set_from_icon_name(main_image, "indicator-messages", DESIGN_TEAM_SIZE); + gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages", DESIGN_TEAM_SIZE); } return; @@ -175,6 +175,29 @@ server_removed (IndicateListener * listener, IndicateListenerServer * server, gc return; } +typedef struct _menushell_location menushell_location_t; +struct _menushell_location { + const IndicateListenerServer * server; + gint position; + gboolean found; +}; + +static void +menushell_foreach_cb (gpointer data_mi, gpointer data_ms) { + menushell_location_t * msl = (menushell_location_t *)data_ms; + + if (msl->found) return; + + msl->position++; + + AppMenuItem * appmenu = APP_MENU_ITEM(data_mi); + if (!g_strcmp0(INDICATE_LISTENER_SERVER_DBUS_NAME(msl->server), INDICATE_LISTENER_SERVER_DBUS_NAME(app_menu_item_get_server(appmenu)))) { + msl->found = TRUE; + } + + return; +} + static void subtype_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { @@ -213,7 +236,18 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica imList = g_list_append(imList, listItem); g_debug("Placing in Shell"); - gtk_menu_shell_prepend(menushell, GTK_WIDGET(menuitem)); + menushell_location_t msl; + msl.found = FALSE; + msl.position = 0; + msl.server = server; + + gtk_container_foreach(GTK_CONTAINER(menushell), menushell_foreach_cb, &msl); + if (msl.found) { + gtk_menu_shell_insert(menushell, GTK_WIDGET(menuitem), msl.position); + } else { + g_warning("Unable to find server menu item"); + gtk_menu_shell_append(menushell, GTK_WIDGET(menuitem)); + } } return; -- cgit v1.2.3