]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-roster-contact.c
Merge remote-tracking branch 'origin/gnome-3-8'
[empathy.git] / libempathy-gtk / empathy-roster-contact.c
index 3b30d2517a7f248676e99aca041bca686f9d1ba0..2db024a3d8a9a5283483a4794dc60c3e89a264aa 100644 (file)
@@ -1,13 +1,11 @@
 #include "config.h"
-
 #include "empathy-roster-contact.h"
 
-#include <telepathy-glib/util.h>
-
-#include <libempathy/empathy-utils.h>
+#include <glib/gi18n-lib.h>
 
-#include <libempathy-gtk/empathy-images.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
+#include "empathy-images.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 G_DEFINE_TYPE (EmpathyRosterContact, empathy_roster_contact, GTK_TYPE_ALIGNMENT)
 
@@ -16,6 +14,7 @@ G_DEFINE_TYPE (EmpathyRosterContact, empathy_roster_contact, GTK_TYPE_ALIGNMENT)
 enum
 {
   PROP_INDIVIDIUAL = 1,
+  PROP_GROUP,
   PROP_ONLINE,
   PROP_ALIAS,
   N_PROPS
@@ -33,6 +32,7 @@ static guint signals[LAST_SIGNAL];
 struct _EmpathyRosterContactPriv
 {
   FolksIndividual *individual;
+  gchar *group;
 
   GtkWidget *avatar;
   GtkWidget *first_line_alig;
@@ -41,6 +41,9 @@ struct _EmpathyRosterContactPriv
   GtkWidget *presence_icon;
   GtkWidget *phone_icon;
 
+  /* If not NULL, used instead of the individual's presence icon */
+  gchar *event_icon;
+
   gboolean online;
 };
 
@@ -64,6 +67,9 @@ empathy_roster_contact_get_property (GObject *object,
       case PROP_INDIVIDIUAL:
         g_value_set_object (value, self->priv->individual);
         break;
+      case PROP_GROUP:
+        g_value_set_string (value, self->priv->group);
+        break;
       case PROP_ONLINE:
         g_value_set_boolean (value, self->priv->online);
         break;
@@ -90,6 +96,10 @@ empathy_roster_contact_set_property (GObject *object,
         g_assert (self->priv->individual == NULL); /* construct only */
         self->priv->individual = g_value_dup_object (value);
         break;
+      case PROP_GROUP:
+        g_assert (self->priv->group == NULL); /* construct only */
+        self->priv->group = g_value_dup_string (value);
+        break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
         break;
@@ -159,25 +169,11 @@ alias_changed_cb (FolksIndividual *individual,
   update_alias (self);
 }
 
-static gboolean
-is_phone (FolksIndividual *individual)
-{
-  const gchar * const *types;
-
-  types = empathy_individual_get_client_types (individual);
-  if (types == NULL)
-    return FALSE;
-
-  if (g_strv_length ((GStrv) types) <= 0)
-    return FALSE;
-
-  return !tp_strdiff (types[0], "phone");
-}
-
 static void
 update_presence_msg (EmpathyRosterContact *self)
 {
   const gchar *msg;
+  GStrv types;
 
   msg = folks_presence_details_get_presence_message (
       FOLKS_PRESENCE_DETAILS (self->priv->individual));
@@ -192,7 +188,25 @@ update_presence_msg (EmpathyRosterContact *self)
     }
   else
     {
-      gtk_label_set_text (GTK_LABEL (self->priv->presence_msg), msg);
+      FolksPresenceType type;
+
+      type = folks_presence_details_get_presence_type (
+          FOLKS_PRESENCE_DETAILS (self->priv->individual));
+      if (type == FOLKS_PRESENCE_TYPE_ERROR)
+        {
+          gchar *tmp;
+
+          /* Add a prefix explaining that something goes wrong when trying to
+           * fetch contact's presence. */
+          tmp = g_strdup_printf (_("Server cannot find contact: %s"), msg);
+          gtk_label_set_text (GTK_LABEL (self->priv->presence_msg), tmp);
+
+          g_free (tmp);
+        }
+      else
+        {
+          gtk_label_set_text (GTK_LABEL (self->priv->presence_msg), msg);
+        }
 
       gtk_alignment_set (GTK_ALIGNMENT (self->priv->first_line_alig),
           0, 0.75, 1, 1);
@@ -201,8 +215,10 @@ update_presence_msg (EmpathyRosterContact *self)
       gtk_widget_show (self->priv->presence_msg);
     }
 
+  types = (GStrv) empathy_individual_get_client_types (self->priv->individual);
+
   gtk_widget_set_visible (self->priv->phone_icon,
-      is_phone (self->priv->individual));
+      empathy_client_types_contains_mobile_device (types));
 }
 
 static void
@@ -218,7 +234,10 @@ update_presence_icon (EmpathyRosterContact *self)
 {
   const gchar *icon;
 
-  icon = empathy_icon_name_for_individual (self->priv->individual);
+  if (self->priv->event_icon == NULL)
+    icon = empathy_icon_name_for_individual (self->priv->individual);
+  else
+    icon = self->priv->event_icon;
 
   gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->presence_icon), icon,
       GTK_ICON_SIZE_MENU);
