]> git.0d.be Git - empathy.git/blobdiff - src/empathy-accounts-common.c
empathy-debugger: rely on gtk_application_add_window() to manage the main loop
[empathy.git] / src / empathy-accounts-common.c
index 89d7eb8a85b189efe9a044eac884d6fa4ecc7911..88d14c321a88698ffede7892a54611566bf23227 100644 (file)
@@ -30,8 +30,7 @@
 #include <stdlib.h>
 
 #include <gtk/gtk.h>
-#include <glib/gi18n.h>
-#include <unique/unique.h>
+#include <glib/gi18n-lib.h>
 
 #include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/util.h>
@@ -43,7 +42,6 @@
 #include "empathy-accounts-common.h"
 #include "empathy-accounts-dialog.h"
 #include "empathy-account-assistant.h"
-#include "empathy-import-mc4-accounts.h"
 #include "empathy-auto-salut-account-helper.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
@@ -71,107 +69,48 @@ empathy_accounts_has_non_salut_accounts (TpAccountManager *manager)
   return ret;
 }
 
-/* Try to import accounts from MC4 and returns TRUE if we should display the
- * accounts assistant. */
 gboolean
-empathy_accounts_import (TpAccountManager *account_mgr,
-    EmpathyConnectionManagers *cm_mgr)
+empathy_accounts_has_accounts (TpAccountManager *manager)
 {
-  g_return_val_if_fail (tp_account_manager_is_prepared (account_mgr,
-      TP_ACCOUNT_MANAGER_FEATURE_CORE), FALSE);
-  g_return_val_if_fail (empathy_connection_managers_is_ready (cm_mgr), FALSE);
+  GList *accounts;
+  gboolean has_accounts;
 
-  if (empathy_import_mc4_has_imported ())
-    return FALSE;
-
-  if (empathy_import_mc4_accounts (cm_mgr))
-    return FALSE;
-
-  if (empathy_accounts_has_non_salut_accounts (account_mgr))
-    return FALSE;
-
-  if (!should_create_salut_account (account_mgr))
-    return FALSE;
+  accounts = tp_account_manager_get_valid_accounts (manager);
+  has_accounts = (accounts != NULL);
+  g_list_free (accounts);
 
-  return TRUE;
+  return has_accounts;
 }
 
 static void
 do_show_accounts_ui (TpAccountManager *manager,
     TpAccount *account,
-    GCallback window_destroyed_cb)
+    GApplication *app)
 {
-  GtkWidget *accounts_window;
+  static GtkWidget *accounts_window = NULL;
 
-  accounts_window = empathy_accounts_dialog_show (NULL, account);
+  if (accounts_window == NULL)
+    {
+      accounts_window = empathy_accounts_dialog_show (NULL, account);
 
-  if (window_destroyed_cb)
-    g_signal_connect (accounts_window, "destroy", window_destroyed_cb, NULL);
+      gtk_application_add_window (GTK_APPLICATION (app),
+          GTK_WINDOW (accounts_window));
+    }
 
   gtk_window_present (GTK_WINDOW (accounts_window));
 }
 
-static GtkWidget*
+static GtkWidget *
 show_account_assistant (EmpathyConnectionManagers *connection_mgrs,
-    GCallback assistant_destroy_cb)
+    GApplication *app)
 {
   GtkWidget *assistant;
 
   assistant = empathy_account_assistant_show (NULL, connection_mgrs);
-  if (assistant_destroy_cb)
-    g_signal_connect (assistant, "destroy", assistant_destroy_cb, NULL);
-
-  return assistant;
-}
-
-static void
-connection_managers_prepare_cb (
-    EmpathyConnectionManagers *cm_mgr,
-    GAsyncResult *result,
-    gpointer user_data)
-{
-  GCallback assistant_destroy_cb = g_object_get_data (G_OBJECT (cm_mgr),
-      "assistant-destroy-callback");
-  TpAccountManager *account_mgr = g_object_get_data (G_OBJECT (cm_mgr),
-      "account-manager");
-  gboolean hidden = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (cm_mgr),
-        "hidden"));
-
-  if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
-    goto out;
 
-  if (empathy_accounts_import (account_mgr, cm_mgr) &&
-      !hidden)
-    {
-      show_account_assistant (cm_mgr, assistant_destroy_cb);
-    }
-  else
-    {
-      if (assistant_destroy_cb)
-        assistant_destroy_cb ();
-    }
+  gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (assistant));
 
-out:
-  g_object_unref (cm_mgr);
-}
-
-void
-empathy_accounts_manager_ready_for_show_assistant (
-    TpAccountManager *account_mgr,
-    gboolean hidden)
-{
-  EmpathyConnectionManagers *cm_mgr;
-
-  cm_mgr = empathy_connection_managers_dup_singleton ();
-
-  g_object_set_data (G_OBJECT (cm_mgr), "assistant-destroy-callback",
-      g_object_get_data (G_OBJECT (account_mgr), "assistant-destroy-callback"));
-  g_object_set_data_full (G_OBJECT (cm_mgr), "account-manager",
-      g_object_ref (account_mgr), g_object_unref);
-  g_object_set_data (G_OBJECT (cm_mgr), "hidden", GUINT_TO_POINTER (hidden));
-
-  empathy_connection_managers_prepare_async (cm_mgr,
-      (GAsyncReadyCallback) connection_managers_prepare_cb, NULL);
+  return assistant;
 }
 
 static void
@@ -180,29 +119,32 @@ connection_managers_prepare_for_accounts (GObject *source,
     gpointer user_data)
 {
   EmpathyConnectionManagers *cm_mgr = EMPATHY_CONNECTION_MANAGERS (source);
-  GCallback assistant_destroy_cb = G_CALLBACK (user_data);
+  GApplication *app = user_data;
 
   if (!empathy_connection_managers_prepare_finish (cm_mgr, result, NULL))
     goto out;
 
-  show_account_assistant (cm_mgr, assistant_destroy_cb);
-  g_debug ("would show the account assistant");
+  show_account_assistant (cm_mgr, app);
+  DEBUG ("would show the account assistant");
 
 out:
   g_object_unref (cm_mgr);
+  g_application_release (app);
 }
 
 void
 empathy_accounts_show_accounts_ui (TpAccountManager *manager,
     TpAccount *account,
-    GCallback window_destroyed_cb)
+    gboolean assistant,
+    GApplication *app)
 {
   g_return_if_fail (TP_IS_ACCOUNT_MANAGER (manager));
   g_return_if_fail (!account || TP_IS_ACCOUNT (account));
 
-  if (empathy_accounts_has_non_salut_accounts (manager))
+  if ((empathy_accounts_has_non_salut_accounts (manager) && !assistant) ||
+          account != NULL)
     {
-      do_show_accounts_ui (manager, account, window_destroyed_cb);
+      do_show_accounts_ui (manager, account, app);
     }
   else
     {
@@ -210,7 +152,10 @@ empathy_accounts_show_accounts_ui (TpAccountManager *manager,
 
       cm_mgr = empathy_connection_managers_dup_singleton ();
 
+      /* Hold the application while preparing cm_mgr */
+      g_application_hold (app);
+
       empathy_connection_managers_prepare_async (cm_mgr,
-          connection_managers_prepare_for_accounts, window_destroyed_cb);
+          connection_managers_prepare_for_accounts, app);
     }
 }