]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-log-window.c
Move should_create_salut_account to local-xmpp-assistant-widget
[empathy.git] / libempathy-gtk / empathy-log-window.c
index ab15b16162911f6106b303210557e020abe55536..51a47c7a39b527246d2e777857db931796b3e69c 100644 (file)
@@ -62,6 +62,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 +299,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 +317,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 +604,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 +658,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,7 +688,7 @@ 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_icon_name (GTK_ENTRY (self->priv->search_entry),
@@ -759,9 +747,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 +774,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 *
@@ -1634,9 +1625,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 +1810,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);
     }
@@ -2070,31 +2072,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;
 
@@ -2122,12 +2171,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:
@@ -2137,29 +2180,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
@@ -2796,6 +2826,7 @@ sort_by_date (GtkTreeModel *model,
     gpointer user_data)
 {
   GDate *date1, *date2;
+  gint result;
 
   gtk_tree_model_get (model, a,
       COL_WHEN_DATE, &date1,
@@ -2805,7 +2836,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
@@ -3348,6 +3383,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);
                 }
             }
         }
@@ -3432,18 +3469,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);
@@ -3706,18 +3755,6 @@ log_window_logger_clear_account_cb (TpProxy *proxy,
       EMPATHY_ACCOUNT_CHOOSER (self->priv->account_chooser));
 }
 
-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));
-}
-
 static void
 log_window_delete_menu_clicked_cb (GtkMenuItem *menuitem,
     EmpathyLogWindow *self)
@@ -3735,11 +3772,9 @@ log_window_delete_menu_clicked_cb (GtkMenuItem *menuitem,
   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,
@@ -3754,7 +3789,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);