Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/model
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@localhost.localdomain>2006-09-15 13:28:18 (GMT)
committer Marco Pesenti Gritti <marco@localhost.localdomain>2006-09-15 13:28:18 (GMT)
commitf2f25f874d639c31d4c8182c18ee8f11acb0b579 (patch)
treec8b16b0455535cb22d5742c7b13f33ca3bcfe10f /shell/model
parent16574cbfccdd5a5bb8da7a8c6165a0063f5f7ce3 (diff)
Implement friends removal, lots of cleanups
Diffstat (limited to 'shell/model')
-rw-r--r--shell/model/Friends.py51
-rw-r--r--shell/model/ShellModel.py20
2 files changed, 19 insertions, 52 deletions
diff --git a/shell/model/Friends.py b/shell/model/Friends.py
index 6beca66..a11acc0 100644
--- a/shell/model/Friends.py
+++ b/shell/model/Friends.py
@@ -3,67 +3,54 @@ from ConfigParser import ConfigParser
import gobject
-from sugar.canvas.IconColor import IconColor
-from sugar.presence import PresenceService
+from model.BuddyInfo import BuddyInfo
from sugar import env
-class Friend:
- def __init__(self, name, color):
- self._name = name
- self._color = color
-
- def get_name(self):
- return self._name
-
- def get_color(self):
- return IconColor(self._color)
-
- def get_buddy(self):
- pservice = PresenceService.get_instance()
- return pservice.get_buddy_by_name(self._name)
-
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])),
+ gobject.TYPE_NONE, ([str])),
}
def __init__(self):
gobject.GObject.__init__(self)
- self._list = []
+ self._friends = {}
self._path = os.path.join(env.get_profile_path(), 'friends')
self.load()
def has_buddy(self, buddy):
- for friend in self:
- if friend.get_name() == buddy.get_name():
- return True
- return False
+ return self._friends.has_key(buddy.get_name())
- def add_friend(self, name, color):
- friend = Friend(name, color)
- self._list.append(friend)
+ def add_friend(self, buddy_info):
+ self._friends[buddy_info.get_name()] = buddy_info
+ self.emit('friend-added', buddy_info)
- self.emit('friend-added', friend)
-
- def add_buddy(self, buddy):
+ def make_friend(self, buddy):
if not self.has_buddy(buddy):
- self.add_friend(buddy.get_name(), buddy.get_color())
+ self.add_friend(BuddyInfo(buddy))
self.save()
+ def remove(self, buddy_info):
+ del self._friends[buddy_info.get_name()]
+ self.save()
+ self.emit('friend-removed', buddy_info.get_name())
+
def __iter__(self):
- return self._list.__iter__()
+ return self._friends.values().__iter__()
def load(self):
cp = ConfigParser()
if cp.read([self._path]):
for name in cp.sections():
- self.add_friend(name, cp.get(name, 'color'))
+ buddy = BuddyInfo()
+ buddy.set_name(name)
+ buddy.set_color(cp.get(name, 'color'))
+ self.add_friend(buddy)
def save(self):
cp = ConfigParser()
diff --git a/shell/model/ShellModel.py b/shell/model/ShellModel.py
index 2f9dd25..4929fe7 100644
--- a/shell/model/ShellModel.py
+++ b/shell/model/ShellModel.py
@@ -1,8 +1,6 @@
import gobject
from sugar.presence import PresenceService
-from sugar.activity import ActivityFactory
-from sugar.activity import Activity
from model.Friends import Friends
from model.Invites import Invites
from model.Owner import ShellOwner
@@ -66,21 +64,3 @@ class ShellModel(gobject.GObject):
def get_current_activity(self):
return self._current_activity
-
- def join_activity(self, bundle_id, activity_id):
- activity = self.get_activity(activity_id)
- if activity:
- activity.present()
- else:
- activity_ps = self._pservice.get_activity(activity_id)
-
- if activity_ps:
- activity = ActivityFactory.create(bundle_id)
- activity.join(activity_ps.object_path())
- else:
- logging.error('Cannot start activity.')
-
- def start_activity(self, activity_type):
- activity = ActivityFactory.create(activity_type)
- activity.execute('test', [])
- return activity