Revert "Make ShellModel emit signals on activity change, and make Owner listen for them. Fix Owner's current activity update code to actually update at the correct interval"

This reverts 906f5bbed0 commit.
This commit is contained in:
Ian Bicking 2006-09-27 16:51:56 -05:00
parent 906f5bbed0
commit 56281c804f
2 changed files with 15 additions and 30 deletions

View File

@ -2,7 +2,6 @@ import os
import random import random
import base64 import base64
import time import time
import gobject
import conf import conf
from sugar import env from sugar import env
@ -19,12 +18,9 @@ class ShellOwner(object):
"""Class representing the owner of this machine/instance. This class """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 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.""" server portion of the Owner, paired with the client portion in Buddy.py."""
def __init__(self, shell_model): def __init__(self):
profile = conf.get_profile() profile = conf.get_profile()
self._shell_model = shell_model
self._shell_model.connect('activity-changed', self.__activity_changed_cb)
self._nick = profile.get_nick_name() self._nick = profile.get_nick_name()
user_dir = profile.get_path() user_dir = profile.get_path()
@ -82,33 +78,29 @@ class ShellOwner(object):
def __update_advertised_current_activity_cb(self): def __update_advertised_current_activity_cb(self):
self._last_activity_update = time.time() self._last_activity_update = time.time()
self._pending_activity_update_timer = None self._pending_activity_update_timer = None
actid = self._pending_activity_update if self._pending_activity_update:
if not actid: logging.debug("*** Updating current activity to %s" % self._pending_activity_update)
actid = "" self._service.set_published_value('curact', dbus.String(self._pending_activity_update))
self._service.set_published_value('curact', dbus.String(actid))
return False return False
def __activity_changed_cb(self, shell_model, activity_id): def set_current_activity(self, activity_id):
"""Update our presence service with the latest activity, but no """Update our presence service with the latest activity, but no
more frequently than every 30 seconds""" more frequently than every 30 seconds"""
if activity_id == self._pending_activity_update:
return
self._pending_activity_update = activity_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)
if not self._pending_activity_update_timer or time.time() - self._last_activity_update > 30:
self.__update_advertised_current_activity_cb()
return
# If we have a pending update already, we have nothing left to do # If we have a pending update already, we have nothing left to do
if self._pending_activity_update_timer: if self._pending_activity_update_timer:
return return
# 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)
if time.time() - self._last_activity_update > 30:
self.__update_advertised_current_activity_cb()
return
# Otherwise, we start a timer to update the activity at the next # Otherwise, we start a timer to update the activity at the next
# interval, which should be 30 seconds from the last update, or if that # interval, which should be 30 seconds from the last update, or if that
# is in the past already, then now # is in the past already, then now
next = int(30 - max(0, time.time() - self._last_activity_update)) next = 30 - max(30, time.time() - self._last_activity_update)
self._pending_activity_update_timer = gobject.timeout_add(next * 1000, self._pending_activity_update_timer = gobject.timeout_add(next * 1000,
self.__update_advertised_current_activity_cb) self.__update_advertised_current_activity_cb)

View File

@ -2,22 +2,15 @@ from sugar.presence import PresenceService
from model.Friends import Friends from model.Friends import Friends
from model.MeshModel import MeshModel from model.MeshModel import MeshModel
from model.Owner import ShellOwner from model.Owner import ShellOwner
import gobject
class ShellModel(gobject.GObject):
__gsignals__ = {
'activity-changed': (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT]))
}
class ShellModel:
def __init__(self): def __init__(self):
gobject.GObject.__init__(self)
self._current_activity = None self._current_activity = None
PresenceService.start() PresenceService.start()
self._pservice = PresenceService.get_instance() self._pservice = PresenceService.get_instance()
self._owner = ShellOwner(self) self._owner = ShellOwner()
self._owner.announce() self._owner.announce()
self._friends = Friends() self._friends = Friends()
self._mesh = MeshModel() self._mesh = MeshModel()
@ -36,7 +29,7 @@ class ShellModel(gobject.GObject):
def set_current_activity(self, activity_id): def set_current_activity(self, activity_id):
self._current_activity = activity_id self._current_activity = activity_id
self.emit('activity-changed', activity_id) self._owner.set_current_activity(activity_id)
def get_current_activity(self): def get_current_activity(self):
return self._current_activity return self._current_activity