File virtman-manager.diff of Package virt-manager

Index: virt-manager-0.8.0/src/virtManager/manager.py
===================================================================
--- virt-manager-0.8.0.orig/src/virtManager/manager.py
+++ virt-manager-0.8.0/src/virtManager/manager.py
@@ -624,6 +624,15 @@ class vmmManager(gobject.GObject):
         vmlist = self.window.get_widget("vm-list")
         selection = vmlist.get_selection()
         active = selection.get_selected()
+        if active[1] == None and active[0] != None:
+            # in some cases on vhost, the connection is not being selected at startup.
+            # when creating new vms, if current_connection() returns None, several
+            # functions will fail, so if the user hasn't selected a connection, default
+            # to the first connection in the list.
+            first = active[0].get_iter_first()
+            if first != None:
+                selection.select_iter( first )
+                active = selection.get_selected()
         if active[1] != None:
             parent = active[0].iter_parent(active[1])
             # return the connection of the currently selected vm, or the
@@ -769,7 +778,14 @@ class vmmManager(gobject.GObject):
             return False
 
     def new_vm(self, ignore=None):
-        self.emit("action-show-create", self.current_connection_uri())
+        conn = self.current_connection()
+        if conn.get_state() == vmmConnection.STATE_ACTIVE:
+            self.emit("action-show-create", self.current_connection_uri())
+        else:
+            message_box = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_WARNING, gtk.BUTTONS_OK,
+                                             _("Must select an active connection before creating a Virtual Machine") )
+            message_box.run()
+            message_box.destroy()
 
     def delete_vm(self, ignore=None):
         conn = self.current_connection()
openSUSE Build Service is sponsored by