Mercurial > libervia-backend
comparison src/plugins/plugin_misc_file.py @ 1635:591e04f0103c
plugin file: added "Action/send" file menu
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 20 Nov 2015 01:57:18 +0100 |
parents | 63cef4dbf2a4 |
children | baac2e120600 |
comparison
equal
deleted
inserted
replaced
1634:95ea323e7d04 | 1635:591e04f0103c |
---|---|
39 "description": _("""File Tansfer Management: | 39 "description": _("""File Tansfer Management: |
40 This plugin manage the various ways of sending a file, and choose the best one.""") | 40 This plugin manage the various ways of sending a file, and choose the best one.""") |
41 } | 41 } |
42 | 42 |
43 | 43 |
44 SENDING = D_(u'Please select a file to send to {peer}') | |
45 SENDING_TITLE = D_(u'File sending') | |
44 CONFIRM = D_(u'{peer} wants to send the file "{name}" to you:\n{desc}\n\nThe file has a size of {size_human}\n\nDo you accept ?') | 46 CONFIRM = D_(u'{peer} wants to send the file "{name}" to you:\n{desc}\n\nThe file has a size of {size_human}\n\nDo you accept ?') |
45 CONFIRM_TITLE = D_(u'Confirm file transfer') | 47 CONFIRM_TITLE = D_(u'Confirm file transfer') |
46 CONFIRM_OVERWRITE = D_(u'File {} already exists, are you sure you want to overwrite ?') | 48 CONFIRM_OVERWRITE = D_(u'File {} already exists, are you sure you want to overwrite ?') |
47 CONFIRM_OVERWRITE_TITLE = D_(u'File exists') | 49 CONFIRM_OVERWRITE_TITLE = D_(u'File exists') |
48 | 50 |
178 def __init__(self, host): | 180 def __init__(self, host): |
179 log.info(_("plugin File initialization")) | 181 log.info(_("plugin File initialization")) |
180 self.host = host | 182 self.host = host |
181 host.bridge.addMethod("fileSend", ".plugin", in_sign='sssss', out_sign='a{ss}', method=self._fileSend, async=True) | 183 host.bridge.addMethod("fileSend", ".plugin", in_sign='sssss', out_sign='a{ss}', method=self._fileSend, async=True) |
182 self._file_callbacks = [] | 184 self._file_callbacks = [] |
185 host.importMenu((D_("Action"), D_("send file")), self._fileSendMenu, security_limit=10, help_string=D_("Send a file"), type_=C.MENU_SINGLE) | |
183 | 186 |
184 def _fileSend(self, peer_jid_s, filepath, name="", file_desc="", profile=C.PROF_KEY_NONE): | 187 def _fileSend(self, peer_jid_s, filepath, name="", file_desc="", profile=C.PROF_KEY_NONE): |
185 return self.fileSend(jid.JID(peer_jid_s), filepath, name or None, file_desc or None, profile) | 188 return self.fileSend(jid.JID(peer_jid_s), filepath, name or None, file_desc or None, profile) |
186 | 189 |
187 @defer.inlineCallbacks | 190 @defer.inlineCallbacks |
206 progress_id = yield defer.maybeDeferred(callback, peer_jid, filepath, filename, file_desc, profile) | 209 progress_id = yield defer.maybeDeferred(callback, peer_jid, filepath, filename, file_desc, profile) |
207 defer.returnValue({'progress': progress_id}) | 210 defer.returnValue({'progress': progress_id}) |
208 msg = u"Can't find any method to send file to {jid}".format(jid=peer_jid.full()) | 211 msg = u"Can't find any method to send file to {jid}".format(jid=peer_jid.full()) |
209 log.warning(msg) | 212 log.warning(msg) |
210 defer.returnValue({'xmlui': xml_tools.note(u"Can't transfer file", msg, C.XMLUI_DATA_LVL_WARNING).toXml()}) | 213 defer.returnValue({'xmlui': xml_tools.note(u"Can't transfer file", msg, C.XMLUI_DATA_LVL_WARNING).toXml()}) |
214 | |
215 def _onFileChoosed(self, peer_jid, data, profile): | |
216 cancelled = C.bool(data.get("cancelled", C.BOOL_FALSE)) | |
217 if cancelled: | |
218 return | |
219 path=data['path'] | |
220 return self.fileSend(peer_jid, path, profile=profile) | |
221 | |
222 def _fileSendMenu(self, data, profile): | |
223 """ XMLUI activated by menu: return file sending UI | |
224 | |
225 @param profile: %(doc_profile)s | |
226 """ | |
227 try: | |
228 jid_ = jid.JID(data['jid']) | |
229 except RuntimeError: | |
230 raise exceptions.DataError(_("Invalid JID")) | |
231 | |
232 file_choosed_id = self.host.registerCallback(lambda data, profile: self._onFileChoosed(jid_, data, profile), with_data=True, one_shot=True) | |
233 xml_ui = xml_tools.XMLUI( | |
234 C.XMLUI_DIALOG, | |
235 dialog_opt = { | |
236 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_FILE, | |
237 C.XMLUI_DATA_MESS: _(SENDING).format(peer=jid_.full())}, | |
238 title = _(SENDING_TITLE), | |
239 submit_id = file_choosed_id) | |
240 | |
241 return {'xmlui': xml_ui.toXml()} | |
211 | 242 |
212 def register(self, namespace, callback, priority=0, method_name=None): | 243 def register(self, namespace, callback, priority=0, method_name=None): |
213 """Register a fileSending method | 244 """Register a fileSending method |
214 | 245 |
215 @param namespace(unicode): XEP namespace | 246 @param namespace(unicode): XEP namespace |