[gnome-disk-utility] fstab, crypttab dialogs: Use switch to better convey whether conf exists



commit fe9b2f14704be357e027e9e7b6a7735e00a75fea
Author: David Zeuthen <davidz redhat com>
Date:   Tue Feb 28 11:02:59 2012 -0500

    fstab, crypttab dialogs: Use switch to better convey whether conf exists
    
    This was suggested by Jon McCann - thanks!
    
    http://people.freedesktop.org/~david/palimpsest2-edit-crypttab-w-switch.png
    http://people.freedesktop.org/~david/palimpsest2-edit-fstab-w-switch.png
    http://people.freedesktop.org/~david/palimpsest2-edit-fstab-w-switch-on.png
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/edit-crypttab-dialog.ui    |   94 ++++++++-------
 data/ui/edit-fstab-dialog.ui       |   93 ++++++++-------
 data/ui/palimpsest.ui              |    2 +-
 src/palimpsest/gducrypttabdialog.c |  241 +++++++++++++++++++-----------------
 src/palimpsest/gdufstabdialog.c    |  204 +++++++++++++++++--------------
 5 files changed, 340 insertions(+), 294 deletions(-)
---
diff --git a/data/ui/edit-crypttab-dialog.ui b/data/ui/edit-crypttab-dialog.ui
index accff60..2484e83 100644
--- a/data/ui/edit-crypttab-dialog.ui
+++ b/data/ui/edit-crypttab-dialog.ui
@@ -39,8 +39,8 @@
                 <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
                 <property name="can_default">True</property>
+                <property name="receives_default">True</property>
                 <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
               </object>
@@ -50,22 +50,6 @@
                 <property name="position">1</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkButton" id="crypttab-reset-button">
-                <property name="label" translatable="yes">Reset</property>
-                <property name="use_action_appearance">False</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>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-                <property name="secondary">True</property>
-              </packing>
-            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -79,7 +63,7 @@
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="orientation">vertical</property>
-            <property name="spacing">12</property>
+            <property name="spacing">6</property>
             <child>
               <object class="GtkBox" id="infobar-vbox">
                 <property name="visible">True</property>
@@ -96,9 +80,53 @@
               </packing>
             </child>
             <child>
+              <object class="GtkBox" id="box1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="spacing">12</property>
+                <child>
+                  <object class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Automatic Encryption Options</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                      <attribute name="scale" value="1"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSwitch" id="automatic-crypt-options-switch">
+                    <property name="use_action_appearance">False</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="has_tooltip">True</property>
+                    <property name="tooltip_markup" translatable="yes">Switch off &lt;i&gt;Automatic Encryption Options&lt;/i&gt; to manage encryption options and passphrase for the device. The options correspond to an entry in the &lt;b&gt;/etc/crypttab&lt;/b&gt; file</property>
+                    <property name="use_action_appearance">False</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="position">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkGrid" id="crypttab-grid">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="margin_left">24</property>
                 <property name="row_spacing">6</property>
                 <property name="column_spacing">10</property>
                 <child>
@@ -145,8 +173,7 @@
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="has_tooltip">True</property>
-                    <property name="tooltip_markup" translatable="yes">The name to use for the unlocked device - the device is set up as the name prefixed with /dev/mapper/</property>
-                    <property name="tooltip_text" translatable="yes">The name to use for the unlocked device - the device is set up as the name prefixed with /dev/mapper/</property>
+                    <property name="tooltip_markup" translatable="yes">The name to use for the unlocked device - the device is set up as the name prefixed with &lt;b&gt;/dev/mapper&lt;/b&gt;/</property>
                     <property name="hexpand">True</property>
                     <property name="invisible_char">â</property>
                     <property name="invisible_char_set">True</property>
@@ -164,7 +191,6 @@
                     <property name="can_focus">True</property>
                     <property name="has_tooltip">True</property>
                     <property name="tooltip_markup" translatable="yes">Options to use when unlocking the device</property>
-                    <property name="tooltip_text" translatable="yes">Options to use when unlocking the device</property>
                     <property name="hexpand">True</property>
                     <property name="invisible_char">â</property>
                     <property name="invisible_char_set">True</property>
@@ -234,7 +260,6 @@
                     <property name="can_focus">True</property>
                     <property name="has_tooltip">True</property>
                     <property name="tooltip_markup" translatable="yes">Passphrase of the device or empty to request from user when setting up the device</property>
-                    <property name="tooltip_text" translatable="yes">Passphrase of the device or empty to request from user when setting up the device</property>
                     <property name="hexpand">True</property>
                     <property name="invisible_char">â</property>
                     <property name="invisible_char_set">True</property>
