1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# This file is part of Gajim.
#
# Gajim is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation; version 3 only.
#
# Gajim is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
from gi.repository import Gtk
from gajim.common import app
from gajim.common import types
from gajim.common.const import SimpleClientState
from gajim.common.i18n import _
from gajim.common.modules.contacts import GroupchatContact
from gajim.gtk.builder import get_builder
class GroupchatState(Gtk.Box):
def __init__(self) -> None:
Gtk.Box.__init__(self)
self.set_halign(Gtk.Align.CENTER)
self.set_valign(Gtk.Align.END)
self.set_no_show_all(True)
self._contact = None
self._client = None
self._ui = get_builder('groupchat_state.ui')
self._ui.connect_signals(self)
self.add(self._ui.groupchat_state)
self.show_all()
self.hide()
def clear(self) -> None:
if self._contact is not None:
self._contact.disconnect_all_from_obj(self)
if self._client is not None:
self._client.disconnect_all_from_obj(self)
self._contact = None
self._client = None
self.hide()
def switch_contact(self, contact: types.ChatContactT) -> None:
self.clear()
if not isinstance(contact, GroupchatContact):
return
self._contact = contact
self._contact.connect('state-changed', self._on_muc_state_changed)
self._contact.connect('mam-sync-started', self._on_mam_sync_changed)
self._contact.connect('mam-sync-finished', self._on_mam_sync_changed)
self._contact.connect('mam-sync-error', self._on_mam_sync_error)
self._client = app.get_client(contact.account)
self._client.connect_signal('state-changed',
self._on_client_state_changed)
self._update_state(contact)
def _on_client_state_changed(self,
client: types.Client,
_signal_name: str,
_state: SimpleClientState) -> None:
assert self._contact is not None
self._update_state(self._contact)
def _on_muc_state_changed(self,
contact: GroupchatContact,
_signal_name: str
) -> None:
self._update_state(contact)
def _update_state(self, contact: GroupchatContact) -> None:
if contact.is_joining:
self._ui.groupchat_state.set_visible_child_name('joining')
elif contact.is_not_joined:
self._ui.groupchat_state.set_visible_child_name('not-joined')
assert self._client is not None
self.set_visible(self._client.state.is_available and
not contact.is_joined)
def _on_mam_sync_changed(self,
_contact: GroupchatContact,
signal_name: str,
) -> None:
if signal_name == 'mam-sync-started':
self.set_visible(True)
self._ui.groupchat_state.set_visible_child_name(signal_name)
return
self.hide()
def _on_mam_sync_error(self,
_contact: GroupchatContact,
signal_name: str,
error_text: str
) -> None:
self.set_visible(True)
self._ui.groupchat_state.set_visible_child_name(signal_name)
self._ui.mam_error_label.set_text(
_('There has been an error while trying to '
'fetch messages: %s') % error_text)
def _on_close_clicked(self, _button: Gtk.Button) -> None:
self.hide()
def _on_join_clicked(self, _button: Gtk.Button) -> None:
assert self._contact is not None
client = app.get_client(self._contact.account)
client.get_module('MUC').join(self._contact.jid)
def _on_abort_clicked(self, _button: Gtk.Button) -> None:
assert self._contact is not None
client = app.get_client(self._contact.account)
client.get_module('MUC').abort_join(self._contact.jid)
|