]> git.0d.be Git - empathy.git/blobdiff - src/empathy-roster-window.c
Merge branch 'gnome-3-8'
[empathy.git] / src / empathy-roster-window.c
index f0b30cf779e45a05736562a6c30b9d81b4ec575e..93001d8d428b18d1137ee0382e89bbe9418e3aa0 100644 (file)
  *          Danielle Madeley <danielle.madeley@collabora.co.uk>
  */
 
-#include <config.h>
+#include "config.h"
+#include "empathy-roster-window.h"
 
 #include <sys/stat.h>
-#include <gtk/gtk.h>
-#include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
 
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/util.h>
-#include <folks/folks.h>
-
-#include <libempathy/empathy-contact.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-request-util.h>
-#include <libempathy/empathy-chatroom-manager.h>
-#include <libempathy/empathy-chatroom.h>
-#include <libempathy/empathy-gsettings.h>
-#include <libempathy/empathy-individual-manager.h>
-#include <libempathy/empathy-gsettings.h>
-#include <libempathy/empathy-status-presets.h>
-#include <libempathy/empathy-presence-manager.h>
-
-#include <libempathy-gtk/empathy-live-search.h>
-#include <libempathy-gtk/empathy-contact-blocking-dialog.h>
-#include <libempathy-gtk/empathy-contact-search-dialog.h>
-#include <libempathy-gtk/empathy-geometry.h>
-#include <libempathy-gtk/empathy-gtk-enum-types.h>
-#include <libempathy-gtk/empathy-individual-dialogs.h>
-#include <libempathy-gtk/empathy-individual-store-manager.h>
-#include <libempathy-gtk/empathy-roster-model.h>
-#include <libempathy-gtk/empathy-roster-model-manager.h>
-#include <libempathy-gtk/empathy-roster-view.h>
-#include <libempathy-gtk/empathy-new-message-dialog.h>
-#include <libempathy-gtk/empathy-new-call-dialog.h>
-#include <libempathy-gtk/empathy-log-window.h>
-#include <libempathy-gtk/empathy-presence-chooser.h>
-#include <libempathy-gtk/empathy-sound-manager.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
-
+#include "empathy-about-dialog.h"
 #include "empathy-accounts-dialog.h"
 #include "empathy-call-observer.h"
 #include "empathy-chat-manager.h"
-#include "empathy-roster-window.h"
-#include "empathy-preferences.h"
-#include "empathy-about-dialog.h"
-#include "empathy-debug-window.h"
-#include "empathy-new-chatroom-dialog.h"
+#include "empathy-chatroom-manager.h"
 #include "empathy-chatrooms-window.h"
+#include "empathy-contact-blocking-dialog.h"
+#include "empathy-contact-search-dialog.h"
 #include "empathy-event-manager.h"
 #include "empathy-ft-manager.h"
+#include "empathy-geometry.h"
+#include "empathy-gsettings.h"
+#include "empathy-gsettings.h"
+#include "empathy-gtk-enum-types.h"
+#include "empathy-individual-dialogs.h"
+#include "empathy-log-window.h"
+#include "empathy-new-call-dialog.h"
+#include "empathy-new-chatroom-dialog.h"
+#include "empathy-new-message-dialog.h"
+#include "empathy-preferences.h"
+#include "empathy-presence-chooser.h"
+#include "empathy-presence-manager.h"
+#include "empathy-request-util.h"
+#include "empathy-roster-model-manager.h"
+#include "empathy-roster-view.h"
+#include "empathy-status-presets.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 /* Flashing delay for icons (milliseconds). */
 #define FLASH_TIMEOUT 500
