Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2013-03-30 14:28:03 (GMT)
committer Walter Bender <walter.bender@gmail.com>2013-03-30 14:28:03 (GMT)
commit650b188365e14538badab3e416dfc1012e108c70 (patch)
tree821d6a1bd492d15ead7a0ffd2d1bd0445cfd9554
parent0b5e199e01760bbb79b85d6dd188d072af0a9969 (diff)
clean up of comment code
-rw-r--r--extensions/web/facebook/facebook_online_account.py16
-rw-r--r--extensions/web/twitter/twitter_online_account.py26
-rw-r--r--src/jarabe/journal/expandedentry.py51
-rw-r--r--src/jarabe/journal/journaltoolbox.py3
-rw-r--r--src/jarabe/web/online_account.py34
5 files changed, 81 insertions, 49 deletions
diff --git a/extensions/web/facebook/facebook_online_account.py b/extensions/web/facebook/facebook_online_account.py
index a0054d2..ecf654f 100644
--- a/extensions/web/facebook/facebook_online_account.py
+++ b/extensions/web/facebook/facebook_online_account.py
@@ -109,11 +109,11 @@ class FacebookOnlineAccount(online_account.OnlineAccount):
return self._client.get_string(self.ACCESS_TOKEN_KEY)
-class _FacebookShareMenu(online_account.OnlineMenu):
+class _FacebookShareMenu(online_account.OnlineShareMenu):
__gtype_name__ = 'JournalFacebookMenu'
def __init__(self, metadata, is_active):
- online_account.OnlineMenu.__init__(self, ONLINE_ACCOUNT_NAME)
+ online_account.OnlineShareMenu.__init__(self, ONLINE_ACCOUNT_NAME)
if is_active:
icon_name = 'facebook-share'
@@ -197,9 +197,9 @@ class _FacebookShareMenu(online_account.OnlineMenu):
pixbuf.savev(image_path, 'png', [], [])
-class _FacebookRefreshMenu(online_account.OnlineMenu):
+class _FacebookRefreshMenu(online_account.OnlineRefreshMenu):
def __init__(self, is_active):
- online_account.OnlineMenu.__init__(self, ONLINE_ACCOUNT_NAME)
+ online_account.OnlineRefreshMenu.__init__(self, ONLINE_ACCOUNT_NAME)
self._is_active = is_active
self._metadata = None
@@ -220,10 +220,12 @@ class _FacebookRefreshMenu(online_account.OnlineMenu):
if self._metadata:
if 'fb_object_id' in self._metadata:
self.set_sensitive(True)
- self.set_icon_name('facebook-refresh')
+ icon_name = 'facebook-refresh'
else:
self.set_sensitive(False)
- self.set_icon_name('facebook-refresh-insensitive')
+ icon_name = 'facebook-refresh-insensitive'
+ self.set_image(Icon(icon_name=icon_name,
+ icon_size=Gtk.IconSize.MENU))
def _fb_refresh_menu_clicked_cb(self, button):
logging.debug('_fb_refresh_menu_clicked_cb')
@@ -270,7 +272,7 @@ class _FacebookRefreshMenu(online_account.OnlineMenu):
if new_comment:
ds_object.metadata[COMMENTS] = json.dumps(ds_comments)
ds_object.metadata[COMMENT_IDS] = json.dumps(ds_comment_ids)
- self.emit('comments-updated')
+ self.emit('comments-changed', ds_object.metadata[COMMENTS])
datastore.write(ds_object, update_mtime=False)
diff --git a/extensions/web/twitter/twitter_online_account.py b/extensions/web/twitter/twitter_online_account.py
index de9142a..273b3c3 100644
--- a/extensions/web/twitter/twitter_online_account.py
+++ b/extensions/web/twitter/twitter_online_account.py
@@ -49,7 +49,7 @@ ACCOUNT_ACTIVE = 1
ONLINE_ACCOUNT_NAME = _('Twitter')
COMMENTS = 'comments'
COMMENT_IDS = 'twr_comment_ids'
-COMMENT_ID = 'last_comment_id'
+COMMENT_LAST_ID = 'last_comment_id'
class TwitterOnlineAccount(online_account.OnlineAccount):
@@ -115,11 +115,11 @@ class TwitterOnlineAccount(online_account.OnlineAccount):
self._client.get_string(self.ACCESS_SECRET_KEY))
-class _TwitterShareMenu(online_account.OnlineMenu):
+class _TwitterShareMenu(online_account.OnlineShareMenu):
__gtype_name__ = 'JournalTwitterMenu'
def __init__(self, metadata, is_active):
- online_account.OnlineMenu.__init__(self, ONLINE_ACCOUNT_NAME)
+ online_account.OnlineShareMenu.__init__(self, ONLINE_ACCOUNT_NAME)
if is_active:
icon_name = 'twitter-share'
@@ -184,9 +184,9 @@ class _TwitterShareMenu(online_account.OnlineMenu):
pixbuf.savev(image_path, 'png', [], [])
-class _TwitterRefreshMenu(online_account.OnlineMenu):
+class _TwitterRefreshMenu(online_account.OnlineRefreshMenu):
def __init__(self, is_active):
- online_account.OnlineMenu.__init__(self, ONLINE_ACCOUNT_NAME)
+ online_account.OnlineRefreshMenu.__init__(self, ONLINE_ACCOUNT_NAME)
self._is_active = is_active
self._metadata = None
@@ -205,12 +205,14 @@ class _TwitterRefreshMenu(online_account.OnlineMenu):
self._metadata = metadata
if self._is_active:
if self._metadata:
- if 'twr_object_id' in self._metadata:
+ if 'fb_object_id' in self._metadata:
self.set_sensitive(True)
- self.set_icon_name('twitter-refresh')
+ icon_name = 'twitter-refresh'
else:
self.set_sensitive(False)
- self.set_icon_name('twitter-refresh-insensitive')
+ icon_name = 'twitter-refresh-insensitive'
+ self.set_image(Icon(icon_name=icon_name,
+ icon_size=Gtk.IconSize.MENU))
def _twr_refresh_menu_clicked_cb(self, button):
logging.debug('_twr_refresh_menu_clicked_cb')
@@ -229,8 +231,8 @@ class _TwitterRefreshMenu(online_account.OnlineMenu):
# XXX is there other way to update metadata?
ds_object = datastore.get(self._metadata['uid'])
- if COMMENT_ID in ds_object.metadata:
- status_id = ds_object.metadata[COMMENT_ID]
+ if COMMENT_LAST_ID in ds_object.metadata:
+ status_id = ds_object.metadata[COMMENT_LAST_ID]
timeline = TwrTimeline()
timeline.connect('mentions-downloaded', self._twr_mentions_downloaded_cb)
@@ -268,10 +270,10 @@ class _TwitterRefreshMenu(online_account.OnlineMenu):
new_comment = True
if new_comment:
- ds_object.metadata[COMMENT_ID] = comment_id
+ ds_object.metadata[COMMENT_LAST_ID] = comment_id
ds_object.metadata[COMMENTS] = json.dumps(ds_comments)
ds_object.metadata[COMMENT_IDS] = json.dumps(ds_comment_ids)
- self.emit('comments-updated')
+ self.emit('comments-changed', ds_object.metadata[COMMENTS])
datastore.write(ds_object, update_mtime=False)
diff --git a/src/jarabe/journal/expandedentry.py b/src/jarabe/journal/expandedentry.py
index 81fd79d..ebf3385 100644
--- a/src/jarabe/journal/expandedentry.py
+++ b/src/jarabe/journal/expandedentry.py
@@ -75,8 +75,7 @@ class TextView(Gtk.TextView):
class CommentsView(Gtk.TreeView):
__gsignals__ = {
- 'comments-updated': (GObject.SignalFlags.RUN_FIRST, None, ([])),
- 'update-comments': (GObject.SignalFlags.RUN_FIRST, None, ([str])),
+ 'comments-changed': (GObject.SignalFlags.RUN_FIRST, None, ([str])),
'clicked': (GObject.SignalFlags.RUN_FIRST, None, [object]),
}
@@ -102,25 +101,21 @@ class CommentsView(Gtk.TreeView):
if comments:
self._comments = simplejson.loads(comments)
for comment in self._comments:
- self._add_row(
- self._get_comment_field(comment, self.FROM, ''),
- self._get_comment_field(comment, self.MESSAGE, ''),
- self._get_comment_field(comment, self.ICON, 'computer-xo'),
- self._get_comment_field(comment, self.ICON_COLOR,
- '#FFFFFF,#000000'))
+ self._add_row(comment.get(self.FROM, ''),
+ comment.get(self.MESSAGE, ''),
+ comment.get(self.ICON, 'computer-xo'),
+ comment.get(self.ICON_COLOR, '#FFFFFF,#000000'))
def _get_selected_row(self):
selection = self.get_selection()
return selection.get_selected()
- def _get_comment_field(self, comment, field, default):
- if field in comment:
- return comment[field]
- return default
-
def _add_row(self, sender, message, icon_name, icon_color):
- self._store.append((get_icon_file_name(icon_name), XoColor(icon_color),
- sender, message, get_icon_file_name('list-remove'),
+ self._store.append((get_icon_file_name(icon_name),
+ XoColor(icon_color),
+ sender,
+ message,
+ get_icon_file_name('list-remove'),
XoColor('#FFFFFF,#000000')))
def _init_model(self):
@@ -173,10 +168,18 @@ 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._comments.remove(
- self._comments[int(str(self._store[entry].path))])
self._store.remove(entry)
- self.emit('update-comments', simplejson.dumps(self._comments))
+ # 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))
class CellRendererCommentIcon(CellRendererIcon):
@@ -311,13 +314,11 @@ class ExpandedEntry(Gtk.EventBox):
def set_comments(self, comments):
self._metadata['comments'] = comments
+ self._comments.update_comments(comments)
self._write_entry()
def get_comments(self):
- if 'comments' in self._metadata:
- return self._metadata['comments']
- else:
- return ''
+ return self._metadata.get('comments', None)
def _create_keep_icon(self):
keep_icon = KeepIcon()
@@ -504,8 +505,7 @@ class ExpandedEntry(Gtk.EventBox):
def _create_comments(self):
widget = CommentsView()
- widget.connect('comments-updated', self._comments_updated_event_cb)
- widget.connect('update-comments', self._update_comments_cb)
+ widget.connect('comments-changed', self._update_comments_cb)
return self._create_scrollable(widget), widget
def _title_notify_text_cb(self, entry, pspec):
@@ -519,9 +519,6 @@ class ExpandedEntry(Gtk.EventBox):
def _description_tags_focus_out_event_cb(self, text_view, event):
self._update_entry()
- def _comments_updated_event_cb(self, event):
- self.update_comments(self.get_comments())
-
def _update_comments_cb(self, event, comments):
self.set_comments(comments)
diff --git a/src/jarabe/journal/journaltoolbox.py b/src/jarabe/journal/journaltoolbox.py
index 201e8eb..db934a3 100644
--- a/src/jarabe/journal/journaltoolbox.py
+++ b/src/jarabe/journal/journaltoolbox.py
@@ -389,7 +389,7 @@ class DetailToolbox(ToolbarBox):
if len(oam.OnlineAccountsManager.configured_accounts()) > 0:
self._refresh = ToolButton()
- icon = Icon(icon_name='edit-refresh', xo_color=color)
+ icon = Icon(icon_name='refresh', xo_color=color)
self._refresh.set_icon_widget(icon)
icon.show()
self._refresh.set_tooltip(_('Refresh'))
@@ -537,6 +537,7 @@ class DetailToolbox(ToolbarBox):
for account in oam.OnlineAccountsManager.configured_accounts():
menu = account.get_refresh_menu()
palette.menu.append(menu)
+ menu.set_metadata(self._metadata)
def __volume_error_cb(self, menu_item, message, severity):
self.emit('volume-error', message, severity)
diff --git a/src/jarabe/web/online_account.py b/src/jarabe/web/online_account.py
index aeb9bd9..a2eba14 100644
--- a/src/jarabe/web/online_account.py
+++ b/src/jarabe/web/online_account.py
@@ -25,7 +25,7 @@ import logging
from gi.repository import GObject
from sugar3.graphics.menuitem import MenuItem
-
+from sugar3.graphics.toolbutton import ToolButton
class OnlineAccount(GObject.GObject):
def get_description(self):
@@ -44,13 +44,43 @@ class OnlineAccount(GObject.GObject):
raise Exception("Not defined")
-class OnlineMenu(MenuItem):
+'''
+class _TransferWidget(GObject.GObject):
+ __gsignals__ = {
+ 'transfer-started': (GObject.SignalFlags.RUN_FIRST, None, ([int, int])),
+ 'transfer-progress': (GObject.SignalFlags.RUN_FIRST, None, ([int, int, float])),
+ 'transfer-completed': (GObject.SignalFlags.RUN_FIRST, None, ([int, int])),
+ 'transfer-failed': (GObject.SignalFlags.RUN_FIRST, None, ([int, int, str])),
+ 'transfer-state-changed': (GObject.SignalFlags.RUN_FIRST, None, ([str])),
+ }
+
+ def _transfer_state_changed_cb(self, transfer_object, state):
+ self.emit('transfer-state-changed', state)
+'''
+
+class OnlineShareMenu(MenuItem):
+ __gsignals__ = {
+ 'transfer-started': (GObject.SignalFlags.RUN_FIRST, None, ([int, int])),
+ 'transfer-progress': (GObject.SignalFlags.RUN_FIRST, None, ([int, int, float])),
+ 'transfer-completed': (GObject.SignalFlags.RUN_FIRST, None, ([int, int])),
+ 'transfer-failed': (GObject.SignalFlags.RUN_FIRST, None, ([int, int, str])),
+ 'transfer-state-changed': (GObject.SignalFlags.RUN_FIRST, None, ([str])),
+ }
+
+ def _transfer_state_changed_cb(self, transfer_object, state):
+ logging.debug('_transfer_state_changed_cb')
+ self.emit('transfer-state-changed', state)
+
+
+# class OnlineRefreshButton(ToolButton):
+class OnlineRefreshMenu(MenuItem):
__gsignals__ = {
'transfer-started': (GObject.SignalFlags.RUN_FIRST, None, ([int, int])),
'transfer-progress': (GObject.SignalFlags.RUN_FIRST, None, ([int, int, float])),
'transfer-completed': (GObject.SignalFlags.RUN_FIRST, None, ([int, int])),
'transfer-failed': (GObject.SignalFlags.RUN_FIRST, None, ([int, int, str])),
'transfer-state-changed': (GObject.SignalFlags.RUN_FIRST, None, ([str])),
+ 'comments-changed': (GObject.SignalFlags.RUN_FIRST, None, ([str])),
}
def _transfer_state_changed_cb(self, transfer_object, state):