From 997f88d5d21b721383db1312a34ec587c6fef258 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Sun, 20 Dec 2009 19:32:27 -0200 Subject: [PATCH] Added favourite option and display --- ...111a994574de34537952ec6486cd52589e302.yaml | 8 ++- mitterlib/ui/ui_pygtk.py | 69 +++++++++++++++++-- 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/issues/issue-1a5111a994574de34537952ec6486cd52589e302.yaml b/issues/issue-1a5111a994574de34537952ec6486cd52589e302.yaml index 9453a35..b8bee35 100644 --- a/issues/issue-1a5111a994574de34537952ec6486cd52589e302.yaml +++ b/issues/issue-1a5111a994574de34537952ec6486cd52589e302.yaml @@ -5,8 +5,8 @@ type: :feature component: pygtk release: 1.0.0 reporter: Julio Biason -status: :unstarted -disposition: +status: :closed +disposition: :fixed creation_time: 2009-12-16 11:18:12.708128 Z references: - network-1 @@ -20,3 +20,7 @@ log_events: - Julio Biason - added reference 1 - "" +- - 2009-12-20 21:32:03.624302 Z + - Julio Biason + - closed with disposition fixed + - "" diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index 8a63e66..9cd0099 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -309,6 +309,7 @@ class Interface(object): + @@ -332,6 +333,7 @@ class Interface(object): + @@ -425,6 +427,15 @@ class Interface(object): self._repost_action.connect('activate', self._repost_message) action_group.add_action_with_accel(self._repost_action, 'p') + self._favourite_action = gtk.Action('Favourite', '_Favourite', + 'Toggle the favourite status of a message', + gtk.STOCK_ABOUT) + self._favourite_action.set_property('sensitive', False) + self._favourite_action.connect('activate', self._favourite_message) + action_group.add_action_with_accel(self._favourite_action, 'f') + # XXX: Not sure if "Ctrl+F" is a good option, since other applications + # use it as "Find". + # Help actions about_action = gtk.Action('About', '_About', 'About Mitter', gtk.STOCK_ABOUT) @@ -587,17 +598,17 @@ class Interface(object): else: read_status = '' - if data.favourited: - favourited = '★' + if data.favourite: + favourite = '★' else: - favourited = '☆' + favourite = '☆' if data.reposted_by: reposted_message = ' — reposted by %s' else: reposted_message = '' - markup = MESSAGE_FORMAT % (favourited, data.name, username, + markup = MESSAGE_FORMAT % (favourite, data.name, username, reposted_message, read_status, message, time) cell.set_property('markup', markup) @@ -825,6 +836,8 @@ class Interface(object): self._connection.can_reply(data)) self._repost_action.set_property('sensitive', self._connection.can_repost(data)) + self._favourite_action.set_property('sensitive', + self._connection.can_favourite(data)) return 0 @@ -872,6 +885,25 @@ class Interface(object): message) return + def _favourite_message(self, widget, user_data=None): + """Toggle the favourite status of a message.""" + (model, iter) = self._grid.get_selection().get_selected() + message = model.get_value(iter, 0) + + self._favourite_iter = iter + + if message.favourite: + display = 'Removing message from %s from favourites...' + else: + display = 'Marking message from %s as favourite...' + self._update_status(display % (message.username)) + + self._threads.add_work(self._post_favourite_message, + self._exception_favourite_message, + self._connection.favourite, + message) + return + def _show_settings(self, widget, user_data=None): """Display the settings window.""" settings_window = gtk.Dialog(title='Settings', @@ -1156,6 +1188,34 @@ class Interface(object): error_win.hide() return + ### Results from the favourite call + def _post_favourite_message(self, widget, data): + """Called when the message was favourited successfully.""" + _log.debug('Favourite status changed.') + message = self._grid.get_model().get_value(self._favourite_iter, 0) + if message.favourite: + display = 'Message unfavourited.' + else: + display = 'Message favourited.' + self._update_statusbar(display) + message.favourite = not message.favourite + self._favourite_iter = None + return + + def _exception_favourite_message(self, widget, exception): + """Called when the message couldn't be favourited.""" + _log.debug('Favourite error.') + _log.debug(str(exception)) + + error_win = gtk.MessageDialog(parent=self._main_window, + type=gtk.MESSAGE_ERROR, + message_format='Error changing favourite status of the ' \ + 'message. Please, try again.', + buttons=gtk.BUTTONS_OK) + error_win.run() + error_win.hide() + return + # ------------------------------------------------------------ # Required functions for all interfaces # ------------------------------------------------------------ @@ -1192,6 +1252,7 @@ class Interface(object): # interthread communication. self._delete_iter = None self._reply_message_id = None + self._favourite_iter = None self._new_message_count = 0 return