[gnome-disk-utility] Add a "Auto-clear" switch for loop devices



commit 447dd06544601bb5c27b7c3400d2a8b516f2f7da
Author: David Zeuthen <davidz redhat com>
Date:   Tue May 1 00:08:55 2012 -0400

    Add a "Auto-clear" switch for loop devices
    
    Signed-off-by: David Zeuthen <davidz redhat com>

 data/ui/palimpsest.ui      |   65 +++++++++++++++++++++----
 src/palimpsest/gduwindow.c |  115 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 171 insertions(+), 9 deletions(-)
---
diff --git a/data/ui/palimpsest.ui b/data/ui/palimpsest.ui
index 100b28b..275a24d 100644
--- a/data/ui/palimpsest.ui
+++ b/data/ui/palimpsest.ui
@@ -947,7 +947,7 @@
                           <object class="GtkTable" id="devtab-table">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
-                            <property name="n_rows">6</property>
+                            <property name="n_rows">7</property>
                             <property name="n_columns">2</property>
                             <property name="column_spacing">10</property>
                             <child>
@@ -994,8 +994,8 @@
                                 </style>
                               </object>
                               <packing>
-                                <property name="top_attach">4</property>
-                                <property name="bottom_attach">5</property>
+                                <property name="top_attach">5</property>
+                                <property name="bottom_attach">6</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options"></property>
                                 <property name="y_padding">4</property>
@@ -1013,8 +1013,8 @@
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
-                                <property name="top_attach">4</property>
-                                <property name="bottom_attach">5</property>
+                                <property name="top_attach">5</property>
+                                <property name="bottom_attach">6</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options"></property>
                                 <property name="y_padding">4</property>
@@ -1068,8 +1068,8 @@
                                 </style>
                               </object>
                               <packing>
-                                <property name="top_attach">5</property>
-                                <property name="bottom_attach">6</property>
+                                <property name="top_attach">6</property>
+                                <property name="bottom_attach">7</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options"></property>
                                 <property name="y_padding">4</property>
@@ -1087,14 +1087,61 @@
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="right_attach">2</property>
-                                <property name="top_attach">5</property>
-                                <property name="bottom_attach">6</property>
+                                <property name="top_attach">6</property>
+                                <property name="bottom_attach">7</property>
+                                <property name="x_options">GTK_FILL</property>
+                                <property name="y_options"></property>
+                                <property name="y_padding">4</property>
+                              </packing>
+                            </child>
+
+                            <child>
+                              <object class="GtkLabel" id="devtab-loop-autoclear-label">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">1</property>
+                                <property name="label" translatable="yes">Auto-clear</property>
+                                <style>
+                                  <class name="dim-label"/>
+                                </style>
+                              </object>
+                              <packing>
+                                <property name="top_attach">4</property>
+                                <property name="bottom_attach">5</property>
                                 <property name="x_options">GTK_FILL</property>
                                 <property name="y_options"></property>
                                 <property name="y_padding">4</property>
                               </packing>
                             </child>
                             <child>
+                              <object class="GtkBox" id="devtab-loop-autoclear-switch-box">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <child>
+                                  <object class="GtkSwitch" id="devtab-loop-autoclear-switch">
+                                    <property name="use_action_appearance">False</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="use_action_appearance">False</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">True</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                                <property name="top_attach">4</property>
+                                <property name="bottom_attach">5</property>
+                                <property name="x_options">GTK_FILL</property>
+                                <property name="y_options"></property>
+                              </packing>
+                            </child>
+
+                            <child>
                               <object class="GtkLabel" id="devtab-partition-label">
                                 <property name="visible">True</property>
                                 <property name="can_focus">False</property>
diff --git a/src/palimpsest/gduwindow.c b/src/palimpsest/gduwindow.c
index 5ef3b31..41283ca 100644
--- a/src/palimpsest/gduwindow.c
+++ b/src/palimpsest/gduwindow.c
@@ -122,6 +122,8 @@ struct _GduWindow
   GtkWidget *generic_menu_item_create_volume_image;
   GtkWidget *generic_menu_item_restore_volume_image;
 
+  GtkWidget *devtab_loop_autoclear_switch;
+
   GHashTable *label_connections;
 };
 
