[virt-tools-list] [virt-manager PATCH v2 3/3] addhardware: enable setting model when adding controller

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Wed Apr 23 10:23:30 UTC 2014


If no USB controller, we could add a new one;
if had, disable 'create-finish' button and
add a tooltip beside type combo.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 ui/addhardware.ui          | 22 ++++++++++++++++++---
 virtManager/addhardware.py | 48 +++++++++++++++++++++++++++++++++++-----------
 2 files changed, 56 insertions(+), 14 deletions(-)

diff --git a/ui/addhardware.ui b/ui/addhardware.ui
index 97d03c0..7a5b30d 100644
--- a/ui/addhardware.ui
+++ b/ui/addhardware.ui
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.16.1 -->
+<!-- Generated with glade 3.16.0 on Wed Apr 23 16:58:20 2014 -->
 <interface>
-  <requires lib="gtk+" version="3.0"/>
+  <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkAdjustment" id="adjustment1">
     <property name="upper">67000</property>
     <property name="step_increment">1</property>
@@ -169,12 +169,12 @@
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
                                     <property name="halign">start</property>
-                                    <signal name="changed" handler="on_config_storage_devtype_changed" swapped="no"/>
                                     <child internal-child="accessible">
                                       <object class="AtkObject" id="config-storage-devtype-atkobject">
                                         <property name="AtkObject::accessible-name" translatable="yes">Device Type Field</property>
                                       </object>
                                     </child>
+                                    <signal name="changed" handler="on_config_storage_devtype_changed" swapped="no"/>
                                   </object>
                                   <packing>
                                     <property name="left_attach">1</property>
@@ -387,6 +387,22 @@
                                 <property name="height">1</property>
                               </packing>
                             </child>
+                            <child>
+                              <object class="GtkImage" id="controller-tooltip">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="stock">gtk-info</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">2</property>
+                                <property name="top_attach">0</property>
+                                <property name="width">1</property>
+                                <property name="height">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </object>
                           <packing>
                             <property name="position">2</property>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 78235bb..4fc5532 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -325,9 +325,6 @@ class vmmAddHardware(vmmGObjectUI):
         target_model = Gtk.ListStore(str, str)
         combo.set_model(target_model)
         uiutil.set_combo_text_column(combo, 1)
-        # FIXME: we should deal with controller model
-        combo.set_visible(False)
-        self.widget("controller-model-label").set_visible(False)
 
         # Available HW options
         is_local = not self.conn.is_remote()
@@ -872,6 +869,22 @@ class vmmAddHardware(vmmGObjectUI):
 
         controller_type = self.get_config_controller_type()
         modellist = self.widget("controller-model")
+        model_tooltip = self.widget("controller-tooltip")
+        model_tooltip.set_visible(False)
+
+        controllers = self.vm.get_controller_devices()
+        if (controller_type == VirtualController.TYPE_USB and
+                len([x for x in controllers if
+                    (x.type == VirtualController.TYPE_USB)])):
+            vmname = self.vm.get_name()
+            tooltip = (_("%s already has a USB controller attached.\n"
+            "Adding more than one USB controller is not supported.\nYou can change "
+            "the USB controller type in the VM details screen.") % vmname)
+            model_tooltip.set_visible(True)
+            model_tooltip.set_tooltip_text(tooltip)
+            self.widget("create-finish").set_sensitive(False)
+        else:
+            self.widget("create-finish").set_sensitive(True)
         modellist.set_sensitive(True)
         self.populate_controller_model_combo(modellist, controller_type, None, True)
 
@@ -1806,16 +1819,29 @@ class vmmAddHardware(vmmGObjectUI):
     def validate_page_controller(self):
         conn = self.conn.get_backend()
         controller_type = self.get_config_controller_type()
+        model = self.get_config_controller_model()
         self._dev = VirtualController(conn)
 
-        controllers = self.vm.get_controller_devices()
-        controller_num = [x for x in controllers if
-                (x.type == controller_type)]
-        if len(controller_num) > 0:
-            index_new = max([x.index for x in controller_num]) + 1
-            self._dev.index = index_new
-
-        self._dev.type = controller_type
+        if model == "ich9-ehci1":
+            for dev in VirtualController.get_usb2_controllers(conn):
+                self._dev.type = dev.type
+                self._dev.model = dev.model
+                self._dev.master_startport = dev.master_startport
+                if dev.model != "ich9-uhci3":
+                    self.add_device()
+        else:
+            controllers = self.vm.get_controller_devices()
+            controller_num = [x for x in controllers if
+                    (x.type == controller_type)]
+            if len(controller_num) > 0:
+                index_new = max([x.index for x in controller_num]) + 1
+                self._dev.index = index_new
+
+            self._dev.type = controller_type
+            if model != "none":
+                if model == "default":
+                    model = None
+                self._dev.model = model
 
     def validate_page_rng(self):
         conn = virtinst.VirtualRNGDevice.BACKEND_MODE_CONNECT in \
-- 
1.9.0




More information about the virt-tools-list mailing list