2006-08-30 12:22:01 +02:00
|
|
|
import gobject
|
|
|
|
|
2006-08-30 11:46:14 +02:00
|
|
|
from sugar.canvas.IconColor import IconColor
|
|
|
|
|
|
|
|
class Friend:
|
|
|
|
def __init__(self, name, color):
|
|
|
|
self._name = name
|
|
|
|
self._color = color
|
|
|
|
|
|
|
|
def get_name(self):
|
2006-08-30 12:22:01 +02:00
|
|
|
return self._name
|
2006-08-30 11:46:14 +02:00
|
|
|
|
|
|
|
def get_color(self):
|
|
|
|
return IconColor(self._color)
|
|
|
|
|
2006-08-30 12:22:01 +02:00
|
|
|
class Friends(gobject.GObject):
|
|
|
|
__gsignals__ = {
|
|
|
|
'friend-added': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([object])),
|
|
|
|
'friend-removed': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([object])),
|
|
|
|
}
|
|
|
|
|
2006-08-30 11:46:14 +02:00
|
|
|
def __init__(self):
|
2006-08-30 12:22:01 +02:00
|
|
|
gobject.GObject.__init__(self)
|
|
|
|
|
|
|
|
self._list = []
|
|
|
|
|
|
|
|
def has_buddy(self, buddy):
|
|
|
|
for friend in self:
|
|
|
|
if friend.get_name() == buddy.get_name():
|
|
|
|
return True
|
|
|
|
return False
|
2006-08-30 11:46:14 +02:00
|
|
|
|
|
|
|
def add_buddy(self, buddy):
|
2006-08-30 12:22:01 +02:00
|
|
|
if not self.has_buddy(buddy):
|
|
|
|
friend = Friend(buddy.get_name(), buddy.get_color())
|
|
|
|
self._list.append(friend)
|
|
|
|
self.emit('friend-added', friend)
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self._list.__iter__()
|