Improved connection to clipboard service.

This commit is contained in:
Tomeu Vizoso 2007-02-01 20:21:56 +01:00
parent d448cba742
commit 4e267c18bf

View File

@ -28,32 +28,38 @@ class ClipboardService(gobject.GObject):
gobject.GObject.__init__(self) gobject.GObject.__init__(self)
self._dbus_service = None self._dbus_service = None
bus = dbus.SessionBus() bus = dbus.SessionBus()
bus.add_signal_receiver(self._name_owner_changed_cb, self._nameOwnerChangedHandler = bus.add_signal_receiver(
signal_name="NameOwnerChanged", self._name_owner_changed_cb,
dbus_interface="org.freedesktop.DBus") signal_name="NameOwnerChanged",
dbus_interface="org.freedesktop.DBus",
arg0=DBUS_SERVICE)
self._connected = False
# Try to register to ClipboardService, if we fail, we'll try later. # Try to register to ClipboardService, if we fail, we'll try later.
try: try:
self._connect_clipboard_signals() self._connect_clipboard_signals()
except dbus.DBusException, exception: except dbus.DBusException, exception:
pass logging.debug(exception)
def _connect_clipboard_signals(self): def _connect_clipboard_signals(self):
bus = dbus.SessionBus() bus = dbus.SessionBus()
proxy_obj = bus.get_object(DBUS_SERVICE, DBUS_PATH) if not self._connected:
self._dbus_service = dbus.Interface(proxy_obj, DBUS_SERVICE) proxy_obj = bus.get_object(DBUS_SERVICE, DBUS_PATH)
self._dbus_service.connect_to_signal('object_added', self._dbus_service = dbus.Interface(proxy_obj, DBUS_SERVICE)
self._object_added_cb) self._dbus_service.connect_to_signal('object_added',
self._dbus_service.connect_to_signal('object_deleted', self._object_added_cb)
self._object_deleted_cb) self._dbus_service.connect_to_signal('object_deleted',
self._dbus_service.connect_to_signal('object_state_changed', self._object_deleted_cb)
self._object_state_changed_cb) self._dbus_service.connect_to_signal('object_state_changed',
self._object_state_changed_cb)
self._connected = True
bus.remove_signal_receiver(self._nameOwnerChangedHandler)
def _name_owner_changed_cb(self, name, old, new): def _name_owner_changed_cb(self, name, old, new):
if name != DBUS_SERVICE: if not old and new:
return
if (not old and not len(old)) and (new and len(new)):
# ClipboardService started up # ClipboardService started up
self._connect_clipboard_signals() self._connect_clipboard_signals()