]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-individual-widget.c
Change Finnish translation team web page to l10n.gnome.org
[empathy.git] / libempathy-gtk / empathy-individual-widget.c
index 08c1c1c6ba463ab972549aecd6d21f93acab14eb..fac2c5a1bd46cf42ecfb0186a083dd4e0c289c35 100644 (file)
  *          Philip Withnall <philip.withnall@collabora.co.uk>
  */
 
-#include <config.h>
-
-#include <string.h>
-#include <stdlib.h>
+#include "config.h"
+#include "empathy-individual-widget.h"
 
-#include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
-
-#include <telepathy-glib/util.h>
-
-#include <folks/folks.h>
-#include <folks/folks-telepathy.h>
+#include <tp-account-widgets/tpaw-builder.h>
+#include <tp-account-widgets/tpaw-contactinfo-utils.h>
+#include <tp-account-widgets/tpaw-time.h>
+#include <tp-account-widgets/tpaw-utils.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
 
 #ifdef HAVE_LIBCHAMPLAIN
 #include <champlain/champlain.h>
 #include <champlain-gtk/champlain-gtk.h>
 #endif
 
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-location.h>
-#include <libempathy/empathy-time.h>
-
 #include "empathy-avatar-image.h"
-#include "empathy-contactinfo-utils.h"
 #include "empathy-groups-widget.h"
 #include "empathy-gtk-enum-types.h"
-#include "empathy-individual-widget.h"
+#include "empathy-location.h"
+#include "empathy-request-util.h"
 #include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 /**
  * SECTION:empathy-individual-widget
@@ -228,6 +222,70 @@ add_row (GtkGrid *grid,
   gtk_widget_show (value);
 }
 
+static gboolean
+channel_name_activated_cb (
+    GtkLabel *label,
+    gchar *uri,
+    TpAccount *account)
+{
+  empathy_join_muc (account, uri, empathy_get_current_action_time ());
+  return TRUE;
+}
+
+static GtkWidget *
+create_channel_list_label (TpAccount *account,
+    GList *info,
+    guint row)
+{
+  GtkWidget *label = NULL;
+  GString *label_markup = g_string_new ("");
+  guint i;
+  GPtrArray *channels;
+  GList *l;
+
+  /* Is there channels? */
+  channels = g_ptr_array_new ();
+
+  for (l = info; l != NULL; l = l->next)
+    {
+      TpContactInfoField *field = l->data;
+
+      if (!tp_strdiff (field->field_name, "x-irc-channel"))
+        g_ptr_array_add (channels, (gpointer) field->field_value[0]);
+    }
+
+  if (channels->len == 0)
+    goto out;
+
+  for (i = 0; i < channels->len; i++)
+    {
+      const gchar *channel_name = g_ptr_array_index (channels, i);
+      /* We abuse the URI of the link to hold the channel name. It seems to
+       * be okay to just use it essentially verbatim, rather than trying to
+       * ensure it's actually a valid URI. */
+      gchar *escaped = g_markup_escape_text (channel_name, -1);
+
+      if (i > 0)
+        g_string_append (label_markup, ", ");
+
+      g_string_append_printf (label_markup, "<a href='%s'>%s</a>",
+          escaped, escaped);
+      g_free (escaped);
+    }
+
+  label = gtk_label_new (NULL);
+  gtk_label_set_markup (GTK_LABEL (label), label_markup->str);
+  gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+
+  g_signal_connect (label, "activate-link",
+      (GCallback) channel_name_activated_cb, account);
+
+out:
+  g_ptr_array_unref (channels);
+  g_string_free (label_markup, TRUE);
+
+  return label;
+}
 static guint
 details_update_show (EmpathyIndividualWidget *self,
     TpContact *contact)
