[gnome-disk-utility] Use response signal on MessageDialogs



commit 9672ed047b9315362535f9b3fee66258be2b3293
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Tue Oct 12 16:03:49 2021 +0200

    Use response signal on MessageDialogs

 src/disk-image-mounter/main.c | 11 +++++--
 src/disks/gduresizedialog.c   | 11 +++++--
 src/disks/gduwindow.c         | 72 ++++++++++++++++++++++++++++++++++---------
 src/libgdu/gduutils.c         | 11 +++++--
 4 files changed, 85 insertions(+), 20 deletions(-)
---
diff --git a/src/disk-image-mounter/main.c b/src/disk-image-mounter/main.c
index 1df674bd..cd567536 100644
--- a/src/disk-image-mounter/main.c
+++ b/src/disk-image-mounter/main.c
@@ -25,6 +25,13 @@ static GMainLoop *main_loop = NULL;
 
 static void show_error (const gchar *format, ...) G_GNUC_PRINTF (1, 2);
 
+static void
+response_cb (GtkDialog *dialog,
+             gint       response)
+{
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 static void
 show_error (const gchar *format, ...)
 {
@@ -46,8 +53,8 @@ show_error (const gchar *format, ...)
                                                    _("An error occurred"));
       gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog), "%s", s);
       gtk_window_set_title (GTK_WINDOW (dialog), _("Disk Image Mounter"));
-      gtk_dialog_run (GTK_DIALOG (dialog));
-      gtk_widget_destroy (dialog);
+      g_signal_connect (dialog, "response", G_CALLBACK (response_cb), NULL);
+      gtk_window_present (GTK_WINDOW (dialog));
     }
   else
     {
diff --git a/src/disks/gduresizedialog.c b/src/disks/gduresizedialog.c
index 521fa5df..76cc959e 100644
--- a/src/disks/gduresizedialog.c
+++ b/src/disks/gduresizedialog.c
@@ -441,6 +441,13 @@ fs_resize_cb_offline_next_repair (UDisksFilesystem *filesystem,
     }
 }
 
+static void
+response_cb (GtkDialog *dialog,
+             gint       response)
+{
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 static gboolean
 resize_filesystem_waiter (gpointer user_data)
 {
@@ -464,9 +471,9 @@ resize_filesystem_waiter (gpointer user_data)
                                                    _("Resizing not ready"));
       gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
                                                   _("Waited too long for the filesystem"));
-      gtk_dialog_run (GTK_DIALOG (dialog));
+      g_signal_connect (dialog, "response", G_CALLBACK (response_cb), NULL);
+      gtk_window_present (GTK_WINDOW (dialog));
 
-      gtk_widget_destroy (dialog);
       resize_dialog_data_unref (data);
 
       return G_SOURCE_REMOVE;
