diff --git a/src/common/connection.py b/src/common/connection.py index 14827cad8..949ad5b0f 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -192,6 +192,7 @@ class Connection: tim = msg.getTimestamp() tim = time.strptime(tim, '%Y%m%dT%H:%M:%S') tim = time.localtime(timegm(tim)) + encrypted = False xtags = msg.getTags('x') encTag = None decmsg = '' @@ -208,6 +209,7 @@ class Connection: decmsg = self.gpg.decrypt(encmsg, keyID) if decmsg: msgtxt = decmsg + encrypted = True if mtype == 'error': self.dispatch('MSGERROR', (str(msg.getFrom()), \ msg.getErrorCode(), msg.getError(), msgtxt, tim)) @@ -220,7 +222,7 @@ class Connection: gajim.logger.write('gc', msgtxt, str(msg.getFrom()), tim = tim) else: gajim.logger.write('incoming', msgtxt, str(msg.getFrom()), tim = tim) - self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim)) + self.dispatch('MSG', (str(msg.getFrom()), msgtxt, tim, encrypted)) # END messageCB def _presenceCB(self, con, prs): diff --git a/src/gajim.py b/src/gajim.py index 37fe6d9b6..70be4788a 100755 --- a/src/gajim.py +++ b/src/gajim.py @@ -329,7 +329,7 @@ class Interface: array[10], array[11], account) def handle_event_msg(self, account, array): - #('MSG', account, (user, msg, time)) + #('MSG', account, (user, msg, time, encrypted)) jid = array[0].split('/')[0] if jid.find('@') <= 0: jid = jid.replace('@', '') @@ -352,7 +352,7 @@ class Interface: instance = dialogs.Popup_notification_window(self, 'New Message', jid, account) self.roster.popup_notification_windows.append(instance) - self.roster.on_message(jid, array[1], array[2], account) + self.roster.on_message(jid, array[1], array[2], account, array[3]) if gajim.config.get_per('soundevents', 'first_message_received', \ 'enabled') and first: self.play_sound('first_message_received') diff --git a/src/roster_window.py b/src/roster_window.py index 39a593662..3aaae70ec 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -956,7 +956,7 @@ class Roster_window: self.plugin.windows[account]['gc'][jid] = \ groupchat_window.Groupchat_window(jid, nick, self.plugin, account) - def on_message(self, jid, msg, tim, account): + def on_message(self, jid, msg, tim, account, encrypted = False): '''when we receive a message''' if not self.contacts[account].has_key(jid): keyID = '' @@ -985,7 +985,7 @@ class Roster_window: self.draw_contact(jid, account) if self.plugin.systray_enabled: self.plugin.systray.add_jid(jid, account) - self.plugin.queues[account][jid].put((msg, tim)) + self.plugin.queues[account][jid].put((msg, tim, encrypted)) self.nb_unread += 1 self.show_title() if not path: @@ -1005,7 +1005,7 @@ class Roster_window: self.tree.scroll_to_cell(path) self.tree.set_cursor(path) self.plugin.windows[account]['chats'][jid].print_conversation(msg, - jid, tim = tim) + jid, tim = tim, encrypted = encrypted) def on_preferences_menuitem_activate(self, widget): if self.plugin.windows['preferences'].window.get_property('visible'): diff --git a/src/tabbed_chat_window.py b/src/tabbed_chat_window.py index 2df6be285..7e515b093 100644 --- a/src/tabbed_chat_window.py +++ b/src/tabbed_chat_window.py @@ -43,6 +43,7 @@ class Tabbed_chat_window(chat.Chat): def __init__(self, user, plugin, account): chat.Chat.__init__(self, plugin, account, 'tabbed_chat_window') self.users = {} + self.encrypted = {} self.new_user(user) self.show_title() self.xml.signal_connect('on_tabbed_chat_window_destroy', @@ -176,6 +177,7 @@ class Tabbed_chat_window(chat.Chat): self.childs[user.jid] = self.xmls[user.jid].get_widget('chats_vbox') chat.Chat.new_tab(self, user.jid) self.users[user.jid] = user + self.encrypted[user.jid] = False self.redraw_tab(user.jid) self.draw_widgets(user) @@ -233,11 +235,13 @@ class Tabbed_chat_window(chat.Chat): self.on_clear(None, widget) # clear message textview too return True keyID = '' + encrypted = False if self.xmls[jid].get_widget('gpg_togglebutton').get_active(): keyID = self.users[jid].keyID + encrypted = True gajim.connections[self.account].send_message(jid, message, keyID) message_buffer.set_text('', -1) - self.print_conversation(message, jid, jid) + self.print_conversation(message, jid, jid, encrypted = encrypted) return True def on_contact_button_clicked(self, widget): @@ -251,7 +255,8 @@ class Tabbed_chat_window(chat.Chat): user = self.users[jid] while not q.empty(): event = q.get() - self.print_conversation(event[0], jid, tim = event[1]) + self.print_conversation(event[0], jid, tim = event[1], + encrypted = event[2]) self.plugin.roster.nb_unread -= 1 self.plugin.roster.show_title() del self.plugin.queues[self.account][jid] @@ -264,7 +269,8 @@ class Tabbed_chat_window(chat.Chat): if len(self.plugin.roster.contacts[self.account][jid]) == 1: self.plugin.roster.really_remove_user(user, self.account) - def print_conversation(self, text, jid, contact = '', tim = None): + def print_conversation(self, text, jid, contact = '', tim = None, + encrypted = False): """Print a line in the conversation: if contact is set to status: it's a status message if contact is set to another value: it's an outgoing message @@ -274,6 +280,14 @@ class Tabbed_chat_window(chat.Chat): kind = 'status' name = '' else: + if encrypted and not self.encrypted[jid]: + chat.Chat.print_conversation_line(self, 'Encryption enabled', jid, + 'status', '', tim) + if not encrypted and self.encrypted[jid]: + chat.Chat.print_conversation_line(self, 'Encryption disabled', jid, + 'status', '', tim) + self.encrypted[jid] = encrypted + self.xmls[jid].get_widget('gpg_togglebutton').set_active(encrypted) if contact: kind = 'outgoing' name = self.plugin.nicks[self.account]