@@ -126,6 +110,8 @@ struct _EmpathyRosterWindowPriv {
   GtkWidget *no_entry_label;
   GtkWidget *button_account_settings;
   GtkWidget *button_online;
+  GtkWidget *button_show_offline;
+  GtkWidget *button_add_contact;
   GtkWidget *spinner_loading;
   GtkWidget *tooltip_widget;
 
@@ -366,10 +352,9 @@ individual_activated_cb (EmpathyRosterView *self,
 static void
 event_activated_cb (EmpathyRosterView *self,
     FolksIndividual *individual,
+    EmpathyEvent *event,
     gpointer user_data)
 {
-  EmpathyEvent *event = user_data;
-
   empathy_event_activate (event);
 }
 
@@ -395,14 +380,56 @@ button_online_clicked_cb (GtkButton *button,
   g_object_unref (mgr);
 }
 
+static void
+button_show_offline_clicked_cb (GtkButton *button,
+    EmpathyRosterWindow *self)
+{
+  g_settings_set_boolean (self->priv->gsettings_ui,
+      EMPATHY_PREFS_UI_SHOW_OFFLINE, TRUE);
+}
+
+static void
+button_add_contact_clicked_cb (GtkButton *button,
+    EmpathyRosterWindow *self)
+{
+  empathy_new_individual_dialog_show (GTK_WINDOW (self));
+}
+
 typedef enum
 {
   PAGE_MESSAGE_FLAG_NONE = 0,
   PAGE_MESSAGE_FLAG_ACCOUNTS = 1 << 0,
   PAGE_MESSAGE_FLAG_SPINNER = 1 << 2,
   PAGE_MESSAGE_FLAG_ONLINE = 1 << 3,
+  PAGE_MESSAGE_FLAG_SHOW_OFFLINE = 1 << 4,
+  PAGE_MESSAGE_FLAG_ADD_CONTACT = 1 << 5,
 } PageMessageFlags;
 
+static gboolean
+can_add_contact (EmpathyRosterWindow *self)
+{
+  GList *accounts, *l;
+  gboolean result = FALSE;
+
+  accounts = tp_account_manager_dup_valid_accounts (
+      self->priv->account_manager);
+  for (l = accounts; l != NULL && !result; l = g_list_next (l))
+    {
+      TpAccount *account = TP_ACCOUNT (l->data);
+      TpConnection *conn;
+
+      conn = tp_account_get_connection (account);
+      if (conn == NULL)
+        continue;
+
+      if (tp_connection_get_can_change_contact_list (conn))
+        result = TRUE;
+    }
+
+  g_list_free_full (accounts, g_object_unref);
+  return result;
+}
+
 static void
 display_page_message (EmpathyRosterWindow *self,
     const gchar *msg,
@@ -431,6 +458,14 @@ display_page_message (EmpathyRosterWindow *self,
       (flags & PAGE_MESSAGE_FLAG_SPINNER) != 0);
   gtk_widget_set_visible (self->priv->button_online,
       (flags & PAGE_MESSAGE_FLAG_ONLINE) != 0);
+  gtk_widget_set_visible (self->priv->button_show_offline,
+      (flags & PAGE_MESSAGE_FLAG_SHOW_OFFLINE) != 0);
+  gtk_widget_set_visible (self->priv->button_add_contact,
+      (flags & PAGE_MESSAGE_FLAG_ADD_CONTACT) != 0);
+
+  if ((flags & PAGE_MESSAGE_FLAG_ADD_CONTACT) != 0)
+    gtk_widget_set_sensitive (self->priv->button_add_contact,
+        can_add_contact (self));
 
   gtk_notebook_set_current_page (GTK_NOTEBOOK (self->priv->notebook),
       PAGE_MESSAGE);
@@ -440,7 +475,7 @@ static void
 display_page_no_account (EmpathyRosterWindow *self)
 {
   display_page_message (self,
-      _("You need to setup an account to see contacts here."),
+      _("You need to set up an account to see contacts here."),
       PAGE_MESSAGE_FLAG_ACCOUNTS);
 }
 
@@ -561,6 +596,7 @@ roster_window_error_create_info_bar (EmpathyRosterWindow *self,
   label = gtk_label_new (message_markup);
   gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
   gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+  gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
   gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
   gtk_widget_show (label);
 
@@ -606,6 +642,54 @@ roster_window_error_add_stock_button (GtkInfoBar *info_bar,
   gtk_info_bar_add_action_widget (info_bar, button, response_id);
 }
 
+#ifdef HAVE_UOA
+static const gchar *
+uoa_account_display_string (TpAccount *account)
+{
+  const gchar *service;
+
+  service = tp_account_get_service (account);
+
+  /* Use well known service name, if available */
+  if (!tp_strdiff (service, "windows-live"))
+    return _("Windows Live");
+  else if (!tp_strdiff (service, "google-talk"))
+    return _("Google Talk");
+  else if (!tp_strdiff (service, "facebook"))
+    return _("Facebook");
+
+  return tp_account_get_display_name (account);
+}
+
+static void
+roster_window_uoa_auth_error (EmpathyRosterWindow *self,
+    TpAccount *account)
+{
+  GtkWidget *info_bar;
+  GtkWidget *image;
+  GtkWidget *button;
+  gchar *str;
+
+  /* translators: %s is an account name like 'Facebook' or 'Google Talk' */
+  str = g_strdup_printf (_("%s account requires authorisation"),
+      uoa_account_display_string (account));
+
+  info_bar = roster_window_error_create_info_bar (self, account,
+      GTK_MESSAGE_OTHER, str);
+  g_free (str);
+
+  image = gtk_image_new_from_icon_name ("credentials-preferences",
+      GTK_ICON_SIZE_BUTTON);
+  button = gtk_button_new ();
+  gtk_button_set_image (GTK_BUTTON (button), image);
+  gtk_widget_set_tooltip_text (button, _("Online Accounts"));
+  gtk_widget_show (button);
+
+  gtk_info_bar_add_action_widget (GTK_INFO_BAR (info_bar), button,
+      ERROR_RESPONSE_EDIT);
+}
+#endif
+
 static void
 roster_window_error_display (EmpathyRosterWindow *self,
     TpAccount *account)
@@ -621,6 +705,17 @@ roster_window_error_display (EmpathyRosterWindow *self,
   if (user_requested)
     return;
 
+#ifdef HAVE_UOA
+  if (!tp_strdiff (TP_ERROR_STR_AUTHENTICATION_FAILED,
+       tp_account_get_detailed_error (account, NULL)) &&
+      !tp_strdiff (tp_account_get_storage_provider (account),
+       EMPATHY_UOA_PROVIDER))
+    {
+      roster_window_uoa_auth_error (self, account);
+      return;
+    }
+#endif
+
   str = g_markup_printf_escaped ("<b>%s</b>\n%s",
       tp_account_get_display_name (account), error_message);
 
@@ -658,6 +753,7 @@ roster_window_update_status (EmpathyRosterWindow *self)
 {
   gboolean connected, connecting;
   GList *l;
+  GAction *action;
 
   connected = empathy_account_manager_get_accounts_connected (&connecting);
 
@@ -676,6 +772,10 @@ roster_window_update_status (EmpathyRosterWindow *self)
   /* Update widgets sensibility */
   for (l = self->priv->actions_connected; l; l = l->next)
     g_simple_action_set_enabled (l->data, connected);
+
+  action = g_action_map_lookup_action (G_ACTION_MAP (self), "chat_add_contact");
+  if (!can_add_contact (self))
+    g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
 }
 
 static void
@@ -933,16 +1033,30 @@ empathy_roster_window_finalize (GObject *window)
 static gboolean
 roster_window_key_press_event_cb  (GtkWidget *window,
     GdkEventKey *event,
-    gpointer user_data)
+    EmpathyRosterWindow *self)
 {
   if (event->keyval == GDK_KEY_T
       && event->state & GDK_SHIFT_MASK
       && event->state & GDK_CONTROL_MASK)
     empathy_chat_manager_call_undo_closed_chat ();
 
+  if (event->keyval == GDK_KEY_f
+      && event->state & GDK_CONTROL_MASK)
+    gtk_widget_show (self->priv->search_bar);
+
   return FALSE;
 }
 
+static void
+unprepare_cb (GObject *source,
+    GAsyncResult *result,
+    gpointer user_data)
+{
+  GtkWidget *self = user_data;
+
+  gtk_widget_destroy (self);
+}
+
 static void
 roster_window_chat_quit_cb (GSimpleAction *action,
     GVariant *parameter,
@@ -950,7 +1064,14 @@ roster_window_chat_quit_cb (GSimpleAction *action,
 {
   EmpathyRosterWindow *self = user_data;
 
-  gtk_widget_destroy (GTK_WIDGET (self));
+  /* Destroying the window will make us leave the main loop and so exit the
+   * process. Before doing so we want to unprepare the individual manager.
+   * Just hide the window now and actually destroy it once Folks is done.
+   */
+  gtk_widget_hide (GTK_WIDGET (self));
+
+  empathy_individual_manager_unprepare_async (self->priv->individual_manager,
+      unprepare_cb, self);
 }
 
 static void
@@ -1507,7 +1628,7 @@ set_notebook_page (EmpathyRosterWindow *self)
 
   gtk_spinner_stop (GTK_SPINNER (self->priv->spinner_loading));
 
-  accounts = tp_account_manager_get_valid_accounts (
+  accounts = tp_account_manager_dup_valid_accounts (
       self->priv->account_manager);
 
   len = g_list_length (accounts);
@@ -1551,8 +1672,13 @@ set_notebook_page (EmpathyRosterWindow *self)
         }
       else
         {
-          display_page_message (self, _("No online contacts"),
-              PAGE_MESSAGE_FLAG_NONE);
+          if (g_settings_get_boolean (self->priv->gsettings_ui,
+                EMPATHY_PREFS_UI_SHOW_OFFLINE))
+            display_page_message (self, _("You haven't added any contact yet"),
+                PAGE_MESSAGE_FLAG_ADD_CONTACT);
+          else
+            display_page_message (self, _("No online contacts"),
+                PAGE_MESSAGE_FLAG_SHOW_OFFLINE);
         }
       goto out;
     }
@@ -1560,7 +1686,7 @@ set_notebook_page (EmpathyRosterWindow *self)
   display_page_contact_list (self);
 
 out:
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
 }
 
 static void
@@ -1636,7 +1762,8 @@ account_manager_prepared_cb (GObject *source_object,
       return;
     }
 
-  accounts = tp_account_manager_get_valid_accounts (self->priv->account_manager);
+  accounts = tp_account_manager_dup_valid_accounts (
+      self->priv->account_manager);
   for (j = accounts; j != NULL; j = j->next)
     {
       TpAccount *account = TP_ACCOUNT (j->data);
@@ -1655,7 +1782,7 @@ account_manager_prepared_cb (GObject *source_object,
 
   set_notebook_page (self);
 
-  g_list_free (accounts);
+  g_list_free_full (accounts, g_object_unref);
 }
 
 void
@@ -2069,6 +2196,14 @@ roster_window_most_available_presence_changed_cb (TpAccountManager *manager,
   set_notebook_page (self);
 }
 
+static void
+show_offline_changed_cb (GSettings *settings,
+    const gchar *key,
+    EmpathyRosterWindow *self)
+{
+  set_notebook_page (self);
+}
+
 static void
 empathy_roster_window_init (EmpathyRosterWindow *self)
 {
@@ -2110,6 +2245,8 @@ empathy_roster_window_init (EmpathyRosterWindow *self)
       "roster_scrolledwindow", &sw,
       "button_account_settings", &self->priv->button_account_settings,
       "button_online", &self->priv->button_online,
+      "button_show_offline", &self->priv->button_show_offline,
+      "button_add_contact", &self->priv->button_add_contact,
       "spinner_loading", &self->priv->spinner_loading,
       NULL);
   g_free (filename);
@@ -2118,7 +2255,7 @@ empathy_roster_window_init (EmpathyRosterWindow *self)
   gtk_widget_show (self->priv->main_vbox);
 
   g_signal_connect (self, "key-press-event",
-      G_CALLBACK (roster_window_key_press_event_cb), NULL);
+      G_CALLBACK (roster_window_key_press_event_cb), self);
 
   g_object_unref (gui);
 
@@ -2261,6 +2398,9 @@ empathy_roster_window_init (EmpathyRosterWindow *self)
   g_settings_bind (self->priv->gsettings_ui, EMPATHY_PREFS_UI_SHOW_OFFLINE,
       self->priv->view, "show-offline",
       G_SETTINGS_BIND_GET);
+  tp_g_signal_connect_object (self->priv->gsettings_ui,
+      "changed::" EMPATHY_PREFS_UI_SHOW_OFFLINE,
+      G_CALLBACK (show_offline_changed_cb), self, 0);
   g_settings_bind (self->priv->gsettings_ui, EMPATHY_PREFS_UI_SHOW_GROUPS,
       self->priv->view, "show-groups",
       G_SETTINGS_BIND_GET);
@@ -2272,8 +2412,10 @@ empathy_roster_window_init (EmpathyRosterWindow *self)
       G_CALLBACK (button_account_settings_clicked_cb), self);
   g_signal_connect (self->priv->button_online, "clicked",
       G_CALLBACK (button_online_clicked_cb), self);
-
-  set_notebook_page (self);
+  g_signal_connect (self->priv->button_show_offline, "clicked",
+      G_CALLBACK (button_show_offline_clicked_cb), self);
+  g_signal_connect (self->priv->button_add_contact, "clicked",
+      G_CALLBACK (button_add_contact_clicked_cb), self);
 }
 
 GtkWidget *