[virt-tools-list] [PATCH] ui: allow to set an empty password for graphics

Giuseppe Scrivano gscrivano at gnu.org
Wed Jul 31 23:14:17 UTC 2013


Now when a password is used a check box must be explicitely selected.
This enable the possibility to set an empty password "".

Solves: https://bugzilla.redhat.com/show_bug.cgi?id=749718

Signed-off-by: Giuseppe Scrivano <gscrivano at gnu.org>
---
I have implemented the changes you reported, now the check box must be
selected to make clear that a password must be used.

The same control is performed in addhardware.py.

 ui/vmm-add-hardware.ui     | 60 +++++++++++++++++++++++++++++++++-------------
 ui/vmm-details.ui          | 38 +++++++++++++++++++++++++----
 virtManager/addhardware.py | 26 ++++++++++++++++----
 virtManager/details.py     | 37 ++++++++++++++++++++++++----
 virtManager/domain.py      |  2 +-
 5 files changed, 132 insertions(+), 31 deletions(-)

diff --git a/ui/vmm-add-hardware.ui b/ui/vmm-add-hardware.ui
index 88438af..ea4c3a9 100644
--- a/ui/vmm-add-hardware.ui
+++ b/ui/vmm-add-hardware.ui
@@ -1094,22 +1094,6 @@
                                           </packing>
                                         </child>
                                         <child>
-                                          <object class="GtkEntry" id="graphics-password">
-                                            <property name="visible">True</property>
-                                            <property name="can_focus">True</property>
-                                            <property name="visibility">False</property>
-                                            <property name="invisible_char">●</property>
-                                          </object>
-                                          <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="x_options">GTK_FILL</property>
-                                            <property name="y_options"/>
-                                          </packing>
-                                        </child>
-                                        <child>
                                           <object class="GtkAlignment" id="alignment160">
                                             <property name="visible">True</property>
                                             <property name="can_focus">False</property>
@@ -1402,12 +1386,54 @@
                                             <property name="y_options">GTK_FILL</property>
                                           </packing>
                                         </child>
+                                        <child>
+                                          <object class="GtkBox" id="graphics-password-box">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <child>
+                                              <object class="GtkCheckButton" id="graphics-password-chk">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="receives_default">False</property>
+                                                <property name="use_stock">True</property>
+                                                <property name="xalign">0</property>
+                                                <property name="draw_indicator">True</property>
+                                                <signal name="toggled" handler="on_graphics_use_password" swapped="no"/>
+                                              </object>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <object class="GtkEntry" id="graphics-password">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="visibility">False</property>
+                                                <property name="invisible_char">●</property>
+                                                <property name="invisible_char_set">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="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">5</property>
+                                            <property name="bottom_attach">6</property>
+                                          </packing>
+                                        </child>
                                       </object>
                                     </child>
                                   </object>
                                   <packing>
                                     <property name="expand">False</property>
-                                    <property name="fill">True</property>
+                                    <property name="fill">False</property>
                                     <property name="position">1</property>
                                   </packing>
                                 </child>
diff --git a/ui/vmm-details.ui b/ui/vmm-details.ui
index ee5bc45..a04be18 100644
--- a/ui/vmm-details.ui
+++ b/ui/vmm-details.ui
@@ -5419,12 +5419,40 @@ I/O:</property>
                                               </packing>
                                             </child>
                                             <child>
-                                              <object class="GtkEntry" id="gfx-password">
+                                              <object class="GtkHBox" id="gfx-password-box">
                                                 <property name="visible">True</property>
-                                                <property name="can_focus">True</property>
-                                                <property name="visibility">False</property>
-                                                <property name="invisible_char">●</property>
-                                                <signal name="changed" handler="on_vnc_password_changed" swapped="no"/>
+                                                <property name="can_focus">False</property>
+                                                <child>
+                                                  <object class="GtkCheckButton" id="gfx-use-password">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">False</property>
+                                                    <property name="use_stock">True</property>
+                                                    <property name="xalign">0</property>
+                                                    <property name="draw_indicator">True</property>
+                                                    <signal name="toggled" handler="on_vnc_use_password_toggled" swapped="no"/>
+                                                  </object>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">True</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <object class="GtkEntry" id="gfx-password">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="visibility">False</property>
+                                                    <property name="invisible_char">●</property>
+                                                    <property name="invisible_char_set">True</property>
+                                                    <signal name="changed" handler="on_vnc_password_changed" swapped="no"/>
+                                                  </object>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">True</property>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
                                               </object>
                                               <packing>
                                                 <property name="left_attach">1</property>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 76580dc..c2354b7 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -97,6 +97,7 @@ class vmmAddHardware(vmmGObjectUI):
             "on_graphics_type_changed": self.change_graphics_type,
             "on_graphics_port_auto_toggled": self.change_port_auto,
             "on_graphics_keymap_toggled": self.change_keymap,
