comparison libervia/desktop_kivy/plugins/plugin_wid_chat.kv @ 493:b3cedbee561d

refactoring: rename `cagou` to `libervia.desktop_kivy` + update imports and names following backend changes
author Goffi <goffi@goffi.org>
date Fri, 02 Jun 2023 18:26:16 +0200
parents cagou/plugins/plugin_wid_chat.kv@203755bbe0fe
children 196483685a63
comparison
equal deleted inserted replaced
492:5114bbb5daa3 493:b3cedbee561d
1 #Libervia Desktop-Kivy
2 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org)
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
13
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 #:import _ libervia.backend.core.i18n._
18 #:import C libervia.desktop_kivy.core.constants.Const
19 #:import G libervia.desktop_kivy.G
20 #:import escape kivy.utils.escape_markup
21 #:import SimpleXHTMLWidget libervia.desktop_kivy.core.simple_xhtml.SimpleXHTMLWidget
22 #:import DelayedBoxLayout libervia.desktop_kivy.core.common_widgets.DelayedBoxLayout
23 #:import ScrollEffect kivy.effects.scroll.ScrollEffect
24 #:import CategorySeparator libervia.desktop_kivy.core.common_widgets.CategorySeparator
25
26
27 # Chat
28
29
30 <BaseAttachmentItem>:
31 size_hint: None, None
32 size: self.minimum_width, dp(50)
33
34
35 <AttachmentItem>:
36 canvas.before:
37 Color:
38 rgb: app.c_prim_dark
39 Line:
40 rounded_rectangle: self.x + dp(1), self.y + dp(1), self.width - dp(2), self.height - dp(2), 10
41 Color:
42 rgb: app.c_sec_light
43 RoundedRectangle:
44 pos: self.x + dp(1), self.y + dp(1)
45 size: (self.width - dp(2)) * root.progress / 100, self.height - dp(2)
46 SymbolButtonLabel:
47 symbol: root.get_symbol(root.data)
48 color: 0, 0, 0, 1
49 text: root.data.get('name', _('unnamed'))
50 bold: False
51 on_press: root.on_press()
52
53
54 <AttachmentImageItem>:
55 size: self.minimum_width, self.minimum_height
56 image: image
57 orientation: "vertical"
58 SizedImage:
59 id: image
60 anim_delay: -1
61 source: "data/images/image-loading.gif"
62
63
64 <AttachmentImagesCollectionItem>:
65 cols: 2
66 size_hint: None, None
67 size: dp(150), dp(150)
68 padding: dp(5)
69 spacing: dp(2)
70 canvas.before:
71 Color:
72 rgb: app.c_prim
73 RoundedRectangle:
74 radius: [dp(5)]
75 pos: self.pos
76 size: self.size
77 Color:
78 rgb: 0, 0, 0, 1
79 Line:
80 rounded_rectangle: self.x, self.y, self.width, self.height, dp(5)
81
82
83 <AttachmentsLayout>:
84 attachments: self
85 size_hint: 1, None
86 height: self.minimum_height
87 spacing: dp(5)
88
89
90 <MessAvatar>:
91 size_hint: None, None
92 size: dp(30), dp(30)
93 canvas.before:
94 Color:
95 rgba: (0.87,0.87,0.87,1)
96 RoundedRectangle:
97 radius: [dp(5)]
98 pos: self.pos
99 size: self.size
100
101
102 <MessageWidget>:
103 size_hint: 1, None
104 avatar: avatar
105 delivery: delivery
106 mess_xhtml: mess_xhtml
107 right_part: right_part
108 header_box: header_box
109 height: self.minimum_height
110 BoxLayout:
111 orientation: 'vertical'
112 width: avatar.width
113 size_hint: None, 1
114 MessAvatar:
115 id: avatar
116 source: root.mess_data.avatar['path'] if root.mess_data and root.mess_data.avatar else app.default_avatar
117 on_press: root.chat.add_nick(root.nick)
118 Widget:
119 # use to push the avatar on the top
120 size_hint: 1, 1
121 BoxLayout:
122 size_hint: 1, None
123 orientation: 'vertical'
124 id: right_part
125 height: self.minimum_height
126 BoxLayout:
127 id: header_box
128 size_hint: 1, None
129 height: time_label.height if root.mess_type != C.MESS_TYPE_INFO else 0
130 opacity: 1 if root.mess_type != C.MESS_TYPE_INFO else 0
131 Label:
132 id: time_label
133 color: (0, 0, 0, 1) if root.own_mess else (0.55,0.55,0.55,1)
134 font_size: root.font_size
135 text_size: None, None
136 size_hint: None, None
137 size: self.texture_size
138 padding: dp(5), 0
139 markup: True
140 valign: 'middle'
141 text: u"[b]{}[/b], {}".format(escape(root.nick), root.time_text)
142 Symbol:
143 size_hint_x: None
144 width: self.height
145 id: encrypted
146 symbol: 'lock-filled' if root.mess_data.encrypted else 'lock-open'
147 font_size: self.height - dp(3)
148 color: (1, 0, 0, 1) if not root.mess_data.encrypted and root.chat.encrypted else (0.55,0.55,0.55,1)
149 Label:
150 id: delivery
151 color: C.COLOR_BTN_LIGHT
152 font_size: root.font_size
153 text_size: None, None
154 size_hint: None, None
155 size: self.texture_size
156 padding: dp(5), 0
157 # XXX: DejaVuSans font is needed as check mark is not in Roboto
158 # this can be removed when Kivy will be able to handle fallback mechanism
159 # which will allow us to use fonts with more unicode characters
160 font_name: "DejaVuSans"
161 text: u''
162 SimpleXHTMLWidget:
163 id: mess_xhtml
164 size_hint: 1, None
165 height: self.minimum_height
166 xhtml: root.message_xhtml or self.escape(root.message or '')
167 color: (0.74,0.74,0.24,1) if root.mess_type == "info" else (0, 0, 0, 1)
168 padding: root.mess_padding
169 bold: True if root.mess_type == "info" else False
170
171
172 <AttachmentToSendItem>:
173 SymbolButton:
174 opacity: 0 if root.sending else 1
175 size_hint: None, 1
176 symbol: "cancel-circled"
177 on_press: root.parent.remove_widget(root)
178
179
180 <AttachmentsToSend>:
181 attachments: attachments_layout.attachments
182 reduce_checkbox: reduce_checkbox
183 orientation: "vertical"
184 size_hint: 1, None
185 height: self.minimum_height if self.attachments.children else 0
186 opacity: 1 if self.attachments.children else 0
187 padding: [app.MARGIN_LEFT, dp(5), app.MARGIN_RIGHT, dp(5)]
188 canvas.before:
189 Color:
190 rgba: app.c_prim
191 Rectangle:
192 pos: self.pos
193 size: self.size
194 Label:
195 size_hint: 1, None
196 size: self.texture_size
197 text: _("attachments:")
198 bold: True
199 AttachmentsLayout:
200 id: attachments_layout
201 BoxLayout:
202 id: resize_box
203 size_hint: 1, None
204 opacity: 1 if root.show_resize else 0
205 height: dp(25) if root.show_resize else 0
206 Widget:
207 CheckBox:
208 id: reduce_checkbox
209 size_hint: None, 1
210 width: dp(20)
211 active: True
212 Label:
213 size_hint: None, 1
214 text: _("reduce images size")
215 text_size: None, None
216 size: self.texture_size
217 valign: "middle"
218 padding_x: dp(10)
219 font_size: sp(15)
220 Widget:
221
222 <Chat>:
223 attachments_to_send: attachments_to_send
224 message_input: message_input
225 messages_widget: messages_widget
226 history_scroll: history_scroll
227 send_button_visible: G.local_platform.send_button_visible or bool(attachments_to_send.attachments.children)
228 ScrollView:
229 id: history_scroll
230 scroll_y: 0
231 on_scroll_y: root.on_scroll(*args)
232 do_scroll_x: False
233 scroll_type: ['bars', 'content']
234 bar_width: dp(10)
235 effect_cls: ScrollEffect
236 DelayedBoxLayout:
237 id: messages_widget
238 size_hint_y: None
239 padding: [app.MARGIN_LEFT, 0, app.MARGIN_RIGHT, dp(10)]
240 spacing: dp(10)
241 height: self.minimum_height
242 orientation: 'vertical'
243 AttachmentsToSend:
244 id: attachments_to_send
245 MessageInputBox:
246 size_hint: 1, None
247 height: self.minimum_height
248 spacing: dp(10)
249 padding: [app.MARGIN_LEFT, 0, app.MARGIN_RIGHT, dp(10)]
250 message_input: message_input
251 MessageInputWidget:
252 id: message_input
253 size_hint: 1, None
254 height: min(self.minimum_height, dp(250))
255 multiline: True
256 hint_text: _(u"Enter your message here")
257 on_text_validate: root.on_send(args[0])
258 SymbolButton:
259 # "send" button, permanent visibility depends on platform
260 symbol: "forward"
261 size_hint: None, 1
262 width: dp(30) if root.send_button_visible else 0
263 opacity: 1 if root.send_button_visible else 0
264 font_size: dp(25)
265 on_release: self.parent.send_text()
266
267
268 # Buttons added in header
269
270 <TransferButton>:
271 size_hint: None, 1
272 symbol: "plus-circled"
273 width: dp(30)
274 font_size: dp(25)
275 color: 0.4, 0.4, 0.4, 1
276
277 <MenuButton@Button>
278 size_hint_y: None
279 height: dp(30)
280 on_texture_size: self.parent.parent.width = max(self.parent.parent.width, self.texture_size[0] + dp(10))
281
282 <ExtraMenu>:
283 auto_width: False
284 MenuButton:
285 text: _("bookmarks")
286 on_release: root.select("bookmark")
287 MenuButton:
288 text: _("close")
289 on_release: root.select("close")
290
291 <ExtraButton>:
292 size_hint: None, 1
293 symbol: "dot-3-vert"
294 width: dp(30)
295 font_size: dp(25)
296 color: 0.4, 0.4, 0.4, 1
297 on_release: self.chat.extra_menu.open(self)
298
299 <EncryptionMainButton>:
300 size_hint: None, 1
301 width: dp(30)
302 color: self.get_color()
303 symbol: self.get_symbol()
304
305 <TrustManagementButton>:
306 symbol: "shield"
307 padding: dp(5), dp(10)
308 bg_color: app.c_prim_dark
309 size_hint: None, 1
310 width: dp(30)
311 on_release: self.parent.dispatch("on_trust_release")
312
313 <EncryptionButton>:
314 size_hint: None, None
315 width: self.parent.parent.best_width if self.parent is not None else 30
316 height: dp(30)
317 on_best_width: self.parent.parent.best_width = max(self.parent.parent.best_width, args[1])
318 Button:
319 text: root.text
320 size_hint: 1, 1
321 padding: dp(5), dp(10)
322 color: 0, 0, 0, 1
323 bold: root.bold
324 background_normal: app.expand('{media}/misc/borders/border_filled_black.png')
325 background_color: app.c_sec if root.selected else app.c_prim_dark
326 on_release: root.dispatch("on_release")
327 on_texture_size: root.best_width = self.texture_size[0] + (dp(30) if root.trust_button else 0)
328
329 <EncryptionMenu>:
330 size_hint_x: None
331 width: self.container.minimum_width
332 auto_width: False
333 canvas.before:
334 Color:
335 rgba: 0, 0, 0, 1
336 Rectangle:
337 pos: self.pos
338 size: self.size
339
340
341 # Chat Selector
342
343 <ChatSelector>:
344 jid_selector: jid_selector
345 JidSelector:
346 id: jid_selector
347 on_select: root.on_select(args[1])
348 to_show: ["opened_chats", "roster", "bookmarks"]
349