@@ -281,9 +306,9 @@
                         <property name="has_tooltip">True</property>
                         <property name="tooltip_markup" translatable="yes">If checked, the device will be unlocked at startup [!noauto]</property>
                         <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
-                        <property name="use_underline">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -301,11 +326,10 @@
                         <property name="receives_default">False</property>
                         <property name="has_tooltip">True</property>
                         <property name="tooltip_markup" translatable="yes">If checked, additional authorization is required to unlock the device [x-udisks-auth]</property>
-                        <property name="tooltip_text" translatable="yes">If checked, additional authorization is required to unlock the device [x-udisks-auth]</property>
                         <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
-                        <property name="use_underline">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -332,25 +356,6 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLinkButton" id="linkbutton2">
-                <property name="label" translatable="yes">What's this?</property>
-                <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="has_tooltip">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="relief">none</property>
-                <property name="xalign">0</property>
-                <property name="uri">man:crypttab</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
                 <property name="position">2</property>
               </packing>
             </child>
@@ -366,7 +371,6 @@
     <action-widgets>
       <action-widget response="0">crypttab-cancel-button</action-widget>
       <action-widget response="-5">crypttab-ok-button</action-widget>
-      <action-widget response="1">crypttab-reset-button</action-widget>
     </action-widgets>
   </object>
 </interface>
diff --git a/data/ui/edit-fstab-dialog.ui b/data/ui/edit-fstab-dialog.ui
index 97336e0..87af8c1 100644
--- a/data/ui/edit-fstab-dialog.ui
+++ b/data/ui/edit-fstab-dialog.ui
@@ -14,11 +14,11 @@
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child>
-          <object class="GtkBox" id="box2">
+          <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>
+            <property name="spacing">6</property>
             <child>
               <object class="GtkBox" id="fstab-infobar-hbox">
                 <property name="visible">True</property>
@@ -34,9 +34,52 @@
               </packing>
             </child>
             <child>
+              <object class="GtkBox" id="box3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="spacing">12</property>
+                <child>
+                  <object class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="label" translatable="yes">Automatic Mount Options</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                      <attribute name="scale" value="1"/>
+                    </attributes>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSwitch" id="automatic-mount-options-switch">
+                    <property name="use_action_appearance">False</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="tooltip_markup" translatable="yes">Switch off &lt;i&gt;Automatic Mount Options&lt;/i&gt; to manage mount point and mount options for the device. The options correspond to an entry in the &lt;b&gt;/etc/fstab&lt;/b&gt; file</property>
+                    <property name="use_action_appearance">False</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="position">1</property>
+              </packing>
+            </child>
+            <child>
               <object class="GtkGrid" id="fstab-grid">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="margin_left">24</property>
                 <property name="row_spacing">10</property>
                 <property name="column_spacing">6</property>
                 <child>
@@ -250,9 +293,9 @@
                         <property name="tooltip_markup" translatable="yes">If checked, the device is always shown in the user interface no matter what its directory is [x-gvfs-show]</property>
                         <property name="tooltip_text" translatable="yes">If checked, the device is always shown in the user interface no matter what its directory is [x-gvfs-show]</property>
                         <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
-                        <property name="use_underline">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -272,9 +315,9 @@
                         <property name="tooltip_markup" translatable="yes">If checked, additional authorization is required to mount the device [x-udisks-auth]</property>
                         <property name="tooltip_text" translatable="yes">If checked, additional authorization is required to mount the device [x-udisks-auth]</property>
                         <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
-                        <property name="use_underline">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -293,9 +336,9 @@
                         <property name="has_tooltip">True</property>
                         <property name="tooltip_markup" translatable="yes">If checked, the device will be mounted at startup [!noauto]</property>
                         <property name="use_action_appearance">False</property>
+                        <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
-                        <property name="use_underline">True</property>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -358,25 +401,6 @@
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkLinkButton" id="linkbutton1">
-                <property name="label" translatable="yes">What's this?</property>
-                <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="has_tooltip">True</property>
-                <property name="use_action_appearance">False</property>
-                <property name="relief">none</property>
-                <property name="xalign">0</property>
-                <property name="uri">man:fstab</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
                 <property name="position">2</property>
               </packing>
             </child>
@@ -413,9 +437,8 @@
                 <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
                 <property name="can_default">True</property>
-                <property name="tooltip_markup" translatable="yes">Click to create or update entry in the &lt;b&gt;/etc/fstab&lt;/b&gt; file</property>
+                <property name="receives_default">True</property>
                 <property name="use_action_appearance">False</property>
                 <property name="use_stock">True</property>
               </object>
@@ -425,23 +448,6 @@
                 <property name="position">1</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkButton" id="fstab-button-reset">
