Draw service avatar in background
[conv-inbox] / src / el-home-applet.c
index 0a4d62f..020c37f 100644 (file)
 #include <libosso-abook/osso-abook-account-manager.h>
 
 #include <telepathy-glib/interfaces.h>
+#include <telepathy-glib/dbus.h>
+#include <rtcom-telepathy-glib/extensions.h>
 
 #define EL_HOME_APPLET_GET_PRIVATE(obj) ( \
         G_TYPE_INSTANCE_GET_PRIVATE (obj, \
                 EL_TYPE_HOME_APPLET, ELHomeAppletPrivate))
 
 #define BOX_WIDTH 352
-#define BOX_HEIGHT 276
+#define BOX_HEIGHT 284
 
 #define CONTENT_OFFSET_X HILDON_MARGIN_HALF
 #define CONTENT_OFFSET_Y_TOP 4*HILDON_MARGIN_HALF
 #define C_HEIGHT (BOX_HEIGHT - (CONTENT_OFFSET_Y_TOP + CONTENT_OFFSET_Y_BOTTOM))
 
 #define HEADER_HEIGHT 48
-#define MESSAGE_HEIGHT (C_HEIGHT - HEADER_HEIGHT)
+#define FOOTER_HEIGHT 24
+#define FOOTER_HEIGHT_PRESS FOOTER_HEIGHT*2 /* approx, used only for checking clicks */
+#define FOOTER_WIDTH C_WIDTH/4
+#define FOOTER_WIDTH_PRESS (FOOTER_WIDTH + FOOTER_WIDTH/2) /* approx, used only for checking clicks, bigger than controls */
+
+#define MESSAGE_HEIGHT (C_HEIGHT - HEADER_HEIGHT - FOOTER_HEIGHT)
 #define MESSAGE_WIDTH (C_WIDTH - 2*HILDON_MARGIN_DEFAULT)
 
-#define FOOTER_HEIGHT 26 /* approx, used only for checking clicks, bigger than controls */
+#define SERVICE_ICON_SIZE 64
 
-#define BOX_RADIOUS 10
+#define BOX_RADIOUS 20
 
 #define SCROLL_PERIOD 100 /* ms */
 #define SCROLL_STEP 1 /* pixel */
 #define NOTIFICATION_UI_DBUS_PATH     "/org/freedesktop/Telepathy/Client/NotificationUI"
 #define NOTIFICATION_UI_DBUS_IFACE    "com.nokia.RtcomNotificationUi"
 
+static const gchar *conv_services[] = {"RTCOM_EL_SERVICE_SMS",
+                                       "RTCOM_EL_SERVICE_CHAT",
+                                       NULL};
+static const gchar *conv_event_types[] = {"RTCOM_EL_EVENTTYPE_SMS_INBOUND",
+                                          "RTCOM_EL_EVENTTYPE_CHAT_INBOUND",
+                                          NULL};
+
 typedef enum {
         SELECTED_NONE,
         SELECTED_HEADER,
@@ -101,6 +115,8 @@ struct _ELHomeAppletPrivate
         guint8 border_color[4];
         PangoFontDescription *font_desc;
 
+        GdkPixbuf *service_pixbuf;
+
         guint idle_id;
 
         cairo_surface_t *message_surface;
@@ -115,6 +131,7 @@ struct _ELHomeAppletPrivate
         gchar *contact_id;
         gchar *remote_id;
         gchar *local_id;
+        gchar *group_uid;
         OssoABookContact *contact;
 };
 
@@ -148,34 +165,79 @@ el_home_applet_realize (GtkWidget *widget)
         GTK_WIDGET_CLASS (el_home_applet_parent_class)->realize (widget);
 }
 
