aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/im-menu-item.c153
-rw-r--r--src/im-menu-item.h13
-rw-r--r--src/indicator-messages.c2
3 files changed, 153 insertions, 15 deletions
diff --git a/src/im-menu-item.c b/src/im-menu-item.c
index 0785c00..073e79b 100644
--- a/src/im-menu-item.c
+++ b/src/im-menu-item.c
@@ -8,42 +8,179 @@ typedef struct _ImMenuItemPrivate ImMenuItemPrivate;
struct _ImMenuItemPrivate
{
+ IndicateListener * listener;
+ IndicateListenerSever * server;
+ IndicateListenerIndicator * indicator;
+
+ GtkHBox * hbox;
+ GtkLabel * user;
+ GtkLabel * time;
+ GtkImage * icon;
};
-#define IM_MENU_ITEM_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE ((o), IM_MENU_ITEM_TYPE, ImMenuItemPrivate))
+#define IM_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), IM_MENU_ITEM_TYPE, ImMenuItemPrivate))
+/* Prototypes */
static void im_menu_item_class_init (ImMenuItemClass *klass);
static void im_menu_item_init (ImMenuItem *self);
static void im_menu_item_dispose (GObject *object);
static void im_menu_item_finalize (GObject *object);
+static void sender_cb (IndicateListener * listener,
+ IndicateListenerServer * server,
+ IndicateListenerIndicator * indicator,
+ gchar * property,
+ gchar * propertydata,
+ gpointer data);
+static void time_cb (IndicateListener * listener,
+ IndicateListenerServer * server,
+ IndicateListenerIndicator * indicator,
+ gchar * property,
+ gchar * propertydata,
+ gpointer data);
+static void icon_cb (IndicateListener * listener,
+ IndicateListenerServer * server,
+ IndicateListenerIndicator * indicator,
+ gchar * property,
+ gchar * propertydata,
+ gpointer data);
+
+
+static GtkSizeGroup * icon_group = NULL;
+static GtkSizeGroup * user_group = NULL;
+static GtkSizeGroup * time_group = NULL;
+
G_DEFINE_TYPE (ImMenuItem, im_menu_item, GTK_TYPE_MENU_ITEM);
static void
im_menu_item_class_init (ImMenuItemClass *klass)
{
-GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
-g_type_class_add_private (klass, sizeof (ImMenuItemPrivate));
+ g_type_class_add_private (klass, sizeof (ImMenuItemPrivate));
-object_class->dispose = im_menu_item_dispose;
-object_class->finalize = im_menu_item_finalize;
+ object_class->dispose = im_menu_item_dispose;
+ object_class->finalize = im_menu_item_finalize;
}
static void
im_menu_item_init (ImMenuItem *self)
{
+ ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
+
+ priv->listener = NULL;
+ priv->server = NULL;
+ priv->indicator = NULL;
+
+ /* build widgets first */
+ priv->icon = gtk_image_new();
+ priv->user = gtk_label_new("");
+ priv->time = gtk_label_new("");
+
+ if (icon_group == NULL) {
+ icon_group = gtk_size_group_new(GTK_SIZE_GROUP_MODE_HORIZONTAL);
+ }
+ if (user_group == NULL) {
+ user_group = gtk_size_group_new(GTK_SIZE_GROUP_MODE_HORIZONTAL);
+ }
+ if (time_group == NULL) {
+ time_group = gtk_size_group_new(GTK_SIZE_GROUP_MODE_HORIZONTAL);
+ }
+ gtk_size_group_add_widget(icon_group, priv->icon);
+ gtk_size_group_add_widget(user_group, priv->user);
+ gtk_size_group_add_widget(time_group, priv->time);
+
+ priv->hbox = gtk_hbox_new(FALSE, 3);
+ gtk_box_pack(GTK_BOX(priv->hbox), GTK_WIDGET(priv->time), FALSE, TRUE, 3);
+ gtk_box_pack(GTK_BOX(priv->hbox), GTK_WIDGET(priv->user), TRUE, TRUE, 3);
+ gtk_box_pack(GTK_BOX(priv->hbox), GTK_WIDGET(priv->icon), FALSE, TRUE, 3);
+
+ gtk_container_add(GTK_CONTAINER(self), priv->hbox);
+
+ return;
}
static void
im_menu_item_dispose (GObject *object)
{
-G_OBJECT_CLASS (im_menu_item_parent_class)->dispose (object);
+ G_OBJECT_CLASS (im_menu_item_parent_class)->dispose (object);
}
static void
im_menu_item_finalize (GObject *object)
{
-G_OBJECT_CLASS (im_menu_item_parent_class)->finalize (object);
+ G_OBJECT_CLASS (im_menu_item_parent_class)->finalize (object);
+}
+
+static void
+icon_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data)
+{
+
+
+}
+
+static void
+time_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data)
+{
+ ImMenuItem * self = IM_MENU_ITEM(data);
+ if (self == NULL) {
+ g_error("Menu Item callback called without a menu item");
+ return;
+ }
+
+ if (property == NULL || strcmp(property, "sender")) {
+ g_warning("Sender callback called without being send the sender.");
+ return;
+ }
+
+ ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
+
+ gtk_label_set_label(priv->time, propertydata);
+ gtk_widget_show(priv->time);
+
+ return;
+}
+
+static void
+sender_cb (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator, gchar * property, gchar * propertydata, gpointer data)
+{
+ ImMenuItem * self = IM_MENU_ITEM(data);
+ if (self == NULL) {
+ g_error("Menu Item callback called without a menu item");
+ return;
+ }
+
+ if (property == NULL || strcmp(property, "sender")) {
+ g_warning("Sender callback called without being send the sender.");
+ return;
+ }
+
+ ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
+
+ gtk_label_set_label(priv->user, propertydata);
+ gtk_widget_show(priv->user);
+
+ /* Once we have the user we'll show the menu item */
+ gtk_widget_show(self);
+
+ return;
+}
+
+ImMenuItem *
+im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator)
+{
+ ImMenuItem * self = g_object_new(IM_MENU_ITEM_TYPE, NULL);
+
+ ImMenuItemPrivate * priv = IM_MENU_ITEM_GET_PRIVATE(self);
+
+ priv->listener = listener;
+ priv->server = server;
+ priv->indicator = indicator;
+
+
+ indicate_listener_get_property(listener, server, indicator, "sender", sender_cb, self);
+ indicate_listener_get_property(listener, server, indicator, "time", time_cb, self);
+ indicate_listener_get_property(listener, server, indicator, "icon", icon_cb, self);
+
+ return;
}
diff --git a/src/im-menu-item.h b/src/im-menu-item.h
index c5fb83e..ad9bb6b 100644
--- a/src/im-menu-item.h
+++ b/src/im-menu-item.h
@@ -4,6 +4,8 @@
#include <glib.h>
#include <glib-object.h>
+#include <libindicate/listener.h>
+
G_BEGIN_DECLS
#define IM_MENU_ITEM_TYPE (im_menu_item_get_type ())
@@ -16,17 +18,16 @@ G_BEGIN_DECLS
typedef struct _ImMenuItem ImMenuItem;
typedef struct _ImMenuItemClass ImMenuItemClass;
-struct _ImMenuItemClass
-{
-GtkMenuItemClass parent_class;
+struct _ImMenuItemClass {
+ GtkMenuItemClass parent_class;
};
-struct _ImMenuItem
-{
-GtkMenuItem parent;
+struct _ImMenuItem {
+ GtkMenuItem parent;
};
GType im_menu_item_get_type (void);
+ImMenuItem * im_menu_item_new (IndicateListener * listener, IndicateListenerServer * server, IndicateListenerIndicator * indicator);
G_END_DECLS
diff --git a/src/indicator-messages.c b/src/indicator-messages.c
index 993451e..68bc434 100644
--- a/src/indicator-messages.c
+++ b/src/indicator-messages.c
@@ -55,7 +55,7 @@ subtype_cb (IndicateListener * listener, IndicateListenerServer * server, Indica
hasher->server = server;
hasher->indicator = indicator;
- GtkWidget * menuitem = im_menu_item_new(listener, server, indicator);
+ GtkWidget * menuitem = GTK_WIDGET(im_menu_item_new(listener, server, indicator));
g_object_ref(menuitem);
g_hash_table_insert(imHash, hasher, menuitem);