annotate src/cagou/plugins/plugin_wid_chat.py @ 111:c3952922ca56

chat: uploaded images are now sent with XHTML, so they are shown inline
author Goffi <goffi@goffi.org>
date Sun, 15 Jan 2017 23:52:28 +0100
parents 7631325e11f4
children f0291755b07c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2016 Jérôme Poisson (goffi@goffi.org)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from sat.core import log as logging
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 log = logging.getLogger(__name__)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core.i18n import _
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from cagou.core.constants import Const as C
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
25 from kivy.uix.boxlayout import BoxLayout
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
26 from kivy.uix.gridlayout import GridLayout
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from kivy.uix.textinput import TextInput
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
28 from kivy.metrics import dp
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from kivy import properties
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from sat_frontends.quick_frontend import quick_widgets
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from sat_frontends.quick_frontend import quick_chat
106
9909ed7a7a20 moved SimpleXHTMLWidget to a dedicated module
Goffi <goffi@goffi.org>
parents: 105
diff changeset
32 from sat_frontends.tools import jid
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from cagou.core import cagou_widget
106
9909ed7a7a20 moved SimpleXHTMLWidget to a dedicated module
Goffi <goffi@goffi.org>
parents: 105
diff changeset
34 from cagou.core.image import Image
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
35 from cagou.core.common import JidWidget
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
36 from kivy.uix.dropdown import DropDown
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from cagou import G
111
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
38 import mimetypes
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 PLUGIN_INFO = {
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 "name": _(u"chat"),
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "main": "Chat",
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 "description": _(u"instant messaging with one person or a group"),
90
9a6121722669 chat, contact_list, selector: use of new icons from muchoslava
Goffi <goffi@goffi.org>
parents: 88
diff changeset
45 "icon_small": u"{media}/icons/muchoslava/png/chat_new_32.png",
9a6121722669 chat, contact_list, selector: use of new icons from muchoslava
Goffi <goffi@goffi.org>
parents: 88
diff changeset
46 "icon_medium": u"{media}/icons/muchoslava/png/chat_new_44.png"
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 }
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
44
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
50 class MessAvatar(Image):
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
51 pass
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
52
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
53
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
54 class MessageWidget(GridLayout):
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 mess_data = properties.ObjectProperty()
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
56 mess_xhtml = properties.ObjectProperty()
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
57 mess_padding = (dp(5), dp(5))
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
58 avatar = properties.ObjectProperty()
103
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
59 delivery = properties.ObjectProperty()
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
60
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
61 def __init__(self, **kwargs):
105
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
62 # self must be registered in widgets before kv is parsed
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
63 kwargs['mess_data'].widgets.add(self)
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
64 super(MessageWidget, self).__init__(**kwargs)
105
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
65 avatar_path = self.mess_data.avatar
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
66 if avatar_path is not None:
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
67 self.avatar.source = avatar_path
44
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
68
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
69 @property
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
70 def chat(self):
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
71 """return parent Chat instance"""
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
72 return self.mess_data.parent
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 @property
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def message(self):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 """Return currently displayed message"""
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 return self.mess_data.main_message
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
79 @property
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
80 def message_xhtml(self):
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
81 """Return currently displayed message"""
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
82 return self.mess_data.main_message_xhtml
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
83
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
84 def widthAdjust(self):
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 """this widget grows up with its children"""
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
86 pass
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
87 # parent = self.mess_xhtml.parent
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
88 # padding_x = self.mess_padding[0]
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
89 # text_width, text_height = self.mess_xhtml.texture_size
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
90 # if text_width > parent.width:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
91 # self.mess_xhtml.text_size = (parent.width - padding_x, None)
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
92 # self.text_max = text_width
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
93 # elif self.mess_xhtml.text_size[0] is not None and text_width < parent.width - padding_x:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
94 # if text_width < self.text_max:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
95 # self.mess_xhtml.text_size = (None, None)
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
96 # else:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
97 # self.mess_xhtml.text_size = (parent.width - padding_x, None)
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98
54
514c187afebc chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents: 47
diff changeset
99 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
100 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
101 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
102 if 'status' in update_dict:
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
103 status = update_dict['status']
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
104 self.delivery.text = u'\u2714' if status == 'delivered' else u''
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
105
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
107 class MessageInputBox(BoxLayout):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
108 pass
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
109
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
110
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 class MessageInputWidget(TextInput):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 def _key_down(self, key, repeat=False):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 displayed_str, internal_str, internal_action, scale = key
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 if internal_action == 'enter':
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.dispatch('on_text_validate')
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 else:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 super(MessageInputWidget, self)._key_down(key, repeat)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
121 class MessagesWidget(GridLayout):
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
122 pass
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
126 message_input = properties.ObjectProperty()
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 78
diff changeset
127 messages_widget = properties.ObjectProperty()
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128
46
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
129 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
130 quick_chat.QuickChat.__init__(self, host, target, type_, nick, occupants, subject, profiles=profiles)
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 cagou_widget.CagouWidget.__init__(self)
67
5f7f72c2635f chat: shortened chat header
Goffi <goffi@goffi.org>
parents: 59
diff changeset
132 self.header_input.hint_text = u"{}".format(target)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
133 self.host.addListener('progressError', self.onProgressError, profiles)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
134 self.host.addListener('progressFinished', self.onProgressFinished, profiles)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
135 self._waiting_pids = {} # waiting progress ids
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 self.postInit()
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
137 # completion attribtues
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
138 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
139 self._hi_comp_last = 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
140 self._hi_comp_dropdown = 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
141 self._hi_comp_allowed = True
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 @classmethod
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def factory(cls, plugin_info, target, profiles):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 profiles = list(profiles)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 if len(profiles) > 1:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 raise NotImplementedError(u"Multi-profiles is not available yet for chat")
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 if target is None:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 target = G.host.profiles[profiles[0]].whoami
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, on_existing_widget=C.WIDGET_RECREATE, profiles=profiles)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151
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
152 ## 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
153
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
154 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
155 """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
156
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
157 @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
158 """
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
159 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
160 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
161 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
162 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
163
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
164 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
165 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
166 try:
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
167 if text.count(u'@') != 1 or text.count(u' '):
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
168 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
169 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
170 except 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
171 log.info(u"entered text is not a 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
172 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
173
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
174 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
175 # 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
176 if "conference" in [i[0] for i in disco[1]]:
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
177 G.host.bridge.mucJoin(unicode(jid_), "", "", self.profile, callback=self._mucJoinCb, errback=self._mucJoinEb)
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
178 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
179 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
180
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
181 def discoEb(failure):
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
182 log.warning(u"Disco failure, ignore this text: {}".format(failure))
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
183
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
184 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, errback=discoEb)
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
185
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
186 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
187 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
188 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
189 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
190 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
191 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
192
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
193 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
194 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
195 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
196 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
197 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
198 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
199 self._hi_comp_last = 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
200 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
201
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
202 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
203
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
204 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
205 # 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213
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
214 # 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
215 # 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
216 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
217
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
218 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
219 # 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
220 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
221
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
222 for jid_, jid_data in 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
223 nick = jid_data.get(u'nick', u'')
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
224 if text in jid_.bare or text in nick.lower():
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
225 btn = JidWidget(
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
226 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
227 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
228 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
229 nick = nick,
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
230 on_release=lambda dummy, txt=jid_.bare: self.onHeaderInputCompleted(wid, txt)
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
231 )
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
232 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
233 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
234 # 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
235 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
236 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
237 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
238 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
239 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
240 dropdown.remove_widget(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
241
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
242 dropdown.open(wid)
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
243 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
244
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 def messageDataConverter(self, idx, mess_id):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 return {"mess_data": self.messages[mess_id]}
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
247
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 def _onHistoryPrinted(self):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 """Refresh or scroll down the focus after the history is printed"""
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 # self.adapter.data = self.messages
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 for mess_data in self.messages.itervalues():
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 self.appendMessage(mess_data)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 super(Chat, self)._onHistoryPrinted()
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
254
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 def createMessage(self, message):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 self.appendMessage(message)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 def appendMessage(self, mess_data):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data))
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
260
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 def onSend(self, input_widget):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 G.host.messageSend(
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 self.target,
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 {'': input_widget.text}, # TODO: handle language
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT, # TODO: put this in QuickChat
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 profile_key=self.profile
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 )
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 input_widget.text = ''
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
269
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
270 def onProgressFinished(self, progress_id, metadata, profile):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
271 try:
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
272 callback, cleaning_cb = self._waiting_pids.pop(progress_id)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
273 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
274 return
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
275 if cleaning_cb is not None:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
276 cleaning_cb()
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
277 callback(metadata, profile)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
278
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
279 def onProgressError(self, progress_id, err_msg, profile):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
280 try:
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
281 dummy, cleaning_cb = self._waiting_pids[progress_id]
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
282 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
283 return
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
284 else:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
285 del self._waiting_pids[progress_id]
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
286 if cleaning_cb is not None:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
287 cleaning_cb()
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
288 # TODO: display message to user
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
289 log.warning(u"Can't transfer file: {}".format(err_msg))
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
290
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
291 def fileTransferDone(self, metadata, profile):
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
292 log.debug("file transfered: {}".format(metadata))
111
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
293 extra = {}
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
294
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
295 # FIXME: Q&D way of getting file type, upload plugins shouls give it
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
296 mime_type = mimetypes.guess_type(metadata['url'])[0]
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
297 if mime_type is not None:
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
298 if mime_type.split(u'/')[0] == 'image':
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
299 # we generate url ourselves, so this formatting is safe
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
300 extra['xhtml'] = u"<img src='{url}' />".format(**metadata)
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
301
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
302 G.host.messageSend(
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
303 self.target,
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
304 {'': metadata['url']},
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
305 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT,
111
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
306 extra = extra,
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
307 profile_key=profile
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
308 )
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
309
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
310 def fileTransferCb(self, progress_data, cleaning_cb):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
311 try:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
312 progress_id = progress_data['progress']
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
313 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
314 xmlui = progress_data['xmlui']
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
315 G.host.showUI(xmlui)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
316 else:
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
317 self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
318
98
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
319 def onTransferOK(self, file_path, cleaning_cb, transfer_type):
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
320 if transfer_type == C.TRANSFER_UPLOAD:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
321 G.host.bridge.fileUpload(
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
322 file_path,
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
323 "",
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
324 "",
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
325 {"ignore_tls_errors": C.BOOL_TRUE}, # FIXME: should not be the default
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
326 self.profile,
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
327 callback = lambda progress_data: self.fileTransferCb(progress_data, cleaning_cb)
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
328 )
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
329 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
330 if self.type == C.CHAT_GROUP:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
331 log.warning(u"P2P transfer is not possible for group chat")
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
332 # TODO: show an error dialog to user, or better hide the send button for MUC
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
333 else:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
334 jid_ = self.target
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
335 if not jid_.resource:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
336 jid_ = G.host.contact_lists[self.profile].getFullJid(jid_)
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
337 G.host.bridge.fileSend(jid_, file_path, "", "", profile=self.profile)
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
338 # 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
339 else:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
340 raise log.error(u"transfer of type {} are not handled".format(transfer_type))
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
341
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
342
46
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
343 def _mucJoinCb(self, joined_data):
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
344 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
345 self.host.mucRoomJoinedHandler(*joined_data[1:])
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
346 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
347 self.changeWidget(jid_)
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
348
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
349 def _mucJoinEb(self, failure):
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
350 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
351
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
352 def _onDelete(self):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
353 self.host.removeListener('progressFinished', self.onProgressFinished)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
354 self.host.removeListener('progressError', self.onProgressError)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
355 return super(Chat, self).onDelete()
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
356
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
357 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
358 if force==True:
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
359 return 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
360 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
361 # we don't keep duplicate widgets
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
362 return 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
363 return False
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
364
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
365
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 PLUGIN_INFO["factory"] = Chat.factory
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 quick_widgets.register(quick_chat.QuickChat, Chat)