Daniel Brötzmann pushed to branch newcontrol at gajim / gajim
Commits:
-
bd4ce98e
by wurstsalat at 2022-07-09T17:59:14+02:00
-
40f863f1
by wurstsalat at 2022-07-10T19:07:03+02:00
7 changed files:
- gajim/gtk/chat_banner.py
- gajim/gtk/chat_stack.py
- gajim/gtk/controls/base.py
- gajim/gtk/controls/chat.py
- gajim/gtk/controls/groupchat.py
- gajim/gtk/controls/private.py
- gajim/gtk/message_actions_box.py
Changes:
| ... | ... | @@ -117,6 +117,8 @@ def switch_contact(self, |
| 117 | 117 | |
| 118 | 118 | if isinstance(self._contact, GroupchatParticipant):
|
| 119 | 119 | self._contact.multi_connect({
|
| 120 | + 'user-joined': self._on_user_state_changed,
|
|
| 121 | + 'user-left': self._on_user_state_changed,
|
|
| 120 | 122 | 'user-avatar-update': self._on_user_avatar_update,
|
| 121 | 123 | 'user-nickname-changed': self._on_user_nickname_changed
|
| 122 | 124 | })
|
| ... | ... | @@ -193,6 +195,9 @@ def _on_user_nickname_changed(self, |
| 193 | 195 | |
| 194 | 196 | self._update_content()
|
| 195 | 197 | |
| 198 | + def _on_user_state_changed(self, *args: Any) -> None:
|
|
| 199 | + self._update_avatar()
|
|
| 200 | + |
|
| 196 | 201 | def _on_user_avatar_update(self, *args: Any) -> None:
|
| 197 | 202 | self._update_avatar()
|
| 198 | 203 |
| ... | ... | @@ -96,6 +96,8 @@ def show_chat(self, account: str, jid: JID) -> None: |
| 96 | 96 | 'state-changed': self._on_muc_state_changed
|
| 97 | 97 | })
|
| 98 | 98 | self._update_group_chat_actions(self._current_contact)
|
| 99 | + elif isinstance(self._current_contact, GroupchatParticipant):
|
|
| 100 | + self._update_participant_actions(self._current_contact)
|
|
| 99 | 101 | else:
|
| 100 | 102 | self._update_chat_actions(self._current_contact)
|
| 101 | 103 |
| ... | ... | @@ -327,24 +327,11 @@ def update_actions(self) -> None: |
| 327 | 327 | Derived types MAY implement this
|
| 328 | 328 | """
|
| 329 | 329 | |
| 330 | - def update_toolbar(self) -> None:
|
|
| 331 | - """
|
|
| 332 | - update state of buttons in toolbar
|
|
| 333 | - """
|
|
| 334 | - self._update_toolbar()
|
|
| 335 | - app.plugin_manager.gui_extension_point(
|
|
| 336 | - 'chat_control_base_update_toolbar', self)
|
|
| 337 | - |
|
| 338 | 330 | def update_ui(self) -> None:
|
| 339 | 331 | """
|
| 340 | 332 | Derived types SHOULD implement this
|
| 341 | 333 | """
|
| 342 | 334 | |
| 343 | - def _update_toolbar(self) -> None:
|
|
| 344 | - """
|
|
| 345 | - Derived types MAY implement this
|
|
| 346 | - """
|
|
| 347 | - |
|
| 348 | 335 | def _nec_ping(self, obj):
|
| 349 | 336 | raise NotImplementedError
|
| 350 | 337 | |
| ... | ... | @@ -382,8 +369,6 @@ def shutdown(self) -> None: |
| 382 | 369 | # Plugins might want to remove their widgets on
|
| 383 | 370 | # remove_gui_extension_point(), so delete the objects only afterwards.
|
| 384 | 371 | app.plugin_manager.remove_gui_extension_point('chat_control_base', self)
|
| 385 | - app.plugin_manager.remove_gui_extension_point(
|
|
| 386 | - 'chat_control_base_update_toolbar', self)
|
|
| 387 | 372 | |
| 388 | 373 | self._client.disconnect_all_from_obj(self)
|
| 389 | 374 | self.contact.disconnect_all_from_obj(self)
|
| ... | ... | @@ -688,12 +673,6 @@ def set_control_active(self, state: bool) -> None: |
| 688 | 673 | if not self._chat_loaded:
|
| 689 | 674 | self.fetch_n_lines_history(self._scrolled_view, True, 20)
|
| 690 | 675 | |
| 691 | - def set_message_input_state(self, state: bool) -> None:
|
|
| 692 | - return
|
|
| 693 | - # self.xml.formattings_button.set_sensitive(state)
|
|
| 694 | - # self.msg_textview.set_sensitive(state)
|
|
| 695 | - # self.msg_textview.set_editable(state)
|
|
| 696 | - |
|
| 697 | 676 | @property
|
| 698 | 677 | def is_chat_loaded(self) -> bool:
|
| 699 | 678 | return self._chat_loaded
|
| ... | ... | @@ -85,7 +85,6 @@ def __init__(self, account: str, jid: JID) -> None: |
| 85 | 85 | self._client.connect_signal('state-changed',
|
| 86 | 86 | self._on_client_state_changed)
|
| 87 | 87 | |
| 88 | - self.update_toolbar()
|
|
| 89 | 88 | self.update_ui()
|
| 90 | 89 | |
| 91 | 90 | # PluginSystem: adding GUI extension point for this ChatControl
|
| ... | ... | @@ -94,9 +93,7 @@ def __init__(self, account: str, jid: JID) -> None: |
| 94 | 93 | self.update_actions()
|
| 95 | 94 | |
| 96 | 95 | def _connect_contact_signals(self) -> None:
|
| 97 | - self.contact.multi_connect({
|
|
| 98 | - 'caps-update': self._on_caps_update,
|
|
| 99 | - })
|
|
| 96 | + pass
|
|
| 100 | 97 | |
| 101 | 98 | @property
|
| 102 | 99 | def jid(self) -> JID:
|
| ... | ... | @@ -114,12 +111,6 @@ def focus(self) -> None: |
| 114 | 111 | def delegate_action(self, action: str) -> int:
|
| 115 | 112 | return Gdk.EVENT_PROPAGATE
|
| 116 | 113 | |
| 117 | - def _on_caps_update(self,
|
|
| 118 | - _contact: types.BareContact,
|
|
| 119 | - _signal_name: str
|
|
| 120 | - ) -> None:
|
|
| 121 | - self.update_ui()
|
|
| 122 | - |
|
| 123 | 114 | def _on_mam_message_received(self,
|
| 124 | 115 | event: events.MamMessageReceived) -> None:
|
| 125 | 116 | if event.properties.is_muc_pm:
|
| ... | ... | @@ -214,7 +205,6 @@ def _nec_ping(self, event: events.ApplicationEvent): |
| 214 | 205 | |
| 215 | 206 | def update_ui(self) -> None:
|
| 216 | 207 | BaseControl.update_ui(self)
|
| 217 | - self.update_toolbar()
|
|
| 218 | 208 | self.update_actions()
|
| 219 | 209 | |
| 220 | 210 | def add_message(self,
|
| ... | ... | @@ -281,9 +271,6 @@ def _on_client_state_changed(self, |
| 281 | 271 | _client: Client,
|
| 282 | 272 | _signal_name: str,
|
| 283 | 273 | state: SimpleClientState):
|
| 284 | - self.set_message_input_state(state.is_connected)
|
|
| 285 | - |
|
| 286 | - self.update_toolbar()
|
|
| 287 | 274 | self.update_actions()
|
| 288 | 275 | |
| 289 | 276 | def _on_presence_received(self, event: events.PresenceReceived) -> None:
|
| ... | ... | @@ -610,17 +610,12 @@ def _nec_ping(self, event: events.ApplicationEvent) -> None: |
| 610 | 610 | self.add_info_message(event.error)
|
| 611 | 611 | |
| 612 | 612 | def _set_control_active(self) -> None:
|
| 613 | - self_contact = self.contact.get_self()
|
|
| 614 | - self.set_message_input_state(not self_contact.role.is_visitor)
|
|
| 615 | - |
|
| 616 | 613 | self.roster.initial_draw()
|
| 617 | 614 | self.conversation_view.update_avatars()
|
| 618 | 615 | |
| 619 | 616 | self.update_actions()
|
| 620 | 617 | |
| 621 | 618 | def _set_control_inactive(self) -> None:
|
| 622 | - self.set_message_input_state(False)
|
|
| 623 | - |
|
| 624 | 619 | self.roster.enable_sort(False)
|
| 625 | 620 | self.roster.clear()
|
| 626 | 621 | |
| ... | ... | @@ -758,7 +753,6 @@ def _on_user_role_changed(self, |
| 758 | 753 | actor = '' if actor is None else _(' by {actor}').format(actor=actor)
|
| 759 | 754 | |
| 760 | 755 | if properties.is_muc_self_presence:
|
| 761 | - self.set_message_input_state(not user_contact.role.is_visitor)
|
|
| 762 | 756 | message = _('** Your Role has been set to '
|
| 763 | 757 | '{role}{actor}{reason}').format(role=role,
|
| 764 | 758 | actor=actor,
|
| ... | ... | @@ -58,14 +58,10 @@ def __init__(self, account: str, jid: JID) -> None: |
| 58 | 58 | |
| 59 | 59 | def _connect_contact_signals(self) -> None:
|
| 60 | 60 | self.contact.multi_connect({
|
| 61 | - 'user-joined': self._on_user_joined,
|
|
| 62 | - 'user-left': self._on_user_left,
|
|
| 63 | 61 | 'user-status-show-changed': self._on_user_status_show_changed,
|
| 64 | 62 | 'user-nickname-changed': self._on_user_nickname_changed,
|
| 65 | 63 | # 'room-kicked': self._on_room_kicked,
|
| 66 | 64 | # 'room-destroyed': self._on_room_destroyed,
|
| 67 | - 'room-joined': self._on_room_joined,
|
|
| 68 | - # 'room-left': self._on_room_left
|
|
| 69 | 65 | })
|
| 70 | 66 | |
| 71 | 67 | @property
|
| ... | ... | @@ -121,33 +117,6 @@ def _on_user_status_show_changed(self, |
| 121 | 117 | self.add_info_message(message)
|
| 122 | 118 | self.update_ui()
|
| 123 | 119 | |
| 124 | - # def _on_disconnected(self, event):
|
|
| 125 | - # if event.properties.jid != self.contact.jid:
|
|
| 126 | - # return
|
|
| 127 | - # self.set_message_input_state(False)
|
|
| 128 | - |
|
| 129 | - def _on_user_left(self,
|
|
| 130 | - _user_contact: GroupchatParticipant,
|
|
| 131 | - _signal_name: str,
|
|
| 132 | - _properties: MessageProperties
|
|
| 133 | - ) -> None:
|
|
| 134 | - self.set_message_input_state(False)
|
|
| 135 | - |
|
| 136 | - def _on_user_joined(self,
|
|
| 137 | - _user_contact: GroupchatParticipant,
|
|
| 138 | - _signal_name: str,
|
|
| 139 | - _properties: MessageProperties
|
|
| 140 | - ) -> None:
|
|
| 141 | - self.set_message_input_state(True)
|
|
| 142 | - |
|
| 143 | - def _on_room_joined(self,
|
|
| 144 | - _contact: GroupchatContact,
|
|
| 145 | - _signal_name: str
|
|
| 146 | - ) -> None:
|
|
| 147 | - if not self.contact.is_available:
|
|
| 148 | - return
|
|
| 149 | - self.set_message_input_state(True)
|
|
| 150 | - |
|
| 151 | 120 | def send_message(self,
|
| 152 | 121 | message: str,
|
| 153 | 122 | process_commands: bool = True,
|
| ... | ... | @@ -36,6 +36,8 @@ |
| 36 | 36 | from gajim.common import app
|
| 37 | 37 | from gajim.common import i18n
|
| 38 | 38 | from gajim.common.i18n import _
|
| 39 | +from gajim.common.client import Client
|
|
| 40 | +from gajim.common.const import SimpleClientState
|
|
| 39 | 41 | from gajim.common.const import Direction
|
| 40 | 42 | from gajim.common.modules.contacts import GroupchatContact
|
| 41 | 43 | from gajim.common.modules.contacts import GroupchatParticipant
|
| ... | ... | @@ -65,6 +67,7 @@ class MessageActionsBox(Gtk.Grid): |
| 65 | 67 | def __init__(self) -> None:
|
| 66 | 68 | super().__init__()
|
| 67 | 69 | |
| 70 | + self._client: Optional[Client] = None
|
|
| 68 | 71 | self._contact: Optional[ChatContactT] = None
|
| 69 | 72 | |
| 70 | 73 | self._ui = get_builder('message_actions_box.ui')
|
| ... | ... | @@ -175,7 +178,30 @@ def _on_action(self, |
| 175 | 178 | self.msg_textview.mention_participant(param.get_string())
|
| 176 | 179 | |
| 177 | 180 | def switch_contact(self, contact: ChatContactT) -> None:
|
| 181 | + if self._client is not None:
|
|
| 182 | + self._client.disconnect_all_from_obj(self)
|
|
| 183 | + |
|
| 184 | + if self._contact is not None:
|
|
| 185 | + self._contact.disconnect_all_from_obj(self)
|
|
| 186 | + |
|
| 187 | + self._client = app.get_client(contact.account)
|
|
| 188 | + self._client.connect_signal(
|
|
| 189 | + 'state-changed', self._on_client_state_changed)
|
|
| 190 | + |
|
| 178 | 191 | self._contact = contact
|
| 192 | + if isinstance(self._contact, GroupchatContact):
|
|
| 193 | + self._contact.multi_connect({
|
|
| 194 | + 'state-changed': self._on_muc_state_changed,
|
|
| 195 | + 'user-role-changed': self._on_muc_state_changed,
|
|
| 196 | + })
|
|
| 197 | + if isinstance(self._contact, GroupchatParticipant):
|
|
| 198 | + self._contact.multi_connect({
|
|
| 199 | + 'user-joined': self._on_user_state_changed,
|
|
| 200 | + 'user-left': self._on_user_state_changed,
|
|
| 201 | + 'room-joined': self._on_user_state_changed,
|
|
| 202 | + 'room-left': self._on_user_state_changed,
|
|
| 203 | + })
|
|
| 204 | + |
|
| 179 | 205 | self._set_settings_menu(contact)
|
| 180 | 206 | |
| 181 | 207 | encryption = self._contact.settings.get('encryption')
|
| ... | ... | @@ -188,6 +214,40 @@ def switch_contact(self, contact: ChatContactT) -> None: |
| 188 | 214 | self.msg_textview.switch_contact(contact)
|
| 189 | 215 | self._security_label_selector.switch_contact(contact)
|
| 190 | 216 | |
| 217 | + self._update_message_input_state()
|
|
| 218 | + |
|
| 219 | + def _on_client_state_changed(self,
|
|
| 220 | + _client: Client,
|
|
| 221 | + _signal_name: str,
|
|
| 222 | + state: SimpleClientState
|
|
| 223 | + ) -> None:
|
|
| 224 | + self._update_message_input_state()
|
|
| 225 | + |
|
| 226 | + def _on_muc_state_changed(self, *args: Any) -> None:
|
|
| 227 | + self._update_message_input_state()
|
|
| 228 | + |
|
| 229 | + def _on_user_state_changed(self, *args: Any) -> None:
|
|
| 230 | + self._update_message_input_state()
|
|
| 231 | + |
|
| 232 | + def _update_message_input_state(self) -> None:
|
|
| 233 | + assert self._client
|
|
| 234 | + state = self._client.state.is_connected
|
|
| 235 | + |
|
| 236 | + if isinstance(self._contact, GroupchatContact):
|
|
| 237 | + state = self._contact.is_joined
|
|
| 238 | + if self._contact.is_joined:
|
|
| 239 | + self_contact = self._contact.get_self()
|
|
| 240 | + assert self_contact
|
|
| 241 | + state = not self_contact.role.is_visitor
|
|
| 242 | + |
|
| 243 | + if isinstance(self._contact, GroupchatParticipant):
|
|
| 244 | + state = self._contact.is_available
|
|
| 245 | + |
|
| 246 | + self._ui.emoticons_button.set_sensitive(state)
|
|
| 247 | + self._ui.formattings_button.set_sensitive(state)
|
|
| 248 | + self.msg_textview.set_sensitive(state)
|
|
| 249 | + self.msg_textview.set_editable(state)
|
|
| 250 | + |
|
| 191 | 251 | def _set_chatstate(self) -> None:
|
| 192 | 252 | return #TODO
|
| 193 | 253 | if state:
|