diff --git a/src/disks/gduwindow.c b/src/disks/gduwindow.c
index f7211609..06141eb5 100644
--- a/src/disks/gduwindow.c
+++ b/src/disks/gduwindow.c
@@ -2959,6 +2959,14 @@ on_volume_menu_item_resize (GSimpleAction *action,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static void
+response_cb (GtkDialog *dialog,
+             gint       response,
+             gpointer   user_data)
+{
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 static void
 fs_repair_cb (UDisksFilesystem *filesystem,
               GAsyncResult     *res,
@@ -3011,9 +3019,9 @@ fs_repair_cb (UDisksFilesystem *filesystem,
         }
 
       gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (message_dialog), "%s", s);
-      gtk_dialog_run (GTK_DIALOG (message_dialog));
+      g_signal_connect (message_dialog, "response", G_CALLBACK (response_cb), NULL);
+      gtk_window_present (GTK_WINDOW (message_dialog));
 
-      gtk_widget_destroy (message_dialog);
       g_free (s);
     }
 
@@ -3042,6 +3050,23 @@ fs_repair_unmount_cb (GduWindow        *window,
   g_object_unref (object);
 }
 
+static void
+on_response (GtkDialog *dialog,
+             gint       response,
+             gpointer   user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  UDisksObject *object;
+
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+
+  if (response == GTK_RESPONSE_OK)
+    gdu_window_ensure_unused (window, object, (GAsyncReadyCallback) fs_repair_unmount_cb,
+                              NULL, g_object_ref (object));
+
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 static void
 on_volume_menu_item_repair (GSimpleAction *action,
                             GVariant      *parameter,
@@ -3070,11 +3095,8 @@ on_volume_menu_item_repair (GSimpleAction *action,
   ok_button = gtk_dialog_get_widget_for_response (GTK_DIALOG (message_dialog), GTK_RESPONSE_OK);
   gtk_style_context_add_class (gtk_widget_get_style_context (ok_button), "destructive-action");
 
-  if (gtk_dialog_run (GTK_DIALOG (message_dialog)) == GTK_RESPONSE_OK)
-    gdu_window_ensure_unused (window, object, (GAsyncReadyCallback) fs_repair_unmount_cb,
-                              NULL, g_object_ref (object));
-
-  gtk_widget_destroy (message_dialog);
+  g_signal_connect (message_dialog, "response", G_CALLBACK (on_response), user_data);
+  gtk_window_present (GTK_WINDOW (message_dialog));
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
@@ -3160,6 +3182,14 @@ on_volume_menu_item_take_ownership (GSimpleAction *action,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static void
+on_message_dialog_response (GtkDialog *dialog,
+             gint       response,
+             gpointer   user_data)
+{
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 static void
 fs_check_cb (UDisksFilesystem *filesystem,
              GAsyncResult     *res,
@@ -3212,9 +3242,9 @@ fs_check_cb (UDisksFilesystem *filesystem,
         }
 
       gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (message_dialog), "%s", s);
-      gtk_dialog_run (GTK_DIALOG (message_dialog));
+      g_signal_connect (message_dialog, "response", G_CALLBACK (on_message_dialog_response), NULL);
+      gtk_window_present (GTK_WINDOW (message_dialog));
 
-      gtk_widget_destroy (message_dialog);
       g_free (s);
     }
 }
@@ -3241,6 +3271,23 @@ fs_check_unmount_cb (GduWindow        *window,
   g_object_unref (object);
 }
 
+static void
+on_check_message_dialog_response (GtkDialog *dialog,
+                                  gint       response,
+                                  gpointer   user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  UDisksObject *object;
+
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+
+  if (response == GTK_RESPONSE_OK)
+    gdu_window_ensure_unused (window, object, (GAsyncReadyCallback) fs_check_unmount_cb,
+                              NULL, g_object_ref (object));
+
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 static void
 on_volume_menu_item_check (GSimpleAction *action,
                            GVariant      *parameter,
@@ -3266,11 +3313,8 @@ on_volume_menu_item_check (GSimpleAction *action,
   ok_button = gtk_dialog_get_widget_for_response (GTK_DIALOG (message_dialog), GTK_RESPONSE_OK);
   gtk_style_context_add_class (gtk_widget_get_style_context (ok_button), "suggested-action");
 
-  if (gtk_dialog_run (GTK_DIALOG (message_dialog)) == GTK_RESPONSE_OK)
-    gdu_window_ensure_unused (window, object, (GAsyncReadyCallback) fs_check_unmount_cb,
-                              NULL, g_object_ref (object));
-
-  gtk_widget_destroy (message_dialog);
+  g_signal_connect (message_dialog, "response", G_CALLBACK (on_check_message_dialog_response), user_data);
+  gtk_window_present (GTK_WINDOW (message_dialog));
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/libgdu/gduutils.c b/src/libgdu/gduutils.c
index a7c437bd..2e5b7be6 100644
--- a/src/libgdu/gduutils.c
+++ b/src/libgdu/gduutils.c
@@ -702,6 +702,13 @@ gdu_utils_is_inside_dos_extended (UDisksClient         *client,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+static void
+response_cb (GtkDialog *dialog,
+             gint       response)
+{
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 void
 gdu_utils_show_error (GtkWindow   *parent_window,
                       const gchar *message,
@@ -738,8 +745,8 @@ gdu_utils_show_error (GtkWindow   *parent_window,
                                               g_quark_to_string (error->domain),
                                               error->code);
   g_error_free (fixed_up_error);
-  gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_destroy (dialog);
+  g_signal_connect (dialog, "response", G_CALLBACK (response_cb), NULL);
+  gtk_window_present (GTK_WINDOW (dialog));
 
  no_dialog:
   ;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]