]> git.0d.be Git - empathy.git/blobdiff - src/empathy-accounts-dialog.c
Port EmpathyAccountsDialog to new API
[empathy.git] / src / empathy-accounts-dialog.c
index c1e59da57236543c57c74f7f7cd48feb033e3b83..036c7f86b16e495d5a7fabdf5dd89619d2e4dcbc 100644 (file)
@@ -28,7 +28,6 @@
 #include <stdlib.h>
 
 #include <gtk/gtk.h>
-#include <glade/glade.h>
 #include <glib/gi18n.h>
 #include <dbus/dbus-glib.h>
 
@@ -128,7 +127,6 @@ static gboolean   accounts_dialog_row_changed_foreach       (GtkTreeModel
                                                             GtkTreeIter              *iter,
                                                             gpointer                  user_data);
 static gboolean   accounts_dialog_flash_connecting_cb       (EmpathyAccountsDialog    *dialog);
-static gboolean   accounts_dialog_are_accounts_connecting   (MissionControl           *mc);
 static void       accounts_dialog_connection_changed_cb     (EmpathyAccountManager    *manager,
                                                             McAccount                *account,
                                                             TpConnectionStatusReason  reason,
@@ -261,6 +259,7 @@ accounts_dialog_update_account (EmpathyAccountsDialog *dialog,
 
        gtk_container_add (GTK_CONTAINER (dialog->alignment_settings),
                           dialog->settings_widget);
+       gtk_widget_show (dialog->settings_widget);
 
 
        gtk_image_set_from_icon_name (GTK_IMAGE (dialog->image_type),
@@ -315,7 +314,7 @@ accounts_dialog_name_edited_cb (GtkCellRendererText   *renderer,
        GtkTreePath  *treepath;
        GtkTreeIter   iter;
 
-       if (accounts_dialog_are_accounts_connecting (dialog->mc)) {
+       if (empathy_account_manager_get_connecting_accounts (dialog->account_manager) > 0) {
                dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
                                                       (GSourceFunc) accounts_dialog_flash_connecting_cb,
                                                       dialog);
@@ -659,7 +658,7 @@ accounts_dialog_account_added_cb (EmpathyAccountManager *manager,
         *    parameter for CM that have it. */
        current_name = mc_account_get_display_name (account);
        mc_account_get_param_string (account, "account", &account_param);
-       if (!G_STR_EMPTY (account_param)) {
+       if (!EMP_STR_EMPTY (account_param)) {
                McProfile   *profile;
                const gchar *profile_name;
                gchar       *new_name;
@@ -718,30 +717,6 @@ accounts_dialog_flash_connecting_cb (EmpathyAccountsDialog *dialog)
        return TRUE;
 }
 
-static gboolean
-accounts_dialog_are_accounts_connecting (MissionControl *mc)
-{
-       GList    *accounts, *l;
-       gboolean  found = FALSE;
-
-       /* Check if there is still accounts in CONNECTING state */
-       accounts = mc_accounts_list_by_enabled (TRUE);
-       for (l = accounts; l; l = l->next) {
-               McAccount          *this_account = l->data;
-               TpConnectionStatus  status;
-
-               status = mission_control_get_connection_status (mc, this_account,
-                                                               NULL);
-               if (status == TP_CONNECTION_STATUS_CONNECTING) {
-                       found = TRUE;
-                       break;
-               }
-       }
-       mc_accounts_list_free (accounts);
-
-       return found;
-}
-
 static void
 accounts_dialog_connection_changed_cb     (EmpathyAccountManager    *manager,
                                           McAccount                *account,
@@ -769,12 +744,13 @@ accounts_dialog_connection_changed_cb     (EmpathyAccountManager    *manager,
                gtk_tree_path_free (path);
        }
 
-       found = accounts_dialog_are_accounts_connecting (dialog->mc);           
+       found = (empathy_account_manager_get_connecting_accounts (manager) > 0);
 
        if (!found && dialog->connecting_id) {
                g_source_remove (dialog->connecting_id);
                dialog->connecting_id = 0;
        }
+
        if (found && !dialog->connecting_id) {
                dialog->connecting_id = g_timeout_add (FLASH_TIMEOUT,
                                                       (GSourceFunc) accounts_dialog_flash_connecting_cb,
@@ -847,6 +823,12 @@ accounts_dialog_button_create_clicked_cb (GtkWidget             *button,
 
        /* Create account */
        account = mc_account_create (profile);
+       if (account == NULL) {
+               /* We can't display an error to the user as MC doesn't give us
+                * any clue about the reason of the failure... */
+               return;
+       }
+
        /* To translator: %s is the protocol name */
        str = g_strdup_printf (_("New %s account"),
                               mc_profile_get_display_name (profile));
@@ -1061,7 +1043,7 @@ empathy_accounts_dialog_show (GtkWindow *parent,
                              McAccount *selected_account)
 {
        static EmpathyAccountsDialog *dialog = NULL;
-       GladeXML                     *glade;
+       GtkBuilder                   *gui;
        gchar                        *filename;
        GList                        *accounts, *l;
        gboolean                      import_asked;
@@ -1073,11 +1055,9 @@ empathy_accounts_dialog_show (GtkWindow *parent,
 
        dialog = g_new0 (EmpathyAccountsDialog, 1);
 
-       filename = empathy_file_lookup ("empathy-accounts-dialog.glade",
+       filename = empathy_file_lookup ("empathy-accounts-dialog.ui",
                                        "src");
-       glade = empathy_glade_get_file (filename,
-                                      "accounts_dialog",
-                                      NULL,
+       gui = empathy_builder_get_file (filename,
                                       "accounts_dialog", &dialog->window,
                                       "vbox_details", &dialog->vbox_details,
                                       "frame_no_profile", &dialog->frame_no_profile,
@@ -1096,8 +1076,7 @@ empathy_accounts_dialog_show (GtkWindow *parent,
                                       NULL);
        g_free (filename);
 
-       empathy_glade_connect (glade,
-                             dialog,
+       empathy_builder_connect (gui, dialog,
                              "accounts_dialog", "destroy", accounts_dialog_destroy_cb,
                              "accounts_dialog", "response", accounts_dialog_response_cb,
                              "button_create", "clicked", accounts_dialog_button_create_clicked_cb,
@@ -1110,7 +1089,7 @@ empathy_accounts_dialog_show (GtkWindow *parent,
 
        g_object_add_weak_pointer (G_OBJECT (dialog->window), (gpointer) &dialog);
 
-       g_object_unref (glade);
+       g_object_unref (gui);
 
        /* Create profile chooser */
        dialog->combobox_profile = empathy_profile_chooser_new ();
@@ -1123,8 +1102,8 @@ empathy_accounts_dialog_show (GtkWindow *parent,
                          dialog);
 
        /* Set up signalling */
-       dialog->account_manager = empathy_account_manager_new ();
-       dialog->mc = empathy_mission_control_new ();
+       dialog->account_manager = empathy_account_manager_dup_singleton ();
+       dialog->mc = empathy_mission_control_dup_singleton ();
 
        g_signal_connect (dialog->account_manager, "account-created",
                          G_CALLBACK (accounts_dialog_account_added_cb),
@@ -1171,11 +1150,17 @@ empathy_accounts_dialog_show (GtkWindow *parent,
        empathy_conf_get_bool (empathy_conf_get (),
                               EMPATHY_PREFS_IMPORT_ASKED, &import_asked);
 
-       if (!import_asked) {
-               empathy_conf_set_bool (empathy_conf_get (),
-                                      EMPATHY_PREFS_IMPORT_ASKED, TRUE);
-               empathy_import_dialog_show (GTK_WINDOW (dialog->window),
-                                           FALSE);
+
+       if (empathy_import_dialog_accounts_to_import ()) {
+
+               if (!import_asked) {
+                       empathy_conf_set_bool (empathy_conf_get (),
+                                              EMPATHY_PREFS_IMPORT_ASKED, TRUE);
+                       empathy_import_dialog_show (GTK_WINDOW (dialog->window),
+                                                   FALSE);
+               }
+       } else {
+               gtk_widget_set_sensitive (dialog->button_import, FALSE);
        }
 
        return dialog->window;