-                <property name="label" translatable="yes">Reset</property>
-                <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="tooltip_markup" translatable="yes">Click to remove the entry from the &lt;b&gt;/etc/fstab&lt;/b&gt; file</property>
-                <property name="use_action_appearance">False</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
-                <property name="secondary">True</property>
-              </packing>
-            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -455,7 +461,6 @@
     <action-widgets>
       <action-widget response="-6">fstab-button-cancel</action-widget>
       <action-widget response="-5">fstab-button-ok</action-widget>
-      <action-widget response="1">fstab-button-reset</action-widget>
     </action-widgets>
   </object>
   <object class="GtkAdjustment" id="fstab-freq-adjustment">
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index 4d45b79..c4e03cf 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -172,7 +172,7 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="use_action_appearance">False</property>
-        <property name="label" translatable="yes">Edit Crypt Options...</property>
+        <property name="label" translatable="yes">Edit Encryption Options...</property>
         <property name="use_underline">True</property>
       </object>
     </child>
diff --git a/src/palimpsest/gducrypttabdialog.c b/src/palimpsest/gducrypttabdialog.c
index a5a8139..89957ae 100644
--- a/src/palimpsest/gducrypttabdialog.c
+++ b/src/palimpsest/gducrypttabdialog.c
@@ -45,7 +45,7 @@ typedef struct
   GtkWidget *infobar_vbox;
   GtkWidget *passphrase_warning_infobar;
 
-  GtkWidget *reset_button;
+  GtkWidget *automatic_crypt_options_switch;
   GtkWidget *grid;
 
   GtkWidget *name_entry;
@@ -81,10 +81,11 @@ static void
 update (CrypttabDialogData *data,
         GtkWidget          *widget)
 {
+  gboolean ui_configured;
+  gboolean configured;
   const gchar *ui_name;
   const gchar *ui_options;
   const gchar *ui_passphrase_contents;
-  gboolean configured;
   const gchar *name;
   const gchar *passphrase_path;
   const gchar *passphrase_contents;
@@ -113,6 +114,7 @@ update (CrypttabDialogData *data,
   ui_name = gtk_entry_get_text (GTK_ENTRY (data->name_entry));
   ui_options = gtk_entry_get_text (GTK_ENTRY (data->options_entry));
   ui_passphrase_contents = gtk_entry_get_text (GTK_ENTRY (data->passphrase_entry));
+  ui_configured = !gtk_switch_get_active (GTK_SWITCH (data->automatic_crypt_options_switch));
 
   if (!configured)
     {
@@ -158,15 +160,25 @@ update (CrypttabDialogData *data,
   g_object_thaw_notify (G_OBJECT (data->options_entry));
 
   can_ok = FALSE;
-  if (g_strcmp0 (ui_name, name) != 0 ||
-      g_strcmp0 (ui_options, options) != 0 ||
-      g_strcmp0 (ui_passphrase_contents, passphrase_contents) != 0)
+  if (configured != ui_configured)
     {
       can_ok = TRUE;
     }
+  else if (ui_configured)
+    {
+      if (g_strcmp0 (ui_name, name) != 0 ||
+          g_strcmp0 (ui_options, options) != 0 ||
+          g_strcmp0 (ui_passphrase_contents, passphrase_contents) != 0)
+        {
+          can_ok = TRUE;
+        }
+    }
+
   gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog),
                                      GTK_RESPONSE_OK,
                                      can_ok);
+
+  gtk_widget_set_sensitive (data->grid, ui_configured);
 }
 
 static void
@@ -216,6 +228,8 @@ crypttab_dialog_present (CrypttabDialogData *data)
                           "visibility",
                           G_BINDING_SYNC_CREATE);
 
