Blob Blame History Raw
From 76f5e0e98a86e5a91f636ae2fb74c5b6663208ab Mon Sep 17 00:00:00 2001
From: Matthias Clasen <mclasen@redhat.com>
Date: Wed, 8 Jan 2014 19:25:03 -0500
Subject: [PATCH 2/2] Make dialog work with --xid again

When triggering an async operation from a GApplicationCommandline,
we must use g_application_hold/release to ensure the application
instance stays around until the operation is done.

https://bugzilla.gnome.org/show_bug.cgi?id=721278
---
 src/disks/gduapplication.c        |  4 +++-
 src/disks/gduformatvolumedialog.c | 19 +++++++++++++++----
 src/disks/gduformatvolumedialog.h |  4 +++-
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/disks/gduapplication.c b/src/disks/gduapplication.c
index 1334d28..78d6272 100644
--- a/src/disks/gduapplication.c
+++ b/src/disks/gduapplication.c
@@ -251,7 +251,9 @@ gdu_application_command_line (GApplication            *_app,
     }
   else if (opt_format)
     {
-      gdu_format_volume_dialog_show_for_xid (app->client, opt_xid, object_to_select);
+      g_application_hold (_app);
+      gdu_format_volume_dialog_show_for_xid (app->client, opt_xid, object_to_select,
+                                             (GCallback)g_application_release, _app);
     }
 
 
diff --git a/src/disks/gduformatvolumedialog.c b/src/disks/gduformatvolumedialog.c
index f741ade..2e0ca79 100644
--- a/src/disks/gduformatvolumedialog.c
+++ b/src/disks/gduformatvolumedialog.c
@@ -33,11 +33,16 @@ typedef struct
 
   GtkWidget *contents_box;
   GtkWidget *create_filesystem_widget;
+
+  GCallback finished_cb;
+  gpointer  cb_data;
 } FormatVolumeData;
 
 static void
 format_volume_data_free (FormatVolumeData *data)
 {
+  if (data->finished_cb)
+    ((GDestroyNotify) data->finished_cb) (data->cb_data);
   g_clear_object (&data->parent_window);
   g_object_unref (data->object);
   g_object_unref (data->block);
@@ -144,13 +149,17 @@ static void
 gdu_format_volume_dialog_show_internal (UDisksClient *client,
                                         GtkWindow    *parent_window,
                                         gint          parent_xid,
-                                        UDisksObject *object)
+                                        UDisksObject *object,
+                                        GCallback     finished_cb,
+                                        gpointer      cb_data)
 {
   GduApplication *app = GDU_APPLICATION (g_application_get_default ());
   FormatVolumeData *data;
   gint response;
 
   data = g_new0 (FormatVolumeData, 1);
+  data->finished_cb = finished_cb;
+  data->cb_data = cb_data;
   data->parent_window = (parent_window != NULL) ? g_object_ref (parent_window) : NULL;
   data->object = g_object_ref (object);
   data->block = udisks_object_get_block (object);
@@ -250,9 +259,11 @@ gdu_format_volume_dialog_show_internal (UDisksClient *client,
 void
 gdu_format_volume_dialog_show_for_xid (UDisksClient *client,
                                        gint          xid,
-                                       UDisksObject *object)
+                                       UDisksObject *object,
+                                       GCallback     finished_cb,
+                                       gpointer      cb_data)
 {
-  gdu_format_volume_dialog_show_internal (client, NULL, xid, object);
+  gdu_format_volume_dialog_show_internal (client, NULL, xid, object, finished_cb, cb_data);
 }
 
 void
@@ -260,5 +271,5 @@ gdu_format_volume_dialog_show (GduWindow    *window,
                                UDisksObject *object)
 {
   gdu_format_volume_dialog_show_internal (gdu_window_get_client (window), GTK_WINDOW (window),
-                                          -1, object);
+                                          -1, object, NULL, NULL);
 }
diff --git a/src/disks/gduformatvolumedialog.h b/src/disks/gduformatvolumedialog.h
index 62a43ef..3721fbb 100644
--- a/src/disks/gduformatvolumedialog.h
+++ b/src/disks/gduformatvolumedialog.h
@@ -19,7 +19,9 @@ void     gdu_format_volume_dialog_show         (GduWindow    *window,
                                                 UDisksObject *object);
 void     gdu_format_volume_dialog_show_for_xid (UDisksClient *client,
                                                 gint          xid,
-                                                UDisksObject *object);
+                                                UDisksObject *object,
+                                                GCallback     finished_cb,
+                                                gpointer      cb_data);
 
 G_END_DECLS
 
-- 
1.8.4.2