]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-log-window.c
Merge remote-tracking branch 'glassrose/debug-window-send-to-pastebin-button-658724'
[empathy.git] / libempathy-gtk / empathy-log-window.c
index 9ef1e16f5bdeb4050b82c57deca785c35ce0c935..13fdefbd576ef7f5d47b5ba9d9ac01e1e96efd1c 100644 (file)
@@ -34,8 +34,6 @@
 #include <telepathy-glib/telepathy-glib.h>
 #include <telepathy-glib/proxy-subclass.h>
 
-#include <telepathy-yell/telepathy-yell.h>
-
 #include <telepathy-logger/telepathy-logger.h>
 #ifdef HAVE_CALL_LOGS
 # include <telepathy-logger/call-event.h>
@@ -62,6 +60,7 @@
 #include "empathy-theme-manager.h"
 #include "empathy-ui-utils.h"
 #include "empathy-webkit-utils.h"
+#include "empathy-geometry.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
 #include <libempathy/empathy-debug.h>
@@ -298,16 +297,6 @@ ctx_free (Ctx *ctx)
   g_slice_free (Ctx, ctx);
 }
 
-static void
-account_chooser_ready_cb (EmpathyAccountChooser *chooser,
-    EmpathyLogWindow *self)
-{
-  /* We'll display the account once the model has been populate with the chats
-   * of this account. */
-  empathy_account_chooser_set_account (EMPATHY_ACCOUNT_CHOOSER (
-      self->priv->account_chooser), self->priv->selected_account);
-}
-
 static void
 select_account_once_ready (EmpathyLogWindow *self,
     TpAccount *account,
@@ -326,12 +315,8 @@ select_account_once_ready (EmpathyLogWindow *self,
 
   self->priv->selected_is_chatroom = is_chatroom;
 
-  if (empathy_account_chooser_is_ready (account_chooser))
-    account_chooser_ready_cb (account_chooser, self);
-  else
-    /* Chat will be selected once the account chooser is ready */
-    g_signal_connect (account_chooser, "ready",
-        G_CALLBACK (account_chooser_ready_cb), self);
+  empathy_account_chooser_set_account (account_chooser,
+      self->priv->selected_account);
 }
 
 static void
@@ -617,6 +602,7 @@ empathy_log_window_init (EmpathyLogWindow *self)
   GFile *gfile;
   GtkWidget *vbox, *accounts, *search, *label, *closeitem;
   GtkWidget *scrolledwindow_events;
+  gchar *uri;
 
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
       EMPATHY_TYPE_LOG_WINDOW, EmpathyLogWindowPriv);
@@ -670,7 +656,7 @@ empathy_log_window_init (EmpathyLogWindow *self)
       G_CALLBACK (gtk_widget_destroy), self);
 
   /* Account chooser for chats */
-  vbox = gtk_vbox_new (FALSE, 3);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
 
   self->priv->account_chooser = empathy_account_chooser_new ();
   account_chooser = EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser);
@@ -700,13 +686,13 @@ empathy_log_window_init (EmpathyLogWindow *self)
   gtk_container_add (GTK_CONTAINER (accounts), vbox);
 
   /* Search entry */
-  vbox = gtk_vbox_new (FALSE, 3);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
 
   self->priv->search_entry = gtk_entry_new ();
-  gtk_entry_set_icon_from_stock (GTK_ENTRY (self->priv->search_entry),
-      GTK_ENTRY_ICON_PRIMARY, GTK_STOCK_FIND);
-  gtk_entry_set_icon_from_stock (GTK_ENTRY (self->priv->search_entry),
-      GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
+  gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self->priv->search_entry),
+      GTK_ENTRY_ICON_SECONDARY, "edit-find-symbolic");
+  gtk_entry_set_icon_sensitive (GTK_ENTRY (self->priv->search_entry),
+                                GTK_ENTRY_ICON_SECONDARY, FALSE);
 
   label = gtk_label_new (_("Search"));
 
@@ -759,9 +745,10 @@ empathy_log_window_init (EmpathyLogWindow *self)
   gfile = g_file_new_for_path (filename);
   g_free (filename);
 
-  webkit_web_view_load_uri (WEBKIT_WEB_VIEW (self->priv->webview),
-      g_file_get_uri (gfile));
+  uri = g_file_get_uri (gfile);
+  webkit_web_view_load_uri (WEBKIT_WEB_VIEW (self->priv->webview), uri);
   g_object_unref (gfile);
