diff --git a/data/gui/groupchat_control.ui b/data/gui/groupchat_control.ui index 7ab14ecca..7a0d7e8f4 100644 --- a/data/gui/groupchat_control.ui +++ b/data/gui/groupchat_control.ui @@ -1,5 +1,5 @@ - + @@ -127,19 +127,56 @@ - + True - True - never - never - in + False + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 3 - + + ChatControl-AuthenticationButton + True + False + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + none + + + True + False + gtk-dialog-authentication + 1 + + + + + False + False + 0 + + + + + True + True + never + never + in + + + + + + True + True + 1 + False - True + False 1 @@ -214,12 +251,12 @@ True True + False True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK True Show a list of formattings none - False True @@ -364,12 +401,12 @@ True True + False True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK True Show advanced functions (Alt+D) none - False True @@ -397,7 +434,24 @@ - + + True + True + True + none + + + True + False + channel-secure-symbolic.symbolic + + + + + False + True + 10 + @@ -418,6 +472,9 @@ 11 + + + False diff --git a/src/chat_control.py b/src/chat_control.py index 2a39d5628..2b1e8fa05 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -286,7 +286,7 @@ class ChatControl(ChatControlBase): self.encryption_menu = self.xml.get_object('encryption_menu') self.encryption_menu.set_menu_model( - gui_menu_builder.get_encryption_menu(self.contact)) + gui_menu_builder.get_encryption_menu(self.contact, self.type_id)) # restore previous conversation self.restore_conversation() self.msg_textview.grab_focus() diff --git a/src/chat_control_base.py b/src/chat_control_base.py index 3b6cde993..299dda9ca 100644 --- a/src/chat_control_base.py +++ b/src/chat_control_base.py @@ -398,7 +398,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): self.encryption = 'disabled' self.set_encryption_state() - self.add_window_actions() + if self.parent_win: + self.add_window_actions() # PluginSystem: adding GUI extension point for ChatControlBase # instance object (also subclasses, eg. ChatControl or GroupchatControl) @@ -435,7 +436,8 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools): if not plugin.activate_encryption(self): return else: - self.terminate_esessions() + if not self.widget_name == 'groupchat_control': + self.terminate_esessions() action.set_state(param) gajim.config.set_per( 'contacts', self.contact.jid, 'encryption', encryption) diff --git a/src/common/connection.py b/src/common/connection.py index baf18bc45..094625bb5 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -2672,6 +2672,14 @@ class Connection(CommonConnection, ConnectionHandlers): def _nec_gc_stanza_message_outgoing(self, obj): if obj.conn.name != self.name: return + encryption = gajim.config.get_per('contacts', obj.jid, 'encryption') + if encryption != 'disabled': + gajim.plugin_manager.gui_extension_point( + 'gc_encrypt' + encryption, self, obj, self.send_gc_message) + else: + self.send_gc_message(obj) + + def send_gc_message(self, obj): if obj.correction_msg: obj.msg_id = self.connection.send(obj.correction_msg) else: diff --git a/src/groupchat_control.py b/src/groupchat_control.py index 7c62977de..17f30a3c0 100644 --- a/src/groupchat_control.py +++ b/src/groupchat_control.py @@ -481,6 +481,19 @@ class GroupchatControl(ChatControlBase): self.form_widget = None + # Encryption + self.lock_image = self.xml.get_object('lock_image') + self.authentication_button = self.xml.get_object( + 'authentication_button') + id_ = self.authentication_button.connect('clicked', + self._on_authentication_button_clicked) + self.handlers[id_] = self.authentication_button + self.set_lock_image() + + self.encryption_menu = self.xml.get_object('encryption_menu') + self.encryption_menu.set_menu_model( + gui_menu_builder.get_encryption_menu(self.contact, self.type_id)) + gajim.ged.register_event_handler('gc-presence-received', ged.GUI1, self._nec_gc_presence_received) gajim.ged.register_event_handler('gc-message-received', ged.GUI1, @@ -508,6 +521,11 @@ class GroupchatControl(ChatControlBase): # instance object gajim.plugin_manager.gui_extension_point('groupchat_control', self) + def on_groupchat_maximize(self): + self.set_tooltip() + self.add_window_actions() + self.set_lock_image() + def set_tooltip(self): widget = self.xml.get_object('list_treeview') if widget.get_tooltip_window(): @@ -751,6 +769,42 @@ class GroupchatControl(ChatControlBase): for nick in gajim.contacts.get_nick_list(self.account, self.room_jid): self.draw_contact(nick) + def set_lock_image(self): + visible = self.encryption != 'disabled' + + encryption_state = {'visible': visible, + 'enc_type': self.encryption, + 'authenticated': False} + + gajim.plugin_manager.gui_extension_point( + 'encryption_state' + self.encryption, self, encryption_state) + + self._show_lock_image(**encryption_state) + + def _show_lock_image(self, visible, enc_type='', + authenticated=False): + """ + Set lock icon visibility and create tooltip + """ + if authenticated: + authenticated_string = _('and authenticated') + img_path = gtkgui_helpers.get_icon_path('security-high') + else: + authenticated_string = _('and NOT authenticated') + img_path = gtkgui_helpers.get_icon_path('security-low') + self.lock_image.set_from_file(img_path) + + tooltip = _('%(type)s encryption is active %(authenticated)s.') % { + 'type': enc_type, 'authenticated': authenticated_string} + + self.authentication_button.set_tooltip_text(tooltip) + self.widget_set_visible(self.authentication_button, not visible) + self.lock_image.set_sensitive(visible) + + def _on_authentication_button_clicked(self, widget): + gajim.plugin_manager.gui_extension_point( + 'encryption_dialog' + self.encryption, self) + def _change_style(self, model, path, iter_, option): model[iter_][Column.NICK] = model[iter_][Column.NICK] @@ -1966,6 +2020,13 @@ class GroupchatControl(ChatControlBase): if not message: return + if self.encryption: + self.sendmessage = True + gajim.plugin_manager.gui_extension_point( + 'send_message' + self.encryption, self) + if not self.sendmessage: + return + if process_commands and self.process_as_command(message): return diff --git a/src/gui_menu_builder.py b/src/gui_menu_builder.py index f03d61a87..58f892533 100644 --- a/src/gui_menu_builder.py +++ b/src/gui_menu_builder.py @@ -750,12 +750,21 @@ def build_bookmark_menu(account): menu.insert_submenu(1, label, bookmark_menu) -def get_encryption_menu(contact): +def get_encryption_menu(contact, type_id): menu = Gio.Menu() menu.append( - 'Disabled', 'win.{}-encryptiongroup::{}'.format(contact.jid, 'disabled')) - for encryption in gajim.plugin_manager.encryption_plugins: + 'Disabled', 'win.{}-encryptiongroup::{}'.format(contact.jid, + 'disabled')) + for name, plugin in gajim.plugin_manager.encryption_plugins.items(): + if type_id == 'gc': + if not hasattr(plugin, 'allow_groupchat'): + continue + if type_id == 'pm': + if not hasattr(plugin, 'allow_privatchat'): + continue menu_action = 'win.{}-encryptiongroup::{}'.format( - contact.jid, encryption) - menu.append(encryption, menu_action) + contact.jid, name) + menu.append(name, menu_action) + if menu.get_n_items() == 1: + return None return menu diff --git a/src/roster_window.py b/src/roster_window.py index 81766ef94..7d33908e8 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -3220,7 +3220,7 @@ class RosterWindow: ctrl._on_window_motion_notify) ctrl.handlers[id_] = mw.window ctrl.parent_win = mw - ctrl.set_tooltip() + ctrl.on_groupchat_maximize() mw.new_tab(ctrl) mw.set_active_tab(ctrl) mw.window.get_window().focus(Gtk.get_current_event_time())