sugar-toolkit-gtk3/shell/home/FriendsModel.py

52 lines
1.3 KiB
Python
Raw Normal View History

2006-08-19 11:12:25 +02:00
import gobject
from sugar.presence import PresenceService
2006-08-25 00:49:39 +02:00
from sugar.canvas.IconColor import IconColor
import logging
2006-08-19 11:12:25 +02:00
class Friend:
def __init__(self, buddy):
self._buddy = buddy
def get_name(self):
return self._buddy.get_name()
2006-08-25 00:49:39 +02:00
def get_color(self):
color = self._buddy.get_color()
try:
icolor = IconColor(color)
except RuntimeError:
icolor = IconColor()
logging.info("Buddy %s doesn't have an allowed color; using a random color instead." % self.get_name())
return icolor
2006-08-25 00:49:39 +02:00
2006-08-19 11:12:25 +02:00
class FriendsModel(gobject.GObject):
__gsignals__ = {
'friend-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT])),
'friend-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([gobject.TYPE_PYOBJECT]))
}
def __init__(self):
gobject.GObject.__init__(self)
self._friends = []
self._pservice = PresenceService.get_instance()
2006-08-19 11:12:25 +02:00
self._pservice.connect("buddy-appeared", self.__buddy_appeared_cb)
for buddy in self._pservice.get_buddies():
self.add_friend(buddy)
def add_friend(self, buddy):
friend = Friend(buddy)
self._friends.append(friend)
self.emit('friend-added', friend)
def __iter__(self):
return self._friends.__iter__()
def __buddy_appeared_cb(self, pservice, buddy):
self.add_friend(buddy)