Show presence status
authorArtem Garmash <artemgarmash@gmail.com>
Fri, 29 Jan 2010 22:55:57 +0000 (00:55 +0200)
committerArtem Garmash <artem.garmash@nokia.com>
Sun, 27 Jun 2010 19:13:45 +0000 (22:13 +0300)
src/el-home-applet.c

index bc4443c..270bfa2 100644 (file)
@@ -31,7 +31,8 @@
 #include <libosso-abook/osso-abook-aggregator.h>
 #include <libosso-abook/osso-abook-contact.h>
 #include <libosso-abook/osso-abook-waitable.h>
-#include <libosso-abook/osso-abook-contact.h>
+#include <libosso-abook/osso-abook-presence.h>
+#include <libosso-abook/osso-abook-avatar.h>
 #include <libosso-abook/osso-abook-touch-contact-starter.h>
 #include <libosso-abook/osso-abook-temporary-contact-dialog.h>
 #include <libosso-abook/osso-abook-account-manager.h>
@@ -62,7 +63,6 @@
 #define MESSAGE_HEIGHT (C_HEIGHT - HEADER_HEIGHT - FOOTER_HEIGHT)
 #define MESSAGE_WIDTH (C_WIDTH - 2*HILDON_MARGIN_DEFAULT)
 
-#define SERVICE_ICON_SIZE HILDON_ICON_PIXEL_SIZE_SMALL
 #define AVATAR_SIZE HILDON_ICON_PIXEL_SIZE_THUMB
 
 #define AVATAR_X (C_WIDTH - AVATAR_SIZE - HILDON_MARGIN_DEFAULT)
@@ -120,6 +120,7 @@ struct _ELHomeAppletPrivate
         PangoFontDescription *font_desc;
 
         GdkPixbuf *avatar_pixbuf;
+        GdkPixbuf *presence_pixbuf;
 
         guint idle_id;
 
@@ -498,21 +499,21 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
                                        1.0f);
                 cairo_stroke (cr);
         }
-#if 0
-        if (priv->service_pixbuf) {
-                guint x = C_WIDTH - SERVICE_ICON_SIZE - HILDON_MARGIN_DEFAULT;
-                guint y = (HEADER_HEIGHT - SERVICE_ICON_SIZE)/2;
+        if (priv->presence_pixbuf) {
+                guint x = C_WIDTH - HILDON_ICON_PIXEL_SIZE_XSMALL - HILDON_MARGIN_DEFAULT;
+                guint y = (HEADER_HEIGHT - HILDON_ICON_PIXEL_SIZE_XSMALL)/2;
 
                 if (priv->avatar_pixbuf)
                         x -= AVATAR_SIZE + HILDON_MARGIN_DEFAULT;
 
                 cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
                 gdk_cairo_set_source_pixbuf (cr,
-                                             priv->service_pixbuf,
-                                             x, y);
+                                             priv->presence_pixbuf,
+                                             x,
+                                             y);
                 cairo_paint (cr);
         }
-#endif
+
         if (priv->message) {
 
                 /* draw footer unread part bg */
@@ -584,6 +585,40 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
         return GTK_WIDGET_CLASS (el_home_applet_parent_class)->expose_event (self, event);
 }
 
+static void
+update_presence_pixbuf (ELHomeApplet *self,
+                        OssoABookPresence *presence)
+{
+        ELHomeAppletPrivate *priv = self->priv;
+        const gchar *icon_name = osso_abook_presence_get_icon_name (presence);
+
+        if (priv->presence_pixbuf) {
+                g_object_unref (priv->presence_pixbuf);
+                priv->presence_pixbuf = NULL;
+        }
+        g_warning ("presence %s", icon_name);
+        if (icon_name)
+                priv->presence_pixbuf = gtk_icon_theme_load_icon
+                        (gtk_icon_theme_get_default (),
+                         icon_name,
+                         HILDON_ICON_PIXEL_SIZE_XSMALL,
+                         0, NULL);
+
+        gtk_widget_queue_draw (GTK_WIDGET (self));
+}
+
+static void
+presence_updated (OssoABookPresence *presence,
+                  GParamSpec *spec,
+                  gpointer *user_data)
+{
+        ELHomeApplet *self = EL_HOME_APPLET(user_data);
+
+        if (!OSSO_ABOOK_IS_CONTACT(self->priv->contact))
+                return;
+
+        update_presence_pixbuf (self, presence);
+}
 
 static void
 clean_state (ELHomeApplet *self)
@@ -601,6 +636,11 @@ clean_state (ELHomeApplet *self)
                 priv->avatar_pixbuf = NULL;
         }
 
+        if (priv->presence_pixbuf) {
+                g_object_unref (priv->presence_pixbuf);
+                priv->presence_pixbuf = NULL;
+        }
+
         if (priv->message) {
                 g_free (priv->message);
                 priv->message = NULL;
@@ -624,6 +664,9 @@ clean_state (ELHomeApplet *self)
         }
 
         if (priv->contact) {
+                g_signal_handlers_disconnect_by_func (priv->contact,
+                                                      presence_updated,
+                                                      self);
                 g_object_unref (priv->contact);
                 priv->contact = NULL;
         }
@@ -730,6 +773,13 @@ aggregator_ready_cb (OssoABookWaitable *waitable,
                                                      HILDON_ICON_PIXEL_SIZE_THUMB);
 
                 }
+
+                update_presence_pixbuf (self,
+                                        OSSO_ABOOK_PRESENCE (priv->contact));
+                g_signal_connect (priv->contact,
+                                  "notify::presence-status",
+                                  G_CALLBACK (presence_updated),
+                                  self);
 #if 0
                 if (priv->avatar_pixbuf) {
                         gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar),
@@ -995,7 +1045,7 @@ read_event (ELHomeApplet *self)
         if (icon_name) {
                 gtk_image_set_from_icon_name (GTK_IMAGE (priv->icon),
                                               icon_name,
-                                              HILDON_ICON_SIZE_SMALL);
+                                              HILDON_ICON_SIZE_XSMALL);
                 gtk_widget_show (priv->icon);
         }