[gnome-disk-utility/udisks2-port] Add a "Format Volume" dialog



commit b4c0a0aa101905a23eb552f6b777aee6dffb6e50
Author: David Zeuthen <davidz redhat com>
Date:   Wed Nov 2 10:54:42 2011 -0400

    Add a "Format Volume" dialog
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/Makefile.am                    |    4 +
 data/ui/format-volume-dialog.ui        |  216 ++++++++++++++++++++++++++++++++
 data/ui/palimpsest.ui                  |    9 ++
 src/palimpsest/Makefile.am             |    1 +
 src/palimpsest/gduformatvolumedialog.c |  171 +++++++++++++++++++++++++
 src/palimpsest/gduformatvolumedialog.h |   36 ++++++
 src/palimpsest/gduwindow.c             |   29 +++++
 7 files changed, 466 insertions(+), 0 deletions(-)
---
diff --git a/data/ui/Makefile.am b/data/ui/Makefile.am
index 07756e6..f91b504 100644
--- a/data/ui/Makefile.am
+++ b/data/ui/Makefile.am
@@ -8,8 +8,12 @@ ui_DATA = 				\
 	edit-filesystem-dialog.ui	\
 	edit-fstab-dialog.ui		\
 	edit-partition-dialog.ui	\
+	edit-gpt-partition-dialog.ui	\
+	edit-dos-partition-dialog.ui	\
 	palimpsest.ui			\
 	unlock-device-dialog.ui		\
+	format-volume-dialog.ui		\
+	smart-dialog.ui			\
 	$(NULL)
 
 clean-local :
diff --git a/data/ui/format-volume-dialog.ui b/data/ui/format-volume-dialog.ui
new file mode 100644
index 0000000..847563c
--- /dev/null
+++ b/data/ui/format-volume-dialog.ui
@@ -0,0 +1,216 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkDialog" id="format-volume-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">12</property>
+    <property name="resizable">False</property>
+    <property name="modal">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button1">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button2">
+                <property name="label" translatable="yes">_Format...</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_action_appearance">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="box1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">&lt;big&gt;Format Volume&lt;/big&gt;</property>
+                <property name="use_markup">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkGrid" id="grid1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="margin_left">12</property>
+                <property name="row_spacing">6</property>
+                <property name="column_spacing">10</property>
+                <child>
+                  <object class="GtkLabel" id="label5">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">_Type:</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">type-combobox</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkComboBoxText" id="type-combobox">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="has_tooltip">True</property>
+                    <property name="tooltip_markup" translatable="yes">The kind of filesystem to create. Choose &lt;b&gt;Custom&lt;/b&gt; to specify a custom filesystem type such as &lt;i&gt;btrfs&lt;/i&gt; or &lt;i&gt;swap&lt;/i&gt;</property>
+                    <items>
+                      <item translatable="yes">Compatible with all systems (FAT)</item>
+                      <item translatable="yes">Compatible with Linux (ext4)</item>
+                      <item translatable="yes">Encrypted, compatible with Linux (LUKS + ext4)</item>
+                      <item translatable="yes">Custom</item>
+                    </items>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">0</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">1</property>
+                    <property name="label" translatable="yes">_Name:</property>
+                    <property name="use_underline">True</property>
+                    <property name="mnemonic_widget">name-entry</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="name-entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="tooltip_markup" translatable="yes">The name to use for the filesystem. This is useful if you want to refer to the device via a symlink in the &lt;b&gt;/dev/disk/by-label&lt;/b&gt; directory</property>
+                    <property name="invisible_char">â</property>
+                    <property name="activates_default">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">1</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="filesystem-label">
+                    <property name="visible">True</property>
+                    <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="use_underline">True</property>
+                    <property name="mnemonic_widget">filesystem-entry</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">0</property>
+                    <property name="top_attach">2</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="filesystem-entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="no_show_all">True</property>
+                    <property name="tooltip_markup" translatable="yes">The custom filesystem type to create e.g. &lt;i&gt;btrfs&lt;/i&gt; or &lt;i&gt;btrfs&lt;/i&gt;</property>
+                    <property name="invisible_char">â</property>
+                    <property name="activates_default">True</property>
+                    <property name="invisible_char_set">True</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="top_attach">2</property>
+                    <property name="width">1</property>
+                    <property name="height">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">button1</action-widget>
+      <action-widget response="-5">button2</action-widget>
+    </action-widgets>
+  </object>
+</interface>
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index 78ab431..5b3444f 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -105,6 +105,15 @@
         <property name="use_underline">True</property>
       </object>
     </child>