+  g_free (uri);
 
   /* handle all navigation externally */
   g_signal_connect (self->priv->webview, "navigation-policy-decision-requested",
@@ -785,6 +772,8 @@ empathy_log_window_init (EmpathyLogWindow *self)
 
   log_window_update_buttons_sensitivity (self);
   gtk_widget_show (GTK_WIDGET (self));
+
+  empathy_geometry_bind (GTK_WINDOW (self), "log-window");
 }
 
 GtkWidget *
@@ -882,7 +871,7 @@ maybe_refresh_logs (TpChannel *channel,
       !(event_mask & TPL_EVENT_MASK_TEXT))
     goto out;
   if ((!tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) ||
-       !tp_strdiff (type, TPY_IFACE_CHANNEL_TYPE_CALL)) &&
+       !tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_CALL)) &&
       !(event_mask & TPL_EVENT_MASK_CALL))
     goto out;
 
@@ -1024,7 +1013,7 @@ observe_channels (TpSimpleObserver *observer,
           tp_g_signal_connect_object (channel, "invalidated",
               G_CALLBACK (on_channel_ended), self, 0);
         }
-      else if (!tp_strdiff (type, TPY_IFACE_CHANNEL_TYPE_CALL) ||
+      else if (!tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_CALL) ||
           !tp_strdiff (type, TP_IFACE_CHANNEL_TYPE_STREAMED_MEDIA))
         {
           g_hash_table_insert (self->priv->channels,
@@ -1069,7 +1058,7 @@ log_window_create_observer (EmpathyLogWindow *self)
   tp_base_client_take_observer_filter (self->priv->observer,
       tp_asv_new (
           TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING,
-            TPY_IFACE_CHANNEL_TYPE_CALL,
+            TP_IFACE_CHANNEL_TYPE_CALL,
           NULL));
 
   tp_base_client_register (self->priv->observer, NULL);
@@ -1634,9 +1623,11 @@ model_has_date (GtkTreeModel *model,
   if (!g_date_compare (date, d))
     {
       has_element = TRUE;
+      g_date_free (d);
       return TRUE;
     }
 
+  g_date_free (d);
   return FALSE;
 }
 
@@ -1817,18 +1808,27 @@ populate_dates_from_search_hits (GList *accounts,
 
   if (gtk_tree_model_get_iter_first (model, &iter))
     {
+      GDate *date;
+
+      date = g_date_new_dmy (1, 1, -1),
+
       gtk_list_store_prepend (store, &iter);
       gtk_list_store_set (store, &iter,
-          COL_WHEN_DATE, g_date_new_dmy (1, 1, -1),
+          COL_WHEN_DATE, date,
           COL_WHEN_TEXT, "separator",
           -1);
 
+      g_date_free (date);
+
+      date = g_date_new_dmy (2, 1, -1),
       gtk_list_store_prepend (store, &iter);
       gtk_list_store_set (store, &iter,
-          COL_WHEN_DATE, g_date_new_dmy (2, 1, -1),
+          COL_WHEN_DATE, date,
           COL_WHEN_TEXT, _("Anytime"),
           -1);
 
+      g_date_free (date);
+
       if (gtk_tree_model_iter_nth_child (model, &iter, NULL, 2))
         gtk_tree_selection_select_iter (selection, &iter);
     }
@@ -2025,6 +2025,25 @@ static void
 log_window_search_entry_changed_cb (GtkWidget *entry,
     EmpathyLogWindow *self)
 {
+  const gchar *str;
+
+  str = gtk_entry_get_text (GTK_ENTRY (self->priv->search_entry));
+
+  if (!tp_str_empty (str))
+    {
+      gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self->priv->search_entry),
+          GTK_ENTRY_ICON_SECONDARY, "edit-clear-symbolic");
+      gtk_entry_set_icon_sensitive (GTK_ENTRY (self->priv->search_entry),
+          GTK_ENTRY_ICON_SECONDARY, TRUE);
+    }
+  else
+    {
+      gtk_entry_set_icon_from_icon_name (GTK_ENTRY (self->priv->search_entry),
+          GTK_ENTRY_ICON_SECONDARY, "edit-find-symbolic");
+      gtk_entry_set_icon_sensitive (GTK_ENTRY (self->priv->search_entry),
+          GTK_ENTRY_ICON_SECONDARY, FALSE);
+    }
+
   if (self->priv->source != 0)
     g_source_remove (self->priv->source);
   self->priv->source = g_timeout_add (500, (GSourceFunc) start_find_search,
@@ -2051,31 +2070,78 @@ log_window_search_entry_icon_pressed_cb (GtkEntry *entry,
     "", -1);
 }
 
+static void
+do_update_buttons_sensitivity (EmpathyLogWindow *self)
+{
+  EmpathyCapabilities capabilities;
+  gboolean profile, chat, call, video;
+
+  tp_clear_object (&self->priv->button_video_binding);
+
+  if (self->priv->selected_contact != NULL)
+    {
+      capabilities = empathy_contact_get_capabilities (
+          self->priv->selected_contact);
+
+      profile = chat = TRUE;
+      call = capabilities & EMPATHY_CAPABILITIES_AUDIO;
+      video = capabilities & EMPATHY_CAPABILITIES_VIDEO;
+    }
+  else
+    {
+      profile = chat = call = video = FALSE;
+    }
+
+  gtk_widget_set_sensitive (self->priv->button_profile, profile);
+  gtk_widget_set_sensitive (self->priv->button_chat, chat);
+  gtk_widget_set_sensitive (self->priv->button_call, call);
+
+  if (video)
+    {
+      self->priv->button_video_binding = g_object_bind_property (
+          self->priv->camera_monitor, "available",
+          self->priv->button_video, "sensitive",
+          G_BINDING_SYNC_CREATE);
+    }
+  else
+    {
+      /* Don't override the binding */
+      gtk_widget_set_sensitive (self->priv->button_video, video);
+    }
+}
+
+static void
+contact_capabilities_changed_cb (EmpathyContact *contact,
+    GParamSpec *spec,
+    EmpathyLogWindow *self)
+{
+  do_update_buttons_sensitivity (self);
+}
+
 static void
 log_window_update_buttons_sensitivity (EmpathyLogWindow *self)
 {
   GtkTreeView *view;
   GtkTreeModel *model;
   GtkTreeSelection *selection;
-  EmpathyCapabilities capabilities;
   TpAccount *account;
   TplEntity *target;
   GtkTreeIter iter;
   GList *paths;
   GtkTreePath *path;
-  gboolean profile, chat, call, video;
 
-  profile = chat = call = video = FALSE;
+  if (self->priv->selected_contact != NULL)
+    {
+      g_signal_handlers_disconnect_by_func (self->priv->selected_contact,
+          contact_capabilities_changed_cb, self);
 
-  tp_clear_object (&self->priv->button_video_binding);
-  tp_clear_object (&self->priv->selected_contact);
+      tp_clear_object (&self->priv->selected_contact);
+    }
 
   view = GTK_TREE_VIEW (self->priv->treeview_who);
   model = gtk_tree_view_get_model (view);
   selection = gtk_tree_view_get_selection (view);
 
-  profile = chat = call = video = FALSE;
-
   if (!gtk_tree_model_get_iter_first (model, &iter))
     goto events;
 
@@ -2103,12 +2169,6 @@ log_window_update_buttons_sensitivity (EmpathyLogWindow *self)
   g_object_unref (account);
   g_object_unref (target);
 
-  capabilities = empathy_contact_get_capabilities (self->priv->selected_contact);
-
-  profile = chat = TRUE;
-  call = capabilities & EMPATHY_CAPABILITIES_AUDIO;
-  video = capabilities & EMPATHY_CAPABILITIES_VIDEO;
-
   goto out;
 
  events:
@@ -2118,29 +2178,16 @@ log_window_update_buttons_sensitivity (EmpathyLogWindow *self)
 
   if (self->priv->events_contact != NULL)
     self->priv->selected_contact = g_object_ref (self->priv->events_contact);
-  else
-    goto out;
-
-  capabilities = empathy_contact_get_capabilities (self->priv->selected_contact);
-
-  profile = chat = TRUE;
-  call = capabilities & EMPATHY_CAPABILITIES_AUDIO;
-  video = capabilities & EMPATHY_CAPABILITIES_VIDEO;
-
-  if (video)
-    self->priv->button_video_binding = g_object_bind_property (
-        self->priv->camera_monitor, "available",
-        self->priv->button_video, "sensitive",
-        G_BINDING_SYNC_CREATE);
 
  out:
-  gtk_widget_set_sensitive (self->priv->button_profile, profile);
-  gtk_widget_set_sensitive (self->priv->button_chat, chat);
-  gtk_widget_set_sensitive (self->priv->button_call, call);
+  if (self->priv->selected_contact != NULL)
+    {
+      tp_g_signal_connect_object (self->priv->selected_contact,
+          "notify::capabilities", G_CALLBACK (contact_capabilities_changed_cb),
+          self, 0);
+    }
 
-  /* Don't override the binding */
-  if (!video)
-    gtk_widget_set_sensitive (self->priv->button_video, video);
+  do_update_buttons_sensitivity (self);
 }
 
 static void
@@ -2777,6 +2824,7 @@ sort_by_date (GtkTreeModel *model,
     gpointer user_data)
 {
   GDate *date1, *date2;
+  gint result;
 
   gtk_tree_model_get (model, a,
       COL_WHEN_DATE, &date1,
@@ -2786,7 +2834,11 @@ sort_by_date (GtkTreeModel *model,
       COL_WHEN_DATE, &date2,
       -1);
 
-  return g_date_compare (date1, date2);
+  result =  g_date_compare (date1, date2);
+
+  g_date_free (date1);
+  g_date_free (date2);
+  return result;
 }
 
 static gboolean
@@ -3329,6 +3381,8 @@ log_window_get_messages_for_dates (EmpathyLogWindow *self,
                           event_mask, subtype, self->priv->count);
                       _tpl_action_chain_append (self->priv->chain, get_events_for_date, ctx);
                     }
+
+                  g_date_free (d);
                 }
             }
         }