-/*
- * Thanks http://cairographics.org/cookbook/roundedrectangles/
+enum {
+        ROUND_CORNER_TL = 1,
+        ROUND_CORNER_TR = 1<<1,
+        ROUND_CORNER_BL = 1<<2,
+        ROUND_CORNER_BR = 1<<3,
+        ROUND_CORNER_ALL = ROUND_CORNER_TL | ROUND_CORNER_TR |
+                           ROUND_CORNER_BL | ROUND_CORNER_BR
+};
+
+/**
+ * Draw rectangle with optional round corners.
+ *
+ * @x
+ * @y
+ * @w width
+ * @h height
+ * @r round corner radious
+ * @round_corners define which corners draw round, ROUND_CORNER_TL,
+ *                ROUND_CORNER_TR, ROUND_CORNER_BL, ROUND_CORNER_BR
  */
 static void
 rounded_rectangle (cairo_t *cr,
-                   double   x,
-                   double   y,
-                   double   w,
-                   double   h,
-                   double   r)
+                   double x,
+                   double y,
+                   double w,
+                   double h,
+                   double r,
+                   guint round_corners)
 {
-        cairo_move_to (cr, x + r, y);
-        cairo_line_to (cr, x + w - r, y);
-        cairo_curve_to (cr, x + w, y,
-                        x + w, y,
-                        x + w, y + r);
-        cairo_line_to (cr, x + w, y + h - r);
-        cairo_curve_to (cr, x + w, y + h,
-                        x + w, y + h,
-                        x + w - r, y + h);
-        cairo_line_to (cr, x + r, y + h);
-        cairo_curve_to (cr, x, y + h,
-                        x, y + h,
-                        x, y + h - r);
-        cairo_line_to (cr, x, y + r);
-        cairo_curve_to (cr, x, y,
-                        x, y,
-                        x + r, y);
+        if (round_corners & ROUND_CORNER_TL)
+                cairo_move_to (cr, x + r, y);
+        else
+                cairo_move_to (cr, x, y);
+
+        if (round_corners & ROUND_CORNER_TR) {
+                cairo_line_to (cr, x + w - r, y);
+                cairo_rel_curve_to (cr,
+                                    r, 0,
+                                    r, 0,
+                                    r, r);
+        }
+        else
+                cairo_line_to (cr, x + w, y);
+
+        if (round_corners & ROUND_CORNER_BR) {
+                cairo_line_to (cr, x + w, y + h - r);
+                cairo_rel_curve_to (cr,
+                                    0, r,
+                                    0, r,
+                                    -r, r);
+        }
+        else
+                cairo_line_to (cr, x + w, y + h);
+
+        if (round_corners & ROUND_CORNER_BL) {
+                cairo_line_to (cr, x + r, y + h);
+                cairo_rel_curve_to (cr,
+                                    -r, 0,
+                                    -r, 0,
+                                    -r, -r);
+        }
+        else
+                cairo_line_to (cr, x, y + h);
+
+        if (round_corners & ROUND_CORNER_TL) {
+                cairo_line_to (cr, x, y + r);
+                cairo_rel_curve_to (cr,
+                                    0, -r,
+                                    0, -r,
+                                    r, -r);
+        }
+        else
+                cairo_line_to (cr, x, y);
 }
 
 static cairo_surface_t*
@@ -229,15 +291,19 @@ draw_text (cairo_t              *cr,
         return result_surface;
 }
 
-static void
+static gboolean
 stop_scroll_anim (ELHomeAppletPrivate *priv)
 {
-        if (priv->scroll_anim_id > 0) {
+        gboolean result = priv->scroll_anim_id > 0;
+
+        if (result) {
                 g_source_remove (priv->scroll_anim_id);
                 priv->scroll_anim_id = 0;
                 priv->scroll_on_click = FALSE;
                 gtk_widget_hide (priv->cut_message);
         }
+
+        return result;
 }
 
 static void
@@ -274,20 +340,28 @@ style_set_cb (GtkWidget *widget,
 }
 
 static void
+reset_scroll (ELHomeApplet *self)
+{
+        ELHomeAppletPrivate *priv = self->priv;
+
+        if (stop_scroll_anim (self->priv)) {
+                priv->scroll_on_click = TRUE;/* priv->scroll_offset; */
+                priv->scroll_offset = 0;
+                if (priv->scroll_on_click)
+                        gtk_widget_show (priv->cut_message);
+        }
+}
+
+static void
 notify_on_current_desktop (GObject      *object,
                            GParamSpec   *unused G_GNUC_UNUSED,
                            ELHomeApplet *self)
 {
-        ELHomeAppletPrivate *priv = self->priv;
         gboolean on;
 
         g_object_get (object, "is-on-current-desktop", &on, NULL);
         if (!on) {
-                stop_scroll_anim (self->priv);
-                priv->scroll_on_click = priv->scroll_offset;
-                priv->scroll_offset = 0;
-                if (priv->scroll_on_click)
-                        gtk_widget_show (priv->cut_message);
+                reset_scroll (self);
                 gtk_widget_queue_draw (GTK_WIDGET (self));
         }
 }
@@ -297,9 +371,7 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
 {
         ELHomeAppletPrivate *priv = EL_HOME_APPLET(self)->priv;
         cairo_t *cr;
-        int message_height;
-
-        message_height = C_HEIGHT - priv->received->allocation.height - HEADER_HEIGHT;
+        cairo_pattern_t *grad;
 
         cr = gdk_cairo_create (self->window);
         gdk_cairo_region (cr, event->region);
@@ -316,7 +388,8 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
                            CONTENT_OFFSET_Y_TOP,
                            BOX_WIDTH - 2*CONTENT_OFFSET_X,
                            BOX_HEIGHT - (CONTENT_OFFSET_Y_TOP + CONTENT_OFFSET_Y_BOTTOM),
-                           BOX_RADIOUS);
+                           BOX_RADIOUS,
+                           ROUND_CORNER_ALL);
 
         cairo_close_path (cr);
         cairo_stroke (cr);
