From 85b833960ded9148fbb42e773720ba3bcb02145e Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Mon, 24 Aug 2009 17:20:45 +0000 Subject: add technical details to details view in Journal --- (limited to 'src') diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py index 88c0b41..924f872 100644 --- a/src/jarabe/journal/expandedentry.py +++ b/src/jarabe/journal/expandedentry.py @@ -17,6 +17,7 @@ import logging from gettext import gettext as _ import StringIO +import time import hippo import cairo @@ -29,6 +30,7 @@ from sugar.graphics.icon import CanvasIcon from sugar.graphics.xocolor import XoColor from sugar.graphics.entry import CanvasEntry from sugar.graphics.canvastextview import CanvasTextView +from sugar.util import format_size from jarabe.journal.keepicon import KeepIcon from jarabe.journal.palettes import ObjectPalette, BuddyPalette @@ -118,6 +120,9 @@ class ExpandedEntry(hippo.CanvasBox): self._preview = self._create_preview() first_column.append(self._preview) + technical_box = self._create_technical() + first_column.append(technical_box) + # Second column description_box, self._description = self._create_description() @@ -216,6 +221,37 @@ class ExpandedEntry(hippo.CanvasBox): box.append(preview_box) return box + def _create_technical(self): + vbox = hippo.CanvasBox() + vbox.props.spacing = style.DEFAULT_SPACING + + lines = [ + _('Kind: %s') % (self._metadata.get('mime_type') or _('Unknown'),), + _('Date: %s') % (self._format_date(),), + _('Size: %s') % (format_size(model.get_file_size(self._metadata['uid'])),), + ] + + for line in lines: + text = hippo.CanvasText(text=line, + font_desc=style.FONT_NORMAL.get_pango_desc()) + text.props.color = style.COLOR_BUTTON_GREY.get_int() + + if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: + text.props.xalign = hippo.ALIGNMENT_END + else: + text.props.xalign = hippo.ALIGNMENT_START + + vbox.append(text) + + return vbox + + def _format_date(self): + if 'timestamp' in self._metadata: + timestamp = float(self._metadata['timestamp']) + return time.strftime('%x', time.localtime(timestamp)) + else: + return _('No date') + def _create_buddy_list(self): vbox = hippo.CanvasBox() diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py index 15259bb..02ce26a 100644 --- a/src/jarabe/journal/model.py +++ b/src/jarabe/journal/model.py @@ -420,6 +420,21 @@ def get_file(object_id): else: return None +def get_file_size(object_id): + """Return the file size for an object + """ + logging.debug('get_file_size %r', object_id) + if os.path.exists(object_id): + return os.stat(object_id).st_size + + file_path = dbus_helpers.get_filename(object_id) + if file_path: + size = os.stat(file_path).st_size + os.remove(file_path) + return size + + return 0 + def get_unique_values(key): """Returns a list with the different values a property has taken """ -- cgit v0.9.1