Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/model/Owner.py
diff options
context:
space:
mode:
authorDan Williams <dcbw@localhost.localdomain>2006-09-27 21:00:12 (GMT)
committer Dan Williams <dcbw@localhost.localdomain>2006-09-27 21:00:12 (GMT)
commit906f5bbed0c2199d738f6f4b0b28a398afa8054b (patch)
tree9af2db3f878fb497cc2a439ba58246e6d74d1953 /shell/model/Owner.py
parent22be6cb0dafe115683240e495f1b61bda0e00a9d (diff)
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
Diffstat (limited to 'shell/model/Owner.py')
-rw-r--r--shell/model/Owner.py30
1 files changed, 19 insertions, 11 deletions
diff --git a/shell/model/Owner.py b/shell/model/Owner.py
index 3bf3a55..ec62ba5 100644
--- a/shell/model/Owner.py
+++ b/shell/model/Owner.py
@@ -2,6 +2,7 @@ import os
import random
import base64
import time
+import gobject
import conf
from sugar import env
@@ -18,9 +19,12 @@ 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):
+ def __init__(self, shell_model):
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()
@@ -78,29 +82,33 @@ class ShellOwner(object):
def __update_advertised_current_activity_cb(self):
self._last_activity_update = time.time()
self._pending_activity_update_timer = None
- 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))
+ actid = self._pending_activity_update
+ if not actid:
+ actid = ""
+ self._service.set_published_value('curact', dbus.String(actid))
return False
- def set_current_activity(self, activity_id):
+ def __activity_changed_cb(self, shell_model, 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 not self._pending_activity_update_timer or time.time() - self._last_activity_update > 30:
+ if 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 = 30 - max(30, time.time() - self._last_activity_update)
+ next = int(30 - max(0, time.time() - self._last_activity_update))
self._pending_activity_update_timer = gobject.timeout_add(next * 1000,
self.__update_advertised_current_activity_cb)