display a message if accounts need to be enabled
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 2 Feb 2012 16:00:08 +0000 (17:00 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Fri, 3 Feb 2012 11:57:51 +0000 (12:57 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=656097

src/empathy-roster-window.c

index 709df601dbad3826d83be035f0d1538db055acf4..12299015c53285cf2a802037d4577b5eba3a45b6 100644 (file)
@@ -2120,19 +2120,78 @@ add_account (EmpathyRosterWindow *self,
   roster_window_setup_balance (self, account);
 }
 
+/* @account: if not %NULL, the only account which can be enabled */
+static void
+display_page_account_not_enabled (EmpathyRosterWindow *self,
+    TpAccount *account)
+{
+  if (account == NULL)
+    {
+      display_page_message (self,
+          _("You need to enable one of your accounts to see contacts here."),
+          TRUE);
+    }
+  else
+    {
+      gchar *tmp;
+
+      /* translators: argument is an account name */
+      tmp = g_strdup_printf (_("You need to enable %s to see contacts here."),
+          tp_account_get_display_name (account));
+
+      display_page_message (self, tmp, TRUE);
+      g_free (tmp);
+    }
+}
+static gboolean
+has_enabled_account (GList *accounts)
+{
+  GList *l;
+
+  for (l = accounts; l != NULL; l = g_list_next (l))
+    {
+      TpAccount *account = l->data;
+
+      if (tp_account_is_enabled (account))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 static void
 set_notebook_page (EmpathyRosterWindow *self)
 {
   GList *accounts;
+  guint len;
 
   accounts = tp_account_manager_get_valid_accounts (
       self->priv->account_manager);
 
-  if (g_list_length (accounts) == 0)
-    display_page_no_account (self);
-  else
-    display_page_contact_list (self);
+  len = g_list_length (accounts);
 
+  if (len == 0)
+    {
+      /* No account */
+      display_page_no_account (self);
+      goto out;
+    }
+
+  if (!has_enabled_account (accounts))
+    {
+      TpAccount *account = NULL;
+
+      /* Pass the account if there is only one which can be enabled */
+      if (len == 1)
+        account = accounts->data;
+
+      display_page_account_not_enabled (self, account);
+      goto out;
+    }
+
+  display_page_contact_list (self);
+
+out:
   g_list_free (accounts);
 }
 
@@ -2186,6 +2245,22 @@ roster_window_connection_items_setup (EmpathyRosterWindow *self,
   self->priv->actions_connected = list;
 }
 
+static void
+account_enabled_cb (TpAccountManager *manager,
+    TpAccount *account,
+    EmpathyRosterWindow *self)
+{
+  set_notebook_page (self);
+}
+
+static void
+account_disabled_cb (TpAccountManager *manager,
+    TpAccount *account,
+    EmpathyRosterWindow *self)
+{
+  set_notebook_page (self);
+}
+
 static void
 account_manager_prepared_cb (GObject *source_object,
     GAsyncResult *result,
@@ -2213,6 +2288,10 @@ account_manager_prepared_cb (GObject *source_object,
 
   g_signal_connect (manager, "account-validity-changed",
       G_CALLBACK (roster_window_account_validity_changed_cb), self);
+  tp_g_signal_connect_object (manager, "account-disabled",
+      G_CALLBACK (account_disabled_cb), self, 0);
+  tp_g_signal_connect_object (manager, "account-enabled",
+      G_CALLBACK (account_enabled_cb), self, 0);
 
   roster_window_update_status (self);