+  g_signal_connect (data->automatic_crypt_options_switch,
+                    "notify::active", G_CALLBACK (on_property_changed), data);
   g_signal_connect (data->name_entry,
                     "notify::text", G_CALLBACK (on_property_changed), data);
   g_signal_connect (data->options_entry,
@@ -227,136 +241,141 @@ crypttab_dialog_present (CrypttabDialogData *data)
   g_signal_connect (data->passphrase_entry,
                     "notify::text", G_CALLBACK (on_property_changed), data);
 
+  gtk_switch_set_active (GTK_SWITCH (data->automatic_crypt_options_switch), !configured);
   gtk_widget_show_all (data->dialog);
 
-  /* Show "Reset" button only if already configured */
-  if (!configured)
-    gtk_widget_hide (data->reset_button);
-
   update (data, NULL);
 
   response = gtk_dialog_run (GTK_DIALOG (data->dialog));
 
-  if (response == 1) /* application-defined for "crypttab-button-reset" */
+  if (response == GTK_RESPONSE_OK)
     {
+      gboolean configured;
+      gboolean ui_configured;
       GError *error;
 
-      error = NULL;
-      if (!udisks_block_call_remove_configuration_item_sync (data->block,
-                                                             g_variant_new ("(s a{sv})", "crypttab",
-                                                                            data->orig_crypttab_entry),
-                                                             g_variant_new ("a{sv}", NULL), /* options */
-                                                             NULL, /* GCancellable */
-                                                             &error))
-        {
-          gdu_window_show_error (data->window,
-                                 _("Error removing /etc/crypttab entry"),
-                                 error);
-          g_error_free (error);
-          goto out;
-        }
-    }
-  else if (response == GTK_RESPONSE_OK)
-    {
-      const gchar *ui_name;
-      const gchar *ui_options;
-      const gchar *ui_passphrase_contents;
-      const gchar *old_passphrase_path;
-      GError *error;
-      GVariant *old_item = NULL;
-      GVariant *new_item = NULL;
-      GVariantBuilder builder;
-      gchar *s;
-
-      ui_name = gtk_entry_get_text (GTK_ENTRY (data->name_entry));
-      ui_options = gtk_entry_get_text (GTK_ENTRY (data->options_entry));
-      ui_passphrase_contents = gtk_entry_get_text (GTK_ENTRY (data->passphrase_entry));
-
-      gtk_widget_hide (data->dialog);
+      configured = (data->orig_crypttab_entry != NULL);
+      ui_configured = !gtk_switch_get_active (GTK_SWITCH (data->automatic_crypt_options_switch));
 
-      old_passphrase_path = NULL;
-      if (data->orig_crypttab_entry != NULL)
+      if (configured && !ui_configured)
         {
-          const gchar *s;
-          if (g_variant_lookup (data->orig_crypttab_entry, "passphrase-path", "^&ay", &s))
+          error = NULL;
+          if (!udisks_block_call_remove_configuration_item_sync (data->block,
+                                                                 g_variant_new ("(s a{sv})", "crypttab",
+                                                                                data->orig_crypttab_entry),
+                                                                 g_variant_new ("a{sv}", NULL), /* options */
+                                                                 NULL, /* GCancellable */
+                                                                 &error))
             {
-              if (strlen (s) > 0 && !g_str_has_prefix (s, "/dev"))
-                old_passphrase_path = s;
+              gdu_window_show_error (data->window,
+                                     _("Error removing /etc/crypttab entry"),
+                                     error);
+              g_error_free (error);
+              goto out;
             }
-          error = NULL;
-          old_item = g_variant_new ("(s a{sv})", "crypttab",
-                                    data->orig_crypttab_entry);
         }
-
-      g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
-      s = g_strdup_printf ("UUID=%s", udisks_block_get_id_uuid (data->block));
-      g_variant_builder_add (&builder, "{sv}", "device", g_variant_new_bytestring (s));
-      g_free (s);
-      g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_bytestring (ui_name));
-      g_variant_builder_add (&builder, "{sv}", "options", g_variant_new_bytestring (ui_options));
-      if (strlen (ui_passphrase_contents) > 0)
+      else
         {
-          /* use old/existing passphrase file, if available */
-          if (old_passphrase_path != NULL)
+          const gchar *ui_name;
+          const gchar *ui_options;
+          const gchar *ui_passphrase_contents;
+          const gchar *old_passphrase_path;
+          GError *error;
+          GVariant *old_item = NULL;
+          GVariant *new_item = NULL;
+          GVariantBuilder builder;
+          gchar *s;
+
+          ui_name = gtk_entry_get_text (GTK_ENTRY (data->name_entry));
+          ui_options = gtk_entry_get_text (GTK_ENTRY (data->options_entry));
+          ui_passphrase_contents = gtk_entry_get_text (GTK_ENTRY (data->passphrase_entry));
+
+          gtk_widget_hide (data->dialog);
+
+          old_passphrase_path = NULL;
+          if (data->orig_crypttab_entry != NULL)
             {
-              g_variant_builder_add (&builder, "{sv}", "passphrase-path",
-                                     g_variant_new_bytestring (old_passphrase_path));
+              const gchar *s;
+              if (g_variant_lookup (data->orig_crypttab_entry, "passphrase-path", "^&ay", &s))
+                {
+                  if (strlen (s) > 0 && !g_str_has_prefix (s, "/dev"))
+                    old_passphrase_path = s;
+                }
+              error = NULL;
+              old_item = g_variant_new ("(s a{sv})", "crypttab",
+                                        data->orig_crypttab_entry);
+            }
+
+          g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
+          s = g_strdup_printf ("UUID=%s", udisks_block_get_id_uuid (data->block));
+          g_variant_builder_add (&builder, "{sv}", "device", g_variant_new_bytestring (s));
+          g_free (s);
+          g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_bytestring (ui_name));
+          g_variant_builder_add (&builder, "{sv}", "options", g_variant_new_bytestring (ui_options));
+          if (strlen (ui_passphrase_contents) > 0)
+            {
+              /* use old/existing passphrase file, if available */
+              if (old_passphrase_path != NULL)
+                {
+                  g_variant_builder_add (&builder, "{sv}", "passphrase-path",
+                                         g_variant_new_bytestring (old_passphrase_path));
+                }
+              else
+                {
+                  /* otherwise fall back to the requested name */
+                  s = g_strdup_printf ("/etc/luks-keys/%s", ui_name);
+                  g_variant_builder_add (&builder, "{sv}", "passphrase-path", g_variant_new_bytestring (s));
+                  g_free (s);
+                }
+              g_variant_builder_add (&builder, "{sv}", "passphrase-contents",
+                                     g_variant_new_bytestring (ui_passphrase_contents));
             }
           else
             {
-              /* otherwise fall back to the requested name */
-              s = g_strdup_printf ("/etc/luks-keys/%s", ui_name);
-              g_variant_builder_add (&builder, "{sv}", "passphrase-path", g_variant_new_bytestring (s));
-              g_free (s);
+              g_variant_builder_add (&builder, "{sv}", "passphrase-path",
+                                     g_variant_new_bytestring (""));
+              g_variant_builder_add (&builder, "{sv}", "passphrase-contents",
+                                     g_variant_new_bytestring (""));
             }
-          g_variant_builder_add (&builder, "{sv}", "passphrase-contents",
-                                 g_variant_new_bytestring (ui_passphrase_contents));
-        }
-      else
-        {
-          g_variant_builder_add (&builder, "{sv}", "passphrase-path",
-                                 g_variant_new_bytestring (""));
-          g_variant_builder_add (&builder, "{sv}", "passphrase-contents",
-                                 g_variant_new_bytestring (""));
-        }
-      new_item = g_variant_new ("(sa{sv})", "crypttab", &builder);
+          new_item = g_variant_new ("(sa{sv})", "crypttab", &builder);
 
