aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-03-15 09:48:32 -0500
committerTed Gould <ted@canonical.com>2009-03-15 09:48:32 -0500
commitc9f60d213f559fdd49e5cc4229658f8b30ad8533 (patch)
treecf7e1481d6e853a2c01d4ba8f5ad2f5dcd88eee7
parent31e467f02e0ad2871258bddcbf7019c4954f9933 (diff)
downloadayatana-indicator-messages-c9f60d213f559fdd49e5cc4229658f8b30ad8533.tar.gz
ayatana-indicator-messages-c9f60d213f559fdd49e5cc4229658f8b30ad8533.tar.bz2
ayatana-indicator-messages-c9f60d213f559fdd49e5cc4229658f8b30ad8533.zip
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.
-rw-r--r--src/app-menu-item.c67
-rw-r--r--src/app-menu-item.h5
2 files changed, 72 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>.
#include <gio/gdesktopappinfo.h>
#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