From 91b6dbfa83d68a621de2355ecbfa6b9ad2766089 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Wed, 2 Dec 2009 18:57:26 -0200 Subject: [PATCH] Message actions are now sensitive to the user's own messages --- mitterlib/ui/ui_pygtk.py | 52 ++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index e1e75e7..71745da 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -267,8 +267,8 @@ class Interface(object): self._grid.append_column(message_column) self._grid.set_resize_mode(gtk.RESIZE_IMMEDIATE) - #self.grid.connect('cursor-changed', self.check_post) - #self.grid.connect('row-activated', self.open_post) + self._grid.connect('cursor-changed', self._message_selected) + #self._grid.connect('row-activated', self.open_post) #self.grid.connect('button-press-event', self.click_post) #self.grid.connect('popup-menu', # lambda view: self.show_post_popup(view, None)) @@ -287,6 +287,7 @@ class Interface(object): + @@ -302,6 +303,7 @@ class Interface(object): + @@ -348,7 +350,7 @@ class Interface(object): refresh_action = gtk.Action('Refresh', '_Refresh', 'Update the listing', gtk.STOCK_REFRESH) #refresh_action.connect('activate', self.refresh) - action_group.add_action_with_accel(refresh_action, 'F5') + action_group.add_action_with_accel(refresh_action, None) self._update_action = gtk.Action('Update', '_Update', 'Update your status', gtk.STOCK_ADD) @@ -356,6 +358,11 @@ class Interface(object): self._update_action.connect('activate', self._update_status) action_group.add_action_with_accel(self._update_action, 'Return') + + clear_action = gtk.Action('Clear', '_Clear', + 'Clear the message list', gtk.STOCK_CLEAR) + action_group.add_action_with_accel(clear_action, None) + # TODO: Connect #shrink_url_action = gtk.Action('ShrinkURL', 'Shrink _URL', # 'Shrink selected URL', gtk.STOCK_EXECUTE) @@ -373,25 +380,25 @@ class Interface(object): action_group.add_action(settings_action) # Message actions - delete_action = gtk.Action('Delete', '_Delete', 'Delete a post', - gtk.STOCK_DELETE) - delete_action.set_property('sensitive', False) + self._delete_action = gtk.Action('Delete', '_Delete', + 'Delete a post', gtk.STOCK_DELETE) + self._delete_action.set_property('sensitive', False) #delete_action.connect('activate', self.delete_tweet) - action_group.add_action(delete_action) + action_group.add_action(self._delete_action) - reply_action = gtk.Action('Reply', '_Reply', + self._reply_action = gtk.Action('Reply', '_Reply', "Send a response to someone's else message", gtk.STOCK_REDO) - reply_action.set_property('sensitive', False) + self._reply_action.set_property('sensitive', False) # TODO: Connect - action_group.add_action(reply_action) + action_group.add_action(self._reply_action) # TODO: Find a better word (non-network related) to this - retweet_action = gtk.Action('Retweet', 'Re_tweet', + self._retweet_action = gtk.Action('Retweet', 'Re_tweet', "Put someone's else message on your timeline", gtk.STOCK_CONVERT) - retweet_action.set_property('sensitive', False) + self._retweet_action.set_property('sensitive', False) # TODO: Connect - action_group.add_action(retweet_action) + action_group.add_action(self._retweet_action) # Help actions about_action = gtk.Action('About', '_About', 'About Mitter', @@ -531,6 +538,7 @@ class Interface(object): # use a different highlight for the current user # TODO: How to handle this with several networks? + # SOLUTION: self._connection.is_self(message) #message = re.sub(r'(@'+self.twitter.username+')', # r'\1', # message) @@ -657,6 +665,24 @@ class Interface(object): (message2.message_time > message1.message_time): return 1 return 0 + + def _message_selected(self, view, user_data=None): + """Callback when a row in the list is selected. Mostly, we'll check + if the message is from the logged user and we change de "sensitive" + property of the message actions to reflect what the user can and + cannot do.""" + + (model, iter) = view.get_selection().get_selected() + data = model.get_value(iter, 0) + + user_owned = self._connection.is_self(data) + _log.debug('User message: %s', str(user_owned)) + + self._delete_action.set_property('sensitive', user_owned) + self._reply_action.set_property('sensitive', not user_owned) + self._retweet_action.set_property('sensitive', not user_owned) + + return 0 # ------------------------------------------------------------ # Network related functions