changeset 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
author Goffi <goffi@goffi.org>
date Sun, 15 Nov 2015 23:11:27 +0100
parents 8d41cd4da2f6
children 33728a2f17bf
files src/plugins/plugin_misc_file.py src/tools/xml_tools.py
diffstat 2 files changed, 21 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_file.py	Sat Nov 14 19:54:27 2015 +0100
+++ b/src/plugins/plugin_misc_file.py	Sun Nov 15 23:11:27 2015 +0100
@@ -202,6 +202,10 @@
                 self.host,
                 _(CONFIRM_OVERWRITE).format(file_path),
                 _(CONFIRM_OVERWRITE_TITLE),
+                action_extra={'meta_from_jid': peer_jid.full(),
+                              'meta_type': C.META_TYPE_OVERWRITE,
+                              'meta_progress_id': file_data[PROGRESS_ID_KEY]
+                             },
                 profile=profile)
             exists_d.addCallback(check_overwrite)
             return exists_d
@@ -243,6 +247,10 @@
             _(CONFIRM_TITLE),
             type_=C.XMLUI_DIALOG_FILE,
             options={C.XMLUI_DATA_FILETYPE: C.XMLUI_DATA_FILETYPE_DIR},
+            action_extra={'meta_from_jid': peer_jid.full(),
+                          'meta_type': C.META_TYPE_FILE,
+                          'meta_progress_id': file_data[PROGRESS_ID_KEY]
+                         },
             profile=profile)
         d.addCallback(self._gotConfirmation, peer_jid, transfer_data, file_data, profile)
         return d
--- a/src/tools/xml_tools.py	Sat Nov 14 19:54:27 2015 +0100
+++ b/src/tools/xml_tools.py	Sun Nov 15 23:11:27 2015 +0100
@@ -1249,12 +1249,14 @@
                        )
     return note_xmlui
 
-def deferXMLUI(host, xmlui, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE):
+def deferXMLUI(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE):
     """Create a deferred linked to XMLUI
 
     @param xmlui(XMLUI): instance of the XMLUI
         Must be an XMLUI that you can submit, with submit_id set to ''
     @param profile: %(doc_profile)s
+    @param action_extra(None, dict): extra action to merge with xmlui
+        mainly used to add meta informations (see actionNew doc)
     @param security_limit: %(doc_security_limit)s
     @return (data): a deferred which fire the data
     """
@@ -1266,16 +1268,23 @@
         return {}
 
     xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True)
-    host.actionNew({'xmlui': xmlui.toXml()}, profile=profile)
+    action_data = {'xmlui': xmlui.toXml()}
+    if action_extra is not None:
+        action_data.update(action_extra)
+    host.actionNew(action_data, profile=profile)
     return xmlui_d
 
-def deferDialog(host, message, title=u'Please confirm', type_=C.XMLUI_DIALOG_CONFIRM, options=None, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE):
+def deferDialog(host, message, title=u'Please confirm', type_=C.XMLUI_DIALOG_CONFIRM, options=None,
+        action_extra=None, security_limit=C.NO_SECURITY_LIMIT, profile=C.PROF_KEY_NONE):
     """Create a submitable dialog and manage it with a deferred
 
     @param message(unicode): message to display
     @param title(unicode): title of the dialog
     @param type(unicode): dialog type (C.XMLUI_DIALOG_*)
     @param options(None, dict): if not None, will be used to update (extend) dialog_opt arguments of XMLUI
+    @param action_extra(None, dict): extra action to merge with xmlui
+        mainly used to add meta informations (see actionNew doc)
+    @param security_limit: %(doc_security_limit)s
     @param profile: %(doc_profile)s
     @return (dict): Deferred dict
     """
@@ -1284,7 +1293,7 @@
     if options is not None:
         dialog_opt.update(options)
     dialog = XMLUI(C.XMLUI_DIALOG, title=title, dialog_opt=dialog_opt, submit_id='')
-    return deferXMLUI(host, dialog, security_limit, profile)
+    return deferXMLUI(host, dialog, action_extra, security_limit, profile)
 
 def deferConfirm(*args, **kwargs):
     """call deferDialog and return a boolean instead of the whole data dict"""