]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-log-window.c
Merge branch 'gnome-3-8'
[empathy.git] / libempathy-gtk / empathy-log-window.c
index 13fdefbd576ef7f5d47b5ba9d9ac01e1e96efd1c..a815c45fe870564ddbeb0823c32b8e25ede5481d 100644 (file)
  */
 
 #include "config.h"
-
-#include <string.h>
-#include <stdlib.h>
+#include "empathy-log-window.h"
 
 #include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-#include <webkit/webkit.h>
-
-#include <telepathy-glib/telepathy-glib.h>
 #include <telepathy-glib/proxy-subclass.h>
 
-#include <telepathy-logger/telepathy-logger.h>
-#ifdef HAVE_CALL_LOGS
-# include <telepathy-logger/call-event.h>
-#endif
-
-#include <extensions/extensions.h>
-
-#include <libempathy/action-chain-internal.h>
-#include <libempathy/empathy-camera-monitor.h>
-#include <libempathy/empathy-chatroom-manager.h>
-#include <libempathy/empathy-chatroom.h>
-#include <libempathy/empathy-gsettings.h>
-#include <libempathy/empathy-message.h>
-#include <libempathy/empathy-request-util.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-time.h>
-
-#include "empathy-log-window.h"
+#include "action-chain-internal.h"
 #include "empathy-account-chooser.h"
 #include "empathy-call-utils.h"
-#include "empathy-chat-view.h"
-#include "empathy-contact-dialogs.h"
+#include "empathy-camera-monitor.h"
+#include "empathy-geometry.h"
+#include "empathy-gsettings.h"
 #include "empathy-images.h"
+#include "empathy-individual-information-dialog.h"
+#include "empathy-request-util.h"
 #include "empathy-theme-manager.h"
 #include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 #include "empathy-webkit-utils.h"
-#include "empathy-geometry.h"
+#include "extensions.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 #define EMPATHY_NS "http://live.gnome.org/Empathy"
 
@@ -323,11 +304,17 @@ static void
 toolbutton_profile_clicked (GtkToolButton *toolbutton,
     EmpathyLogWindow *self)
 {
+  FolksIndividual *individual;
+
   g_return_if_fail (self != NULL);
   g_return_if_fail (EMPATHY_IS_CONTACT (self->priv->selected_contact));
 
-  empathy_contact_information_dialog_show (self->priv->selected_contact,
-      GTK_WINDOW (self));
+  individual = empathy_ensure_individual_from_tp_contact (
+      empathy_contact_get_tp_contact (self->priv->selected_contact));
+
+  empathy_display_individual_info (individual);
+
+  g_object_unref (individual);
 }
 
 static void
