annotate src/cagou/plugins/plugin_wid_chat.py @ 120:51e804dbf608

chat: fixed OTR calls: D-Bus bridge is converting jid.JID to unicode, but pb is not, resulting in a issue when calling OTR menus. This commit fixes it.
author Goffi <goffi@goffi.org>
date Tue, 31 Jan 2017 22:51:29 +0100
parents f0291755b07c
children c498178d8122
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
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
35 from cagou.core.common import IconButton, JidWidget
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
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
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
125 class EncryptionButton(IconButton):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
126
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
127 def __init__(self, chat, **kwargs):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
128 """
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
129 @param chat(Chat): Chat instance
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
130 """
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
131 # for now we do a simple ContextMenu as we have only OTR
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
132 self.otr_menu = OtrMenu(chat)
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
133 super(EncryptionButton, self).__init__(**kwargs)
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
134 self.bind(on_release=self.otr_menu.open)
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
135
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
136
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
137 class OtrMenu(DropDown):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
138
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
139 def __init__(self, chat, **kwargs):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
140 """
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
141 @param chat(Chat): Chat instance
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
142 """
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
143 self.chat = chat
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
144 super(OtrMenu, self).__init__(**kwargs)
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
145
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
146 def otr_start(self):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
147 self.dismiss()
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
148 G.host.launchMenu(
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
149 C.MENU_SINGLE,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
150 (u"otr", u"start/refresh"),
120
51e804dbf608 chat: fixed OTR calls:
Goffi <goffi@goffi.org>
parents: 117
diff changeset
151 {u'jid': unicode(self.chat.target)},
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
152 None,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
153 C.NO_SECURITY_LIMIT,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
154 self.chat.profile
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
155 )
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
156
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
157 def otr_end(self):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
158 self.dismiss()
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
159 G.host.launchMenu(
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
160 C.MENU_SINGLE,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
161 (u"otr", u"end session"),
120
51e804dbf608 chat: fixed OTR calls:
Goffi <goffi@goffi.org>
parents: 117
diff changeset
162 {u'jid': unicode(self.chat.target)},
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
163 None,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
164 C.NO_SECURITY_LIMIT,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
165 self.chat.profile
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
166 )
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
167
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
168 def otr_authenticate(self):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
169 self.dismiss()
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
170 G.host.launchMenu(
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
171 C.MENU_SINGLE,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
172 (u"otr", u"authenticate"),
120
51e804dbf608 chat: fixed OTR calls:
Goffi <goffi@goffi.org>
parents: 117
diff changeset
173 {u'jid': unicode(self.chat.target)},
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
174 None,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
175 C.NO_SECURITY_LIMIT,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
176 self.chat.profile
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
177 )
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
178
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
179
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
181 message_input = properties.ObjectProperty()
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 78
diff changeset
182 messages_widget = properties.ObjectProperty()
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183
46
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
184 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
185 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
186 cagou_widget.CagouWidget.__init__(self)
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
187 if type_ == C.CHAT_ONE2ONE:
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
188 self.headerInputAddExtra(EncryptionButton(self))
67
5f7f72c2635f chat: shortened chat header
Goffi <goffi@goffi.org>
parents: 59
diff changeset
189 self.header_input.hint_text = u"{}".format(target)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
190 self.host.addListener('progressError', self.onProgressError, profiles)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
191 self.host.addListener('progressFinished', self.onProgressFinished, profiles)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
192 self._waiting_pids = {} # waiting progress ids
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 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
194 # 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
195 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
196 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
197 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
198 self._hi_comp_allowed = True
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
199
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 @classmethod
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 def factory(cls, plugin_info, target, profiles):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 profiles = list(profiles)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 if len(profiles) > 1:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 raise NotImplementedError(u"Multi-profiles is not available yet for chat")
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 if target is None:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 target = G.host.profiles[profiles[0]].whoami
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 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
208
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
209 ## 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
210
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 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
212 """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
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 @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
215 """
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 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
217 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
218 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
219 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
220
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 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230
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 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
232 # 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
233 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
234 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
235 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
236 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
237
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 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
239 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
240
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 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
242
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 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
244 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
245 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
246 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
247 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
248 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
249
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
250 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
251 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
252 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
253 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
254 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
255 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
256 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
257 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
258
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
259 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
260
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
261 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
262 # 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
263 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
264 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
265 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
266 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
267 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
268 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
269 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
270
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
271 # 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
272 # 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
273 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
274
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
275 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
276 # 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
277 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
278
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
279 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
280 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
281 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
282 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
283 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
284 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
285 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
286 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
287 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
288 )
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
289 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
290 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
291 # 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
292 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
293 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
294 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
295 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
296 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
297 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
298
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
299 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
300 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
301
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 def messageDataConverter(self, idx, mess_id):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 return {"mess_data": self.messages[mess_id]}
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
304
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 def _onHistoryPrinted(self):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 """Refresh or scroll down the focus after the history is printed"""
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 # self.adapter.data = self.messages
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 for mess_data in self.messages.itervalues():
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 self.appendMessage(mess_data)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 super(Chat, self)._onHistoryPrinted()
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
311
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 def createMessage(self, message):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 self.appendMessage(message)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
314
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 def appendMessage(self, mess_data):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data))
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
317
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 def onSend(self, input_widget):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 G.host.messageSend(
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 self.target,
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 {'': input_widget.text}, # TODO: handle language
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 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
323 profile_key=self.profile
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 )
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 input_widget.text = ''
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
326
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
327 def onProgressFinished(self, progress_id, metadata, profile):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
328 try:
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
329 callback, cleaning_cb = self._waiting_pids.pop(progress_id)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
330 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
331 return
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
332 if cleaning_cb is not None:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
333 cleaning_cb()
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
334 callback(metadata, profile)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
335
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
336 def onProgressError(self, progress_id, err_msg, profile):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
337 try:
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
338 dummy, cleaning_cb = self._waiting_pids[progress_id]
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
339 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
340 return
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
341 else:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
342 del self._waiting_pids[progress_id]
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
343 if cleaning_cb is not None:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
344 cleaning_cb()
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
345 # TODO: display message to user
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
346 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
347
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
348 def fileTransferDone(self, metadata, profile):
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
349 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
350 extra = {}
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
351
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
352 # 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
353 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
354 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
355 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
356 # 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
357 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
358
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
359 G.host.messageSend(
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
360 self.target,
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
361 {'': metadata['url']},
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
362 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
363 extra = extra,
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
364 profile_key=profile
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
365 )
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
366
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
367 def fileTransferCb(self, progress_data, cleaning_cb):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
368 try:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
369 progress_id = progress_data['progress']
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
370 except KeyError:
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
371 xmlui = progress_data['xmlui']
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
372 G.host.showUI(xmlui)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
373 else:
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
374 self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
375
98
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
376 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
377 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
378 G.host.bridge.fileUpload(
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
379 file_path,
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
380 "",
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
381 "",
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
382 {"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
383 self.profile,
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
384 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
385 )
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
386 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
387 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
388 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
389 # 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
390 else:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
391 jid_ = self.target
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
392 if not jid_.resource:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
393 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
394 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
395 # 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
396 else:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
397 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
398
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
399
46
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
400 def _mucJoinCb(self, joined_data):
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
401 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
402 self.host.mucRoomJoinedHandler(*joined_data[1:])
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
403 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
404 self.changeWidget(jid_)
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
405
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
406 def _mucJoinEb(self, failure):
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
407 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
408
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
409 def _onDelete(self):
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
410 self.host.removeListener('progressFinished', self.onProgressFinished)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
411 self.host.removeListener('progressError', self.onProgressError)
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
412 return super(Chat, self).onDelete()
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
413
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
414 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
415 if force==True:
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
416 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
417 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
418 # we don't keep duplicate widgets
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
419 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
420 return False
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
421
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
422
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
423 PLUGIN_INFO["factory"] = Chat.factory
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
424 quick_widgets.register(quick_chat.QuickChat, Chat)