Draw service avatar in background
[conv-inbox] / src / el-home-applet.c
index 20da3fd..020c37f 100644 (file)
@@ -62,6 +62,8 @@
 #define MESSAGE_HEIGHT (C_HEIGHT - HEADER_HEIGHT - FOOTER_HEIGHT)
 #define MESSAGE_WIDTH (C_WIDTH - 2*HILDON_MARGIN_DEFAULT)
 
+#define SERVICE_ICON_SIZE 64
+
 #define BOX_RADIOUS 20
 
 #define SCROLL_PERIOD 100 /* ms */
 #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,
@@ -106,6 +115,8 @@ struct _ELHomeAppletPrivate
         guint8 border_color[4];
         PangoFontDescription *font_desc;
 
+        GdkPixbuf *service_pixbuf;
+
         guint idle_id;
 
         cairo_surface_t *message_surface;
@@ -462,6 +473,15 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
         cairo_pattern_destroy (grad);
 
         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);
+                }
+
                 /* draw footer unread part bg */
                 rounded_rectangle (cr,
                                    0, C_HEIGHT - FOOTER_HEIGHT,
@@ -537,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;
@@ -834,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);
@@ -926,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);
 }
 
@@ -1102,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