From d9cf67dd382b492e93549344273658860e2410ae Mon Sep 17 00:00:00 2001
From: Tomeu Vizoso <[EMAIL PROTECTED]>
Date: Mon, 19 May 2008 18:04:24 +0200
Subject: [PATCH] Add ActivityBundle.installation_time and format the date in the activity list

---
 service/activityregistryservice.py |    3 ++-
 src/view/home/activitieslist.py    |    4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/service/activityregistryservice.py b/service/activityregistryservice.py
index 7746877..bf98ef9 100644
--- a/service/activityregistryservice.py
+++ b/service/activityregistryservice.py
@@ -132,7 +132,8 @@ class ActivityRegistry(dbus.service.Object):
                 'path': bundle.get_path(),
                 'command': bundle.get_command(),
                 'show_launcher': bundle.get_show_launcher(),
-                'favorite': favorite}
+                'favorite': favorite,
+                'installation_time': bundle.get_installation_time()}
 
     def _bundle_added_cb(self, bundle_registry, bundle):
         self.ActivityAdded(self._bundle_to_dict(bundle))
diff --git a/src/view/home/activitieslist.py b/src/view/home/activitieslist.py
index ebdf1ec..48f16ee 100644
--- a/src/view/home/activitieslist.py
+++ b/src/view/home/activitieslist.py
@@ -20,6 +20,7 @@ import hippo
 
 from sugar import profile
 from sugar import activity
+from sugar import util
 from sugar.graphics import style
 from sugar.graphics.icon import CanvasIcon
 
@@ -134,7 +135,8 @@ class ActivityEntry(hippo.CanvasBox, hippo.CanvasItem):
         expander = hippo.CanvasBox()
         self.append(expander, hippo.PACK_EXPAND)
 
-        date = hippo.CanvasText(text='3 weeks ago',
+        timestamp = activity_info.installation_time
+        date = hippo.CanvasText(text=util.timestamp_to_elapsed_string(timestamp),
                                 xalign=hippo.ALIGNMENT_START,
                                 font_desc=style.FONT_NORMAL.get_pango_desc(),
                                 box_width=ActivityEntry._DATE_COL_WIDTH)
-- 
1.5.2.5

From 2c06e6be16492990601f51d25fbbedd4f0ab1a02 Mon Sep 17 00:00:00 2001
From: Tomeu Vizoso <[EMAIL PROTECTED]>
Date: Mon, 19 May 2008 18:03:04 +0200
Subject: [PATCH] Move timestamp_to_elapsed_string to sugar.util and add ActivityBundle.installation_time

---
 src/sugar/activity/registry.py     |    8 +++--
 src/sugar/bundle/activitybundle.py |    5 +++
 src/sugar/util.py                  |   69 ++++++++++++++++++++++++++++++++++++
 3 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/src/sugar/activity/registry.py b/src/sugar/activity/registry.py
index 5f5aefc..d5d0529 100644
--- a/src/sugar/activity/registry.py
+++ b/src/sugar/activity/registry.py
@@ -31,11 +31,12 @@ def _activity_info_from_dict(info_dict):
     return ActivityInfo(info_dict['name'], info_dict['icon'],
                         info_dict['bundle_id'], info_dict['version'],
                         info_dict['path'], info_dict['show_launcher'],
-                        info_dict['command'], info_dict['favorite'])
+                        info_dict['command'], info_dict['favorite'],
+                        info_dict['installation_time'])
 
 class ActivityInfo(object):
-    def __init__(self, name, icon, bundle_id, version,
-                 path, show_launcher, command, favorite):
+    def __init__(self, name, icon, bundle_id, version, path, show_launcher,
+                 command, favorite, installation_time):
         self.name = name
         self.icon = icon
         self.bundle_id = bundle_id
@@ -44,6 +45,7 @@ class ActivityInfo(object):
         self.command = command
         self.show_launcher = show_launcher
         self.favorite = favorite
