Mercurial > libervia-desktop-kivy
annotate src/cagou/plugins/plugin_wid_chat.py @ 67:5f7f72c2635f
chat: shortened chat header
"You are talking with " has been removed from chat header, so it can be displayed on small screens (phones)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 17 Dec 2016 14:32:40 +0100 |
parents | 2aa44a82d0e7 |
children | 4a1e1012337e |
rev | line source |
---|---|
22 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 from sat.core import log as logging | |
22 log = logging.getLogger(__name__) | |
23 from sat.core.i18n import _ | |
24 from cagou.core.constants import Const as C | |
45 | 25 from kivy.uix.gridlayout import GridLayout |
57 | 26 from kivy.uix.stacklayout import StackLayout |
22 | 27 from kivy.uix.scrollview import ScrollView |
28 from kivy.uix.textinput import TextInput | |
57 | 29 from kivy.uix.label import Label |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
30 from kivy.uix.image import AsyncImage |
45 | 31 from kivy.metrics import dp |
57 | 32 from kivy.utils import escape_markup |
22 | 33 from kivy import properties |
34 from sat_frontends.quick_frontend import quick_widgets | |
35 from sat_frontends.quick_frontend import quick_chat | |
57 | 36 from sat_frontends.tools import jid, css_color |
22 | 37 from cagou.core import cagou_widget |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
38 from cagou.core.image import Image |
22 | 39 from cagou import G |
57 | 40 from xml.etree import ElementTree as ET |
22 | 41 |
42 | |
43 PLUGIN_INFO = { | |
44 "name": _(u"chat"), | |
45 "main": "Chat", | |
46 "description": _(u"instant messaging with one person or a group"), | |
25
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
47 "icon_small": u"{media}/icons/muchoslava/png/chat_rouge_32.png", |
d09bd16dbbe2
code (cagou widget), selector: icons handling + use of new muchoslava icon set
Goffi <goffi@goffi.org>
parents:
24
diff
changeset
|
48 "icon_medium": u"{media}/icons/muchoslava/png/chat_rouge_44.png" |
22 | 49 } |
50 | |
51 | |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
52 class MessAvatar(Image): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
53 pass |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
54 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
55 |
57 | 56 class Escape(unicode): |
57 """Class used to mark that a message need to be escaped""" | |
58 | |
59 def __init__(self, text): | |
60 super(Escape, self).__init__(text) | |
61 | |
62 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
63 class SimpleXHTMLWidgetEscapedText(Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
64 pass |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
65 |
59 | 66 |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
67 class SimpleXHTMLWidgetText(Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
68 pass |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
69 |
59 | 70 |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
71 class SimpleXHTMLWidgetImage(AsyncImage): |
59 | 72 # following properties are desired height/width |
73 # i.e. the ones specified in height/width attributes of <img> | |
74 # (or wanted for whatever reason) | |
75 # set to 0 to ignore them | |
76 target_height = properties.NumericProperty() | |
77 target_width = properties.NumericProperty() | |
78 | |
79 def _get_parent_container(self): | |
80 """get parent SimpleXHTMLWidget instance | |
81 | |
82 @param warning(bool): if True display a log.error if nothing found | |
83 @return (SimpleXHTMLWidget, None): found SimpleXHTMLWidget instance | |
84 """ | |
85 parent = self.parent | |
86 while parent and not isinstance(parent, SimpleXHTMLWidget): | |
87 parent = parent.parent | |
88 if parent is None: | |
89 log.error(u"no SimpleXHTMLWidget parent found") | |
90 return parent | |
91 | |
92 def _on_source_load(self, value): | |
93 # this method is called when image is loaded | |
94 super(SimpleXHTMLWidgetImage, self)._on_source_load(value) | |
95 if self.parent is not None: | |
96 container = self._get_parent_container() | |
97 # image is loaded, we need to recalculate size | |
98 self.on_container_width(container, container.width) | |
99 | |
100 def on_container_width(self, container, container_width): | |
101 """adapt size according to container width | |
102 | |
103 called when parent container (SimpleXHTMLWidget) width change | |
104 """ | |
105 target_size = (self.target_width or self.texture.width, self.target_height or self.texture.height) | |
106 padding = container.padding | |
107 padding_h = (padding[0] + padding[2]) if len(padding) == 4 else padding[0] | |
108 width = container_width - padding_h | |
109 if target_size[0] < width: | |
110 self.size = target_size | |
111 else: | |
112 height = width / self.image_ratio | |
113 self.size = (width, height) | |
114 | |
115 def on_parent(self, instance, parent): | |
116 if parent is not None: | |
117 container = self._get_parent_container() | |
118 container.bind(width=self.on_container_width) | |
119 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
120 |
57 | 121 class SimpleXHTMLWidget(StackLayout): |
122 """widget handling simple XHTML parsing""" | |
123 xhtml = properties.StringProperty() | |
124 color = properties.ListProperty([1, 1, 1, 1]) | |
125 # XXX: bold is only used for escaped text | |
126 bold = properties.BooleanProperty(False) | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
127 content_width = properties.NumericProperty(0) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
128 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
129 # text/XHTML input |
57 | 130 |
131 def on_xhtml(self, instance, xhtml): | |
132 """parse xhtml and set content accordingly | |
133 | |
134 if xhtml is an instance of Escape, a Label with not markup | |
135 will be used | |
136 """ | |
137 self.clear_widgets() | |
138 if isinstance(xhtml, Escape): | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
139 label = SimpleXHTMLWidgetEscapedText(text=xhtml, color=self.color) |
57 | 140 self.bind(color=label.setter('color')) |
141 self.bind(bold=label.setter('bold')) | |
142 self.add_widget(label) | |
143 else: | |
144 xhtml = ET.fromstring(xhtml.encode('utf-8')) | |
145 self.current_wid = None | |
146 self.styles = [] | |
147 self._callParseMethod(xhtml) | |
148 | |
149 def escape(self, text): | |
150 """mark that a text need to be escaped (i.e. no markup)""" | |
151 return Escape(text) | |
152 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
153 # sizing |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
154 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
155 def on_width(self, instance, width): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
156 if len(self.children) == 1: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
157 wid = self.children[0] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
158 if isinstance(wid, Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
159 try: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
160 full_width = wid._full_width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
161 except AttributeError: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
162 wid.size_hint = (None, None) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
163 wid.texture_update() |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
164 full_width = wid._full_width = wid.texture_size[0] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
165 if full_width > width: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
166 wid.text_size = width, None |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
167 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
168 wid.text_size = None, None |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
169 self.content_width = wid.width + self.padding[0] + self.padding[2] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
170 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
171 wid.size_hint(1, None) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
172 wid.height = 100 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
173 self.content_width = self.width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
174 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
175 self._do_complexe_sizing(width) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
176 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
177 def _do_complexe_sizing(self, width): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
178 try: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
179 self.splitted |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
180 except AttributeError: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
181 # XXX: to make things easier, we split labels in words |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
182 log.debug(u"split start") |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
183 children = self.children[::-1] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
184 self.clear_widgets() |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
185 for child in children: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
186 if isinstance(child, Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
187 log.debug(u"label before split: {}".format(child.text)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
188 styles = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
189 tag = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
190 new_text = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
191 current_tag = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
192 current_value = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
193 current_wid = self._createText() |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
194 value = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
195 close = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
196 # we will parse the text and create a new widget |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
197 # on each new word (actually each space) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
198 # FIXME: handle '\n' and other white chars |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
199 for c in child.text: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
200 if tag: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
201 # we are parsing a markup tag |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
202 if c == u']': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
203 current_tag_s = u''.join(current_tag) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
204 current_style = (current_tag_s, u''.join(current_value)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
205 if close: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
206 for idx, s in enumerate(reversed(styles)): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
207 if s[0] == current_tag_s: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
208 del styles[len(styles) - idx - 1] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
209 break |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
210 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
211 styles.append(current_style) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
212 current_tag = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
213 current_value = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
214 tag = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
215 value = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
216 close = False |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
217 elif c == u'/': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
218 close = True |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
219 elif c == u'=': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
220 value = True |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
221 elif value: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
222 current_value.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
223 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
224 current_tag.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
225 new_text.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
226 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
227 # we are parsing regular text |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
228 if c == u'[': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
229 new_text.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
230 tag = True |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
231 elif c == u' ': |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
232 # new word, we do a new widget |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
233 new_text.append(u' ') |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
234 for t, v in reversed(styles): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
235 new_text.append(u'[/{}]'.format(t)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
236 current_wid.text = u''.join(new_text) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
237 new_text = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
238 self.add_widget(current_wid) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
239 log.debug(u"new widget: {}".format(current_wid.text)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
240 current_wid = self._createText() |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
241 for t, v in styles: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
242 new_text.append(u'[{tag}{value}]'.format( |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
243 tag = t, |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
244 value = u'={}'.format(v) if v else u'')) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
245 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
246 new_text.append(c) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
247 if current_wid.text: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
248 # we may have a remaining widget after the parsing |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
249 close_styles = [] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
250 for t, v in reversed(styles): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
251 close_styles.append(u'[/{}]'.format(t)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
252 current_wid.text = u''.join(close_styles) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
253 self.add_widget(current_wid) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
254 log.debug(u"new widget: {}".format(current_wid.text)) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
255 else: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
256 # non Label widgets, we just add them |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
257 self.add_widget(child) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
258 self.splitted = True |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
259 log.debug(u"split OK") |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
260 |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
261 # we now set the content width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
262 # FIXME: for now we just use the full width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
263 self.content_width = width |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
264 |
57 | 265 # XHTML parsing methods |
266 | |
267 def _callParseMethod(self, e): | |
268 """call the suitable method to parse the element | |
269 | |
270 self.xhtml_[tag] will be called if it exists, else | |
271 self.xhtml_generic will be used | |
272 @param e(ET.Element): element to parse | |
273 """ | |
274 try: | |
275 method = getattr(self, "xhtml_{}".format(e.tag)) | |
276 except AttributeError: | |
277 log.warning(u"Unhandled XHTML tag: {}".format(e.tag)) | |
278 method = self.xhtml_generic | |
279 method(e) | |
280 | |
281 def _addStyle(self, tag, value=None, append_to_list=True): | |
282 """add a markup style to label | |
283 | |
284 @param tag(unicode): markup tag | |
285 @param value(unicode): markup value if suitable | |
286 @param append_to_list(bool): if True style we be added to self.styles | |
287 self.styles is needed to keep track of styles to remove | |
288 should most probably be set to True | |
289 """ | |
290 label = self._getLabel() | |
291 label.text += u'[{tag}{value}]'.format( | |
292 tag = tag, | |
293 value = u'={}'.format(value) if value else '' | |
294 ) | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
295 if append_to_list: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
296 self.styles.append((tag, value)) |
57 | 297 |
298 def _removeStyle(self, tag, remove_from_list=True): | |
299 """remove a markup style from the label | |
300 | |
301 @param tag(unicode): markup tag to remove | |
302 @param remove_from_list(bool): if True, remove from self.styles too | |
303 should most probably be set to True | |
304 """ | |
305 label = self._getLabel() | |
306 label.text += u'[/{tag}]'.format( | |
307 tag = tag | |
308 ) | |
309 if remove_from_list: | |
310 for rev_idx, style in enumerate(reversed(self.styles)): | |
311 if style[0] == tag: | |
312 tag_idx = len(self.styles) - 1 - rev_idx | |
313 del self.styles[tag_idx] | |
314 break | |
315 | |
316 def _getLabel(self): | |
317 """get current Label if it exists, or create a new one""" | |
318 if not isinstance(self.current_wid, Label): | |
319 self._addLabel() | |
320 return self.current_wid | |
321 | |
322 def _addLabel(self): | |
323 """add a new Label | |
324 | |
325 current styles will be closed and reopened if needed | |
326 """ | |
327 self._closeLabel() | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
328 self.current_wid = self._createText() |
57 | 329 for tag, value in self.styles: |
330 self._addStyle(tag, value, append_to_list=False) | |
331 self.add_widget(self.current_wid) | |
332 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
333 def _createText(self): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
334 label = SimpleXHTMLWidgetText(color=self.color, markup=True) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
335 self.bind(color=label.setter('color')) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
336 label.bind(texture_size=label.setter('size')) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
337 return label |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
338 |
57 | 339 def _closeLabel(self): |
340 """close current style tags in current label | |
341 | |
342 needed when you change label to keep style between | |
343 different widgets | |
344 """ | |
345 if isinstance(self.current_wid, Label): | |
346 for tag, value in reversed(self.styles): | |
347 self._removeStyle(tag, remove_from_list=False) | |
348 | |
349 def _parseCSS(self, e): | |
350 """parse CSS found in "style" attribute of element | |
351 | |
352 self._css_styles will be created and contained markup styles added by this method | |
353 @param e(ET.Element): element which may have a "style" attribute | |
354 """ | |
355 styles_limit = len(self.styles) | |
356 styles = e.attrib['style'].split(u';') | |
357 for style in styles: | |
358 try: | |
359 prop, value = style.split(u':') | |
360 except ValueError: | |
361 log.warning(u"can't parse style: {}".format(style)) | |
362 continue | |
363 prop = prop.strip().replace(u'-', '_') | |
364 value = value.strip() | |
365 try: | |
366 method = getattr(self, "css_{}".format(prop)) | |
367 except AttributeError: | |
368 log.warning(u"Unhandled CSS: {}".format(prop)) | |
369 else: | |
370 method(e, value) | |
371 self._css_styles = self.styles[styles_limit:] | |
372 | |
373 def _closeCSS(self): | |
374 """removed CSS styles | |
375 | |
376 styles in self._css_styles will be removed | |
377 and the attribute will be deleted | |
378 """ | |
379 for tag, dummy in reversed(self._css_styles): | |
380 self._removeStyle(tag) | |
381 del self._css_styles | |
382 | |
383 def xhtml_generic(self, elem, style=True, markup=None): | |
384 """generic method for adding HTML elements | |
385 | |
386 this method handle content, style and children parsing | |
387 @param elem(ET.Element): element to add | |
388 @param style(bool): if True handle style attribute (CSS) | |
389 @param markup(tuple[unicode, (unicode, None)], None): kivy markup to use | |
390 """ | |
391 # we first add markup and CSS style | |
392 if markup is not None: | |
393 if isinstance(markup, basestring): | |
394 tag, value = markup, None | |
395 else: | |
396 tag, value = markup | |
397 self._addStyle(tag, value) | |
398 style_ = 'style' in elem.attrib and style | |
399 if style_: | |
400 self._parseCSS(elem) | |
401 | |
402 # then content | |
403 if elem.text: | |
404 self._getLabel().text += escape_markup(elem.text) | |
405 | |
406 # we parse the children | |
407 for child in elem: | |
408 self._callParseMethod(child) | |
409 | |
410 # closing CSS style and markup | |
411 if style_: | |
412 self._closeCSS() | |
413 if markup is not None: | |
414 self._removeStyle(tag) | |
415 | |
416 # and the tail, which is regular text | |
417 if elem.tail: | |
418 self._getLabel().text += escape_markup(elem.tail) | |
419 | |
420 # method handling XHTML elements | |
421 | |
422 def xhtml_br(self, elem): | |
423 label = self._getLabel() | |
424 label.text+='\n' | |
425 self.xhtml_generic(style=False) | |
426 | |
427 def xhtml_em(self, elem): | |
428 self.xhtml_generic(elem, markup='i') | |
429 | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
430 def xhtml_img(self, elem): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
431 try: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
432 src = elem.attrib['src'] |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
433 except KeyError: |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
434 log.warning(u"<img> element without src: {}".format(ET.tostring(elem))) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
435 return |
59 | 436 try: |
437 target_height = int(elem.get(u'height', 0)) | |
438 except ValueError: | |
439 log.warning(u"Can't parse image height: {}".format(elem.get(u'height'))) | |
440 target_height = 0 | |
441 try: | |
442 target_width = int(elem.get(u'width', 0)) | |
443 except ValueError: | |
444 log.warning(u"Can't parse image width: {}".format(elem.get(u'width'))) | |
445 target_width = 0 | |
446 | |
447 img = SimpleXHTMLWidgetImage(source=src, target_height=target_height, target_width=target_width) | |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
448 self.current_wid = img |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
449 self.add_widget(img) |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
450 |
57 | 451 def xhtml_p(self, elem): |
58
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
452 if isinstance(self.current_wid, Label): |
7aa2ffff9067
chat: <img/> tag handling first draft:
Goffi <goffi@goffi.org>
parents:
57
diff
changeset
|
453 self.current_wid.text+="\n\n" |
57 | 454 self.xhtml_generic(elem) |
455 | |
456 def xhtml_span(self, elem): | |
457 self.xhtml_generic(elem) | |
458 | |
459 def xhtml_strong(self, elem): | |
460 self.xhtml_generic(elem, markup='b') | |
461 | |
462 # methods handling CSS properties | |
463 | |
464 def css_color(self, elem, value): | |
465 self._addStyle(u"color", css_color.parse(value)) | |
466 | |
467 def css_text_decoration(self, elem, value): | |
468 if value == u'underline': | |
469 log.warning(u"{} not handled yet, it needs Kivy 1.9.2 to be released".format(value)) | |
470 # FIXME: activate when 1.9.2 is out | |
471 # self._addStyle('u') | |
472 elif value == u'line-through': | |
473 log.warning(u"{} not handled yet, it needs Kivy 1.9.2 to be released".format(value)) | |
474 # FIXME: activate when 1.9.2 is out | |
475 # self._addStyle('s') | |
476 else: | |
477 log.warning(u"unhandled text decoration: {}".format(value)) | |
478 | |
479 | |
45 | 480 class MessageWidget(GridLayout): |
22 | 481 mess_data = properties.ObjectProperty() |
57 | 482 mess_xhtml = properties.ObjectProperty() |
45 | 483 mess_padding = (dp(5), dp(5)) |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
484 avatar = properties.ObjectProperty() |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
485 |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
486 def __init__(self, **kwargs): |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
487 super(MessageWidget, self).__init__(**kwargs) |
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
488 self.mess_data.widgets.add(self) |
44
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
489 |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
490 @property |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
491 def chat(self): |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
492 """return parent Chat instance""" |
7819e9efa250
chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
493 return self.mess_data.parent |
22 | 494 |
495 @property | |
496 def message(self): | |
497 """Return currently displayed message""" | |
498 return self.mess_data.main_message | |
499 | |
57 | 500 @property |
501 def message_xhtml(self): | |
502 """Return currently displayed message""" | |
503 return self.mess_data.main_message_xhtml | |
504 | |
45 | 505 def widthAdjust(self): |
22 | 506 """this widget grows up with its children""" |
57 | 507 pass |
508 # parent = self.mess_xhtml.parent | |
509 # padding_x = self.mess_padding[0] | |
510 # text_width, text_height = self.mess_xhtml.texture_size | |
511 # if text_width > parent.width: | |
512 # self.mess_xhtml.text_size = (parent.width - padding_x, None) | |
513 # self.text_max = text_width | |
514 # elif self.mess_xhtml.text_size[0] is not None and text_width < parent.width - padding_x: | |
515 # if text_width < self.text_max: | |
516 # self.mess_xhtml.text_size = (None, None) | |
517 # else: | |
518 # self.mess_xhtml.text_size = (parent.width - padding_x, None) | |
22 | 519 |
54
514c187afebc
chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents:
47
diff
changeset
|
520 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
|
521 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
|
522 self.avatar.source = update_dict['avatar'] |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
523 |
22 | 524 |
525 class MessageInputWidget(TextInput): | |
526 | |
527 def _key_down(self, key, repeat=False): | |
528 displayed_str, internal_str, internal_action, scale = key | |
529 if internal_action == 'enter': | |
530 self.dispatch('on_text_validate') | |
531 else: | |
532 super(MessageInputWidget, self)._key_down(key, repeat) | |
533 | |
534 | |
45 | 535 class MessagesWidget(GridLayout): |
536 pass | |
22 | 537 |
538 | |
539 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): | |
540 | |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
541 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, profiles=None): |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
542 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles) |
22 | 543 cagou_widget.CagouWidget.__init__(self) |
67 | 544 self.header_input.hint_text = u"{}".format(target) |
37
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
545 scroll_view = ScrollView(size_hint=(1,0.8), scroll_y=0, do_scroll_x=False) |
22 | 546 self.messages_widget = MessagesWidget() |
547 scroll_view.add_widget(self.messages_widget) | |
548 self.add_widget(scroll_view) | |
549 message_input = MessageInputWidget() | |
550 message_input.bind(on_text_validate=self.onSend) | |
551 self.add_widget(message_input) | |
552 self.postInit() | |
553 | |
554 @classmethod | |
555 def factory(cls, plugin_info, target, profiles): | |
556 profiles = list(profiles) | |
557 if len(profiles) > 1: | |
558 raise NotImplementedError(u"Multi-profiles is not available yet for chat") | |
559 if target is None: | |
560 target = G.host.profiles[profiles[0]].whoami | |
561 return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE, profiles=profiles) | |
562 | |
563 def messageDataConverter(self, idx, mess_id): | |
564 return {"mess_data": self.messages[mess_id]} | |
565 | |
566 def _onHistoryPrinted(self): | |
567 """Refresh or scroll down the focus after the history is printed""" | |
568 # self.adapter.data = self.messages | |
569 for mess_data in self.messages.itervalues(): | |
570 self.appendMessage(mess_data) | |
571 super(Chat, self)._onHistoryPrinted() | |
572 | |
573 def createMessage(self, message): | |
574 self.appendMessage(message) | |
575 | |
576 def appendMessage(self, mess_data): | |
577 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data)) | |
578 | |
579 def onSend(self, input_widget): | |
580 G.host.messageSend( | |
581 self.target, | |
582 {'': input_widget.text}, # TODO: handle language | |
583 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, # TODO: put this in QuickChat | |
584 profile_key=self.profile | |
585 ) | |
586 input_widget.text = '' | |
587 | |
46
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
588 def _mucJoinCb(self, joined_data): |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
589 joined, room_jid_s, occupants, user_nick, subject, profile = joined_data |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
590 self.host.mucRoomJoinedHandler(*joined_data[1:]) |
d6a63942d5ad
chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents:
45
diff
changeset
|
591 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
|
592 self.changeWidget(jid_) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
593 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
594 def _mucJoinEb(self, failure): |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
595 log.warning(u"Can't join room: {}".format(failure)) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
596 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
597 def changeWidget(self, jid_): |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
598 """change current widget for a new one with given jid |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
599 |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
600 @param jid_(jid.JID): jid of the widget to create |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
601 """ |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
602 plugin_info = G.host.getPluginInfo(main=Chat) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
603 factory = plugin_info['factory'] |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
604 G.host.switchWidget(self, factory(plugin_info, jid_, profiles=[self.profile])) |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
605 self.header_input.text = '' |
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
606 |
22 | 607 def onHeaderInput(self): |
608 text = self.header_input.text.strip() | |
609 try: | |
610 if text.count(u'@') != 1 or text.count(u' '): | |
611 raise ValueError | |
612 jid_ = jid.JID(text) | |
613 except ValueError: | |
614 log.info(u"entered text is not a jid") | |
615 return | |
616 | |
617 def discoCb(disco): | |
618 # TODO: check if plugin XEP-0045 is activated | |
619 if "conference" in [i[0] for i in disco[1]]: | |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
620 G.host.bridge.mucJoin(unicode(jid_), "", "", self.profile, callback=self._mucJoinCb, errback=self._mucJoinEb) |
22 | 621 else: |
42
286865bc013a
chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents:
41
diff
changeset
|
622 self.changeWidget(jid_) |
22 | 623 |
624 def discoEb(failure): | |
625 log.warning(u"Disco failure, ignore this text: {}".format(failure)) | |
626 | |
627 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, errback=discoEb) | |
628 | |
37
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
629 def onDelete(self, force=False): |
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
630 if force==True: |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
631 return super(Chat, self).onDelete() |
37
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
632 if len(list(G.host.widgets.getWidgets(self.__class__, self.target, profiles=self.profiles))) > 1: |
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
633 # we don't keep duplicate widgets |
47
abb81efef3bb
chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents:
46
diff
changeset
|
634 return super(Chat, self).onDelete() |
37
6cf08d0ee460
chat: forbid scrolling on X axis + don't delete widget until explicitly requested (with force attribute)
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
635 return False |
22 | 636 |
637 | |
638 PLUGIN_INFO["factory"] = Chat.factory | |
639 quick_widgets.register(quick_chat.QuickChat, Chat) |