Daniel Brötzmann pushed to branch newcontrol at gajim / gajim
Commits:
-
9448b3de
by wurstsalat at 2022-07-04T23:04:17+02:00
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:
| ... | ... | @@ -25,6 +25,8 @@ |
| 25 | 25 | |
| 26 | 26 | from nbxmpp.protocol import JID
|
| 27 | 27 | from nbxmpp.modules.security_labels import Catalog
|
| 28 | +from nbxmpp.modules.security_labels import Displaymarking
|
|
| 29 | +from nbxmpp.modules.security_labels import SecurityLabel
|
|
| 28 | 30 | from nbxmpp.structs import HTTPAuthData
|
| 29 | 31 | from nbxmpp.structs import ModerationData
|
| 30 | 32 | from nbxmpp.structs import LocationData
|
| ... | ... | @@ -162,7 +164,7 @@ class MessageSent(ApplicationEvent): |
| 162 | 164 | chatstate: Optional[str]
|
| 163 | 165 | timestamp: float
|
| 164 | 166 | additional_data: AdditionalDataDict
|
| 165 | - label: Optional[str]
|
|
| 167 | + label: Optional[SecurityLabel]
|
|
| 166 | 168 | correct_id: Optional[str]
|
| 167 | 169 | play_sound: bool
|
| 168 | 170 | |
| ... | ... | @@ -393,7 +395,7 @@ class MessageReceived(ApplicationEvent): |
| 393 | 395 | session: Any
|
| 394 | 396 | delayed: Optional[float]
|
| 395 | 397 | msg_log_id: int
|
| 396 | - displaymarking: str
|
|
| 398 | + displaymarking: Optional[Displaymarking]
|
|
| 397 | 399 | |
| 398 | 400 | |
| 399 | 401 | @dataclass
|
| ... | ... | @@ -31,6 +31,7 @@ |
| 31 | 31 | from nbxmpp.const import Chatstate
|
| 32 | 32 | from nbxmpp.const import PresenceShow
|
| 33 | 33 | from nbxmpp.const import Role
|
| 34 | +from nbxmpp.modules.security_labels import SecurityLabel
|
|
| 34 | 35 | from nbxmpp.protocol import JID
|
| 35 | 36 | from nbxmpp.structs import PresenceProperties
|
| 36 | 37 | |
| ... | ... | @@ -92,7 +93,7 @@ def __init__(self, |
| 92 | 93 | marker: Optional[tuple[str, str]] = None,
|
| 93 | 94 | resource: Optional[str] = None,
|
| 94 | 95 | user_nick: Optional[str] = None,
|
| 95 | - label: Optional[str] = None,
|
|
| 96 | + label: Optional[SecurityLabel] = None,
|
|
| 96 | 97 | control: Optional[Any] = None,
|
| 97 | 98 | attention: Optional[bool] = None,
|
| 98 | 99 | correct_id: Optional[str] = None,
|
| ... | ... | @@ -273,6 +273,7 @@ def _on_send_message(self) -> None: |
| 273 | 273 | return
|
| 274 | 274 | |
| 275 | 275 | contact = self._current_contact
|
| 276 | + assert contact is not None
|
|
| 276 | 277 | client = app.get_client(contact.account)
|
| 277 | 278 | |
| 278 | 279 | message = helpers.remove_invalid_xml_chars(message)
|
| ... | ... | @@ -282,8 +283,7 @@ def _on_send_message(self) -> None: |
| 282 | 283 | # if process_commands and self.process_as_command(message):
|
| 283 | 284 | # return
|
| 284 | 285 | |
| 285 | - # TODO
|
|
| 286 | - # label = self.get_seclabel()
|
|
| 286 | + label = self._message_action_box.get_seclabel()
|
|
| 287 | 287 | |
| 288 | 288 | correct_id: Optional[str] = None
|
| 289 | 289 | if control.correcting and control.last_sent_msg:
|
| ... | ... | @@ -303,7 +303,7 @@ def _on_send_message(self) -> None: |
| 303 | 303 | message=message,
|
| 304 | 304 | type_=type_,
|
| 305 | 305 | chatstate=chatstate,
|
| 306 | - # label=label,
|
|
| 306 | + label=label,
|
|
| 307 | 307 | control=control,
|
| 308 | 308 | correct_id=correct_id)
|
| 309 | 309 |
| ... | ... | @@ -550,9 +550,6 @@ def drag_data_file_transfer(self, selection: Gtk.SelectionData) -> None: |
| 550 | 550 | |
| 551 | 551 | self._start_filetransfer(path)
|
| 552 | 552 | |
| 553 | - def get_seclabel(self) -> Optional[str]:
|
|
| 554 | - return self._security_label_selector.get_seclabel()
|
|
| 555 | - |
|
| 556 | 553 | def get_our_nick(self) -> str:
|
| 557 | 554 | return app.nicks[self.account]
|
| 558 | 555 |
| ... | ... | @@ -29,7 +29,9 @@ |
| 29 | 29 | from gi.repository import Gio
|
| 30 | 30 | from gi.repository import Gtk
|
| 31 | 31 | from gi.repository import GObject
|
| 32 | + |
|
| 32 | 33 | from nbxmpp.const import Chatstate
|
| 34 | +from nbxmpp.modules.security_labels import SecurityLabel
|
|
| 33 | 35 | |
| 34 | 36 | from gajim.common import app
|
| 35 | 37 | from gajim.common import i18n
|
| ... | ... | @@ -76,9 +78,8 @@ def __init__(self) -> None: |
| 76 | 78 | self._ui.send_message_button,
|
| 77 | 79 | 'set_visible')
|
| 78 | 80 | |
| 79 | - # self._security_label_selector = SecurityLabelSelector(
|
|
| 80 | - # account, self._contact)
|
|
| 81 | - # self._ui.box.pack_start(self._security_label_selector, False, True, 0)
|
|
| 81 | + self._security_label_selector = SecurityLabelSelector()
|
|
| 82 | + self._ui.box.pack_start(self._security_label_selector, False, True, 0)
|
|
| 82 | 83 | |
| 83 | 84 | self.msg_textview = MessageInputTextView()
|
| 84 | 85 | self.msg_textview.get_buffer().connect('changed',
|
| ... | ... | @@ -113,6 +114,9 @@ def get_current_contact(self) -> ChatContactT: |
| 113 | 114 | assert self._contact is not None
|
| 114 | 115 | return self._contact
|
| 115 | 116 | |
| 117 | + def get_seclabel(self) -> Optional[SecurityLabel]:
|
|
| 118 | + return self._security_label_selector.get_seclabel()
|
|
| 119 | + |
|
| 116 | 120 | def _connect_actions(self) -> None:
|
| 117 | 121 | actions = [
|
| 118 | 122 | 'input-bold',
|
| ... | ... | @@ -169,11 +173,11 @@ def switch_contact(self, contact: ChatContactT) -> None: |
| 169 | 173 | self._set_spell_checker_language(contact)
|
| 170 | 174 | self._set_chatstate()
|
| 171 | 175 | |
| 176 | + self._security_label_selector.switch_contact(contact)
|
|
| 177 | + |
|
| 172 | 178 | def _set_chatstate(self) -> None:
|
| 173 | 179 | return #TODO
|
| 174 | 180 | if state:
|
| 175 | - self._security_label_selector.update()
|
|
| 176 | - |
|
| 177 | 181 | if self.msg_textview.has_text():
|
| 178 | 182 | self._client.get_module('Chatstate').set_chatstate(
|
| 179 | 183 | self.contact, Chatstate.PAUSED)
|
| ... | ... | @@ -19,6 +19,7 @@ |
| 19 | 19 | from gi.repository import Gtk
|
| 20 | 20 | from gi.repository import Pango
|
| 21 | 21 | |
| 22 | +from nbxmpp.modules.security_labels import SecurityLabel
|
|
| 22 | 23 | from nbxmpp.protocol import JID
|
| 23 | 24 | |
| 24 | 25 | from gajim.common import app
|
| ... | ... | @@ -31,11 +32,11 @@ |
| 31 | 32 | |
| 32 | 33 | |
| 33 | 34 | class SecurityLabelSelector(Gtk.ComboBox):
|
| 34 | - def __init__(self, account: str, contact: ChatContactT) -> None:
|
|
| 35 | + def __init__(self) -> None:
|
|
| 35 | 36 | Gtk.ComboBox.__init__(self, no_show_all=True)
|
| 36 | - self._account = account
|
|
| 37 | - self._client = app.get_client(account)
|
|
| 38 | - self._contact = contact
|
|
| 37 | + self._account: Optional[str] = None
|
|
| 38 | + self._client: Optional[Client] = None
|
|
| 39 | + self._contact: Optional[ChatContactT] = None
|
|
| 39 | 40 | |
| 40 | 41 | self.set_valign(Gtk.Align.CENTER)
|
| 41 | 42 | self.set_tooltip_text(_('Select a security label for your message…'))
|
| ... | ... | @@ -51,14 +52,25 @@ def __init__(self, account: str, contact: ChatContactT) -> None: |
| 51 | 52 | app.ged.register_event_handler(
|
| 52 | 53 | 'sec-catalog-received', ged.GUI1, self._sec_labels_received)
|
| 53 | 54 | |
| 55 | + self.connect('changed', self._on_changed)
|
|
| 56 | + self.connect('destroy', self._on_destroy)
|
|
| 57 | + |
|
| 58 | + def switch_contact(self, contact: ChatContactT) -> None:
|
|
| 59 | + app.settings.disconnect_signals(self)
|
|
| 60 | + if self._client is not None:
|
|
| 61 | + self._client.disconnect_all_from_obj(self)
|
|
| 62 | + |
|
| 63 | + self._account = contact.account
|
|
| 64 | + self._client = app.get_client(contact.account)
|
|
| 65 | + self._contact = contact
|
|
| 66 | + |
|
| 54 | 67 | app.settings.connect_signal(
|
| 55 | 68 | 'enable_security_labels',
|
| 56 | 69 | self._on_setting_changed,
|
| 57 | 70 | account=self._account)
|
| 58 | 71 | self._client.connect_signal(
|
| 59 | 72 | 'state-changed', self._on_client_state_changed)
|
| 60 | - self.connect('changed', self._on_changed)
|
|
| 61 | - self.connect('destroy', self._on_destroy)
|
|
| 73 | + self._update()
|
|
| 62 | 74 | |
| 63 | 75 | def _on_destroy(self, _widget: SecurityLabelSelector) -> None:
|
| 64 | 76 | app.ged.remove_event_handler('sec-catalog-received',
|
| ... | ... | @@ -79,13 +91,14 @@ def _on_changed(self, _combo: Gtk.ComboBox) -> None: |
| 79 | 91 | def _on_client_state_changed(self,
|
| 80 | 92 | _client: Client,
|
| 81 | 93 | _signal_name: str,
|
| 82 | - _state: SimpleClientState):
|
|
| 83 | - self.update()
|
|
| 94 | + _state: SimpleClientState
|
|
| 95 | + ) -> None:
|
|
| 96 | + self._update()
|
|
| 84 | 97 | |
| 85 | 98 | def _on_setting_changed(self,
|
| 86 | 99 | state: bool,
|
| 87 | 100 | _name: str,
|
| 88 | - account: str,
|
|
| 101 | + _account: Optional[str],
|
|
| 89 | 102 | _jid: Optional[JID]
|
| 90 | 103 | ) -> None:
|
| 91 | 104 | self.set_no_show_all(not state)
|
| ... | ... | @@ -93,9 +106,13 @@ def _on_setting_changed(self, |
| 93 | 106 | self.show_all()
|
| 94 | 107 | else:
|
| 95 | 108 | self.hide()
|
| 109 | + self._update()
|
|
| 96 | 110 | |
| 97 | 111 | def _sec_labels_received(self, event: SecCatalogReceived) -> None:
|
| 98 | - if event.account != self._account:
|
|
| 112 | + if self._account is None or self._account != event.account:
|
|
| 113 | + return
|
|
| 114 | + |
|
| 115 | + if self._contact is None:
|
|
| 99 | 116 | return
|
| 100 | 117 | |
| 101 | 118 | if event.jid != self._contact.jid.bare:
|
| ... | ... | @@ -120,11 +137,13 @@ def _sec_labels_received(self, event: SecCatalogReceived) -> None: |
| 120 | 137 | self.set_no_show_all(False)
|
| 121 | 138 | self.show_all()
|
| 122 | 139 | |
| 123 | - def get_seclabel(self) -> Optional[str]:
|
|
| 140 | + def get_seclabel(self) -> Optional[SecurityLabel]:
|
|
| 124 | 141 | index = self.get_active()
|
| 125 | 142 | if index == -1:
|
| 126 | 143 | return None
|
| 127 | 144 | |
| 145 | + assert self._contact is not None
|
|
| 146 | + assert self._client is not None
|
|
| 128 | 147 | jid = self._contact.jid.bare
|
| 129 | 148 | catalog = self._client.get_module('SecLabels').get_catalog(jid)
|
| 130 | 149 | if catalog is None:
|
| ... | ... | @@ -132,10 +151,13 @@ def get_seclabel(self) -> Optional[str]: |
| 132 | 151 | |
| 133 | 152 | labels, label_list = catalog.labels, catalog.get_label_names()
|
| 134 | 153 | label_name = label_list[index]
|
| 135 | - label = labels[label_name]
|
|
| 136 | - return label
|
|
| 154 | + return labels[label_name]
|
|
| 155 | + |
|
| 156 | + def _update(self) -> None:
|
|
| 157 | + assert self._account is not None
|
|
| 158 | + assert self._client is not None
|
|
| 159 | + assert self._contact is not None
|
|
| 137 | 160 | |
| 138 | - def update(self) -> None:
|
|
| 139 | 161 | chat_active = app.window.is_chat_active(
|
| 140 | 162 | self._account, self._contact.jid)
|
| 141 | 163 | if chat_active:
|