-- cgit v1.2.3 From daf90eeba54e340417b89e386c3fb1692001a6ab Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 10:02:13 -0500 Subject: Reshuffle. Now the creation of an indicator makes for a im-menu-item without looking at type and subtype at all. We'll have a bunch more now. --- src/messages-service.c | 118 ++++++++++++++++++++----------------------------- 1 file changed, 47 insertions(+), 71 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index 754021b..c411ffc 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -646,8 +646,11 @@ resort_menu (DbusmenuMenuitem * menushell) return; } +/* Responding to a new indicator showing up on the bus. We + need to create a menuitem for it and start populating the + internal structures to track it. */ static void -subtype_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) +indicator_added (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gpointer data) { DbusmenuMenuitem * menushell = DBUSMENU_MENUITEM(data); if (menushell == NULL) { @@ -655,84 +658,57 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica 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; - } + imList_t * listItem = g_new0(imList_t, 1); + listItem->server = server; + listItem->indicator = indicator; - 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 = DBUSMENU_MENUITEM(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; - } + /* Building the IM Menu Item which is a subclass + of DBus Menuitem */ + ImMenuItem * menuitem = im_menu_item_new(listener, server, indicator); + g_object_ref(G_OBJECT(menuitem)); + listItem->menuitem = DBUSMENU_MENUITEM(menuitem); - 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); + /* Looking for a server entry to attach this indicator + to. If we can't find one then we have to build one + and attach the indicator to it. */ + 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); - g_debug("Placing in Shell"); - menushell_location_t msl; - msl.found = FALSE; - msl.position = 0; - msl.server = server; + 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; - dbusmenu_menuitem_foreach(DBUSMENU_MENUITEM(menushell), menushell_foreach_cb, &msl); - if (msl.found) { - dbusmenu_menuitem_child_add_position(menushell, DBUSMENU_MENUITEM(menuitem), msl.position); - } else { - g_warning("Unable to find server menu item"); - dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); - } + serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); + } else { + sl_item = (serverList_t *)serverentry->data; } - 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; + /* Added a this entry into the 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); + + /* Placing the item into the shell. Look to see if + we can find our server and slip in there. Otherwise + we'll just append. */ + menushell_location_t msl; + msl.found = FALSE; + msl.position = 0; + msl.server = server; + + dbusmenu_menuitem_foreach(DBUSMENU_MENUITEM(menushell), menushell_foreach_cb, &msl); + if (msl.found) { + dbusmenu_menuitem_child_add_position(menushell, DBUSMENU_MENUITEM(menuitem), msl.position); + } else { + g_warning("Unable to find server menu item"); + dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); } - g_debug("Got a message"); - indicate_listener_get_property(listener, server, indicator, "subtype", subtype_cb, data); return; } -- cgit v1.2.3 From 585541595135fe2317d9f5065073b09ad10052ca Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 10:46:25 -0500 Subject: We have to drop show_time as a parameter as the caller doesn't really know if that's the case or not anymore. --- src/im-menu-item.c | 4 ++-- src/im-menu-item.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 6f58ebd..2a5265b 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -287,7 +287,7 @@ indicator_modified_cb (IndicateListener * listener, IndicateListenerServer * ser } ImMenuItem * -im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gboolean show_time) +im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator) { ImMenuItem * self = g_object_new(IM_MENU_ITEM_TYPE, NULL); @@ -296,7 +296,7 @@ im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, priv->listener = listener; priv->server = server; priv->indicator = indicator; - priv->show_time = show_time; + priv->show_time = TRUE; priv->time_update_min = 0; dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "type", DBUSMENU_CLIENT_TYPES_IMAGE); diff --git a/src/im-menu-item.h b/src/im-menu-item.h index 51414de..8d0c273 100644 --- a/src/im-menu-item.h +++ b/src/im-menu-item.h @@ -53,7 +53,7 @@ struct _ImMenuItem { }; GType im_menu_item_get_type (void); -ImMenuItem * im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gboolean show_time); +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 c63d06803b61ba0597e698077aac6c8b69c0549e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 10:57:59 -0500 Subject: Removing the type from the indicator_removed function. --- src/messages-service.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index c411ffc..c59edc2 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -49,7 +49,7 @@ static void server_count_changed (AppMenuItem * appitem, guint count, gpointer d static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data); static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data); static void resort_menu (DbusmenuMenuitem * menushell); -static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data); +static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gpointer data); static void check_eclipses (AppMenuItem * ai); static void remove_eclipses (AppMenuItem * ai); static gboolean build_launcher (gpointer data); @@ -525,7 +525,7 @@ server_removed (IndicateListener * listener, IndicateListenerServer * server, gc while (sltp->imList) { imList_t * imitem = (imList_t *)sltp->imList->data; - indicator_removed(listener, server, imitem->indicator, "message", data); + indicator_removed(listener, server, imitem->indicator, data); } serverList = g_list_remove(serverList, sltp); @@ -713,15 +713,9 @@ indicator_added (IndicateListener * listener, IndicateListenerServer * server, I } static void -indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) +indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, 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; -- cgit v1.2.3 From 93ed77b9bce3890f81bcde67cce898bef86c2d35 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 14:57:04 -0500 Subject: Adding properties for the new menuitems we need to build for showing applications and indicators. --- src/dbus-data.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dbus-data.h b/src/dbus-data.h index db59003..eb15bcd 100644 --- a/src/dbus-data.h +++ b/src/dbus-data.h @@ -12,4 +12,13 @@ #define LAUNCHER_MENUITEM_PROP_APP_NAME "application-name" #define LAUNCHER_MENUITEM_PROP_APP_DESC "application-description" +#define APPLICATION_MENUITEM_TYPE "application-item" +#define APPLICATION_MENUITEM_PROP_NAME "app-name" +#define APPLICATION_MENUITEM_PROP_COUNT "count" + +#define INDICATOR_MENUITEM_TYPE "indicator-item" +#define INDICATOR_MENUITEM_PROP_LABEL "label" +#define INDICATOR_MENUITEM_PROP_ICON "icon" +#define INDICATOR_MENUITEM_PROP_RIGHT "right-side-text" + #endif /* __DBUS_DATA_H__ */ -- cgit v1.2.3 From 7f0f735b408ad87ee70764485001d07806280673 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 14:59:04 -0500 Subject: Making sure these don't conflict with ones already in usage. --- src/dbus-data.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dbus-data.h b/src/dbus-data.h index eb15bcd..5ea4046 100644 --- a/src/dbus-data.h +++ b/src/dbus-data.h @@ -14,11 +14,11 @@ #define APPLICATION_MENUITEM_TYPE "application-item" #define APPLICATION_MENUITEM_PROP_NAME "app-name" -#define APPLICATION_MENUITEM_PROP_COUNT "count" +#define APPLICATION_MENUITEM_PROP_COUNT "app-count" #define INDICATOR_MENUITEM_TYPE "indicator-item" -#define INDICATOR_MENUITEM_PROP_LABEL "label" -#define INDICATOR_MENUITEM_PROP_ICON "icon" +#define INDICATOR_MENUITEM_PROP_LABEL "indicator-label" +#define INDICATOR_MENUITEM_PROP_ICON "indicator-icon" #define INDICATOR_MENUITEM_PROP_RIGHT "right-side-text" #endif /* __DBUS_DATA_H__ */ -- cgit v1.2.3 From 31a318bf3f316ef4873dc8b109e62248a226be43 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 15:28:55 -0500 Subject: Fleshing out the indicator item. It's purdy. --- src/indicator-messages.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/indicator-messages.c b/src/indicator-messages.c index c410ef7..42f2707 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -24,6 +24,7 @@ with this program. If not, see . #include #include #include +#include #include #include @@ -41,6 +42,8 @@ static GtkIconSize design_team_size; static DBusGProxy * icon_proxy = NULL; +static GtkSizeGroup * indicator_right_group = NULL; + static void attention_changed_cb (DBusGProxy * proxy, gboolean dot, gpointer userdata) { @@ -137,6 +140,54 @@ setup_icon_proxy (gpointer userdata) return FALSE; } +/* We have a small little menuitem type that handles all + of the fun stuff for indicators. Mostly this is the + shifting over and putting the icon in with some right + side text that'll be determined by the service. */ +static gboolean +new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + /* Note: not checking parent, it's reasonable for it to be NULL */ + + GtkMenuItem * gmi = GTK_MENU_ITEM(gtk_menu_item_new()); + + GtkWidget * hbox = gtk_hbox_new(FALSE, 4); + + /* Icon, probably someone's face or avatar on an IM */ + GtkWidget * icon = gtk_image_new(); + GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(newitem, INDICATOR_MENUITEM_PROP_ICON); + if (pixbuf != NULL) { + gtk_image_set_from_pixbuf(GTK_IMAGE(icon), pixbuf); + } + gtk_misc_set_alignment(GTK_MISC(icon), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0); + gtk_widget_show(icon); + + /* Label, probably a username, chat room or mailbox name */ + GtkWidget * label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_LABEL)); + gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); + gtk_widget_show(label); + + /* Usually either the time or the count on the individual + item. */ + GtkWidget * right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT)); + gtk_size_group_add_widget(indicator_right_group, right); + gtk_misc_set_alignment(GTK_MISC(right), 1.0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), right, FALSE, FALSE, 0); + gtk_widget_show(right); + + gtk_container_add(GTK_CONTAINER(gmi), hbox); + gtk_widget_show(hbox); + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); + /* TODO: Handle changes */ + + return TRUE; +} + static gboolean new_launcher_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { @@ -207,12 +258,15 @@ get_menu (void) return NULL; } + indicator_right_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); + g_idle_add(setup_icon_proxy, NULL); DbusmenuGtkMenu * menu = dbusmenu_gtkmenu_new(INDICATOR_MESSAGES_DBUS_NAME, INDICATOR_MESSAGES_DBUS_OBJECT); DbusmenuGtkClient * client = dbusmenu_gtkmenu_get_client(menu); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), LAUNCHER_MENUITEM_TYPE, new_launcher_item); + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), INDICATOR_MENUITEM_TYPE, new_indicator_item); return GTK_MENU(menu); } -- cgit v1.2.3 From b6cc96c33d4568d421195f3b360bbc5914f9118e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 15:34:11 -0500 Subject: Converting this over to an indicator menuitem. --- src/im-menu-item.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 2a5265b..4251572 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -28,6 +28,7 @@ with this program. If not, see . #include #include #include "im-menu-item.h" +#include "dbus-data.h" enum { TIME_CHANGED, @@ -150,7 +151,7 @@ im_menu_item_finalize (GObject *object) static void icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(data), DBUSMENU_MENUITEM_PROP_ICON_DATA, propertydata); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(data), INDICATOR_MENUITEM_PROP_ICON, propertydata); return; } @@ -160,7 +161,7 @@ update_time (ImMenuItem * self) ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self); if (!priv->show_time) { - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "right-column", ""); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT, ""); return; } @@ -191,7 +192,7 @@ update_time (ImMenuItem * self) } if (timestring != NULL) { - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "right-column", ""); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT, timestring); g_free(timestring); } @@ -253,7 +254,7 @@ sender_cb (IndicateListener * listener, IndicateListenerServer * server, Indicat return; } - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_LABEL, propertydata); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_LABEL, propertydata); return; } @@ -299,7 +300,7 @@ im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, priv->show_time = TRUE; priv->time_update_min = 0; - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "type", DBUSMENU_CLIENT_TYPES_IMAGE); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "type", INDICATOR_MENUITEM_TYPE); indicate_listener_get_property(listener, server, indicator, "sender", sender_cb, self); indicate_listener_get_property_time(listener, server, indicator, "time", time_cb, self); -- cgit v1.2.3 From b5f190ff40e8c3880a35568fd8ba44e442a0ba55 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 15:37:59 -0500 Subject: Dropping dep on indicate-gtk, we don't need it now that we're just passing the image data on. --- configure.ac | 1 - 1 file changed, 1 deletion(-) diff --git a/configure.ac b/configure.ac index a3d937b..b7db004 100644 --- a/configure.ac +++ b/configure.ac @@ -34,7 +34,6 @@ PKG_CHECK_MODULES(APPLET, gtk+-2.0 >= $GTK_REQUIRED_VERSION gio-unix-2.0 >= $GIO_UNIX_REQUIRED_VERSION indicator >= $INDICATOR_REQUIRED_VERSION indicate >= $INDICATE_REQUIRED_VERSION - indicate-gtk >= $INDICATE_REQUIRED_VERSION dbusmenu-gtk >= $DBUSMENUGTK_REQUIRED_VERSION) AC_SUBST(APPLET_CFLAGS) AC_SUBST(APPLET_LIBS) -- cgit v1.2.3 From 47eff60cee5bf9877f9fe4472f34f84007dbe644 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 15:38:33 -0500 Subject: Removing the indicate-gtk headers. --- src/im-menu-item.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 4251572..f913fac 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -25,8 +25,8 @@ with this program. If not, see . #include #include -#include -#include +#include +#include #include "im-menu-item.h" #include "dbus-data.h" -- cgit v1.2.3 From afd7c0690b215e6c73661183d358d3c1b728b413 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 15:55:28 -0500 Subject: Changing the properties to be the indicate v2 ones. Mostly this involves adding extra properties at this point. --- src/im-menu-item.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index f913fac..af4ebb8 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -26,6 +26,7 @@ with this program. If not, see . #include #include #include +#include #include #include "im-menu-item.h" #include "dbus-data.h" @@ -259,6 +260,20 @@ sender_cb (IndicateListener * listener, IndicateListenerServer * server, Indicat return; } +static void +count_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) +{ + g_debug("Got Count Information"); + +} + +static void +attention_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) +{ + g_debug("Got Attention Information"); + +} + static void activate_cb (ImMenuItem * self, gpointer data) { @@ -276,12 +291,20 @@ indicator_modified_cb (IndicateListener * listener, IndicateListenerServer * ser if (INDICATE_LISTENER_INDICATOR_ID(indicator) != INDICATE_LISTENER_INDICATOR_ID(priv->indicator)) return; if (server != priv->server) return; - if (!g_strcmp0(property, "sender")) { + if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_NAME)) { + indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_NAME, sender_cb, self); + } else if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_TIME)) { + indicate_listener_get_property_time(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_TIME, time_cb, self); + } else if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_ICON)) { + indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ICON, icon_cb, self); + } else if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_COUNT)) { + indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_COUNT, count_cb, self); + } else if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION)) { + indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, attention_cb, self); + } else if (!g_strcmp0(property, "sender")) { + /* This is a compatibility string with v1 and should be removed */ + g_debug("Indicator is using 'sender' property which is a v1 string."); indicate_listener_get_property(listener, server, indicator, "sender", sender_cb, self); - } else if (!g_strcmp0(property, "time")) { - indicate_listener_get_property_time(listener, server, indicator, "time", time_cb, self); - } else if (!g_strcmp0(property, "icon")) { - indicate_listener_get_property(listener, server, indicator, "icon", icon_cb, self); } return; -- cgit v1.2.3 From 1b0210cbd43099ae96ea48f817a4cef50941c9c2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:03:53 -0500 Subject: Well, you know, Oholoh says that I don't comment enough. Better put some more in. --- src/im-menu-item.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index af4ebb8..2d361ac 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -149,6 +149,8 @@ im_menu_item_finalize (GObject *object) G_OBJECT_CLASS (im_menu_item_parent_class)->finalize (object); } +/* Call back for getting icon data. It just passes it along + to the indicator so that it can visualize it. Not our problem. */ static void icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { @@ -156,6 +158,10 @@ icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateL return; } +/* This function takes the time and turns it into the appropriate + string to put on the right side of the menu item. Of course it + doesn't do that if there is a count set. If there's a count then + it gets that space. */ static void update_time (ImMenuItem * self) { @@ -200,6 +206,8 @@ update_time (ImMenuItem * self) return; } +/* This is a wrapper around update_time that matches the prototype + needed to make this a timer callback. Silly. */ static gboolean time_update_cb (gpointer data) { @@ -210,6 +218,10 @@ time_update_cb (gpointer data) return TRUE; } +/* Yet another time function. This one takes the time as formated as + we get it from libindicate and turns it into the seconds that we're + looking for. It should only be called once at the init with a new + indicator and again when the value changes. */ static void time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, GTimeVal * propertydata, gpointer data) { @@ -240,6 +252,8 @@ time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateL return; } +/* Callback from libindicate that is for getting the sender information + on a particular indicator. */ static void sender_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { @@ -260,6 +274,9 @@ sender_cb (IndicateListener * listener, IndicateListenerServer * server, Indicat return; } +/* Callback saying that the count is updated, we need to either put + that on the menu item or just remove it if the count is gone. If + that's the case we can update time. */ static void count_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { @@ -267,6 +284,9 @@ count_cb (IndicateListener * listener, IndicateListenerServer * server, Indicate } +/* This is getting the attention variable that's looking at whether + this indicator should be calling for attention or not. If we are, + we need to signal that. */ static void attention_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { @@ -274,6 +294,7 @@ attention_cb (IndicateListener * listener, IndicateListenerServer * server, Indi } +/* Callback when the item gets clicked on from the Messaging Menu */ static void activate_cb (ImMenuItem * self, gpointer data) { @@ -282,6 +303,8 @@ activate_cb (ImMenuItem * self, gpointer data) indicate_listener_display(priv->listener, priv->server, priv->indicator); } +/* Callback when a property gets modified. It figures out which one + got modified and notifies the appropriate person. */ void indicator_modified_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property, ImMenuItem * self) { -- cgit v1.2.3 From 43f6131be305835947b565d0afcc0dc11660e218 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:06:18 -0500 Subject: oops forgot to remove type from the modified one, oops. --- src/im-menu-item.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 2d361ac..75da527 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -83,7 +83,6 @@ static void activate_cb (ImMenuItem * self, static void indicator_modified_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, - gchar * type, gchar * property, ImMenuItem * self); @@ -306,7 +305,7 @@ activate_cb (ImMenuItem * self, gpointer data) /* Callback when a property gets modified. It figures out which one got modified and notifies the appropriate person. */ void -indicator_modified_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gchar * property, ImMenuItem * self) +indicator_modified_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, ImMenuItem * self) { ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self); @@ -314,6 +313,8 @@ indicator_modified_cb (IndicateListener * listener, IndicateListenerServer * ser if (INDICATE_LISTENER_INDICATOR_ID(indicator) != INDICATE_LISTENER_INDICATOR_ID(priv->indicator)) return; if (server != priv->server) return; + /* Determine which property has been changed and request the + value go to the appropriate callback. */ if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_NAME)) { indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_NAME, sender_cb, self); } else if (!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_TIME)) { -- cgit v1.2.3 From 5c2ee1f5f3604fa095f2e8c401fd71d02650067a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:12:17 -0500 Subject: Making the sender support the name attribute and clean up the code a bit. --- src/im-menu-item.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 75da527..5d397a5 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -258,13 +258,18 @@ sender_cb (IndicateListener * listener, IndicateListenerServer * server, Indicat { g_debug("Got Sender Information"); ImMenuItem * self = IM_MENU_ITEM(data); - if (self == NULL) { - g_error("Menu Item callback called without a menu item"); - return; - } - if (property == NULL || g_strcmp0(property, "sender")) { - g_warning("Sender callback called without being sent the sender. We got '%s' with value '%s'.", property, propertydata); + /* Our data should be right */ + g_return_if_fail(self != NULL); + /* We should have a property name */ + g_return_if_fail(property != NULL); + /* The Property should be sender or name */ + g_return_if_fail(!g_strcmp0(property, "sender") || !g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_NAME)); + + /* We might get the sender variable returning a + null string as it doesn't exist on newer clients + but we don't want to listen to that. */ + if (!g_strcmp0(property, "sender") && property[0] == '\0') { return; } -- cgit v1.2.3 From 1b860bf5516f760774881bbb9dec90cea75109f8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:14:21 -0500 Subject: We're tracking count instead of whether we should show the time as a boolean. --- src/im-menu-item.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 5d397a5..193b1a4 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -47,7 +47,7 @@ struct _ImMenuItemPrivate IndicateListenerIndicator * indicator; glong seconds; - gboolean show_time; + gchar * count; gulong indicator_changed; guint time_update_min; @@ -166,8 +166,7 @@ update_time (ImMenuItem * self) { ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self); - if (!priv->show_time) { - dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT, ""); + if (priv->count != NULL) { return; } @@ -349,7 +348,7 @@ im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, priv->listener = listener; priv->server = server; priv->indicator = indicator; - priv->show_time = TRUE; + priv->count = NULL; priv->time_update_min = 0; dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "type", INDICATOR_MENUITEM_TYPE); -- cgit v1.2.3 From 567920a040c541ad10dfc53844ca9f5bd1e22a21 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:15:38 -0500 Subject: Ask for all the properties up front. --- src/im-menu-item.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 193b1a4..36ae2f6 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -353,9 +353,12 @@ im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "type", INDICATOR_MENUITEM_TYPE); + indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_NAME, sender_cb, self); + indicate_listener_get_property_time(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_TIME, time_cb, self); + indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ICON, icon_cb, self); + indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_COUNT, count_cb, self); + indicate_listener_get_property(listener, server, indicator, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION, attention_cb, self); indicate_listener_get_property(listener, server, indicator, "sender", sender_cb, self); - indicate_listener_get_property_time(listener, server, indicator, "time", time_cb, self); - indicate_listener_get_property(listener, server, indicator, "icon", icon_cb, self); g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL); priv->indicator_changed = g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_INDICATOR_MODIFIED, G_CALLBACK(indicator_modified_cb), self); -- cgit v1.2.3 From 5ce56eed0dd09f122f175971a093f07c81741206 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:22:49 -0500 Subject: Fleshing out the count item --- src/im-menu-item.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 36ae2f6..11381cf 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -284,7 +284,36 @@ static void count_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { g_debug("Got Count Information"); + ImMenuItem * self = IM_MENU_ITEM(data); + /* Our data should be right */ + g_return_if_fail(self != NULL); + /* We should have a property name */ + g_return_if_fail(property != NULL); + /* The Property should be count */ + g_return_if_fail(!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_COUNT)); + + ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self); + + if (propertydata == NULL || propertydata[0] == '\0') { + /* The count is either being unset or it was never + set in the first place. */ + if (priv->count != NULL) { + g_free(priv->count); + priv->count = NULL; + update_time(self); + } + return; + } + + if (priv->count != NULL) { + g_free(priv->count); + } + + priv->count = g_strdup_printf("(%s)", propertydata); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), INDICATOR_MENUITEM_PROP_RIGHT, priv->count); + + return; } /* This is getting the attention variable that's looking at whether -- cgit v1.2.3 From c3637d885d7800bbcf045436b4b28d19a4b04fb0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:24:55 -0500 Subject: Adding in a signal for when the attention changes. --- src/im-menu-item.c | 8 ++++++++ src/im-menu-item.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 11381cf..fd93cc7 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -33,6 +33,7 @@ with this program. If not, see . enum { TIME_CHANGED, + ATTENTION_CHANGED, LAST_SIGNAL }; @@ -105,6 +106,13 @@ im_menu_item_class_init (ImMenuItemClass *klass) NULL, NULL, g_cclosure_marshal_VOID__LONG, G_TYPE_NONE, 1, G_TYPE_LONG); + signals[ATTENTION_CHANGED] = g_signal_new(IM_MENU_ITEM_SIGNAL_ATTENTION_CHANGED, + G_TYPE_FROM_CLASS(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ImMenuItemClass, attention_changed), + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); return; } diff --git a/src/im-menu-item.h b/src/im-menu-item.h index 8d0c273..5ae4f82 100644 --- a/src/im-menu-item.h +++ b/src/im-menu-item.h @@ -38,6 +38,7 @@ G_BEGIN_DECLS #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" +#define IM_MENU_ITEM_SIGNAL_ATTENTION_CHANGED "attention-changed" typedef struct _ImMenuItem ImMenuItem; typedef struct _ImMenuItemClass ImMenuItemClass; @@ -46,6 +47,7 @@ struct _ImMenuItemClass { DbusmenuMenuitemClass parent_class; void (*time_changed) (glong seconds); + void (*attention_changed) (gboolean requestit); }; struct _ImMenuItem { -- cgit v1.2.3 From 9533ec199b1fb11a911de5d8859f946af6a6f060 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:29:00 -0500 Subject: Adding an attention variable and a function to access it. --- src/im-menu-item.c | 17 +++++++++++++++++ src/im-menu-item.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index fd93cc7..ee91f71 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -50,6 +50,7 @@ struct _ImMenuItemPrivate glong seconds; gchar * count; gulong indicator_changed; + gboolean attention; guint time_update_min; }; @@ -387,6 +388,7 @@ im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, priv->indicator = indicator; priv->count = NULL; priv->time_update_min = 0; + priv->attention = FALSE; dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), "type", INDICATOR_MENUITEM_TYPE); @@ -403,9 +405,24 @@ im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, return self; } +/* Gets the number of seconds for the creator + of this item. */ glong im_menu_item_get_seconds (ImMenuItem * menuitem) { + g_return_val_if_fail(IS_IM_MENU_ITEM(menuitem), 0); + ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(menuitem); return priv->seconds; } + +/* Gets whether or not this indicator item is + asking for attention or not. */ +gboolean +im_menu_item_get_attention (ImMenuItem * menuitem) +{ + g_return_val_if_fail(IS_IM_MENU_ITEM(menuitem), FALSE); + + ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(menuitem); + return priv->attention; +} diff --git a/src/im-menu-item.h b/src/im-menu-item.h index 5ae4f82..1ec9bf0 100644 --- a/src/im-menu-item.h +++ b/src/im-menu-item.h @@ -57,6 +57,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); +gboolean im_menu_item_get_attention (ImMenuItem * menuitem); G_END_DECLS -- cgit v1.2.3 From e740035a0d5605e07034ea026948cec8da3b3ee7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:32:39 -0500 Subject: Fleshing out the attention_cb to make it record the value and signal on changes. --- src/im-menu-item.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index ee91f71..d64a917 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -332,7 +332,30 @@ static void attention_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { g_debug("Got Attention Information"); + ImMenuItem * self = IM_MENU_ITEM(data); + + /* Our data should be right */ + g_return_if_fail(self != NULL); + /* We should have a property name */ + g_return_if_fail(property != NULL); + /* The Property should be count */ + g_return_if_fail(!g_strcmp0(property, INDICATE_INDICATOR_MESSAGES_PROP_ATTENTION)); + ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self); + + gboolean wantit; + if (propertydata == NULL || propertydata[0] == '\0' || !g_strcmp0(propertydata, "false")) { + wantit = FALSE; + } else { + wantit = TRUE; + } + + if (priv->attention != wantit) { + priv->attention = wantit; + g_signal_emit(G_OBJECT(self), signals[ATTENTION_CHANGED], 0, wantit, TRUE); + } + + return; } /* Callback when the item gets clicked on from the Messaging Menu */ -- cgit v1.2.3 From 486c49f150ed875ee1f39a002d6fe95efc7b208f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 16:46:48 -0500 Subject: Setting the property on the dbusmenu menuitem as well --- src/im-menu-item.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 52cf80c..7f82dba 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -478,6 +478,7 @@ im_menu_item_show (ImMenuItem * menuitem, gboolean show) again if we're being shown, otherwise no. */ g_signal_emit(G_OBJECT(menuitem), signals[ATTENTION_CHANGED], 0, priv->show, TRUE); } + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(menuitem), DBUSMENU_MENUITEM_PROP_VISIBLE, priv->show ? "true" : "false"); return; } -- cgit v1.2.3 From e16fd98511c81dceef2f063fe7a67f384713a8bc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 17:14:23 -0500 Subject: Defining the max number of indicators and telling the server about it. --- src/app-menu-item.c | 2 ++ src/dbus-data.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index feb780d..ecb5b5d 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -27,6 +27,7 @@ with this program. If not, see . #include #include #include "app-menu-item.h" +#include "dbus-data.h" enum { COUNT_CHANGED, @@ -173,6 +174,7 @@ app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server) indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_DISPLAY); indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_SIGNAL); + indicate_listener_set_server_max_indicators(listener, server, MAX_NUMBER_OF_INDICATORS); return self; } diff --git a/src/dbus-data.h b/src/dbus-data.h index 5ea4046..9f53f94 100644 --- a/src/dbus-data.h +++ b/src/dbus-data.h @@ -21,4 +21,6 @@ #define INDICATOR_MENUITEM_PROP_ICON "indicator-icon" #define INDICATOR_MENUITEM_PROP_RIGHT "right-side-text" +#define MAX_NUMBER_OF_INDICATORS 7 + #endif /* __DBUS_DATA_H__ */ -- cgit v1.2.3 From cecbadf9b10264eab61dc82ca259b07250b830fe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 17:21:30 -0500 Subject: Hiding the items that go over our bounds. That's how it is. Hard, hard, limits. --- src/messages-service.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index c59edc2..f7c879f 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -693,6 +693,18 @@ indicator_added (IndicateListener * listener, IndicateListenerServer * server, I 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); + /* Check the length of the list. If we've got more inidactors + than we allow. Well. Someone's gotta pay. Sorry. I didn't + want to do this, but you did it to yourself. */ + if (g_list_length(sl_item->imList) > MAX_NUMBER_OF_INDICATORS) { + GList * indicatoritem; + gint count; + for (indicatoritem = sl_item->imList, count = 0; indicatoritem != NULL; indicatoritem = g_list_next(indicatoritem), count++) { + imList_t * im = (imList_t *)indicatoritem->data; + im_menu_item_show(IM_MENU_ITEM(im->menuitem), count < MAX_NUMBER_OF_INDICATORS); + } + } + /* Placing the item into the shell. Look to see if we can find our server and slip in there. Otherwise we'll just append. */ -- cgit v1.2.3 From e8505fb54db95018b89d29682f507fbb8e56cad2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 17:31:29 -0500 Subject: Adding in a small function to access the show variable. --- src/im-menu-item.c | 12 ++++++++++++ src/im-menu-item.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 7f82dba..03cea5e 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -482,3 +482,15 @@ im_menu_item_show (ImMenuItem * menuitem, gboolean show) return; } + +/* Check to see if this item is shown. Accessor for the + internal variable. */ +gboolean +im_menu_item_shown (ImMenuItem * menuitem) +{ + g_return_val_if_fail(IS_IM_MENU_ITEM(menuitem), FALSE); + + ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(menuitem); + + return priv->show; +} diff --git a/src/im-menu-item.h b/src/im-menu-item.h index 244c32a..4279c2e 100644 --- a/src/im-menu-item.h +++ b/src/im-menu-item.h @@ -59,6 +59,7 @@ ImMenuItem * im_menu_item_new (IndicateListener * listener, IndicateListenerServ glong im_menu_item_get_seconds (ImMenuItem * menuitem); gboolean im_menu_item_get_attention (ImMenuItem * menuitem); void im_menu_item_show (ImMenuItem * menuitem, gboolean show); +gboolean im_menu_item_shown (ImMenuItem * menuitem); G_END_DECLS -- cgit v1.2.3 From cb98b75a8ed64e1fd815b412b007ead62d46aace Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 17:31:54 -0500 Subject: If the item was shown, and we're in an overload case, we need to find someone else to show when we're dying. --- src/messages-service.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index f7c879f..e5024fe 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -758,6 +758,18 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, g_signal_handler_disconnect(menuitem, ilt->timechange_cb); g_free(ilt); + if (im_menu_item_shown(IM_MENU_ITEM(menuitem)) && g_list_length(sl_item->imList) >= MAX_NUMBER_OF_INDICATORS) { + /* In this case we need to show a different indicator + becasue a shown one has left. But we're going to be + easy and set all the values. */ + GList * indicatoritem; + gint count; + for (indicatoritem = sl_item->imList, count = 0; indicatoritem != NULL; indicatoritem = g_list_next(indicatoritem), count++) { + imList_t * im = (imList_t *)indicatoritem->data; + im_menu_item_show(IM_MENU_ITEM(im->menuitem), count < MAX_NUMBER_OF_INDICATORS); + } + } + dbusmenu_menuitem_property_set(menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, "false"); dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), menuitem); removed = TRUE; -- cgit v1.2.3 From addb7fac30af90d62e3081c40a3aad37e65b9398 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 20:30:53 -0500 Subject: Adding an attention parameter to the server and initing it. --- src/messages-service.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index e5024fe..8089375 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -71,6 +71,7 @@ typedef struct _serverList_t serverList_t; struct _serverList_t { IndicateListenerServer * server; AppMenuItem * menuitem; + gboolean attention; GList * imList; }; @@ -421,6 +422,7 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha sl_item->server = server; sl_item->menuitem = menuitem; sl_item->imList = NULL; + sl_item->attention = FALSE; /* Incase we got an indicator first */ GList * alreadythere = g_list_find_custom(serverList, sl_item, serverList_equal); @@ -683,6 +685,7 @@ indicator_added (IndicateListener * listener, IndicateListenerServer * server, I sl_item->server = server; sl_item->menuitem = NULL; sl_item->imList = NULL; + sl_item->attention = FALSE; serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); } else { -- cgit v1.2.3 From 467063d1291347dd04fd28acdb30facc4858df3f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 20:54:48 -0500 Subject: Reworking how we handle the server count changing and how that makes us check for attention now. --- src/messages-service.c | 85 +++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index 8089375..6dafa97 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -72,6 +72,7 @@ struct _serverList_t { IndicateListenerServer * server; AppMenuItem * menuitem; gboolean attention; + guint count; GList * imList; }; @@ -391,6 +392,25 @@ blacklist_dir_changed (GFileMonitor * monitor, GFile * file, GFile * other_file, * More code */ +/* Goes through all the servers and sees if any of them + want attention. If they do, then well we'll give it + to them. If they don't, let's not bother the user + any, shall we? */ +static void +check_attention (void) +{ + GList * pointer; + for (pointer = serverList; pointer != NULL; pointer = g_list_next(pointer)) { + serverList_t * slt = (serverList_t *)pointer->data; + if (slt->attention) { + message_service_dbus_set_attention(dbus_interface, TRUE); + return; + } + } + message_service_dbus_set_attention(dbus_interface, FALSE); + return; +} + static void server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { @@ -414,10 +434,10 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha return; } + /* Build the Menu item */ 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); + /* Build a possible server structure */ serverList_t * sl_item = g_new0(serverList_t, 1); sl_item->server = server; sl_item->menuitem = menuitem; @@ -427,14 +447,20 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha /* Incase we got an indicator first */ GList * alreadythere = g_list_find_custom(serverList, sl_item, serverList_equal); if (alreadythere != NULL) { + /* Use the one we already had */ g_free(sl_item); sl_item = (serverList_t *)alreadythere->data; sl_item->menuitem = menuitem; serverList = g_list_sort(serverList, serverList_sort); } else { + /* Insert the new one in the list */ serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); } + /* Connect the signals up to the menu item */ + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_COUNT_CHANGED, G_CALLBACK(server_count_changed), sl_item); + g_signal_connect(G_OBJECT(menuitem), APP_MENU_ITEM_SIGNAL_NAME_CHANGED, G_CALLBACK(server_name_changed), menushell); + dbusmenu_menuitem_child_append(menushell, DBUSMENU_MENUITEM(menuitem)); /* Should be prepend ^ */ @@ -453,47 +479,24 @@ server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data) return; } +/* If the count on the server changes, we need to know + whether that should be grabbing attention or not. If + it is, we need to reevaluate whether the whole thing + should be grabbing attention or not. */ 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; - message_service_dbus_set_attention(dbus_interface, TRUE); - 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. */ + serverList_t * slt = (serverList_t *)data; + slt->count = count; - 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 (count == 0 && slt->attention) { + slt->attention = FALSE; + check_attention(); } - if (!we_have_indicators) { - g_debug("Setting image to boring"); - showing_new_icon = FALSE; - message_service_dbus_set_attention(dbus_interface, FALSE); + if (count != 0 && !slt->attention) { + slt->attention = TRUE; + check_attention(); } return; @@ -538,10 +541,14 @@ server_removed (IndicateListener * listener, IndicateListenerServer * server, gc g_object_unref(G_OBJECT(sltp->menuitem)); } + if (sltp->attention) { + /* Check to see if this was the server causing the menu item to + be lit up. */ + check_attention(); + } + g_free(sltp); - /* Simulate a server saying zero to recalculate icon */ - server_count_changed(NULL, 0, NULL); check_hidden(); return; -- cgit v1.2.3 From 2a87b9c42f64cd97c60c2d21733bba9f4625e8cc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 21:02:21 -0500 Subject: Oops, a little silly before. We really need to check the indicators as well, we can't just clear the attention for the count value. --- src/messages-service.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/messages-service.c b/src/messages-service.c index 6dafa97..2467dd4 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -411,6 +411,23 @@ check_attention (void) return; } +/* This checks a server listing to see if it should + have attention. It can get attention through it's + count or by having an indicator that is requestion + attention. */ +static void +server_attention (serverList_t * slt) +{ + /* Count, easy yes and out. */ + if (slt->count > 0) { + slt->attention = TRUE; + return; + } + + + return; +} + static void server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { @@ -490,13 +507,18 @@ server_count_changed (AppMenuItem * appitem, guint count, gpointer data) slt->count = count; if (count == 0 && slt->attention) { - slt->attention = FALSE; - check_attention(); + /* Regen based on indicators if the count isn't going to cause it. */ + server_attention(slt); + /* If we're dropping let's see if we're the last. */ + if (!slt->attention) { + check_attention(); + } } if (count != 0 && !slt->attention) { slt->attention = TRUE; - check_attention(); + /* Let's tell everyone about us! */ + message_service_dbus_set_attention(dbus_interface, TRUE); } return; -- cgit v1.2.3 From 30926eccbe28028ae88294fa597bfa2217ccaa41 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 21:13:10 -0500 Subject: Initializing count --- src/messages-service.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 2467dd4..b6374f0 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -460,6 +460,7 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha sl_item->menuitem = menuitem; sl_item->imList = NULL; sl_item->attention = FALSE; + sl_item->count = 0; /* Incase we got an indicator first */ GList * alreadythere = g_list_find_custom(serverList, sl_item, serverList_equal); @@ -715,6 +716,7 @@ indicator_added (IndicateListener * listener, IndicateListenerServer * server, I sl_item->menuitem = NULL; sl_item->imList = NULL; sl_item->attention = FALSE; + sl_item->count = 0; serverList = g_list_insert_sorted(serverList, sl_item, serverList_sort); } else { -- cgit v1.2.3 From 8e7605cf161650a699449d95d39dd02231ab9142 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 21:16:01 -0500 Subject: Fleshing out checking server attention by looking at all the indicators. --- src/messages-service.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index b6374f0..764bcf4 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -424,7 +424,16 @@ server_attention (serverList_t * slt) return; } + GList * pointer; + for (pointer = slt->imList; pointer != NULL; pointer = g_list_next(pointer)) { + imList_t * ilt = (imList_t *)pointer->data; + if (im_menu_item_get_attention(IM_MENU_ITEM(ilt->menuitem))) { + slt->attention = TRUE; + return; + } + } + slt->attention = FALSE; return; } -- cgit v1.2.3 From 01e4df1dbd970e35f209150b67f0c296e01d4f32 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 21:17:59 -0500 Subject: Comments. --- src/messages-service.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 764bcf4..dbc4d15 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -424,6 +424,7 @@ server_attention (serverList_t * slt) return; } + /* Check to see if any of the indicators want attention */ GList * pointer; for (pointer = slt->imList; pointer != NULL; pointer = g_list_next(pointer)) { imList_t * ilt = (imList_t *)pointer->data; @@ -433,10 +434,14 @@ server_attention (serverList_t * slt) } } + /* Nope, no one */ slt->attention = FALSE; return; } +/* A new server has been created on the indicate bus. + We need to check to see if we like it. And build + structures for it if so. */ static void server_added (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { @@ -497,6 +502,10 @@ server_added (IndicateListener * listener, IndicateListenerServer * server, gcha return; } +/* The name of a server has changed, we probably + need to reorder the menu to keep it in alphabetical + order. This happens often after we read the destkop + file from disk. */ static void server_name_changed (AppMenuItem * appitem, gchar * name, gpointer data) { -- cgit v1.2.3 From bbbc78a5a802f67478eedba9f34b9bc769076b62 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 21:31:26 -0500 Subject: Processing the attention when an indicator leaves the building. --- src/messages-service.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index dbc4d15..57094d3 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -776,6 +776,10 @@ indicator_added (IndicateListener * listener, IndicateListenerServer * server, I return; } +/* Process and indicator getting removed from the system. We + first need to ensure that it's one of ours and figure out + where we put it. When we find all that out we can go through + the process of removing the effect it had on the system. */ static void indicator_removed (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gpointer data) { @@ -783,11 +787,13 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, gboolean removed = FALSE; + /* Find the server that was related to this item */ 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) { + /* We didn't care about that server */ return; } sl_item = (serverList_t *)serverentry->data; @@ -805,11 +811,26 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, menuitem = ilt->menuitem; } + /* If we found a menu item and an imList_t item then + we can go ahead and remove it. Otherwise we can + skip this and exit. */ 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); + if (im_menu_item_get_attention(IM_MENU_ITEM(menuitem)) && im_menu_item_shown(IM_MENU_ITEM(menuitem))) { + /* If the removed indicator menu item was asking for + attention we need to see if this server should still + be asking for attention. */ + server_attention(sl_item); + /* If the server is no longer asking for attention then + we need to check if the whole system should be. */ + if (!sl_item->attention) { + check_attention(); + } + } + if (im_menu_item_shown(IM_MENU_ITEM(menuitem)) && g_list_length(sl_item->imList) >= MAX_NUMBER_OF_INDICATORS) { /* In this case we need to show a different indicator becasue a shown one has left. But we're going to be @@ -822,6 +843,8 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, } } + /* Hide the item immediately, and then remove it + which might take a little longer. */ dbusmenu_menuitem_property_set(menuitem, DBUSMENU_MENUITEM_PROP_VISIBLE, "false"); dbusmenu_menuitem_child_delete(DBUSMENU_MENUITEM(data), menuitem); removed = TRUE; -- cgit v1.2.3 From f7cbbad880d7412004429888f0fe8bb4e809499d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 21:59:46 -0500 Subject: Connecting into the attention signal. --- src/messages-service.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 57094d3..7f80620 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -114,6 +114,7 @@ struct _imList_t { IndicateListenerIndicator * indicator; DbusmenuMenuitem * menuitem; gulong timechange_cb; + gulong attentionchange_cb; }; static gboolean @@ -543,6 +544,9 @@ server_count_changed (AppMenuItem * appitem, guint count, gpointer data) return; } +/* Respond to the IM entrie's time changing + which results in it needing to resort the list + and rebuild the menu to match. */ static void im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data) { @@ -552,6 +556,15 @@ im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data) return; } +/* The IM entrie's request for attention has changed + so we need to pass that up the stack. */ +static void +im_attention_changed (ImMenuItem * imitem, gboolean requestit, gpointer data) +{ + + return; +} + static void server_removed (IndicateListener * listener, IndicateListenerServer * server, gchar * type, gpointer data) { @@ -744,6 +757,7 @@ indicator_added (IndicateListener * listener, IndicateListenerServer * server, I /* Added a this entry into the 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); + listItem->attentionchange_cb = g_signal_connect(G_OBJECT(menuitem), IM_MENU_ITEM_SIGNAL_ATTENTION_CHANGED, G_CALLBACK(im_attention_changed), sl_item); /* Check the length of the list. If we've got more inidactors than we allow. Well. Someone's gotta pay. Sorry. I didn't @@ -817,6 +831,7 @@ indicator_removed (IndicateListener * listener, IndicateListenerServer * server, if (!removed && menuitem != NULL) { sl_item->imList = g_list_remove(sl_item->imList, ilt); g_signal_handler_disconnect(menuitem, ilt->timechange_cb); + g_signal_handler_disconnect(menuitem, ilt->attentionchange_cb); g_free(ilt); if (im_menu_item_get_attention(IM_MENU_ITEM(menuitem)) && im_menu_item_shown(IM_MENU_ITEM(menuitem))) { -- cgit v1.2.3 From d03f5dfaafc6d8eccc2f04865d062615df4167cb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 22:06:42 -0500 Subject: Fleshing out indicator changing the attention parameter. --- src/messages-service.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/messages-service.c b/src/messages-service.c index 7f80620..f7b869e 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -561,6 +561,17 @@ im_time_changed (ImMenuItem * imitem, glong seconds, gpointer data) static void im_attention_changed (ImMenuItem * imitem, gboolean requestit, gpointer data) { + serverList_t * sl = (serverList_t *)data; + + if (requestit) { + sl->attention = TRUE; + message_service_dbus_set_attention(dbus_interface, TRUE); + } else { + server_attention(sl); + if (!sl->attention) { + check_attention(); + } + } return; } -- cgit v1.2.3 From 13108917542ba7a92759f311f02530a24f36dc06 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 22:18:46 -0500 Subject: We don't need to be tracking the added and removed signals for indicators anymore. --- src/app-menu-item.c | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index ecb5b5d..5107540 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -61,8 +61,6 @@ 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); static void update_label (AppMenuItem * self); @@ -121,9 +119,6 @@ app_menu_item_dispose (GObject *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); - g_object_unref(priv->listener); G_OBJECT_CLASS (app_menu_item_parent_class)->dispose (object); @@ -164,9 +159,6 @@ app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server) priv->server = server; /* Can not ref as not real GObject */ - 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_removed_cb), self); - indicate_listener_server_get_type(listener, server, type_cb, self); indicate_listener_server_get_desktop(listener, server, desktop_cb, self); @@ -270,46 +262,6 @@ activate_cb (AppMenuItem * self, gpointer data) return; } -static void -indicator_added_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * type, gpointer data) -{ - g_return_if_fail(IS_APP_MENU_ITEM(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++; - - update_label(APP_MENU_ITEM(data)); - g_signal_emit(G_OBJECT(data), signals[COUNT_CHANGED], 0, priv->unreadcount, 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; - } - - /* 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, priv->unreadcount, TRUE); - - return; -} - guint app_menu_item_get_count (AppMenuItem * appitem) { -- cgit v1.2.3 From 3e060f4b38af60b843984ed67dd898b87fe6350b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 22:32:49 -0500 Subject: Removing the count on the label boolean as we're detecting that differently now. --- src/app-menu-item.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 5107540..5df4e97 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -48,7 +48,6 @@ struct _AppMenuItemPrivate GAppInfo * appinfo; gchar * desktop; guint unreadcount; - gboolean count_on_label; }; #define APP_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), APP_MENU_ITEM_TYPE, AppMenuItemPrivate)) @@ -107,8 +106,6 @@ app_menu_item_init (AppMenuItem *self) priv->appinfo = NULL; priv->desktop = NULL; priv->unreadcount = 0; - priv->count_on_label = FALSE; - return; } @@ -189,16 +186,9 @@ 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"))) { - /* For IM and Microblogging we want the individual items, not a count */ - priv->count_on_label = TRUE; - update_label(self); - - indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_COUNT); - } else { - indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_DISPLAY); - indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_SIGNAL); - } + indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_COUNT); + indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_DISPLAY); + indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_SIGNAL); return; } @@ -208,7 +198,7 @@ update_label (AppMenuItem * self) { AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); - if (priv->count_on_label && !priv->unreadcount < 1) { + if (priv->unreadcount > 0) { /* 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)"), app_menu_item_get_name(self), priv->unreadcount); -- cgit v1.2.3 From 6533f296498545bc4b46590cea25707228869ce0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 4 Sep 2009 23:55:52 -0500 Subject: Replacing type with count --- src/app-menu-item.c | 53 +++++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index 5df4e97..b20c426 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -24,6 +24,7 @@ with this program. If not, see . #include "config.h" #endif +#include #include #include #include "app-menu-item.h" @@ -58,7 +59,7 @@ static void app_menu_item_init (AppMenuItem *self); static void app_menu_item_dispose (GObject *object); 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 count_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); static void desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); static void update_label (AppMenuItem * self); @@ -156,41 +157,19 @@ app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server) priv->server = server; /* Can not ref as not real GObject */ - indicate_listener_server_get_type(listener, server, type_cb, self); indicate_listener_server_get_desktop(listener, server, desktop_cb, self); + indicate_listener_server_get_count(listener, server, count_cb, self); g_signal_connect(G_OBJECT(self), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(activate_cb), NULL); indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_DISPLAY); indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_SERVER_SIGNAL); - indicate_listener_set_server_max_indicators(listener, server, MAX_NUMBER_OF_INDICATORS); - - return self; -} - -static void -type_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) -{ - AppMenuItem * self = APP_MENU_ITEM(data); - AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); - - if (priv->type != NULL) { - g_free(priv->type); - priv->type = NULL; - } - - if (value == NULL) { - g_warning("Type value is NULL, that shouldn't really happen"); - return; - } - - priv->type = g_strdup(value); - indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_COUNT); indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_DISPLAY); indicate_listener_server_show_interest(listener, server, INDICATE_INTEREST_INDICATOR_SIGNAL); + indicate_listener_set_server_max_indicators(listener, server, MAX_NUMBER_OF_INDICATORS); - return; + return self; } static void @@ -211,6 +190,28 @@ update_label (AppMenuItem * self) return; } +/* Callback for getting the count property off + of the server. */ +static void +count_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) +{ + AppMenuItem * self = APP_MENU_ITEM(data); + AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + + int count = atoi(value); + if (priv->unreadcount != count) { + priv->unreadcount = count; + update_label(self); + g_signal_emit(G_OBJECT(self), signals[COUNT_CHANGED], 0, priv->unreadcount, TRUE); + } + + return; +} + +/* Callback for when we ask the server for the path + to it's desktop file. We then turn it into an + app structure and start sucking data out of it. + Mostly the name. */ static void desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) { -- cgit v1.2.3 From a081622756ff3cecfa42d6f623ae69c5806c5bcd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sat, 5 Sep 2009 11:08:59 -0500 Subject: Setting up the listener signal to make it so that we know when the count changes. Using the property call back and just calling that function. --- src/app-menu-item.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index b20c426..ba71ef5 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -59,12 +59,12 @@ static void app_menu_item_init (AppMenuItem *self); static void app_menu_item_dispose (GObject *object); static void app_menu_item_finalize (GObject *object); static void activate_cb (AppMenuItem * self, gpointer data); +static void count_changed (IndicateListener * listener, IndicateListenerServer * server, guint count, gpointer data); static void count_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); static void desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); static void update_label (AppMenuItem * self); - - +/* GObject Boilerplate */ G_DEFINE_TYPE (AppMenuItem, app_menu_item, DBUSMENU_TYPE_MENUITEM); static void @@ -152,11 +152,17 @@ app_menu_item_new (IndicateListener * listener, IndicateListenerServer * server) AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); + /* Copy the listener so we can use it later */ priv->listener = listener; g_object_ref(G_OBJECT(listener)); - priv->server = server; + /* Can not ref as not real GObject */ + priv->server = server; + + /* Set up listener signals */ + g_signal_connect(G_OBJECT(listener), INDICATE_LISTENER_SIGNAL_SERVER_COUNT_CHANGED, G_CALLBACK(count_changed), self); + /* Get the values we care about from the server */ indicate_listener_server_get_desktop(listener, server, desktop_cb, self); indicate_listener_server_get_count(listener, server, count_cb, self); @@ -190,15 +196,16 @@ update_label (AppMenuItem * self) return; } -/* Callback for getting the count property off - of the server. */ -static void -count_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) +/* Callback to the signal that the server count + has changed to a new value. This checks to see if + it's actually changed and if so signals everyone and + updates the label. */ +static void +count_changed (IndicateListener * listener, IndicateListenerServer * server, guint count, gpointer data) { AppMenuItem * self = APP_MENU_ITEM(data); AppMenuItemPrivate * priv = APP_MENU_ITEM_GET_PRIVATE(self); - int count = atoi(value); if (priv->unreadcount != count) { priv->unreadcount = count; update_label(self); @@ -208,6 +215,20 @@ count_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * return; } +/* Callback for getting the count property off + of the server. */ +static void +count_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) +{ + g_return_if_fail(value != NULL); + g_return_if_fail(value[0] != '\0'); + + int count = atoi(value); + count_changed(listener, server, count, data); + + return; +} + /* Callback for when we ask the server for the path to it's desktop file. We then turn it into an app structure and start sucking data out of it. -- cgit v1.2.3 From 29ae116e82c75e40a57b89b0c6455de45092c645 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sat, 5 Sep 2009 11:43:13 -0500 Subject: Fixing as I fixed the libindicate API, we shouldn't have to do an atoi here. --- src/app-menu-item.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index ba71ef5..fc96ed6 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -60,7 +60,7 @@ static void app_menu_item_dispose (GObject *object); static void app_menu_item_finalize (GObject *object); static void activate_cb (AppMenuItem * self, gpointer data); static void count_changed (IndicateListener * listener, IndicateListenerServer * server, guint count, gpointer data); -static void count_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); +static void count_cb (IndicateListener * listener, IndicateListenerServer * server, guint value, gpointer data); static void desktop_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data); static void update_label (AppMenuItem * self); @@ -218,14 +218,9 @@ count_changed (IndicateListener * listener, IndicateListenerServer * server, gui /* Callback for getting the count property off of the server. */ static void -count_cb (IndicateListener * listener, IndicateListenerServer * server, gchar * value, gpointer data) +count_cb (IndicateListener * listener, IndicateListenerServer * server, guint value, gpointer data) { - g_return_if_fail(value != NULL); - g_return_if_fail(value[0] != '\0'); - - int count = atoi(value); - count_changed(listener, server, count, data); - + count_changed(listener, server, value, data); return; } -- cgit v1.2.3 From e7abefb09efca68e2101def3ff445d546fe74bac Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sat, 5 Sep 2009 11:43:36 -0500 Subject: No atoi, no stdlib.h, that's how it is. --- src/app-menu-item.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app-menu-item.c b/src/app-menu-item.c index fc96ed6..aa0b60c 100644 --- a/src/app-menu-item.c +++ b/src/app-menu-item.c @@ -24,7 +24,6 @@ with this program. If not, see . #include "config.h" #endif -#include #include #include #include "app-menu-item.h" -- cgit v1.2.3 From 990756858a90aec22d0e1bf001a97208fc1a699f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 8 Sep 2009 20:18:08 -0500 Subject: Adding in support for properties changing on the indicator menu item on the visualization side of things. --- src/indicator-messages.c | 67 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 42f2707..3dbc217 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -140,6 +140,39 @@ setup_icon_proxy (gpointer userdata) return FALSE; } +typedef struct _indicator_item_t indicator_item_t; +struct _indicator_item_t { + GtkWidget * icon; + GtkWidget * label; + GtkWidget * right; +}; + +/* Whenever we have a property change on a DbusmenuMenuitem + we need to be responsive to that. */ +static void +indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, indicator_item_t * mi_data) +{ + if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_LABEL)) { + /* Set the main label */ + gtk_label_set_text(GTK_LABEL(mi_data->label), value); + } else if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_RIGHT)) { + /* Set the right label */ + gtk_label_set_text(GTK_LABEL(mi_data->right), value); + } else if (!g_strcmp0(prop, INDICATOR_MENUITEM_PROP_ICON)) { + /* We don't use the value here, which is probably less efficient, + but it's easier to use the easy function. And since th value + is already cached, shouldn't be a big deal really. */ + GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(newitem, INDICATOR_MENUITEM_PROP_ICON); + if (pixbuf != NULL) { + gtk_image_set_from_pixbuf(GTK_IMAGE(mi_data->icon), pixbuf); + } + } else { + g_warning("Indicator Item property '%s' unknown", prop); + } + + return; +} + /* We have a small little menuitem type that handles all of the fun stuff for indicators. Mostly this is the shifting over and putting the icon in with some right @@ -147,6 +180,8 @@ setup_icon_proxy (gpointer userdata) static gboolean new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { + indicator_item_t * mi_data = g_new0(indicator_item_t, 1); + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); /* Note: not checking parent, it's reasonable for it to be NULL */ @@ -156,34 +191,36 @@ new_indicator_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm GtkWidget * hbox = gtk_hbox_new(FALSE, 4); /* Icon, probably someone's face or avatar on an IM */ - GtkWidget * icon = gtk_image_new(); + mi_data->icon = gtk_image_new(); GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(newitem, INDICATOR_MENUITEM_PROP_ICON); if (pixbuf != NULL) { - gtk_image_set_from_pixbuf(GTK_IMAGE(icon), pixbuf); + gtk_image_set_from_pixbuf(GTK_IMAGE(mi_data->icon), pixbuf); } - gtk_misc_set_alignment(GTK_MISC(icon), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), icon, FALSE, FALSE, 0); - gtk_widget_show(icon); + gtk_misc_set_alignment(GTK_MISC(mi_data->icon), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), mi_data->icon, FALSE, FALSE, 0); + gtk_widget_show(mi_data->icon); /* Label, probably a username, chat room or mailbox name */ - GtkWidget * label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_LABEL)); - gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); - gtk_widget_show(label); + mi_data->label = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_LABEL)); + gtk_misc_set_alignment(GTK_MISC(mi_data->label), 0.0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), mi_data->label, TRUE, TRUE, 0); + gtk_widget_show(mi_data->label); /* Usually either the time or the count on the individual item. */ - GtkWidget * right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT)); - gtk_size_group_add_widget(indicator_right_group, right); - gtk_misc_set_alignment(GTK_MISC(right), 1.0, 0.5); - gtk_box_pack_start(GTK_BOX(hbox), right, FALSE, FALSE, 0); - gtk_widget_show(right); + mi_data->right = gtk_label_new(dbusmenu_menuitem_property_get(newitem, INDICATOR_MENUITEM_PROP_RIGHT)); + gtk_size_group_add_widget(indicator_right_group, mi_data->right); + gtk_misc_set_alignment(GTK_MISC(mi_data->right), 1.0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), mi_data->right, FALSE, FALSE, 0); + gtk_widget_show(mi_data->right); gtk_container_add(GTK_CONTAINER(gmi), hbox); gtk_widget_show(hbox); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, gmi, parent); - /* TODO: Handle changes */ + + g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(indicator_prop_change_cb), mi_data); + g_signal_connect(G_OBJECT(newitem), "destroyed", G_CALLBACK(g_free), mi_data); return TRUE; } -- cgit v1.2.3 From c16260bbe714ef79c48e40a27b84eaf92b8253d6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 8 Sep 2009 20:18:34 -0500 Subject: Checking the wrong variable, let's not get caught by those legacy guys ;) --- src/im-menu-item.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/im-menu-item.c b/src/im-menu-item.c index 03cea5e..f97436e 100644 --- a/src/im-menu-item.c +++ b/src/im-menu-item.c @@ -265,7 +265,7 @@ time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateL static void sender_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data) { - g_debug("Got Sender Information"); + g_debug("Got Sender Information: %s", propertydata); ImMenuItem * self = IM_MENU_ITEM(data); /* Our data should be right */ @@ -278,7 +278,7 @@ sender_cb (IndicateListener * listener, IndicateListenerServer * server, Indicat /* We might get the sender variable returning a null string as it doesn't exist on newer clients but we don't want to listen to that. */ - if (!g_strcmp0(property, "sender") && property[0] == '\0') { + if (!g_strcmp0(property, "sender") && propertydata[0] == '\0') { return; } -- cgit v1.2.3 From 5613a2924e2cfd15ff8d441ed7c968f70a22730c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 8 Sep 2009 20:20:45 -0500 Subject: Bother. --- src/indicator-messages.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/indicator-messages.c b/src/indicator-messages.c index 3dbc217..a3f22aa 100644 --- a/src/indicator-messages.c +++ b/src/indicator-messages.c @@ -162,7 +162,7 @@ indicator_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, gchar * value, in /* We don't use the value here, which is probably less efficient, but it's easier to use the easy function. And since th value is already cached, shouldn't be a big deal really. */ - GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(newitem, INDICATOR_MENUITEM_PROP_ICON); + GdkPixbuf * pixbuf = dbusmenu_menuitem_property_get_image(mi, INDICATOR_MENUITEM_PROP_ICON); if (pixbuf != NULL) { gtk_image_set_from_pixbuf(GTK_IMAGE(mi_data->icon), pixbuf); } -- cgit v1.2.3