+        self.installation_time = installation_time
 
 class ActivityRegistry(gobject.GObject):
     __gsignals__ = {
diff --git a/src/sugar/bundle/activitybundle.py b/src/sugar/bundle/activitybundle.py
index 5f1fb7b..db30555 100644
--- a/src/sugar/bundle/activitybundle.py
+++ b/src/sugar/bundle/activitybundle.py
@@ -163,6 +163,11 @@ class ActivityBundle(Bundle):
         """Get the activity user visible name."""
         return self._name
 
+    def get_installation_time(self):
+        """Get a timestamp representing the time at which this activity was
+        installed."""
+        return os.stat(self._path).st_mtime
+
     def get_bundle_id(self):
         """Get the activity bundle id"""
         return self._bundle_id
diff --git a/src/sugar/util.py b/src/sugar/util.py
index 12f6824..f885523 100644
--- a/src/sugar/util.py
+++ b/src/sugar/util.py
@@ -21,6 +21,8 @@ import sha
 import random
 import binascii
 import string
+from gettext import gettext as _
+import gettext
 
 def printable_hash(in_hash):
     """Convert binary hash data into printable characters."""
@@ -168,3 +170,70 @@ class LRU:
             yield j
     def keys(self):
         return self.d.keys()
+
+units = [['%d year',   '%d years',   356 * 24 * 60 * 60],
+         ['%d month',  '%d months',  30 * 24 * 60 * 60],
+         ['%d week',   '%d weeks',   7 * 24 * 60 * 60],
+         ['%d day',    '%d days',    24 * 60 * 60],
+         ['%d hour',   '%d hours',   60 * 60],
+         ['%d minute', '%d minutes', 60]]
+
+AND = _(' and ')
+COMMA = _(', ')
+
+# TRANS: Indicating something that just happened, eg. "just now", "moments ago"
+NOW = _('Seconds ago')
+
+# TRANS: Indicating time passed, eg. "[10 day, 5 hours] ago",
+# "[2 minutes] in the past", or "[3 years, 1 month] earlier"
+ELAPSED = _('%s ago')
+
+# Explanation of the following hack:
+# The xgettext utility extracts plural forms by reading the strings included as
+# parameters of ngettext(). As our plurals are not passed to ngettext()
+# straight away because there needs to be a calculation before we know which
+# strings need to be used, then we need to call ngettext() in a fake way so
+# xgettext will pick them up as plurals.
+
+def ngettext(singular, plural, n): pass
+
+# TRANS: Relative dates (eg. 1 month and 5 days).
+ngettext('%d year',   '%d years',   1)
+ngettext('%d month',  '%d months',  1)
+ngettext('%d week',   '%d weeks',   1)
+ngettext('%d day',    '%d days',    1)
+ngettext('%d hour',   '%d hours',   1)
+ngettext('%d minute', '%d minutes', 1)
+
+del ngettext
+
+# End of plurals hack
+
+def timestamp_to_elapsed_string(timestamp, max_levels=2):
+    levels = 0
+    time_period = ''
+    elapsed_seconds = int(time.time() - timestamp)
+
+    for name_singular, name_plural, factor in units:
+        elapsed_units = elapsed_seconds / factor
+        if elapsed_units > 0:
+
+            if levels > 0:
+                time_period += COMMA
+
+            time_period += gettext.ngettext(name_singular, name_plural,
+                                            elapsed_units) % elapsed_units
+
+            elapsed_seconds -= elapsed_units * factor
+
+        if time_period != '':
+            levels += 1
+
+        if levels == max_levels:
+            break
+
+    if levels == 0:
+        return NOW
+
+    return ELAPSED % time_period
+
-- 
1.5.2.5

From 1dc714e5ba7cb5e9d070f861e1aee266c834ff9b Mon Sep 17 00:00:00 2001
From: Tomeu Vizoso <[EMAIL PROTECTED]>
Date: Mon, 19 May 2008 18:01:41 +0200
Subject: [PATCH] Move timestamp_to_elapsed_string to sugar.util

---
 misc.py |   76 +++-----------------------------------------------------------
 1 files changed, 4 insertions(+), 72 deletions(-)

diff --git a/misc.py b/misc.py
index 9d3ecb8..8d476c7 100644
--- a/misc.py
+++ b/misc.py
@@ -14,8 +14,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
-from gettext import gettext as _
-import gettext
 import logging
 import time
 import traceback
@@ -30,7 +28,7 @@ from sugar.bundle.activitybundle import ActivityBundle
 from sugar.bundle.contentbundle import ContentBundle
 from sugar.bundle.bundle import MalformedBundleException, \
      ZipExtractException, RegistrationException
-from sugar.util import LRU
+from sugar import util
 
 from journalentrybundle import JournalEntryBundle
 
@@ -45,7 +43,7 @@ def _get_icon_file_name(icon_name):
     del info
     return fname
 
-_icon_cache = LRU(50)
+_icon_cache = util.LRU(50)
 
 def get_icon_name(jobject):
 
@@ -83,79 +81,13 @@ def get_icon_name(jobject):
 
     return file_name
 
-# TRANS: Relative dates (eg. 1 month and 5 days).
-units = [['%d year',   '%d years',   356 * 24 * 60 * 60],
-         ['%d month',  '%d months',  30 * 24 * 60 * 60],
-         ['%d week',   '%d weeks',   7 * 24 * 60 * 60],
-         ['%d day',    '%d days',    24 * 60 * 60],
-         ['%d hour',   '%d hours',   60 * 60],
-         ['%d minute', '%d minutes', 60]]
-
-AND = _(' and ')
-COMMA = _(', ')
-
-# TRANS: Indicating something that just happened, eg. "just now", "moments ago"
-NOW = _('Seconds ago')
-
-# TRANS: Indicating time passed, eg. "[10 day, 5 hours] ago",
-# "[2 minutes] in the past", or "[3 years, 1 month] earlier"
-ELAPSED = _('%s ago')
-
-# Explanation of the following hack:
-# The xgettext utility extracts plural forms by reading the strings included as
-# parameters of ngettext(). As our plurals are not passed to ngettext()
-# straight away because there needs to be a calculation before we know which
-# strings need to be used, then we need to call ngettext() in a fake way so
-# xgettext will pick them up as plurals.
-
-def ngettext(singular, plural, n): pass
-
-ngettext('%d year',   '%d years',   1)
-ngettext('%d month',  '%d months',  1)
-ngettext('%d week',   '%d weeks',   1)
-ngettext('%d day',    '%d days',    1)
-ngettext('%d hour',   '%d hours',   1)
-ngettext('%d minute', '%d minutes', 1)
-
-del ngettext
-
-# End of plurals hack
-
-def _get_elapsed_string(timestamp, max_levels=2):
-    levels = 0
-    time_period = ''
-    elapsed_seconds = int(time.time() - timestamp)
-
-    for name_singular, name_plural, factor in units:
-        elapsed_units = elapsed_seconds / factor
-        if elapsed_units > 0:
-
-            if levels > 0:
-                time_period += COMMA
-
-            time_period += gettext.ngettext(name_singular, name_plural,
-                                            elapsed_units) % elapsed_units
-
-            elapsed_seconds -= elapsed_units * factor
-
-        if time_period != '':
-            levels += 1
-
-        if levels == max_levels:
-            break
-
-    if levels == 0:
-        return NOW
-
-    return ELAPSED % time_period
-
 def get_date(jobject):
     """ Convert from a string in iso format to a more human-like format. """
     if jobject.metadata.has_key('timestamp'):
-        return _get_elapsed_string(jobject.metadata['timestamp'])
+        return util.timestamp_to_elapsed_string(jobject.metadata['timestamp'])
     elif jobject.metadata.has_key('mtime'):
         ti = time.strptime(jobject.metadata['mtime'], "%Y-%m-%dT%H:%M:%S")
-        return _get_elapsed_string(time.mktime(ti))
+        return util.timestamp_to_elapsed_string(time.mktime(ti))
     else:
         return _('No date')
 
-- 
1.5.2.5

_______________________________________________
Sugar mailing list
Sugar@lists.laptop.org
http://lists.laptop.org/listinfo/sugar

Reply via email to