From 97c719c1289bddce6d8a5005e74c594b23cd80b8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 9 Mar 2009 14:21:47 +0200 Subject: changing the size of the icon --- src/indicator-messages.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 9a51b6b..0021219 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -33,6 +33,9 @@ static GHashTable * serverHash; static GtkWidget * main_image; static GtkWidget * main_menu; +#define DESIGN_TEAM_SIZE design_team_size +static GtkIconSize design_team_size; + typedef struct _imList_t imList_t; struct _imList_t { IndicateListenerServer * server; @@ -163,7 +166,7 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica if (g_list_length(imList) != 0) { g_debug("Setting image to 'new'"); - gtk_image_set_from_icon_name(main_image, "indicator-messages-new", GTK_ICON_SIZE_MENU); + gtk_image_set_from_icon_name(main_image, "indicator-messages-new", DESIGN_TEAM_SIZE); } else { g_debug("Hmm, still no entries"); } @@ -226,7 +229,7 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, } if (g_list_length(imList) == 0) { - gtk_image_set_from_icon_name(main_image, "indicator-messages", GTK_ICON_SIZE_MENU); + gtk_image_set_from_icon_name(main_image, "indicator-messages", DESIGN_TEAM_SIZE); if (g_list_length(g_hash_table_get_keys(serverHash)) == 0) { gtk_widget_hide(main_menu); } @@ -238,6 +241,8 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, GtkWidget * get_menu_item (void) { + design_team_size = gtk_icon_size_register("design-team-size", 22, 22); + listener = indicate_listener_new(); imList = NULL; @@ -246,7 +251,7 @@ get_menu_item (void) main_menu = gtk_menu_item_new(); - main_image = gtk_image_new_from_icon_name("indicator-messages", GTK_ICON_SIZE_MENU); + main_image = gtk_image_new_from_icon_name("indicator-messages", DESIGN_TEAM_SIZE); gtk_widget_show(main_image); gtk_container_add(GTK_CONTAINER(main_menu), main_image); -- cgit v1.2.3 From c9f60d213f559fdd49e5cc4229658f8b30ad8533 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 09:48:32 -0500 Subject: Adding in an unread count variable, and then a signal to show it chagned. Also, watching for the indicators on this server to make sure it stays correct. --- src/app-menu-item.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/app-menu-item.h | 5 ++++ 2 files changed, 72 insertions(+) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 2622010..e0562cb 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -29,6 +29,13 @@ with this program. If not, see . #include #include "app-menu-item.h" +enum { + COUNT_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + typedef struct _AppMenuItemPrivate AppMenuItemPrivate; struct _AppMenuItemPrivate @@ -38,6 +45,7 @@ struct _AppMenuItemPrivate gchar * type; GAppInfo * appinfo; + guint unreadcount; GtkWidget * name; }; @@ -52,6 +60,8 @@ static void app_menu_item_finalize (GObject *object); static void activate_cb (AppMenuItem * self, gpointer data); static void type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); static void desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); +static void indicator_added_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); +static void indicator_removed_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); @@ -66,6 +76,16 @@ app_menu_item_class_init (AppMenuItemClass *klass) object_class->dispose = app_menu_item_dispose; object_class->finalize = app_menu_item_finalize; + + signals[COUNT_CHANGED] = g_signal_new(APP_MENU_ITEM_SIGNAL_COUNT_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (AppMenuItemClass, count_changed), + NULL, NULL, + g_cclosure_marshal_VOID__UINT, + G_TYPE_NONE, 1, G_TYPE_UINT); + + return; } static void @@ -79,6 +99,7 @@ app_menu_item_init (AppMenuItem *self) priv->name = NULL; priv->type = NULL; priv->appinfo = NULL; + priv->unreadcount = 0; return; @@ -106,6 +127,9 @@ app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server) priv->listener = listener; priv->server = server; + g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added_cb), self); + g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_added_cb), self); + priv->name = gtk_label_new(INDICATE_LISTENER_SERVER_DBUS_NAME(server)); gtk_misc_set_alignment(GTK_MISC(priv->name), 0.0, 0.5); gtk_widget_show(GTK_WIDGET(priv->name)); @@ -162,3 +186,46 @@ activate_cb (AppMenuItem * self, gpointer data) return; } + +static void +indicator_added_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(data); + + if (g_strcmp0(INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_SERVER_DBUS_NAME(priv->server))) { + /* Not us */ + return; + } + + priv->unreadcount++; + + g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, TRUE); + + return; +} + +static void +indicator_removed_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +{ + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(data); + + if (g_strcmp0(INDICATE_LISTENER_SERVER_DBUS_NAME(server), INDICATE_LISTENER_SERVER_DBUS_NAME(priv->server))) { + /* Not us */ + return; + } + + priv->unreadcount--; + + g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, TRUE); + + return; +} + +guint +app_menu_item_get_count (AppMenuItem * appitem) +{ + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); + + return priv->unreadcount; +} + diff --git a/src/app-menu-item.h b/src/app-menu-item.h index 6d21c57..3a9a4e5 100644 --- a/src/app-menu-item.h +++ b/src/app-menu-item.h @@ -36,11 +36,15 @@ G_BEGIN_DECLS #define IS_APP_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APP_MENU_ITEM_TYPE)) #define APP_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APP_MENU_ITEM_TYPE, AppMenuItemClass)) +#define APP_MENU_ITEM_SIGNAL_COUNT_CHANGED "count-changed" + typedef struct _AppMenuItem AppMenuItem; typedef struct _AppMenuItemClass AppMenuItemClass; struct _AppMenuItemClass { GtkMenuItemClass parent_class; + + void (* count_changed) (guint count); }; struct _AppMenuItem { @@ -49,6 +53,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); G_END_DECLS -- cgit v1.2.3 From 6793aaa5123b0390e84cbef5b27a23e8325e334c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 10:03:28 -0500 Subject: Splitting the label updating into it's own function and making that called by the other functions that adjust how that happens. --- src/app-menu-item.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index e0562cb..9923075 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -46,6 +46,7 @@ struct _AppMenuItemPrivate gchar * type; GAppInfo * appinfo; guint unreadcount; + gboolean count_on_label; GtkWidget * name; }; @@ -62,6 +63,7 @@ static void type_cb (IndicateListener * listener, IndicateListenerServer * serve static void desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); static void indicator_added_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); static void indicator_removed_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); +static void update_label (AppMenuItem * self); @@ -100,6 +102,7 @@ app_menu_item_init (AppMenuItem *self) priv->type = NULL; priv->appinfo = NULL; priv->unreadcount = 0; + priv->count_on_label = FALSE; return; @@ -156,6 +159,28 @@ type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * v priv->type = g_strdup(value); + if (g_strcmp0(priv->type, "message.im") || g_strcmp0(priv->type, "message.micro")) { + /* For IM and Microblogging we want the individual items, not a count */ + priv->count_on_label = TRUE; + update_label(self); + } + + return; +} + +static void +update_label (AppMenuItem * self) +{ + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + + if (priv->count_on_label && !priv->unreadcount < 1) { + gchar * label = g_strdup_printf(_("%s (%d)"), g_app_info_get_name(priv->appinfo), priv->unreadcount); + gtk_label_set_text(GTK_LABEL(priv->name), label); + g_free(label); + } else { + gtk_label_set_text(GTK_LABEL(priv->name), g_app_info_get_name(priv->appinfo)); + } + return; } @@ -172,7 +197,7 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(value)); g_return_if_fail(priv->appinfo != NULL); - gtk_label_set_text(GTK_LABEL(priv->name), g_app_info_get_name(priv->appinfo)); + update_label(self); return; } @@ -199,6 +224,7 @@ indicator_added_cb (IndicateListener * listener, IndicateListenerServer * server priv->unreadcount++; + update_label(APP_MENU_ITEM(data)); g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, TRUE); return; @@ -214,8 +240,12 @@ indicator_removed_cb (IndicateListener * listener, IndicateListenerServer * serv return; } - priv->unreadcount--; + /* Should never happen, but let's have some protection on that */ + if (priv->unreadcount > 0) { + priv->unreadcount--; + } + update_label(APP_MENU_ITEM(data)); g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, TRUE); return; -- cgit v1.2.3 From d0261d805ea2a47199dfe8fc34e689944cd62653 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 10:27:08 -0500 Subject: Switching the icon to be based on whether or not the server is reporting indicators instead of counting the number of indicators items. --- src/indicator-messages.c | 63 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 0021219..b5075d6 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -33,6 +33,8 @@ static GHashTable * serverHash; static GtkWidget * main_image; static GtkWidget * main_menu; +void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); + #define DESIGN_TEAM_SIZE design_team_size static GtkIconSize design_team_size; @@ -88,6 +90,7 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha gchar * servername = g_strdup(INDICATE_LISTENER_SERVER_DBUS_NAME(server)); 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_hash_table_insert(serverHash, servername, menuitem); gtk_menu_shell_prepend(menushell, GTK_WIDGET(menuitem)); @@ -97,6 +100,52 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha return; } +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(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 = g_hash_table_get_values(serverHash); + for (; appitems != NULL; appitems = appitems->next) { + AppMenuItem * appitem = APP_MENU_ITEM(appitems->data); + 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(main_image, "indicator-messages", DESIGN_TEAM_SIZE); + } + + return; +} + void server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { @@ -164,13 +213,6 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica gtk_menu_shell_prepend(menushell, GTK_WIDGET(menuitem)); } - if (g_list_length(imList) != 0) { - g_debug("Setting image to 'new'"); - gtk_image_set_from_icon_name(main_image, "indicator-messages-new", DESIGN_TEAM_SIZE); - } else { - g_debug("Hmm, still no entries"); - } - return; } @@ -228,13 +270,6 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, g_warning("We were asked to remove %s %d but we didn't.", (gchar*)server, (guint)indicator); } - if (g_list_length(imList) == 0) { - gtk_image_set_from_icon_name(main_image, "indicator-messages", DESIGN_TEAM_SIZE); - if (g_list_length(g_hash_table_get_keys(serverHash)) == 0) { - gtk_widget_hide(main_menu); - } - } - return; } -- cgit v1.2.3 From e02359f6e727470c66e6f54c900843e09d3a8829 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 10:32:27 -0500 Subject: Setting up the library versioning to basically not have any, this is a module. --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 67fbd05..eb6ba12 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,3 +4,4 @@ messaginglib_LTLIBRARIES = libmessaging.la libmessaging_la_SOURCES = indicator-messages.c im-menu-item.c im-menu-item.h app-menu-item.c app-menu-item.h libmessaging_la_CFLAGS = $(APPLET_CFLAGS) -Wall -Wl,-Bsymbolic-functions -Wl,-z,defs -Wl,--as-needed libmessaging_la_LIBADD = $(APPLET_LIBS) +libmessaging_la_LDFLAGS = -module -avoid-version -- cgit v1.2.3 From e527f992ac9276a22a680cda881e80ed70c9f73f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 10:39:19 -0500 Subject: Add simulation of zero count on server remove --- src/indicator-messages.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index b5075d6..9a4ce6f 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -169,6 +169,9 @@ server_removed (IndicateListener * listener, IndicateListenerServer * server, gc gtk_widget_hide(main_menu); } + /* Simulate a server saying zero to recalculate icon */ + server_count_changed(NULL, 0, NULL); + return; } -- cgit v1.2.3 From 34c84145647ea961ab5fc32f03b34742b3f3a129 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 10:46:33 -0500 Subject: Disconnecting our signals properly, avoids a crash --- src/app-menu-item.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 9923075..0d5fb85 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -118,6 +118,14 @@ static void app_menu_item_finalize (GObject *object) { G_OBJECT_CLASS (app_menu_item_parent_class)->finalize (object); + + AppMenuItem * self = APP_MENU_ITEM(object); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), G_CALLBACK(indicator_added_cb), self); + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->listener), G_CALLBACK(indicator_removed_cb), self); + + return; } AppMenuItem * @@ -131,7 +139,7 @@ app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server) priv->server = server; g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_INDICATOR_ADDED, G_CALLBACK(indicator_added_cb), self); - g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_added_cb), self); + g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_INDICATOR_REMOVED, G_CALLBACK(indicator_removed_cb), self); priv->name = gtk_label_new(INDICATE_LISTENER_SERVER_DBUS_NAME(server)); gtk_misc_set_alignment(GTK_MISC(priv->name), 0.0, 0.5); -- cgit v1.2.3 From 772b8553ed4c398ce4e73b37198444745febf64e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 10:50:50 -0500 Subject: Bad truth --- src/app-menu-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 0d5fb85..1ab2ba8 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -167,7 +167,7 @@ type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * v priv->type = g_strdup(value); - if (g_strcmp0(priv->type, "message.im") || g_strcmp0(priv->type, "message.micro")) { + if (g_strcmp0(priv->type, "message.im") && g_strcmp0(priv->type, "message.micro")) { /* For IM and Microblogging we want the individual items, not a count */ priv->count_on_label = TRUE; update_label(self); -- cgit v1.2.3 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(-) (limited to 'src') 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 From 0fdeda8fd1140865e5edafbbf1b87de3a5d17dfa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 12:19:02 -0500 Subject: Adding functions to make it so that we can get signaled on name changes and also query them in app-menu-items --- src/app-menu-item.c | 29 ++++++++++++++++++++++++++++- src/app-menu-item.h | 5 ++++- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index d6d3e4a..7d158e5 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -31,6 +31,7 @@ with this program. If not, see . enum { COUNT_CHANGED, + NAME_CHANGED, LAST_SIGNAL }; @@ -86,6 +87,13 @@ app_menu_item_class_init (AppMenuItemClass *klass) NULL, NULL, g_cclosure_marshal_VOID__UINT, G_TYPE_NONE, 1, G_TYPE_UINT); + signals[NAME_CHANGED] = g_signal_new(APP_MENU_ITEM_SIGNAL_NAME_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (AppMenuItemClass, name_changed), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); return; } @@ -182,6 +190,8 @@ update_label (AppMenuItem * self) AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); if (priv->count_on_label && !priv->unreadcount < 1) { + /* TRANSLATORS: This is the name of the program and the number of indicators. So it + would read something like "Mail Client (5)" */ gchar * label = g_strdup_printf(_("%s (%d)"), g_app_info_get_name(priv->appinfo), priv->unreadcount); gtk_label_set_text(GTK_LABEL(priv->name), label); g_free(label); @@ -201,11 +211,16 @@ desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar if (priv->appinfo != NULL) { g_object_unref(G_OBJECT(priv->appinfo)); } + + if (value == NULL || value[0] == '\0') { + return; + } priv->appinfo = G_APP_INFO(g_desktop_app_info_new_from_filename(value)); g_return_if_fail(priv->appinfo != NULL); update_label(self); + g_signal_emit(G_OBJECT(self), signals[NAME_CHANGED], 0, g_app_info_get_name(priv->appinfo), TRUE); return; } @@ -233,7 +248,7 @@ indicator_added_cb (IndicateListener * listener, IndicateListenerServer * server priv->unreadcount++; update_label(APP_MENU_ITEM(data)); - g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, TRUE); + g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, priv->unreadcount, TRUE); return; } @@ -273,3 +288,15 @@ app_menu_item_get_server (AppMenuItem * appitem) { return priv->server; } + +const gchar * +app_menu_item_get_name (AppMenuItem * appitem) +{ + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(appitem); + + if (priv->appinfo == NULL) { + return INDICATE_LISTENER_SERVER_DBUS_NAME(priv->server); + } else { + return g_app_info_get_name(priv->appinfo); + } +} diff --git a/src/app-menu-item.h b/src/app-menu-item.h index 5e012e7..1e1b5eb 100644 --- a/src/app-menu-item.h +++ b/src/app-menu-item.h @@ -36,7 +36,8 @@ G_BEGIN_DECLS #define IS_APP_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), APP_MENU_ITEM_TYPE)) #define APP_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), APP_MENU_ITEM_TYPE, AppMenuItemClass)) -#define APP_MENU_ITEM_SIGNAL_COUNT_CHANGED "count-changed" +#define APP_MENU_ITEM_SIGNAL_COUNT_CHANGED "count-changed" +#define APP_MENU_ITEM_SIGNAL_NAME_CHANGED "name-changed" typedef struct _AppMenuItem AppMenuItem; typedef struct _AppMenuItemClass AppMenuItemClass; @@ -45,6 +46,7 @@ struct _AppMenuItemClass { GtkMenuItemClass parent_class; void (* count_changed) (guint count); + void (* name_changed) (gchar * name); }; struct _AppMenuItem { @@ -55,6 +57,7 @@ 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); +const gchar * app_menu_item_get_name (AppMenuItem * appitem); G_END_DECLS -- cgit v1.2.3 From 4eff83ac63a29a6b32c88bd45866a0d858f20f1a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 15 Mar 2009 13:24:24 -0500 Subject: Switching the servers from a hash table to a list. Cleans things up a little, and sets us up for menu organization at a more complete level. --- src/indicator-messages.c | 103 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 82 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 0d20468..f64f5e1 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -29,15 +29,51 @@ with this program. If not, see . static IndicateListener * listener; static GList * imList; -static GHashTable * serverHash; +static GList * serverList; static GtkWidget * main_image; static GtkWidget * main_menu; -void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); +static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); +static void reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell); #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; + + gchar * pas = INDICATE_LISTENER_SERVER_DBUS_NAME(pa->server); + 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; @@ -88,19 +124,35 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha return; } - gchar * servername = g_strdup(INDICATE_LISTENER_SERVER_DBUS_NAME(server)); 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_hash_table_insert(serverHash, servername, menuitem); + serverList_t * sl_item = g_new(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_menu)); + reconsile_list_and_menu(serverList, menushell); + return; } -void +static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data) { static gboolean showing_new_icon = FALSE; @@ -128,9 +180,9 @@ server_count_changed (AppMenuItem * appitem, guint count, gpointer data) the plain one. Let's check. */ gboolean we_have_indicators = FALSE; - GList * appitems = g_hash_table_get_values(serverHash); + GList * appitems = serverList; for (; appitems != NULL; appitems = appitems->next) { - AppMenuItem * appitem = APP_MENU_ITEM(appitems->data); + AppMenuItem * appitem = ((serverList_t *)appitems->data)->menuitem; if (app_menu_item_get_count(appitem) != 0) { we_have_indicators = TRUE; break; @@ -150,28 +202,32 @@ void server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { g_debug("Removing server: %s", INDICATE_LISTENER_SERVER_DBUS_NAME(server)); - gpointer lookup = g_hash_table_lookup(serverHash, 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; } - g_hash_table_remove(serverHash, INDICATE_LISTENER_SERVER_DBUS_NAME(server)); + serverList_t * sltp = (serverList_t *)lookup->data; + serverList = g_list_remove(serverList, sltp); - AppMenuItem * menuitem = APP_MENU_ITEM(lookup); - g_return_if_fail(menuitem != NULL); + if (sltp->menuitem != NULL) { + gtk_widget_hide(GTK_WIDGET(sltp->menuitem)); + gtk_container_remove(GTK_CONTAINER(data), GTK_WIDGET(sltp->menuitem)); + } - gtk_widget_hide(GTK_WIDGET(menuitem)); - gtk_container_remove(GTK_CONTAINER(data), GTK_WIDGET(menuitem)); + g_free(sltp); - if (g_list_length(g_hash_table_get_keys(serverHash)) == 0 && g_list_length(imList) == 0) { + if (g_list_length(serverList) == 0) { gtk_widget_hide(main_menu); + } 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; } @@ -183,7 +239,7 @@ struct _menushell_location { }; static void -menushell_foreach_cb (gpointer data_mi, gpointer data_ms) { +menushell_foreach_cb (GtkWidget * data_mi, gpointer data_ms) { menushell_location_t * msl = (menushell_location_t *)data_ms; if (msl->found) return; @@ -198,6 +254,13 @@ menushell_foreach_cb (gpointer data_mi, gpointer data_ms) { return; } +static void +reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell) +{ + + +} + static void subtype_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { @@ -317,9 +380,7 @@ get_menu_item (void) listener = indicate_listener_new(); imList = NULL; - - serverHash = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, NULL); + serverList = NULL; main_menu = gtk_menu_item_new(); -- cgit v1.2.3 From 9ab9320c9e5688f51064f91fd8c87a5b7d691b65 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 17 Mar 2009 10:47:43 -0500 Subject: Forgot to actually pass the value to the signal, ahhhh --- src/app-menu-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 7d158e5..8badd70 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -269,7 +269,7 @@ indicator_removed_cb (IndicateListener * listener, IndicateListenerServer * serv } update_label(APP_MENU_ITEM(data)); - g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, TRUE); + g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, priv->unreadcount, TRUE); return; } -- cgit v1.2.3 From d41675f236196e8634ab1062a28c970d89313f0a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Mar 2009 10:00:01 -0500 Subject: Relaying out the data structures so that the indicators are sub to the servers --- src/indicator-messages.c | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index f64f5e1..800a3a0 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -28,7 +28,6 @@ with this program. If not, see . #include "app-menu-item.h" static IndicateListener * listener; -static GList * imList; static GList * serverList; static GtkWidget * main_image; static GtkWidget * main_menu; @@ -295,8 +294,27 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica 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_new(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 Hash"); - imList = g_list_append(imList, listItem); + sl_item->imList = g_list_append(sl_item->imList, listItem); g_debug("Placing in Shell"); menushell_location_t msl; @@ -344,12 +362,21 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, 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(imList, &listData, imList_equal); + GList * listItem = g_list_find_custom(sl_item->imList, &listData, imList_equal); GtkWidget * menuitem = NULL; if (listItem != NULL) { menuitem = ((imList_t *)listItem->data)->menuitem; @@ -357,7 +384,7 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, if (!removed && menuitem != NULL) { g_object_ref(menuitem); - imList = g_list_remove(imList, listItem->data); + sl_item->imList = g_list_remove(sl_item->imList, listItem->data); gtk_widget_hide(menuitem); gtk_container_remove(GTK_CONTAINER(data), menuitem); @@ -379,7 +406,6 @@ get_menu_item (void) design_team_size = gtk_icon_size_register("design-team-size", 22, 22); listener = indicate_listener_new(); - imList = NULL; serverList = NULL; main_menu = gtk_menu_item_new(); -- cgit v1.2.3 From 5d7e356e05dfdc71ea29ada80d4d613984b9aea5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Mar 2009 10:03:59 -0500 Subject: Wrong name --- src/app-menu-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 8badd70..32b6aa2 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -175,7 +175,7 @@ type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * v priv->type = g_strdup(value); - if (g_strcmp0(priv->type, "message.im") && g_strcmp0(priv->type, "message.micro")) { + if (!g_strcmp0(priv->type, "message.instant") || !g_strcmp0(priv->type, "message.micro")) { /* For IM and Microblogging we want the individual items, not a count */ priv->count_on_label = TRUE; update_label(self); -- cgit v1.2.3 From 8d5f26a09d68bf02cd08745f7333a38171f4d466 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Mar 2009 12:56:29 -0500 Subject: Fleshing out the reconsile function. And making sure it gets called everytime there is a name change on the server side. --- src/indicator-messages.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 800a3a0..51a7db6 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -33,6 +33,7 @@ static GtkWidget * main_image; static GtkWidget * main_menu; static void server_count_changed (AppMenuItem * appitem, guint count, gpointer data); +static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data); static void reconsile_list_and_menu (GList * serverlist, GtkMenuShell * menushell); #define DESIGN_TEAM_SIZE design_team_size @@ -125,6 +126,7 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha 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_new(serverList_t, 1); sl_item->server = server; @@ -151,6 +153,14 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha 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) { @@ -245,6 +255,10 @@ menushell_foreach_cb (GtkWidget * data_mi, gpointer data_ms) { 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(msl->server), INDICATE_LISTENER_SERVER_DBUS_NAME(app_menu_item_get_server(appmenu)))) { msl->found = TRUE; @@ -256,8 +270,32 @@ menushell_foreach_cb (GtkWidget * data_mi, gpointer data_ms) { 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 -- cgit v1.2.3 From 1cf60571c0663efc4eab8e3c94002e521490a206 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Mar 2009 13:21:21 -0500 Subject: Putting the seconds into the private structure, a function to get them, and a signal when they change. --- src/im-menu-item.c | 32 ++++++++++++++++++++++++++++++++ src/im-menu-item.h | 5 +++++ 2 files changed, 37 insertions(+) (limited to 'src') diff --git a/src/im-menu-item.c b/src/im-menu-item.c index b5940ac..eaf65a6 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -27,6 +27,13 @@ with this program. If not, see . #include #include "im-menu-item.h" +enum { + TIME_CHANGED, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + typedef struct _ImMenuItemPrivate ImMenuItemPrivate; struct _ImMenuItemPrivate @@ -35,6 +42,8 @@ struct _ImMenuItemPrivate IndicateListenerServer * server; IndicateListenerIndicator * indicator; + glong seconds; + GtkHBox * hbox; GtkLabel * user; GtkLabel * time; @@ -92,6 +101,16 @@ im_menu_item_class_init (ImMenuItemClass *klass) object_class->dispose = im_menu_item_dispose; object_class->finalize = im_menu_item_finalize; + + signals[TIME_CHANGED] = g_signal_new(IM_MENU_ITEM_SIGNAL_TIME_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ImMenuItemClass, time_changed), + NULL, NULL, + g_cclosure_marshal_VOID__LONG, + G_TYPE_NONE, 1, G_TYPE_LONG); + + return; } static void @@ -104,6 +123,8 @@ im_menu_item_init (ImMenuItem *self) priv->server = NULL; priv->indicator = NULL; + priv->seconds = 0; + /* build widgets first */ priv->icon = GTK_IMAGE(gtk_image_new()); priv->user = GTK_LABEL(gtk_label_new("")); @@ -185,6 +206,8 @@ time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateL ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self); + priv->seconds = propertydata->tv_sec; + time_t timet; struct tm * structtm; @@ -198,6 +221,8 @@ time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateL gtk_label_set_label(priv->time, timestring); gtk_widget_show(GTK_WIDGET(priv->time)); + g_signal_emit(G_OBJECT(self), signals[TIME_CHANGED], 0, priv->seconds, TRUE); + return; } @@ -276,3 +301,10 @@ im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, return self; } + +glong +im_menu_item_get_seconds (ImMenuItem * menuitem) +{ + ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(menuitem); + return priv->seconds; +} diff --git a/src/im-menu-item.h b/src/im-menu-item.h index a70f55a..34da453 100644 --- a/src/im-menu-item.h +++ b/src/im-menu-item.h @@ -36,11 +36,15 @@ G_BEGIN_DECLS #define IS_IM_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IM_MENU_ITEM_TYPE)) #define IM_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IM_MENU_ITEM_TYPE, ImMenuItemClass)) +#define IM_MENU_ITEM_SIGNAL_TIME_CHANGED "time-changed" + typedef struct _ImMenuItem ImMenuItem; typedef struct _ImMenuItemClass ImMenuItemClass; struct _ImMenuItemClass { GtkMenuItemClass parent_class; + + void (*time_changed) (glong seconds); }; struct _ImMenuItem { @@ -49,6 +53,7 @@ struct _ImMenuItem { GType im_menu_item_get_type (void); ImMenuItem * im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator); +glong im_menu_item_get_seconds (ImMenuItem * menuitem); G_END_DECLS -- cgit v1.2.3 From 912e0e21903fdd8b0d2106bbcab77dd455892657 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Mar 2009 13:37:28 -0500 Subject: Making the IM list sorted and handling the time changed signal --- src/indicator-messages.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 51a7db6..fc13217 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -34,6 +34,7 @@ static GtkWidget * main_menu; 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); #define DESIGN_TEAM_SIZE design_team_size @@ -100,6 +101,16 @@ imList_equal (gconstpointer a, gconstpointer b) return !((!strcmp(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(pa->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem))); +} void server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) @@ -207,6 +218,15 @@ server_count_changed (AppMenuItem * appitem, guint count, gpointer data) 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; +} + void server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { @@ -351,8 +371,9 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica sl_item = (serverList_t *)serverentry->data; } - g_debug("Adding to IM Hash"); - sl_item->imList = g_list_append(sl_item->imList, listItem); + g_debug("Adding to IM List"); + sl_item->imList = g_list_insert_sorted(sl_item->imList, listItem, imList_sort); + 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; -- cgit v1.2.3 From b1110c5e34159c106a30316bd56c80c6223e6909 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Mar 2009 13:38:27 -0500 Subject: Adding in message.im, should have spec'd this better now there's some drift. --- src/app-menu-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 32b6aa2..0645668 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -175,7 +175,7 @@ type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * v priv->type = g_strdup(value); - if (!g_strcmp0(priv->type, "message.instant") || !g_strcmp0(priv->type, "message.micro")) { + if (!g_strcmp0(priv->type, "message.instant") || !g_strcmp0(priv->type, "message.micro") || !g_strcmp0(priv->type, "message.im")) { /* For IM and Microblogging we want the individual items, not a count */ priv->count_on_label = TRUE; update_label(self); -- cgit v1.2.3 From 9147f109cd6de709b749637c6f768d1c2bae2203 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Mar 2009 13:45:51 -0500 Subject: Backwards sorting --- src/indicator-messages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/indicator-messages.c b/src/indicator-messages.c index fc13217..c600460 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -109,7 +109,7 @@ imList_sort (gconstpointer a, gconstpointer b) pa = (imList_t *)a; pb = (imList_t *)b; - return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem))); + return (gint)(im_menu_item_get_seconds(IM_MENU_ITEM(pb->menuitem)) - im_menu_item_get_seconds(IM_MENU_ITEM(pa->menuitem))); } void -- cgit v1.2.3 From 2ebeacae7268879e8f68bb68a18c22cd32d1afb7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Mar 2009 14:22:08 -0500 Subject: Making the truth correct --- src/app-menu-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 0645668..4fe3298 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -175,7 +175,7 @@ type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * v priv->type = g_strdup(value); - if (!g_strcmp0(priv->type, "message.instant") || !g_strcmp0(priv->type, "message.micro") || !g_strcmp0(priv->type, "message.im")) { + if (!(!g_strcmp0(priv->type, "message.instant") || !g_strcmp0(priv->type, "message.micro") || !g_strcmp0(priv->type, "message.im"))) { /* For IM and Microblogging we want the individual items, not a count */ priv->count_on_label = TRUE; update_label(self); -- cgit v1.2.3