annotate cagou/plugins/plugin_wid_chat.py @ 277:f5302d57fb09

chat: use the new progress_cb and progress_eb methods of actionManager: thanks to those arguments, progress management code in chat is not needed anymore, simplifying the code.
author Goffi <goffi@goffi.org>
date Wed, 20 Mar 2019 09:29:44 +0100
parents a0835f0212d8
children 444ba439530f
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
126
cd99f70ea592 global file reorganisation:
Goffi <goffi@goffi.org>
parents: 122
diff changeset
5 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org)
22
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
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
21 from functools import partial
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
22 import mimetypes
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
23 import sys
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core import log as logging
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core.i18n import _
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from cagou.core.constants import Const as C
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
27 from kivy.uix.boxlayout import BoxLayout
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
28 from kivy.uix.gridlayout import GridLayout
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from kivy.uix.textinput import TextInput
185
ab3f5173ef5c chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents: 184
diff changeset
30 from kivy.metrics import sp, dp
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
31 from kivy.clock import Clock
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from kivy import properties
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from sat_frontends.quick_frontend import quick_widgets
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from sat_frontends.quick_frontend import quick_chat
106
9909ed7a7a20 moved SimpleXHTMLWidget to a dedicated module
Goffi <goffi@goffi.org>
parents: 105
diff changeset
35 from sat_frontends.tools import jid
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 from cagou.core import cagou_widget
242
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
37 from cagou.core import xmlui
106
9909ed7a7a20 moved SimpleXHTMLWidget to a dedicated module
Goffi <goffi@goffi.org>
parents: 105
diff changeset
38 from cagou.core.image import Image
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 186
diff changeset
39 from cagou.core.common import SymbolButton, JidButton
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
40 from kivy.uix.dropdown import DropDown
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
41 from kivy.core.window import Window
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 from cagou import G
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
44 log = logging.getLogger(__name__)
22
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 PLUGIN_INFO = {
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 "name": _(u"chat"),
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 "main": "Chat",
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 "description": _(u"instant messaging with one person or a group"),
180
0ddd2b20cc6b plugins chat, contact_list, settings, widget_selector: changed icons theme
Goffi <goffi@goffi.org>
parents: 156
diff changeset
50 "icon_symbol": u"chat",
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 }
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
244
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 242
diff changeset
53 # FIXME: OTR specific code is legacy, and only used nowadays for lock color
5bd94bc08f5c plugin chat: fixed OTR State filtering + removed some legacy code
Goffi <goffi@goffi.org>
parents: 242
diff changeset
54 # we can probably get rid of them.
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
55 OTR_STATE_UNTRUSTED = 'untrusted'
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
56 OTR_STATE_TRUSTED = 'trusted'
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
57 OTR_STATE_TRUST = (OTR_STATE_UNTRUSTED, OTR_STATE_TRUSTED)
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
58 OTR_STATE_UNENCRYPTED = 'unencrypted'
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
59 OTR_STATE_ENCRYPTED = 'encrypted'
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
60 OTR_STATE_ENCRYPTION = (OTR_STATE_UNENCRYPTED, OTR_STATE_ENCRYPTED)
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
61
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
62 SYMBOL_UNENCRYPTED = 'lock-open'
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
63 SYMBOL_ENCRYPTED = 'lock'
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
64 SYMBOL_ENCRYPTED_TRUSTED = 'lock-filled'
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
65 COLOR_UNENCRYPTED = (0.4, 0.4, 0.4, 1)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
66 COLOR_ENCRYPTED = (0.4, 0.4, 0.4, 1)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
67 COLOR_ENCRYPTED_TRUSTED = (0.29,0.87,0.0,1)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
68
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
44
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
70 class MessAvatar(Image):
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
71 pass
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
72
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
73
138
53fb221ad084 plugin chat: layout change:
Goffi <goffi@goffi.org>
parents: 135
diff changeset
74 class MessageWidget(BoxLayout):
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 mess_data = properties.ObjectProperty()
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
76 mess_xhtml = properties.ObjectProperty()
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
77 mess_padding = (dp(5), dp(5))
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
78 avatar = properties.ObjectProperty()
103
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
79 delivery = properties.ObjectProperty()
185
ab3f5173ef5c chat, simple XHTML: font size adjustement
Goffi <goffi@goffi.org>
parents: 184
diff changeset
80 font_size = properties.NumericProperty(sp(12))
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
81
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
82 def __init__(self, **kwargs):
105
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
83 # self must be registered in widgets before kv is parsed
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
84 kwargs['mess_data'].widgets.add(self)
47
abb81efef3bb chat: update avatar following quick frontend improvments
Goffi <goffi@goffi.org>
parents: 46
diff changeset
85 super(MessageWidget, self).__init__(**kwargs)
105
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
86 avatar_path = self.mess_data.avatar
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
87 if avatar_path is not None:
ce6ef88f2cff chat: avatar improvments:
Goffi <goffi@goffi.org>
parents: 103
diff changeset
88 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
89
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
90 @property
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
91 def chat(self):
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
92 """return parent Chat instance"""
7819e9efa250 chat: avatar and nick are now displayed, need further aesthetic improvments
Goffi <goffi@goffi.org>
parents: 42
diff changeset
93 return self.mess_data.parent
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 @property
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 def message(self):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 """Return currently displayed message"""
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 return self.mess_data.main_message
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
100 @property
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
101 def message_xhtml(self):
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
102 """Return currently displayed message"""
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
103 return self.mess_data.main_message_xhtml
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
104
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
105 def widthAdjust(self):
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 """this widget grows up with its children"""
57
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
107 pass
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
108 # parent = self.mess_xhtml.parent
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
109 # padding_x = self.mess_padding[0]
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
110 # text_width, text_height = self.mess_xhtml.texture_size
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
111 # if text_width > parent.width:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
112 # self.mess_xhtml.text_size = (parent.width - padding_x, None)
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
113 # self.text_max = text_width
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
114 # 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
115 # if text_width < self.text_max:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
116 # self.mess_xhtml.text_size = (None, None)
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
117 # else:
a51ea7874e43 chat: XHTML parsing first draft:
Goffi <goffi@goffi.org>
parents: 54
diff changeset
118 # self.mess_xhtml.text_size = (parent.width - padding_x, None)
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
54
514c187afebc chat: changed udpate to use dict instead of single key/value
Goffi <goffi@goffi.org>
parents: 47
diff changeset
120 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
121 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
122 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
123 if 'status' in update_dict:
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
124 status = update_dict['status']
c601e3d40342 chat: display delivery receipt (with a green check mark)
Goffi <goffi@goffi.org>
parents: 102
diff changeset
125 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
126
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
128 class SendButton(SymbolButton):
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
129 message_input_box = properties.ObjectProperty()
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
130
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
131
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
132 class MessageInputBox(BoxLayout):
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
133 message_input = properties.ObjectProperty()
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
134
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
135 def __init__(self, *args, **kwargs):
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
136 super(MessageInputBox, self).__init__(*args, **kwargs)
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
137 Clock.schedule_once(self.post_init, 0)
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
138
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
139 def post_init(self, *args):
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
140 if sys.platform == 'android':
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
141 self.add_widget(SendButton(message_input_box=self), 0)
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
142
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
143 def send_text(self):
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
144 self.message_input.send_text()
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
145
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
146
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 class MessageInputWidget(TextInput):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
149 def keyboard_on_key_down(self, window, keycode, text, modifiers):
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
150 # We don't send text when shift is pressed to be able to add line feeds
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
151 # (i.e. multi-lines messages). We don't send on Android either as the
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
152 # send button appears on this platform.
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
153 if (keycode[-1] == "enter"
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
154 and "shift" not in modifiers
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
155 and sys.platform != 'android'):
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
156 self.send_text()
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 else:
276
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
158 return super(MessageInputWidget, self).keyboard_on_key_down(
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
159 window, keycode, text, modifiers)
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
160
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
161 def send_text(self):
a0835f0212d8 chat: multi-lines input:
Goffi <goffi@goffi.org>
parents: 265
diff changeset
162 self.dispatch('on_text_validate')
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164
45
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
165 class MessagesWidget(GridLayout):
b0595a33465d chat: design improvments:
Goffi <goffi@goffi.org>
parents: 44
diff changeset
166 pass
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
169 class EncryptionMainButton(SymbolButton):
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
170
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
171 def __init__(self, chat, **kwargs):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
172 """
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
173 @param chat(Chat): Chat instance
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
174 """
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
175 self.chat = chat
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
176 # for now we do a simple ContextMenu as we have only OTR
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
177 self.encryption_menu = EncryptionMenu(chat)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
178 super(EncryptionMainButton, self).__init__(**kwargs)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
179 self.bind(on_release=self.encryption_menu.open)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
180
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
181 def selectAlgo(self, name):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
182 """Mark an encryption algorithm as selected.
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
183
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
184 This will also deselect all other button
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
185 @param name(unicode, None): encryption plugin name
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
186 None for plain text
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
187 """
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
188 buttons = self.encryption_menu.container.children
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
189 buttons[-1].selected = name is None
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
190 for button in buttons[:-1]:
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
191 button.selected = button.text == name
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
192
135
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
193 def getColor(self):
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
194 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED:
135
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
195 return (0.4, 0.4, 0.4, 1)
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
196 elif self.chat.otr_state_trust == OTR_STATE_TRUSTED:
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
197 return (0.29,0.87,0.0,1)
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
198 else:
135
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
199 return (0.4, 0.4, 0.4, 1)
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
200
135
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
201 def getSymbol(self):
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
202 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED:
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
203 return 'lock-open'
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
204 elif self.chat.otr_state_trust == OTR_STATE_TRUSTED:
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
205 return 'lock-filled'
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
206 else:
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
207 return 'lock'
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
208
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
209
242
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
210 class TrustManagementButton(SymbolButton):
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
211 pass
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
212
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
213
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
214 class EncryptionButton(BoxLayout):
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
215 selected = properties.BooleanProperty(False)
242
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
216 text = properties.StringProperty()
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
217 trust_button = properties.BooleanProperty(False)
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
218 best_width = properties.NumericProperty(0)
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
219
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
220 def __init__(self, **kwargs):
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
221 self.register_event_type('on_release')
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
222 self.register_event_type('on_trust_release')
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
223 super(EncryptionButton, self).__init__(**kwargs)
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
224 if self.trust_button:
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
225 self.add_widget(TrustManagementButton())
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
226
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
227 def on_release(self):
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
228 pass
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
229
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
230 def on_trust_release(self):
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
231 pass
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
232
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
234 class EncryptionMenu(DropDown):
242
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
235 # best with to display all algorithms buttons + trust buttons
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
236 best_width = properties.NumericProperty(0)
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
237
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
238 def __init__(self, chat, **kwargs):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
239 """
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
240 @param chat(Chat): Chat instance
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
241 """
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
242 self.chat = chat
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
243 super(EncryptionMenu, self).__init__(**kwargs)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
244 btn = EncryptionButton(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
245 text=_(u"unencrypted (plain text)"),
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
246 on_release=self.unencrypted,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
247 selected=True,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
248 bold=False,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
249 )
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
250 self.add_widget(btn)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
251 for plugin in G.host.encryption_plugins:
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
252 btn = EncryptionButton(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
253 text=plugin[u'name'],
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
254 on_release=partial(self.startEncryption, plugin=plugin),
242
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
255 on_trust_release=partial(self.getTrustUI, plugin=plugin),
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
256 trust_button=True,
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
257 )
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
258 self.add_widget(btn)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
259 log.info("added encryption: {}".format(plugin['name']))
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
260
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
261 def messageEncryptionStopCb(self):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
262 log.info(_(u"Session with {destinee} is now in plain text").format(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
263 destinee = self.chat.target))
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
264
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
265 def messageEncryptionStopEb(self, failure_):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
266 msg = _(u"Error while stopping encryption with {destinee}: {reason}").format(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
267 destinee = self.chat.target,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
268 reason = failure_)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
269 log.warning(msg)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
270 G.host.addNote(_(u"encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
271
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
272 def unencrypted(self, button):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
273 self.dismiss()
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
274 G.host.bridge.messageEncryptionStop(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
275 unicode(self.chat.target),
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
276 self.chat.profile,
242
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
277 callback=self.messageEncryptionStopCb,
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
278 errback=self.messageEncryptionStopEb)
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
279
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
280 def messageEncryptionStartCb(self, plugin):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
281 log.info(_(u"Session with {destinee} is now encrypted with {encr_name}").format(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
282 destinee = self.chat.target,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
283 encr_name = plugin['name']))
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
284
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
285 def messageEncryptionStartEb(self, failure_):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
286 msg = _(u"Session can't be encrypted with {destinee}: {reason}").format(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
287 destinee = self.chat.target,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
288 reason = failure_)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
289 log.warning(msg)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
290 G.host.addNote(_(u"encryption problem"), msg, C.XMLUI_DATA_LVL_ERROR)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
291
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
292 def startEncryption(self, button, plugin):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
293 """Request encryption with given plugin for this session
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
294
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
295 @param button(EncryptionButton): button which has been pressed
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
296 @param plugin(dict): plugin data
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
297 """
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
298 self.dismiss()
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
299 G.host.bridge.messageEncryptionStart(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
300 unicode(self.chat.target),
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
301 plugin['namespace'],
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
302 True,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
303 self.chat.profile,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
304 callback=partial(self.messageEncryptionStartCb, plugin=plugin),
242
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
305 errback=self.messageEncryptionStartEb)
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
306
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
307 def encryptionTrustUIGetCb(self, xmlui_raw):
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
308 xml_ui = xmlui.create(
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
309 G.host, xmlui_raw, profile=self.chat.profile)
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
310 xml_ui.show()
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
311
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
312 def encryptionTrustUIGetEb(self, failure_):
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
313 msg = _(u"Trust manager interface can't be retrieved: {reason}").format(
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
314 reason = failure_)
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
315 log.warning(msg)
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
316 G.host.addNote(_(u"encryption trust management problem"), msg,
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
317 C.XMLUI_DATA_LVL_ERROR)
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
318
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
319 def getTrustUI(self, button, plugin):
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
320 """Request and display trust management UI
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
321
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
322 @param button(EncryptionButton): button which has been pressed
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
323 @param plugin(dict): plugin data
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
324 """
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
325 self.dismiss()
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
326 G.host.bridge.encryptionTrustUIGet(
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
327 unicode(self.chat.target),
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
328 plugin['namespace'],
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
329 self.chat.profile,
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
330 callback=self.encryptionTrustUIGetCb,
c2503168fab7 plugin chat (encryption): added a button to display trust management UI.
Goffi <goffi@goffi.org>
parents: 233
diff changeset
331 errback=self.encryptionTrustUIGetEb)
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
332
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
333 def otr_start(self):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
334 self.dismiss()
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
335 G.host.launchMenu(
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
336 C.MENU_SINGLE,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
337 (u"otr", u"start/refresh"),
120
51e804dbf608 chat: fixed OTR calls:
Goffi <goffi@goffi.org>
parents: 117
diff changeset
338 {u'jid': unicode(self.chat.target)},
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
339 None,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
340 C.NO_SECURITY_LIMIT,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
341 self.chat.profile
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
342 )
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
343
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
344 def otr_end(self):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
345 self.dismiss()
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
346 G.host.launchMenu(
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
347 C.MENU_SINGLE,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
348 (u"otr", u"end session"),
120
51e804dbf608 chat: fixed OTR calls:
Goffi <goffi@goffi.org>
parents: 117
diff changeset
349 {u'jid': unicode(self.chat.target)},
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
350 None,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
351 C.NO_SECURITY_LIMIT,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
352 self.chat.profile
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
353 )
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
354
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
355 def otr_authenticate(self):
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
356 self.dismiss()
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
357 G.host.launchMenu(
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
358 C.MENU_SINGLE,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
359 (u"otr", u"authenticate"),
120
51e804dbf608 chat: fixed OTR calls:
Goffi <goffi@goffi.org>
parents: 117
diff changeset
360 {u'jid': unicode(self.chat.target)},
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
361 None,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
362 C.NO_SECURITY_LIMIT,
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
363 self.chat.profile
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
364 )
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
365
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
366
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget):
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
368 message_input = properties.ObjectProperty()
86
c711be670ecd core, chat: upload plugin system:
Goffi <goffi@goffi.org>
parents: 78
diff changeset
369 messages_widget = properties.ObjectProperty()
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
370
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
371 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
372 subject=None, profiles=None):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
373 quick_chat.QuickChat.__init__(
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
374 self, host, target, type_, nick, occupants, subject, profiles=profiles)
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
375 self.otr_state_encryption = OTR_STATE_UNENCRYPTED
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
376 self.otr_state_trust = OTR_STATE_UNTRUSTED
225
a3162b29cda1 plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents: 193
diff changeset
377 # completion attributes
a3162b29cda1 plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents: 193
diff changeset
378 self._hi_comp_data = None
a3162b29cda1 plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents: 193
diff changeset
379 self._hi_comp_last = None
a3162b29cda1 plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents: 193
diff changeset
380 self._hi_comp_dropdown = DropDown()
a3162b29cda1 plugin chat: fixed AttributeError when message is receved and a corresponding ChatWidget is not created yet
Goffi <goffi@goffi.org>
parents: 193
diff changeset
381 self._hi_comp_allowed = True
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 cagou_widget.CagouWidget.__init__(self)
117
f0291755b07c chat: OTR integration first draft:
Goffi <goffi@goffi.org>
parents: 111
diff changeset
383 if type_ == C.CHAT_ONE2ONE:
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
384 self.encryption_btn = EncryptionMainButton(self)
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
385 self.headerInputAddExtra(self.encryption_btn)
67
5f7f72c2635f chat: shortened chat header
Goffi <goffi@goffi.org>
parents: 59
diff changeset
386 self.header_input.hint_text = u"{}".format(target)
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 self.postInit()
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
388
156
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
389 def __unicode__(self):
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
390 return u"Chat({})".format(self.target)
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
391
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
392 def __str__(self):
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
393 return self.__unicode__().encode('utf-8')
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
394
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
395 def __repr__(self):
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
396 return self.__str__()
826e7b17a19b chat: added __unicode__ and __str__
Goffi <goffi@goffi.org>
parents: 145
diff changeset
397
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
398 @classmethod
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 def factory(cls, plugin_info, target, profiles):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
400 profiles = list(profiles)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
401 if len(profiles) > 1:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
402 raise NotImplementedError(u"Multi-profiles is not available yet for chat")
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
403 if target is None:
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
404 target = G.host.profiles[profiles[0]].whoami
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
405 return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None,
260
145c29b5f2b5 core: improved getOrClone + use in chat and widgets_handler:
Goffi <goffi@goffi.org>
parents: 250
diff changeset
406 on_existing_widget=G.host.getOrClone,
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
407 profiles=profiles)
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
408
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
409 ## 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
410
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
411 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
412 """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
413
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
414 @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
415 """
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
416 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
417 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
418 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
419 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
420
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
421 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
422 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
423 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
424 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
425 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
426 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
427 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
428 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
429 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
430
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
431 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
432 # 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
433 if "conference" in [i[0] for i in disco[1]]:
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
434 G.host.bridge.mucJoin(unicode(jid_), "", "", self.profile,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
435 callback=self._mucJoinCb, errback=self._mucJoinEb)
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
436 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
437 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
438
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
439 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
440 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
441
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
442 G.host.bridge.discoInfos(jid_.domain, self.profile, callback=discoCb,
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
443 errback=discoEb)
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
444
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
445 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
446 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
447 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
448 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
449 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
450 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
451
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
452 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
453 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
454 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
455 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
456 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
457 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
458 self._hi_comp_last = None
144
ae58f84fe4e6 plugin chat: fixed dropdown:
Goffi <goffi@goffi.org>
parents: 138
diff changeset
459 self._hi_comp_dropdown.dismiss()
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
460 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
461
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
462 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
463
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
464 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
465 # 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
466 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
467 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
468 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
469 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
470 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
471 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
472 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
473
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
474 # 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
475 # 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
476 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
477
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
478 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
479 # 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
480 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
481
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
482 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
483 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
484 if text in jid_.bare or text in nick.lower():
193
284cb5c467b0 core (common): split JidItem in 3 classes:
Goffi <goffi@goffi.org>
parents: 186
diff changeset
485 btn = JidButton(
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
486 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
487 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
488 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
489 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
490 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
491 )
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
492 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
493 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
494 # 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
495 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
496 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
497 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
498 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
499 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
500 dropdown.remove_widget(c)
144
ae58f84fe4e6 plugin chat: fixed dropdown:
Goffi <goffi@goffi.org>
parents: 138
diff changeset
501 if dropdown.attach_to is None:
ae58f84fe4e6 plugin chat: fixed dropdown:
Goffi <goffi@goffi.org>
parents: 138
diff changeset
502 dropdown.open(wid)
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
503 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
504
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
505 def messageDataConverter(self, idx, mess_id):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
506 return {"mess_data": self.messages[mess_id]}
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
507
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
508 def _onHistoryPrinted(self):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
509 """Refresh or scroll down the focus after the history is printed"""
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
510 # self.adapter.data = self.messages
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
511 for mess_data in self.messages.itervalues():
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
512 self.appendMessage(mess_data)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
513 super(Chat, self)._onHistoryPrinted()
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
514
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
515 def createMessage(self, message):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
516 self.appendMessage(message)
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
517
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
518 def appendMessage(self, mess_data):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
519 self.messages_widget.add_widget(MessageWidget(mess_data=mess_data))
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
520 self.notify(mess_data)
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
521
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
522 def _get_notif_msg(self, mess_data):
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
523 return _(u"{nick}: {message}").format(
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
524 nick=mess_data.nick,
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
525 message=mess_data.main_message)
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
526
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
527 def notify(self, mess_data):
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
528 """Notify user when suitable
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
529
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
530 For one2one chat, notification will happen when window has not focus
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
531 or when one2one chat is not visible. A note is also there when widget
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
532 is not visible.
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
533 For group chat, note will be added on mention, with a desktop notification if
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
534 window has not focus.
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
535 """
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
536 visible_clones = [w for w in G.host.getVisibleList(self.__class__)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
537 if w.target == self.target]
186
a826c70beda2 chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents: 185
diff changeset
538 if len(visible_clones) > 1 and visible_clones.index(self) > 0:
a826c70beda2 chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents: 185
diff changeset
539 # to avoid multiple notifications in case of multiple cloned widgets
a826c70beda2 chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents: 185
diff changeset
540 # we only handle first clone
a826c70beda2 chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents: 185
diff changeset
541 return
a826c70beda2 chat: avoid multiple notifications when there are several cloned chats (i.e. with same target)
Goffi <goffi@goffi.org>
parents: 185
diff changeset
542 is_visible = bool(visible_clones)
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
543 if self.type == C.CHAT_ONE2ONE:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
544 if (not Window.focus or not is_visible) and not mess_data.history:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
545 notif_msg = self._get_notif_msg(mess_data)
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
546 G.host.desktop_notif(
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
547 notif_msg,
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
548 title=_(u"private message"))
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
549 if not is_visible:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
550 G.host.addNote(
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
551 _(u"private message"),
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
552 notif_msg,
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
553 symbol = u"chat",
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
554 action = {
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
555 "action": u'chat',
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
556 "target": self.target,
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
557 "profiles": self.profiles}
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
558 )
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
559 else:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
560 if mess_data.mention and not mess_data.history:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
561 notif_msg = self._get_notif_msg(mess_data)
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
562 G.host.addNote(
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
563 _(u"mention"),
250
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
564 notif_msg,
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
565 symbol = u"chat",
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
566 action = {
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
567 "action": u'chat',
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
568 "target": self.target,
ff1efdeff53f core: notifs can now have a custom icon and be clickable:
Goffi <goffi@goffi.org>
parents: 244
diff changeset
569 "profiles": self.profiles}
184
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
570 )
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
571 if not Window.focus:
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
572 G.host.desktop_notif(
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
573 notif_msg,
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
574 title=_(u"mention ({room_jid})").format(
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
575 room_jid=self.target)
c63922860f80 chat: show desktop notification and/or note when suitable
Goffi <goffi@goffi.org>
parents: 180
diff changeset
576 )
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
577
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
578 def onSend(self, input_widget):
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
579 G.host.messageSend(
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
580 self.target,
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
581 {'': input_widget.text}, # TODO: handle language
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
582 mess_type = (C.MESS_TYPE_GROUPCHAT
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
583 if self.type == C.CHAT_GROUP else C.MESS_TYPE_CHAT), # TODO: put this in QuickChat
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
584 profile_key=self.profile
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
585 )
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
586 input_widget.text = ''
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
587
277
f5302d57fb09 chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
588 def fileTransferEb(self, err_msg, cleaning_cb, profile):
88
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
589 if cleaning_cb is not None:
3dc526bb4a5a upload: plugin android gallery, first draft:
Goffi <goffi@goffi.org>
parents: 86
diff changeset
590 cleaning_cb()
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
591 # TODO: display message to user
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
592 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
593
277
f5302d57fb09 chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
594 def fileTransferCb(self, metadata, cleaning_cb, profile):
97
5d2289127bb7 menu (upload): better menu using dedicated widget:
Goffi <goffi@goffi.org>
parents: 90
diff changeset
595 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
596 extra = {}
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
597
c3952922ca56 chat: uploaded images are now sent with XHTML, so they are shown inline
Goffi <goffi@goffi.org>
parents: 109
diff changeset
598 # 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
599 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
600 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
601 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
602 # 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
603 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
604
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
605 G.host.messageSend(
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
606 self.target,
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
607 {'': metadata['url']},
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
608 mess_type = (C.MESS_TYPE_GROUPCHAT
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
609 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
610 extra = extra,
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
611 profile_key=profile
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
612 )
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
613
98
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
614 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
615 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
616 G.host.bridge.fileUpload(
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
617 file_path,
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
618 "",
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
619 "",
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
620 {"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
621 self.profile,
277
f5302d57fb09 chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
622 callback = partial(
f5302d57fb09 chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
623 G.host.actionManager,
f5302d57fb09 chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
624 progress_cb = partial(self.fileTransferCb, cleaning_cb=cleaning_cb),
f5302d57fb09 chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
625 progress_eb = partial(self.fileTransferEb, cleaning_cb=cleaning_cb), )
f5302d57fb09 chat: use the new progress_cb and progress_eb methods of actionManager:
Goffi <goffi@goffi.org>
parents: 276
diff changeset
626 )
98
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
627 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
628 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
629 log.warning(u"P2P transfer is not possible for group chat")
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
630 # TODO: show an error dialog to user, or better hide the send button for
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
631 # MUC
98
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
632 else:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
633 jid_ = self.target
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
634 if not jid_.resource:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
635 jid_ = G.host.contact_lists[self.profile].getFullJid(jid_)
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
636 G.host.bridge.fileSend(unicode(jid_), file_path, "", "",
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
637 profile=self.profile)
98
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
638 # 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
639 else:
4d8c122b86a6 menu (upload): send transfer (i.e. P2P transfer) is now working
Goffi <goffi@goffi.org>
parents: 97
diff changeset
640 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
641
233
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
642 def messageEncryptionStarted(self, plugin_data):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
643 quick_chat.QuickChat.messageEncryptionStarted(self, plugin_data)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
644 self.encryption_btn.symbol = SYMBOL_ENCRYPTED
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
645 self.encryption_btn.color = COLOR_ENCRYPTED
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
646 self.encryption_btn.selectAlgo(plugin_data[u'name'])
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
647
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
648 def messageEncryptionStopped(self, plugin_data):
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
649 quick_chat.QuickChat.messageEncryptionStopped(self, plugin_data)
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
650 self.encryption_btn.symbol = SYMBOL_UNENCRYPTED
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
651 self.encryption_btn.color = COLOR_UNENCRYPTED
ba8f3a4a5ac7 plugin chat: e2e encryption improvments:
Goffi <goffi@goffi.org>
parents: 225
diff changeset
652 self.encryption_btn.selectAlgo(None)
78
46d962910801 chat: file upload first draft:
Goffi <goffi@goffi.org>
parents: 68
diff changeset
653
46
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
654 def _mucJoinCb(self, joined_data):
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
655 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
656 self.host.mucRoomJoinedHandler(*joined_data[1:])
d6a63942d5ad chat: fixed MUC joining following changes in backend
Goffi <goffi@goffi.org>
parents: 45
diff changeset
657 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
658 self.changeWidget(jid_)
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
659
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
660 def _mucJoinEb(self, failure):
286865bc013a chat: joining MUC using header input is now working:
Goffi <goffi@goffi.org>
parents: 41
diff changeset
661 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
662
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
663 def onOTRState(self, state, dest_jid, profile):
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
664 assert profile in self.profiles
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
665 if state in OTR_STATE_ENCRYPTION:
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
666 self.otr_state_encryption = state
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
667 elif state in OTR_STATE_TRUST:
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
668 self.otr_state_trust = state
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
669 else:
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
670 log.error(_(u"Unknown OTR state received: {}".format(state)))
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
671 return
135
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
672 self.encryption_btn.symbol = self.encryption_btn.getSymbol()
091e288838e1 plugin chat: use new Symbol widget to display encryption button
Goffi <goffi@goffi.org>
parents: 126
diff changeset
673 self.encryption_btn.color = self.encryption_btn.getColor()
122
dcd6fbb3f010 chat: handle new OTR state signal and change encryption icon consequently
Goffi <goffi@goffi.org>
parents: 121
diff changeset
674
265
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 261
diff changeset
675 def onVisible(self):
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 261
diff changeset
676 if not self.sync:
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 261
diff changeset
677 self.resync()
805c4103dac5 core: resync widgets only when they are visible:
Goffi <goffi@goffi.org>
parents: 261
diff changeset
678
261
a579eda31f4f chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents: 260
diff changeset
679 def onDelete(self):
a579eda31f4f chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents: 260
diff changeset
680 # we always keep one widget, so it's available when swiping
a579eda31f4f chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents: 260
diff changeset
681 # TODO: delete all widgets when chat is closed
a579eda31f4f chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents: 260
diff changeset
682 nb_instances = sum(1 for _ in self.host.widgets.getWidgetInstances(self))
a579eda31f4f chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents: 260
diff changeset
683 if nb_instances > 1:
a579eda31f4f chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents: 260
diff changeset
684 return super(Chat, self).onDelete()
a579eda31f4f chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents: 260
diff changeset
685 else:
a579eda31f4f chat: don't use "force" argument anymore
Goffi <goffi@goffi.org>
parents: 260
diff changeset
686 return False
22
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
687
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
688
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
689 PLUGIN_INFO["factory"] = Chat.factory
74117b733bac plugin chat: first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
690 quick_widgets.register(quick_chat.QuickChat, Chat)