Mercurial > libervia-desktop-kivy
annotate cagou/plugins/plugin_wid_file_sharing.py @ 202:e20796eea873
plugin file sharing: transtype jid.Jid instance to unicode when using bridge, to avoid troubles with pb
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 May 2018 11:55:28 +0200 |
parents | b80d275e437f |
children | 9cefc9f8efc9 |
rev | line source |
---|---|
192 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # Cagou: desktop/mobile frontend for Salut à Toi XMPP client | |
5 # Copyright (C) 2016-2018 Jérôme Poisson (goffi@goffi.org) | |
6 | |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
20 | |
21 from sat.core import log as logging | |
22 from sat.core import exceptions | |
23 log = logging.getLogger(__name__) | |
24 from sat.core.i18n import _ | |
25 from sat.tools.common import files_utils | |
26 from sat_frontends.quick_frontend import quick_widgets | |
27 from sat_frontends.tools import jid | |
28 from cagou.core.constants import Const as C | |
29 from cagou.core import cagou_widget | |
198
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
30 from cagou.core.menu import EntitiesSelectorMenu |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
31 from cagou.core.utils import FilterBehavior |
192 | 32 from cagou import G |
33 from kivy import properties | |
34 from kivy.uix.label import Label | |
35 from kivy.uix.button import Button | |
36 from kivy.uix.boxlayout import BoxLayout | |
37 from kivy.garden import modernmenu | |
38 from kivy.clock import Clock | |
39 from kivy.metrics import dp | |
40 from functools import partial | |
41 import os.path | |
42 import json | |
43 | |
44 | |
45 PLUGIN_INFO = { | |
46 "name": _(u"file sharing"), | |
47 "main": "FileSharing", | |
48 "description": _(u"share/transfer files between devices"), | |
49 "icon_symbol": u"exchange", | |
50 } | |
51 MODE_VIEW = u"view" | |
52 MODE_LOCAL = u"local" | |
194
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
53 SELECT_INSTRUCTIONS = _(u"Please select entities to share with") |
192 | 54 |
55 | |
56 dist = modernmenu.dist | |
57 | |
58 | |
59 class ModeBtn(Button): | |
60 | |
61 def __init__(self, parent, **kwargs): | |
62 super(ModeBtn, self).__init__(**kwargs) | |
63 parent.bind(mode=self.on_mode) | |
64 self.on_mode(parent, parent.mode) | |
65 | |
66 def on_mode(self, parent, new_mode): | |
67 if new_mode == MODE_VIEW: | |
68 self.text = _(u"view shared files") | |
69 elif new_mode == MODE_LOCAL: | |
70 self.text = _(u"share local files") | |
71 else: | |
72 exceptions.InternalError(u"Unknown mode: {mode}".format(mode=new_mode)) | |
73 | |
74 | |
75 class Identities(object): | |
76 | |
77 def __init__(self, entity_ids): | |
78 identities = {} | |
79 for cat, type_, name in entity_ids: | |
80 identities.setdefault(cat, {}).setdefault(type_, []).append(name) | |
81 self.identities = identities | |
82 | |
83 @property | |
84 def name(self): | |
85 return self.identities.values()[0].values()[0][0] | |
86 | |
87 | |
88 class ItemWidget(BoxLayout): | |
89 click_timeout = properties.NumericProperty(0.4) | |
90 base_width = properties.NumericProperty(dp(100)) | |
91 | |
92 def __init__(self, sharing_wid, name): | |
93 self.sharing_wid = sharing_wid | |
94 self.name = name | |
95 super(ItemWidget, self).__init__() | |
96 | |
97 def on_touch_down(self, touch): | |
98 if not self.collide_point(*touch.pos): | |
99 return | |
100 t = partial(self.open_menu, touch) | |
101 touch.ud['menu_timeout'] = t | |
102 Clock.schedule_once(t, self.click_timeout) | |
103 return super(ItemWidget, self).on_touch_down(touch) | |
104 | |
105 def do_item_action(self, touch): | |
106 pass | |
107 | |
108 def on_touch_up(self, touch): | |
109 if touch.ud.get('menu_timeout'): | |
110 Clock.unschedule(touch.ud['menu_timeout']) | |
111 if self.collide_point(*touch.pos) and self.sharing_wid.menu is None: | |
112 self.do_item_action(touch) | |
113 return super(ItemWidget, self).on_touch_up(touch) | |
114 | |
115 def open_menu(self, touch, dt): | |
116 self.sharing_wid.open_menu(self, touch) | |
117 del touch.ud['menu_timeout'] | |
118 | |
119 def getMenuChoices(self): | |
120 """return choice adapted to selected item | |
121 | |
122 @return (list[dict]): choices ad expected by ModernMenu | |
123 """ | |
124 return [] | |
125 | |
126 | |
127 class PathWidget(ItemWidget): | |
128 | |
129 def __init__(self, sharing_wid, filepath): | |
130 name = os.path.basename(filepath) | |
131 self.filepath = os.path.normpath(filepath) | |
132 if self.filepath == u'.': | |
133 self.filepath = u'' | |
134 super(PathWidget, self).__init__(sharing_wid, name) | |
135 | |
136 @property | |
137 def is_dir(self): | |
138 raise NotImplementedError | |
139 | |
140 def do_item_action(self, touch): | |
141 if self.is_dir: | |
142 self.sharing_wid.current_dir = self.filepath | |
143 | |
144 def open_menu(self, touch, dt): | |
145 log.debug(_(u"opening menu for {path}").format(path=self.filepath)) | |
146 super(PathWidget, self).open_menu(touch, dt) | |
147 | |
148 | |
149 class LocalPathWidget(PathWidget): | |
150 | |
151 @property | |
152 def is_dir(self): | |
153 return os.path.isdir(self.filepath) | |
154 | |
155 def getMenuChoices(self): | |
156 choices = [] | |
157 if self.shared: | |
158 choices.append(dict(text=_(u'unshare'), | |
159 index=len(choices)+1, | |
160 callback=self.sharing_wid.unshare)) | |
161 else: | |
162 choices.append(dict(text=_(u'share'), | |
163 index=len(choices)+1, | |
164 callback=self.sharing_wid.share)) | |
165 return choices | |
166 | |
167 | |
168 class RemotePathWidget(PathWidget): | |
169 | |
170 def __init__(self, sharing_wid, filepath, type_): | |
171 self.type_ = type_ | |
172 super(RemotePathWidget, self).__init__(sharing_wid, filepath) | |
173 | |
174 @property | |
175 def is_dir(self): | |
176 return self.type_ == C.FILE_TYPE_DIRECTORY | |
177 | |
178 def do_item_action(self, touch): | |
179 if self.is_dir: | |
180 if self.filepath == u'..': | |
181 self.sharing_wid.remote_entity = u'' | |
182 else: | |
183 super(RemotePathWidget, self).do_item_action(touch) | |
184 else: | |
185 self.sharing_wid.request_item(self) | |
186 return True | |
187 | |
188 | |
189 class DeviceWidget(ItemWidget): | |
190 | |
191 def __init__(self, sharing_wid, entity_jid, identities): | |
192 self.entity_jid = entity_jid | |
193 self.identities = identities | |
194 self.own_device = entity_jid.bare == next(G.host.profiles.itervalues()).whoami | |
195 name = self.identities.name if self.own_device else self.entity_jid.node | |
196 super(DeviceWidget, self).__init__(sharing_wid, name) | |
197 | |
198 def do_item_action(self, touch): | |
199 self.sharing_wid.remote_entity = self.entity_jid | |
200 self.sharing_wid.remote_dir = u'' | |
201 | |
202 | |
203 class CategorySeparator(Label): | |
204 pass | |
205 | |
206 | |
207 class Menu(modernmenu.ModernMenu): | |
208 pass | |
209 | |
210 | |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
211 class FileSharing(quick_widgets.QuickWidget, cagou_widget.CagouWidget, FilterBehavior): |
192 | 212 SINGLE=False |
213 float_layout = properties.ObjectProperty() | |
214 layout = properties.ObjectProperty() | |
215 mode = properties.OptionProperty(MODE_LOCAL, options=[MODE_VIEW, MODE_LOCAL]) | |
216 local_dir = properties.StringProperty(os.path.expanduser(u'~')) | |
217 remote_dir = properties.StringProperty(u'') | |
218 remote_entity = properties.StringProperty(u'') | |
219 shared_paths = properties.ListProperty() | |
220 signals_registered = False | |
221 | |
222 def __init__(self, host, target, profiles): | |
223 quick_widgets.QuickWidget.__init__(self, host, target, profiles) | |
224 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
|
225 FilterBehavior.__init__(self) |
192 | 226 self.mode_btn = ModeBtn(self) |
227 self.mode_btn.bind(on_release=self.change_mode) | |
228 self.headerInputAddExtra(self.mode_btn) | |
229 self.bind(local_dir=self.update_view, | |
230 remote_dir=self.update_view, | |
231 remote_entity=self.update_view) | |
232 self.update_view() | |
233 self.menu = None | |
234 self.menu_item = None | |
235 self.float_layout.bind(children=self.clean_fl_children) | |
236 if not FileSharing.signals_registered: | |
237 # FIXME: we use this hack (registering the signal for the whole class) now | |
238 # as there is currently no unregisterSignal available in bridges | |
239 G.host.registerSignal("FISSharedPathNew", handler=FileSharing.shared_path_new, iface="plugin") | |
240 G.host.registerSignal("FISSharedPathRemoved", handler=FileSharing.shared_path_removed, iface="plugin") | |
241 FileSharing.signals_registered = True | |
242 G.host.bridge.FISLocalSharesGet(self.profile, | |
243 callback=self.fill_paths, | |
244 errback=G.host.errback) | |
245 | |
246 @property | |
247 def current_dir(self): | |
248 return self.local_dir if self.mode == MODE_LOCAL else self.remote_dir | |
249 | |
250 @current_dir.setter | |
251 def current_dir(self, new_dir): | |
252 if self.mode == MODE_LOCAL: | |
253 self.local_dir = new_dir | |
254 else: | |
255 self.remote_dir = new_dir | |
256 | |
257 def fill_paths(self, shared_paths): | |
258 self.shared_paths.extend(shared_paths) | |
259 | |
260 def change_mode(self, mode_btn): | |
261 self.clear_menu() | |
262 opt = self.__class__.mode.options | |
263 new_idx = (opt.index(self.mode)+1) % len(opt) | |
264 self.mode = opt[new_idx] | |
265 | |
266 def on_mode(self, instance, new_mode): | |
267 print(instance) | |
268 self.update_view(None, self.local_dir) | |
269 | |
194
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
270 def onHeaderInput(self): |
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
271 if u'/' in self.header_input.text or self.header_input.text == u'~': |
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
272 self.current_dir = os.path.expanduser(self.header_input.text) |
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
273 |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
274 def onHeaderInputComplete(self, wid, text, **kwargs): |
192 | 275 """we filter items when text is entered in input box""" |
194
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
276 if u'/' in text: |
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
277 return |
196
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
278 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
|
279 text, |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
280 lambda c: c.name, |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
281 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
|
282 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
|
283 continue_tests=[lambda c: not isinstance(c, ItemWidget), |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
284 lambda c: c.name == u'..']) |
519b3a29743c
utils, plugin file sharing: new utils module, with a FilterBehavior:
Goffi <goffi@goffi.org>
parents:
194
diff
changeset
|
285 |
192 | 286 |
287 ## remote sharing callback ## | |
288 | |
289 def _discoFindByFeaturesCb(self, data): | |
290 entities_services, entities_own, entities_roster = data | |
291 for entities_map, title in ((entities_services, | |
292 _(u'services')), | |
293 (entities_own, | |
294 _(u'your devices')), | |
295 (entities_roster, | |
296 _(u'your contacts devices'))): | |
297 if entities_map: | |
298 self.layout.add_widget(CategorySeparator(text=title)) | |
299 for entity_str, entity_ids in entities_map.iteritems(): | |
300 entity_jid = jid.JID(entity_str) | |
301 item = DeviceWidget(self, | |
302 entity_jid, | |
303 Identities(entity_ids)) | |
304 self.layout.add_widget(item) | |
305 | |
306 def discover_devices(self): | |
307 """Looks for devices handling file "File Information Sharing" and display them""" | |
308 try: | |
309 namespace = self.host.ns_map['fis'] | |
310 except KeyError: | |
311 msg = _(u"can't find file information sharing namespace, is the plugin running?") | |
312 log.warning(msg) | |
313 G.host.addNote(_(u"missing plugin"), msg, C.XMLUI_DATA_LVL_ERROR) | |
314 return | |
315 self.host.bridge.discoFindByFeatures( | |
199
b80d275e437f
plugin file sharing: use new local_device argument of discoFindByFeatures
Goffi <goffi@goffi.org>
parents:
198
diff
changeset
|
316 [namespace], [], False, True, True, True, False, self.profile, |
192 | 317 callback=self._discoFindByFeaturesCb, |
318 errback=partial(G.host.errback, | |
319 title=_(u"shared folder error"), | |
320 message=_(u"can't check sharing devices: {msg}"))) | |
321 | |
322 def FISListCb(self, files_data): | |
323 for file_data in files_data: | |
324 filepath = os.path.join(self.current_dir, file_data[u'name']) | |
325 item = RemotePathWidget( | |
326 self, | |
327 filepath=filepath, | |
328 type_=file_data[u'type']) | |
329 self.layout.add_widget(item) | |
330 | |
331 def FISListEb(self, failure_): | |
332 self.remote_dir = u'' | |
333 G.host.addNote( | |
334 _(u"shared folder error"), | |
335 _(u"can't list files for {remote_entity}: {msg}").format( | |
336 remote_entity=self.remote_entity, | |
337 msg=failure_), | |
338 level=C.XMLUI_DATA_LVL_WARNING) | |
339 | |
340 ## view generation ## | |
341 | |
342 def update_view(self, *args): | |
343 """update items according to current mode, entity and dir""" | |
344 log.debug(u'updating {}, {}'.format(self.current_dir, args)) | |
345 self.layout.clear_widgets() | |
346 self.header_input.text = u'' | |
194
a68c9baa6694
plugin file sharing: use header hint to show current path, and open new path:
Goffi <goffi@goffi.org>
parents:
192
diff
changeset
|
347 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
|
348 |
192 | 349 if self.mode == MODE_LOCAL: |
350 filepath = os.path.join(self.local_dir, u'..') | |
351 self.layout.add_widget(LocalPathWidget(sharing_wid=self, filepath=filepath)) | |
352 files = sorted(os.listdir(self.local_dir)) | |
353 for f in files: | |
354 filepath = os.path.join(self.local_dir, f) | |
355 self.layout.add_widget(LocalPathWidget(sharing_wid=self, filepath=filepath)) | |
356 elif self.mode == MODE_VIEW: | |
357 if not self.remote_entity: | |
358 self.discover_devices() | |
359 else: | |
360 # we always a way to go back | |
361 # so user can return to previous list even in case of error | |
362 parent_path = os.path.join(self.remote_dir, u'..') | |
363 item = RemotePathWidget( | |
364 self, | |
365 filepath = parent_path, | |
366 type_ = C.FILE_TYPE_DIRECTORY) | |
367 self.layout.add_widget(item) | |
368 self.host.bridge.FISList( | |
202
e20796eea873
plugin file sharing: transtype jid.Jid instance to unicode when using bridge, to avoid troubles with pb
Goffi <goffi@goffi.org>
parents:
199
diff
changeset
|
369 unicode(self.remote_entity), |
192 | 370 self.remote_dir, |
371 {}, | |
372 self.profile, | |
373 callback=self.FISListCb, | |
374 errback=self.FISListEb) | |
375 | |
376 ## menu methods ## | |
377 | |
378 def clean_fl_children(self, layout, children): | |
379 """insure that self.menu and self.menu_item are None when menu is dimissed""" | |
380 if self.menu is not None and self.menu not in children: | |
381 self.menu = self.menu_item = None | |
382 | |
383 def clear_menu(self): | |
384 """remove menu if there is one""" | |
385 if self.menu is not None: | |
386 self.menu.dismiss() | |
387 self.menu = None | |
388 self.menu_item = None | |
389 | |
390 def open_menu(self, item, touch): | |
391 """open menu for item | |
392 | |
393 @param item(PathWidget): item when the menu has been requested | |
394 @param touch(kivy.input.MotionEvent): touch data | |
395 """ | |
396 if self.menu_item == item: | |
397 return | |
398 self.clear_menu() | |
399 pos = self.to_widget(*touch.pos) | |
400 choices = item.getMenuChoices() | |
401 if not choices: | |
402 return | |
403 self.menu = Menu(choices=choices, | |
404 center=pos, | |
405 size_hint=(None, None)) | |
406 self.float_layout.add_widget(self.menu) | |
407 self.menu.start_display(touch) | |
408 self.menu_item = item | |
409 | |
410 ## Share methods ## | |
411 | |
198
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
412 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
|
413 if entities_jids: |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
414 access = {u'read': {u'type': 'whitelist', |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
415 u'jids': entities_jids}} |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
416 else: |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
417 access = {} |
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
418 |
192 | 419 G.host.bridge.FISSharePath( |
420 item.name, | |
421 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
|
422 json.dumps(access, ensure_ascii=False), |
192 | 423 self.profile, |
424 callback=lambda name: G.host.addNote( | |
425 _(u"sharing folder"), | |
426 _(u"{name} is now shared").format(name=name)), | |
427 errback=partial(G.host.errback, | |
428 title=_(u"sharing folder"), | |
429 message=_(u"can't share folder: {msg}"))) | |
430 | |
198
60b63c3e63a1
plugin file sharing: use new EntitiesSelectorMenu to select entities which can access shared files
Goffi <goffi@goffi.org>
parents:
196
diff
changeset
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 |
192 | 437 def unshare(self, menu): |
438 item = self.menu_item | |
439 self.clear_menu() | |
440 G.host.bridge.FISUnsharePath( | |
441 item.filepath, | |
442 self.profile, | |
443 callback=lambda: G.host.addNote( | |
444 _(u"sharing folder"), | |
445 _(u"{name} is not shared anymore").format(name=item.name)), | |
446 errback=partial(G.host.errback, | |
447 title=_(u"sharing folder"), | |
448 message=_(u"can't unshare folder: {msg}"))) | |
449 | |
450 def fileJingleRequestCb(self, progress_id, item, dest_path): | |
451 G.host.addNote( | |
452 _(u"file request"), | |
453 _(u"{name} download started at {dest_path}").format( | |
454 name = item.name, | |
455 dest_path = dest_path)) | |
456 | |
457 def request_item(self, item): | |
458 """Retrieve an item from remote entity | |
459 | |
460 @param item(RemotePathWidget): item to retrieve | |
461 """ | |
462 path, name = os.path.split(item.filepath) | |
463 assert name | |
464 assert self.remote_entity | |
465 extra = {'path': path} | |
466 dest_path = files_utils.get_unique_name(os.path.join(G.host.downloads_dir, name)) | |
202
e20796eea873
plugin file sharing: transtype jid.Jid instance to unicode when using bridge, to avoid troubles with pb
Goffi <goffi@goffi.org>
parents:
199
diff
changeset
|
467 G.host.bridge.fileJingleRequest(unicode(self.remote_entity), |
192 | 468 dest_path, |
469 name, | |
470 u'', | |
471 u'', | |
472 extra, | |
473 self.profile, | |
474 callback=partial(self.fileJingleRequestCb, | |
475 item=item, | |
476 dest_path=dest_path), | |
477 errback=partial(G.host.errback, | |
478 title = _(u"file request error"), | |
479 message = _(u"can't request file: {msg}"))) | |
480 | |
481 @classmethod | |
482 def shared_path_new(cls, shared_path, name, profile): | |
483 for wid in G.host.getVisibleList(cls): | |
484 if shared_path not in wid.shared_paths: | |
485 wid.shared_paths.append(shared_path) | |
486 | |
487 @classmethod | |
488 def shared_path_removed(cls, shared_path, profile): | |
489 for wid in G.host.getVisibleList(cls): | |
490 if shared_path in wid.shared_paths: | |
491 wid.shared_paths.remove(shared_path) | |
492 else: | |
493 log.warning(_(u"shared path {path} not found in {widget}".format( | |
494 path = shared_path, widget = wid))) |