changeset 1635:591e04f0103c

plugin file: added "Action/send" file menu
author Goffi <goffi@goffi.org>
date Fri, 20 Nov 2015 01:57:18 +0100
parents 95ea323e7d04
children e00f450c25fc
files src/plugins/plugin_misc_file.py src/plugins/plugin_xep_0100.py
diffstat 2 files changed, 32 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_file.py	Fri Nov 20 01:57:18 2015 +0100
+++ b/src/plugins/plugin_misc_file.py	Fri Nov 20 01:57:18 2015 +0100
@@ -41,6 +41,8 @@
 }
 
 
+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 @@
         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 @@
         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
 
--- a/src/plugins/plugin_xep_0100.py	Fri Nov 20 01:57:18 2015 +0100
+++ b/src/plugins/plugin_xep_0100.py	Fri Nov 20 01:57:18 2015 +0100
@@ -67,8 +67,8 @@
 
     def _gatewaysMenu(self, data, profile):
         """ XMLUI activated by menu: return Gateways UI
+
         @param profile: %(doc_profile)s
-
         """
         client = self.host.getClient(profile)
         try: