[virt-tools-list] [virt-manager PATCH v2] [RFC] Make deleting storage files default with added prompt

Martin Kletzander mkletzan at redhat.com
Mon Dec 3 16:12:59 UTC 2012


This patch changes the default checkbox-state of "Delete all
associated storage" to be checked, but adds a prompt with a warning
for users to be sure they notice this change and they know what they
are doing (hopefully).
---
I tried playing with this and it works, but unfortunately after the
configuration gets changed few times.  I haven't tried on a clean
machine, so it maybe a problem of some old schemas being stuck in
there.  Feel free to correct my thoughts and patch.

v2:
 - there is no configuration for what the default state should be,
   it's changed to 'checked' by default, but there is a prompt added

 src/virt-manager.schemas.in    | 13 +++++++++++++
 src/virtManager/config.py      |  8 +++++++-
 src/virtManager/delete.py      | 12 ++++++++++--
 src/virtManager/preferences.py | 11 ++++++++++-
 src/vmm-preferences.ui         | 30 ++++++++++++++++++++++++++++++
 5 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/src/virt-manager.schemas.in b/src/virt-manager.schemas.in
index 8154534..dc11187 100644
--- a/src/virt-manager.schemas.in
+++ b/src/virt-manager.schemas.in
@@ -378,6 +378,19 @@
     </schema>

     <schema>
+      <key>/schemas/apps/::PACKAGE::/confirm/delete_storage</key>
+      <applyto>/apps/::PACKAGE::/confirm/delete_storage</applyto>
+      <owner>::PACKAGE::</owner>
+      <type>bool</type>
+      <default>1</default>
+
+      <locale name="C">
+        <short>Confirm deleting storage</short>
+        <long>Whether we require a confirmation on deleting storage</long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/::PACKAGE::/manager_window_height</key>
       <applyto>/apps/::PACKAGE::/manager_window_height</applyto>
       <owner>::PACKAGE::</owner>
diff --git a/src/virtManager/config.py b/src/virtManager/config.py
index 508fea0..21fc616 100644
--- a/src/virtManager/config.py
+++ b/src/virtManager/config.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006 Red Hat, Inc.
+# Copyright (C) 2006, 2012 Red Hat, Inc.
 # Copyright (C) 2006 Daniel P. Berrange <berrange at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -375,6 +375,8 @@ class vmmConfig(object):
         return self.conf.get_bool(self.conf_dir + "/confirm/interface_power")
     def get_confirm_unapplied(self):
         return self.conf.get_bool(self.conf_dir + "/confirm/unapplied_dev")
+    def get_confirm_delstorage(self):
+        return self.conf.get_bool(self.conf_dir + "/confirm/delete_storage")


     def set_confirm_forcepoweroff(self, val):
@@ -389,6 +391,8 @@ class vmmConfig(object):
         self.conf.set_bool(self.conf_dir + "/confirm/interface_power", val)
     def set_confirm_unapplied(self, val):
         self.conf.set_bool(self.conf_dir + "/confirm/unapplied_dev", val)
+    def set_confirm_delstorage(self, val):
+        self.conf.set_bool(self.conf_dir + "/confirm/delete_storage", val)

     def on_confirm_forcepoweroff_changed(self, cb):
         return self.conf.notify_add(self.conf_dir + "/confirm/forcepoweroff", cb)
@@ -402,6 +406,8 @@ class vmmConfig(object):
         return self.conf.notify_add(self.conf_dir + "/confirm/interface_power", cb)
     def on_confirm_unapplied_changed(self, cb):
         return self.conf.notify_add(self.conf_dir + "/confirm/unapplied_dev", cb)
+    def on_confirm_delstorage_changed(self, cb):
+        return self.conf.notify_add(self.conf_dir + "/confirm/delete_storage", cb)


     # System tray visibility
diff --git a/src/virtManager/delete.py b/src/virtManager/delete.py
index 9b7d08a..493ef96 100644
--- a/src/virtManager/delete.py
+++ b/src/virtManager/delete.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2009 Red Hat, Inc.
+# Copyright (C) 2009, 2012 Red Hat, Inc.
 # Copyright (C) 2009 Cole Robinson <crobinso at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -96,7 +96,7 @@ class vmmDeleteDialog(vmmGObjectUI):
         self.widget("delete-cancel").grab_focus()

         # Disable storage removal by default
