Mercurial > libervia-backend
annotate sat/plugins/plugin_misc_file.py @ 2583:8378806a70fe
plugin XEP-0045: fixed room configuration cancellation
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 11 May 2018 17:24:37 +0200 |
parents | 26edcf3a30eb |
children | 56f94936df1e |
rev | line source |
---|---|
1934
2daf7b4c6756
use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
1 #!/usr/bin/env python2 |
1525 | 2 # -*- coding: utf-8 -*- |
3 | |
4 # SAT plugin for file tansfer | |
2483 | 5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) |
1525 | 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 | |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
20 from sat.core.i18n import _, D_ |
1525 | 21 from sat.core.constants import Const as C |
22 from sat.core.log import getLogger | |
23 log = getLogger(__name__) | |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
24 from sat.core import exceptions |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
25 from sat.tools import xml_tools |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
26 from sat.tools import stream |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
27 from twisted.internet import defer |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
28 from twisted.words.protocols.jabber import jid |
1525 | 29 import os |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
30 import os.path |
1525 | 31 |
32 | |
33 PLUGIN_INFO = { | |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
34 C.PI_NAME: "File Tansfer", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
35 C.PI_IMPORT_NAME: "FILE", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
36 C.PI_TYPE: C.PLUG_TYPE_MISC, |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
37 C.PI_MODES: C.PLUG_MODE_BOTH, |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
38 C.PI_MAIN: "FilePlugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
39 C.PI_HANDLER: "no", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
40 C.PI_DESCRIPTION: _("""File Tansfer Management: |
1525 | 41 This plugin manage the various ways of sending a file, and choose the best one.""") |
42 } | |
43 | |
44 | |
1635
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
45 SENDING = D_(u'Please select a file to send to {peer}') |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
46 SENDING_TITLE = D_(u'File sending') |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
47 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 ?') |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
48 CONFIRM_TITLE = D_(u'Confirm file transfer') |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
49 CONFIRM_OVERWRITE = D_(u'File {} already exists, are you sure you want to overwrite ?') |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
50 CONFIRM_OVERWRITE_TITLE = D_(u'File exists') |
1647
31b96ac3eec2
core (param), plugin file: set security_limit for acount changes, backend (dis)connection, and put a higher one for file send
Goffi <goffi@goffi.org>
parents:
1646
diff
changeset
|
51 SECURITY_LIMIT = 30 |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
52 |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
53 PROGRESS_ID_KEY = 'progress_id' |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
54 |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
55 |
1525 | 56 class FilePlugin(object): |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
57 File=stream.SatFile |
1525 | 58 |
59 def __init__(self, host): | |
60 log.info(_("plugin File initialization")) | |
61 self.host = host | |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
62 host.bridge.addMethod("fileSend", ".plugin", in_sign='ssssa{ss}s', out_sign='a{ss}', method=self._fileSend, async=True) |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
63 self._file_callbacks = [] |
1635
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
64 host.importMenu((D_("Action"), D_("send file")), self._fileSendMenu, security_limit=10, help_string=D_("Send a file"), type_=C.MENU_SINGLE) |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
65 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
66 def _fileSend(self, peer_jid_s, filepath, name="", file_desc="", extra=None, profile=C.PROF_KEY_NONE): |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
67 client = self.host.getClient(profile) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
68 return self.fileSend(client, jid.JID(peer_jid_s), filepath, name or None, file_desc or None, extra) |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
69 |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
70 @defer.inlineCallbacks |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
71 def fileSend(self, client, peer_jid, filepath, filename=None, file_desc=None, extra=None): |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
72 """Send a file using best available method |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
73 |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
74 @param peer_jid(jid.JID): jid of the destinee |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
75 @param filepath(str): absolute path to the file |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
76 @param filename(unicode, None): name to use, or None to find it from filepath |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
77 @param file_desc(unicode, None): description of the file |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
78 @param profile: %(doc_profile)s |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
79 @return (dict): action dictionary, with progress id in case of success, else xmlui message |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
80 """ |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
81 if not os.path.isfile(filepath): |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
82 raise exceptions.DataError(u"The given path doesn't link to a file") |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
83 if not filename: |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
84 filename = os.path.basename(filepath) or '_' |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
85 for namespace, callback, priority, method_name in self._file_callbacks: |
2148
a543eda2c923
core (memory/disco): getInfos now handle node + use client instead of profile in many methods
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
86 has_feature = yield self.host.hasFeature(client, namespace, peer_jid) |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
87 if has_feature: |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
88 log.info(u"{name} method will be used to send the file".format(name=method_name)) |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
89 progress_id = yield callback(client, peer_jid, filepath, filename, file_desc, extra) |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
90 defer.returnValue({'progress': progress_id}) |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
91 msg = u"Can't find any method to send file to {jid}".format(jid=peer_jid.full()) |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
92 log.warning(msg) |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
93 defer.returnValue({'xmlui': xml_tools.note(u"Can't transfer file", msg, C.XMLUI_DATA_LVL_WARNING).toXml()}) |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
94 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
95 def _onFileChoosed(self, client, peer_jid, data): |
1635
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
96 cancelled = C.bool(data.get("cancelled", C.BOOL_FALSE)) |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
97 if cancelled: |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
98 return |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
99 path=data['path'] |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
100 return self.fileSend(client, peer_jid, path) |
1635
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
101 |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
102 def _fileSendMenu(self, data, profile): |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
103 """ XMLUI activated by menu: return file sending UI |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
104 |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
105 @param profile: %(doc_profile)s |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
106 """ |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
107 try: |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
108 jid_ = jid.JID(data['jid']) |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
109 except RuntimeError: |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
110 raise exceptions.DataError(_("Invalid JID")) |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
111 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
112 file_choosed_id = self.host.registerCallback(lambda data, profile: self._onFileChoosed(self.host.getClient(profile), jid_, data), with_data=True, one_shot=True) |
1635
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
113 xml_ui = xml_tools.XMLUI( |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
114 C.XMLUI_DIALOG, |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
115 dialog_opt = { |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
116 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_FILE, |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
117 C.XMLUI_DATA_MESS: _(SENDING).format(peer=jid_.full())}, |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
118 title = _(SENDING_TITLE), |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
119 submit_id = file_choosed_id) |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
120 |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
121 return {'xmlui': xml_ui.toXml()} |
591e04f0103c
plugin file: added "Action/send" file menu
Goffi <goffi@goffi.org>
parents:
1626
diff
changeset
|
122 |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
123 def register(self, namespace, callback, priority=0, method_name=None): |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
124 """Register a fileSending method |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
125 |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
126 @param namespace(unicode): XEP namespace |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
127 @param callback(callable): method to call (must have the same signature as [fileSend]) |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
128 @param priority(int): pririoty of this method, the higher available will be used |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
129 @param method_name(unicode): short name for the method, namespace will be used if None |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
130 """ |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
131 for data in self._file_callbacks: |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
132 if namespace == data[0]: |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
133 raise exceptions.ConflictError(u'A method with this namespace is already registered') |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
134 self._file_callbacks.append((namespace, callback, priority, method_name or namespace)) |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
135 self._file_callbacks.sort(key=lambda data: data[2], reverse=True) |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
136 |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
137 def unregister(self, namespace): |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
138 for idx, data in enumerate(self._file_callbacks): |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
139 if data[0] == namespace: |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
140 del [idx] |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
141 return |
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
142 raise exceptions.NotFound(u"The namespace to unregister doesn't exist") |
1525 | 143 |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
144 # Dialogs with user |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
145 # the overwrite check is done here |
1525 | 146 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
147 def openFileWrite(self, client, file_path, transfer_data, file_data, stream_object): |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
148 """create SatFile or FileStremaObject for the requested file and fill suitable data |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
149 """ |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
150 if stream_object: |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
151 assert 'stream_object' not in transfer_data |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
152 transfer_data['stream_object'] = stream.FileStreamObject( |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
153 self.host, |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
154 client, |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
155 file_path, |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
156 mode='wb', |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
157 uid=file_data[PROGRESS_ID_KEY], |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
158 size=file_data['size'], |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
159 data_cb = file_data.get('data_cb'), |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
160 ) |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
161 else: |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
162 assert 'file_obj' not in transfer_data |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
163 transfer_data['file_obj'] = stream.SatFile( |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
164 self.host, |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
165 client, |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
166 file_path, |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
167 mode='wb', |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
168 uid=file_data[PROGRESS_ID_KEY], |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
169 size=file_data['size'], |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
170 data_cb = file_data.get('data_cb'), |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
171 ) |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
172 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
173 def _gotConfirmation(self, data, client, peer_jid, transfer_data, file_data, stream_object): |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
174 """Called when the permission and dest path have been received |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
175 |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
176 @param peer_jid(jid.JID): jid of the file sender |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
177 @param transfer_data(dict): same as for [self.getDestDir] |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
178 @param file_data(dict): same as for [self.getDestDir] |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
179 @param stream_object(bool): same as for [self.getDestDir] |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
180 return (bool): True if copy is wanted and OK |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
181 False if user wants to cancel |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
182 if file exists ask confirmation and call again self._getDestDir if needed |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
183 """ |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
184 if data.get('cancelled', False): |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
185 return False |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
186 path = data['path'] |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
187 file_data['file_path'] = file_path = os.path.join(path, file_data['name']) |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
188 log.debug(u'destination file path set to {}'.format(file_path)) |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
189 |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
190 # we manage case where file already exists |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
191 if os.path.exists(file_path): |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
192 def check_overwrite(overwrite): |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
193 if overwrite: |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
194 self.openFileWrite(client, file_path, transfer_data, file_data, stream_object) |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
195 return True |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
196 else: |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
197 return self.getDestDir(client, peer_jid, transfer_data, file_data) |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
198 |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
199 exists_d = xml_tools.deferConfirm( |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
200 self.host, |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
201 _(CONFIRM_OVERWRITE).format(file_path), |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
202 _(CONFIRM_OVERWRITE_TITLE), |
1601
e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
203 action_extra={'meta_from_jid': peer_jid.full(), |
e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
204 'meta_type': C.META_TYPE_OVERWRITE, |
e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
205 'meta_progress_id': file_data[PROGRESS_ID_KEY] |
e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
206 }, |
1646
7f0c8856e4e1
plugin file: deferred XMLUI now use security limit
Goffi <goffi@goffi.org>
parents:
1639
diff
changeset
|
207 security_limit=SECURITY_LIMIT, |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
208 profile=client.profile) |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
209 exists_d.addCallback(check_overwrite) |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
210 return exists_d |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
211 |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
212 self.openFileWrite(client, file_path, transfer_data, file_data, stream_object) |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
213 return True |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
214 |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
215 def getDestDir(self, client, peer_jid, transfer_data, file_data, stream_object=False): |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
216 """Request confirmation and destination dir to user |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
217 |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
218 Overwrite confirmation is managed. |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
219 if transfer is confirmed, 'file_obj' is added to transfer_data |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
220 @param peer_jid(jid.JID): jid of the file sender |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
221 @param filename(unicode): name of the file |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
222 @param transfer_data(dict): data of the transfer session, |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
223 it will be only used to store the file_obj. |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
224 "file_obj" (or "stream_object") key *MUST NOT* exist before using getDestDir |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
225 @param file_data(dict): information about the file to be transfered |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
226 It MUST contain the following keys: |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
227 - peer_jid (jid.JID): other peer jid |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
228 - name (unicode): name of the file to trasnsfer |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
229 the name must not be empty or contain a "/" character |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
230 - size (int): size of the file |
1619
3ec7511dbf28
plugin file: 'data_cb' key can be used in file_data to specified a callback used on each read/write
Goffi <goffi@goffi.org>
parents:
1607
diff
changeset
|
231 - desc (unicode): description of the file |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
232 - progress_id (unicode): id to use for progression |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
233 It *MUST NOT* contain the "peer" key |
1619
3ec7511dbf28
plugin file: 'data_cb' key can be used in file_data to specified a callback used on each read/write
Goffi <goffi@goffi.org>
parents:
1607
diff
changeset
|
234 It may contain: |
3ec7511dbf28
plugin file: 'data_cb' key can be used in file_data to specified a callback used on each read/write
Goffi <goffi@goffi.org>
parents:
1607
diff
changeset
|
235 - data_cb (callable): method called on each data read/write |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
236 "file_path" will be added to this dict once destination selected |
1575
833bdb227b16
plugins XEP-0234, file: moved human file size conversion to file plugi
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
237 "size_human" will also be added with human readable file size |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
238 @param stream_object(bool): if True, a stream_object will be used instead of file_obj |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
239 a stream.FileStreamObject will be used |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
240 return (defer.Deferred): True if transfer is accepted |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
241 """ |
2502
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
242 cont,ret_value = self.host.trigger.returnPoint("FILE_getDestDir", client, peer_jid, transfer_data, file_data, stream_object) |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
243 if not cont: |
7ad5f2c4e34a
XEP-0065,XEP-0096,XEP-0166,XEP-0235,XEP-0300: file transfer improvments:
Goffi <goffi@goffi.org>
parents:
2489
diff
changeset
|
244 return ret_value |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
245 filename = file_data['name'] |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
246 assert filename and not '/' in filename |
1585
846a39900fa6
plugins XEP-0096, XEP-0260, file: sendFile method is managed by file plugin, which choose the best available method + progress_id fix
Goffi <goffi@goffi.org>
parents:
1575
diff
changeset
|
247 assert PROGRESS_ID_KEY in file_data |
1575
833bdb227b16
plugins XEP-0234, file: moved human file size conversion to file plugi
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
248 # human readable size |
833bdb227b16
plugins XEP-0234, file: moved human file size conversion to file plugi
Goffi <goffi@goffi.org>
parents:
1574
diff
changeset
|
249 file_data['size_human'] = u'{:.6n} Mio'.format(float(file_data['size'])/(1024**2)) |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
250 d = xml_tools.deferDialog(self.host, |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
251 _(CONFIRM).format(peer=peer_jid.full(), **file_data), |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
252 _(CONFIRM_TITLE), |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
253 type_=C.XMLUI_DIALOG_FILE, |
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
254 options={C.XMLUI_DATA_FILETYPE: C.XMLUI_DATA_FILETYPE_DIR}, |
1601
e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
255 action_extra={'meta_from_jid': peer_jid.full(), |
e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
256 'meta_type': C.META_TYPE_FILE, |
e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
257 'meta_progress_id': file_data[PROGRESS_ID_KEY] |
e0a152f2cf6d
core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents:
1598
diff
changeset
|
258 }, |
1646
7f0c8856e4e1
plugin file: deferred XMLUI now use security limit
Goffi <goffi@goffi.org>
parents:
1639
diff
changeset
|
259 security_limit=SECURITY_LIMIT, |
2489
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
260 profile=client.profile) |
e2a7bb875957
plugin pipe/stream, file transfert: refactoring and improvments:
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
261 d.addCallback(self._gotConfirmation, client, peer_jid, transfer_data, file_data, stream_object) |
1574
babd97d80049
plugins XEP-0234, file: moved file request dialog to file plugin
Goffi <goffi@goffi.org>
parents:
1568
diff
changeset
|
262 return d |