-      if (old_item == NULL && new_item != NULL)
-        {
-          error = NULL;
-          if (!udisks_block_call_add_configuration_item_sync (data->block,
-                                                              new_item,
-                                                              g_variant_new ("a{sv}", NULL), /* options */
-                                                              NULL, /* GCancellable */
-                                                              &error))
+          if (old_item == NULL && new_item != NULL)
             {
-              gdu_window_show_error (data->window,
-                                     _("Error adding /etc/crypttab entry"),
-                                     error);
-              g_error_free (error);
-              goto out;
+              error = NULL;
+              if (!udisks_block_call_add_configuration_item_sync (data->block,
+                                                                  new_item,
+                                                                  g_variant_new ("a{sv}", NULL), /* options */
+                                                                  NULL, /* GCancellable */
+                                                                  &error))
+                {
+                  gdu_window_show_error (data->window,
+                                         _("Error adding /etc/crypttab entry"),
+                                         error);
+                  g_error_free (error);
+                  goto out;
+                }
             }
-        }
-      else if (old_item != NULL && new_item != NULL)
-        {
-          error = NULL;
-          if (!udisks_block_call_update_configuration_item_sync (data->block,
-                                                                 old_item,
-                                                                 new_item,
-                                                                 g_variant_new ("a{sv}", NULL), /* options */
-                                                                 NULL, /* GCancellable */
-                                                                 &error))
+          else if (old_item != NULL && new_item != NULL)
             {
-              gdu_window_show_error (data->window,
-                                     _("Error updating /etc/crypttab entry"),
-                                     error);
-              g_error_free (error);
-              goto out;
+              error = NULL;
+              if (!udisks_block_call_update_configuration_item_sync (data->block,
+                                                                     old_item,
+                                                                     new_item,
+                                                                     g_variant_new ("a{sv}", NULL), /* options */
+                                                                     NULL, /* GCancellable */
+                                                                     &error))
+                {
+                  gdu_window_show_error (data->window,
+                                         _("Error updating /etc/crypttab entry"),
+                                         error);
+                  g_error_free (error);
+                  goto out;
+                }
+            }
+          else
+            {
+              g_assert_not_reached ();
             }
-        }
-      else
-        {
-          g_assert_not_reached ();
         }
     }
 
