Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_chat.py @ 414:72a6b06728ab
core: file dropping:
on compatible OSes, one or more file(s) can now be dropped on the main window, it will
then be transmitted to the selected widget if it has a "on_drop_file" method.
This is used in chat widget to add an attachment
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 23 Feb 2020 15:39:06 +0100 |
parents | c466678c57b2 |
children | 5b50b7ef2617 |
rev | line source |
---|---|
379 | 1 #!/usr/bin/env python3 |
22 | 2 |
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
378 | 4 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org) |
22 | 5 |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 | |
276 | 20 from functools import partial |
412 | 21 from pathlib import Path |
276 | 22 import sys |
412 | 23 import uuid |
78 | 24 from kivy.uix.boxlayout import BoxLayout |
22 | 25 from kivy.uix.textinput import TextInput |
354 | 26 from kivy.uix.screenmanager import Screen, NoTransition |
27 from kivy.uix import screenmanager | |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
28 from kivy.uix.behaviors import ButtonBehavior |
185
ab3f5173ef5c
chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
29 from kivy.metrics import sp, dp |
276 | 30 from kivy.clock import Clock |
22 | 31 from kivy import properties |
411
b018386653c2
chat: work around ScrollView bug in attachments by using a StackLayout instead:
Goffi <goffi@goffi.org>
parents:
409
diff
changeset
|
32 from kivy.uix.stacklayout import StackLayout |
325 | 33 from kivy.uix.dropdown import DropDown |
34 from kivy.core.window import Window | |
35 from sat.core import log as logging | |
36 from sat.core.i18n import _ | |
37 from sat.core import exceptions | |
333
69d2a96ce26f
chat: serialise `options` in `fileUpload` following change in backend
Goffi <goffi@goffi.org>
parents:
332
diff
changeset
|
38 from sat.tools.common import data_format |
22 | 39 from sat_frontends.quick_frontend import quick_widgets |
40 from sat_frontends.quick_frontend import quick_chat | |
106
9909ed7a7a20
moved SimpleXHTMLWidget to a dedicated module
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
41 from sat_frontends.tools import jid |
325 | 42 from cagou import G |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
43 from ..core.constants import Const as C |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
44 from ..core import cagou_widget |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
45 from ..core import xmlui |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
46 from ..core.image import Image |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
47 from ..core.common import SymbolButton, JidButton |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
48 from ..core.behaviors import FilterBehavior |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
49 from ..core import menu |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
50 from ..core.common import ContactButton |
22 | 51 |
276 | 52 log = logging.getLogger(__name__) |
22 | 53 |
54 PLUGIN_INFO = { | |
312 | 55 "name": _("chat"), |
22 | 56 "main": "Chat", |
312 | 57 "description": _("instant messaging with one person or a group"), |
58 "icon_symbol": "chat", | |
22 | 59 } |
60 | |
244
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
242
diff
changeset
|
61 # FIXME: OTR specific code is legacy, and only used nowadays for lock color |
5bd94bc08f5c
plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents:
242
diff
changeset
|
62 # we can probably get rid of them. |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
63 OTR_STATE_UNTRUSTED = 'untrusted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
64 OTR_STATE_TRUSTED = 'trusted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
65 OTR_STATE_TRUST = (OTR_STATE_UNTRUSTED, OTR_STATE_TRUSTED) |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
66 OTR_STATE_UNENCRYPTED = 'unencrypted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
67 OTR_STATE_ENCRYPTED = 'encrypted' |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
68 OTR_STATE_ENCRYPTION = (OTR_STATE_UNENCRYPTED, OTR_STATE_ENCRYPTED) |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
69 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
70 SYMBOL_UNENCRYPTED = 'lock-open' |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
71 SYMBOL_ENCRYPTED = 'lock' |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
72 SYMBOL_ENCRYPTED_TRUSTED = 'lock-filled' |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
73 COLOR_UNENCRYPTED = (0.4, 0.4, 0.4, 1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
74 COLOR_ENCRYPTED = (0.4, 0.4, 0.4, 1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
75 COLOR_ENCRYPTED_TRUSTED = (0.29,0.87,0.0,1) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
76 |
326 | 77 # below this limit, new messages will be prepended |
78 INFINITE_SCROLL_LIMIT = dp(600) | |
79 | |
412 | 80 # File sending progress |
81 PROGRESS_UPDATE = 0.2 # number of seconds before next progress update | |
82 | |
22 | 83 |
411
b018386653c2
chat: work around ScrollView bug in attachments by using a StackLayout instead:
Goffi <goffi@goffi.org>
parents:
409
diff
changeset
|
84 # FIXME: a ScrollLayout was supposed to be used here, but due |
b018386653c2
chat: work around ScrollView bug in attachments by using a StackLayout instead:
Goffi <goffi@goffi.org>
parents:
409
diff
changeset
|
85 # to https://github.com/kivy/kivy/issues/6745, a StackLayout is used for now |
b018386653c2
chat: work around ScrollView bug in attachments by using a StackLayout instead:
Goffi <goffi@goffi.org>
parents:
409
diff
changeset
|
86 class AttachmentsLayout(StackLayout): |
412 | 87 """Layout for attachments in a received message""" |
88 padding = properties.VariableListProperty([dp(5), dp(5), 0, dp(5)]) | |
89 attachments = properties.ObjectProperty() | |
90 | |
91 | |
92 class AttachmentsToSend(BoxLayout): | |
93 """Layout for attachments to be sent with current message""" | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
94 attachments = properties.ObjectProperty() |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
95 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
96 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
97 class AttachmentItem(BoxLayout): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
98 data = properties.DictProperty() |
412 | 99 progress = properties.NumericProperty(0) |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
100 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
101 def get_symbol(self, data): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
102 media_type = data.get('media_type', '') |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
103 main_type = media_type.split('/', 1)[0] |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
104 if main_type == 'image': |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
105 return "file-image" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
106 elif main_type == 'video': |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
107 return "file-video" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
108 elif main_type == 'audio': |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
109 return "file-audio" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
110 else: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
111 return "doc" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
112 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
113 def on_press(self): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
114 url = self.data.get('url') |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
115 if url: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
116 G.local_platform.open_url(url, self) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
117 else: |
412 | 118 log.warning(f"can't find URL in {self.data}") |
119 | |
120 | |
121 class AttachmentToSendItem(AttachmentItem): | |
122 # True when the item is being sent | |
123 sending = properties.BooleanProperty(False) | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
124 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
125 |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
126 class MessAvatar(ButtonBehavior, Image): |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
127 pass |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
128 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
129 |
325 | 130 class MessageWidget(quick_chat.MessageWidget, BoxLayout): |
22 | 131 mess_data = properties.ObjectProperty() |
57 | 132 mess_xhtml = properties.ObjectProperty() |
45 | 133 mess_padding = (dp(5), dp(5)) |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
134 avatar = properties.ObjectProperty() |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
135 delivery = properties.ObjectProperty() |
185
ab3f5173ef5c
chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents:
184
diff
changeset
|
136 font_size = properties.NumericProperty(sp(12)) |
325 | 137 right_part = properties.ObjectProperty() |
138 header_box = properties.ObjectProperty() | |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
139 |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
140 def on_kv_post(self, __): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
141 if not self.mess_data: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
142 raise exceptions.InternalError( |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
143 "mess_data must always be set in MessageWidget") |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
144 |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
145 self.mess_data.widgets.add(self) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
146 self.add_attachments() |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
147 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
148 @property |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
149 def chat(self): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
150 """return parent Chat instance""" |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
151 return self.mess_data.parent |
22 | 152 |
325 | 153 def _get_from_mess_data(self, name, default): |
154 if self.mess_data is None: | |
155 return default | |
156 return getattr(self.mess_data, name) | |
157 | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
158 def _get_message(self): |
22 | 159 """Return currently displayed message""" |
325 | 160 if self.mess_data is None: |
161 return "" | |
22 | 162 return self.mess_data.main_message |
163 | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
164 def _set_message(self, message): |
325 | 165 if self.mess_data is None: |
166 return False | |
312 | 167 if message == self.mess_data.message.get(""): |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
168 return False |
312 | 169 self.mess_data.message = {"": message} |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
170 return True |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
171 |
325 | 172 message = properties.AliasProperty( |
173 partial(_get_from_mess_data, name="main_message", default=""), | |
174 _set_message, | |
175 bind=['mess_data'], | |
176 ) | |
177 message_xhtml = properties.AliasProperty( | |
178 partial(_get_from_mess_data, name="main_message_xhtml", default=""), | |
179 bind=['mess_data']) | |
180 mess_type = properties.AliasProperty( | |
181 partial(_get_from_mess_data, name="type", default=""), bind=['mess_data']) | |
182 own_mess = properties.AliasProperty( | |
183 partial(_get_from_mess_data, name="own_mess", default=False), bind=['mess_data']) | |
184 nick = properties.AliasProperty( | |
185 partial(_get_from_mess_data, name="nick", default=""), bind=['mess_data']) | |
186 time_text = properties.AliasProperty( | |
187 partial(_get_from_mess_data, name="time_text", default=""), bind=['mess_data']) | |
57 | 188 |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
189 @property |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
190 def info_type(self): |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
191 return self.mess_data.info_type |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
192 |
54
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
193 def update(self, update_dict): |
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
194 if 'avatar' in update_dict: |
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
195 self.avatar.source = update_dict['avatar'] |
103
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
196 if 'status' in update_dict: |
c601e3d40342
chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents:
102
diff
changeset
|
197 status = update_dict['status'] |
312 | 198 self.delivery.text = '\u2714' if status == 'delivered' else '' |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
199 |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
200 def add_attachments(self): |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
201 """Add attachments layout + attachments item""" |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
202 attachments = self.mess_data.attachments |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
203 if not attachments: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
204 return |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
205 root_layout = AttachmentsLayout() |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
206 self.right_part.add_widget(root_layout) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
207 layout = root_layout.attachments |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
208 for attachment in attachments: |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
209 item = AttachmentItem(data=attachment) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
210 layout.add_widget(item) |
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
211 |
22 | 212 |
78 | 213 class MessageInputBox(BoxLayout): |
276 | 214 message_input = properties.ObjectProperty() |
215 | |
216 def send_text(self): | |
217 self.message_input.send_text() | |
78 | 218 |
219 | |
22 | 220 class MessageInputWidget(TextInput): |
221 | |
276 | 222 def keyboard_on_key_down(self, window, keycode, text, modifiers): |
223 # We don't send text when shift is pressed to be able to add line feeds | |
224 # (i.e. multi-lines messages). We don't send on Android either as the | |
225 # send button appears on this platform. | |
226 if (keycode[-1] == "enter" | |
227 and "shift" not in modifiers | |
228 and sys.platform != 'android'): | |
229 self.send_text() | |
22 | 230 else: |
276 | 231 return super(MessageInputWidget, self).keyboard_on_key_down( |
232 window, keycode, text, modifiers) | |
233 | |
234 def send_text(self): | |
235 self.dispatch('on_text_validate') | |
22 | 236 |
237 | |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
238 class TransferButton(SymbolButton): |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
239 chat = properties.ObjectProperty() |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
240 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
241 def on_release(self, *args): |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
242 menu.TransferMenu(callback=self.chat.transferFile).show(self) |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
243 |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
244 |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
245 class ExtraMenu(DropDown): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
246 chat = properties.ObjectProperty() |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
247 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
248 def on_select(self, menu): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
249 if menu == 'bookmark': |
312 | 250 G.host.bridge.menuLaunch(C.MENU_GLOBAL, ("groups", "bookmarks"), |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
251 {}, C.NO_SECURITY_LIMIT, self.chat.profile, |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
252 callback=partial( |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
253 G.host.actionManager, profile=self.chat.profile), |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
254 errback=G.host.errback) |
393
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
255 elif menu == 'close': |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
256 if self.chat.type == C.CHAT_GROUP: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
257 # for MUC, we have to indicate the backend that we've left |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
258 G.host.bridge.mucLeave(self.chat.target, self.chat.profile) |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
259 else: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
260 # for one2one, backend doesn't keep any state, so we just delete the |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
261 # widget here in the frontend |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
262 G.host.widgets.deleteWidget( |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
263 self.chat, all_instances=True, explicit_close=True) |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
264 else: |
312 | 265 raise exceptions.InternalError("Unknown menu: {}".format(menu)) |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
266 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
267 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
268 class ExtraButton(SymbolButton): |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
269 chat = properties.ObjectProperty() |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
270 |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
271 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
272 class EncryptionMainButton(SymbolButton): |
117 | 273 |
274 def __init__(self, chat, **kwargs): | |
275 """ | |
276 @param chat(Chat): Chat instance | |
277 """ | |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
278 self.chat = chat |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
279 self.encryption_menu = EncryptionMenu(chat) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
280 super(EncryptionMainButton, self).__init__(**kwargs) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
281 self.bind(on_release=self.encryption_menu.open) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
282 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
283 def selectAlgo(self, name): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
284 """Mark an encryption algorithm as selected. |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
285 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
286 This will also deselect all other button |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
287 @param name(unicode, None): encryption plugin name |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
288 None for plain text |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
289 """ |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
290 buttons = self.encryption_menu.container.children |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
291 buttons[-1].selected = name is None |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
292 for button in buttons[:-1]: |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
293 button.selected = button.text == name |
117 | 294 |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
295 def getColor(self): |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
296 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
297 return (0.4, 0.4, 0.4, 1) |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
298 elif self.chat.otr_state_trust == OTR_STATE_TRUSTED: |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
299 return (0.29,0.87,0.0,1) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
300 else: |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
301 return (0.4, 0.4, 0.4, 1) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
302 |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
303 def getSymbol(self): |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
304 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
305 return 'lock-open' |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
306 elif self.chat.otr_state_trust == OTR_STATE_TRUSTED: |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
307 return 'lock-filled' |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
308 else: |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
309 return 'lock' |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
310 |
117 | 311 |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
312 class TrustManagementButton(SymbolButton): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
313 pass |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
314 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
315 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
316 class EncryptionButton(BoxLayout): |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
317 selected = properties.BooleanProperty(False) |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
318 text = properties.StringProperty() |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
319 trust_button = properties.BooleanProperty(False) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
320 best_width = properties.NumericProperty(0) |
312 | 321 bold = properties.BooleanProperty(True) |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
322 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
323 def __init__(self, **kwargs): |
312 | 324 super(EncryptionButton, self).__init__(**kwargs) |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
325 self.register_event_type('on_release') |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
326 self.register_event_type('on_trust_release') |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
327 if self.trust_button: |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
328 self.add_widget(TrustManagementButton()) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
329 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
330 def on_release(self): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
331 pass |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
332 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
333 def on_trust_release(self): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
334 pass |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
335 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
336 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
337 class EncryptionMenu(DropDown): |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
338 # best with to display all algorithms buttons + trust buttons |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
339 best_width = properties.NumericProperty(0) |
117 | 340 |
341 def __init__(self, chat, **kwargs): | |
342 """ | |
343 @param chat(Chat): Chat instance | |
344 """ | |
345 self.chat = chat | |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
346 super(EncryptionMenu, self).__init__(**kwargs) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
347 btn = EncryptionButton( |
312 | 348 text=_("unencrypted (plain text)"), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
349 on_release=self.unencrypted, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
350 selected=True, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
351 bold=False, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
352 ) |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
353 btn.bind( |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
354 on_release=self.unencrypted, |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
355 ) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
356 self.add_widget(btn) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
357 for plugin in G.host.encryption_plugins: |
339
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
358 if chat.type == C.CHAT_GROUP and plugin["directed"]: |
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
359 # directed plugins can't work with group chat |
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
360 continue |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
361 btn = EncryptionButton( |
312 | 362 text=plugin['name'], |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
363 trust_button=True, |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
364 ) |
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
365 btn.bind( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
366 on_release=partial(self.startEncryption, plugin=plugin), |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
367 on_trust_release=partial(self.getTrustUI, plugin=plugin), |
332
13bc00b9743a
chat: use `bind` for EncryptionButton events:
Goffi <goffi@goffi.org>
parents:
329
diff
changeset
|
368 ) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
369 self.add_widget(btn) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
370 log.info("added encryption: {}".format(plugin['name'])) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
371 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
372 def messageEncryptionStopCb(self): |
312 | 373 log.info(_("Session with {destinee} is now in plain text").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
374 destinee = self.chat.target)) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
375 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
376 def messageEncryptionStopEb(self, failure_): |
312 | 377 msg = _("Error while stopping encryption with {destinee}: {reason}").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
378 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
379 reason = failure_) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
380 log.warning(msg) |
312 | 381 G.host.addNote(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
382 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
383 def unencrypted(self, button): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
384 self.dismiss() |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
385 G.host.bridge.messageEncryptionStop( |
312 | 386 str(self.chat.target), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
387 self.chat.profile, |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
388 callback=self.messageEncryptionStopCb, |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
389 errback=self.messageEncryptionStopEb) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
390 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
391 def messageEncryptionStartCb(self, plugin): |
312 | 392 log.info(_("Session with {destinee} is now encrypted with {encr_name}").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
393 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
394 encr_name = plugin['name'])) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
395 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
396 def messageEncryptionStartEb(self, failure_): |
312 | 397 msg = _("Session can't be encrypted with {destinee}: {reason}").format( |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
398 destinee = self.chat.target, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
399 reason = failure_) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
400 log.warning(msg) |
312 | 401 G.host.addNote(_("encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
402 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
403 def startEncryption(self, button, plugin): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
404 """Request encryption with given plugin for this session |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
405 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
406 @param button(EncryptionButton): button which has been pressed |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
407 @param plugin(dict): plugin data |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
408 """ |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
409 self.dismiss() |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
410 G.host.bridge.messageEncryptionStart( |
312 | 411 str(self.chat.target), |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
412 plugin['namespace'], |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
413 True, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
414 self.chat.profile, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
415 callback=partial(self.messageEncryptionStartCb, plugin=plugin), |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
416 errback=self.messageEncryptionStartEb) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
417 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
418 def encryptionTrustUIGetCb(self, xmlui_raw): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
419 xml_ui = xmlui.create( |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
420 G.host, xmlui_raw, profile=self.chat.profile) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
421 xml_ui.show() |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
422 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
423 def encryptionTrustUIGetEb(self, failure_): |
312 | 424 msg = _("Trust manager interface can't be retrieved: {reason}").format( |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
425 reason = failure_) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
426 log.warning(msg) |
312 | 427 G.host.addNote(_("encryption trust management problem"), msg, |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
428 C.XMLUI_DATA_LVL_ERROR) |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
429 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
430 def getTrustUI(self, button, plugin): |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
431 """Request and display trust management UI |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
432 |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
433 @param button(EncryptionButton): button which has been pressed |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
434 @param plugin(dict): plugin data |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
435 """ |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
436 self.dismiss() |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
437 G.host.bridge.encryptionTrustUIGet( |
312 | 438 str(self.chat.target), |
242
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
439 plugin['namespace'], |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
440 self.chat.profile, |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
441 callback=self.encryptionTrustUIGetCb, |
c2503168fab7
plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents:
233
diff
changeset
|
442 errback=self.encryptionTrustUIGetEb) |
117 | 443 |
444 | |
22 | 445 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): |
78 | 446 message_input = properties.ObjectProperty() |
86 | 447 messages_widget = properties.ObjectProperty() |
326 | 448 history_scroll = properties.ObjectProperty() |
412 | 449 attachments_to_send = properties.ObjectProperty() |
413
c466678c57b2
chat: control send button visibility in core.platform_, and show it when there are attachments
Goffi <goffi@goffi.org>
parents:
412
diff
changeset
|
450 send_button_visible = properties.BooleanProperty() |
387
d61bbbac4160
cagou widget: don't add header_input systematically anymore:
Goffi <goffi@goffi.org>
parents:
379
diff
changeset
|
451 use_header_input = True |
354 | 452 global_screen_manager = True |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
453 collection_carousel = True |
22 | 454 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
455 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, |
338
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
456 subject=None, statuses=None, profiles=None): |
354 | 457 self.show_chat_selector = False |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
458 if statuses is None: |
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
459 statuses = {} |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
460 quick_chat.QuickChat.__init__( |
338
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
461 self, host, target, type_, nick, occupants, subject, statuses, |
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
462 profiles=profiles) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
463 self.otr_state_encryption = OTR_STATE_UNENCRYPTED |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
464 self.otr_state_trust = OTR_STATE_UNTRUSTED |
225
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
465 # completion attributes |
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
466 self._hi_comp_data = None |
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
467 self._hi_comp_last = None |
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
468 self._hi_comp_dropdown = DropDown() |
a3162b29cda1
plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents:
193
diff
changeset
|
469 self._hi_comp_allowed = True |
22 | 470 cagou_widget.CagouWidget.__init__(self) |
278
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
471 transfer_btn = TransferButton(chat=self) |
444ba439530f
chat: moved transfer button to header_box
Goffi <goffi@goffi.org>
parents:
277
diff
changeset
|
472 self.headerInputAddExtra(transfer_btn) |
339
63cdabdd032e
chat: show encryption button with group chats:
Goffi <goffi@goffi.org>
parents:
338
diff
changeset
|
473 if (type_ == C.CHAT_ONE2ONE or "REALJID_PUBLIC" in statuses): |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
474 self.encryption_btn = EncryptionMainButton(self) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
475 self.headerInputAddExtra(self.encryption_btn) |
287
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
476 self.extra_menu = ExtraMenu(chat=self) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
477 extra_btn = ExtraButton(chat=self) |
5d96bcd3bfec
chat: added an extra menu (3 dots menu):
Goffi <goffi@goffi.org>
parents:
284
diff
changeset
|
478 self.headerInputAddExtra(extra_btn) |
325 | 479 self.header_input.hint_text = target |
326 | 480 self._history_prepend_lock = False |
481 self.history_count = 0 | |
22 | 482 |
353
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
483 def on_kv_post(self, __): |
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
484 self.postInit() |
19422bbd9c8e
core (widgets handler): refactoring:
Goffi <goffi@goffi.org>
parents:
340
diff
changeset
|
485 |
354 | 486 def screenManagerInit(self, screen_manager): |
487 screen_manager.transition = screenmanager.SlideTransition(direction='down') | |
488 sel_screen = Screen(name='chat_selector') | |
489 chat_selector = ChatSelector(profile=self.profile) | |
490 sel_screen.add_widget(chat_selector) | |
491 screen_manager.add_widget(sel_screen) | |
492 if self.show_chat_selector: | |
493 transition = screen_manager.transition | |
494 screen_manager.transition = NoTransition() | |
495 screen_manager.current = 'chat_selector' | |
496 screen_manager.transition = transition | |
497 | |
156
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
498 def __str__(self): |
312 | 499 return "Chat({})".format(self.target) |
156
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
500 |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
501 def __repr__(self): |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
502 return self.__str__() |
826e7b17a19b
chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents:
145
diff
changeset
|
503 |
22 | 504 @classmethod |
505 def factory(cls, plugin_info, target, profiles): | |
506 profiles = list(profiles) | |
507 if len(profiles) > 1: | |
312 | 508 raise NotImplementedError("Multi-profiles is not available yet for chat") |
22 | 509 if target is None: |
354 | 510 show_chat_selector = True |
22 | 511 target = G.host.profiles[profiles[0]].whoami |
354 | 512 else: |
513 show_chat_selector = False | |
514 wid = G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, | |
515 on_existing_widget=G.host.getOrClone, | |
516 profiles=profiles) | |
517 wid.show_chat_selector = show_chat_selector | |
518 return wid | |
22 | 519 |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
520 @property |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
521 def message_widgets_rev(self): |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
522 return self.messages_widget.children |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
523 |
354 | 524 ## keyboard ## |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
525 |
354 | 526 def key_input(self, window, key, scancode, codepoint, modifier): |
527 if key == 27: | |
528 screen_manager = self.screen_manager | |
529 screen_manager.transition.direction = 'down' | |
530 screen_manager.current = 'chat_selector' | |
531 return True | |
532 | |
414 | 533 ## drop ## |
534 | |
535 def on_drop_file(self, path): | |
536 self.addAttachment(path) | |
354 | 537 |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
538 ## header ## |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
539 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
540 def changeWidget(self, jid_): |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
541 """change current widget for a new one with given jid |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
542 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
543 @param jid_(jid.JID): jid of the widget to create |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
544 """ |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
545 plugin_info = G.host.getPluginInfo(main=Chat) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
546 factory = plugin_info['factory'] |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
547 G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile])) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
548 self.header_input.text = '' |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
549 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
550 def onHeaderInput(self): |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
551 text = self.header_input.text.strip() |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
552 try: |
312 | 553 if text.count('@') != 1 or text.count(' '): |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
554 raise ValueError |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
555 jid_ = jid.JID(text) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
556 except ValueError: |
312 | 557 log.info("entered text is not a jid") |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
558 return |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
559 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
560 def discoCb(disco): |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
561 # TODO: check if plugin XEP-0045 is activated |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
562 if "conference" in [i[0] for i in disco[1]]: |
312 | 563 G.host.bridge.mucJoin(str(jid_), "", "", self.profile, |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
564 callback=self._mucJoinCb, errback=self._mucJoinEb) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
565 else: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
566 self.changeWidget(jid_) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
567 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
568 def discoEb(failure): |
312 | 569 log.warning("Disco failure, ignore this text: {}".format(failure)) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
570 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
571 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
572 errback=discoEb) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
573 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
574 def onHeaderInputCompleted(self, input_wid, completed_text): |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
575 self._hi_comp_allowed = False |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
576 input_wid.text = completed_text |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
577 self._hi_comp_allowed = True |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
578 self._hi_comp_dropdown.dismiss() |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
579 self.onHeaderInput() |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
580 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
581 def onHeaderInputComplete(self, wid, text): |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
582 if not self._hi_comp_allowed: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
583 return |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
584 text = text.lstrip() |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
585 if not text: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
586 self._hi_comp_data = None |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
587 self._hi_comp_last = None |
144 | 588 self._hi_comp_dropdown.dismiss() |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
589 return |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
590 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
591 profile = list(self.profiles)[0] |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
592 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
593 if self._hi_comp_data is None: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
594 # first completion, we build the initial list |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
595 comp_data = self._hi_comp_data = [] |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
596 self._hi_comp_last = '' |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
597 for jid_, jid_data in G.host.contact_lists[profile].all_iter: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
598 comp_data.append((jid_, jid_data)) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
599 comp_data.sort(key=lambda datum: datum[0]) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
600 else: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
601 comp_data = self._hi_comp_data |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
602 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
603 # XXX: dropdown is rebuilt each time backspace is pressed or if the text is changed, |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
604 # it works OK, but some optimisation may be done here |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
605 dropdown = self._hi_comp_dropdown |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
606 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
607 if not text.startswith(self._hi_comp_last) or not self._hi_comp_last: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
608 # text has changed or backspace has been pressed, we restart |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
609 dropdown.clear_widgets() |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
610 |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
611 for jid_, jid_data in comp_data: |
312 | 612 nick = jid_data.get('nick', '') |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
613 if text in jid_.bare or text in nick.lower(): |
193
284cb5c467b0
core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents:
186
diff
changeset
|
614 btn = JidButton( |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
615 jid = jid_.bare, |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
616 profile = profile, |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
617 size_hint = (0.5, None), |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
618 nick = nick, |
284 | 619 on_release=lambda __, txt=jid_.bare: self.onHeaderInputCompleted(wid, txt) |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
620 ) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
621 dropdown.add_widget(btn) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
622 else: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
623 # more chars, we continue completion by removing unwanted widgets |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
624 to_remove = [] |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
625 for c in dropdown.children[0].children: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
626 if text not in c.jid and text not in (c.nick or ''): |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
627 to_remove.append(c) |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
628 for c in to_remove: |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
629 dropdown.remove_widget(c) |
144 | 630 if dropdown.attach_to is None: |
631 dropdown.open(wid) | |
109
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
632 self._hi_comp_last = text |
7631325e11f4
chat: added completion of header's input, any entity in cache containing the entered text is shown
Goffi <goffi@goffi.org>
parents:
106
diff
changeset
|
633 |
22 | 634 def messageDataConverter(self, idx, mess_id): |
635 return {"mess_data": self.messages[mess_id]} | |
636 | |
637 def _onHistoryPrinted(self): | |
638 """Refresh or scroll down the focus after the history is printed""" | |
639 # self.adapter.data = self.messages | |
312 | 640 for mess_data in self.messages.values(): |
22 | 641 self.appendMessage(mess_data) |
642 super(Chat, self)._onHistoryPrinted() | |
643 | |
644 def createMessage(self, message): | |
645 self.appendMessage(message) | |
329
51520ce98154
common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
646 # we need to render immediatly next 2 layouts to avoid an unpleasant flickering |
51520ce98154
common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
647 # when sending or receiving a message |
51520ce98154
common_widgets (DelayedBoxLayout), chat: don't delay layout on new message:
Goffi <goffi@goffi.org>
parents:
326
diff
changeset
|
648 self.messages_widget.dont_delay_next_layouts = 2 |
22 | 649 |
650 def appendMessage(self, mess_data): | |
289
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
651 """Append a message Widget to the history |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
652 |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
653 @param mess_data(quick_chat.Message): message data |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
654 """ |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
655 if self.handleUserMoved(mess_data): |
717c6c368f70
chat: merge user moved info messages:
Goffi <goffi@goffi.org>
parents:
287
diff
changeset
|
656 return |
22 | 657 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
658 self.notify(mess_data) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
659 |
326 | 660 def prependMessage(self, mess_data): |
661 """Prepend a message Widget to the history | |
662 | |
663 @param mess_data(quick_chat.Message): message data | |
664 """ | |
665 mess_wid = self.messages_widget | |
666 last_idx = len(mess_wid.children) | |
667 mess_wid.add_widget(MessageWidget(mess_data=mess_data), index=last_idx) | |
668 | |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
669 def _get_notif_msg(self, mess_data): |
312 | 670 return _("{nick}: {message}").format( |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
671 nick=mess_data.nick, |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
672 message=mess_data.main_message) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
673 |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
674 def notify(self, mess_data): |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
675 """Notify user when suitable |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
676 |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
677 For one2one chat, notification will happen when window has not focus |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
678 or when one2one chat is not visible. A note is also there when widget |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
679 is not visible. |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
680 For group chat, note will be added on mention, with a desktop notification if |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
681 window has not focus or is not visible. |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
682 """ |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
683 visible_clones = [w for w in G.host.getVisibleList(self.__class__) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
684 if w.target == self.target] |
186
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
685 if len(visible_clones) > 1 and visible_clones.index(self) > 0: |
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
686 # to avoid multiple notifications in case of multiple cloned widgets |
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
687 # we only handle first clone |
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
688 return |
a826c70beda2
chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents:
185
diff
changeset
|
689 is_visible = bool(visible_clones) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
690 if self.type == C.CHAT_ONE2ONE: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
691 if (not Window.focus or not is_visible) and not mess_data.history: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
692 notif_msg = self._get_notif_msg(mess_data) |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
693 G.host.notify( |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
694 type_=C.NOTIFY_MESSAGE, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
695 entity=mess_data.from_jid, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
696 message=notif_msg, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
697 subject=_("private message"), |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
698 widget=self, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
699 profile=self.profile |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
700 ) |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
701 if not is_visible: |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
702 G.host.addNote( |
312 | 703 _("private message"), |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
704 notif_msg, |
312 | 705 symbol = "chat", |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
706 action = { |
312 | 707 "action": 'chat', |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
708 "target": self.target, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
709 "profiles": self.profiles} |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
710 ) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
711 else: |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
712 if mess_data.mention: |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
713 notif_msg = self._get_notif_msg(mess_data) |
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
714 G.host.addNote( |
312 | 715 _("mention"), |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
716 notif_msg, |
312 | 717 symbol = "chat", |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
718 action = { |
312 | 719 "action": 'chat', |
250
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
720 "target": self.target, |
ff1efdeff53f
core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents:
244
diff
changeset
|
721 "profiles": self.profiles} |
184
c63922860f80
chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
722 ) |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
723 if not is_visible or not Window.focus: |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
724 subject=_("mention ({room_jid})").format(room_jid=self.target) |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
725 G.host.notify( |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
726 type_=C.NOTIFY_MENTION, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
727 entity=self.target, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
728 message=notif_msg, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
729 subject=subject, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
730 widget=self, |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
731 profile=self.profile |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
732 ) |
22 | 733 |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
734 # message input |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
735 |
412 | 736 def _attachmentProgressCb(self, item, metadata, profile): |
737 item.parent.remove_widget(item) | |
738 log.info(f"item {item.data.get('path')} uploaded successfully") | |
739 | |
740 def _attachmentProgressEb(self, item, err_msg, profile): | |
741 item.parent.remove_widget(item) | |
742 path = item.data.get('path') | |
743 msg = _("item {path} could not be uploaded: {err_msg}").format( | |
744 path=path, err_msg=err_msg) | |
745 G.host.addNote(_("can't upload file"), msg, C.XMLUI_DATA_LVL_WARNING) | |
746 log.warning(msg) | |
747 | |
748 def _progressGetCb(self, item, metadata): | |
749 try: | |
750 position = int(metadata["position"]) | |
751 size = int(metadata["size"]) | |
752 except KeyError: | |
753 # we got empty metadata, the progression is either not yet started or | |
754 # finished | |
755 if item.progress: | |
756 # if progress is already started, receiving empty metadata means | |
757 # that progression is finished | |
758 item.progress = 100 | |
759 return | |
760 else: | |
761 item.progress = position/size*100 | |
762 | |
763 if item.parent is not None: | |
764 # the item is not yet fully received, we reschedule an update | |
765 Clock.schedule_once( | |
766 partial(self._attachmentProgressUpdate, item), | |
767 PROGRESS_UPDATE) | |
768 | |
769 def _attachmentProgressUpdate(self, item, __): | |
770 G.host.bridge.progressGet( | |
771 item.data["progress_id"], | |
772 self.profile, | |
773 callback=partial(self._progressGetCb, item), | |
774 errback=G.host.errback, | |
775 ) | |
776 | |
367
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
777 def addNick(self, nick): |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
778 """Add a nickname to message_input if suitable""" |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
779 if (self.type == C.CHAT_GROUP and not self.message_input.text.startswith(nick)): |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
780 self.message_input.text = f'{nick}: {self.message_input.text}' |
abb57182ebfb
chat: prepend nick to message input when occupant avatar is touched on group chat.
Goffi <goffi@goffi.org>
parents:
357
diff
changeset
|
781 |
22 | 782 def onSend(self, input_widget): |
412 | 783 extra = {} |
784 for item in self.attachments_to_send.attachments.children: | |
785 if item.sending: | |
786 # the item is already being sent | |
787 continue | |
788 item.sending = True | |
789 progress_id = item.data["progress_id"] = str(uuid.uuid4()) | |
790 attachments = extra.setdefault(C.MESS_KEY_ATTACHMENTS, []) | |
791 attachment = { | |
792 "path": str(item.data["path"]), | |
793 "progress_id": progress_id, | |
794 } | |
795 attachments.append(attachment) | |
796 | |
797 Clock.schedule_once( | |
798 partial(self._attachmentProgressUpdate, item), | |
799 PROGRESS_UPDATE) | |
800 | |
801 G.host.registerProgressCbs( | |
802 progress_id, | |
803 callback=partial(self._attachmentProgressCb, item), | |
804 errback=partial(self._attachmentProgressEb, item) | |
805 ) | |
806 | |
807 | |
22 | 808 G.host.messageSend( |
809 self.target, | |
412 | 810 # TODO: handle language |
811 {'': input_widget.text}, | |
812 # TODO: put this in QuickChat | |
813 mess_type= | |
814 C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, | |
815 extra=extra, | |
22 | 816 profile_key=self.profile |
817 ) | |
818 input_widget.text = '' | |
819 | |
412 | 820 def addAttachment(self, file_path): |
821 file_path = Path(file_path) | |
822 data = { | |
823 "path": file_path, | |
824 "name": file_path.name, | |
825 } | |
826 self.attachments_to_send.attachments.add_widget( | |
827 AttachmentToSendItem(data=data) | |
828 ) | |
283
c73a7cd36b54
chat: show warning note on failing fileUpload + added forgotten "profile" argument
Goffi <goffi@goffi.org>
parents:
282
diff
changeset
|
829 |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
830 def transferFile(self, file_path, transfer_type=C.TRANSFER_UPLOAD, cleaning_cb=None): |
412 | 831 # FIXME: cleaning_cb is not managed |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
832 if transfer_type == C.TRANSFER_UPLOAD: |
412 | 833 self.addAttachment(file_path) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
834 elif transfer_type == C.TRANSFER_SEND: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
835 if self.type == C.CHAT_GROUP: |
312 | 836 log.warning("P2P transfer is not possible for group chat") |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
837 # TODO: show an error dialog to user, or better hide the send button for |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
838 # MUC |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
839 else: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
840 jid_ = self.target |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
841 if not jid_.resource: |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
842 jid_ = G.host.contact_lists[self.profile].getFullJid(jid_) |
322
e2b51663d8b8
core, android: new share widget + added Cagou to "share" menu:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
843 G.host.bridge.fileSend(str(jid_), str(file_path), "", "", {}, |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
844 profile=self.profile) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
845 # TODO: notification of sending/failing |
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
846 else: |
312 | 847 raise log.error("transfer of type {} are not handled".format(transfer_type)) |
98
4d8c122b86a6
menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents:
97
diff
changeset
|
848 |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
849 def messageEncryptionStarted(self, plugin_data): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
850 quick_chat.QuickChat.messageEncryptionStarted(self, plugin_data) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
851 self.encryption_btn.symbol = SYMBOL_ENCRYPTED |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
852 self.encryption_btn.color = COLOR_ENCRYPTED |
312 | 853 self.encryption_btn.selectAlgo(plugin_data['name']) |
233
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
854 |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
855 def messageEncryptionStopped(self, plugin_data): |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
856 quick_chat.QuickChat.messageEncryptionStopped(self, plugin_data) |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
857 self.encryption_btn.symbol = SYMBOL_UNENCRYPTED |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
858 self.encryption_btn.color = COLOR_UNENCRYPTED |
ba8f3a4a5ac7
plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents:
225
diff
changeset
|
859 self.encryption_btn.selectAlgo(None) |
78 | 860 |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
861 def _mucJoinCb(self, joined_data): |
338
d4883f9576db
chat: handle room statuses following backend change
Goffi <goffi@goffi.org>
parents:
334
diff
changeset
|
862 joined, room_jid_s, occupants, user_nick, subject, statuses, profile = joined_data |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
863 self.host.mucRoomJoinedHandler(*joined_data[1:]) |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
864 jid_ = jid.JID(room_jid_s) |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
865 self.changeWidget(jid_) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
866 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
867 def _mucJoinEb(self, failure): |
312 | 868 log.warning("Can't join room: {}".format(failure)) |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
869 |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
870 def onOTRState(self, state, dest_jid, profile): |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
871 assert profile in self.profiles |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
872 if state in OTR_STATE_ENCRYPTION: |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
873 self.otr_state_encryption = state |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
874 elif state in OTR_STATE_TRUST: |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
875 self.otr_state_trust = state |
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
876 else: |
312 | 877 log.error(_("Unknown OTR state received: {}".format(state))) |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
878 return |
135
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
879 self.encryption_btn.symbol = self.encryption_btn.getSymbol() |
091e288838e1
plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
880 self.encryption_btn.color = self.encryption_btn.getColor() |
122
dcd6fbb3f010
chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents:
121
diff
changeset
|
881 |
265
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
882 def onVisible(self): |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
883 if not self.sync: |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
884 self.resync() |
805c4103dac5
core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents:
261
diff
changeset
|
885 |
396
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
886 def onSelected(self): |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
887 G.host.clearNotifs(self.target, profile=self.profile) |
ae6f7fd1cb0e
chat: use QuickApp.notify and clear notifications when selected.
Goffi <goffi@goffi.org>
parents:
395
diff
changeset
|
888 |
356
307c2501d8b2
chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one:
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
889 def onDelete(self, **kwargs): |
393
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
890 if kwargs.get('explicit_close', False): |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
891 wrapper = self.whwrapper |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
892 if wrapper is not None: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
893 if len(wrapper.carousel.slides) == 1: |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
894 # if we delete the last opened chat, we need to show the selector |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
895 screen_manager = self.screen_manager |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
896 screen_manager.transition.direction = 'down' |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
897 screen_manager.current = 'chat_selector' |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
898 wrapper.carousel.remove_widget(self) |
e2f806779b53
chat: added a "close" item in menu, to leave MUC/close current chat widget.
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
899 return True |
261
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
900 # we always keep one widget, so it's available when swiping |
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
901 # TODO: delete all widgets when chat is closed |
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
902 nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self)) |
356
307c2501d8b2
chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one:
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
903 # we want to keep at least one instance of Chat by WHWrapper |
307c2501d8b2
chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one:
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
904 nb_to_keep = len(G.host.widgets_handler.children) |
307c2501d8b2
chat: keep as many instances of opened chat as there are active WHWrapper, instead of just one:
Goffi <goffi@goffi.org>
parents:
354
diff
changeset
|
905 if nb_instances <= nb_to_keep: |
261
a579eda31f4f
chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents:
260
diff
changeset
|
906 return False |
22 | 907 |
326 | 908 def _history_unlock(self, __): |
909 self._history_prepend_lock = False | |
910 log.debug("history prepend unlocked") | |
911 # we call manually onScroll, to check if we are still in the scrolling zone | |
912 self.onScroll(self.history_scroll, self.history_scroll.scroll_y) | |
913 | |
914 def _history_scroll_adjust(self, __, scroll_start_height): | |
915 # history scroll position must correspond to where it was before new messages | |
916 # have been appended | |
917 self.history_scroll.scroll_y = ( | |
918 scroll_start_height / self.messages_widget.height | |
919 ) | |
920 | |
921 # we want a small delay before unlocking, to avoid re-fetching history | |
922 # again | |
923 Clock.schedule_once(self._history_unlock, 1.5) | |
924 | |
925 def _backHistoryGetCb_post(self, __, history, scroll_start_height): | |
926 if len(history) == 0: | |
927 # we don't unlock self._history_prepend_lock if there is no history, as there | |
928 # is no sense to try to retrieve more in this case. | |
929 log.debug(f"we've reached top of history for {self.target.bare} chat") | |
930 else: | |
931 # we have to schedule again for _history_scroll_adjust, else messages_widget | |
932 # is not resized (self.messages_widget.height is not yet updated) | |
933 # as a result, the scroll_to can't work correctly | |
934 Clock.schedule_once(partial( | |
935 self._history_scroll_adjust, | |
936 scroll_start_height=scroll_start_height)) | |
937 log.debug( | |
938 f"{len(history)} messages prepended to history (last: {history[0][0]})") | |
939 | |
940 def _backHistoryGetCb(self, history): | |
941 # TODO: factorise with QuickChat._historyGetCb | |
942 scroll_start_height = self.messages_widget.height * self.history_scroll.scroll_y | |
943 for data in reversed(history): | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
944 uid, timestamp, from_jid, to_jid, message, subject, type_, extra_s = data |
326 | 945 from_jid = jid.JID(from_jid) |
946 to_jid = jid.JID(to_jid) | |
409
2caea63ae2ab
chat: show attachments as clickable icons
Goffi <goffi@goffi.org>
parents:
406
diff
changeset
|
947 extra = data_format.deserialise(extra_s) |
326 | 948 extra["history"] = True |
949 self.messages[uid] = message = quick_chat.Message( | |
950 self, | |
951 uid, | |
952 timestamp, | |
953 from_jid, | |
954 to_jid, | |
955 message, | |
956 subject, | |
957 type_, | |
958 extra, | |
959 self.profile, | |
960 ) | |
961 self.messages.move_to_end(uid, last=False) | |
962 self.prependMessage(message) | |
963 Clock.schedule_once(partial( | |
964 self._backHistoryGetCb_post, | |
965 history=history, | |
966 scroll_start_height=scroll_start_height)) | |
967 | |
968 def _backHistoryGetEb(self, failure_): | |
969 G.host.addNote( | |
970 _("Problem while getting back history"), | |
971 _("Can't back history for {target}: {problem}").format( | |
972 target=self.target, problem=failure_), | |
973 C.XMLUI_DATA_LVL_ERROR) | |
974 # we don't unlock self._history_prepend_lock on purpose, no need | |
975 # to try to get more history if something is wrong | |
976 | |
977 def onScroll(self, scroll_view, scroll_y): | |
978 if self._history_prepend_lock: | |
979 return | |
980 if (1-scroll_y) * self.messages_widget.height < INFINITE_SCROLL_LIMIT: | |
981 self._history_prepend_lock = True | |
982 log.debug(f"Retrieving back history for {self} [{self.history_count}]") | |
983 self.history_count += 1 | |
984 first_uid = next(iter(self.messages.keys())) | |
985 filters = self.history_filters.copy() | |
986 filters['before_uid'] = first_uid | |
987 self.host.bridge.historyGet( | |
988 str(self.host.profiles[self.profile].whoami.bare), | |
989 str(self.target), | |
990 30, | |
991 True, | |
992 {k: str(v) for k,v in filters.items()}, | |
993 self.profile, | |
994 callback=self._backHistoryGetCb, | |
995 errback=self._backHistoryGetEb, | |
996 ) | |
997 | |
22 | 998 |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
999 class ChatSelector(cagou_widget.CagouWidget, FilterBehavior): |
394
d15828ca9d86
chat: use the new "implicit_update" and "to_show" properties for ChatSelector.jid_selector:
Goffi <goffi@goffi.org>
parents:
393
diff
changeset
|
1000 jid_selector = properties.ObjectProperty() |
354 | 1001 profile = properties.StringProperty() |
1002 plugin_info_class = Chat | |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1003 use_header_input = True |
354 | 1004 |
1005 def on_select(self, contact_button): | |
1006 contact_jid = jid.JID(contact_button.jid) | |
1007 plugin_info = G.host.getPluginInfo(main=Chat) | |
1008 factory = plugin_info['factory'] | |
1009 self.screen_manager.transition.direction = 'up' | |
1010 carousel = self.whwrapper.carousel | |
1011 current_slides = {w.target: w for w in carousel.slides} | |
1012 if contact_jid in current_slides: | |
1013 slide = current_slides[contact_jid] | |
1014 idx = carousel.slides.index(slide) | |
1015 carousel.index = idx | |
1016 self.screen_manager.current = '' | |
1017 else: | |
1018 G.host.switchWidget( | |
1019 self, factory(plugin_info, contact_jid, profiles=[self.profile])) | |
1020 | |
1021 | |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1022 def onHeaderInput(self): |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1023 text = self.header_input.text.strip() |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1024 try: |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1025 if text.count('@') != 1 or text.count(' '): |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1026 raise ValueError |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1027 jid_ = jid.JID(text) |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1028 except ValueError: |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1029 log.info("entered text is not a jid") |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1030 return |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1031 G.host.doAction("chat", jid_, [self.profile]) |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1032 |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1033 def onHeaderInputComplete(self, wid, text, **kwargs): |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1034 """we filter items when text is entered in input box""" |
404
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1035 for layout in self.jid_selector.items_layouts: |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1036 self.do_filter( |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1037 layout, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1038 text, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1039 # we append nick to jid to filter on both |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1040 lambda c: c.jid + c.data.get('nick', ''), |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1041 width_cb=lambda c: c.base_width, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1042 height_cb=lambda c: c.minimum_height, |
f7476818f9fb
core (common): JidSelector + behaviors various improvments:
Goffi <goffi@goffi.org>
parents:
396
diff
changeset
|
1043 continue_tests=[lambda c: not isinstance(c, ContactButton)]) |
395
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1044 |
c04c3b167cb0
chat: use header input to filter entities + open a new chat with unknown jid.
Goffi <goffi@goffi.org>
parents:
394
diff
changeset
|
1045 |
22 | 1046 PLUGIN_INFO["factory"] = Chat.factory |
1047 quick_widgets.register(quick_chat.QuickChat, Chat) |