+            "on_graphics_use_password": self.change_password_chk,
 
             "on_char_device_type_changed": self.change_char_device_type,
 
@@ -471,6 +472,8 @@ class vmmAddHardware(vmmGObjectUI):
         self.widget("graphics-address").set_active(False)
         self.widget("graphics-port-auto").set_active(True)
         self.widget("graphics-password").set_text("")
+        self.widget("graphics-password").set_sensitive(False)
+        self.widget("graphics-password-chk").set_active(False)
         self.widget("graphics-keymap").set_text("")
         self.widget("graphics-keymap-chk").set_active(True)
 
@@ -676,8 +679,9 @@ class vmmAddHardware(vmmGObjectUI):
         return "127.0.0.1"
 
     def get_config_graphics_password(self):
-        pw = self.widget("graphics-password")
-        return pw.get_text()
+        if not self.widget("graphics-password-chk").get_active():
+            return None
+        return self.widget("graphics-password").get_text()
 
     def get_config_keymap(self):
         g = self.widget("graphics-keymap")
@@ -953,7 +957,12 @@ class vmmAddHardware(vmmGObjectUI):
         if graphics in ["vnc", "spice"]:
             self.widget("graphics-port-auto").set_sensitive(True)
             self.widget("graphics-address").set_sensitive(True)
-            self.widget("graphics-password").set_sensitive(True)
+            # Skip this code if the checkbox value is not changed.  In this way
+            # the password field maintains its value.
+            if not self.widget("graphics-password-chk").get_sensitive():
+                self.widget("graphics-password").set_sensitive(False)
+                self.widget("graphics-password-chk").set_sensitive(True)
+                self.widget("graphics-password-chk").set_active(False)
             self.widget("graphics-keymap-chk").set_sensitive(True)
             self.change_port_auto()
         else:
@@ -962,6 +971,8 @@ class vmmAddHardware(vmmGObjectUI):
             self.widget("graphics-port-auto").set_sensitive(False)
             self.widget("graphics-address").set_sensitive(False)
             self.widget("graphics-password").set_sensitive(False)
+            self.widget("graphics-password-chk").set_sensitive(False)
+            self.widget("graphics-password-chk").set_active(False)
             self.widget("graphics-keymap-chk").set_sensitive(False)
             self.widget("graphics-keymap").set_sensitive(False)
 
@@ -981,6 +992,13 @@ class vmmAddHardware(vmmGObjectUI):
         else:
             self.widget("graphics-keymap").set_sensitive(True)
 
+    def change_password_chk(self, ignore=None):
+        if self.widget("graphics-password-chk").get_active():
+            self.widget("graphics-password").set_sensitive(True)
+        else:
+            self.widget("graphics-password").set_text("")
+            self.widget("graphics-password").set_sensitive(False)
+
     # Char device listeners
     def get_char_type(self):
         row = self.get_hw_selection()
@@ -1428,7 +1446,7 @@ class vmmAddHardware(vmmGObjectUI):
             self._dev.type = gtype
             if gtype != "sdl":
                 self._dev.port = self.get_config_graphics_port()
-                self._dev.passwd = self.get_config_graphics_password() or None
+                self._dev.passwd = self.get_config_graphics_password()
                 self._dev.listen = self.get_config_graphics_address()
                 self._dev.keymap = self.get_config_keymap()
             if gtype == "spice":
diff --git a/virtManager/details.py b/virtManager/details.py
index 597b1c4..d868b49 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -43,7 +43,7 @@ import virtinst
 
 
 # Parameters that can be editted in the details window
