empathy-debugger: rely on gtk_application_add_window() to manage the main loop
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 25 Oct 2011 15:03:28 +0000 (17:03 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Wed, 26 Oct 2011 09:02:51 +0000 (11:02 +0200)
We have to old the application while doing async preparation as the app window
is not created right away.

https://bugzilla.gnome.org/show_bug.cgi?id=662504

src/empathy-accounts-common.c
src/empathy-accounts-common.h
src/empathy-accounts.c

index a08a1ef77eef2ac74931cc8fe48eb230e365a6a7..88d14c321a88698ffede7892a54611566bf23227 100644 (file)
@@ -85,28 +85,30 @@ empathy_accounts_has_accounts (TpAccountManager *manager)
 static void
 do_show_accounts_ui (TpAccountManager *manager,
     TpAccount *account,
-    GCallback window_destroyed_cb)
+    GApplication *app)
 {
   static GtkWidget *accounts_window = NULL;
 
   if (accounts_window == NULL)
-    accounts_window = empathy_accounts_dialog_show (NULL, account);
+    {
+      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 *
 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);
+
+  gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (assistant));
 
   return assistant;
 }
@@ -117,23 +119,24 @@ 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);
+  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,
     gboolean assistant,
-    GCallback window_destroyed_cb)
+    GApplication *app)
 {
   g_return_if_fail (TP_IS_ACCOUNT_MANAGER (manager));
   g_return_if_fail (!account || TP_IS_ACCOUNT (account));
@@ -141,7 +144,7 @@ empathy_accounts_show_accounts_ui (TpAccountManager *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
     {
@@ -149,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);
     }
 }
index 002d78323175233190026cee4d580ca4c467554f..f9294fbd2592cb62176b1fbfab85ca3d42ee22f1 100644 (file)
@@ -29,6 +29,6 @@ gboolean empathy_accounts_has_accounts (TpAccountManager *manager);
 void empathy_accounts_show_accounts_ui (TpAccountManager *manager,
     TpAccount *account,
     gboolean assistant,
-    GCallback window_destroyed_cb);
+    GApplication *app);
 
 #endif /* __EMPATHY_ACCOUNTS_COMMON_H__ */
index fa6b6b26f8b0a5396ecf0a123849d1bd2257b983..3b25201c5abb0839d7365edc4584fab47ea2a327 100644 (file)
@@ -57,13 +57,16 @@ static gchar *selected_account_name = NULL;
 static gboolean assistant = FALSE;
 
 static void
-maybe_show_accounts_ui (TpAccountManager *manager)
+maybe_show_accounts_ui (TpAccountManager *manager,
+    GApplication *app)
 {
-  if (hidden ||
-      (only_if_needed && empathy_accounts_has_non_salut_accounts (manager)))
-    gtk_main_quit ();
-  else
-    empathy_accounts_show_accounts_ui (manager, NULL, assistant, gtk_main_quit);
+  if (hidden)
+    return;
+
+  if (only_if_needed && empathy_accounts_has_non_salut_accounts (manager))
+    return;
+
+  empathy_accounts_show_accounts_ui (manager, NULL, assistant, app);
 }
 
 static TpAccount *
@@ -94,12 +97,13 @@ account_manager_ready_for_accounts_cb (GObject *source_object,
 {
   TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
   GError *error = NULL;
+  GApplication *app = G_APPLICATION (user_data);
 
   if (!tp_proxy_prepare_finish (manager, result, &error))
     {
       DEBUG ("Failed to prepare account manager: %s", error->message);
       g_clear_error (&error);
-      return;
+      goto out;
     }
 
   if (selected_account_name != NULL)
@@ -119,10 +123,8 @@ account_manager_ready_for_accounts_cb (GObject *source_object,
 
       if (account != NULL)
         {
-          empathy_accounts_show_accounts_ui (manager, account, assistant,
-              G_CALLBACK (gtk_main_quit));
-
-          return;
+          empathy_accounts_show_accounts_ui (manager, account, assistant, app);
+          goto out;
         }
       else
         {
@@ -130,15 +132,18 @@ account_manager_ready_for_accounts_cb (GObject *source_object,
 
           g_clear_error (&error);
 
-          maybe_show_accounts_ui (manager);
+          maybe_show_accounts_ui (manager, app);
         }
 
       g_free (account_path);
     }
   else
     {
-      maybe_show_accounts_ui (manager);
+      maybe_show_accounts_ui (manager, app);
     }
+
+out:
+  g_application_release (app);
 }
 
 static int
@@ -147,12 +152,13 @@ app_command_line_cb (GApplication *app,
 {
   TpAccountManager *account_manager;
 
-  g_application_hold (app);
-
   account_manager = tp_account_manager_dup ();
 
+  /* Hold the application while preparing the AM */
+  g_application_hold (app);
+
   tp_proxy_prepare_async (account_manager, NULL,
-    account_manager_ready_for_accounts_cb, NULL);
+    account_manager_ready_for_accounts_cb, app);
 
   g_object_unref (account_manager);