Add 'encryption' config options group
We have to save the value per account and contact, because otherwise it could lead to problems if a jid is added to more than one account. As key this uses a string in the form of 'Account-BareJid'. The config option group 'contacts' is not used because there are values like 'speller_language' that make more sense to set on a Jid basis, rather than a Account-Jid basis. Treat an empty config value or no config value as 'disabled', instead of writing a config value of 'disabled'. This has the benefit that we dont have to write config values for contacts were we dont use encryption.
This commit is contained in:
parent
a73f02735a
commit
3335482345
|
@ -843,15 +843,15 @@ class ChatControl(ChatControlBase):
|
||||||
self.on_jingle_button_toggled(widget, 'video')
|
self.on_jingle_button_toggled(widget, 'video')
|
||||||
|
|
||||||
def set_lock_image(self):
|
def set_lock_image(self):
|
||||||
visible = self.encryption != 'disabled'
|
|
||||||
loggable = self.session and self.session.is_loggable()
|
loggable = self.session and self.session.is_loggable()
|
||||||
|
|
||||||
encryption_state = {'visible': visible,
|
encryption_state = {'visible': self.encryption is not None,
|
||||||
'enc_type': self.encryption,
|
'enc_type': self.encryption,
|
||||||
'authenticated': False}
|
'authenticated': False}
|
||||||
|
|
||||||
gajim.plugin_manager.gui_extension_point(
|
if self.encryption:
|
||||||
'encryption_state' + self.encryption, self, encryption_state)
|
gajim.plugin_manager.gui_extension_point(
|
||||||
|
'encryption_state' + self.encryption, self, encryption_state)
|
||||||
|
|
||||||
self._show_lock_image(**encryption_state)
|
self._show_lock_image(**encryption_state)
|
||||||
|
|
||||||
|
@ -875,8 +875,9 @@ class ChatControl(ChatControlBase):
|
||||||
self.lock_image.set_sensitive(visible)
|
self.lock_image.set_sensitive(visible)
|
||||||
|
|
||||||
def _on_authentication_button_clicked(self, widget):
|
def _on_authentication_button_clicked(self, widget):
|
||||||
gajim.plugin_manager.gui_extension_point(
|
if self.encryption:
|
||||||
'encryption_dialog' + self.encryption, self)
|
gajim.plugin_manager.gui_extension_point(
|
||||||
|
'encryption_dialog' + self.encryption, self)
|
||||||
|
|
||||||
def send_message(self, message, keyID='', chatstate=None, xhtml=None,
|
def send_message(self, message, keyID='', chatstate=None, xhtml=None,
|
||||||
process_commands=True, attention=False):
|
process_commands=True, attention=False):
|
||||||
|
@ -1401,7 +1402,7 @@ class ChatControl(ChatControlBase):
|
||||||
|
|
||||||
def _on_message_tv_buffer_changed(self, textbuffer):
|
def _on_message_tv_buffer_changed(self, textbuffer):
|
||||||
super()._on_message_tv_buffer_changed(textbuffer)
|
super()._on_message_tv_buffer_changed(textbuffer)
|
||||||
if textbuffer.get_char_count():
|
if textbuffer.get_char_count() and self.encryption:
|
||||||
gajim.plugin_manager.gui_extension_point(
|
gajim.plugin_manager.gui_extension_point(
|
||||||
'typing' + self.encryption, self)
|
'typing' + self.encryption, self)
|
||||||
if (not self.session or not self.session.status) and \
|
if (not self.session or not self.session.status) and \
|
||||||
|
|
|
@ -396,8 +396,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
self._on_window_motion_notify)
|
self._on_window_motion_notify)
|
||||||
self.handlers[id_] = parent_win.window
|
self.handlers[id_] = parent_win.window
|
||||||
|
|
||||||
self.encryption = 'disabled'
|
self.encryption = self.get_encryption_state()
|
||||||
self.set_encryption_state()
|
|
||||||
if self.parent_win:
|
if self.parent_win:
|
||||||
self.add_window_actions()
|
self.add_window_actions()
|
||||||
|
|
||||||
|
@ -422,16 +421,19 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
action = Gio.SimpleAction.new_stateful(
|
action = Gio.SimpleAction.new_stateful(
|
||||||
"%s-encryptiongroup" % self.contact.jid,
|
"%s-encryptiongroup" % self.contact.jid,
|
||||||
GLib.VariantType.new("s"),
|
GLib.VariantType.new("s"),
|
||||||
GLib.Variant("s", self.encryption))
|
GLib.Variant("s", self.encryption or 'disabled'))
|
||||||
action.connect("change-state", self.activate_encryption)
|
action.connect("change-state", self.activate_encryption)
|
||||||
self.parent_win.window.add_action(action)
|
self.parent_win.window.add_action(action)
|
||||||
|
|
||||||
def activate_encryption(self, action, param):
|
def activate_encryption(self, action, param):
|
||||||
encryption = param.get_string()
|
encryption = param.get_string()
|
||||||
|
if encryption == 'disabled':
|
||||||
|
encryption = None
|
||||||
|
|
||||||
if self.encryption == encryption:
|
if self.encryption == encryption:
|
||||||
return
|
return
|
||||||
|
|
||||||
if encryption != 'disabled':
|
if encryption:
|
||||||
plugin = gajim.plugin_manager.encryption_plugins[encryption]
|
plugin = gajim.plugin_manager.encryption_plugins[encryption]
|
||||||
if not plugin.activate_encryption(self):
|
if not plugin.activate_encryption(self):
|
||||||
return
|
return
|
||||||
|
@ -439,19 +441,19 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
|
||||||
if not self.widget_name == 'groupchat_control':
|
if not self.widget_name == 'groupchat_control':
|
||||||
self.terminate_esessions()
|
self.terminate_esessions()
|
||||||
action.set_state(param)
|
action.set_state(param)
|
||||||
gajim.config.set_per(
|
self.set_encryption_state(encryption)
|
||||||
'contacts', self.contact.jid, 'encryption', encryption)
|
|
||||||
self.encryption = encryption
|
|
||||||
self.set_lock_image()
|
self.set_lock_image()
|
||||||
|
|
||||||
def set_encryption_state(self):
|
def set_encryption_state(self, encryption):
|
||||||
enc = gajim.config.get_per('contacts', self.contact.jid, 'encryption')
|
config_key = '%s-%s' % (self.account, self.contact.jid)
|
||||||
if enc not in gajim.plugin_manager.encryption_plugins:
|
self.encryption = encryption
|
||||||
self.encryption = 'disabled'
|
gajim.config.set_per('encryption', config_key,
|
||||||
gajim.config.set_per(
|
'encryption', self.encryption or '')
|
||||||
'contacts', self.contact.jid, 'encryption', 'disabled')
|
|
||||||
else:
|
def get_encryption_state(self):
|
||||||
self.encryption = enc
|
config_key = '%s-%s' % (self.account, self.contact.jid)
|
||||||
|
state = gajim.config.get_per('encryption', config_key, 'encryption')
|
||||||
|
return state or None
|
||||||
|
|
||||||
def set_speller(self):
|
def set_speller(self):
|
||||||
# now set the one the user selected
|
# now set the one the user selected
|
||||||
|
|
|
@ -480,9 +480,10 @@ class Config:
|
||||||
'state_muc_directed_msg_color': [ opt_color, 'red2' ],
|
'state_muc_directed_msg_color': [ opt_color, 'red2' ],
|
||||||
}, {}),
|
}, {}),
|
||||||
'contacts': ({
|
'contacts': ({
|
||||||
'encryption': [ opt_str, '', _('Encryption used for this contact.')],
|
|
||||||
'speller_language': [ opt_str, '', _('Language for which we want to check misspelled words')],
|
'speller_language': [ opt_str, '', _('Language for which we want to check misspelled words')],
|
||||||
}, {}),
|
}, {}),
|
||||||
|
'encryption': ({'encryption': [ opt_str, '', _('The currently active encryption for that contact')],
|
||||||
|
},{}),
|
||||||
'rooms': ({
|
'rooms': ({
|
||||||
'speller_language': [ opt_str, '', _('Language for which we want to check misspelled words')],
|
'speller_language': [ opt_str, '', _('Language for which we want to check misspelled words')],
|
||||||
'muc_restore_lines': [opt_int, -2, _('How many lines to request from server when entering a groupchat. -1 means no limit, -2 means global value')],
|
'muc_restore_lines': [opt_int, -2, _('How many lines to request from server when entering a groupchat. -1 means no limit, -2 means global value')],
|
||||||
|
|
|
@ -2053,8 +2053,10 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
def _nec_stanza_message_outgoing(self, obj):
|
def _nec_stanza_message_outgoing(self, obj):
|
||||||
if obj.conn.name != self.name:
|
if obj.conn.name != self.name:
|
||||||
return
|
return
|
||||||
encryption = gajim.config.get_per('contacts', obj.jid, 'encryption')
|
|
||||||
if encryption != 'disabled':
|
config_key = '%s-%s' % (self.name, obj.jid)
|
||||||
|
encryption = gajim.config.get_per('encryption', config_key, 'encryption')
|
||||||
|
if encryption:
|
||||||
gajim.plugin_manager.gui_extension_point(
|
gajim.plugin_manager.gui_extension_point(
|
||||||
'encrypt' + encryption, self, obj, self.send_message)
|
'encrypt' + encryption, self, obj, self.send_message)
|
||||||
else:
|
else:
|
||||||
|
@ -2672,8 +2674,10 @@ class Connection(CommonConnection, ConnectionHandlers):
|
||||||
def _nec_gc_stanza_message_outgoing(self, obj):
|
def _nec_gc_stanza_message_outgoing(self, obj):
|
||||||
if obj.conn.name != self.name:
|
if obj.conn.name != self.name:
|
||||||
return
|
return
|
||||||
encryption = gajim.config.get_per('contacts', obj.jid, 'encryption')
|
|
||||||
if encryption != 'disabled':
|
config_key = '%s-%s' % (self.name, obj.jid)
|
||||||
|
encryption = gajim.config.get_per('encryption', config_key, 'encryption')
|
||||||
|
if encryption:
|
||||||
gajim.plugin_manager.gui_extension_point(
|
gajim.plugin_manager.gui_extension_point(
|
||||||
'gc_encrypt' + encryption, self, obj, self.send_gc_message)
|
'gc_encrypt' + encryption, self, obj, self.send_gc_message)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -770,14 +770,13 @@ class GroupchatControl(ChatControlBase):
|
||||||
self.draw_contact(nick)
|
self.draw_contact(nick)
|
||||||
|
|
||||||
def set_lock_image(self):
|
def set_lock_image(self):
|
||||||
visible = self.encryption != 'disabled'
|
encryption_state = {'visible': self.encryption is not None,
|
||||||
|
|
||||||
encryption_state = {'visible': visible,
|
|
||||||
'enc_type': self.encryption,
|
'enc_type': self.encryption,
|
||||||
'authenticated': False}
|
'authenticated': False}
|
||||||
|
|
||||||
gajim.plugin_manager.gui_extension_point(
|
if self.encryption:
|
||||||
'encryption_state' + self.encryption, self, encryption_state)
|
gajim.plugin_manager.gui_extension_point(
|
||||||
|
'encryption_state' + self.encryption, self, encryption_state)
|
||||||
|
|
||||||
self._show_lock_image(**encryption_state)
|
self._show_lock_image(**encryption_state)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue