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

46 lines
1.1 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
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()
return IconColor(color)
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)