Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/journal/objectmodel.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/jarabe/journal/objectmodel.py')
-rw-r--r--src/jarabe/journal/objectmodel.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/jarabe/journal/objectmodel.py b/src/jarabe/journal/objectmodel.py
new file mode 100644
index 0000000..621f261
--- /dev/null
+++ b/src/jarabe/journal/objectmodel.py
@@ -0,0 +1,76 @@
+# Copyright (C) 2009, Aleksey Lim
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import gtk
+import cairo
+import gobject
+import logging
+
+from sugar import util
+
+from jarabe.journal import misc
+from jarabe.journal.source import Source
+from jarabe.journal.browse.lazymodel import LazyModel
+
+class ObjectModel(LazyModel):
+ def __init__(self):
+ LazyModel.__init__(self, Source.FIELDS_BASE, Source.FIELDS_CALC)
+ self._fetch_queue = []
+ self._object_delayed_fetch_handle = None
+
+ def on_calc_value(self, row, column):
+ if column == Source.FIELD_MODIFY_TIME:
+ return util.timestamp_to_elapsed_string(
+ int(row[Source.FIELD_TIMESTAMP]) or 0)
+
+ if column == Source.FIELD_THUMB:
+ row = self.fetch_metadata(row)
+ if row is not None:
+ return
+ return None
+
+ return None
+
+ def fetch_metadata(self, row, force=False):
+ if row.has_key(Source.FIELD_FETCHED):
+ return row
+
+ if row not in self._fetch_queue:
+ self._fetch_queue.append(row)
+ if len(self._fetch_queue) == 1:
+ gobject.idle_add(self.__idle_cb, force)
+
+ def __idle_cb(self, force):
+ while len(self._fetch_queue):
+ row = self._fetch_queue[0]
+ if force or self.in_frame(row.path[0]):
+ self.source.get_object(row, self.__get_object_cb)
+ break
+ del self._fetch_queue[0]
+ return False
+
+ def __get_object_cb(self, metadata):
+ row = self._fetch_queue[0]
+ del self._fetch_queue[0]
+
+ if metadata is not None:
+ row[Source.FIELD_THUMB] = misc.load_preview(metadata)
+ row.metadata.update(metadata)
+ row[Source.FIELD_FETCHED] = True
+ self.emit('row-changed', row.path, row.iter)
+
+ if len(self._fetch_queue):
+ self.__idle_cb(False)