Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_file_sharing.py @ 379:1da3c379205b
fixed shebangs
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 29 Jan 2020 10:04:35 +0100 |
parents | 4d660b252487 |
children | a90f26e89a4a |
rev | line source |
---|---|
379 | 1 #!/usr/bin/env python3 |
192 | 2 |
3 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
378 | 4 # Copyright (C) 2016-2020 Jérôme Poisson (goffi@goffi.org) |
192 | 5 |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 | |
20 from sat.core import log as logging | |
21 from sat.core import exceptions | |
22 log = logging.getLogger(__name__) | |
23 from sat.core.i18n import _ | |
24 from sat.tools.common import files_utils | |
25 from sat_frontends.quick_frontend import quick_widgets | |
26 from sat_frontends.tools import jid | |
27 from cagou.core.constants import Const as C | |
28 from cagou.core import cagou_widget | |
237
059c5b39032d
plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
222
diff
changeset
|
29 from cagou.core.menu import EntitiesSelectorMenu, TouchMenuBehaviour |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
30 from cagou.core.utils import FilterBehavior |
237
059c5b39032d
plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
222
diff
changeset
|
31 from cagou.core.common_widgets import (Identities, ItemWidget, DeviceWidget, |
059c5b39032d
plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
222
diff
changeset
|
32 CategorySeparator) |
192 | 33 from cagou import G |
34 from kivy import properties | |
35 from kivy.uix.label import Label | |
36 from kivy.uix.button import Button | |
205
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
37 from kivy import utils as kivy_utils |
192 | 38 from functools import partial |
39 import os.path | |
40 import json | |
41 | |
42 | |
43 PLUGIN_INFO = { | |
312 | 44 "name": _("file sharing"), |
192 | 45 "main": "FileSharing", |
312 | 46 "description": _("share/transfer files between devices"), |
47 "icon_symbol": "exchange", | |
192 | 48 } |
312 | 49 MODE_VIEW = "view" |
50 MODE_LOCAL = "local" | |
51 SELECT_INSTRUCTIONS = _("Please select entities to share with") | |
192 | 52 |
205
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
53 if kivy_utils.platform == "android": |
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
54 from jnius import autoclass |
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
55 Environment = autoclass("android.os.Environment") |
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
56 base_dir = Environment.getExternalStorageDirectory().getAbsolutePath() |
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
57 def expanduser(path): |
312 | 58 if path == '~' or path.startswith('~/'): |
59 return path.replace('~', base_dir, 1) | |
205
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
60 return path |
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
61 else: |
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
62 expanduser = os.path.expanduser |
192 | 63 |
64 | |
65 class ModeBtn(Button): | |
66 | |
67 def __init__(self, parent, **kwargs): | |
68 super(ModeBtn, self).__init__(**kwargs) | |
69 parent.bind(mode=self.on_mode) | |
70 self.on_mode(parent, parent.mode) | |
71 | |
72 def on_mode(self, parent, new_mode): | |
73 if new_mode == MODE_VIEW: | |
312 | 74 self.text = _("view shared files") |
192 | 75 elif new_mode == MODE_LOCAL: |
312 | 76 self.text = _("share local files") |
192 | 77 else: |
312 | 78 exceptions.InternalError("Unknown mode: {mode}".format(mode=new_mode)) |
192 | 79 |
80 | |
81 class PathWidget(ItemWidget): | |
82 | |
222 | 83 def __init__(self, filepath, main_wid, **kw): |
192 | 84 name = os.path.basename(filepath) |
85 self.filepath = os.path.normpath(filepath) | |
312 | 86 if self.filepath == '.': |
87 self.filepath = '' | |
222 | 88 super(PathWidget, self).__init__(name=name, main_wid=main_wid, **kw) |
192 | 89 |
90 @property | |
91 def is_dir(self): | |
92 raise NotImplementedError | |
93 | |
94 def do_item_action(self, touch): | |
95 if self.is_dir: | |
222 | 96 self.main_wid.current_dir = self.filepath |
192 | 97 |
98 def open_menu(self, touch, dt): | |
312 | 99 log.debug(_("opening menu for {path}").format(path=self.filepath)) |
192 | 100 super(PathWidget, self).open_menu(touch, dt) |
101 | |
102 | |
103 class LocalPathWidget(PathWidget): | |
104 | |
105 @property | |
106 def is_dir(self): | |
107 return os.path.isdir(self.filepath) | |
108 | |
109 def getMenuChoices(self): | |
110 choices = [] | |
111 if self.shared: | |
312 | 112 choices.append(dict(text=_('unshare'), |
192 | 113 index=len(choices)+1, |
222 | 114 callback=self.main_wid.unshare)) |
192 | 115 else: |
312 | 116 choices.append(dict(text=_('share'), |
192 | 117 index=len(choices)+1, |
222 | 118 callback=self.main_wid.share)) |
192 | 119 return choices |
120 | |
121 | |
122 class RemotePathWidget(PathWidget): | |
123 | |
222 | 124 def __init__(self, main_wid, filepath, type_, **kw): |
192 | 125 self.type_ = type_ |
222 | 126 super(RemotePathWidget, self).__init__(filepath, main_wid=main_wid, **kw) |
192 | 127 |
128 @property | |
129 def is_dir(self): | |
130 return self.type_ == C.FILE_TYPE_DIRECTORY | |
131 | |
132 def do_item_action(self, touch): | |
133 if self.is_dir: | |
312 | 134 if self.filepath == '..': |
135 self.main_wid.remote_entity = '' | |
192 | 136 else: |
137 super(RemotePathWidget, self).do_item_action(touch) | |
138 else: | |
222 | 139 self.main_wid.request_item(self) |
192 | 140 return True |
141 | |
237
059c5b39032d
plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
222
diff
changeset
|
142 class SharingDeviceWidget(DeviceWidget): |
206
890b48e41998
plugin file sharing: use appropriate symbol when discovering devices
Goffi <goffi@goffi.org>
parents:
205
diff
changeset
|
143 |
192 | 144 def do_item_action(self, touch): |
222 | 145 self.main_wid.remote_entity = self.entity_jid |
312 | 146 self.main_wid.remote_dir = '' |
192 | 147 |
148 | |
222 | 149 class FileSharing(quick_widgets.QuickWidget, cagou_widget.CagouWidget, FilterBehavior, |
150 TouchMenuBehaviour): | |
192 | 151 SINGLE=False |
152 layout = properties.ObjectProperty() | |
254 | 153 mode = properties.OptionProperty(MODE_VIEW, options=[MODE_VIEW, MODE_LOCAL]) |
312 | 154 local_dir = properties.StringProperty(expanduser('~')) |
155 remote_dir = properties.StringProperty('') | |
156 remote_entity = properties.StringProperty('') | |
192 | 157 shared_paths = properties.ListProperty() |
158 signals_registered = False | |
159 | |
160 def __init__(self, host, target, profiles): | |
161 quick_widgets.QuickWidget.__init__(self, host, target, profiles) | |
162 cagou_widget.CagouWidget.__init__(self) | |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
163 FilterBehavior.__init__(self) |
222 | 164 TouchMenuBehaviour.__init__(self) |
192 | 165 self.mode_btn = ModeBtn(self) |
166 self.mode_btn.bind(on_release=self.change_mode) | |
167 self.headerInputAddExtra(self.mode_btn) | |
168 self.bind(local_dir=self.update_view, | |
169 remote_dir=self.update_view, | |
170 remote_entity=self.update_view) | |
171 self.update_view() | |
172 if not FileSharing.signals_registered: | |
173 # FIXME: we use this hack (registering the signal for the whole class) now | |
174 # as there is currently no unregisterSignal available in bridges | |
217
286f14127f61
plugin file sharing: started to limit line to 90 chars as a test
Goffi <goffi@goffi.org>
parents:
214
diff
changeset
|
175 G.host.registerSignal("FISSharedPathNew", |
286f14127f61
plugin file sharing: started to limit line to 90 chars as a test
Goffi <goffi@goffi.org>
parents:
214
diff
changeset
|
176 handler=FileSharing.shared_path_new, |
286f14127f61
plugin file sharing: started to limit line to 90 chars as a test
Goffi <goffi@goffi.org>
parents:
214
diff
changeset
|
177 iface="plugin") |
286f14127f61
plugin file sharing: started to limit line to 90 chars as a test
Goffi <goffi@goffi.org>
parents:
214
diff
changeset
|
178 G.host.registerSignal("FISSharedPathRemoved", |
286f14127f61
plugin file sharing: started to limit line to 90 chars as a test
Goffi <goffi@goffi.org>
parents:
214
diff
changeset
|
179 handler=FileSharing.shared_path_removed, |
286f14127f61
plugin file sharing: started to limit line to 90 chars as a test
Goffi <goffi@goffi.org>
parents:
214
diff
changeset
|
180 iface="plugin") |
192 | 181 FileSharing.signals_registered = True |
182 G.host.bridge.FISLocalSharesGet(self.profile, | |
183 callback=self.fill_paths, | |
184 errback=G.host.errback) | |
185 | |
186 @property | |
187 def current_dir(self): | |
188 return self.local_dir if self.mode == MODE_LOCAL else self.remote_dir | |
189 | |
190 @current_dir.setter | |
191 def current_dir(self, new_dir): | |
192 if self.mode == MODE_LOCAL: | |
193 self.local_dir = new_dir | |
194 else: | |
195 self.remote_dir = new_dir | |
196 | |
197 def fill_paths(self, shared_paths): | |
198 self.shared_paths.extend(shared_paths) | |
199 | |
200 def change_mode(self, mode_btn): | |
201 self.clear_menu() | |
202 opt = self.__class__.mode.options | |
203 new_idx = (opt.index(self.mode)+1) % len(opt) | |
204 self.mode = opt[new_idx] | |
205 | |
206 def on_mode(self, instance, new_mode): | |
207 self.update_view(None, self.local_dir) | |
208 | |
194
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
209 def onHeaderInput(self): |
312 | 210 if '/' in self.header_input.text or self.header_input.text == '~': |
205
9cefc9f8efc9
plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~"
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
211 self.current_dir = expanduser(self.header_input.text) |
194
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
212 |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
213 def onHeaderInputComplete(self, wid, text, **kwargs): |
192 | 214 """we filter items when text is entered in input box""" |
312 | 215 if '/' in text: |
194
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
216 return |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
217 self.do_filter(self.layout.children, |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
218 text, |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
219 lambda c: c.name, |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
220 width_cb=lambda c: c.base_width, |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
221 height_cb=lambda c: c.minimum_height, |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
222 continue_tests=[lambda c: not isinstance(c, ItemWidget), |
312 | 223 lambda c: c.name == '..']) |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
224 |
192 | 225 |
226 ## remote sharing callback ## | |
227 | |
228 def _discoFindByFeaturesCb(self, data): | |
229 entities_services, entities_own, entities_roster = data | |
230 for entities_map, title in ((entities_services, | |
312 | 231 _('services')), |
192 | 232 (entities_own, |
312 | 233 _('your devices')), |
192 | 234 (entities_roster, |
312 | 235 _('your contacts devices'))): |
192 | 236 if entities_map: |
237 self.layout.add_widget(CategorySeparator(text=title)) | |
312 | 238 for entity_str, entity_ids in entities_map.items(): |
192 | 239 entity_jid = jid.JID(entity_str) |
237
059c5b39032d
plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
222
diff
changeset
|
240 item = SharingDeviceWidget( |
059c5b39032d
plugin file sharing: moved common discovery widgets to new core.common_widgets module
Goffi <goffi@goffi.org>
parents:
222
diff
changeset
|
241 self, entity_jid, Identities(entity_ids)) |
192 | 242 self.layout.add_widget(item) |
214
6a98d70a3a66
file sharing: display a message when not sharing device has been found
Goffi <goffi@goffi.org>
parents:
213
diff
changeset
|
243 if not entities_services and not entities_own and not entities_roster: |
6a98d70a3a66
file sharing: display a message when not sharing device has been found
Goffi <goffi@goffi.org>
parents:
213
diff
changeset
|
244 self.layout.add_widget(Label( |
6a98d70a3a66
file sharing: display a message when not sharing device has been found
Goffi <goffi@goffi.org>
parents:
213
diff
changeset
|
245 size_hint=(1, 1), |
6a98d70a3a66
file sharing: display a message when not sharing device has been found
Goffi <goffi@goffi.org>
parents:
213
diff
changeset
|
246 halign='center', |
6a98d70a3a66
file sharing: display a message when not sharing device has been found
Goffi <goffi@goffi.org>
parents:
213
diff
changeset
|
247 text_size=self.size, |
312 | 248 text=_("No sharing device found"))) |
192 | 249 |
250 def discover_devices(self): | |
251 """Looks for devices handling file "File Information Sharing" and display them""" | |
252 try: | |
253 namespace = self.host.ns_map['fis'] | |
254 except KeyError: | |
312 | 255 msg = _("can't find file information sharing namespace, " |
256 "is the plugin running?") | |
192 | 257 log.warning(msg) |
312 | 258 G.host.addNote(_("missing plugin"), msg, C.XMLUI_DATA_LVL_ERROR) |
192 | 259 return |
260 self.host.bridge.discoFindByFeatures( | |
199
b80d275e437f
plugin file sharing: use new local_device argument of discoFindByFeatures
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
261 [namespace], [], False, True, True, True, False, self.profile, |
192 | 262 callback=self._discoFindByFeaturesCb, |
263 errback=partial(G.host.errback, | |
312 | 264 title=_("shared folder error"), |
265 message=_("can't check sharing devices: {msg}"))) | |
192 | 266 |
267 def FISListCb(self, files_data): | |
268 for file_data in files_data: | |
312 | 269 filepath = os.path.join(self.current_dir, file_data['name']) |
192 | 270 item = RemotePathWidget( |
271 filepath=filepath, | |
222 | 272 main_wid=self, |
312 | 273 type_=file_data['type']) |
192 | 274 self.layout.add_widget(item) |
275 | |
276 def FISListEb(self, failure_): | |
312 | 277 self.remote_dir = '' |
192 | 278 G.host.addNote( |
312 | 279 _("shared folder error"), |
280 _("can't list files for {remote_entity}: {msg}").format( | |
192 | 281 remote_entity=self.remote_entity, |
282 msg=failure_), | |
283 level=C.XMLUI_DATA_LVL_WARNING) | |
284 | |
285 ## view generation ## | |
286 | |
287 def update_view(self, *args): | |
288 """update items according to current mode, entity and dir""" | |
312 | 289 log.debug('updating {}, {}'.format(self.current_dir, args)) |
192 | 290 self.layout.clear_widgets() |
312 | 291 self.header_input.text = '' |
194
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
292 self.header_input.hint_text = self.current_dir |
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
293 |
192 | 294 if self.mode == MODE_LOCAL: |
312 | 295 filepath = os.path.join(self.local_dir, '..') |
222 | 296 self.layout.add_widget(LocalPathWidget(filepath=filepath, main_wid=self)) |
213
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
297 try: |
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
298 files = sorted(os.listdir(self.local_dir)) |
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
299 except OSError as e: |
312 | 300 msg = _("can't list files in \"{local_dir}\": {msg}").format( |
213
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
301 local_dir=self.local_dir, |
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
302 msg=e) |
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
303 G.host.addNote( |
312 | 304 _("shared folder error"), |
213
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
305 msg, |
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
306 level=C.XMLUI_DATA_LVL_WARNING) |
312 | 307 self.local_dir = expanduser('~') |
213
423d462ea739
file sharing: catch OS errors while trying to list files on a local dir
Goffi <goffi@goffi.org>
parents:
212
diff
changeset
|
308 return |
192 | 309 for f in files: |
310 filepath = os.path.join(self.local_dir, f) | |
222 | 311 self.layout.add_widget(LocalPathWidget(filepath=filepath, |
312 main_wid=self)) | |
192 | 313 elif self.mode == MODE_VIEW: |
314 if not self.remote_entity: | |
315 self.discover_devices() | |
316 else: | |
317 # we always a way to go back | |
318 # so user can return to previous list even in case of error | |
312 | 319 parent_path = os.path.join(self.remote_dir, '..') |
192 | 320 item = RemotePathWidget( |
321 filepath = parent_path, | |
222 | 322 main_wid=self, |
192 | 323 type_ = C.FILE_TYPE_DIRECTORY) |
324 self.layout.add_widget(item) | |
325 self.host.bridge.FISList( | |
312 | 326 str(self.remote_entity), |
192 | 327 self.remote_dir, |
328 {}, | |
329 self.profile, | |
330 callback=self.FISListCb, | |
331 errback=self.FISListEb) | |
332 | |
333 ## Share methods ## | |
334 | |
198
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
335 def do_share(self, entities_jids, item): |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
336 if entities_jids: |
312 | 337 access = {'read': {'type': 'whitelist', |
338 'jids': entities_jids}} | |
198
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
339 else: |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
340 access = {} |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
341 |
192 | 342 G.host.bridge.FISSharePath( |
343 item.name, | |
344 item.filepath, | |
198
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
345 json.dumps(access, ensure_ascii=False), |
192 | 346 self.profile, |
347 callback=lambda name: G.host.addNote( | |
312 | 348 _("sharing folder"), |
349 _("{name} is now shared").format(name=name)), | |
192 | 350 errback=partial(G.host.errback, |
312 | 351 title=_("sharing folder"), |
352 message=_("can't share folder: {msg}"))) | |
192 | 353 |
198
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
354 def share(self, menu): |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
355 item = self.menu_item |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
356 self.clear_menu() |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
357 EntitiesSelectorMenu(instructions=SELECT_INSTRUCTIONS, |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
358 callback=partial(self.do_share, item=item)).show() |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
359 |
192 | 360 def unshare(self, menu): |
361 item = self.menu_item | |
362 self.clear_menu() | |
363 G.host.bridge.FISUnsharePath( | |
364 item.filepath, | |
365 self.profile, | |
366 callback=lambda: G.host.addNote( | |
312 | 367 _("sharing folder"), |
368 _("{name} is not shared anymore").format(name=item.name)), | |
192 | 369 errback=partial(G.host.errback, |
312 | 370 title=_("sharing folder"), |
371 message=_("can't unshare folder: {msg}"))) | |
192 | 372 |
373 def fileJingleRequestCb(self, progress_id, item, dest_path): | |
374 G.host.addNote( | |
312 | 375 _("file request"), |
376 _("{name} download started at {dest_path}").format( | |
192 | 377 name = item.name, |
378 dest_path = dest_path)) | |
379 | |
380 def request_item(self, item): | |
381 """Retrieve an item from remote entity | |
382 | |
383 @param item(RemotePathWidget): item to retrieve | |
384 """ | |
385 path, name = os.path.split(item.filepath) | |
386 assert name | |
387 assert self.remote_entity | |
388 extra = {'path': path} | |
389 dest_path = files_utils.get_unique_name(os.path.join(G.host.downloads_dir, name)) | |
312 | 390 G.host.bridge.fileJingleRequest(str(self.remote_entity), |
328
dddea9684a8e
plugin file sharing: convert `dest_path` to string when sending to bridge:
Goffi <goffi@goffi.org>
parents:
312
diff
changeset
|
391 str(dest_path), |
192 | 392 name, |
312 | 393 '', |
394 '', | |
192 | 395 extra, |
396 self.profile, | |
397 callback=partial(self.fileJingleRequestCb, | |
398 item=item, | |
399 dest_path=dest_path), | |
400 errback=partial(G.host.errback, | |
312 | 401 title = _("file request error"), |
402 message = _("can't request file: {msg}"))) | |
192 | 403 |
404 @classmethod | |
405 def shared_path_new(cls, shared_path, name, profile): | |
406 for wid in G.host.getVisibleList(cls): | |
407 if shared_path not in wid.shared_paths: | |
408 wid.shared_paths.append(shared_path) | |
409 | |
410 @classmethod | |
411 def shared_path_removed(cls, shared_path, profile): | |
412 for wid in G.host.getVisibleList(cls): | |
413 if shared_path in wid.shared_paths: | |
414 wid.shared_paths.remove(shared_path) | |
415 else: | |
312 | 416 log.warning(_("shared path {path} not found in {widget}".format( |
192 | 417 path = shared_path, widget = wid))) |