@@ -325,14 +398,11 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
         cairo_set_line_width (cr, 1.0f);
 
         cairo_translate (cr, CONTENT_OFFSET_X, CONTENT_OFFSET_Y_TOP);
-        cairo_move_to (cr, 0, HEADER_HEIGHT);
-        cairo_line_to (cr, 0, BOX_RADIOUS);
-        cairo_curve_to (cr, 0, 0, 0, 0, BOX_RADIOUS, 0);
-        cairo_line_to (cr, C_WIDTH - BOX_RADIOUS, 0);
-        cairo_curve_to (cr, C_WIDTH, 0, C_WIDTH, 0, C_WIDTH, BOX_RADIOUS);
-        cairo_line_to (cr, C_WIDTH, HEADER_HEIGHT);
-        cairo_line_to (cr, 0, HEADER_HEIGHT);
-
+        rounded_rectangle (cr,
+                           0, 0,
+                           C_WIDTH, HEADER_HEIGHT,
+                           BOX_RADIOUS,
+                           ROUND_CORNER_TL | ROUND_CORNER_TR);
         cairo_close_path (cr);
 
         switch (priv->active) {
@@ -359,19 +429,21 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
         cairo_stroke (cr);
 
         /* draw body */
-        cairo_move_to (cr, 0, HEADER_HEIGHT);
-        cairo_line_to (cr, 0, C_HEIGHT - BOX_RADIOUS);
-        cairo_curve_to (cr, 0, C_HEIGHT, 0, C_HEIGHT, BOX_RADIOUS, C_HEIGHT);
-        cairo_line_to (cr, C_WIDTH - BOX_RADIOUS, C_HEIGHT);
-        cairo_curve_to (cr, C_WIDTH, C_HEIGHT, C_WIDTH, C_HEIGHT, C_WIDTH, C_HEIGHT - BOX_RADIOUS);
-        cairo_line_to (cr, C_WIDTH, HEADER_HEIGHT);
-        cairo_line_to (cr, 0, HEADER_HEIGHT);
-        cairo_close_path (cr);
+        if (!priv->message) {
+                rounded_rectangle (cr,
+                                   0, HEADER_HEIGHT,
+                                   C_WIDTH, C_HEIGHT,
+                                   BOX_RADIOUS,
+                                   ROUND_CORNER_BL | ROUND_CORNER_BR);
+                cairo_close_path (cr);
+        }
+        else
+                cairo_rectangle (cr, 0, HEADER_HEIGHT,
+                                 C_WIDTH, MESSAGE_HEIGHT);
 
         /* draw body filling depending on (in)active state */
-        cairo_pattern_t *grad;
         grad = cairo_pattern_create_linear (0, HEADER_HEIGHT,
-                                            0, C_HEIGHT);
+                                            0, C_HEIGHT - FOOTER_HEIGHT);
 
         switch (priv->active) {
         case SELECTED_BODY:
@@ -398,48 +470,82 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
         cairo_set_source (cr, grad);
         cairo_fill (cr);
 
-        /* cairo_set_source_rgba (cr, red, green, blue, 1.0f); */
-        /* cairo_translate (cr, -CONTENT_OFFSET_X, -C_Y); */
-        /* rounded_rectangle (cr, */
-        /*                    CONTENT_OFFSET_X, */
-        /*                    C_Y, */
-        /*                    BOX_WIDTH - 2*CONTENT_OFFSET_X, */
-        /*                    BOX_HEIGHT - 2*C_Y, */
-        /*                    BOX_RADIOUS); */
-        /* cairo_close_path (cr); */
-        /* cairo_stroke (cr); */
-
-        /* draw message */
-        if (!priv->message_surface) {
-                gint height;
-
-                priv->message_surface = draw_text (cr,
-                                                   priv->font_desc,
-                                                   priv->message,
-                                                   MESSAGE_WIDTH,
-                                                   &height);
-
-                priv->hidden_message_height = height - message_height;
-                priv->scroll_on_click = priv->hidden_message_height > 0;
-                if (priv->scroll_on_click)
-                        gtk_widget_show (priv->cut_message);
-        }
+        cairo_pattern_destroy (grad);
 
-        cairo_rectangle (cr,
-                         2*CONTENT_OFFSET_X,
-                         TEXT_Y_OFFSET,
-                         MESSAGE_WIDTH,
-                         message_height);
-        cairo_clip (cr);
+        if (priv->message) {
+                if (priv->service_pixbuf) {
+                        cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+                        gdk_cairo_set_source_pixbuf (cr,
+                                                     priv->service_pixbuf,
+                                                     C_WIDTH - SERVICE_ICON_SIZE,
+                                                     C_HEIGHT - FOOTER_HEIGHT - SERVICE_ICON_SIZE);
+                        cairo_paint_with_alpha (cr, 0.3);
+                }
 
-        cairo_set_source_surface (cr,
-                                  priv->message_surface,
-                                  2*CONTENT_OFFSET_X,
-                                  TEXT_Y_OFFSET - priv->scroll_offset);
-        cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
-        cairo_paint (cr);
+                /* draw footer unread part bg */
+                rounded_rectangle (cr,
+                                   0, C_HEIGHT - FOOTER_HEIGHT,
+                                   FOOTER_WIDTH, FOOTER_HEIGHT,
+                                   BOX_RADIOUS,
+                                   ROUND_CORNER_BL);
+                cairo_close_path (cr);
+
+                /* draw body filling depending on (in)active state */
+                switch (priv->active) {
+                case SELECTED_FOOTER:
+                        cairo_set_source_rgba (cr,
+                                               priv->active_color.red,
+                                               priv->active_color.green,
+                                               priv->active_color.blue,
+                                               0.8f);
+                        break;
+                default:
+                        cairo_set_source_rgba (cr, 0.1f, 0.1f, 0.1f, 0.9f);
+                }
+                cairo_fill (cr);
+
+                /* draw footer received part bg */
+                rounded_rectangle (cr,
+                                   FOOTER_WIDTH, C_HEIGHT - FOOTER_HEIGHT,
+                                   C_WIDTH - FOOTER_WIDTH, FOOTER_HEIGHT,
+                                   BOX_RADIOUS,
+                                   ROUND_CORNER_BR);
+                cairo_close_path (cr);
+
+                cairo_set_source_rgba (cr, 0.2f, 0.2f, 0.2f, 0.8f);
+                cairo_fill (cr);
+
+                /* draw message */
+                if (!priv->message_surface) {
+                        gint height;
+
+                        priv->message_surface = draw_text (cr,
+                                                           priv->font_desc,
+                                                           priv->message,
+                                                           MESSAGE_WIDTH,
+                                                           &height);
+
+                        priv->hidden_message_height = height - MESSAGE_HEIGHT;
+                        priv->scroll_on_click = priv->hidden_message_height > 0;
+                        if (priv->scroll_on_click)
+                                gtk_widget_show (priv->cut_message);
+                }
+
+                cairo_rectangle (cr,
+                                 2*CONTENT_OFFSET_X,
+                                 TEXT_Y_OFFSET,
+                                 MESSAGE_WIDTH,
+                                 MESSAGE_HEIGHT);
+                cairo_clip (cr);
+
+                cairo_set_source_surface (cr,
+                                          priv->message_surface,
+                                          2*CONTENT_OFFSET_X,
+                                          TEXT_Y_OFFSET - priv->scroll_offset);
+                cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+                cairo_paint (cr);
+        }
 
-        cairo_pattern_destroy (grad);
         cairo_destroy (cr);
 
         return GTK_WIDGET_CLASS (el_home_applet_parent_class)->expose_event (self, event);
@@ -451,6 +557,11 @@ clean_state (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
 
+        if (priv->service_pixbuf) {
+                g_object_unref (priv->service_pixbuf);
+                priv->service_pixbuf = NULL;
+        }
+
         if (priv->message) {
                 g_free (priv->message);
                 priv->message = NULL;
@@ -468,6 +579,10 @@ clean_state (ELHomeApplet *self)
                 g_free (priv->remote_id);
                 priv->remote_id = NULL;
         }
+        if (priv->group_uid) {
+                g_free (priv->group_uid);
+                priv->group_uid = NULL;
+        }
 
         if (priv->contact) {
                 g_object_unref (priv->contact);
@@ -520,7 +635,6 @@ aggregator_ready_cb (OssoABookWaitable *waitable,
                      const GError      *error,
                      gpointer           userdata)
 {
-        g_warning (G_STRFUNC);
         ELHomeApplet *self = EL_HOME_APPLET(userdata);
         ELHomeAppletPrivate *priv = self->priv;
         GList *contacts = NULL;
@@ -564,18 +678,14 @@ aggregator_ready_cb (OssoABookWaitable *waitable,
                 priv->contact = g_object_ref (OSSO_ABOOK_CONTACT (contacts->data));
                 gtk_label_set_text (GTK_LABEL (priv->sender),
                                     osso_abook_contact_get_display_name (priv->contact));
-                avatar_image = osso_abook_avatar_get_image_rounded
+
+                avatar_image = osso_abook_avatar_get_image_scaled /*rounded*/
                         (OSSO_ABOOK_AVATAR (priv->contact),
                          HILDON_ICON_PIXEL_SIZE_THUMB,
                          HILDON_ICON_PIXEL_SIZE_THUMB,
-                         TRUE,
-                         -1,
-                         priv->border_color);
-
-                g_warning ("contact's name %s\nid=%s\npid=%s",
-                           osso_abook_contact_get_display_name (priv->contact),
-                           osso_abook_contact_get_uid (priv->contact),
-                           osso_abook_contact_get_persistent_uid (priv->contact));
+                         TRUE);
+                         /* -1, */
+                         /* priv->border_color); */
 
                 if (avatar_image) {
                         gtk_image_set_from_pixbuf (GTK_IMAGE (priv->avatar),
@@ -594,8 +704,6 @@ resolve_contact (ELHomeApplet *self)
         EBookQuery *query = NULL;
         GError *error = NULL;
 
-        g_warning ("%s %s %s %s", G_STRFUNC, priv->contact_id, priv->local_id, priv->remote_id);
-
         if (priv->local_id && priv->remote_id) {
                 const gchar *vcard = osso_abook_account_manager_get_vcard_field
                         (NULL, priv->local_id);
@@ -628,7 +736,6 @@ resolve_contact (ELHomeApplet *self)
                          self, NULL);
 
                 osso_abook_roster_start (priv->aggregator);
-                g_warning ("AGG STARTED");
         }
 }
 
@@ -660,7 +767,6 @@ static void
 show_event (ELHomeApplet *self, RTComElIter *it)
 {
         ELHomeAppletPrivate *priv = self->priv;
-        g_warning (G_STRFUNC);
         gchar *remote = NULL;
         gchar *received = NULL;
         /* const gchar *icon_name = NULL; */
@@ -682,13 +788,13 @@ show_event (ELHomeApplet *self, RTComElIter *it)
 
                                         rtcom_el_iter_dup_string (it, "remote-ebook-uid", &priv->contact_id);
                                         rtcom_el_iter_dup_string (it, "local-uid", &priv->local_id);
-                                        g_warning ("abook uid %s", priv->contact_id);
                                 }
                                 else if (priv->remote_id) {
                                         g_free (priv->remote_id);
                                         priv->remote_id = NULL;
                                 }
                         }
+                        rtcom_el_iter_dup_string (it, "group-uid", &priv->group_uid);
 #if 0
                         service = rtcom_el_iter_get_service (it);
                         if (!g_strcmp0 (service, "RTCOM_EL_SERVICE_SMS"))
@@ -702,11 +808,6 @@ show_event (ELHomeApplet *self, RTComElIter *it)
                 priv->event_id = -1;
         }
 
-        g_warning ("event_id=%d\nremote-uid=%s\nremote_name=%s",
-                   priv->event_id,
-                   priv->remote_id,
-                   remote);
-
         gtk_widget_hide (priv->avatar);
 
         if (priv->message) {
@@ -758,28 +859,18 @@ make_query (RTComEl *el, gint event_id)
         RTComElQuery *query = NULL;
         RTComElIter *it = NULL;
 
-        static const gchar *services[] = {"RTCOM_EL_SERVICE_SMS",
-                                          "RTCOM_EL_SERVICE_CHAT",
-                                          NULL};
-        static const gchar *event_types[] = {"RTCOM_EL_EVENTTYPE_SMS_INBOUND",
-                                             "RTCOM_EL_EVENTTYPE_CHAT_INBOUND",
-                                             NULL};
-
         query = rtcom_el_query_new (el);
         rtcom_el_query_set_limit (query, 1);
         if (event_id >= 0) {
                 rtcom_el_query_prepare (query,
-                                        "is-read", FALSE, RTCOM_EL_OP_EQUAL,
                                         "id", event_id, RTCOM_EL_OP_EQUAL,
-                                        "service", services, RTCOM_EL_OP_IN_STRV,
-                                        "event-type", event_types, RTCOM_EL_OP_IN_STRV,
                                         NULL);
         }
         else {
                 rtcom_el_query_prepare (query,
                                         "is-read", FALSE, RTCOM_EL_OP_EQUAL,
-                                        "service", services, RTCOM_EL_OP_IN_STRV,
-                                        "event-type", event_types, RTCOM_EL_OP_IN_STRV,
+                                        "service", conv_services, RTCOM_EL_OP_IN_STRV,
+                                        /* "event-type", conv_event_types, RTCOM_EL_OP_IN_STRV, */
                                         NULL);
         }
         it = rtcom_el_get_events (el, query);
@@ -792,11 +883,14 @@ static void
 update_unread_label (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
-        gchar *text;
 
         if (priv->unread_count > 0) {
-                text = g_strdup_printf ("%d", priv->unread_count);
-                gtk_label_set_text (GTK_LABEL (priv->unread), text);
+                gchar *text;
+                text = g_strdup_printf
+                        ("%d<span foreground=\"red\" rise=\"5000\">*</span>",
+                         priv->unread_count);
+
+                gtk_label_set_markup (GTK_LABEL (priv->unread), text);
                 g_free (text);
         }
         else
@@ -839,7 +933,6 @@ query_unread_events (RTComEl *el)
 static void
 read_event (ELHomeApplet *self)
 {
-        g_warning (G_STRFUNC);
         ELHomeAppletPrivate *priv = self->priv;
         RTComElIter *it = NULL;
 
@@ -848,6 +941,30 @@ read_event (ELHomeApplet *self)
         it = make_query (priv->eventlogger, -1);
         show_event (self, it);
         resolve_contact (self);
+
+        if (g_strcmp0 (priv->local_id, "ring/tel/ring" == 0)) {
+                McAccount *account;
+                const gchar *icon_name = NULL;
+                account = osso_abook_account_manager_lookup_by_name (NULL,
+                                                                     priv->local_id);
+                if (account) {
+                        McProfile *profile = mc_profile_lookup (mc_account_compat_get_profile (account));
+                        icon_name = mc_profile_get_icon_name (profile);
+                }
+                if (icon_name) {
+                        GdkScreen *screen;
+                        GtkIconTheme *icon_theme;
+
+                        screen = gtk_widget_get_screen (GTK_WIDGET (self));
+                        icon_theme = gtk_icon_theme_get_for_screen (screen);
+
+                        priv->service_pixbuf = gtk_icon_theme_load_icon (icon_theme,
+                                                                         icon_name,
+                                                                         SERVICE_ICON_SIZE,
+                                                                         0, NULL);
+                }
+        }
+
         if (it) g_object_unref (it);
 }
 
@@ -921,7 +1038,7 @@ static void
 mark_as_read (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
-        g_warning (G_STRFUNC);
+
         if (priv->event_id >= 0) {
                 rtcom_el_set_read_event (priv->eventlogger,
                                          priv->event_id,
@@ -936,9 +1053,9 @@ open_conversation (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
         McAccount *account;
-        McAccountChannelrequestData request;
+        const gchar *persistent_id = NULL;
 
-        if (!(priv->remote_id && priv->local_id))
+        if (!((priv->remote_id || priv->group_uid) && priv->local_id))
                 return;
 
         account = osso_abook_account_manager_lookup_by_name (NULL,
@@ -946,25 +1063,54 @@ open_conversation (ELHomeApplet *self)
         if (!account)
                 return;
 
-        MC_ACCOUNT_CRD_INIT (&request);
-        MC_ACCOUNT_CRD_SET (&request, channel_type, TP_IFACE_QUARK_CHANNEL_TYPE_TEXT);
-        MC_ACCOUNT_CRD_SET (&request, target_handle_type, TP_HANDLE_TYPE_CONTACT);
-        MC_ACCOUNT_CRD_SET (&request, target_id, priv->remote_id);
-
-        mc_account_channelrequest (
-                account,
-                &request,
-                time (NULL),
-                NULL, /* handler */
-                MC_ACCOUNT_CR_FLAG_USE_EXISTING,
-                NULL, NULL, NULL, NULL);
+        if (priv->group_uid &&
+            g_str_has_prefix (priv->group_uid, "group:")) {
+                persistent_id = strchr (priv->group_uid, '-');
+                if (persistent_id)
+                        persistent_id++;
+        }
+
+        if (persistent_id && persistent_id[0] != '\0') {
+                GHashTable *properties = tp_asv_new
+                        (TP_IFACE_CHANNEL ".ChannelType", G_TYPE_STRING,
+                         TP_IFACE_CHANNEL_TYPE_TEXT,
+                         TP_IFACE_CHANNEL ".TargetHandleType", G_TYPE_UINT,
+                         TP_HANDLE_TYPE_NONE,
+                         RTCOM_TP_IFACE_CHANNEL_INTERFACE_PERSISTENT ".PersistentID",
+                         G_TYPE_STRING, persistent_id,
+                         NULL);
+
+                mc_account_channelrequest_ht (account,
+                                              properties,
+                                              time (NULL),
+                                              NULL,
+                                              MC_ACCOUNT_CR_FLAG_USE_EXISTING,
+                                              NULL, NULL, NULL, NULL);
+
+                g_hash_table_unref (properties);
+        }
+        else if (priv->remote_id) {
+                McAccountChannelrequestData request;
+
+                MC_ACCOUNT_CRD_INIT (&request);
+                MC_ACCOUNT_CRD_SET (&request, channel_type, TP_IFACE_QUARK_CHANNEL_TYPE_TEXT);
+                MC_ACCOUNT_CRD_SET (&request, target_handle_type, TP_HANDLE_TYPE_CONTACT);
+                MC_ACCOUNT_CRD_SET (&request, target_id, priv->remote_id);
+
+                mc_account_channelrequest (account,
+                                           &request,
+                                           time (NULL),
+                                           NULL,
+                                           MC_ACCOUNT_CR_FLAG_USE_EXISTING,
+                                           NULL, NULL, NULL, NULL);
+        }
 }
 
 static gboolean
 read_new_event (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
-        g_warning (G_STRFUNC);
+
         read_event (self);
         priv->unread_count = query_unread_events (priv->eventlogger);
         update_unread_label (self);
@@ -995,8 +1141,15 @@ new_event_cb (RTComEl      *backend,
               const gchar  *service,
               ELHomeApplet *self)
 {
-        /* TODO: avoid updating if not related */
-        add_new_idle (self);
+        const gchar** conv_service = conv_services;
+
+        do {
+                if (!g_strcmp0 (*conv_service, service)) {
+                        add_new_idle (self);
+                        return;
+                }
+        }
+        while(++conv_service);
 }
 
 static gboolean
@@ -1010,7 +1163,7 @@ scroll_anim_cb (ELHomeApplet *self)
                                     3*CONTENT_OFFSET_X,
                                     HEADER_HEIGHT + CONTENT_OFFSET_Y_TOP,
                                     MESSAGE_WIDTH,
-                                    C_HEIGHT - priv->received->allocation.height - HEADER_HEIGHT);
+                                    MESSAGE_HEIGHT);
 
         to_continue = priv->scroll_offset <= priv->hidden_message_height;
         if (!to_continue) {
@@ -1026,19 +1179,17 @@ button_press_event_cb (GtkWidget      *widget,
                        GdkEventButton *event,
                        ELHomeApplet   *self)
 {
-        g_warning (G_STRFUNC);
         ELHomeAppletPrivate *priv = self->priv;
 
         if (priv->event_id > 0) {
-                stop_scroll_anim (priv);
-
                 if (event->y < CONTENT_OFFSET_Y_TOP + HEADER_HEIGHT) {
                         if (priv->aggregator &&
                             osso_abook_waitable_is_ready
                             (OSSO_ABOOK_WAITABLE (priv->aggregator), NULL))
                                 priv->active = SELECTED_HEADER;
                 }
-                else if (event->y > (BOX_HEIGHT - CONTENT_OFFSET_Y_BOTTOM - FOOTER_HEIGHT))
+                else if (event->y > (BOX_HEIGHT - CONTENT_OFFSET_Y_BOTTOM - FOOTER_HEIGHT_PRESS) &&
+                         event->x < FOOTER_WIDTH_PRESS)
                         priv->active = SELECTED_FOOTER;
                 else
                         priv->active = SELECTED_BODY;
@@ -1076,12 +1227,14 @@ create_temporary_contact_dialog (const gchar *remote_id,
 {
         GtkWidget *dialog = NULL;
         const gchar *vcard = NULL;
+        McAccount *account = NULL;
 
         if (account_id) {
             vcard = osso_abook_account_manager_get_vcard_field (NULL, account_id);
+            account = osso_abook_account_manager_lookup_by_name (NULL, account_id);
         }
 
-        if (vcard) {
+        if (vcard && account) {
                 EVCardAttribute *attribute = e_vcard_attribute_new (NULL, vcard);
 
                 e_vcard_attribute_add_value (attribute, remote_id);
@@ -1089,7 +1242,7 @@ create_temporary_contact_dialog (const gchar *remote_id,
                         (NULL,
                          NULL, /*EBook            *book,*/
                          attribute,
-                         NULL /*McAccount        *account*/);
+                         account);
                 g_signal_connect (dialog,
                                   "response",
                                   G_CALLBACK (gtk_widget_destroy),
@@ -1106,27 +1259,17 @@ button_release_event_cb (GtkWidget      *widget,
                          ELHomeApplet   *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
-        g_warning (G_STRFUNC);
 
         switch (priv->active) {
         case SELECTED_BODY:
-                if (priv->scroll_on_click) {
-                        priv->scroll_on_click = FALSE;
-                        priv->scroll_anim_id = g_timeout_add (SCROLL_PERIOD,
-                                                              (GSourceFunc)scroll_anim_cb,
-                                                              self);
-                }
-                else {
-#ifndef DEBUG_LAYOUT
-                        open_conversation (self);
-#endif
-                }
-                gtk_widget_queue_draw (widget);
-
+                reset_scroll (self);
+                open_conversation (self);
                 break;
         case SELECTED_HEADER: {
                 GtkWidget *dialog = NULL;
 
+                reset_scroll (self);
+
                 if (priv->aggregator && priv->contact_id)
                         dialog = create_contact_starter_dialog
                                 (OSSO_ABOOK_AGGREGATOR (priv->aggregator),
@@ -1139,17 +1282,26 @@ button_release_event_cb (GtkWidget      *widget,
 
                 if (dialog)
                         gtk_widget_show (dialog);
-
-                gtk_widget_queue_draw (widget);
         }
                 break;
         case SELECTED_FOOTER:
-                mark_as_read (self);
+                if (priv->scroll_on_click) {
+                        priv->scroll_on_click = FALSE;
+                        priv->scroll_anim_id = g_timeout_add (SCROLL_PERIOD,
+                                                              (GSourceFunc)scroll_anim_cb,
+                                                              self);
+                }
+                else
+#ifndef DEBUG_LAYOUT
+                        mark_as_read (self);
+#endif
                 break;
         default:;
         }
 
         priv->active = SELECTED_NONE;
+        gtk_widget_queue_draw (widget);
+
         return TRUE;
 }
 
@@ -1161,11 +1313,11 @@ leave_notify_event_cb (GtkWidget        *widget,
         ELHomeAppletPrivate *priv = self->priv;
 
         switch (priv->active) {
-        case SELECTED_BODY:
+        case SELECTED_FOOTER:
                 stop_scroll_anim (priv);
-                gtk_widget_queue_draw (widget);
-                break;
+                /* fall down */
         case SELECTED_HEADER:
+        case SELECTED_BODY:
                 gtk_widget_queue_draw (widget);
                 break;
         default:;
@@ -1188,13 +1340,9 @@ el_home_applet_init (ELHomeApplet *self)
         gtk_widget_set_app_paintable (GTK_WIDGET (self), TRUE);
 
         priv->unread = gtk_label_new ("12");
-        hildon_helper_set_logical_color (priv->unread,
-                                         GTK_RC_FG,
-                                         GTK_STATE_NORMAL,
-                                         "ActiveTextColor");
         gtk_misc_set_alignment (GTK_MISC (priv->unread),
-                                1.0f,
-                                1.0f);
+                                0.0f,
+                                0.5f);
         hildon_helper_set_logical_font (priv->unread, "SmallSystemFont");
         /* gtk_widget_set_size_request (priv->unread, */
         /*                              -1, */
@@ -1251,7 +1399,7 @@ el_home_applet_init (ELHomeApplet *self)
         gtk_box_pack_start (GTK_BOX (hbox), priv->sender, TRUE, TRUE, 0);
         gtk_box_pack_start (GTK_BOX (hbox), priv->avatar, FALSE, FALSE, 0);
 
-        footer = gtk_hbox_new (FALSE, 0);
+        footer = gtk_hbox_new (FALSE, HILDON_MARGIN_DEFAULT);
         gtk_box_pack_start (GTK_BOX (footer), priv->unread, FALSE, FALSE, 0);
         gtk_box_pack_start (GTK_BOX (footer), priv->cut_message, TRUE, TRUE, 0);
         gtk_box_pack_end (GTK_BOX (footer), priv->received, FALSE, FALSE, 0);