@@ -161,6 +163,8 @@ static const struct {
   {G_STRUCT_OFFSET (GduWindow, devtab_action_deactivate_swap), "devtab-action-deactivate-swap"},
   {G_STRUCT_OFFSET (GduWindow, devtab_action_generic_drive), "devtab-action-generic-drive"},
 
+  {G_STRUCT_OFFSET (GduWindow, devtab_loop_autoclear_switch), "devtab-loop-autoclear-switch"},
+
   {G_STRUCT_OFFSET (GduWindow, generic_drive_menu), "generic-drive-menu"},
   {G_STRUCT_OFFSET (GduWindow, generic_drive_menu_item_create_disk_image), "generic-drive-menu-item-create-disk-image"},
   {G_STRUCT_OFFSET (GduWindow, generic_drive_menu_item_restore_disk_image), "generic-drive-menu-item-restore-disk-image"},
@@ -176,6 +180,7 @@ static const struct {
   {G_STRUCT_OFFSET (GduWindow, generic_menu_item_format_volume), "generic-menu-item-format-volume"},
   {G_STRUCT_OFFSET (GduWindow, generic_menu_item_create_volume_image), "generic-menu-item-create-volume-image"},
   {G_STRUCT_OFFSET (GduWindow, generic_menu_item_restore_volume_image), "generic-menu-item-restore-volume-image"},
+
   {0, NULL}
 };
 
@@ -273,6 +278,10 @@ static void on_generic_menu_item_create_volume_image (GtkMenuItem *menu_item,
 static void on_generic_menu_item_restore_volume_image (GtkMenuItem *menu_item,
                                                        gpointer   user_data);
 
+static void on_devtab_loop_autoclear_switch_notify_active (GObject    *object,
+                                                           GParamSpec *pspec,
+                                                           gpointer    user_data);
+
 G_DEFINE_TYPE (GduWindow, gdu_window, GTK_TYPE_APPLICATION_WINDOW);
 
 static void
@@ -1116,6 +1125,12 @@ gdu_window_constructed (GObject *object)
                     G_CALLBACK (on_generic_menu_item_restore_volume_image),
                     window);
 
+  /* loop's auto-clear switch */
+  g_signal_connect (window->devtab_loop_autoclear_switch,
+                    "notify::active",
+                    G_CALLBACK (on_devtab_loop_autoclear_switch_notify_active),
+                    window);
+
   g_idle_add (on_constructed_in_idle, g_object_ref (window));
 }
 
@@ -1307,6 +1322,27 @@ set_size (GduWindow      *window,
   g_free (s);
 }
 
+static void
+set_switch (GduWindow      *window,
+            const gchar    *key_label_id,
+            const gchar    *switch_box_id,
+            const gchar    *switch_id,
+            gboolean        active)
+{
+  GtkWidget *key_label;
+  GtkWidget *switch_box;
+  GtkWidget *switch_;
+
+  key_label = GTK_WIDGET (gtk_builder_get_object (window->builder, key_label_id));
+  switch_box = GTK_WIDGET (gtk_builder_get_object (window->builder, switch_box_id));
+  switch_ = GTK_WIDGET (gtk_builder_get_object (window->builder, switch_id));
+
+  gtk_switch_set_active (GTK_SWITCH (switch_), active);
+  gtk_widget_show (key_label);
+  gtk_widget_show (switch_box);
+  gtk_widget_show (switch_);
+}
+
 static GList *
 get_top_level_blocks_for_drive (GduWindow   *window,
                                 const gchar *drive_object_path)
@@ -1894,6 +1930,16 @@ update_device_page_for_block (GduWindow          *window,
                   "devtab-backing-file-value-label",
                   s, SET_MARKUP_FLAGS_NONE);
       g_free (s);
+
+#ifdef UDISKS_CHECK_VERSION
+# if UDISKS_CHECK_VERSION(1,97,0)
+      set_switch (window,
+                  "devtab-loop-autoclear-label",
+                  "devtab-loop-autoclear-switch-box",
+                  "devtab-loop-autoclear-switch",
+                  udisks_loop_get_autoclear (loop));
+# endif
+#endif
     }
 
   usage = udisks_block_get_id_usage (block);
@@ -2777,3 +2823,72 @@ on_devtab_action_deactivate_swap_activated (GtkAction *action, gpointer user_dat
 }
 
 /* ---------------------------------------------------------------------------------------------------- */
+
+#ifdef UDISKS_CHECK_VERSION
+# if UDISKS_CHECK_VERSION(1,97,0)
+
+static void
+loop_set_autoclear_cb (UDisksLoop      *loop,
+                       GAsyncResult    *res,
+                       gpointer         user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  GError *error;
+
+  /* in case of error, make sure the GtkSwitch:active corresponds to UDisksLoop:autoclear */
+  update_all (window);
+
+  error = NULL;
+  if (!udisks_loop_call_set_autoclear_finish (loop,
+                                              res,
+                                              &error))
+    {
+      gdu_window_show_error (window,
+                             _("Error setting autoclear flag"),
+                             error);
+      g_error_free (error);
+    }
+  g_object_unref (window);
+}
+# endif
+#endif
+
+static void
+on_devtab_loop_autoclear_switch_notify_active (GObject    *gobject,
+                                               GParamSpec *pspec,
+                                               gpointer    user_data)
+{
+  GduWindow *window = GDU_WINDOW (user_data);
+  UDisksObject *object;
+  UDisksLoop *loop;
+  gboolean sw_value;
+
+  object = gdu_volume_grid_get_selected_device (GDU_VOLUME_GRID (window->volume_grid));
+  g_assert (object != NULL);
+  loop = udisks_object_peek_loop (object);
+  if (loop == NULL)
+    {
+      g_warning ("current object is not a loop object");
+      goto out;
+    }
+
+  sw_value = !! gtk_switch_get_active (GTK_SWITCH (gobject));
+  if (sw_value != (!!udisks_loop_get_autoclear (loop)))
+    {
+#ifdef UDISKS_CHECK_VERSION
+# if UDISKS_CHECK_VERSION(1,97,0)
+      udisks_loop_call_set_autoclear (loop,
+                                      sw_value,
+                                      g_variant_new ("a{sv}", NULL), /* options */
+                                      NULL, /* cancellable */
+                                      (GAsyncReadyCallback) loop_set_autoclear_cb,
+                                      g_object_ref (window));
+# endif
+#endif
+    }
+
+ out:
+  ;
+}
+
+/* ---------------------------------------------------------------------------------------------------- */



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