Mercurial > libervia-desktop-kivy
annotate cagou/core/share_widget.py @ 342:89799148f894
core: use classes and factory to handle platform specific behaviours in a generic way
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 04 Jan 2020 16:24:57 +0100 |
parents | b0c9017a1db7 |
children | 38fd457b2158 |
rev | line source |
---|---|
336
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # Copyright (C) 2016-2019 Jérôme Poisson (goffi@goffi.org) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 from pathlib import Path |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core import log as logging |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from sat.core.i18n import _ |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from sat.tools.common import data_format |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 from sat_frontends.tools import jid |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from kivy.uix.boxlayout import BoxLayout |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 from kivy.uix.behaviors import ButtonBehavior |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from kivy.properties import StringProperty, DictProperty, ObjectProperty |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 from kivy.core.window import Window |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from kivy.metrics import dp |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 from .common import ContactItem |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 from .constants import Const as C |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 from cagou import G |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 log = logging.getLogger(__name__) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 PLUGIN_INFO = { |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 "name": _("share"), |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 "main": "Share", |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 "description": _("share a file"), |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 "icon_symbol": "share", |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 } |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 class ShareContactItem(ButtonBehavior, ContactItem): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 def filterDataCb(self, data): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 G.host.doAction('chat', jid.JID(self.jid), [self.profile]) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 chat_wid = G.host.selected_widget |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 if self.share_wid.type == 'text': |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 text = self.share_wid.data['text'] |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 chat_wid.message_input.text += text |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 else: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 path = self.share_wid.data['path'] |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 chat_wid.transferFile(path, cleaning_cb=data.get('cleaning_cb')) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.share_wid.close() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 def filterDataEb(self, failure_): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 G.host.addNote( |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 _("file filter error"), |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 _("Can't apply filter to file: {msg}").format(msg=failure_), |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 level=C.XMLUI_DATA_LVL_ERROR) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 def on_press(self): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 self.share_wid = G.host.getAncestorWidget(self, ShareWidget) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 self.share_wid.getFilteredData(self.filterDataCb, self.filterDataEb) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 class TextPreview(BoxLayout): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 """Widget previewing shared text""" |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 text = StringProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 class ImagePreview(BoxLayout): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 """Widget previewing shared image""" |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 path = StringProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 reduce_layout = ObjectProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 reduce_checkbox = ObjectProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 def _checkImageCb(self, report_raw): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 self.report = data_format.deserialise(report_raw) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 if self.report['too_large']: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 self.reduce_layout.opacity = 1 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 self.reduce_layout.height = self.reduce_layout.minimum_height + dp(10) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 self.reduce_layout.padding = [0, dp(5)] |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 def _checkImageEb(self, failure_): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 log.error(f"Can't check image: {failure_}") |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 def on_path(self, wid, path): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 G.host.bridge.imageCheck( |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 path, callback=self._checkImageCb, errback=self._checkImageEb) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 def resizeImage(self, data, callback, errback): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 def imageResizeCb(new_path): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 new_path = Path(new_path) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 log.debug(f"image {data['path']} resized at {new_path}") |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 data['path'] = new_path |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 data['cleaning_cb'] = lambda: new_path.unlink() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 callback(data) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 path = data['path'] |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 width, height = self.report['recommended_size'] |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 G.host.bridge.imageResize( |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 path, width, height, |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 callback=imageResizeCb, |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 errback=errback |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 ) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 def getFilter(self): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 if self.report['too_large'] and self.reduce_checkbox.active: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 return self.resizeImage |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 else: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 return lambda data, callback, errback: callback(data) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 class GenericPreview(BoxLayout): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 """Widget previewing shared image""" |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 path = StringProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 class ShareWidget(BoxLayout): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 media_type = StringProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 data = DictProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 preview_box = ObjectProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 layout = ObjectProperty() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 def __init__(self, **kwargs): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 super().__init__(**kwargs) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 G.host.addListener("contactsFilled", self.onContactsFilled) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 Window.bind(on_keyboard=self.key_input) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 def on_kv_post(self, wid): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 self.type, self.subtype = self.media_type.split('/') |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 if self.type == 'text': |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 self.preview_box.add_widget(TextPreview(text=self.data['text'])) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 elif self.type == 'image': |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 self.preview_box.add_widget(ImagePreview(path=self.data['path'])) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 else: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 self.preview_box.add_widget(GenericPreview(path=self.data['path'])) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 self.addRosterContacts() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 def close(self): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 G.host.closeUI() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 def on_parent(self, wid, parent): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 if parent is None: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 log.debug("removing contactsFilled listener") |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 G.host.removeListener("contactsFilled", self.onContactsFilled) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 def addRosterContacts(self): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 log.debug("starting addRosterContacts") |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 self.layout.clear_widgets() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 for profile in G.host.profiles: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 contact_list = G.host.contact_lists[profile] |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 for entity_jid in sorted(contact_list.roster): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 item = ShareContactItem( |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 jid=entity_jid, |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 data=contact_list.getItem(entity_jid), |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 profile=profile, |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 ) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 self.layout.add_widget(item) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 def onContactsFilled(self, profile): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 log.debug("onContactsFilled event received") |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 self.addRosterContacts() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 def getFilteredData(self, callback, errback): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 """Apply filter if suitable, and call callback with with modified data""" |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 try: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 getFilter = self.preview_box.children[0].getFilter |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 except AttributeError: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 callback(self.data) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 else: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 filter_ = getFilter() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 filter_(self.data, callback=callback, errback=errback) |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 def key_input(self, window, key, scancode, codepoint, modifier): |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 if key == 27: |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 self.close() |
b0c9017a1db7
core: added forgotten share_widget module
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 return True |