Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/jarabe/journal/expandedentry.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/jarabe/journal/expandedentry.py')
-rw-r--r--src/jarabe/journal/expandedentry.py82
1 files changed, 42 insertions, 40 deletions
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
index ebf3385..7ffded2 100644
--- a/src/jarabe/journal/expandedentry.py
+++ b/src/jarabe/journal/expandedentry.py
@@ -26,7 +26,7 @@ from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import Gdk
-import simplejson
+import json
from sugar3.graphics import style
from sugar3.graphics.xocolor import XoColor
@@ -45,7 +45,8 @@ from jarabe.journal import journalwindow
class Separator(Gtk.VBox):
def __init__(self, orientation):
Gtk.VBox.__init__(self,
- background_color=style.COLOR_PANEL_GREY.get_gdk_color())
+ background_color=
+ style.COLOR_PANEL_GREY.get_gdk_color())
class BuddyList(Gtk.Alignment):
@@ -92,14 +93,16 @@ class CommentsView(Gtk.TreeView):
def __init__(self):
Gtk.TreeView.__init__(self)
+ self.set_headers_visible(False)
self._store = Gtk.ListStore(str, object, str, str, str, object)
self._comments = []
self._init_model()
def update_comments(self, comments):
self._store.clear()
+
if comments:
- self._comments = simplejson.loads(comments)
+ self._comments = json.loads(comments)
for comment in self._comments:
self._add_row(comment.get(self.FROM, ''),
comment.get(self.MESSAGE, ''),
@@ -120,7 +123,7 @@ class CommentsView(Gtk.TreeView):
def _init_model(self):
self.set_model(self._store)
- col = Gtk.TreeViewColumn(_('Comments:'))
+ col = Gtk.TreeViewColumn()
who_icon = CellRendererCommentIcon(self)
col.pack_start(who_icon, False)
@@ -139,7 +142,8 @@ class CommentsView(Gtk.TreeView):
erase_icon.connect('clicked', self._erase_comment_cb)
col.pack_start(erase_icon, False)
col.add_attribute(erase_icon, 'file-name', self.COMMENT_ERASE_ICON)
- col.add_attribute(erase_icon, 'xo-color', self.COMMENT_ERASE_ICON_COLOR)
+ col.add_attribute(
+ erase_icon, 'xo-color', self.COMMENT_ERASE_ICON_COLOR)
self.append_column(col)
@@ -167,19 +171,22 @@ class CommentsView(Gtk.TreeView):
def _erase_alert_response_cb(self, alert, response_id, entry):
journalwindow.get_journal_window().remove_alert(alert)
+
if response_id is Gtk.ResponseType.OK:
self._store.remove(entry)
+
# Regenerate comments from current contents of store
self._comments = []
for entry in self._store:
self._comments.append({
- self.FROM: entry[self.COMMENT_FROM],
- self.MESSAGE: entry[self.COMMENT_MESSAGE],
- self.ICON: entry[self.COMMENT_ICON],
- self.ICON_COLOR: '[%s]' % (
- entry[self.COMMENT_ICON_COLOR].to_string()),
- })
- self.emit('comments-changed', simplejson.dumps(self._comments))
+ self.FROM: entry[self.COMMENT_FROM],
+ self.MESSAGE: entry[self.COMMENT_MESSAGE],
+ self.ICON: entry[self.COMMENT_ICON],
+ self.ICON_COLOR: '[%s]' % (
+ entry[self.COMMENT_ICON_COLOR].to_string()),
+ })
+
+ self.emit('comments-changed', json.dumps(self._comments))
class CellRendererCommentIcon(CellRendererIcon):
@@ -195,7 +202,6 @@ class CellRendererCommentIcon(CellRendererIcon):
class ExpandedEntry(Gtk.EventBox):
-
def __init__(self):
Gtk.EventBox.__init__(self)
self._vbox = Gtk.VBox()
@@ -282,7 +288,7 @@ class ExpandedEntry(Gtk.EventBox):
self._icon = self._create_icon()
for child in self._icon_box.get_children():
self._icon_box.remove(child)
- #FIXME: self._icon_box.foreach(self._icon_box.remove)
+ # FIXME: self._icon_box.foreach(self._icon_box.remove)
self._icon_box.pack_start(self._icon, False, False, 0)
self._date.set_text(misc.get_date(metadata))
@@ -295,13 +301,13 @@ class ExpandedEntry(Gtk.EventBox):
for child in self._technical_box.get_children():
self._technical_box.remove(child)
- #FIXME: self._technical_box.foreach(self._technical_box.remove)
+ # FIXME: self._technical_box.foreach(self._technical_box.remove)
self._technical_box.pack_start(self._create_technical(),
False, False, style.DEFAULT_SPACING)
for child in self._buddy_list.get_children():
self._buddy_list.remove(child)
- #FIXME: self._buddy_list.foreach(self._buddy_list.remove)
+ # FIXME: self._buddy_list.foreach(self._buddy_list.remove)
self._buddy_list.pack_start(self._create_buddy_list(), False, False,
style.DEFAULT_SPACING)
@@ -312,14 +318,6 @@ class ExpandedEntry(Gtk.EventBox):
comments = metadata.get('comments', '')
self._comments.update_comments(comments)
- def set_comments(self, comments):
- self._metadata['comments'] = comments
- self._comments.update_comments(comments)
- self._write_entry()
-
- def get_comments(self):
- return self._metadata.get('comments', None)
-
def _create_keep_icon(self):
keep_icon = KeepIcon()
keep_icon.connect('toggled', self._keep_icon_toggled_cb)
@@ -364,7 +362,7 @@ class ExpandedEntry(Gtk.EventBox):
# TODO: We are close to be able to drop this.
import base64
preview_data = base64.b64decode(
- self._metadata['preview'])
+ self._metadata['preview'])
png_file = StringIO.StringIO(preview_data)
try:
@@ -422,10 +420,11 @@ class ExpandedEntry(Gtk.EventBox):
lines = [
_('Kind: %s') % (self._metadata.get('mime_type') or _('Unknown'),),
_('Date: %s') % (self._format_date(),),
- _('Size: %s') % (format_size(int(self._metadata.get(
- 'filesize',
- model.get_file_size(self._metadata['uid'])))))
- ]
+ _('Size: %s') % (format_size(
+ int(self._metadata.get(
+ 'filesize',
+ model.get_file_size(self._metadata['uid'])))))
+ ]
for line in lines:
linebox = Gtk.HBox()
@@ -433,7 +432,7 @@ class ExpandedEntry(Gtk.EventBox):
text = Gtk.Label()
text.set_markup('<span foreground="%s">%s</span>' % (
- style.COLOR_BUTTON_GREY.get_html(), line))
+ style.COLOR_BUTTON_GREY.get_html(), line))
linebox.pack_start(text, False, False, 0)
return vbox
@@ -457,13 +456,13 @@ class ExpandedEntry(Gtk.EventBox):
text = Gtk.Label()
text.set_markup('<span foreground="%s">%s</span>' % (
- style.COLOR_BUTTON_GREY.get_html(), _('Participants:')))
+ style.COLOR_BUTTON_GREY.get_html(), _('Participants:')))
halign = Gtk.Alignment.new(0, 0, 0, 0)
halign.add(text)
vbox.pack_start(halign, False, False, 0)
if self._metadata.get('buddies'):
- buddies = simplejson.loads(self._metadata['buddies']).values()
+ buddies = json.loads(self._metadata['buddies']).values()
vbox.pack_start(BuddyList(buddies), False, False, 0)
return vbox
else:
@@ -476,7 +475,7 @@ class ExpandedEntry(Gtk.EventBox):
if label is not None:
text = Gtk.Label()
text.set_markup('<span foreground="%s">%s</span>' % (
- style.COLOR_BUTTON_GREY.get_html(), label))
+ style.COLOR_BUTTON_GREY.get_html(), label))
halign = Gtk.Alignment.new(0, 0, 0, 0)
halign.add(text)
@@ -505,13 +504,14 @@ class ExpandedEntry(Gtk.EventBox):
def _create_comments(self):
widget = CommentsView()
- widget.connect('comments-changed', self._update_comments_cb)
- return self._create_scrollable(widget), widget
+ widget.connect('comments-changed', self._comments_changed_cb)
+ return self._create_scrollable(widget, label=_('Comments:')), widget
def _title_notify_text_cb(self, entry, pspec):
if not self._update_title_sid:
- self._update_title_sid = GObject.timeout_add_seconds(1,
- self._update_title_cb)
+ self._update_title_sid = \
+ GObject.timeout_add_seconds(1,
+ self._update_title_cb)
def _title_focus_out_event_cb(self, entry, event):
self._update_entry()
@@ -519,8 +519,9 @@ class ExpandedEntry(Gtk.EventBox):
def _description_tags_focus_out_event_cb(self, text_view, event):
self._update_entry()
- def _update_comments_cb(self, event, comments):
- self.set_comments(comments)
+ def _comments_changed_cb(self, event, comments):
+ self._metadata['comments'] = comments
+ self._write_entry()
def _update_entry(self, needs_update=False):
if not model.is_editable(self._metadata):
@@ -563,7 +564,8 @@ class ExpandedEntry(Gtk.EventBox):
else:
old_file_path = os.path.join(
self._metadata['mountpoint'],
- model.get_file_name(old_title, self._metadata['mime_type']))
+ model.get_file_name(self._metadata['title'],
+ self._metadata['mime_type']))
model.write(self._metadata, file_path=old_file_path,
update_mtime=False)