Add PropertyChanged signal for Buddy objects because color and address can change later. Also don't try to stuff None through dbus

This commit is contained in:
Dan Williams 2006-09-07 23:30:22 -04:00
parent 4c167037d4
commit e2306d81bd
2 changed files with 17 additions and 5 deletions

View File

@ -44,6 +44,11 @@ class BuddyDBusHelper(dbus.service.Object):
def LeftActivity(self, object_path):
pass
@dbus.service.signal(BUDDY_DBUS_INTERFACE,
signature="as")
def PropertyChanged(self, prop_list):
pass
@dbus.service.method(BUDDY_DBUS_INTERFACE,
in_signature="", out_signature="ay")
def getIcon(self):
@ -73,7 +78,9 @@ class BuddyDBusHelper(dbus.service.Object):
def getProperties(self):
props = {}
props['name'] = self._parent.get_name()
props['ip4_address'] = self._parent.get_address()
addr = self._parent.get_address()
if addr:
props['ip4_address'] = addr
props['owner'] = self._parent.is_owner()
color = self._parent.get_color()
if color:
@ -174,6 +181,8 @@ class Buddy(object):
print 'Requesting buddy icon %s' % self._nick_name
self._request_buddy_icon(service)
self._color = service.get_one_property('color')
if self._color:
self._dbus_helper.PropertyChanged(['color'])
if self._valid:
self._dbus_helper.ServiceAppeared(service.object_path())
@ -290,8 +299,9 @@ class Owner(Buddy):
# service added to the Owner determines the owner's address
source_addr = service.get_source_address()
if self._address is None:
if source_addr in self._ps.is_local_ip_address(source_addr):
if self._ps.is_local_ip_address(source_addr):
self._address = source_addr
self._dbus_helper.PropertyChanged(['ip4_address'])
return Buddy.add_service(self, service)
def is_owner(self):

View File

@ -14,6 +14,8 @@ class Buddy(gobject.GObject):
'joined-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'left-activity': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'property-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
@ -34,9 +36,7 @@ class Buddy(gobject.GObject):
self._buddy.connect_to_signal('JoinedActivity', self._joined_activity_cb)
self._buddy.connect_to_signal('LeftActivity', self._left_activity_cb)
self._buddy.connect_to_signal('PropertyChanged', self._property_changed_cb)
self._properties = self._buddy.getProperties()
if not self._properties.has_key('color'):
self._properties['color'] = "#deadbe"
self._property_changed_cb([])
def object_path(self):
return self._object_path
@ -78,6 +78,8 @@ class Buddy(gobject.GObject):
def _handle_property_changed_signal(self, prop_list):
self._properties = self._buddy.getProperties()
self.emit('property-changed', prop_list)
return False
def _property_changed_cb(self, prop_list):
gobject.idle_add(self._handle_property_changed_signal, prop_list)