@@ -3413,18 +3467,30 @@ log_manager_got_dates_cb (GObject *manager,
 
       if (g_strcmp0 (separator, "separator") != 0)
         {
+          GDate *date;
+
+          date = g_date_new_dmy (1, 1, -1);
+
           gtk_list_store_prepend (store, &iter);
           gtk_list_store_set (store, &iter,
-              COL_WHEN_DATE, g_date_new_dmy (1, 1, -1),
+              COL_WHEN_DATE, date,
               COL_WHEN_TEXT, "separator",
               -1);
 
+          g_date_free (date);
+
+          date = g_date_new_dmy (2, 1, -1);
+
           gtk_list_store_prepend (store, &iter);
           gtk_list_store_set (store, &iter,
-              COL_WHEN_DATE, g_date_new_dmy (2, 1, -1),
+              COL_WHEN_DATE, date,
               COL_WHEN_TEXT, _("Anytime"),
               -1);
+
+          g_date_free (date);
         }
+
+      g_free (separator);
     }
 
   g_list_free_full (dates, g_free);
@@ -3681,22 +3747,10 @@ log_window_logger_clear_account_cb (TpProxy *proxy,
   gtk_tree_store_clear (self->priv->store_events);
   log_window_who_populate (self);
 
-  /* Re-filter the account chooser so the accounts without logs get greyed out */
-  empathy_account_chooser_set_filter (
-      EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser),
-      empathy_account_chooser_filter_has_logs, NULL);
-}
-
-static void
-log_window_clear_logs_chooser_select_account (EmpathyAccountChooser *chooser,
-    EmpathyLogWindow *self)
-{
-  EmpathyAccountChooser *account_chooser;
-
-  account_chooser = EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser);
-
-  empathy_account_chooser_set_account (chooser,
-      empathy_account_chooser_get_account (account_chooser));
+  /* Re-filter the account chooser so the accounts without logs get
+   * greyed out */
+  empathy_account_chooser_refilter (
+      EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
 }
 
 static void
