From 3f49b6149d6ba1d7d8152709f5f82f1eb259fca5 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Sun, 24 Jan 2010 19:51:16 -0200 Subject: [PATCH] Protected status. fixes #199 --- CHEAT-CODES | 6 ++++++ mitterlib/network/networkbase.py | 4 ++++ mitterlib/network/twitter.py | 6 ++++++ mitterlib/ui/ui_pygtk.py | 33 +++++++++++++++++++++++--------- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/CHEAT-CODES b/CHEAT-CODES index 797fca7..a1052f8 100644 --- a/CHEAT-CODES +++ b/CHEAT-CODES @@ -142,3 +142,9 @@ options: The character to indicate that a message is marked as favourite. The defualt value is '☆', which is a filled star. Beware that not all HTML charcters are accepted. + +*protected_char* + The character to indicate that a message is marked as + protected/private. The default value is + "(protected)", which is the string (protected) with a + smaller font. Beware that not all HTML characters are accepted. diff --git a/mitterlib/network/networkbase.py b/mitterlib/network/networkbase.py index de15437..091f479 100644 --- a/mitterlib/network/networkbase.py +++ b/mitterlib/network/networkbase.py @@ -152,6 +152,9 @@ class NetworkData(object): merging information from all networks. *Networks should NEVER fill this field* + **protected** + Boolean indicating if the message is protected/private or not. + .. [*] Not all fields need to be filled if that would require more than one network call. .. [*] Interfaces should be aware that optional fields may not be filled. @@ -169,6 +172,7 @@ class NetworkData(object): self.parent_owner = '' self.reposted_by = '' self.network = '' + self.protected = False class NetworkBase(object): diff --git a/mitterlib/network/twitter.py b/mitterlib/network/twitter.py index 329a33d..4df01a5 100644 --- a/mitterlib/network/twitter.py +++ b/mitterlib/network/twitter.py @@ -122,12 +122,18 @@ class TwitterNetworkData(NetworkData): """Class initialization. Receives a dictionary with a single tweet.""" NetworkData.__init__(self) + _log.debug(str(data)) + self.id = data['id'] self.name = data['user']['name'] self.username = data['user']['screen_name'] self.avatar = data['user']['profile_image_url'] self.message_time = _to_datetime(data['created_at']) + if 'protected' in data['user']: + # twitter protects all messages from a user, not per message. + self.protected = data['user']['protected'] + if 'favorited' in data: self.favourited = data['favorited'] diff --git a/mitterlib/ui/ui_pygtk.py b/mitterlib/ui/ui_pygtk.py index 6d96bd8..9c8807f 100644 --- a/mitterlib/ui/ui_pygtk.py +++ b/mitterlib/ui/ui_pygtk.py @@ -39,7 +39,6 @@ from mitterlib.ui.helpers import timesince # Constants _log = logging.getLogger('ui.pygtk') - URL_RE = re.compile(r'(https?://[^\s\n\r]+)', re.I) # ---------------------------------------------------------------------- @@ -52,14 +51,16 @@ N_ = t.ngettext # ---------------------------------------------------------------------- # String with the format to the message # ---------------------------------------------------------------------- -MESSAGE_FORMAT = '%(favourite_star)s' \ - '%(full_name)s ' \ - '(%(username)s' \ - '%(message_type)s' \ - '):' \ - '%(read_status)s\n' \ - '%(message)s\n' \ - '%(message_age)s' +MESSAGE_FORMAT = ('%(favourite_star)s' + '%(full_name)s ' + '(%(username)s' + '%(message_type)s' + '):' + '%(read_status)s ' + '%(protected_status)s ' + '\n' + '%(message)s\n' + '%(message_age)s') # ---------------------------------------------------------------------- @@ -626,6 +627,12 @@ class Interface(object): info.append(_(' — in reply to %s') % (data.parent_owner)) + if data.protected: + message_values['protected_status'] = ( + self._options[self.NAMESPACE]['protected_char']) + else: + message_values['protected_status'] = '' + message_values['message_type'] = ''.join(info) markup = MESSAGE_FORMAT % (message_values) @@ -1570,3 +1577,11 @@ class Interface(object): metavar='CHAR', default='☆', is_cmd_option=False) + options.add_option( + group=self.NAMESPACE, + option='protected_char', + help='String to be used to indicate that a message is ' \ + 'protected/private.', + metavar='CHAR', + default=_('(protected)'), + is_cmd_option=False)