+    <child>
+      <object class="GtkMenuItem" id="generic-menu-item-format-volume">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="use_action_appearance">False</property>
+        <property name="label" translatable="yes">Format Volume...</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
   </object>
   <object class="GtkWindow" id="palimpsest-window">
     <property name="can_focus">False</property>
diff --git a/src/palimpsest/Makefile.am b/src/palimpsest/Makefile.am
index 42aeb87..fe37da6 100644
--- a/src/palimpsest/Makefile.am
+++ b/src/palimpsest/Makefile.am
@@ -37,6 +37,7 @@ palimpsest_SOURCES = 					\
 	gdufstabdialog.h	gdufstabdialog.c	\
 	gdupartitiondialog.h	gdupartitiondialog.c	\
 	gduunlockdialog.h	gduunlockdialog.c	\
+	gduformatvolumedialog.h	gduformatvolumedialog.c	\
 	$(enum_built_sources)				\
 	$(NULL)
 
diff --git a/src/palimpsest/gduformatvolumedialog.c b/src/palimpsest/gduformatvolumedialog.c
new file mode 100644
index 0000000..ebe3bc8
--- /dev/null
+++ b/src/palimpsest/gduformatvolumedialog.c
@@ -0,0 +1,171 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+
+#include "gduapplication.h"
+#include "gduwindow.h"
+#include "gduformatvolumedialog.h"
+#include "gduvolumegrid.h"
+#include "gduutils.h"
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+
+typedef struct
+{
+  GduWindow *window;
+  UDisksObject *object;
+  UDisksBlock *block;
+
+  GtkBuilder *builder;
+  GtkWidget *dialog;
+  GtkWidget *type_combobox;
+  GtkWidget *name_entry;
+  GtkWidget *filesystem_label;
+  GtkWidget *filesystem_entry;
+} FormatVolumeData;
+
+static void
+format_volume_data_free (FormatVolumeData *data)
+{
+  g_object_unref (data->window);
+  g_object_unref (data->object);
+  g_object_unref (data->block);
+  if (data->dialog != NULL)
+    {
+      gtk_widget_hide (data->dialog);
+      gtk_widget_destroy (data->dialog);
+    }
+  if (data->builder != NULL)
+    g_object_unref (data->builder);
+  g_free (data);
+}
+
+static void
+format_volume_update (FormatVolumeData *data)
+{
+  gboolean show_filesystem = FALSE;
+  gboolean can_proceed = FALSE;
+
+  if (gtk_combo_box_get_active (GTK_COMBO_BOX (data->type_combobox)) == 3)
+    {
+      /* "Custom" selected */
+      show_filesystem = TRUE;
+      if (strlen (gtk_entry_get_text (GTK_ENTRY (data->filesystem_entry))) > 0)
+        {
+          /* TODO: maybe validate we know how to create this FS?
+           * And also make "Name" + its entry insensitive if it doesn't support labels?
+           */
+          can_proceed = TRUE;
+        }
+    }
+  else
+    {
+      can_proceed = TRUE;
+    }
+
+  if (show_filesystem)
+    {
+      gtk_widget_show (data->filesystem_label);
+      gtk_widget_show (data->filesystem_entry);
+    }
+  else
+    {
+      gtk_widget_hide (data->filesystem_label);
+      gtk_widget_hide (data->filesystem_entry);
+    }
+
+  gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK, can_proceed);
+}
+
+static void
+format_volume_property_changed (GObject     *object,
+                                GParamSpec  *pspec,
+                                gpointer     user_data)
+{
+  FormatVolumeData *data = user_data;
+  format_volume_update (data);
+}
+
+static void
+format_volume_populate (FormatVolumeData *data)
+{
+  /* Select "Compatible with all systems (FAT)" by default */
+  gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_combobox), 1);
+
+  /* Translators: this is the default name for the filesystem */
+  gtk_entry_set_text (GTK_ENTRY (data->name_entry), _("New Volume"));
+
+  /* Set 'swap' for the custom filesystem */
+  gtk_entry_set_text (GTK_ENTRY (data->filesystem_entry), "swap");
+}
+
+void
+gdu_format_volume_dialog_show (GduWindow    *window,
+                               UDisksObject *object)
+{
+  FormatVolumeData *data;
+  gint response;
+
+  data = g_new0 (FormatVolumeData, 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->dialog = gdu_application_new_widget (gdu_window_get_application (window),
+                                             "format-volume-dialog.ui",
+                                             "format-volume-dialog",
+                                             &data->builder);
+  data->type_combobox = GTK_WIDGET (gtk_builder_get_object (data->builder, "type-combobox"));
+  g_signal_connect (data->type_combobox,
+                    "notify::active", G_CALLBACK (format_volume_property_changed), data);
+  data->name_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "name-entry"));
+  g_signal_connect (data->name_entry,
+                    "notify::text", G_CALLBACK (format_volume_property_changed), data);
+  data->filesystem_label = GTK_WIDGET (gtk_builder_get_object (data->builder, "filesystem-label"));
+  data->filesystem_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "filesystem-entry"));
+  g_signal_connect (data->filesystem_entry,
+                    "notify::text", G_CALLBACK (format_volume_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_volume_populate (data);
+  format_volume_update (data);
+
+  gtk_widget_show_all (data->dialog);
+  gtk_widget_grab_focus (data->name_entry);
+
+  /* TODO: do this async */
+  response = gtk_dialog_run (GTK_DIALOG (data->dialog));
+  if (response == GTK_RESPONSE_OK)
+    {
+      /* TODO: confirmation dialog? */
+      g_debug ("TODO: format volume");
+    }
+
+  format_volume_data_free (data);
+}
diff --git a/src/palimpsest/gduformatvolumedialog.h b/src/palimpsest/gduformatvolumedialog.h
new file mode 100644
index 0000000..261f12d
--- /dev/null
+++ b/src/palimpsest/gduformatvolumedialog.h
@@ -0,0 +1,36 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: David Zeuthen <davidz redhat com>
+ */
+
+#ifndef __GDU_FORMAT_VOLUME_DIALOG_H__
+#define __GDU_FORMAT_VOLUME_DIALOG_H__
+
+#include <gtk/gtk.h>
+#include "gdutypes.h"
+
+G_BEGIN_DECLS
+
+void     gdu_format_volume_dialog_show (GduWindow    *window,
+                                        UDisksObject *object);
+
+G_END_DECLS
+
+#endif /* __GDU_FORMAT_VOLUME_DIALOG_H__ */
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index 00df5c8..034a263 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -43,6 +43,7 @@
 #include "gdufilesystemdialog.h"
 #include "gdupartitiondialog.h"
 #include "gduunlockdialog.h"
+#include "gduformatvolumedialog.h"
 
 /* Keep in sync with tabs in palimpsest.ui file */
 typedef enum
@@ -100,6 +101,7 @@ struct _GduWindow
   GtkWidget *generic_menu_item_configure_crypttab;
   GtkWidget *generic_menu_item_edit_label;
   GtkWidget *generic_menu_item_edit_partition;
+  GtkWidget *generic_menu_item_format_volume;
 
   GHashTable *label_connections;
 };
