plugin file: added "Action/send" file menu

This commit is contained in:
Goffi 2015-11-20 01:57:18 +01:00
commit 2494387bf5
2 changed files with 32 additions and 1 deletions

View file

@ -41,6 +41,8 @@ This plugin manage the various ways of sending a file, and choose the best one."
}
SENDING = D_(u'Please select a file to send to {peer}')
SENDING_TITLE = D_(u'File sending')
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 ?')
CONFIRM_TITLE = D_(u'Confirm file transfer')
CONFIRM_OVERWRITE = D_(u'File {} already exists, are you sure you want to overwrite ?')
@ -180,6 +182,7 @@ class FilePlugin(object):
self.host = host
host.bridge.addMethod("fileSend", ".plugin", in_sign='sssss', out_sign='a{ss}', method=self._fileSend, async=True)
self._file_callbacks = []
host.importMenu((D_("Action"), D_("send file")), self._fileSendMenu, security_limit=10, help_string=D_("Send a file"), type_=C.MENU_SINGLE)
def _fileSend(self, peer_jid_s, filepath, name="", file_desc="", profile=C.PROF_KEY_NONE):
return self.fileSend(jid.JID(peer_jid_s), filepath, name or None, file_desc or None, profile)
@ -209,6 +212,34 @@ class FilePlugin(object):
log.warning(msg)
defer.returnValue({'xmlui': xml_tools.note(u"Can't transfer file", msg, C.XMLUI_DATA_LVL_WARNING).toXml()})
def _onFileChoosed(self, peer_jid, data, profile):
cancelled = C.bool(data.get("cancelled", C.BOOL_FALSE))
if cancelled:
return
path=data['path']
return self.fileSend(peer_jid, path, profile=profile)
def _fileSendMenu(self, data, profile):
""" XMLUI activated by menu: return file sending UI
@param profile: %(doc_profile)s
"""
try:
jid_ = jid.JID(data['jid'])
except RuntimeError:
raise exceptions.DataError(_("Invalid JID"))
file_choosed_id = self.host.registerCallback(lambda data, profile: self._onFileChoosed(jid_, data, profile), with_data=True, one_shot=True)
xml_ui = xml_tools.XMLUI(
C.XMLUI_DIALOG,
dialog_opt = {
C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_FILE,
C.XMLUI_DATA_MESS: _(SENDING).format(peer=jid_.full())},
title = _(SENDING_TITLE),
submit_id = file_choosed_id)
return {'xmlui': xml_ui.toXml()}
def register(self, namespace, callback, priority=0, method_name=None):
"""Register a fileSending method