]> git.0d.be Git - empathy.git/blobdiff - src/empathy-accounts-dialog.c
Merge branch 'sasl'
[empathy.git] / src / empathy-accounts-dialog.c
index c753a9f20a3c266eca03a49fee81c28edf542295..8eda73bb41ac3615955cdb16b83047e4cd8baa23 100644 (file)
@@ -39,7 +39,6 @@
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-connection-managers.h>
 #include <libempathy/empathy-connectivity.h>
-#include <libempathy/empathy-gsettings.h>
 
 #include <libempathy-gtk/empathy-ui-utils.h>
 #include <libempathy-gtk/empathy-protocol-chooser.h>
 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountsDialog)
 G_DEFINE_TYPE (EmpathyAccountsDialog, empathy_accounts_dialog, GTK_TYPE_DIALOG);
 
+enum
+{
+  NOTEBOOK_PAGE_ACCOUNT = 0,
+  NOTEBOOK_PAGE_LOADING
+};
+
 typedef struct {
   GtkWidget *alignment_settings;
   GtkWidget *alignment_infobar;
@@ -96,6 +101,10 @@ typedef struct {
   GtkWidget *label_type;
   GtkWidget *settings_widget;
 
+  GtkWidget *notebook_account;
+  GtkWidget *spinner;
+  gboolean loading;
+
   /* We have to keep a reference on the actual EmpathyAccountWidget, not just
    * his GtkWidget. It is the only reliable source we can query to know if
    * there are any unsaved changes to the currently selected account. We can't
@@ -574,55 +583,11 @@ accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
 {
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
   EmpathyAccountSettings *settings;
-  gchar *str;
-  const gchar *name, *display_name;
-  TpConnectionManager *cm;
-  TpConnectionManagerProtocol *proto;
-  gboolean is_gtalk, is_facebook;
-
-  cm = empathy_protocol_chooser_dup_selected (
-      EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol), &proto, &is_gtalk,
-      &is_facebook);
-  if (cm == NULL)
-    return;
-
-  if (is_gtalk)
-    name = "gtalk";
-  else if (is_facebook)
-    name ="facebook";
-  else
-    name = proto->name;
 
-  display_name = empathy_protocol_name_to_display_name (name);
-  if (display_name == NULL)
-    display_name = proto->name;
-
-  /* Create account */
-  /* To translator: %s is the name of the protocol, such as "Google Talk" or
-   * "Yahoo!"
-   */
-  str = g_strdup_printf (_("New %s account"), display_name);
-  settings = empathy_account_settings_new (cm->name, proto->name, str);
-
-  g_free (str);
-
-  if (is_gtalk)
-    {
-      empathy_account_settings_set_icon_name_async (settings, "im-google-talk",
-          NULL, NULL);
-      /* We should not have to set the server but that may cause issue with
-       * buggy router. */
-      empathy_account_settings_set_string (settings, "server",
-          "talk.google.com");
-    }
-  else if (is_facebook)
-    {
-      empathy_account_settings_set_icon_name_async (settings, "im-facebook",
-          NULL, NULL);
-
-      empathy_account_settings_set_string (settings, "server",
-          "chat.facebook.com");
-    }
+  settings = empathy_protocol_chooser_create_account_settings (
+      EMPATHY_PROTOCOL_CHOOSER (priv->combobox_protocol));
+  if (settings == NULL)
+    return;
 
   accounts_dialog_add (dialog, settings);
   accounts_dialog_model_set_selected (dialog, settings);
@@ -630,7 +595,6 @@ accounts_dialog_setup_ui_to_add_account (EmpathyAccountsDialog *dialog)
   gtk_widget_show_all (priv->hbox_protocol);
 
   g_object_unref (settings);
-  g_object_unref (cm);
 }
 
 static void
@@ -1304,7 +1268,8 @@ accounts_dialog_model_selection_changed (GtkTreeSelection *selection,
     }
 
   /* Update remove button sensitivity */
-  gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating);
+  gtk_widget_set_sensitive (priv->button_remove, is_selection && !creating &&
+      !priv->loading);
 }
 
 static void
@@ -1859,6 +1824,29 @@ accounts_dialog_set_selected_account (EmpathyAccountsDialog *dialog,
     gtk_tree_selection_select_iter (selection, &iter);
 }
 
