Daniel Brötzmann pushed to branch newcontrol at gajim / gajim
Commits: 9448b3de by wurstsalat at 2022-07-04T23:04:17+02:00 Fix SecurityLabelSelector
- - - - -
6 changed files:
- gajim/common/events.py - gajim/common/structs.py - gajim/gtk/chat_stack.py - gajim/gtk/controls/base.py - gajim/gtk/message_actions_box.py - gajim/gtk/security_label_selector.py
Changes:
===================================== gajim/common/events.py ===================================== @@ -25,6 +25,8 @@
from nbxmpp.protocol import JID from nbxmpp.modules.security_labels import Catalog +from nbxmpp.modules.security_labels import Displaymarking +from nbxmpp.modules.security_labels import SecurityLabel from nbxmpp.structs import HTTPAuthData from nbxmpp.structs import ModerationData from nbxmpp.structs import LocationData @@ -162,7 +164,7 @@ class MessageSent(ApplicationEvent): chatstate: Optional[str] timestamp: float additional_data: AdditionalDataDict - label: Optional[str] + label: Optional[SecurityLabel] correct_id: Optional[str] play_sound: bool
@@ -393,7 +395,7 @@ class MessageReceived(ApplicationEvent): session: Any delayed: Optional[float] msg_log_id: int - displaymarking: str + displaymarking: Optional[Displaymarking]
@dataclass
===================================== gajim/common/structs.py ===================================== @@ -31,6 +31,7 @@ from nbxmpp.const import Chatstate from nbxmpp.const import PresenceShow from nbxmpp.const import Role +from nbxmpp.modules.security_labels import SecurityLabel from nbxmpp.protocol import JID from nbxmpp.structs import PresenceProperties
@@ -92,7 +93,7 @@ def __init__(self, marker: Optional[tuple[str, str]] = None, resource: Optional[str] = None, user_nick: Optional[str] = None, - label: Optional[str] = None, + label: Optional[SecurityLabel] = None, control: Optional[Any] = None, attention: Optional[bool] = None, correct_id: Optional[str] = None,
===================================== gajim/gtk/chat_stack.py ===================================== @@ -273,6 +273,7 @@ def _on_send_message(self) -> None: return
contact = self._current_contact + assert contact is not None client = app.get_client(contact.account)
message = helpers.remove_invalid_xml_chars(message) @@ -282,8 +283,7 @@ def _on_send_message(self) -> None: # if process_commands and self.process_as_command(message): # return
- # TODO - # label = self.get_seclabel() + label = self._message_action_box.get_seclabel()
correct_id: Optional[str] = None if control.correcting and control.last_sent_msg: @@ -303,7 +303,7 @@ def _on_send_message(self) -> None: message=message, type_=type_, chatstate=chatstate, - # label=label, + label=label, control=control, correct_id=correct_id)
===================================== gajim/gtk/controls/base.py ===================================== @@ -550,9 +550,6 @@ def drag_data_file_transfer(self, selection: Gtk.SelectionData) -> None:
self._start_filetransfer(path)
- def get_seclabel(self) -> Optional[str]: - return self._security_label_selector.get_seclabel() - def get_our_nick(self) -> str: return app.nicks[self.account]
===================================== gajim/gtk/message_actions_box.py ===================================== @@ -29,7 +29,9 @@ from gi.repository import Gio from gi.repository import Gtk from gi.repository import GObject + from nbxmpp.const import Chatstate +from nbxmpp.modules.security_labels import SecurityLabel
from gajim.common import app from gajim.common import i18n @@ -76,9 +78,8 @@ def __init__(self) -> None: self._ui.send_message_button, 'set_visible')
- # self._security_label_selector = SecurityLabelSelector( - # account, self._contact) - # self._ui.box.pack_start(self._security_label_selector, False, True, 0) + self._security_label_selector = SecurityLabelSelector() + self._ui.box.pack_start(self._security_label_selector, False, True, 0)
self.msg_textview = MessageInputTextView() self.msg_textview.get_buffer().connect('changed', @@ -113,6 +114,9 @@ def get_current_contact(self) -> ChatContactT: assert self._contact is not None return self._contact
+ def get_seclabel(self) -> Optional[SecurityLabel]: + return self._security_label_selector.get_seclabel() + def _connect_actions(self) -> None: actions = [ 'input-bold', @@ -169,11 +173,11 @@ def switch_contact(self, contact: ChatContactT) -> None: self._set_spell_checker_language(contact) self._set_chatstate()
+ self._security_label_selector.switch_contact(contact) + def _set_chatstate(self) -> None: return #TODO if state: - self._security_label_selector.update() - if self.msg_textview.has_text(): self._client.get_module('Chatstate').set_chatstate( self.contact, Chatstate.PAUSED)
===================================== gajim/gtk/security_label_selector.py ===================================== @@ -19,6 +19,7 @@ from gi.repository import Gtk from gi.repository import Pango
+from nbxmpp.modules.security_labels import SecurityLabel from nbxmpp.protocol import JID
from gajim.common import app @@ -31,11 +32,11 @@
class SecurityLabelSelector(Gtk.ComboBox): - def __init__(self, account: str, contact: ChatContactT) -> None: + def __init__(self) -> None: Gtk.ComboBox.__init__(self, no_show_all=True) - self._account = account - self._client = app.get_client(account) - self._contact = contact + self._account: Optional[str] = None + self._client: Optional[Client] = None + self._contact: Optional[ChatContactT] = None
self.set_valign(Gtk.Align.CENTER) self.set_tooltip_text(_('Select a security label for your message…')) @@ -51,14 +52,25 @@ def __init__(self, account: str, contact: ChatContactT) -> None: app.ged.register_event_handler( 'sec-catalog-received', ged.GUI1, self._sec_labels_received)
+ self.connect('changed', self._on_changed) + self.connect('destroy', self._on_destroy) + + def switch_contact(self, contact: ChatContactT) -> None: + app.settings.disconnect_signals(self) + if self._client is not None: + self._client.disconnect_all_from_obj(self) + + self._account = contact.account + self._client = app.get_client(contact.account) + self._contact = contact + app.settings.connect_signal( 'enable_security_labels', self._on_setting_changed, account=self._account) self._client.connect_signal( 'state-changed', self._on_client_state_changed) - self.connect('changed', self._on_changed) - self.connect('destroy', self._on_destroy) + self._update()
def _on_destroy(self, _widget: SecurityLabelSelector) -> None: app.ged.remove_event_handler('sec-catalog-received', @@ -79,13 +91,14 @@ def _on_changed(self, _combo: Gtk.ComboBox) -> None: def _on_client_state_changed(self, _client: Client, _signal_name: str, - _state: SimpleClientState): - self.update() + _state: SimpleClientState + ) -> None: + self._update()
def _on_setting_changed(self, state: bool, _name: str, - account: str, + _account: Optional[str], _jid: Optional[JID] ) -> None: self.set_no_show_all(not state) @@ -93,9 +106,13 @@ def _on_setting_changed(self, self.show_all() else: self.hide() + self._update()
def _sec_labels_received(self, event: SecCatalogReceived) -> None: - if event.account != self._account: + if self._account is None or self._account != event.account: + return + + if self._contact is None: return
if event.jid != self._contact.jid.bare: @@ -120,11 +137,13 @@ def _sec_labels_received(self, event: SecCatalogReceived) -> None: self.set_no_show_all(False) self.show_all()
- def get_seclabel(self) -> Optional[str]: + def get_seclabel(self) -> Optional[SecurityLabel]: index = self.get_active() if index == -1: return None
+ assert self._contact is not None + assert self._client is not None jid = self._contact.jid.bare catalog = self._client.get_module('SecLabels').get_catalog(jid) if catalog is None: @@ -132,10 +151,13 @@ def get_seclabel(self) -> Optional[str]:
labels, label_list = catalog.labels, catalog.get_label_names() label_name = label_list[index] - label = labels[label_name] - return label + return labels[label_name] + + def _update(self) -> None: + assert self._account is not None + assert self._client is not None + assert self._contact is not None
- def update(self) -> None: chat_active = app.window.is_chat_active( self._account, self._contact.jid) if chat_active:
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/9448b3decaae2bb9e4b2253cd8725586a...