-        self.widget("delete-remove-storage").set_active(False)
+        self.widget("delete-remove-storage").set_active(True)
         self.widget("delete-remove-storage").toggled()

         populate_storage_list(self.widget("delete-storage-list"),
@@ -125,6 +125,14 @@ class vmmDeleteDialog(vmmGObjectUI):
     def finish(self, src_ignore):
         devs = self.get_paths_to_delete()

+        if devs and not util.chkbox_helper(self, self.config.get_confirm_delstorage,
+                                           self.config.set_confirm_delstorage,
+                                           text1=_("Are you sure you want to delete "
+                                                   "all the storage?"),
+                                           text2=_("This will delete all selected "
+                                                   "storage data.")):
+            return
+
         self.topwin.set_sensitive(False)
         self.topwin.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))

diff --git a/src/virtManager/preferences.py b/src/virtManager/preferences.py
index 0eaf20b..c449f50 100644
--- a/src/virtManager/preferences.py
+++ b/src/virtManager/preferences.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006 Red Hat, Inc.
+# Copyright (C) 2006, 2012 Red Hat, Inc.
 # Copyright (C) 2006 Daniel P. Berrange <berrange at redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
@@ -49,6 +49,7 @@ class vmmPreferences(vmmGObjectUI):
         self.add_gconf_handle(self.config.on_confirm_removedev_changed(self.refresh_confirm_removedev))
         self.add_gconf_handle(self.config.on_confirm_interface_changed(self.refresh_confirm_interface))
         self.add_gconf_handle(self.config.on_confirm_unapplied_changed(self.refresh_confirm_unapplied))
+        self.add_gconf_handle(self.config.on_confirm_delstorage_changed(self.refresh_confirm_delstorage))

         self.refresh_view_system_tray()
         self.refresh_update_interval()
@@ -68,6 +69,7 @@ class vmmPreferences(vmmGObjectUI):
         self.refresh_confirm_removedev()
         self.refresh_confirm_interface()
         self.refresh_confirm_unapplied()
+        self.refresh_confirm_delstorage()

         self.window.connect_signals({
             "on_prefs_system_tray_toggled" : self.change_view_system_tray,
@@ -88,6 +90,7 @@ class vmmPreferences(vmmGObjectUI):
             "on_prefs_confirm_removedev_toggled": self.change_confirm_removedev,
             "on_prefs_confirm_interface_toggled": self.change_confirm_interface,
             "on_prefs_confirm_unapplied_toggled": self.change_confirm_unapplied,
+            "on_prefs_confirm_delstorage_toggled": self.change_confirm_delstorage,
             "on_prefs_btn_keys_define_clicked": self.change_grab_keys,
             "on_prefs_graphics_type_changed": self.change_graphics_type,
             "on_prefs_storage_format_changed": self.change_storage_format,
@@ -233,6 +236,10 @@ class vmmPreferences(vmmGObjectUI):
                                   ignore3=None, ignore4=None):
         self.widget("prefs-confirm-unapplied").set_active(
                                 self.config.get_confirm_unapplied())
+    def refresh_confirm_delstorage(self, ignore1=None, ignore2=None,
+                                   ignore3=None, ignore4=None):
+        self.widget("prefs-confirm-delstorage").set_active(
+                                self.config.get_confirm_delstorage())

     def grabkeys_get_string(self, events):
         keystr = ""
@@ -324,6 +331,8 @@ class vmmPreferences(vmmGObjectUI):
         self.config.set_confirm_interface(src.get_active())
     def change_confirm_unapplied(self, src):
         self.config.set_confirm_unapplied(src.get_active())
+    def change_confirm_delstorage(self, src):
+        self.config.set_confirm_delstorage(src.get_active())

     def change_graphics_type(self, src):
         gtype = 'vnc'
diff --git a/src/vmm-preferences.ui b/src/vmm-preferences.ui
index 6cc3916..dd9b3ab 100644
--- a/src/vmm-preferences.ui
+++ b/src/vmm-preferences.ui
@@ -935,6 +935,36 @@
                                 <property name="bottom_attach">6</property>
                               </packing>
                             </child>
+
+                            <child>
+                              <object class="GtkLabel" id="label66">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">Deleting storage:</property>
+                              </object>
+                              <packing>
+                                <property name="top_attach">7</property>
+                                <property name="bottom_attach">8</property>
+                                <property name="x_options">GTK_FILL</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkCheckButton" id="prefs-confirm-delstorage">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_action_appearance">False</property>
+                                <property name="draw_indicator">True</property>
+                                <signal name="toggled" handler="on_prefs_confirm_delstorage_toggled" swapped="no"/>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                                <property name="top_attach">7</property>
+                                <property name="bottom_attach">8</property>
+                              </packing>
+                            </child>
                           </object>
                         </child>
                       </object>
--
1.8.0




More information about the virt-tools-list mailing list