Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ src/jarabe/journal/volumestoolbar.py
src/jarabe/journal/iconmodel.py
src/jarabe/journal/iconview.py
src/jarabe/journal/projectview.py
src/jarabe/journal/timeline.py
src/jarabe/model/desktop.py
src/jarabe/model/network.py
src/jarabe/model/screenshot.py
Expand Down
1 change: 1 addition & 0 deletions src/jarabe/journal/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ sugar_PYTHON = \
model.py \
objectchooser.py \
projectview.py \
timeline.py \
palettes.py \
volumestoolbar.py
62 changes: 49 additions & 13 deletions src/jarabe/journal/listmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from jarabe.journal import model
from jarabe.journal import misc
from jarabe.journal import timeline


DS_DBUS_SERVICE = 'org.laptop.sugar.DataStore'
Expand Down Expand Up @@ -78,6 +79,7 @@ def __init__(self, query):
self._last_requested_index = None
self._temp_drag_file_uid = None
self._cached_row = None
self._row_facts = {}
self._query = query
self._all_ids = []
t = time.time()
Expand Down Expand Up @@ -139,9 +141,10 @@ def set_value(self, iterator, column, value):
if column == ListModel.COLUMN_TITLE:
metadata['title'] = value
self._updated_entries[metadata['uid']] = metadata
# The edit must survive a re-read of this same row: the row
# cache was primed by the read that preceded this write.
# The edit must survive a re-read of this same row: both row
# caches were primed by the read that preceded this write.
self._last_requested_index = None
self._row_facts.pop(index, None)
if self._updated_callback is not None:
model.updated.disconnect(self._updated_callback)
model.write(metadata, update_mtime=False,
Expand All @@ -151,6 +154,35 @@ def __reconnect_updates_cb(self, metadata, filepath, uid):
if self._updated_callback is not None:
model.updated.connect(self._updated_callback)

def get_row_facts(self, index):
facts = self._row_facts.get(index)
if facts is not None:
return facts
if self.view_is_resizing or index >= self._result_set.length:
return None
self._result_set.seek(index)
metadata = self._result_set.read()
metadata.update(self._updated_entries.get(metadata['uid'], {}))
return self._remember_row_facts(index, metadata)

def get_row_metadata(self, index):
if self.view_is_resizing or index >= self._result_set.length:
return None
self._result_set.seek(index)
metadata = self._result_set.read()
metadata.update(self._updated_entries.get(metadata['uid'], {}))
return dict(metadata)

def _remember_row_facts(self, index, metadata):
timestamp = timeline.safe_timestamp(metadata.get('timestamp', 0))
# sugar-datastore backfills creation_time = timestamp on create/update.
creation_time = timeline.safe_timestamp(
metadata.get('creation_time', timestamp), default=timestamp)
facts = (metadata['uid'], timestamp, misc.get_sitting_key(metadata),
creation_time)
self._row_facts[index] = facts
return facts

def do_get_value(self, iterator, column):
if self.view_is_resizing:
return None
Expand All @@ -165,6 +197,7 @@ def do_get_value(self, iterator, column):
self._result_set.seek(index)
metadata = self._result_set.read()
metadata.update(self._updated_entries.get(metadata['uid'], {}))
facts = self._remember_row_facts(index, metadata)

row = []
row.append(metadata['uid'])
Expand All @@ -188,21 +221,24 @@ def do_get_value(self, iterator, column):
title = GObject.markup_escape_text(title_value)
row.append('<b>%s</b>' % (title, ))

try:
timestamp = float(metadata.get('timestamp', 0))
except (TypeError, ValueError):
timestamp_content = _('Unknown')
else:
# A bare float() lets 'nan' and 'inf' through as truthy;
# util.timestamp_to_elapsed_string raises ValueError on
# both, since int() can't convert a float NaN to an
# integer. A falsy timestamp shows the same "no date"
# string as expandedentry.py's _format_date, instead of a
# false elapsed time.
timestamp = facts[1]
if timestamp:
timestamp_content = util.timestamp_to_elapsed_string(timestamp)
else:
timestamp_content = _('No date')
row.append(timestamp_content)

try:
creation_time = float(metadata.get('creation_time'))
except (TypeError, ValueError):
row.append(_('Unknown'))
creation_time = facts[3]
if creation_time:
row.append(util.timestamp_to_elapsed_string(creation_time))
else:
row.append(
util.timestamp_to_elapsed_string(float(creation_time)))
row.append(_('No date'))

try:
size = int(metadata.get('filesize'))
Expand Down
5 changes: 5 additions & 0 deletions src/jarabe/journal/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ def get_icon_name(metadata):
return file_name


def get_sitting_key(metadata):
"""Key identifying which sitting an entry belongs to."""
return metadata.get('activity', '') or get_icon_name(metadata)


def get_date(metadata):
""" Convert from a string in iso format to a more human-like format. """
if 'timestamp' in metadata:
Expand Down
Loading