From c0d72443bea3c7dc3e612a17a58cc82178af0e78 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 26 May 2009 00:39:44 +0200 Subject: Moving the complex code into the service and leaving the rest for the loadable module. --- src/indicator-service.c | 507 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 507 insertions(+) create mode 100644 src/indicator-service.c (limited to 'src/indicator-service.c') diff --git a/src/indicator-service.c b/src/indicator-service.c new file mode 100644 index 0000000..b0aaffd --- /dev/null +++ b/src/indicator-service.c @@ -0,0 +1,507 @@ +/* +An indicator to show information that is in messaging applications +that the user is using. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include +#include +#include + +#include +INDICATOR_SET_VERSION +INDICATOR_SET_NAME("messages") + +#include "im-menu-item.h" +#include "app-menu-item.h" + +static IndicateListener * listener; +static GList * serverList; +static GtkWidget * main_image; + +static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); +static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data); +static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data); +static void reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell); +static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); + +#define DESIGN_TEAM_SIZE design_team_size +static GtkIconSize design_team_size; + +typedef struct _serverList_t serverList_t; +struct _serverList_t { + IndicateListenerServer * server; + AppMenuItem * menuitem; + GList * imList; +}; + +static gint +serverList_equal (gconstpointer a, gconstpointer b) +{ + serverList_t * pa, * pb; + + pa = (serverList_t *)a; + pb = (serverList_t *)b; + + const gchar * pas = INDICATE_LISTENER_SERVER_DBUS_NAME(pa->server); + const gchar * pbs = INDICATE_LISTENER_SERVER_DBUS_NAME(pb->server); + + return g_strcmp0(pas, pbs); +} + +static gint +serverList_sort (gconstpointer a, gconstpointer b) +{ + serverList_t * pa, * pb; + + pa = (serverList_t *)a; + pb = (serverList_t *)b; + + const gchar * pan = app_menu_item_get_name(pa->menuitem); + const gchar * pbn = app_menu_item_get_name(pb->menuitem); + + return g_strcmp0(pan, pbn); +} + +typedef struct _imList_t imList_t; +struct _imList_t { + IndicateListenerServer * server; + IndicateListenerIndicator * indicator; + GtkWidget * menuitem; + gulong timechange_cb; +}; + +static gboolean +imList_equal (gconstpointer a, gconstpointer b) +{ + imList_t * pa, * pb; + + pa = (imList_t *)a; + pb = (imList_t *)b; + + const gchar * pas = INDICATE_LISTENER_SERVER_DBUS_NAME(pa->server); + const gchar * pbs = INDICATE_LISTENER_SERVER_DBUS_NAME(pb->server); + + guint pai = INDICATE_LISTENER_INDICATOR_ID(pa->indicator); + guint pbi = INDICATE_LISTENER_INDICATOR_ID(pb->indicator); + + g_debug("\tComparing (%s %d) to (%s %d)", pas, pai, pbs, pbi); + + return !((!g_strcmp0(pas, pbs)) && (pai == pbi)); +} + +static gint +imList_sort (gconstpointer a, gconstpointer b) +{ + imList_t * pa, * pb; + + pa = (imList_t *)a; + pb = (imList_t *)b; + + return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem))); +} + +static void +server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Server Added '%s' of type '%s'.", INDICATE_LISTENER_SERVER_DBUS_NAME(server), type); + if (type == NULL) { + return; + } + + if (type[0] == '\0') { + return; + } + + if (strncmp(type, "message", strlen("message"))) { + g_debug("\tServer type '%s' is not a message based type.", type); + return; + } + + GtkMenuShell * menushell = GTK_MENU_SHELL(data); + if (menushell == NULL) { + g_error("\tData in callback is not a menushell"); + return; + } + + AppMenuItem * menuitem = app_menu_item_new(listener, server); + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_COUNT_CHANGED, G_CALLBACK(server_count_changed), NULL); + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_NAME_CHANGED, G_CALLBACK(server_name_changed), menushell); + + serverList_t * sl_item = g_new0(serverList_t, 1); + sl_item->server = server; + sl_item->menuitem = menuitem; + sl_item->imList = NULL; + + /* Incase we got an indicator first */ + GList * alreadythere = g_list_find_custom(serverList, sl_item, serverList_equal); + if (alreadythere != NULL) { + g_free(sl_item); + sl_item = (serverList_t *)alreadythere->data; + sl_item->menuitem = menuitem; + serverList = g_list_sort(serverList, serverList_sort); + } else { + serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); + } + + gtk_menu_shell_prepend(menushell, GTK_WIDGET(menuitem)); + gtk_widget_show(GTK_WIDGET(menuitem)); + gtk_widget_show(GTK_WIDGET(main_image)); + + reconsile_list_and_menu(serverList, menushell); + + return; +} + +static void +server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data) +{ + serverList = g_list_sort(serverList, serverList_sort); + reconsile_list_and_menu(serverList, GTK_MENU_SHELL(data)); + return; +} + +static void +server_count_changed (AppMenuItem * appitem, guint count, gpointer data) +{ + static gboolean showing_new_icon = FALSE; + + /* Quick check for a common case */ + if (count != 0 && showing_new_icon) { + return; + } + + /* Odd that we'd get a signal in this case, but let's + take it out of the mix too */ + if (count == 0 && !showing_new_icon) { + return; + } + + if (count != 0) { + g_debug("Setting image to 'new'"); + showing_new_icon = TRUE; + gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages-new", DESIGN_TEAM_SIZE); + return; + } + + /* Okay, now at this point the count is zero and it + might result in a switching of the icon back to being + the plain one. Let's check. */ + + gboolean we_have_indicators = FALSE; + GList * appitems = serverList; + for (; appitems != NULL; appitems = appitems->next) { + AppMenuItem * appitem = ((serverList_t *)appitems->data)->menuitem; + if (app_menu_item_get_count(appitem) != 0) { + we_have_indicators = TRUE; + break; + } + } + + if (!we_have_indicators) { + g_debug("Setting image to boring"); + showing_new_icon = FALSE; + gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages", DESIGN_TEAM_SIZE); + } + + return; +} + +static void +im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data) +{ + serverList_t * sl = (serverList_t *)data; + sl->imList = g_list_sort(sl->imList, imList_sort); + reconsile_list_and_menu(serverList, GTK_MENU_SHELL(gtk_widget_get_parent(GTK_WIDGET(imitem)))); + return; +} + +static void +server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) +{ + g_debug("Removing server: %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server)); + serverList_t slt; + slt.server = server; + GList * lookup = g_list_find_custom(serverList, &slt, serverList_equal); + + if (lookup == NULL) { + g_debug("\tUnable to find server: %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server)); + return; + } + + serverList_t * sltp = (serverList_t *)lookup->data; + + while (sltp->imList) { + imList_t * imitem = (imList_t *)sltp->imList->data; + indicator_removed(listener, server, imitem->indicator, "message", data); + } + + serverList = g_list_remove(serverList, sltp); + + if (sltp->menuitem != NULL) { + gtk_widget_hide(GTK_WIDGET(sltp->menuitem)); + gtk_container_remove(GTK_CONTAINER(data), GTK_WIDGET(sltp->menuitem)); + } + + g_free(sltp); + + if (g_list_length(serverList) == 0) { + gtk_widget_hide(main_image); + } else { + /* Simulate a server saying zero to recalculate icon */ + server_count_changed(NULL, 0, NULL); + } + + return; +} + +typedef struct _menushell_location menushell_location_t; +struct _menushell_location { + const IndicateListenerServer * server; + gint position; + gboolean found; +}; + +static void +menushell_foreach_cb (GtkWidget * data_mi, gpointer data_ms) { + menushell_location_t * msl = (menushell_location_t *)data_ms; + + if (msl->found) return; + + msl->position++; + + if (!IS_APP_MENU_ITEM(data_mi)) { + return; + } + + AppMenuItem * appmenu = APP_MENU_ITEM(data_mi); + if (!g_strcmp0(INDICATE_LISTENER_SERVER_DBUS_NAME((IndicateListenerServer*)msl->server), INDICATE_LISTENER_SERVER_DBUS_NAME(app_menu_item_get_server(appmenu)))) { + msl->found = TRUE; + } + + return; +} + +static void +reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell) +{ + guint position = 0; + GList * serverentry; + + g_debug("Reordering Menu:"); + + for (serverentry = serverList; serverentry != NULL; serverentry = serverentry->next) { + serverList_t * si = (serverList_t *)serverentry->data; + if (si->menuitem != NULL) { + g_debug("\tMoving app %s to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(si->server), position); + gtk_menu_reorder_child(GTK_MENU(menushell), GTK_WIDGET(si->menuitem), position); + position++; + } + + GList * imentry; + for (imentry = si->imList; imentry != NULL; imentry = imentry->next) { + imList_t * imi = (imList_t *)imentry->data; + + if (imi->menuitem != NULL) { + g_debug("\tMoving indicator on %s id %d to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(imi->server), INDICATE_LISTENER_INDICATOR_ID(imi->indicator), position); + gtk_menu_reorder_child(GTK_MENU(menushell), imi->menuitem, position); + position++; + } + } + } + + return; +} + +static void +subtype_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) +{ + GtkMenuShell * menushell = GTK_MENU_SHELL(data); + if (menushell == NULL) { + g_error("Data in callback is not a menushell"); + return; + } + + if (property == NULL || g_strcmp0(property, "subtype")) { + /* We should only ever get subtypes, but just in case */ + g_warning("Subtype callback got a property '%s'", property); + return; + } + + if (propertydata == NULL || propertydata[0] == '\0') { + /* It's possible that this message didn't have a subtype. That's + * okay, but we don't want to display those */ + g_debug("No subtype"); + return; + } + + g_debug("Message subtype: %s", propertydata); + + if (!g_strcmp0(propertydata, "im") || !g_strcmp0(propertydata, "login")) { + imList_t * listItem = g_new0(imList_t, 1); + listItem->server = server; + listItem->indicator = indicator; + + g_debug("Building IM Item"); + ImMenuItem * menuitem = im_menu_item_new(listener, server, indicator, !g_strcmp0(propertydata, "im")); + g_object_ref(G_OBJECT(menuitem)); + listItem->menuitem = GTK_WIDGET(menuitem); + + g_debug("Finding the server entry"); + serverList_t sl_item_local; + serverList_t * sl_item = NULL; + sl_item_local.server = server; + GList * serverentry = g_list_find_custom(serverList, &sl_item_local, serverList_equal); + + if (serverentry == NULL) { + /* This sucks, we got an indicator before the server. I guess + that's the joy of being asynchronous */ + serverList_t * sl_item = g_new0(serverList_t, 1); + sl_item->server = server; + sl_item->menuitem = NULL; + sl_item->imList = NULL; + + serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); + } else { + sl_item = (serverList_t *)serverentry->data; + } + + g_debug("Adding to IM List"); + sl_item->imList = g_list_insert_sorted(sl_item->imList, listItem, imList_sort); + listItem->timechange_cb = g_signal_connect(G_OBJECT(menuitem), IM_MENU_ITEM_SIGNAL_TIME_CHANGED, G_CALLBACK(im_time_changed), sl_item); + + g_debug("Placing in Shell"); + 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; +} + +static void +indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + if (type == NULL || g_strcmp0(type, "message")) { + /* We only care about message type indicators + all of the others can go to the bit bucket */ + g_debug("Ignoreing indicator of type '%s'", type); + return; + } + g_debug("Got a message"); + + indicate_listener_get_property(listener, server, indicator, "subtype", subtype_cb, data); + return; +} + +static void +indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + g_debug("Removing %s %d", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator)); + if (type == NULL || g_strcmp0(type, "message")) { + /* We only care about message type indicators + all of the others can go to the bit bucket */ + g_debug("Ignoreing indicator of type '%s'", type); + return; + } + + gboolean removed = FALSE; + + serverList_t sl_item_local; + serverList_t * sl_item = NULL; + sl_item_local.server = server; + GList * serverentry = g_list_find_custom(serverList, &sl_item_local, serverList_equal); + if (serverentry == NULL) { + return; + } + sl_item = (serverList_t *)serverentry->data; + + /* Look in the IM Hash Table */ + imList_t listData; + listData.server = server; + listData.indicator = indicator; + + GList * listItem = g_list_find_custom(sl_item->imList, &listData, imList_equal); + GtkWidget * menuitem = NULL; + imList_t * ilt = NULL; + if (listItem != NULL) { + ilt = (imList_t *)listItem->data; + menuitem = ilt->menuitem; + } + + if (!removed && menuitem != NULL) { + sl_item->imList = g_list_remove(sl_item->imList, ilt); + g_signal_handler_disconnect(menuitem, ilt->timechange_cb); + g_free(ilt); + + gtk_widget_hide(menuitem); + gtk_container_remove(GTK_CONTAINER(data), menuitem); + removed = TRUE; + } + + if (!removed) { + g_warning("We were asked to remove %s %d but we didn't.", INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_INDICATOR_ID(indicator)); + } + + return; +} + +GtkLabel * +get_label (void) +{ + return NULL; +} + +GtkImage * +get_icon (void) +{ + design_team_size = gtk_icon_size_register("design-team-size", 22, 22); + + main_image = gtk_image_new_from_icon_name("indicator-messages", DESIGN_TEAM_SIZE); + gtk_widget_show(main_image); + + return GTK_IMAGE(main_image); +} + +GtkMenu * +get_menu (void) +{ + listener = indicate_listener_ref_default(); + serverList = NULL; + + GtkWidget * submenu = gtk_menu_new(); + gtk_widget_show(submenu); + + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), submenu); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), submenu); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), submenu); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), submenu); + + return GTK_MENU(submenu); +} + -- cgit v1.2.3 From 11503c7fc6a8c16b2da49a8247e7d32d5ee45866 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 26 May 2009 14:46:10 +0200 Subject: A simple main() to get things to compile --- src/indicator-service.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/indicator-service.c') diff --git a/src/indicator-service.c b/src/indicator-service.c index b0aaffd..683a7ab 100644 --- a/src/indicator-service.c +++ b/src/indicator-service.c @@ -505,3 +505,9 @@ get_menu (void) return GTK_MENU(submenu); } +int +main (int argc, char ** argv) +{ + + return 0; +} -- cgit v1.2.3 From 67b8e020399db87d2865843c7c4ad651f07ac31d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 26 May 2009 15:34:45 +0200 Subject: First pass, build the listener and do fun stuff like that. --- src/indicator-service.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) (limited to 'src/indicator-service.c') diff --git a/src/indicator-service.c b/src/indicator-service.c index 683a7ab..3c3506f 100644 --- a/src/indicator-service.c +++ b/src/indicator-service.c @@ -24,12 +24,11 @@ with this program. If not, see . #include #include -#include -INDICATOR_SET_VERSION -INDICATOR_SET_NAME("messages") +#include #include "im-menu-item.h" #include "app-menu-item.h" +#include "dbus-data.h" static IndicateListener * listener; static GList * serverList; @@ -471,43 +470,27 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, return; } -GtkLabel * -get_label (void) -{ - return NULL; -} +static GMainLoop * mainloop = NULL; -GtkImage * -get_icon (void) +int +main (int argc, char ** argv) { - design_team_size = gtk_icon_size_register("design-team-size", 22, 22); - - main_image = gtk_image_new_from_icon_name("indicator-messages", DESIGN_TEAM_SIZE); - gtk_widget_show(main_image); - - return GTK_IMAGE(main_image); -} + g_type_init(); -GtkMenu * -get_menu (void) -{ listener = indicate_listener_ref_default(); serverList = NULL; - GtkWidget * submenu = gtk_menu_new(); - gtk_widget_show(submenu); + DbusmenuMenuitem * submenu = dbusmenu_menuitem_new(); + DbusmenuServer * server = dbusmenu_server_new(INDICATOR_MESSAGES_DBUS_OBJECT); + dbusmenu_server_set_root(server, submenu); g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), submenu); g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), submenu); g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), submenu); g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), submenu); - return GTK_MENU(submenu); -} - -int -main (int argc, char ** argv) -{ + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); return 0; } -- cgit v1.2.3 From f3cc98cd85288731b8487fe5a09e61ba0bd73fd3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 26 May 2009 18:05:48 +0200 Subject: First pass at moving everything to doing work with the DbusmenuMenuitem's instead of GTK --- src/indicator-service.c | 86 ++++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'src/indicator-service.c') diff --git a/src/indicator-service.c b/src/indicator-service.c index 3c3506f..bd87903 100644 --- a/src/indicator-service.c +++ b/src/indicator-service.c @@ -21,7 +21,6 @@ with this program. If not, see . */ #include -#include #include #include @@ -32,17 +31,17 @@ with this program. If not, see . static IndicateListener * listener; static GList * serverList; -static GtkWidget * main_image; + +static DbusmenuMenuitem * root_menuitem = NULL; +static GMainLoop * mainloop = NULL; + static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data); static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data); -static void reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell); +static void reconsile_list_and_menu (GList * serverlist, DbusmenuMenuitem * menushell); static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); -#define DESIGN_TEAM_SIZE design_team_size -static GtkIconSize design_team_size; - typedef struct _serverList_t serverList_t; struct _serverList_t { IndicateListenerServer * server; @@ -82,7 +81,7 @@ typedef struct _imList_t imList_t; struct _imList_t { IndicateListenerServer * server; IndicateListenerIndicator * indicator; - GtkWidget * menuitem; + DbusmenuMenuitem * menuitem; gulong timechange_cb; }; @@ -133,7 +132,7 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha return; } - GtkMenuShell * menushell = GTK_MENU_SHELL(data); + DbusmenuMenuitem * menushell = DBUSMENU_MENUITEM(data); if (menushell == NULL) { g_error("\tData in callback is not a menushell"); return; @@ -159,9 +158,8 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); } - gtk_menu_shell_prepend(menushell, GTK_WIDGET(menuitem)); - gtk_widget_show(GTK_WIDGET(menuitem)); - gtk_widget_show(GTK_WIDGET(main_image)); + dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); + /* Should be prepend ^ */ reconsile_list_and_menu(serverList, menushell); @@ -172,7 +170,7 @@ static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data) { serverList = g_list_sort(serverList, serverList_sort); - reconsile_list_and_menu(serverList, GTK_MENU_SHELL(data)); + reconsile_list_and_menu(serverList, DBUSMENU_MENUITEM(data)); return; } @@ -195,7 +193,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(GTK_IMAGE(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; } @@ -216,7 +214,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(GTK_IMAGE(main_image), "indicator-messages", DESIGN_TEAM_SIZE); + /* gtk_image_set_from_icon_name(GTK_IMAGE(main_image), "indicator-messages", DESIGN_TEAM_SIZE); */ } return; @@ -227,7 +225,7 @@ im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data) { serverList_t * sl = (serverList_t *)data; sl->imList = g_list_sort(sl->imList, imList_sort); - reconsile_list_and_menu(serverList, GTK_MENU_SHELL(gtk_widget_get_parent(GTK_WIDGET(imitem)))); + reconsile_list_and_menu(serverList, root_menuitem); return; } @@ -254,18 +252,14 @@ server_removed (IndicateListener * listener, IndicateListenerServer * server, gc serverList = g_list_remove(serverList, sltp); if (sltp->menuitem != NULL) { - gtk_widget_hide(GTK_WIDGET(sltp->menuitem)); - gtk_container_remove(GTK_CONTAINER(data), GTK_WIDGET(sltp->menuitem)); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(sltp->menuitem), "visibile", "false"); + dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM(sltp->menuitem)); } g_free(sltp); - if (g_list_length(serverList) == 0) { - gtk_widget_hide(main_image); - } else { - /* Simulate a server saying zero to recalculate icon */ - server_count_changed(NULL, 0, NULL); - } + /* Simulate a server saying zero to recalculate icon */ + server_count_changed(NULL, 0, NULL); return; } @@ -278,7 +272,7 @@ struct _menushell_location { }; static void -menushell_foreach_cb (GtkWidget * data_mi, gpointer data_ms) { +menushell_foreach_cb (DbusmenuMenuitem * data_mi, gpointer data_ms) { menushell_location_t * msl = (menushell_location_t *)data_ms; if (msl->found) return; @@ -298,7 +292,15 @@ menushell_foreach_cb (GtkWidget * data_mi, gpointer data_ms) { } static void -reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell) +dbusmenu_menuitem_child_reorder(DbusmenuMenuitem * base, DbusmenuMenuitem * child, guint position) +{ + dbusmenu_menuitem_child_delete(base, child); + dbusmenu_menuitem_child_add_position(base, child, position); + return; +} + +static void +reconsile_list_and_menu (GList * serverlist, DbusmenuMenuitem * menushell) { guint position = 0; GList * serverentry; @@ -309,7 +311,7 @@ reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell) serverList_t * si = (serverList_t *)serverentry->data; if (si->menuitem != NULL) { g_debug("\tMoving app %s to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(si->server), position); - gtk_menu_reorder_child(GTK_MENU(menushell), GTK_WIDGET(si->menuitem), position); + dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(si->menuitem), position); position++; } @@ -319,7 +321,7 @@ reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell) if (imi->menuitem != NULL) { g_debug("\tMoving indicator on %s id %d to position %d", INDICATE_LISTENER_SERVER_DBUS_NAME(imi->server), INDICATE_LISTENER_INDICATOR_ID(imi->indicator), position); - gtk_menu_reorder_child(GTK_MENU(menushell), imi->menuitem, position); + dbusmenu_menuitem_child_reorder(DBUSMENU_MENUITEM(menushell), DBUSMENU_MENUITEM(imi->menuitem), position); position++; } } @@ -331,7 +333,7 @@ reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell) static void subtype_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { - GtkMenuShell * menushell = GTK_MENU_SHELL(data); + DbusmenuMenuitem * menushell = DBUSMENU_MENUITEM(data); if (menushell == NULL) { g_error("Data in callback is not a menushell"); return; @@ -360,7 +362,7 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica g_debug("Building IM Item"); ImMenuItem * menuitem = im_menu_item_new(listener, server, indicator, !g_strcmp0(propertydata, "im")); g_object_ref(G_OBJECT(menuitem)); - listItem->menuitem = GTK_WIDGET(menuitem); + listItem->menuitem = DBUSMENU_MENUITEM(menuitem); g_debug("Finding the server entry"); serverList_t sl_item_local; @@ -391,12 +393,12 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica msl.position = 0; msl.server = server; - gtk_container_foreach(GTK_CONTAINER(menushell), menushell_foreach_cb, &msl); + dbusmenu_menuitem_foreach(DBUSMENU_MENUITEM(menushell), menushell_foreach_cb, &msl); if (msl.found) { - gtk_menu_shell_insert(menushell, GTK_WIDGET(menuitem), msl.position); + dbusmenu_menuitem_child_add_position(menushell, DBUSMENU_MENUITEM(menuitem), msl.position); } else { g_warning("Unable to find server menu item"); - gtk_menu_shell_append(menushell, GTK_WIDGET(menuitem)); + dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); } } @@ -446,7 +448,7 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, listData.indicator = indicator; GList * listItem = g_list_find_custom(sl_item->imList, &listData, imList_equal); - GtkWidget * menuitem = NULL; + DbusmenuMenuitem * menuitem = NULL; imList_t * ilt = NULL; if (listItem != NULL) { ilt = (imList_t *)listItem->data; @@ -458,8 +460,8 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, g_signal_handler_disconnect(menuitem, ilt->timechange_cb); g_free(ilt); - gtk_widget_hide(menuitem); - gtk_container_remove(GTK_CONTAINER(data), menuitem); + dbusmenu_menuitem_property_set(menuitem, "visibile", "false"); + dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), menuitem); removed = TRUE; } @@ -470,8 +472,6 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, return; } -static GMainLoop * mainloop = NULL; - int main (int argc, char ** argv) { @@ -480,14 +480,14 @@ main (int argc, char ** argv) listener = indicate_listener_ref_default(); serverList = NULL; - DbusmenuMenuitem * submenu = dbusmenu_menuitem_new(); + root_menuitem = dbusmenu_menuitem_new(); DbusmenuServer * server = dbusmenu_server_new(INDICATOR_MESSAGES_DBUS_OBJECT); - dbusmenu_server_set_root(server, submenu); + dbusmenu_server_set_root(server, root_menuitem); - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), submenu); - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), submenu); - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), submenu); - g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), submenu); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added), root_menuitem); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed), root_menuitem); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_ADDED, G_CALLBACK(server_added), root_menuitem); + g_signal_connect(listener, INDICATE_LISTENER_SIGNAL_SERVER_REMOVED, G_CALLBACK(server_removed), root_menuitem); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); -- cgit v1.2.3 From a472a2b401abb7b108260b6d62a25bb130083dd2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 27 May 2009 00:06:01 +0200 Subject: Removing the child_reorder function as it's now upstream --- src/indicator-service.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'src/indicator-service.c') diff --git a/src/indicator-service.c b/src/indicator-service.c index bd87903..467ef3a 100644 --- a/src/indicator-service.c +++ b/src/indicator-service.c @@ -291,14 +291,6 @@ menushell_foreach_cb (DbusmenuMenuitem * data_mi, gpointer data_ms) { return; } -static void -dbusmenu_menuitem_child_reorder(DbusmenuMenuitem * base, DbusmenuMenuitem * child, guint position) -{ - dbusmenu_menuitem_child_delete(base, child); - dbusmenu_menuitem_child_add_position(base, child, position); - return; -} - static void reconsile_list_and_menu (GList * serverlist, DbusmenuMenuitem * menushell) { -- cgit v1.2.3 From d2bd9a0a70bbcb73997561baa7a61ddbe7e4780a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 27 May 2009 10:44:37 +0200 Subject: Getting a name, and grabbing it, and loving it... --- src/indicator-service.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/indicator-service.c') diff --git a/src/indicator-service.c b/src/indicator-service.c index 467ef3a..77d42e6 100644 --- a/src/indicator-service.c +++ b/src/indicator-service.c @@ -21,6 +21,7 @@ with this program. If not, see . */ #include +#include #include #include @@ -469,6 +470,21 @@ main (int argc, char ** argv) { g_type_init(); + DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + GError * error = NULL; + guint nameret = 0; + + if (!org_freedesktop_DBus_request_name(bus_proxy, INDICATOR_MESSAGES_DBUS_NAME, 0, &nameret, &error)) { + g_error("Unable to call to request name"); + return 1; + } + + if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + g_error("Unable to get name"); + return 1; + } + listener = indicate_listener_ref_default(); serverList = NULL; -- cgit v1.2.3