2010-12-08 16:26:19 -06:00
|
|
|
#
|
|
|
|
# Copyright (C) 2010 Red Hat, Inc.
|
|
|
|
# Copyright (C) 2010 Cole Robinson <crobinso@redhat.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
# MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
|
|
|
|
import os
|
2011-04-11 10:00:57 -05:00
|
|
|
import sys
|
|
|
|
import logging
|
2010-12-08 16:26:19 -06:00
|
|
|
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
import virtManager.config
|
|
|
|
|
|
|
|
class vmmGObject(gobject.GObject):
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def type_register(*args, **kwargs):
|
|
|
|
gobject.type_register(*args, **kwargs)
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
self.config = virtManager.config.running_config
|
|
|
|
|
2011-04-11 10:00:57 -05:00
|
|
|
self._gobject_handles = []
|
|
|
|
self._gobject_timeouts = []
|
|
|
|
self._gconf_handles = []
|
|
|
|
|
2011-04-11 11:54:47 -05:00
|
|
|
self._object_key = str(self)
|
|
|
|
self.config.add_object(self._object_key)
|
|
|
|
|
2011-04-11 10:00:57 -05:00
|
|
|
def cleanup(self):
|
|
|
|
# Do any cleanup required to drop reference counts so object is
|
|
|
|
# actually reaped by python. Usually means unregistering callbacks
|
|
|
|
try:
|
|
|
|
for h in self._gconf_handles[:]:
|
|
|
|
self.remove_gconf_handle(h)
|
|
|
|
for h in self._gobject_handles[:]:
|
2011-04-11 12:06:59 -05:00
|
|
|
self.disconnect(h)
|
2011-04-11 10:00:57 -05:00
|
|
|
for h in self._gobject_timeouts[:]:
|
|
|
|
self.remove_gobject_timeout(h)
|
|
|
|
except:
|
|
|
|
logging.exception("Error cleaning up %s" % self)
|
|
|
|
|
2011-04-11 12:06:59 -05:00
|
|
|
def connect(self, name, callback, *args):
|
|
|
|
ret = gobject.GObject.connect(self, name, callback, *args)
|
|
|
|
self._gobject_handles.append(ret)
|
|
|
|
return ret
|
|
|
|
def disconnect(self, handle):
|
|
|
|
ret = gobject.GObject.disconnect(self, handle)
|
|
|
|
self._gobject_handles.remove(handle)
|
|
|
|
return ret
|
|
|
|
|
2011-04-11 10:00:57 -05:00
|
|
|
def add_gconf_handle(self, handle):
|
|
|
|
self._gconf_handles.append(handle)
|
|
|
|
def remove_gconf_handle(self, handle):
|
|
|
|
self.config.remove_notifier(handle)
|
|
|
|
self._gconf_handles.remove(handle)
|
|
|
|
|
|
|
|
def add_gobject_timeout(self, handle):
|
|
|
|
self._gobject_timeouts.append(handle)
|
|
|
|
def remove_gobject_timeout(self, handle):
|
|
|
|
gobject.source_remove(handle)
|
|
|
|
self._gobject_timeouts.remove(handle)
|
|
|
|
|
|
|
|
def refcount(self):
|
|
|
|
# Function generates 2 temporary refs, so adjust total accordingly
|
|
|
|
return (sys.getrefcount(self) - 2)
|
|
|
|
|
2010-12-09 13:06:00 -06:00
|
|
|
def get_hal_helper(self):
|
|
|
|
from virtManager import halhelper
|
2010-12-10 08:57:42 -06:00
|
|
|
return halhelper.get_hal_helper()
|
2010-12-09 13:06:00 -06:00
|
|
|
|
2011-04-11 11:54:47 -05:00
|
|
|
def __del__(self):
|
|
|
|
if hasattr(gobject.GObject, "__del__"):
|
|
|
|
getattr(gobject.GObject, "__del__")(self)
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.config.remove_object(self._object_key)
|
|
|
|
except:
|
|
|
|
logging.exception("Error removing %s" % self._object_key)
|
2011-04-11 10:00:57 -05:00
|
|
|
|
2010-12-08 16:26:19 -06:00
|
|
|
class vmmGObjectUI(vmmGObject):
|
|
|
|
def __init__(self, filename, windowname):
|
|
|
|
vmmGObject.__init__(self)
|
|
|
|
|
|
|
|
self.windowname = windowname
|
|
|
|
self.window = None
|
|
|
|
self.topwin = None
|
|
|
|
self.gladefile = None
|
2011-04-11 12:06:59 -05:00
|
|
|
self.err = None
|
2010-12-08 16:26:19 -06:00
|
|
|
|
|
|
|
if filename:
|
|
|
|
self.gladefile = os.path.join(self.config.get_glade_dir(),
|
|
|
|
filename)
|
|
|
|
self.window = gtk.glade.XML(self.gladefile,
|
|
|
|
self.windowname,
|
|
|
|
domain="virt-manager")
|
|
|
|
self.topwin = self.window.get_widget(self.windowname)
|
|
|
|
self.topwin.hide()
|
|
|
|
|
2011-04-11 15:26:41 -05:00
|
|
|
self.err = virtManager.error.vmmErrorDialog(self.topwin)
|
2011-04-11 12:06:59 -05:00
|
|
|
|
|
|
|
def cleanup(self):
|
|
|
|
vmmGObject.cleanup(self)
|
|
|
|
self.window = None
|
2011-04-11 17:35:21 -05:00
|
|
|
self.topwin.destroy()
|
2011-04-11 12:06:59 -05:00
|
|
|
self.topwin = None
|
|
|
|
self.gladefile = None
|
|
|
|
self.err = None
|