engine: Use signals for incrementing window counter

This commit is contained in:
Cole Robinson 2011-04-13 10:47:31 -04:00
parent b76804a8a5
commit fd755f99d5
4 changed files with 40 additions and 22 deletions

View File

@ -247,14 +247,15 @@ class vmmDetails(vmmGObjectUI):
gobject.TYPE_NONE, (str, str)),
"details-closed": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ()),
"details-opened": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ()),
}
def __init__(self, vm, engine, parent=None):
def __init__(self, vm, parent=None):
vmmGObjectUI.__init__(self, "vmm-details.glade", "vmm-details")
self.vm = vm
self.conn = self.vm.get_connection()
self.engine = engine
self.is_customize_dialog = False
if parent:
@ -460,7 +461,6 @@ class vmmDetails(vmmGObjectUI):
try:
self.vm = None
self.conn = None
self.engine = None
self.addhwmenu = None
self.console.cleanup()
@ -492,7 +492,7 @@ class vmmDetails(vmmGObjectUI):
if vis:
return
self.engine.increment_window_counter()
self.emit("details-opened")
self.refresh_vm_state()
def close(self, ignore1=None, ignore2=None):
@ -510,7 +510,6 @@ class vmmDetails(vmmGObjectUI):
self.console.close_viewer()
except:
logging.error("Failure when disconnecting from desktop server")
self.engine.decrement_window_counter()
self.emit("details-closed")
return 1

View File

@ -450,11 +450,12 @@ class vmmEngine(vmmGObject):
gobject.source_remove(self.timer)
self.schedule_timer()
def increment_window_counter(self):
def increment_window_counter(self, src):
ignore = src
self.windows += 1
logging.debug("window counter incremented to %s" % self.windows)
def decrement_window_counter(self):
def decrement_window_counter(self, src):
self.windows -= 1
logging.debug("window counter decremented to %s" % self.windows)
@ -462,7 +463,7 @@ class vmmEngine(vmmGObject):
if (self.windows <= 0 and
self.systray and
not self.systray.is_visible()):
self.exit_app()
self.exit_app(src)
def cleanup(self):
try:
@ -510,7 +511,7 @@ class vmmEngine(vmmGObject):
except:
logging.exception("Error cleaning up engine")
def exit_app(self, src=None):
def exit_app(self, src):
if self.err is None:
# Already in cleanup
return
@ -519,7 +520,7 @@ class vmmEngine(vmmGObject):
if debug_ref_leaks:
objs = self.config.get_objects()
if src and src.object_key in objs:
if src.object_key in objs:
# Whatever UI initiates the app exit will always appear
# to leak
logging.debug("Exitting app from %s, skipping leak check" %
@ -647,11 +648,15 @@ class vmmEngine(vmmGObject):
return self.connections[uri]["windowHost"]
con = self._lookup_connection(uri)
obj = vmmHost(con, self)
obj = vmmHost(con)
obj.connect("action-show-help", self._do_show_help)
obj.connect("action-exit-app", self.exit_app)
obj.connect("action-view-manager", self._do_show_manager)
obj.connect("action-restore-domain", self._do_restore_domain)
obj.connect("host-opened", self.increment_window_counter)
obj.connect("host-closed", self.decrement_window_counter)
self.connections[uri]["windowHost"] = obj
return self.connections[uri]["windowHost"]
@ -686,7 +691,7 @@ class vmmEngine(vmmGObject):
con = self._lookup_connection(uri)
obj = vmmDetails(con.get_vm(uuid), self)
obj = vmmDetails(con.get_vm(uuid))
obj.connect("action-save-domain", self._do_save_domain)
obj.connect("action-destroy-domain", self._do_destroy_domain)
obj.connect("action-show-help", self._do_show_help)
@ -699,6 +704,8 @@ class vmmEngine(vmmGObject):
obj.connect("action-view-manager", self._do_show_manager)
obj.connect("action-migrate-domain", self._do_show_migrate)
obj.connect("action-clone-domain", self._do_show_clone)
obj.connect("details-opened", self.increment_window_counter)
obj.connect("details-closed", self.decrement_window_counter)
self.connections[uri]["windowDetails"][uuid] = obj
self.connections[uri]["windowDetails"][uuid].show()
@ -742,6 +749,8 @@ class vmmEngine(vmmGObject):
obj.connect("action-show-connect", self._do_show_connect)
obj.connect("action-connect", self._do_connect)
obj.connect("action-exit-app", self.exit_app)
obj.connect("manager-opened", self.increment_window_counter)
obj.connect("manager-closed", self.decrement_window_counter)
self.windowManager = obj
return self.windowManager

View File

@ -49,17 +49,22 @@ class vmmHost(vmmGObjectUI):
gobject.TYPE_NONE, []),
"action-restore-domain": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, (str,)),
"host-closed": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ()),
"host-opened": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ()),
}
def __init__(self, conn, engine):
def __init__(self, conn):
vmmGObjectUI.__init__(self, "vmm-host.glade", "vmm-host")
self.conn = conn
self.engine = engine
self.title = conn.get_short_hostname() + " " + self.topwin.get_title()
self.topwin.set_title(self.title)
self.PIXBUF_STATE_RUNNING = gtk.gdk.pixbuf_new_from_file_at_size(self.config.get_icon_dir() + "/state_running.png", 18, 18)
self.PIXBUF_STATE_SHUTOFF = gtk.gdk.pixbuf_new_from_file_at_size(self.config.get_icon_dir() + "/state_shutoff.png", 18, 18)
self.PIXBUF_STATE_RUNNING = gtk.gdk.pixbuf_new_from_file_at_size(
self.config.get_icon_dir() + "/state_running.png", 18, 18)
self.PIXBUF_STATE_SHUTOFF = gtk.gdk.pixbuf_new_from_file_at_size(
self.config.get_icon_dir() + "/state_shutoff.png", 18, 18)
self.addnet = None
self.addpool = None
@ -299,7 +304,7 @@ class vmmHost(vmmGObjectUI):
if vis:
return
self.engine.increment_window_counter()
self.emit("host-opened")
def is_visible(self):
return bool(self.topwin.flags() & gtk.VISIBLE)
@ -309,7 +314,8 @@ class vmmHost(vmmGObjectUI):
return
self.topwin.hide()
self.engine.decrement_window_counter()
self.emit("host-closed")
return 1
def cleanup(self):
@ -317,8 +323,6 @@ class vmmHost(vmmGObjectUI):
try:
self.conn = None
self.engine = None
if self.addnet:
self.addnet.cleanup()

View File

@ -112,6 +112,10 @@ class vmmManager(vmmGObjectUI):
gobject.TYPE_NONE, (str, str)),
"action-exit-app": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, []),
"manager-closed": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ()),
"manager-opened": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ()),
}
def __init__(self, engine):
@ -218,7 +222,8 @@ class vmmManager(vmmGObjectUI):
if self.prev_position:
self.topwin.move(*self.prev_position)
self.prev_position = None
self.engine.increment_window_counter()
self.emit("manager-opened")
def close(self, src_ignore=None, src2_ignore=None):
if not self.is_visible():
@ -226,7 +231,8 @@ class vmmManager(vmmGObjectUI):
self.prev_position = self.topwin.get_position()
self.topwin.hide()
self.engine.decrement_window_counter()
self.emit("manager-closed")
return 1