aboutsummaryrefslogtreecommitdiff
path: root/src/app-menu-item.c
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-09-05 11:08:59 -0500
committerTed Gould <ted@canonical.com>2009-09-05 11:08:59 -0500
commita081622756ff3cecfa42d6f623ae69c5806c5bcd (patch)
tree84423df61c2a490381fc691f2d9b09b5ecf28554 /src/app-menu-item.c
parent6533f296498545bc4b46590cea25707228869ce0 (diff)
downloadayatana-indicator-messages-a081622756ff3cecfa42d6f623ae69c5806c5bcd.tar.gz
ayatana-indicator-messages-a081622756ff3cecfa42d6f623ae69c5806c5bcd.tar.bz2
ayatana-indicator-messages-a081622756ff3cecfa42d6f623ae69c5806c5bcd.zip
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.
Diffstat (limited to 'src/app-menu-item.c')
-rw-r--r--src/app-menu-item.c37
1 files 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.