From f04bad9371a81749ae7ce8f7a7b0694f0a4931dc Mon Sep 17 00:00:00 2001
Message-Id: <f04bad9371a81749ae7ce8f7a7b0694f0a4931dc.1278225682.git.andresambrois@gmail.com>
In-Reply-To: <cover.1278225681.git.andresambrois@gmail.com>
References: <cover.1278225681.git.andresambrois@gmail.com>
From: =?UTF-8?q?Andr=C3=A9s=20Ambrois?= <andresambrois@gmail.com>
Date: Fri, 2 Jul 2010 03:40:10 -0300
Subject: [PATCH v2 4/7] Add ctime property to the index and datastore
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


Signed-off-by: Andrés Ambrois <andresambrois@gmail.com>
---
 src/carquinyol/datastore.py  |    4 ++++
 src/carquinyol/indexstore.py |    8 ++++++++
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 357591f..73e2d74 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -42,6 +42,8 @@ DS_SERVICE = "org.laptop.sugar.DataStore"
 DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore"
 DS_OBJECT_PATH = "/org/laptop/sugar/DataStore"
 
+CTIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
+
 logger = logging.getLogger(DS_LOG_CHANNEL)
 
 
@@ -164,6 +166,8 @@ class DataStore(dbus.service.Object):
 
         if not props.get('timestamp', ''):
             props['timestamp'] = int(time.time())
+        if not props.get('ctime', ''):
+            props['ctime'] = time.strftime(CTIME_FORMAT, time.localtime())
 
         if os.path.exists(file_path):
             stat = os.stat(file_path)
diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
index 1b32a01..29d9590 100644
--- a/src/carquinyol/indexstore.py
+++ b/src/carquinyol/indexstore.py
@@ -30,6 +30,7 @@ _VALUE_TIMESTAMP = 1
 _VALUE_TITLE = 2
 # 3 reserved for version support
 _VALUE_FILESIZE = 4
+_VALUE_CTIME = 5
 
 _PREFIX_NONE = 'N'
 _PREFIX_FULL_VALUE = 'F'
@@ -60,6 +61,7 @@ _QUERY_TERM_MAP = {
 _QUERY_VALUE_MAP = {
     'timestamp': {'number': _VALUE_TIMESTAMP, 'type': float},
     'filesize': {'number': _VALUE_FILESIZE, 'type': int},
+    'ctime': {'number': _VALUE_CTIME, 'type': str},
 }
 
 
@@ -76,6 +78,8 @@ class TermGenerator (xapian.TermGenerator):
             except ValueError:
                 logging.debug('Invalid value for filesize property: %s',
                               properties['filesize'])
+        if 'ctime' in properties:
+            document.add_value(_VALUE_CTIME, properties['ctime'])
 
         self.set_document(document)
 
@@ -290,6 +294,10 @@ class IndexStore(object):
             enquire.set_sort_by_value(_VALUE_TIMESTAMP, True)
         elif order_by == '-timestamp':
             enquire.set_sort_by_value(_VALUE_TIMESTAMP, False)
+        elif order_by == '+ctime':
+            enquire.set_sort_by_value(_VALUE_CTIME, True)
+        elif order_by == '-ctime':
+            enquire.set_sort_by_value(_VALUE_CTIME, False)
         elif order_by == '+title':
             enquire.set_sort_by_value(_VALUE_TITLE, True)
         elif order_by == '-title':
-- 
1.7.0.4