@@ -457,7 +476,7 @@ gdu_crypttab_dialog_show (GduWindow    *window,
 
   data->dialog = dialog;
   data->infobar_vbox = GTK_WIDGET (gtk_builder_get_object (data->builder, "infobar-vbox"));
-  data->reset_button = GTK_WIDGET (gtk_builder_get_object (data->builder, "crypttab-reset-button"));
+  data->automatic_crypt_options_switch = GTK_WIDGET (gtk_builder_get_object (data->builder, "automatic-crypt-options-switch"));
   data->grid = GTK_WIDGET (gtk_builder_get_object (data->builder, "crypttab-grid"));
   data->name_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "crypttab-name-entry"));
   data->options_entry = GTK_WIDGET (gtk_builder_get_object (data->builder, "crypttab-options-entry"));
diff --git a/src/palimpsest/gdufstabdialog.c b/src/palimpsest/gdufstabdialog.c
index a138ef7..dfde2b5 100644
--- a/src/palimpsest/gdufstabdialog.c
+++ b/src/palimpsest/gdufstabdialog.c
@@ -35,7 +35,7 @@
 typedef struct
 {
   GtkWidget *dialog;
-  GtkWidget *reset_button;
+  GtkWidget *automatic_mount_options_switch;
   GtkWidget *grid;
 
   GtkWidget *infobar_hbox;
@@ -58,6 +58,8 @@ static void
 update (FstabDialogData *data,
         GtkWidget       *widget)
 {
+  gboolean ui_configured;
+  gboolean configured;
   gchar *ui_fsname;
   const gchar *ui_dir;
   const gchar *ui_type;
@@ -70,6 +72,7 @@ update (FstabDialogData *data,
 
   if (data->orig_fstab_entry != NULL)
     {
+      configured = TRUE;
       g_variant_lookup (data->orig_fstab_entry, "fsname", "^&ay", &fsname);
       g_variant_lookup (data->orig_fstab_entry, "dir", "^&ay", &dir);
       g_variant_lookup (data->orig_fstab_entry, "type", "^&ay", &type);
@@ -77,6 +80,7 @@ update (FstabDialogData *data,
     }
   else
     {
+      configured = FALSE;
       fsname = "";
       dir = "";
       type = "";
@@ -87,6 +91,7 @@ update (FstabDialogData *data,
   ui_dir = gtk_entry_get_text (GTK_ENTRY (data->directory_entry));
   ui_type = gtk_entry_get_text (GTK_ENTRY (data->type_entry));
   ui_opts = gtk_entry_get_text (GTK_ENTRY (data->options_entry));
+  ui_configured = !gtk_switch_get_active (GTK_SWITCH (data->automatic_mount_options_switch));
 
   g_object_freeze_notify (G_OBJECT (data->options_entry));
   gdu_options_update_check_option (data->options_entry, "noauto", widget, data->neg_noauto_checkbutton, TRUE, FALSE);
@@ -97,23 +102,32 @@ update (FstabDialogData *data,
   g_object_thaw_notify (G_OBJECT (data->options_entry));
 
   can_ok = FALSE;
-  if (g_strcmp0 (ui_fsname, fsname) != 0 ||
-      g_strcmp0 (ui_dir, dir) != 0 ||
-      g_strcmp0 (ui_type, type) != 0 ||
-      g_strcmp0 (ui_opts, opts) != 0)
+  if (configured != ui_configured)
     {
       can_ok = TRUE;
     }
-
-  /* sanity-check and validate */
-  if (strlen (ui_fsname) == 0 ||
-      strlen (ui_dir) == 0 ||
-      strlen (ui_type) == 0 ||
-      strlen (ui_opts) == 0)
+  else if (ui_configured)
     {
-      can_ok = FALSE;
+      if (g_strcmp0 (ui_fsname, fsname) != 0 ||
+          g_strcmp0 (ui_dir, dir) != 0 ||
+          g_strcmp0 (ui_type, type) != 0 ||
+          g_strcmp0 (ui_opts, opts) != 0)
+        {
+          can_ok = TRUE;
+        }
+
+      /* sanity-check and validate */
+      if (strlen (ui_fsname) == 0 ||
+          strlen (ui_dir) == 0 ||
+          strlen (ui_type) == 0 ||
+          strlen (ui_opts) == 0)
+        {
+          can_ok = FALSE;
+        }
     }
 
+  gtk_widget_set_sensitive (data->grid, ui_configured);
+
   gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog),
                                      GTK_RESPONSE_OK,
                                      can_ok);
@@ -389,7 +403,7 @@ gdu_fstab_dialog_show (GduWindow    *window,
   memset (&data, '\0', sizeof (FstabDialogData));
   data.dialog = dialog;
   data.infobar_hbox = GTK_WIDGET (gtk_builder_get_object (builder, "fstab-infobar-hbox"));
-  data.reset_button = GTK_WIDGET (gtk_builder_get_object (builder, "fstab-button-reset"));
+  data.automatic_mount_options_switch = GTK_WIDGET (gtk_builder_get_object (builder, "automatic-mount-options-switch"));
   data.grid = GTK_WIDGET (gtk_builder_get_object (builder, "fstab-grid"));
   data.device_combobox = GTK_WIDGET (gtk_builder_get_object (builder, "fstab-device-combobox"));
   data.device_explanation_label = GTK_WIDGET (gtk_builder_get_object (builder, "fstab-device-explanation-label"));
@@ -461,15 +475,14 @@ gdu_fstab_dialog_show (GduWindow    *window,
       gtk_box_pack_start (GTK_BOX (data.infobar_hbox), bar, TRUE, TRUE, 0);
     }
 
+  gtk_switch_set_active (GTK_SWITCH (data.automatic_mount_options_switch), !configured);
   gtk_widget_show_all (dialog);
 
-  /* Show "Reset" button only if already configured */
-  if (!configured)
-    gtk_widget_hide (data.reset_button);
-
   update_device_explanation (&data);
   update (&data, NULL);
 
+  g_signal_connect (data.automatic_mount_options_switch,
+                    "notify::active", G_CALLBACK (on_property_changed), &data);
   g_signal_connect (data.device_combobox,
                     "notify::active", G_CALLBACK (on_property_changed), &data);
   g_signal_connect (data.directory_entry,
@@ -492,101 +505,106 @@ gdu_fstab_dialog_show (GduWindow    *window,
                     "notify::text", G_CALLBACK (on_property_changed), &data);
 
   response = gtk_dialog_run (GTK_DIALOG (dialog));
-  if (response == 1) /* application-defined for "fstab-button-reset" */
+  if (response == GTK_RESPONSE_OK)
     {
+      gboolean ui_configured;
       GError *error;
 
-      error = NULL;
-      if (!udisks_block_call_remove_configuration_item_sync (block,
-                                                             g_variant_new ("(s a{sv})", "fstab", data.orig_fstab_entry),
-                                                             g_variant_new ("a{sv}", NULL), /* options */
-                                                             NULL, /* GCancellable */
-                                                             &error))
-        {
-          gdu_window_show_error (window,
-                                 _("Error removing old /etc/fstab entry"),
-                                 error);
-          g_error_free (error);
-          goto out;
-        }
-    }
-  else if (response == GTK_RESPONSE_OK)
-    {
-      gchar *ui_fsname;
-      const gchar *ui_dir;
-      const gchar *ui_type;
-      const gchar *ui_opts;
-      gint freq = 0;
-      gint passno = 0;
-      GError *error;
-      GVariant *old_item = NULL;
-      GVariant *new_item = NULL;
-      GVariantBuilder builder;
-
-      ui_fsname = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (data.device_combobox));
-      ui_dir = gtk_entry_get_text (GTK_ENTRY (data.directory_entry));
-      ui_type = gtk_entry_get_text (GTK_ENTRY (data.type_entry));
-      ui_opts = gtk_entry_get_text (GTK_ENTRY (data.options_entry));
-      if (data.orig_fstab_entry != NULL)
-        {
-          g_variant_lookup (data.orig_fstab_entry, "freq", "i", &freq);
-          g_variant_lookup (data.orig_fstab_entry, "passno", "i", &passno);
-        }
+      ui_configured = !gtk_switch_get_active (GTK_SWITCH (data.automatic_mount_options_switch));
 
-      gtk_widget_hide (dialog);
-
-      if (data.orig_fstab_entry != NULL)
-        old_item = g_variant_new ("(s a{sv})", "fstab", data.orig_fstab_entry);
-
-      g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
-      g_variant_builder_add (&builder, "{sv}", "fsname", g_variant_new_bytestring (ui_fsname));
-      g_variant_builder_add (&builder, "{sv}", "dir", g_variant_new_bytestring (ui_dir));
-      g_variant_builder_add (&builder, "{sv}", "type", g_variant_new_bytestring (ui_type));
-      g_variant_builder_add (&builder, "{sv}", "opts", g_variant_new_bytestring (ui_opts));
-      g_variant_builder_add (&builder, "{sv}", "freq", g_variant_new_int32 (freq));
-      g_variant_builder_add (&builder, "{sv}", "passno", g_variant_new_int32 (passno));
-      new_item = g_variant_new ("(sa{sv})", "fstab", &builder);
-
-      if (old_item == NULL && new_item != NULL)
-        {
-          error = NULL;
-          if (!udisks_block_call_add_configuration_item_sync (block,
-                                                                     new_item,
-                                                                     g_variant_new ("a{sv}", NULL), /* options */
-                                                                     NULL, /* GCancellable */
-                                                                     &error))
-            {
-              gdu_window_show_error (window,
-                                     _("Error adding new /etc/fstab entry"),
-                                     error);
-              g_error_free (error);
-              g_free (ui_fsname);
-              goto out;
-            }
-        }
-      else if (old_item != NULL && new_item != NULL)
+      if (configured && !ui_configured)
         {
           error = NULL;
-          if (!udisks_block_call_update_configuration_item_sync (block,
-                                                                 old_item,
-                                                                 new_item,
+          if (!udisks_block_call_remove_configuration_item_sync (block,
+                                                                 g_variant_new ("(s a{sv})", "fstab", data.orig_fstab_entry),
                                                                  g_variant_new ("a{sv}", NULL), /* options */
                                                                  NULL, /* GCancellable */
                                                                  &error))
             {
               gdu_window_show_error (window,
-                                     _("Error updating /etc/fstab entry"),
+                                     _("Error removing old /etc/fstab entry"),
                                      error);
               g_error_free (error);
-              g_free (ui_fsname);
               goto out;
             }
         }
       else
         {
-          g_assert_not_reached ();
+          gchar *ui_fsname;
+          const gchar *ui_dir;
+          const gchar *ui_type;
+          const gchar *ui_opts;
+          gint freq = 0;
+          gint passno = 0;
+          GVariant *old_item = NULL;
+          GVariant *new_item = NULL;
+          GVariantBuilder builder;
+
+          ui_fsname = gtk_combo_box_text_get_active_text (GTK_COMBO_BOX_TEXT (data.device_combobox));
+          ui_dir = gtk_entry_get_text (GTK_ENTRY (data.directory_entry));
+          ui_type = gtk_entry_get_text (GTK_ENTRY (data.type_entry));
+          ui_opts = gtk_entry_get_text (GTK_ENTRY (data.options_entry));
+          if (data.orig_fstab_entry != NULL)
+            {
+              g_variant_lookup (data.orig_fstab_entry, "freq", "i", &freq);
+              g_variant_lookup (data.orig_fstab_entry, "passno", "i", &passno);
+            }
+
+          gtk_widget_hide (dialog);
+
+          if (data.orig_fstab_entry != NULL)
+            old_item = g_variant_new ("(s a{sv})", "fstab", data.orig_fstab_entry);
+
+          g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
+          g_variant_builder_add (&builder, "{sv}", "fsname", g_variant_new_bytestring (ui_fsname));
+          g_variant_builder_add (&builder, "{sv}", "dir", g_variant_new_bytestring (ui_dir));
+          g_variant_builder_add (&builder, "{sv}", "type", g_variant_new_bytestring (ui_type));
+          g_variant_builder_add (&builder, "{sv}", "opts", g_variant_new_bytestring (ui_opts));
+          g_variant_builder_add (&builder, "{sv}", "freq", g_variant_new_int32 (freq));
+          g_variant_builder_add (&builder, "{sv}", "passno", g_variant_new_int32 (passno));
+          new_item = g_variant_new ("(sa{sv})", "fstab", &builder);
+
+          if (old_item == NULL && new_item != NULL)
+            {
+              error = NULL;
+              if (!udisks_block_call_add_configuration_item_sync (block,
+                                                                  new_item,
+                                                                  g_variant_new ("a{sv}", NULL), /* options */
+                                                                  NULL, /* GCancellable */
+                                                                  &error))
+                {
+                  gdu_window_show_error (window,
+                                         _("Error adding new /etc/fstab entry"),
+                                         error);
+                  g_error_free (error);
+                  g_free (ui_fsname);
+                  goto out;
+                }
+            }
+          else if (old_item != NULL && new_item != NULL)
+            {
+              error = NULL;
+              if (!udisks_block_call_update_configuration_item_sync (block,
+                                                                     old_item,
+                                                                     new_item,
+                                                                     g_variant_new ("a{sv}", NULL), /* options */
+                                                                     NULL, /* GCancellable */
+                                                                     &error))
+                {
+                  gdu_window_show_error (window,
+                                         _("Error updating /etc/fstab entry"),
+                                         error);
+                  g_error_free (error);
+                  g_free (ui_fsname);
+                  goto out;
+                }
+            }
+          else
+            {
+              g_assert_not_reached ();
+            }
+          g_free (ui_fsname);
         }
-      g_free (ui_fsname);
     }
 
  out:



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