@@ -139,6 +141,7 @@ static const struct {
   {G_STRUCT_OFFSET (GduWindow, generic_menu_item_configure_crypttab), "generic-menu-item-configure-crypttab"},
   {G_STRUCT_OFFSET (GduWindow, generic_menu_item_edit_label), "generic-menu-item-edit-label"},
   {G_STRUCT_OFFSET (GduWindow, generic_menu_item_edit_partition), "generic-menu-item-edit-partition"},
+  {G_STRUCT_OFFSET (GduWindow, generic_menu_item_format_volume), "generic-menu-item-format-volume"},
   {0, NULL}
 };
 
@@ -172,6 +175,7 @@ typedef enum
   SHOW_FLAGS_POPUP_MENU_CONFIGURE_CRYPTTAB = (1<<11),
   SHOW_FLAGS_POPUP_MENU_EDIT_LABEL         = (1<<12),
   SHOW_FLAGS_POPUP_MENU_EDIT_PARTITION     = (1<<13),
+  SHOW_FLAGS_POPUP_MENU_FORMAT_VOLUME      = (1<<14),
 } ShowFlags;
 
 static void setup_device_page (GduWindow *window, UDisksObject *object);
@@ -201,6 +205,8 @@ static void on_generic_menu_item_edit_label (GtkMenuItem *menu_item,
                                              gpointer   user_data);
 static void on_generic_menu_item_edit_partition (GtkMenuItem *menu_item,
                                                  gpointer   user_data);
