Resize sender name depending on avatar and presence icons
authorArtem Garmash <artemgarmash@gmail.com>
Sun, 31 Jan 2010 19:28:10 +0000 (21:28 +0200)
committerArtem Garmash <artem.garmash@nokia.com>
Sun, 27 Jun 2010 19:13:45 +0000 (22:13 +0300)
src/el-home-applet.c

index 4e950cf..39274d3 100644 (file)
@@ -509,7 +509,6 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
         }
 
         if (priv->message) {
-
                 /* draw footer unread part bg */
                 rounded_rectangle (cr,
                                    0, C_HEIGHT - FOOTER_HEIGHT,
@@ -580,23 +579,45 @@ expose_event (GtkWidget *self, GdkEventExpose *event)
 }
 
 static void
+resize_sender (ELHomeAppletPrivate *priv)
+{
+        guint width = C_WIDTH;
+
+        if (priv->avatar_pixbuf) {
+                width -= AVATAR_SIZE + HILDON_MARGIN_DEFAULT;
+        }
+
+        if (priv->presence_pixbuf) {
+                width -= HILDON_ICON_PIXEL_SIZE_XSMALL + HILDON_MARGIN_DEFAULT;
+        }
+
+        gtk_widget_set_size_request (priv->sender,
+                                     width,
+                                     HILDON_ICON_PIXEL_SIZE_THUMB);
+}
+
+static void
 update_presence_pixbuf (ELHomeApplet *self,
                         OssoABookPresence *presence)
 {
         ELHomeAppletPrivate *priv = self->priv;
         const gchar *icon_name = osso_abook_presence_get_icon_name (presence);
+        gboolean resize = !!priv->presence_pixbuf ^ !!icon_name; /* logical via bit XOR */
 
         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);
+        if (resize)
+                resize_sender (priv);
 
         gtk_widget_queue_draw (GTK_WIDGET (self));
 }
@@ -658,20 +679,14 @@ resolve_contact (ELHomeApplet *self)
                          HILDON_ICON_PIXEL_SIZE_THUMB,
                          TRUE);
 
-                g_warning ("HAVE avatar");
-                if (priv->avatar_pixbuf) {
-                        gtk_widget_set_size_request (priv->sender,
-                                                     C_WIDTH - AVATAR_SIZE - HILDON_MARGIN_DEFAULT,
-                                                     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);
+
+                resize_sender (priv);
                 gtk_widget_queue_draw (GTK_WIDGET (self));
         }
 
@@ -694,10 +709,6 @@ reset_contact (ELHomeApplet *self)
 {
         ELHomeAppletPrivate *priv = self->priv;
 
-        gtk_widget_set_size_request (priv->sender,
-                                     C_WIDTH,
-                                     HILDON_ICON_PIXEL_SIZE_THUMB);
-
         gtk_widget_hide (priv->icon);
 
         if (priv->avatar_pixbuf) {
@@ -717,6 +728,8 @@ reset_contact (ELHomeApplet *self)
                 g_object_unref (priv->contact);
                 priv->contact = NULL;
         }
+
+        resize_sender (priv);
 }
 
 static void