+static void
+finished_loading (EmpathyAccountsDialog *self)
+{
+  EmpathyAccountsDialogPriv *priv = GET_PRIV (self);
+  GtkTreeSelection *selection;
+  gboolean has_selected;
+
+  priv->loading = FALSE;
+
+  gtk_widget_set_sensitive (priv->button_add, TRUE);
+  gtk_widget_set_sensitive (priv->button_import, TRUE);
+  gtk_widget_set_sensitive (priv->treeview, TRUE);
+
+  /* Sensitive the remove button if there is an account selected */
+  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview));
+  has_selected = gtk_tree_selection_get_selected (selection, NULL, NULL);
+  gtk_widget_set_sensitive (priv->button_remove, has_selected);
+
+  gtk_spinner_stop (GTK_SPINNER (priv->spinner));
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
+      NOTEBOOK_PAGE_ACCOUNT);
+}
+
 static void
 accounts_dialog_cms_prepare_cb (GObject *source,
     GAsyncResult *result,
@@ -1869,7 +1857,7 @@ accounts_dialog_cms_prepare_cb (GObject *source,
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
 
   if (!empathy_connection_managers_prepare_finish (cms, result, NULL))
-    return;
+    goto out;
 
   accounts_dialog_update_settings (dialog, NULL);
 
@@ -1879,6 +1867,9 @@ accounts_dialog_cms_prepare_cb (GObject *source,
       g_object_unref (priv->initial_selection);
       priv->initial_selection = NULL;
     }
+
+out:
+  finished_loading (dialog);
 }
 
 static void
@@ -1985,6 +1976,7 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
   EmpathyAccountsDialogPriv    *priv = GET_PRIV (dialog);
   GtkWidget                    *content_area;
   GtkWidget *action_area, *vbox, *hbox, *align;
+  GtkWidget *alig;
 
   filename = empathy_file_lookup ("empathy-accounts-dialog.ui", "src");
 
@@ -1999,6 +1991,8 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
       "button_remove", &priv->button_remove,
       "button_import", &priv->button_import,
       "hbox_protocol", &priv->hbox_protocol,
+      "notebook_account", &priv->notebook_account,
+      "alignment_loading", &alig,
       NULL);
   g_free (filename);
 
@@ -2012,7 +2006,7 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
 
   content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
 
-  gtk_container_add (GTK_CONTAINER (content_area), top_hbox);
+  gtk_box_pack_start (GTK_BOX (content_area), top_hbox, TRUE, TRUE, 0);
 
   g_object_unref (gui);
 
@@ -2023,9 +2017,28 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
   gtk_widget_hide (priv->button_remove);
 #endif /* HAVE_MEEGO */
 
-  /* Remove button is unsensitive until we have a selected account */
+  /* Display loading page */
+  priv->loading = TRUE;
+
+  priv->spinner = gtk_spinner_new ();
+
+  gtk_spinner_start (GTK_SPINNER (priv->spinner));
+  gtk_widget_show (priv->spinner);
+
+  gtk_container_add (GTK_CONTAINER (alig), priv->spinner);
+
+  gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook_account),
+      NOTEBOOK_PAGE_LOADING);
+
+  /* Remove button is insensitive until we have a selected account */
   gtk_widget_set_sensitive (priv->button_remove, FALSE);
 
+  /* Add and Import buttons and treeview are insensitive while the dialog
+   * is loading */
+  gtk_widget_set_sensitive (priv->button_add, FALSE);
+  gtk_widget_set_sensitive (priv->button_import, FALSE);
+  gtk_widget_set_sensitive (priv->treeview, FALSE);
+
   priv->combobox_protocol = empathy_protocol_chooser_new ();
   gtk_box_pack_start (GTK_BOX (priv->hbox_protocol), priv->combobox_protocol,
       TRUE, TRUE, 0);
@@ -2096,8 +2109,6 @@ accounts_dialog_build_ui (EmpathyAccountsDialog *dialog)
 
   gtk_window_set_type_hint (GTK_WINDOW (dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
 
-  gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
-
   /* add dialog buttons */
   gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_END);
 
@@ -2194,7 +2205,6 @@ do_constructed (GObject *object)
   EmpathyAccountsDialog *dialog = EMPATHY_ACCOUNTS_DIALOG (object);
   EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog);
   GtkTreeModel *model;
-  GSettings *gsettings = g_settings_new (EMPATHY_PREFS_SCHEMA);
 
   accounts_dialog_build_ui (dialog);
   accounts_dialog_model_setup (dialog);
@@ -2211,24 +2221,7 @@ do_constructed (GObject *object)
   tp_account_manager_prepare_async (priv->account_manager, NULL,
       accounts_dialog_manager_ready_cb, dialog);
 
-  if (empathy_import_accounts_to_import ())
-    {
-      gtk_widget_show (priv->button_import);
-
-      if (!g_settings_get_boolean (gsettings, EMPATHY_PREFS_IMPORT_ASKED))
-        {
-          GtkWidget *import_dialog;
-
-          g_settings_set_boolean (gsettings, EMPATHY_PREFS_IMPORT_ASKED, TRUE);
-          import_dialog = empathy_import_dialog_new (GTK_WINDOW (dialog),
-              FALSE);
-          gtk_widget_show (import_dialog);
-        }
-    }
-
   priv->connectivity = empathy_connectivity_dup_singleton ();
-
-  g_object_unref (gsettings);
 }
 
 static void