From 50197627605391e120ba174f0ca62975cf2c9d32 Mon Sep 17 00:00:00 2001
From: Sascha Silbe <sascha@silbe.org>
Date: Mon, 24 Aug 2009 19:20:45 +0200
Subject: [PATCH] add technical details to details view in Journal
---
src/jarabe/journal/expandedentry.py | 36 +++++++++++++++++++++++++++++++++++
src/jarabe/journal/model.py | 15 ++++++++++++++
2 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
index 88c0b41..924f872 100644
a
|
b
|
|
17 | 17 | import logging |
18 | 18 | from gettext import gettext as _ |
19 | 19 | import StringIO |
| 20 | import time |
20 | 21 | |
21 | 22 | import hippo |
22 | 23 | import cairo |
… |
… |
from sugar.graphics.icon import CanvasIcon |
29 | 30 | from sugar.graphics.xocolor import XoColor |
30 | 31 | from sugar.graphics.entry import CanvasEntry |
31 | 32 | from sugar.graphics.canvastextview import CanvasTextView |
| 33 | from sugar.util import format_size |
32 | 34 | |
33 | 35 | from jarabe.journal.keepicon import KeepIcon |
34 | 36 | from jarabe.journal.palettes import ObjectPalette, BuddyPalette |
… |
… |
class ExpandedEntry(hippo.CanvasBox): |
118 | 120 | self._preview = self._create_preview() |
119 | 121 | first_column.append(self._preview) |
120 | 122 | |
| 123 | technical_box = self._create_technical() |
| 124 | first_column.append(technical_box) |
| 125 | |
121 | 126 | # Second column |
122 | 127 | |
123 | 128 | description_box, self._description = self._create_description() |
… |
… |
class ExpandedEntry(hippo.CanvasBox): |
216 | 221 | box.append(preview_box) |
217 | 222 | return box |
218 | 223 | |
| 224 | def _create_technical(self): |
| 225 | vbox = hippo.CanvasBox() |
| 226 | vbox.props.spacing = style.DEFAULT_SPACING |
| 227 | |
| 228 | lines = [ |
| 229 | _('Kind: %s') % (self._metadata.get('mime_type') or _('Unknown'),), |
| 230 | _('Date: %s') % (self._format_date(),), |
| 231 | _('Size: %s') % (format_size(model.get_file_size(self._metadata['uid'])),), |
| 232 | ] |
| 233 | |
| 234 | for line in lines: |
| 235 | text = hippo.CanvasText(text=line, |
| 236 | font_desc=style.FONT_NORMAL.get_pango_desc()) |
| 237 | text.props.color = style.COLOR_BUTTON_GREY.get_int() |
| 238 | |
| 239 | if gtk.widget_get_default_direction() == gtk.TEXT_DIR_RTL: |
| 240 | text.props.xalign = hippo.ALIGNMENT_END |
| 241 | else: |
| 242 | text.props.xalign = hippo.ALIGNMENT_START |
| 243 | |
| 244 | vbox.append(text) |
| 245 | |
| 246 | return vbox |
| 247 | |
| 248 | def _format_date(self): |
| 249 | if 'timestamp' in self._metadata: |
| 250 | timestamp = float(self._metadata['timestamp']) |
| 251 | return time.strftime('%x', time.localtime(timestamp)) |
| 252 | else: |
| 253 | return _('No date') |
| 254 | |
219 | 255 | def _create_buddy_list(self): |
220 | 256 | |
221 | 257 | vbox = hippo.CanvasBox() |
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index 506c8ac..5668dc5 100644
a
|
b
|
def get_file(object_id): |
394 | 394 | else: |
395 | 395 | return None |
396 | 396 | |
| 397 | def get_file_size(object_id): |
| 398 | """Return the file size for an object |
| 399 | """ |
| 400 | logging.debug('get_file_size %r', object_id) |
| 401 | if os.path.exists(object_id): |
| 402 | return os.stat(object_id).st_size |
| 403 | |
| 404 | file_path = dbus_helpers.get_filename(object_id) |
| 405 | if file_path: |
| 406 | size = os.stat(file_path).st_size |
| 407 | os.remove(file_path) |
| 408 | return size |
| 409 | |
| 410 | return 0 |
| 411 | |
397 | 412 | def get_unique_values(key): |
398 | 413 | """Returns a list with the different values a property has taken |
399 | 414 | """ |