mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
Lifecycle management on vmmConnect & vmmManager so app exits when last window is closed
This commit is contained in:
parent
7547140130
commit
29813b4368
@ -1,7 +1,13 @@
|
||||
import gobject
|
||||
import gtk.glade
|
||||
|
||||
class vmmConnect:
|
||||
class vmmConnect(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
"completed": (gobject.SIGNAL_RUN_FIRST,
|
||||
gobject.TYPE_NONE, (str,bool))
|
||||
}
|
||||
def __init__(self, config, engine):
|
||||
self.__gobject_init__()
|
||||
self.window = gtk.glade.XML(config.get_glade_file(), "vmm-open-connection")
|
||||
self.engine = engine
|
||||
self.window.get_widget("vmm-open-connection").hide()
|
||||
@ -13,15 +19,19 @@ class vmmConnect:
|
||||
"on_type_local_xen_toggled": self.change_active_type,
|
||||
"on_type_remote_xen_toggled": self.change_active_type,
|
||||
"on_type_other_hv_toggled": self.change_active_type,
|
||||
"on_cancel_clicked": self.close,
|
||||
"on_cancel_clicked": self.cancel,
|
||||
"on_connect_clicked": self.open_connection,
|
||||
"on_vmm_open_connection_delete_event": self.close,
|
||||
"on_vmm_open_connection_delete_event": self.cancel,
|
||||
})
|
||||
|
||||
def close(self,ignore1=None,ignore2=None):
|
||||
self.window.get_widget("vmm-open-connection").hide()
|
||||
def cancel(self,ignore1=None,ignore2=None):
|
||||
self.close()
|
||||
self.emit("completed", None, False)
|
||||
return 1
|
||||
|
||||
def close(self):
|
||||
self.window.get_widget("vmm-open-connection").hide()
|
||||
|
||||
def show(self):
|
||||
win = self.window.get_widget("vmm-open-connection")
|
||||
win.show_all()
|
||||
@ -39,7 +49,7 @@ class vmmConnect:
|
||||
self.window.get_widget("remote-xen-options").set_sensitive(False)
|
||||
self.window.get_widget("other-hv-options").set_sensitive(True)
|
||||
|
||||
def open_connection(self,src):
|
||||
def open_connection(self, src):
|
||||
uri = None
|
||||
|
||||
if self.window.get_widget("type-local-xen").get_active():
|
||||
@ -52,6 +62,7 @@ class vmmConnect:
|
||||
else:
|
||||
uri = self.window.get_widget("other-hv-uri").get_text()
|
||||
|
||||
con = self.engine.get_connection(uri, self.window.get_widget("option-read-only").get_active())
|
||||
con.show_manager()
|
||||
self.close()
|
||||
self.emit("completed", uri, self.window.get_widget("option-read-only").get_active())
|
||||
|
||||
gobject.type_register(vmmConnect)
|
||||
|
@ -22,6 +22,7 @@ class vmmConnection(gobject.GObject):
|
||||
self.__gobject_init__()
|
||||
self.engine = engine
|
||||
self.config = config
|
||||
self.uri = uri
|
||||
|
||||
if readOnly:
|
||||
self.vmm = libvirt.openReadOnly(uri)
|
||||
@ -35,6 +36,9 @@ class vmmConnection(gobject.GObject):
|
||||
|
||||
self.stats = vmmStats(config, self)
|
||||
|
||||
def get_uri(self):
|
||||
return self.uri
|
||||
|
||||
def get_stats(self):
|
||||
return self.stats
|
||||
|
||||
@ -50,9 +54,22 @@ class vmmConnection(gobject.GObject):
|
||||
self.windowManager.show()
|
||||
|
||||
def disconnect(self):
|
||||
self.vmm.disconnect()
|
||||
if self.vmm == None:
|
||||
return
|
||||
|
||||
#self.vmm.close()
|
||||
self.vmm = None
|
||||
self.emit("disconnected")
|
||||
if self.windowManager != None:
|
||||
self.windowManager.close()
|
||||
self.windowManager = None
|
||||
for uuid in self.windowDetails.keys():
|
||||
self.windowDetails[uuid].close()
|
||||
del self.windowDetails[uuid]
|
||||
for uuid in self.windowConsole.keys():
|
||||
self.windowConsole[uuid].close()
|
||||
del self.windowConsole[uuid]
|
||||
|
||||
self.emit("disconnected", "dummy")
|
||||
|
||||
def get_host_info(self):
|
||||
return self.vmm.getInfo()
|
||||
|
@ -1,4 +1,5 @@
|
||||
import gobject
|
||||
import gtk
|
||||
|
||||
from virtManager.about import vmmAbout
|
||||
from virtManager.connect import vmmConnect
|
||||
@ -23,6 +24,24 @@ class vmmEngine:
|
||||
self.tick()
|
||||
|
||||
|
||||
def _connection_disconnected(self, connection, dummy):
|
||||
del self.connections[connection.get_uri()]
|
||||
|
||||
if len(self.connections.keys()) == 0 and self.windowOpenConnection == None:
|
||||
print "No more connections, getting out"
|
||||
gtk.main_quit()
|
||||
|
||||
def _connect_to_uri(self, connect, uri, readOnly):
|
||||
self.windowOpenConnection = None
|
||||
if uri != None:
|
||||
conn = self.get_connection(uri, readOnly)
|
||||
self.show_manager(uri)
|
||||
|
||||
if len(self.connections.keys()) == 0 and self.windowOpenConnection == None:
|
||||
print "No more connections, getting out"
|
||||
gtk.main_quit()
|
||||
|
||||
|
||||
def reschedule_timer(self, ignore1,ignore2,ignore3,ignore4):
|
||||
self.schedule_timer()
|
||||
|
||||
@ -64,6 +83,7 @@ class vmmEngine:
|
||||
def show_open_connection(self):
|
||||
if self.windowOpenConnection == None:
|
||||
self.windowOpenConnection = vmmConnect(self.get_config(), self)
|
||||
self.windowOpenConnection.connect("completed", self._connect_to_uri)
|
||||
self.windowOpenConnection.show()
|
||||
|
||||
def show_console(self, uri, uuid):
|
||||
@ -85,5 +105,6 @@ class vmmEngine:
|
||||
|
||||
if not(self.connections.has_key(key)):
|
||||
self.connections[key] = vmmConnection(self, self.get_config(), uri, readOnly)
|
||||
self.connections[key].connect("disconnected", self._connection_disconnected)
|
||||
self.connections[key].tick()
|
||||
return self.connections[key]
|
||||
|
@ -59,10 +59,10 @@ class vmmManager:
|
||||
"on_menu_view_disk_usage_activate" : self.toggle_disk_usage_visible_conf,
|
||||
"on_menu_view_network_traffic_activate" : self.toggle_network_traffic_visible_conf,
|
||||
|
||||
"on_vm_manager_delete_event": self.exit_app,
|
||||
"on_vm_manager_delete_event": self.close,
|
||||
"on_menu_file_open_connection_activate": self.open_connection,
|
||||
"on_menu_file_quit_activate": self.exit_app,
|
||||
"on_vmm_close_clicked": self.exit_app,
|
||||
"on_vmm_close_clicked": self.close,
|
||||
"on_vm_details_clicked": self.show_vm_details,
|
||||
"on_vm_open_clicked": self.open_vm_console,
|
||||
"on_menu_edit_details_activate": self.show_vm_details,
|
||||
@ -77,15 +77,20 @@ class vmmManager:
|
||||
|
||||
self.vm_selected(None)
|
||||
self.window.get_widget("vm-list").get_selection().connect("changed", self.vm_selected)
|
||||
|
||||
self.connection.connect("disconnected", self.close)
|
||||
|
||||
def show(self):
|
||||
win = self.window.get_widget("vmm-manager")
|
||||
win.show_all()
|
||||
win.present()
|
||||
|
||||
def close(self, src=None, src2=None):
|
||||
self.connection.disconnect()
|
||||
win = self.window.get_widget("vmm-manager")
|
||||
win.hide()
|
||||
return 1
|
||||
|
||||
def exit_app(self, ignore=None,ignore2=None):
|
||||
def exit_app(self, src=None, src2=None):
|
||||
gtk.main_quit()
|
||||
|
||||
def open_connection(self, src=None):
|
||||
|
Loading…
Reference in New Issue
Block a user