[gnome-disk-utility/udisks2-port] Call newly added Block.Format() method from the "Format Volume" dialog



commit a4fba0e1eff44bc5ea56d19582e35f46ad583456
Author: David Zeuthen <davidz redhat com>
Date:   Wed Nov 2 12:03:05 2011 -0400

    Call newly added Block.Format() method from the "Format Volume" dialog
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/format-volume-dialog.ui        |    2 +-
 src/palimpsest/gduformatvolumedialog.c |   46 ++++++++++++++++++++++++++++++-
 src/palimpsest/gduwindow.c             |   32 ++++++++++++++++++++++
 src/palimpsest/gduwindow.h             |    6 ++++
 4 files changed, 83 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/format-volume-dialog.ui b/data/ui/format-volume-dialog.ui
index 847563c..ef36732 100644
--- a/data/ui/format-volume-dialog.ui
+++ b/data/ui/format-volume-dialog.ui
@@ -155,7 +155,7 @@
                     <property name="can_focus">False</property>
                     <property name="no_show_all">True</property>
                     <property name="xalign">1</property>
-                    <property name="label" translatable="yes">_Filesystem:</property>
+                    <property name="label" translatable="yes">F_ilesystem:</property>
                     <property name="use_underline">True</property>
                     <property name="mnemonic_widget">filesystem-entry</property>
                   </object>
diff --git a/src/palimpsest/gduformatvolumedialog.c b/src/palimpsest/gduformatvolumedialog.c
index ebe3bc8..1ffaa23 100644
--- a/src/palimpsest/gduformatvolumedialog.c
+++ b/src/palimpsest/gduformatvolumedialog.c
@@ -163,9 +163,51 @@ gdu_format_volume_dialog_show (GduWindow    *window,
   response = gtk_dialog_run (GTK_DIALOG (data->dialog));
   if (response == GTK_RESPONSE_OK)
     {
-      /* TODO: confirmation dialog? */
-      g_debug ("TODO: format volume");
+      GVariantBuilder options_builder;
+      const gchar *type;
+      GError *error;
+
+      gtk_widget_hide (data->dialog);
+      if (!gdu_window_show_confirmation (window,
+                                         _("Are you sure you want to format the volume?"),
+                                         _("All data on the volume will be lost"),
+                                         _("_Format")))
+        goto out;
+
+      g_variant_builder_init (&options_builder, G_VARIANT_TYPE_VARDICT);
+      if (strlen (gtk_entry_get_text (GTK_ENTRY (data->name_entry))) > 0)
+      g_variant_builder_add (&options_builder, "{sv}", "label",
+                             g_variant_new_string (gtk_entry_get_text (GTK_ENTRY (data->name_entry))));
+
+      switch (gtk_combo_box_get_active (GTK_COMBO_BOX (data->type_combobox)))
+        {
+        case 0:
+          type = "vfat";
+          break;
+        case 1:
+          type = "ext4";
+          break;
+        case 2:
+          /* TODO */
+          type = "luks+ext4";
+          break;
+        case 3:
+          type = gtk_entry_get_text (GTK_ENTRY (data->filesystem_entry));
+          break;
+        }
+
+      error = NULL;
+      if (!udisks_block_call_format_sync (data->block,
+                                          type,
+                                          g_variant_builder_end (&options_builder),
+                                          NULL, /* GCancellable */
+                                          &error))
+        {
+          gdu_window_show_error (window, _("Error formatting volume"), error);
+          g_error_free (error);
+        }
     }
 
+ out:
   format_volume_data_free (data);
 }
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index 034a263..2008f6d 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -2040,6 +2040,38 @@ gdu_window_show_error (GduWindow   *window,
 
 /* ---------------------------------------------------------------------------------------------------- */
 
+gboolean
+gdu_window_show_confirmation (GduWindow   *window,
+                              const gchar *message,
+                              const gchar *secondary_message,
+                              const gchar *affirmative_verb)
+{
+  GtkWidget *dialog;
+  gint response;
+
+  dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (window),
+                                               GTK_DIALOG_MODAL,
+                                               GTK_MESSAGE_INFO,
+                                               GTK_BUTTONS_CANCEL,
+                                               "<big><b>%s</b></big>",
+                                               message);
+  gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
+                                              "%s",
+                                              secondary_message);
+
+  gtk_dialog_add_button (GTK_DIALOG (dialog),
+                         affirmative_verb,
+                         GTK_RESPONSE_OK);
+
+  response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+  gtk_widget_destroy (dialog);
+
+  return response == GTK_RESPONSE_OK;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
 static void
 on_generic_menu_item_edit_label (GtkMenuItem *menu_item,
                                  gpointer   user_data)
diff --git a/src/palimpsest/gduwindow.h b/src/palimpsest/gduwindow.h
index da47aed..38d060e 100644
--- a/src/palimpsest/gduwindow.h
+++ b/src/palimpsest/gduwindow.h
@@ -42,6 +42,12 @@ void            gdu_window_show_error      (GduWindow      *window,
                                             const gchar    *message,
                                             GError         *error);
 
+gboolean        gdu_window_show_confirmation (GduWindow   *window,
+                                              const gchar *message,
+                                              const gchar *secondary_message,
+                                              const gchar *affirmative_verb);
+
+
 G_END_DECLS
 
 #endif /* __GDU_WINDOW_H__ */



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