@@ -317,10 +336,13 @@ empathy_roster_contact_dispose (GObject *object)
 static void
 empathy_roster_contact_finalize (GObject *object)
 {
-  //EmpathyRosterContact *self = EMPATHY_ROSTER_CONTACT (object);
+  EmpathyRosterContact *self = EMPATHY_ROSTER_CONTACT (object);
   void (*chain_up) (GObject *) =
       ((GObjectClass *) empathy_roster_contact_parent_class)->finalize;
 
+  g_free (self->priv->group);
+  g_free (self->priv->event_icon);
+
   if (chain_up != NULL)
     chain_up (object);
 }
@@ -344,6 +366,12 @@ empathy_roster_contact_class_init (
       G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (oclass, PROP_INDIVIDIUAL, spec);
 
+  spec = g_param_spec_string ("group", "Group",
+      "Group of this widget, or NULL",
+      NULL,
+      G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (oclass, PROP_GROUP, spec);
+
   spec = g_param_spec_boolean ("online", "Online",
       "TRUE if Individual is online",
       FALSE,
@@ -368,13 +396,13 @@ empathy_roster_contact_init (EmpathyRosterContact *self)
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
       EMPATHY_TYPE_ROSTER_CONTACT, EmpathyRosterContactPriv);
 
-  gtk_widget_set_size_request (GTK_WIDGET (self), 300, 64);
-
   main_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
 
   /* Avatar */
   self->priv->avatar = gtk_image_new ();
 
+  gtk_widget_set_size_request (self->priv->avatar, AVATAR_SIZE, AVATAR_SIZE);
+
   gtk_box_pack_start (GTK_BOX (main_box), self->priv->avatar, FALSE, FALSE, 0);
   gtk_widget_show (self->priv->avatar);
 
@@ -385,8 +413,10 @@ empathy_roster_contact_init (EmpathyRosterContact *self)
   first_line_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
   self->priv->alias = gtk_label_new (NULL);
+  gtk_label_set_ellipsize (GTK_LABEL (self->priv->alias), PANGO_ELLIPSIZE_END);
   gtk_box_pack_start (GTK_BOX (first_line_box), self->priv->alias,
       FALSE, FALSE, 0);
+  gtk_misc_set_alignment (GTK_MISC (self->priv->alias), 0, 0.5);
   gtk_widget_show (self->priv->alias);
 
   self->priv->phone_icon = gtk_image_new_from_icon_name ("phone-symbolic",
@@ -408,6 +438,8 @@ empathy_roster_contact_init (EmpathyRosterContact *self)
 
   /* Presence */
   self->priv->presence_msg = gtk_label_new (NULL);
+  gtk_label_set_ellipsize (GTK_LABEL (self->priv->presence_msg),
+      PANGO_ELLIPSIZE_END);
   gtk_box_pack_start (GTK_BOX (box), self->priv->presence_msg, TRUE, TRUE, 0);
   gtk_widget_show (self->priv->presence_msg);
 
@@ -426,16 +458,18 @@ empathy_roster_contact_init (EmpathyRosterContact *self)
 }
 
 GtkWidget *
-empathy_roster_contact_new (FolksIndividual *individual)
+empathy_roster_contact_new (FolksIndividual *individual,
+    const gchar *group)
 {
   g_return_val_if_fail (FOLKS_IS_INDIVIDUAL (individual), NULL);
 
   return g_object_new (EMPATHY_TYPE_ROSTER_CONTACT,
       "individual", individual,
-      "bottom-padding", 8,
-      "top-padding", 8,
-      "left-padding", 8,
-      "right-padding", 8,
+      "group", group,
+      "bottom-padding", 4,
+      "top-padding", 4,
+      "left-padding", 4,
+      "right-padding", 12,
       NULL);
 }
 
@@ -450,3 +484,28 @@ empathy_roster_contact_is_online (EmpathyRosterContact *self)
 {
   return self->priv->online;
 }
+
+const gchar *
+empathy_roster_contact_get_group (EmpathyRosterContact *self)
+{
+  return self->priv->group;
+}
+
+void
+empathy_roster_contact_set_event_icon (EmpathyRosterContact *self,
+    const gchar *icon)
+{
+  if (!tp_strdiff (self->priv->event_icon, icon))
+    return;
+
+  g_free (self->priv->event_icon);
+  self->priv->event_icon = g_strdup (icon);
+
+  update_presence_icon (self);
+}
+
+GdkPixbuf *
+empathy_roster_contact_get_avatar_pixbuf (EmpathyRosterContact *self)
+{
+  return gtk_image_get_pixbuf (GTK_IMAGE (self->priv->avatar));
+}