+static void on_generic_menu_item_format_volume (GtkMenuItem *menu_item,
+                                                gpointer   user_data);
 
 G_DEFINE_TYPE (GduWindow, gdu_window, GTK_TYPE_WINDOW);
 
@@ -310,6 +316,8 @@ update_for_show_flags (GduWindow *window,
                           show_flags & SHOW_FLAGS_POPUP_MENU_EDIT_LABEL);
   gtk_widget_set_visible (GTK_WIDGET (window->generic_menu_item_edit_partition),
                           show_flags & SHOW_FLAGS_POPUP_MENU_EDIT_PARTITION);
+  gtk_widget_set_visible (GTK_WIDGET (window->generic_menu_item_format_volume),
+                          show_flags & SHOW_FLAGS_POPUP_MENU_FORMAT_VOLUME);
   /* TODO: don't show the button bringing up the popup menu if it has no items */
 }
 
@@ -852,6 +860,10 @@ gdu_window_constructed (GObject *object)
                     "activate",
                     G_CALLBACK (on_generic_menu_item_edit_partition),
                     window);
+  g_signal_connect (window->generic_menu_item_format_volume,
+                    "activate",
+                    G_CALLBACK (on_generic_menu_item_format_volume),
+                    window);
 
   g_idle_add (on_constructed_in_idle, g_object_ref (window));
 }
@@ -1626,6 +1638,9 @@ update_device_page_for_block (GduWindow          *window,
   partition = udisks_object_peek_partition (object);
   filesystem = udisks_object_peek_filesystem (object);
 
+  /* TODO: don't show on CD-ROM drives or RO media etc. */
+  *show_flags |= SHOW_FLAGS_POPUP_MENU_FORMAT_VOLUME;
+
   /* Since /etc/fstab, /etc/crypttab and so on can reference
    * any device regardless of its content ... we want to show
    * the relevant menu option (to get to the configuration dialog)
@@ -2054,6 +2069,20 @@ on_generic_menu_item_edit_partition (GtkMenuItem *menu_item,
 /* ---------------------------------------------------------------------------------------------------- */
 
 static void
+on_generic_menu_item_format_volume (GtkMenuItem *menu_item,
+                                    gpointer   user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  UDisksObject *object;
+
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+  g_assert (object != NULL);
+  gdu_format_volume_dialog_show (window, object);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
 on_generic_menu_item_configure_fstab (GtkMenuItem *menu_item,
                                       gpointer   user_data)
 {



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