-EDIT_TOTAL = 38
+EDIT_TOTAL = 39
 (EDIT_NAME,
 EDIT_ACPI,
 EDIT_APIC,
@@ -83,6 +83,7 @@ EDIT_NET_VPORT,
 EDIT_NET_SOURCE,
 
 EDIT_GFX_PASSWD,
+EDIT_GFX_USE_PASSWD,
 EDIT_GFX_TYPE,
 EDIT_GFX_KEYMAP,
 
@@ -488,6 +489,8 @@ class vmmDetails(vmmGObjectUI):
             "on_gfx_type_combo_changed": lambda *x: self.enable_apply(x, EDIT_GFX_TYPE),
             "on_vnc_keymap_combo_changed": lambda *x: self.enable_apply(x,
                                             EDIT_GFX_KEYMAP),
+
+            "on_vnc_use_password_toggled": lambda *x: self.control_gfx_use_passwd(x),
             "on_vnc_password_changed": lambda *x: self.enable_apply(x, EDIT_GFX_PASSWD),
 
             "on_sound_model_combo_changed": lambda *x: self.enable_apply(x,
@@ -1564,6 +1567,13 @@ class vmmDetails(vmmGObjectUI):
                        self.vm.has_spicevmc_type_redirdev())
         self.widget("details-menu-usb-redirection").set_sensitive(can_usb)
 
+    def control_gfx_use_passwd(self, x):
+        passwd_widget = self.widget("gfx-password")
+        sensitive = self.widget("gfx-use-password").get_active()
+        if not sensitive: passwd_widget.set_text("")
+        passwd_widget.set_sensitive(sensitive)
+        self.enable_apply(x, EDIT_GFX_USE_PASSWD)
+
     def control_vm_run(self, src_ignore):
         self.emit("action-run-domain",
                   self.vm.conn.get_uri(), self.vm.get_uuid())
@@ -2445,8 +2455,12 @@ class vmmDetails(vmmGObjectUI):
     def config_graphics_apply(self, dev_id_info):
         df, da, add_define, hf, ha, add_hotplug = self.make_apply_data()
 
-        if self.editted(EDIT_GFX_PASSWD):
-            passwd = self.get_text("gfx-password", strip=False) or None
+        if self.editted(EDIT_GFX_PASSWD) or self.editted(EDIT_GFX_USE_PASSWD):
+            use_passwd = self.widget("gfx-use-password").get_active()
+            if use_passwd:
+                passwd = self.get_text("gfx-password", strip=False) or ""
+            else:
+                passwd = None
             add_define(self.vm.define_graphics_password, dev_id_info, passwd)
             add_hotplug(self.vm.hotplug_graphics_password, dev_id_info,
                         passwd)
@@ -3124,10 +3138,21 @@ class vmmDetails(vmmGObjectUI):
             self.widget(base + "-title").show()
             self.widget(base + suffix).show()
 
+        def show_box(widget_name):
+            self.widget("gfx-%s-box" % widget_name).show()
+
+        def show_checkbox(widget_name, value):
+            widget = self.widget("gfx-" + widget_name)
+            widget.show()
+            widget.set_active(value)
+
         def show_text(widget_name, text):
             show_row(widget_name)
             self.widget("gfx-" + widget_name).set_text(text)
 
+        def enable_widget(widget_name, value):
+            self.widget("gfx-" + widget_name).set_sensitive(value)
+
         def port_to_string(port):
             if port is None:
                 return "-"
@@ -3147,9 +3172,13 @@ class vmmDetails(vmmGObjectUI):
             port  = port_to_string(gfx.port)
             address = (gfx.listen or "127.0.0.1")
             keymap  = (gfx.keymap or None)
-            passwd  = gfx.passwd or ""
+            use_passwd = gfx.passwd is not None
+            passwd = gfx.passwd or ""
 
+            show_box("password")
             show_text("password", passwd)
+            show_checkbox("use-password", use_passwd)
+            enable_widget("password", use_passwd)
             show_text("port", port)
             show_text("address", address)
 
diff --git a/virtManager/domain.py b/virtManager/domain.py
index a054d4d..de0df8a 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -889,7 +889,7 @@ class vmmDomain(vmmLibvirtObject):
         self.attach_device(devobj)
 
     def hotplug_graphics_password(self, devobj, newval):
-        devobj.passwd = newval or None
+        devobj.passwd = newval
         self.update_device(devobj)
 
     def hotplug_description(self, desc):
-- 
1.8.3.1




More information about the virt-tools-list mailing list