Philipp Hörist pushed to branch master at gajim / gajim
Commits: 8a6b117a by wurstsalat at 2022-08-24T20:48:16+02:00 imprv: MessageActionsBox: Disable encryption button if MUC is public
Fixes #10959
- - - - -
3 changed files:
- gajim/common/modules/contacts.py - gajim/data/gui/message_actions_box.ui - gajim/gtk/message_actions_box.py
Changes:
===================================== gajim/common/modules/contacts.py ===================================== @@ -671,6 +671,15 @@ def is_irc(self) -> bool: return False return disco_info.is_irc
+ @property + def encryption_available(self) -> bool: + disco_info = self.get_disco() + if disco_info is None: + return True + + return (disco_info.muc_is_members_only and + disco_info.muc_is_nonanonymous) + def get_config_value(self, field_name: str) -> Any: disco_info = self.get_disco() assert disco_info is not None
===================================== gajim/data/gui/message_actions_box.ui ===================================== @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.38.2 --> +<!-- Generated with glade 3.40.0 --> <interface> <requires lib="gtk+" version="3.24"/> <object class="GtkBox" id="box"> @@ -91,7 +91,6 @@ <property name="visible">True</property> <property name="can-focus">True</property> <property name="receives-default">True</property> - <property name="tooltip-text" translatable="yes">Choose encryption</property> <property name="relief">none</property> <child> <object class="GtkImage" id="encryption_image">
===================================== gajim/gtk/message_actions_box.py ===================================== @@ -219,9 +219,8 @@ def switch_contact(self, contact: ChatContactT) -> None:
self._set_settings_menu(contact)
- encryption = self._contact.settings.get('encryption') - self._set_encryption_state(encryption) - self._set_encryption_details(encryption) + self._update_encryption_button() + self._update_encryption_details_button()
self._set_chatstate(True)
@@ -286,18 +285,6 @@ def _set_chatstate(self, state: bool) -> None: self._client.get_module('Chatstate').set_chatstate( self._contact, Chatstate.INACTIVE)
- def _set_encryption_state(self, state: str) -> None: - action = app.window.get_action('set-encryption') - action.set_state(GLib.Variant('s', state)) - - if state in ('OMEMO', 'OpenPGP', 'PGP'): - icon_name = 'channel-secure-symbolic' - else: - icon_name = 'channel-insecure-symbolic' - - self._ui.encryption_image.set_from_icon_name(icon_name, - Gtk.IconSize.MENU) - def _change_encryption(self, action: Gio.SimpleAction, param: GLib.Variant @@ -319,13 +306,43 @@ def _change_encryption(self, if not plugin.activate_encryption(app.window.get_control()): return
- self._set_encryption_state(new_state) contact = self.get_current_contact() contact.settings.set('encryption', new_state)
- self._set_encryption_details(new_state) + self._update_encryption_button() + self._update_encryption_details_button() + + def _update_encryption_button(self) -> None: + contact = self.get_current_contact() + state = contact.settings.get('encryption') + + action = app.window.get_action('set-encryption') + action.set_state(GLib.Variant('s', state)) + + sensitive = True + tooltip = _('Choose encryption') + + if state in ('OMEMO', 'OpenPGP', 'PGP'): + icon_name = 'channel-secure-symbolic' + else: + icon_name = 'channel-insecure-symbolic' + + if isinstance(self._contact, GroupchatContact): + if not self._contact.encryption_available: + sensitive = False + tooltip = _('This is a public group chat. ' + 'Encryption is not available.') + icon_name = 'channel-insecure-symbolic' + + self._ui.encryption_menu_button.set_sensitive(sensitive) + self._ui.encryption_menu_button.set_tooltip_text(tooltip) + self._ui.encryption_image.set_from_icon_name( + icon_name, Gtk.IconSize.MENU) + + def _update_encryption_details_button(self) -> None: + contact = self.get_current_contact() + state = contact.settings.get('encryption')
- def _set_encryption_details(self, state: str) -> None: encryption_state = {'visible': bool(state), 'enc_type': state, 'authenticated': False} @@ -341,19 +358,22 @@ def _set_encryption_details(self, state: str) -> None:
if authenticated: authenticated_string = _('and authenticated') - self._ui.encryption_details_image.set_from_icon_name( - 'security-high-symbolic', Gtk.IconSize.MENU) + icon_name = 'security-high-symbolic' else: authenticated_string = _('and NOT authenticated') - self._ui.encryption_details_image.set_from_icon_name( - 'security-low-symbolic', Gtk.IconSize.MENU) + icon_name = 'security-low-symbolic'
tooltip = _('%(type)s encryption is active %(authenticated)s.') % { - 'type': enc_type, 'authenticated': authenticated_string} + 'type': enc_type, + 'authenticated': authenticated_string} + + if isinstance(self._contact, GroupchatContact) and visible: + visible = self._contact.encryption_available
- self._ui.encryption_details_button.set_tooltip_text(tooltip) self._ui.encryption_details_button.set_visible(visible) - self._ui.encryption_details_image.set_sensitive(visible) + self._ui.encryption_details_button.set_tooltip_text(tooltip) + self._ui.encryption_details_image.set_from_icon_name( + icon_name, Gtk.IconSize.MENU)
def _on_encryption_details_clicked(self, _button: Gtk.Button) -> None: contact = self.get_current_contact()
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/8a6b117ae383248b077540c3bb3e39818...