annotate src/cagou/plugins/plugin_wid_chat.py @ 108:953ddf817b8a

cagou widget: added onHeaderInputComplete method which is called when text is changed, and should be used for completion
author Goffi <goffi@goffi.org>
date Sun, 15 Jan 2017 21:21:25 +0100
parents 9909ed7a7a20
children 7631325e11f4
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
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from cagou import G
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 PLUGIN_INFO = {
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 "name": _(u"chat"),
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 "main": "Chat",
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 "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
42 "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
43 "icon_medium": u"{media}/icons/muchoslava/png/chat_new_44.png"
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 }
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
44
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
47 class MessAvatar(Image):
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
48 pass
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
49
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
50
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
51 class MessageWidget(GridLayout):
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 mess_data = properties.ObjectProperty()
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
53 mess_xhtml = properties.ObjectProperty()
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
54 mess_padding = (dp(5), dp(5))
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
55 avatar = properties.ObjectProperty()
103
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
56 delivery = properties.ObjectProperty()
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
57
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
58 def __init__(self, **kwargs):
105
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
59 # self must be registered in widgets before kv is parsed
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
60 kwargs['mess_data'].widgets.add(self)
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
61 super(MessageWidget, self).__init__(**kwargs)
105
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
62 avatar_path = self.mess_data.avatar
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
63 if avatar_path is not None:
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
64 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
65
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
66 @property
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
67 def chat(self):
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
68 """return parent Chat instance"""
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
69 return self.mess_data.parent
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 @property
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 def message(self):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 """Return currently displayed message"""
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 return self.mess_data.main_message
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
76 @property
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
77 def message_xhtml(self):
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
78 """Return currently displayed message"""
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
79 return self.mess_data.main_message_xhtml
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
80
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
81 def widthAdjust(self):
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 """this widget grows up with its children"""
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
83 pass
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
84 # parent = self.mess_xhtml.parent
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
85 # padding_x = self.mess_padding[0]
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
86 # text_width, text_height = self.mess_xhtml.texture_size
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
87 # if text_width > parent.width:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
88 # self.mess_xhtml.text_size = (parent.width - padding_x, None)
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
89 # self.text_max = text_width
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
90 # 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
91 # if text_width < self.text_max:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
92 # self.mess_xhtml.text_size = (None, None)
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
93 # else:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
94 # self.mess_xhtml.text_size = (parent.width - padding_x, None)
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95
54
514c187afebc chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents: 47
diff changeset
96 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
97 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
98 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
99 if 'status' in update_dict:
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
100 status = update_dict['status']
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
101 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
102
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
104 class MessageInputBox(BoxLayout):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
105 pass
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
106
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
107
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 class MessageInputWidget(TextInput):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 def _key_down(self, key, repeat=False):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 displayed_str, internal_str, internal_action, scale = key
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if internal_action == 'enter':
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 self.dispatch('on_text_validate')
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 else:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 super(MessageInputWidget, self)._key_down(key, repeat)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
118 class MessagesWidget(GridLayout):
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
119 pass
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
123 message_input = properties.ObjectProperty()
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 78
diff changeset
124 messages_widget = properties.ObjectProperty()
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125
46
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
126 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
127 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
128 cagou_widget.CagouWidget.__init__(self)
67
5f7f72c2635f chat: shortened chat header
Goffi <goffi@goffi.org>
parents: 59
diff changeset
129 self.header_input.hint_text = u"{}".format(target)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
130 self.host.addListener('progressError', self.onProgressError, profiles)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
131 self.host.addListener('progressFinished', self.onProgressFinished, profiles)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
132 self._waiting_pids = {} # waiting progress ids
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 self.postInit()
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 @classmethod
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 def factory(cls, plugin_info, target, profiles):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 profiles = list(profiles)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 if len(profiles) > 1:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 raise NotImplementedError(u"Multi-profiles is not available yet for chat")
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 if target is None:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 target = G.host.profiles[profiles[0]].whoami
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 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
143
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def messageDataConverter(self, idx, mess_id):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 return {"mess_data": self.messages[mess_id]}
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 def _onHistoryPrinted(self):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 """Refresh or scroll down the focus after the history is printed"""
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 # self.adapter.data = self.messages
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 for mess_data in self.messages.itervalues():
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 self.appendMessage(mess_data)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 super(Chat, self)._onHistoryPrinted()
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 def createMessage(self, message):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 self.appendMessage(message)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 def appendMessage(self, mess_data):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data))
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 def onSend(self, input_widget):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 G.host.messageSend(
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 self.target,
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 {'': input_widget.text}, # TODO: handle language
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 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
165 profile_key=self.profile
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 )
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 input_widget.text = ''
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
169 def onProgressFinished(self, progress_id, metadata, profile):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
170 try:
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
171 callback, cleaning_cb = self._waiting_pids.pop(progress_id)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
172 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
173 return
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
174 if cleaning_cb is not None:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
175 cleaning_cb()
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
176 callback(metadata, profile)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
177
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
178 def onProgressError(self, progress_id, err_msg, profile):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
179 try:
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
180 dummy, cleaning_cb = self._waiting_pids[progress_id]
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
181 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
182 return
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
183 else:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
184 del self._waiting_pids[progress_id]
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
185 if cleaning_cb is not None:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
186 cleaning_cb()
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
187 # TODO: display message to user
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
188 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
189
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
190 def fileTransferDone(self, metadata, profile):
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
191 log.debug("file transfered: {}".format(metadata))
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
192 G.host.messageSend(
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
193 self.target,
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
194 {'': metadata['url']},
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
195 mess_type = C.MESS_TYPE_GROUPCHAT if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT,
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
196 profile_key=profile
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
197 )
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
198
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
199 def fileTransferCb(self, progress_data, cleaning_cb):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
200 try:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
201 progress_id = progress_data['progress']
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
202 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
203 xmlui = progress_data['xmlui']
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
204 G.host.showUI(xmlui)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
205 else:
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
206 self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
207
98
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
208 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
209 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
210 G.host.bridge.fileUpload(
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
211 file_path,
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
212 "",
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
213 "",
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
214 {"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
215 self.profile,
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
216 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
217 )
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
218 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
219 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
220 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
221 # 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
222 else:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
223 jid_ = self.target
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
224 if not jid_.resource:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
225 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
226 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
227 # 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
228 else:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
229 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
230
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
231
46
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
232 def _mucJoinCb(self, joined_data):
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
233 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
234 self.host.mucRoomJoinedHandler(*joined_data[1:])
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
235 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
236 self.changeWidget(jid_)
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
237
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
238 def _mucJoinEb(self, failure):
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
239 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
240
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
241 def changeWidget(self, jid_):
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
242 """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
243
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
244 @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
245 """
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
246 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
247 factory = plugin_info['factory']
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
248 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
249 self.header_input.text = ''
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
250
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 def onHeaderInput(self):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 text = self.header_input.text.strip()
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 try:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 if text.count(u'@') != 1 or text.count(u' '):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 raise ValueError
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 jid_ = jid.JID(text)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 except ValueError:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 log.info(u"entered text is not a jid")
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 return
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 discoCb(disco):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 # TODO: check if plugin XEP-0045 is activated
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 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
264 G.host.bridge.mucJoin(unicode(jid_), "", "", self.profile, callback=self._mucJoinCb, errback=self._mucJoinEb)
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 else:
42
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
266 self.changeWidget(jid_)
22
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 def discoEb(failure):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 log.warning(u"Disco failure, ignore this text: {}".format(failure))
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
270
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb, errback=discoEb)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
272
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
273 def _onDelete(self):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
274 self.host.removeListener('progressFinished', self.onProgressFinished)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
275 self.host.removeListener('progressError', self.onProgressError)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
276 return super(Chat, self).onDelete()
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
277
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
278 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
279 if force==True:
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
280 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
281 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
282 # we don't keep duplicate widgets
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
283 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
284 return False
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
285
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
286
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 PLUGIN_INFO["factory"] = Chat.factory
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 quick_widgets.register(quick_chat.QuickChat, Chat)