Commit 2e148a61 authored by Philipp Hörist's avatar Philipp Hörist

Add encryption API to groupchat_control

parent ce7923e1
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.3 -->
<!-- Generated with glade 3.20.0 -->
<interface>
<requires lib="gtk+" version="3.12"/>
<object class="GtkImage" id="image1">
......@@ -127,19 +127,56 @@
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="message_scrolledwindow">
<object class="GtkBox" id="hbox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<property name="can_focus">False</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="spacing">3</property>
<child>
<placeholder/>
<object class="GtkButton" id="authentication_button">
<property name="name">ChatControl-AuthenticationButton</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="no_show_all">True</property>
<property name="relief">none</property>
<child>
<object class="GtkImage" id="lock_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-dialog-authentication</property>
<property name="icon_size">1</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="message_scrolledwindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
......@@ -214,12 +251,12 @@
<object class="GtkButton" id="formattings_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="has_tooltip">True</property>
<property name="tooltip_text" translatable="yes">Show a list of formattings</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="image11">
<property name="visible">True</property>
......@@ -364,12 +401,12 @@
<object class="GtkButton" id="muc_window_actions_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="has_tooltip">True</property>
<property name="tooltip_text" translatable="yes">Show advanced functions (Alt+D)</property>
<property name="relief">none</property>
<property name="focus_on_click">False</property>
<child>
<object class="GtkImage" id="image1344">
<property name="visible">True</property>
......@@ -397,7 +434,24 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkMenuButton" id="encryption_menu">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="relief">none</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">channel-secure-symbolic.symbolic</property>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">10</property>
</packing>
</child>
<child>
<object class="GtkButton" id="send_button">
......@@ -418,6 +472,9 @@
<property name="position">11</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
......
......@@ -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()
......
......@@ -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)
......
......@@ -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:
......
......@@ -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
......
......@@ -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
......@@ -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())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment