services/presence/buddy: Use add_signal_receiver to connect signals.
This means we don't need to care whether the Sugar shell is actually running - if it is, we'll get its signals, and if it's not, obviously it can't send us any signals!
This commit is contained in:
parent
7b0d65a211
commit
fdd8c315cf
@ -605,48 +605,22 @@ class ShellOwner(GenericOwner):
|
|||||||
nick=nick, color=color, icon=icon, server=server,
|
nick=nick, color=color, icon=icon, server=server,
|
||||||
key_hash=key_hash, registered=registered)
|
key_hash=key_hash, registered=registered)
|
||||||
|
|
||||||
# Connect to the shell to get notifications on Owner object
|
# Ask to get notifications on Owner object property changes in the
|
||||||
# property changes
|
# shell. If it's not currently running, no problem - we'll get the
|
||||||
try:
|
# signals when it does run
|
||||||
self._connect_to_shell()
|
for (signal, cb) in (('IconChanged', self._icon_changed_cb),
|
||||||
except dbus.DBusException:
|
('ColorChanged', self._color_changed_cb),
|
||||||
pass
|
('NickChanged', self._nick_changed_cb)):
|
||||||
|
self._bus.add_signal_receiver(cb, signal_name=signal,
|
||||||
|
dbus_interface=self._SHELL_OWNER_INTERFACE,
|
||||||
|
bus_name=self._SHELL_SERVICE,
|
||||||
|
path=self._SHELL_PATH)
|
||||||
|
|
||||||
def set_registered(self, value):
|
def set_registered(self, value):
|
||||||
"""Handle notification that we have been registered"""
|
"""Handle notification that we have been registered"""
|
||||||
if value:
|
if value:
|
||||||
profile.set_server_registered()
|
profile.set_server_registered()
|
||||||
|
|
||||||
def _name_owner_changed_cb(self, name, old, new):
|
|
||||||
# chain up to superclass
|
|
||||||
GenericOwner._name_owner_changed_cb(self, name, old, new)
|
|
||||||
|
|
||||||
if name != self._SHELL_SERVICE:
|
|
||||||
return
|
|
||||||
if (old and len(old)) and (not new and not len(new)):
|
|
||||||
# shell went away
|
|
||||||
self._shell_owner = None
|
|
||||||
elif (not old and not len(old)) and (new and len(new)):
|
|
||||||
# shell started
|
|
||||||
self._connect_to_shell()
|
|
||||||
|
|
||||||
def _connect_to_shell(self):
|
|
||||||
"""Connect to the Sugar Shell service to watch for events
|
|
||||||
|
|
||||||
Connects the various XChanged events on the Sugar Shell
|
|
||||||
service to our _x_changed_cb methods.
|
|
||||||
"""
|
|
||||||
obj = self._bus.get_object(self._SHELL_SERVICE, self._SHELL_PATH)
|
|
||||||
self._shell_owner = dbus.Interface(obj, self._SHELL_OWNER_INTERFACE)
|
|
||||||
self._shell_owner.connect_to_signal('IconChanged',
|
|
||||||
self._icon_changed_cb)
|
|
||||||
self._shell_owner.connect_to_signal('ColorChanged',
|
|
||||||
self._color_changed_cb)
|
|
||||||
self._shell_owner.connect_to_signal('NickChanged',
|
|
||||||
self._nick_changed_cb)
|
|
||||||
self._shell_owner.connect_to_signal('CurrentActivityChanged',
|
|
||||||
self._cur_activity_changed_cb)
|
|
||||||
|
|
||||||
def _icon_changed_cb(self, icon):
|
def _icon_changed_cb(self, icon):
|
||||||
"""Handle icon change, set property to generate event"""
|
"""Handle icon change, set property to generate event"""
|
||||||
self.props.icon = icon
|
self.props.icon = icon
|
||||||
|
Loading…
Reference in New Issue
Block a user