@@ -239,14 +297,14 @@ details_update_show (EmpathyIndividualWidget *self,
   TpConnection *conn;
   TpAccount *account;
 
-  info = tp_contact_get_contact_info (contact);
-  info = g_list_sort (info, (GCompareFunc) empathy_contact_info_field_cmp);
+  info = tp_contact_dup_contact_info (contact);
+  info = g_list_sort (info, (GCompareFunc) tpaw_contact_info_field_cmp);
   for (l = info; l != NULL; l = l->next)
     {
       TpContactInfoField *field = l->data;
       gchar *title;
       const gchar *value;
-      EmpathyContactInfoFormatFunc format;
+      TpawContactInfoFormatFunc format;
       GtkWidget *title_widget, *value_widget;
 
       if (field->field_value == NULL || field->field_value[0] == NULL)
@@ -254,7 +312,7 @@ details_update_show (EmpathyIndividualWidget *self,
 
       value = field->field_value[0];
 
-      if (!empathy_contact_info_lookup_field (field->field_name,
+      if (!tpaw_contact_info_lookup_field (field->field_name,
           NULL, &format))
         {
           DEBUG ("Unhandled ContactInfo field: %s", field->field_name);
@@ -266,8 +324,8 @@ details_update_show (EmpathyIndividualWidget *self,
         continue;
 
       /* Add Title */
-      title = empathy_contact_info_field_label (field->field_name,
-          field->parameters);
+      title = tpaw_contact_info_field_label (field->field_name,
+          field->parameters, TRUE);
       title_widget = gtk_label_new (title);
 
       /* Add Value */
@@ -294,8 +352,7 @@ details_update_show (EmpathyIndividualWidget *self,
   conn = tp_contact_get_connection (contact);
   account = tp_connection_get_account (conn);
 
-  channels_label = empathy_contact_info_create_channel_list_label (account,
-      info, n_rows);
+  channels_label = create_channel_list_label (account, info, n_rows);
 
   if (channels_label != NULL)
     {
@@ -309,7 +366,7 @@ details_update_show (EmpathyIndividualWidget *self,
       n_rows++;
     }
 
-  g_list_free (info);
+  tp_contact_info_list_free (info);
 
   return n_rows;
 }
@@ -603,7 +660,7 @@ location_update (EmpathyIndividualWidget *self)
 
       stamp = g_value_get_int64 (value);
 
-      user_date = empathy_time_to_string_relative (stamp);
+      user_date = tpaw_time_to_string_relative (stamp);
 
       tmp = g_strdup_printf ("<b>%s</b>", _("Location"));
       /* translators: format is "Location, $date" */
@@ -656,7 +713,7 @@ location_update (EmpathyIndividualWidget *self)
           gint64 time_;
 
           time_ = g_value_get_int64 (value);
-          svalue = empathy_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
+          svalue = tpaw_time_to_string_utc (time_, _("%B %e, %Y at %R UTC"));
         }
 
       if (svalue != NULL)
@@ -680,8 +737,7 @@ location_update (EmpathyIndividualWidget *self)
 
 #ifdef HAVE_LIBCHAMPLAIN
   if ((g_hash_table_lookup (location, EMPATHY_LOCATION_LAT) != NULL) &&
-      (g_hash_table_lookup (location, EMPATHY_LOCATION_LON) != NULL) &&
-      !(priv->flags & EMPATHY_INDIVIDUAL_WIDGET_FOR_TOOLTIP))
+      (g_hash_table_lookup (location, EMPATHY_LOCATION_LON) != NULL))
     {
       /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
        * windows */
@@ -809,9 +865,7 @@ client_types_update (EmpathyIndividualWidget *self)
 
   types = tp_contact_get_client_types (priv->contact);
 
-  if (types != NULL
-      && g_strv_length ((gchar **) types) > 0
-      && !tp_strdiff (types[0], "phone"))
+  if (empathy_client_types_contains_mobile_device ((GStrv) types))
     {
       gtk_widget_show (priv->hbox_client_types);
     }
@@ -1215,6 +1269,8 @@ notify_presence_cb (gpointer folks_object,
   GtkWidget *status_label, *state_image;
   const gchar *message;
   gchar *markup_text = NULL;
+  FolksPresenceType presence;
+  gboolean visible = TRUE;
 
   if (FOLKS_IS_INDIVIDUAL (folks_object))
     grid = G_OBJECT (priv->individual_grid);
@@ -1229,27 +1285,36 @@ notify_presence_cb (gpointer folks_object,
   status_label = g_object_get_data (grid, "status-label");
   state_image = g_object_get_data (grid, "state-image");
 
-  /* FIXME: Default messages should be moved into libfolks (bgo#627403) */
+  presence = folks_presence_details_get_presence_type (
+      FOLKS_PRESENCE_DETAILS (folks_object));
+  if (presence == FOLKS_PRESENCE_TYPE_UNKNOWN ||
+      presence == FOLKS_PRESENCE_TYPE_ERROR)
+    {
+      /* Don't display anything if we don't know the presence */
+      visible = FALSE;
+      goto out;
+    }
+
   message = folks_presence_details_get_presence_message (
       FOLKS_PRESENCE_DETAILS (folks_object));
-  if (EMP_STR_EMPTY (message))
+  if (TPAW_STR_EMPTY (message))
     {
-      message = empathy_presence_get_default_message (
-          folks_presence_details_get_presence_type (
-              FOLKS_PRESENCE_DETAILS (folks_object)));
+      message = folks_presence_details_get_default_message_from_type (presence);
     }
 
   if (message != NULL)
-    markup_text = empathy_add_link_markup (message);
+    markup_text = tpaw_add_link_markup (message);
   gtk_label_set_markup (GTK_LABEL (status_label), markup_text);
   g_free (markup_text);
 
   gtk_image_set_from_icon_name (GTK_IMAGE (state_image),
       empathy_icon_name_for_presence (
-          folks_presence_details_get_presence_type (
-              FOLKS_PRESENCE_DETAILS (folks_object))),
+        empathy_folks_presence_type_to_tp (presence)),
       GTK_ICON_SIZE_BUTTON);
-  gtk_widget_show (state_image);
+
+out:
+  gtk_widget_set_visible (status_label, visible);
+  gtk_widget_set_visible (state_image, visible);
 }
 
 static void
@@ -1323,7 +1388,7 @@ alias_presence_avatar_favourite_set_up (EmpathyIndividualWidget *self,
   current_row++;
 
   /* Presence */
-  priv->hbox_presence = gtk_hbox_new (FALSE, 6);
+  priv->hbox_presence = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
 
   /* Presence image */
   image = gtk_image_new_from_stock (GTK_STOCK_MISSING_IMAGE,
@@ -1478,7 +1543,7 @@ add_persona (EmpathyIndividualWidget *self,
   gtk_widget_show (label);
 
   /* Pack the protocol icon with the account name in an hbox */
-  hbox = GTK_BOX (gtk_hbox_new (FALSE, 6));
+  hbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6));
 
   account_label = gtk_label_new (NULL);
   gtk_label_set_selectable (GTK_LABEL (account_label),
@@ -1540,7 +1605,7 @@ add_persona (EmpathyIndividualWidget *self,
   gtk_widget_show (GTK_WIDGET (grid));
 
   /* Pack a separator after the grid */
-  separator = gtk_hseparator_new ();
+  separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
   g_object_set_data (G_OBJECT (grid), "separator", separator);
   gtk_box_pack_start (GTK_BOX (priv->vbox_individual), separator, FALSE, FALSE,
       0);
@@ -1675,6 +1740,17 @@ individual_grid_destroy (EmpathyIndividualWidget *self)
 
   gtk_container_remove (GTK_CONTAINER (priv->vbox_individual),
       GTK_WIDGET (priv->individual_grid));
+
+#ifdef HAVE_LIBCHAMPLAIN
+  if (priv->map_view_embed != NULL)
+    {
+      gtk_container_remove (GTK_CONTAINER (priv->viewport_map),
+          priv->map_view_embed);
+
+      priv->map_view_embed = NULL;
+    }
+#endif
+
   priv->individual_grid = NULL;
 }
 
@@ -1708,6 +1784,7 @@ personas_changed_cb (FolksIndividual *individual,
 
       g_clear_object (&persona);
     }
+  g_clear_object (&iter);
 
   /*
    * What we display for various conditions:
@@ -1762,30 +1839,30 @@ personas_changed_cb (FolksIndividual *individual,
     }
   else if (!was_showing_personas && will_show_personas)
     {
-      gboolean c;
-
       /* Remove the old Individual grid */
       individual_grid_destroy (self);
 
       /* Set up all the Persona grids instead */
-      for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
+      iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+      while (gee_iterator_next (iter))
         {
           FolksPersona *persona = gee_iterator_get (iter);
           add_persona (self, persona);
           g_clear_object (&persona);
         }
+      g_clear_object (&iter);
     }
   else if (was_showing_personas && !will_show_personas)
     {
-      gboolean c;
-
       /* Remove all Personas */
-      for (c = gee_iterator_first (iter); c; c = gee_iterator_next (iter))
+      iter = gee_iterable_iterator (GEE_ITERABLE (personas));
+      while (gee_iterator_next (iter))
         {
           FolksPersona *persona = gee_iterator_get (iter);
           remove_persona (self, persona);
           g_clear_object (&persona);
         }
+      g_clear_object (&iter);
 
       if (removed != NULL)
         {
@@ -1804,7 +1881,6 @@ personas_changed_cb (FolksIndividual *individual,
       /* Set up the Individual grid instead */
       individual_grid_set_up (self);
     }
-  g_clear_object (&iter);
 
   /* Hide the last separator and show the others */
   children = gtk_container_get_children (GTK_CONTAINER (priv->vbox_individual));
@@ -1958,7 +2034,7 @@ empathy_individual_widget_init (EmpathyIndividualWidget *self)
 
   filename = empathy_file_lookup ("empathy-individual-widget.ui",
       "libempathy-gtk");
-  gui = empathy_builder_get_file (filename,
+  gui = tpaw_builder_get_file (filename,
       "scrolled_window_individual", &priv->scrolled_window_individual,
       "viewport_individual", &priv->viewport_individual,
       "vbox_individual_widget", &priv->vbox_individual_widget,