@@ -367,7 +354,9 @@ insert_or_change_row (EmpathyLogWindow *self,
 {
   char *str = gtk_tree_path_to_string (path);
   char *script, *text, *date, *stock_icon;
+  GString *escaped_text;
   char *icon = NULL;
+  gint i;
 
   gtk_tree_model_get (model, iter,
       COL_EVENTS_TEXT, &text,
@@ -388,16 +377,34 @@ insert_or_change_row (EmpathyLogWindow *self,
       gtk_icon_info_free (icon_info);
     }
 
+  escaped_text = g_string_new (NULL);
+
+  /* Only need to deal with «'» and «\».
+   *
+   * Note that these never appear in non-ascii utf8 characters, so just
+   * pretend like we have an ascii string...
+   */
+  for (i = 0; text && text[i]; i++)
+    {
+      gchar c = text[i];
+
+      if (c == '\'' || c == '\\')
+        g_string_append_c (escaped_text, '\\');
+
+      g_string_append_c (escaped_text, c);
+    }
+
   script = g_strdup_printf ("javascript:%s([%s], '%s', '%s', '%s');",
       method,
       g_strdelimit (str, ":", ','),
-      text,
+      escaped_text->str,
       icon != NULL ? icon : "",
       date);
 
   webkit_web_view_execute_script (WEBKIT_WEB_VIEW (self->priv->webview),
       script);
 
+  g_string_free (escaped_text, TRUE);
   g_free (str);
   g_free (text);
   g_free (date);
@@ -1232,22 +1239,20 @@ get_icon_for_event (TplEvent *event)
       if (!tp_str_empty (tpl_text_event_get_supersedes_token (text)))
         icon = EMPATHY_IMAGE_EDIT_MESSAGE;
     }
-#ifdef HAVE_CALL_LOGS
   else if (TPL_IS_CALL_EVENT (event))
     {
       TplCallEvent *call = TPL_CALL_EVENT (event);
-      TplCallEndReason reason = tpl_call_event_get_end_reason (call);
+      TpCallStateChangeReason reason = tpl_call_event_get_end_reason (call);
       TplEntity *sender = tpl_event_get_sender (event);
       TplEntity *receiver = tpl_event_get_receiver (event);
 
-      if (reason == TPL_CALL_END_REASON_NO_ANSWER)
+      if (reason == TP_CALL_STATE_CHANGE_REASON_NO_ANSWER)
         icon = EMPATHY_IMAGE_CALL_MISSED;
       else if (tpl_entity_get_entity_type (sender) == TPL_ENTITY_SELF)
         icon = EMPATHY_IMAGE_CALL_OUTGOING;
       else if (tpl_entity_get_entity_type (receiver) == TPL_ENTITY_SELF)
         icon = EMPATHY_IMAGE_CALL_INCOMING;
     }
-#endif
 
   return icon;
 }
@@ -1313,7 +1318,6 @@ log_window_append_chat_message (TplEvent *event,
   g_date_time_unref (date);
 }
 
-#ifdef HAVE_CALL_LOGS
 static void
 log_window_append_call (TplEvent *event,
     EmpathyMessage *message)
@@ -1357,7 +1361,7 @@ log_window_append_call (TplEvent *event,
       COL_EVENTS_EVENT, event,
       -1);
 
-  if (tpl_call_event_get_end_reason (call) != TPL_CALL_END_REASON_NO_ANSWER)
+  if (tpl_call_event_get_end_reason (call) != TP_CALL_STATE_CHANGE_REASON_NO_ANSWER)
     {
       gchar *body;
       gchar *tmp;
@@ -1404,7 +1408,6 @@ log_window_append_call (TplEvent *event,
   g_free (pretty_date);
   g_date_time_unref (started_date);
 }
-#endif
 
 static void
 log_window_append_message (TplEvent *event,
@@ -1412,10 +1415,8 @@ log_window_append_message (TplEvent *event,
 {
   if (TPL_IS_TEXT_EVENT (event))
     log_window_append_chat_message (event, message);
-#ifdef HAVE_CALL_LOGS
   else if (TPL_IS_CALL_EVENT (event))
     log_window_append_call (event, message);
-#endif
   else
     DEBUG ("Message type not handled");
 }
@@ -1746,6 +1747,35 @@ format_date_for_display (GDate *date)
   return text;
 }
 
+static void
+add_date_if_needed (EmpathyLogWindow *self,
+    GDate *date)
+{
+  GtkTreeModel *model;
+  GtkListStore *store;
+  gchar *text;
+
+  model = gtk_tree_view_get_model (GTK_TREE_VIEW (
+        log_window->priv->treeview_when));
+  store = GTK_LIST_STORE (model);
+
+  /* Add the date if it's not already there */
+  has_element = FALSE;
+  gtk_tree_model_foreach (model, model_has_date, date);
+  if (has_element)
+    return;
+
+  text = format_date_for_display (date);
+
+  gtk_list_store_insert_with_values (store, NULL, -1,
+      COL_WHEN_DATE, date,
+      COL_WHEN_TEXT, text,
+      COL_WHEN_ICON, CALENDAR_ICON,
+      -1);
+
+  g_free (text);
+}
+
 static void
 populate_dates_from_search_hits (GList *accounts,
     GList *targets)
@@ -1790,20 +1820,7 @@ populate_dates_from_search_hits (GList *accounts,
         if (!found)
           continue;
 
-      /* Add the date if it's not already there */
-      has_element = FALSE;
-      gtk_tree_model_foreach (model, model_has_date, hit->date);
-      if (!has_element)
-        {
-          gchar *text = format_date_for_display (hit->date);
-
-          gtk_list_store_append (store, &iter);
-          gtk_list_store_set (store, &iter,
-              COL_WHEN_DATE, hit->date,
-              COL_WHEN_TEXT, text,
-              COL_WHEN_ICON, CALENDAR_ICON,
-              -1);
-        }
+      add_date_if_needed (log_window, hit->date);
     }
 
   if (gtk_tree_model_get_iter_first (model, &iter))
@@ -1834,6 +1851,41 @@ populate_dates_from_search_hits (GList *accounts,
     }
 }
 
+static void
+add_event_to_store (EmpathyLogWindow *self,
+    TpAccount *account,
+    TplEntity *entity)
+{
+  GtkListStore *store;
+  TplEntityType type = tpl_entity_get_entity_type (entity);
+  EmpathyContact *contact;
+  const gchar *name;
+  gchar *sort_key;
+  gboolean room = type == TPL_ENTITY_ROOM;
+
+  store = GTK_LIST_STORE (gtk_tree_view_get_model (
+        GTK_TREE_VIEW (log_window->priv->treeview_who)));
+
+  contact = empathy_contact_from_tpl_contact (account, entity);
+
+  name = empathy_contact_get_alias (contact);
+  sort_key = g_utf8_collate_key (name, -1);
+
+  gtk_list_store_insert_with_values (store, NULL, -1,
+      COL_WHO_TYPE, COL_TYPE_NORMAL,
+      COL_WHO_ICON, room ? EMPATHY_IMAGE_GROUP_MESSAGE
+                         : EMPATHY_IMAGE_AVATAR_DEFAULT,
+      COL_WHO_NAME, name,
+      COL_WHO_NAME_SORT_KEY, sort_key,
+      COL_WHO_ID, tpl_entity_get_identifier (entity),
+      COL_WHO_ACCOUNT, account,
+      COL_WHO_TARGET, entity,
+      -1);
+
+  g_free (sort_key);
+  g_object_unref (contact);
+}
+
 static void
 populate_entities_from_search_hits (void)
 {
@@ -1873,32 +1925,7 @@ populate_entities_from_search_hits (void)
       gtk_tree_model_foreach (model, model_has_entity, hit);
       if (!has_element)
         {
-          TplEntityType type = tpl_entity_get_entity_type (hit->target);
-          EmpathyContact *contact;
-          const gchar *name;
-          gchar *sort_key;
-          gboolean room = type == TPL_ENTITY_ROOM;
-
-          contact = empathy_contact_from_tpl_contact (hit->account,
-              hit->target);
-
-          name = empathy_contact_get_alias (contact);
-          sort_key = g_utf8_collate_key (name, -1);
-
-          gtk_list_store_append (store, &iter);
-          gtk_list_store_set (store, &iter,
-              COL_WHO_TYPE, COL_TYPE_NORMAL,
-              COL_WHO_ICON, room ? EMPATHY_IMAGE_GROUP_MESSAGE
-                                 : EMPATHY_IMAGE_AVATAR_DEFAULT,
-              COL_WHO_NAME, name,
-              COL_WHO_NAME_SORT_KEY, sort_key,
-              COL_WHO_ID, tpl_entity_get_identifier (hit->target),
-              COL_WHO_ACCOUNT, hit->account,
-              COL_WHO_TARGET, hit->target,
-              -1);
-
-          g_free (sort_key);
-          g_object_unref (contact);
+          add_event_to_store (log_window, hit->account, hit->target);
         }
     }
 
@@ -2344,32 +2371,7 @@ log_manager_got_entities_cb (GObject *manager,
 
   for (l = entities; l; l = l->next)
     {
-      TplEntity *entity = TPL_ENTITY (l->data);
-      TplEntityType type = tpl_entity_get_entity_type (entity);
-      EmpathyContact *contact;
-      const gchar *name;
-      gchar *sort_key;
-      gboolean room = type == TPL_ENTITY_ROOM;
-
-      contact = empathy_contact_from_tpl_contact (ctx->account, entity);
-
-      name = empathy_contact_get_alias (contact);
-      sort_key = g_utf8_collate_key (name, -1);
-
-      gtk_list_store_append (store, &iter);
-      gtk_list_store_set (store, &iter,
-          COL_WHO_TYPE, COL_TYPE_NORMAL,
-          COL_WHO_ICON, room ? EMPATHY_IMAGE_GROUP_MESSAGE
-                             : EMPATHY_IMAGE_AVATAR_DEFAULT,
-          COL_WHO_NAME, name,
-          COL_WHO_NAME_SORT_KEY, sort_key,
-          COL_WHO_ID, tpl_entity_get_identifier (entity),
-          COL_WHO_ACCOUNT, ctx->account,
-          COL_WHO_TARGET, entity,
-          -1);
-
-      g_free (sort_key);
-      g_object_unref (contact);
+      add_event_to_store (ctx->self, ctx->account, l->data);
 
       if (ctx->self->priv->selected_account != NULL &&
           !tp_strdiff (tp_proxy_get_object_path (ctx->account),
@@ -2502,7 +2504,7 @@ log_window_who_populate (EmpathyLogWindow *self)
       GList *accounts, *l;
 
       manager = empathy_account_chooser_get_account_manager (account_chooser);
-      accounts = tp_account_manager_get_valid_accounts (manager);
+      accounts = tp_account_manager_dup_valid_accounts (manager);
 
       for (l = accounts; l != NULL; l = l->next)
         {
@@ -2513,7 +2515,7 @@ log_window_who_populate (EmpathyLogWindow *self)
               get_entities_for_account, ctx);
         }
 
-      g_list_free (accounts);
+      g_list_free_full (accounts, g_object_unref);
     }
   _tpl_action_chain_append (self->priv->chain, select_first_entity, self);
   _tpl_action_chain_start (self->priv->chain);
@@ -3033,23 +3035,21 @@ log_window_what_setup (EmpathyLogWindow *self)
   GtkTreeIter        iter;
   GtkTreeStore      *store;
   GtkCellRenderer   *cell;
+  GtkTreeIter parent;
   guint i;
+
   struct event events [] = {
     { TPL_EVENT_MASK_ANY, 0, NULL, _("Anything") },
     { WHAT_TYPE_SEPARATOR, 0, NULL, "separator" },
     { TPL_EVENT_MASK_TEXT, 0, "format-justify-fill", _("Text chats") },
-#ifdef HAVE_CALL_LOGS
     { TPL_EVENT_MASK_CALL, EVENT_CALL_ALL, EMPATHY_IMAGE_CALL, _("Calls") },
-#endif
   };
-#ifdef HAVE_CALL_LOGS
+
   struct event call_events [] = {
     { TPL_EVENT_MASK_CALL, EVENT_CALL_INCOMING, EMPATHY_IMAGE_CALL_INCOMING, _("Incoming calls") },
     { TPL_EVENT_MASK_CALL, EVENT_CALL_OUTGOING, EMPATHY_IMAGE_CALL_OUTGOING, _("Outgoing calls") },
     { TPL_EVENT_MASK_CALL, EVENT_CALL_MISSED, EMPATHY_IMAGE_CALL_MISSED, _("Missed calls") }
   };
-  GtkTreeIter parent;
-#endif
 
   view = GTK_TREE_VIEW (self->priv->treeview_what);
   selection = gtk_tree_view_get_selection (view);
@@ -3107,7 +3107,6 @@ log_window_what_setup (EmpathyLogWindow *self)
           -1);
     }
 
-#ifdef HAVE_CALL_LOGS
   gtk_tree_model_iter_nth_child (model, &parent, NULL, 3);
   for (i = 0; i < G_N_ELEMENTS (call_events); i++)
     {
@@ -3120,7 +3119,6 @@ log_window_what_setup (EmpathyLogWindow *self)
           COL_WHAT_ICON, call_events[i].icon,
           -1);
     }
-#endif
 
   gtk_tree_view_expand_all (view);
 
@@ -3227,7 +3225,6 @@ log_window_got_messages_for_date_cb (GObject *manager,
       TplEvent *event = l->data;
       gboolean append = TRUE;
 
-#ifdef HAVE_CALL_LOGS
       if (TPL_IS_CALL_EVENT (l->data)
           && ctx->event_mask & TPL_EVENT_MASK_CALL
           && ctx->event_mask != TPL_EVENT_MASK_ANY)
@@ -3242,11 +3239,12 @@ log_window_got_messages_for_date_cb (GObject *manager,
             }
           else
             {
-              TplCallEndReason reason = tpl_call_event_get_end_reason (call);
+              TpCallStateChangeReason reason =
+                tpl_call_event_get_end_reason (call);
               TplEntity *sender = tpl_event_get_sender (event);
               TplEntity *receiver = tpl_event_get_receiver (event);
 
-              if (reason == TPL_CALL_END_REASON_NO_ANSWER)
+              if (reason == TP_CALL_STATE_CHANGE_REASON_NO_ANSWER)
                 {
                   if (ctx->subtype & EVENT_CALL_MISSED)
                     append = TRUE;
@@ -3263,7 +3261,6 @@ log_window_got_messages_for_date_cb (GObject *manager,
                 }
             }
         }
-#endif
 
       if (append)
         {
@@ -3434,24 +3431,7 @@ log_manager_got_dates_cb (GObject *manager,
 
   for (l = dates; l != NULL; l = l->next)
     {
-      GDate *date = l->data;
-
-      /* Add the date if it's not already there */
-      has_element = FALSE;
-      gtk_tree_model_foreach (model, model_has_date, date);
-      if (!has_element)
-        {
-          gchar *text = format_date_for_display (date);
-
-          gtk_list_store_append (store, &iter);
-          gtk_list_store_set (store, &iter,
-              COL_WHEN_DATE, date,
-              COL_WHEN_TEXT, text,
-              COL_WHEN_ICON, CALENDAR_ICON,
-              -1);
-
-          g_free (text);
-        }
+      add_date_if_needed (log_window, l->data);
     }
 
   if (gtk_tree_model_get_iter_first (model, &iter))