Cleanup shell model/view separation

This commit is contained in:
Marco Pesenti Gritti
2006-09-18 11:48:33 +02:00
parent 274dfbbf6a
commit 1f3187e0b5
6 changed files with 59 additions and 63 deletions
+3 -9
View File
@@ -16,7 +16,7 @@ class ShellOwner(object):
"""Class representing the owner of this machine/instance. This class
runs in the shell and serves up the buddy icon and other stuff. It's the
server portion of the Owner, paired with the client portion in Buddy.py."""
def __init__(self, shell):
def __init__(self):
profile = conf.get_profile()
self._nick = profile.get_nick_name()
@@ -35,8 +35,6 @@ class ShellOwner(object):
self._invites = Invites()
self._shell = shell
self._shell.connect('activity-changed', self.__activity_changed_cb)
self._last_activity_update = time.time()
self._pending_activity_update_timer = None
self._pending_activity_update = None
@@ -51,10 +49,6 @@ class ShellOwner(object):
# Create and announce our presence
color = conf.get_profile().get_color()
props = {'color':color.to_string()}
activity = self._shell.get_current_activity()
if activity is not None:
props['cur_activity':activity.get_id()]
self._last_activity_update = time.time()
self._service = self._pservice.register_service(self._nick,
PRESENCE_SERVICE_TYPE, properties=props)
logging.debug("Owner '%s' using port %d" % (self._nick, self._service.get_port()))
@@ -79,10 +73,10 @@ class ShellOwner(object):
logging.debug("*** Updating current activity to %s" % self._pending_activity_update)
return False
def __activity_changed_cb(self, shell, activity):
def set_current_activity(self, activity_id):
"""Update our presence service with the latest activity, but no
more frequently than every 30 seconds"""
self._pending_activity_update = activity.get_id()
self._pending_activity_update = activity_id
# If there's no pending update, we must not have updated it in the
# last 30 seconds (except for the initial update, hence we also check
# for the last update)
+5 -39
View File
@@ -1,29 +1,15 @@
import gobject
from sugar.presence import PresenceService
from model.Friends import Friends
from model.Owner import ShellOwner
class ShellModel(gobject.GObject):
__gsignals__ = {
'activity-opened': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
'activity-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])),
'activity-closed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
}
class ShellModel:
def __init__(self):
gobject.GObject.__init__(self)
self._hosts = {}
self._current_activity = None
PresenceService.start()
self._pservice = PresenceService.get_instance()
self._owner = ShellOwner(self)
self._owner = ShellOwner()
self._owner.announce()
self._friends = Friends()
@@ -36,29 +22,9 @@ class ShellModel(gobject.GObject):
def get_owner(self):
return self._owner
def add_activity(self, activity_host):
self._hosts[activity_host.get_xid()] = activity_host
self.emit('activity-opened', activity_host)
def set_current_activity(self, activity_xid):
activity_host = self._hosts[activity_xid]
if self._current_activity == activity_host:
return
self._current_activity = activity_host
self.emit('activity-changed', activity_host)
def remove_activity(self, activity_xid):
if self._hosts.has_key(activity_xid):
host = self._hosts[activity_xid]
self.emit('activity-closed', host)
del self._hosts[activity_xid]
def get_activity(self, activity_id):
for host in self._hosts.values():
if host.get_id() == activity_id:
return host
return None
def set_current_activity(self, activity_id):
self._current_activity = activity_id
self._owner.set_current_activity(activity_id)
def get_current_activity(self):
return self._current_activity