Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorIan Bicking <ianb@lothlorien.localdomain>2006-09-27 21:51:56 (GMT)
committer Ian Bicking <ianb@lothlorien.localdomain>2006-09-27 21:51:56 (GMT)
commit56281c804f99d6bb5381e710260e1bb88ff67313 (patch)
treeb7616acbe71ba7ee5f8aec18289753805d1cec27 /shell
parent906f5bbed0c2199d738f6f4b0b28a398afa8054b (diff)
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 906f5bbed0c2199d738f6f4b0b28a398afa8054b commit.
Diffstat (limited to 'shell')
-rw-r--r--shell/model/Owner.py30
-rw-r--r--shell/model/ShellModel.py13
2 files changed, 14 insertions, 29 deletions
diff --git a/shell/model/Owner.py b/shell/model/Owner.py
index ec62ba5..3bf3a55 100644
--- a/shell/model/Owner.py
+++ b/shell/model/Owner.py
@@ -2,7 +2,6 @@ import os
import random
import base64
import time
-import gobject
import conf
from sugar import env
@@ -19,12 +18,9 @@ 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_model):
+ def __init__(self):
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()
user_dir = profile.get_path()
@@ -82,33 +78,29 @@ class ShellOwner(object):
def __update_advertised_current_activity_cb(self):
self._last_activity_update = time.time()
self._pending_activity_update_timer = None
- actid = self._pending_activity_update
- if not actid:
- actid = ""
- self._service.set_published_value('curact', dbus.String(actid))
+ if self._pending_activity_update:
+ logging.debug("*** Updating current activity to %s" % self._pending_activity_update)
+ self._service.set_published_value('curact', dbus.String(self._pending_activity_update))
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
more frequently than every 30 seconds"""
- if activity_id == self._pending_activity_update:
- return
self._pending_activity_update = activity_id
-
- # If we have a pending update already, we have nothing left to do
- if self._pending_activity_update_timer:
- 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:
+ 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 self._pending_activity_update_timer:
+ return
+
# 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
# 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.__update_advertised_current_activity_cb)
diff --git a/shell/model/ShellModel.py b/shell/model/ShellModel.py
index 024fd53..9b6d598 100644
--- a/shell/model/ShellModel.py
+++ b/shell/model/ShellModel.py
@@ -2,22 +2,15 @@ from sugar.presence import PresenceService
from model.Friends import Friends
from model.MeshModel import MeshModel
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):
- gobject.GObject.__init__(self)
self._current_activity = None
PresenceService.start()
self._pservice = PresenceService.get_instance()
- self._owner = ShellOwner(self)
+ self._owner = ShellOwner()
self._owner.announce()
self._friends = Friends()
self._mesh = MeshModel()
@@ -36,7 +29,7 @@ class ShellModel(gobject.GObject):
def set_current_activity(self, 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):
return self._current_activity