@@ -3712,15 +3766,13 @@ log_window_delete_menu_clicked_cb (GtkMenuItem *menuitem,
 
   account_chooser = (EmpathyAccountChooser *) empathy_account_chooser_new ();
   empathy_account_chooser_set_has_all_option (account_chooser, TRUE);
-  empathy_account_chooser_set_filter (account_chooser,
-      empathy_account_chooser_filter_has_logs, NULL);
+
+  empathy_account_chooser_refilter (account_chooser);
 
   /* Select the same account as in the history window */
-  if (empathy_account_chooser_is_ready (account_chooser))
-    log_window_clear_logs_chooser_select_account (account_chooser, self);
-  else
-    g_signal_connect (account_chooser, "ready",
-        G_CALLBACK (log_window_clear_logs_chooser_select_account), self);
+  empathy_account_chooser_set_account (account_chooser,
+      empathy_account_chooser_get_account (
+        EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser)));
 
   dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (self),
       GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING,
@@ -3735,7 +3787,7 @@ log_window_delete_menu_clicked_cb (GtkMenuItem *menuitem,
   content_area = gtk_message_dialog_get_message_area (
       GTK_MESSAGE_DIALOG (dialog));
 
-  hbox = gtk_hbox_new (FALSE, 6);
+  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   label = gtk_label_new (_("Delete from:"));
   gtk_box_pack_start (GTK_BOX (hbox), label,
       FALSE, FALSE, 0);