[gnome-disk-utility] formatdiskdialog: Use dialog response api



commit ff4c7021d3b1dd053fd9f602f7b494e7fd3a218b
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Tue Oct 12 14:49:15 2021 +0200

    formatdiskdialog: Use dialog response api

 src/disks/gduformatdiskdialog.c | 97 ++++++++++++++++++++++-------------------
 1 file changed, 53 insertions(+), 44 deletions(-)
---
diff --git a/src/disks/gduformatdiskdialog.c b/src/disks/gduformatdiskdialog.c
index f6b258ae..a752cf19 100644
--- a/src/disks/gduformatdiskdialog.c
+++ b/src/disks/gduformatdiskdialog.c
@@ -365,48 +365,15 @@ ensure_unused_cb (GduWindow     *window,
   ;
 }
 
-void
-gdu_format_disk_dialog_show (GduWindow    *window,
-                               UDisksObject *object)
+static void
+dialog_response_cb (GtkDialog *dialog,
+                    gint       response,
+                    gpointer   user_data)
 {
-  FormatDiskData *data;
-  gint response;
-
-  data = g_new0 (FormatDiskData, 1);
-  data->window = g_object_ref (window);
-  data->object = g_object_ref (object);
-  data->block = udisks_object_get_block (object);
-  g_assert (data->block != NULL);
-  data->drive = udisks_client_get_drive_for_block (gdu_window_get_client (window), data->block);
-  if (data->drive != NULL)
-    {
-      GDBusObject *drive_object;
-      drive_object = g_dbus_interface_get_object (G_DBUS_INTERFACE (data->drive));
-      if (drive_object != NULL)
-        {
-          data->ata = udisks_object_get_drive_ata (UDISKS_OBJECT (drive_object));
-        }
-    }
-  data->dialog = GTK_WIDGET (gdu_application_new_widget (gdu_window_get_application (window),
-                                                         "format-disk-dialog.ui",
-                                                         "format-disk-dialog",
-                                                         &data->builder));
-  data->type_combobox = GTK_WIDGET (gtk_builder_get_object (data->builder, "type-combobox"));
-  data->erase_combobox = GTK_WIDGET (gtk_builder_get_object (data->builder, "erase-combobox"));
-  g_signal_connect (data->type_combobox, "notify::active", G_CALLBACK (on_property_changed), data);
-
-  gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (window));
-  gtk_dialog_set_default_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK);
-
-  format_disk_populate (data);
-  format_disk_update (data);
-
-  gtk_widget_show_all (data->dialog);
-  gtk_widget_grab_focus (data->type_combobox);
+    FormatDiskData *data = user_data;
 
-  response = gtk_dialog_run (GTK_DIALOG (data->dialog));
-  if (response == GTK_RESPONSE_OK)
-    {
+    gtk_widget_destroy (data->dialog);
+    if (response == GTK_RESPONSE_OK) {
       const gchar *erase_type;
       const gchar *primary_message;
       GString *str;
@@ -436,9 +403,8 @@ gdu_format_disk_dialog_show (GduWindow    *window,
           g_string_append (str, _("<b>WARNING</b>: The Secure Erase command may take a very long time to 
complete, can’t be canceled and may not work properly with some hardware. In the worst case, your drive may 
be rendered unusable or your system may crash or lock up. Before proceeding, please read the article about <a 
href='https://ata.wiki.kernel.org/index.php/ATA_Secure_Erase'>ATA Secure Erase</a> and make sure you 
understand the risks"));
         }
 
-      objects = g_list_append (NULL, object);
-      gtk_widget_hide (data->dialog);
-      if (!gdu_utils_show_confirmation (GTK_WINDOW (window),
+      objects = g_list_append (NULL, data->object);
+      if (!gdu_utils_show_confirmation (GTK_WINDOW (data->window),
                                         primary_message,
                                         str->str,
                                         _("_Format"),
@@ -462,5 +428,48 @@ gdu_format_disk_dialog_show (GduWindow    *window,
     }
 
  out:
-  format_disk_data_free (data);
+    format_disk_data_free (data);
+}
+
+void
+gdu_format_disk_dialog_show (GduWindow    *window,
+                             UDisksObject *object)
+{
+  FormatDiskData *data;
+  gint response;
+
+  data = g_new0 (FormatDiskData, 1);
+  data->window = g_object_ref (window);
+  data->object = g_object_ref (object);
+  data->block = udisks_object_get_block (object);
+  g_assert (data->block != NULL);
+  data->drive = udisks_client_get_drive_for_block (gdu_window_get_client (window), data->block);
+  if (data->drive != NULL)
+    {
+      GDBusObject *drive_object;
+      drive_object = g_dbus_interface_get_object (G_DBUS_INTERFACE (data->drive));
+      if (drive_object != NULL)
+        {
+          data->ata = udisks_object_get_drive_ata (UDISKS_OBJECT (drive_object));
+        }
+    }
+  data->dialog = GTK_WIDGET (gdu_application_new_widget (gdu_window_get_application (window),
+                                                         "format-disk-dialog.ui",
+                                                         "format-disk-dialog",
+                                                         &data->builder));
+  data->type_combobox = GTK_WIDGET (gtk_builder_get_object (data->builder, "type-combobox"));
+  data->erase_combobox = GTK_WIDGET (gtk_builder_get_object (data->builder, "erase-combobox"));
+  g_signal_connect (data->type_combobox, "notify::active", G_CALLBACK (on_property_changed), data);
+
+  gtk_window_set_transient_for (GTK_WINDOW (data->dialog), GTK_WINDOW (window));
+  gtk_dialog_set_default_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK);
+
+  format_disk_populate (data);
+  format_disk_update (data);
+
+  gtk_widget_show_all (data->dialog);
+  gtk_widget_grab_focus (data->type_combobox);
+
+  g_signal_connect (data->dialog, "response", dialog_response_cb, data);
+  gtk_window_present (GTK_WINDOW (data->dialog));
 }


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