diff src/cagou/plugins/plugin_wid_chat.py @ 88:3dc526bb4a5a

upload: plugin android gallery, first draft: - added "external" key in PLUGIN_INFO which indicate that a plugin doesn't create a widget when set to True - callback and cancel_cb method in UploadMenu now use a cleaning_cb arguments which can be None. If set, the callback will be called without argument once the file is uploaded - the AndroidGallery plugin looks for images on Android, then save the content to a temporary file an upload it, then clean the file. This plugin is only active on android platform.
author Goffi <goffi@goffi.org>
date Sun, 25 Dec 2016 22:53:50 +0100
parents c711be670ecd
children 9a6121722669
line wrap: on
line diff
--- a/src/cagou/plugins/plugin_wid_chat.py	Sun Dec 25 16:41:25 2016 +0100
+++ b/src/cagou/plugins/plugin_wid_chat.py	Sun Dec 25 22:53:50 2016 +0100
@@ -596,16 +596,22 @@
 
     def onProgressFinished(self, progress_id, metadata, profile):
         try:
-            callback = self._waiting_pids.pop(progress_id)
+            callback, cleaning_cb = self._waiting_pids.pop(progress_id)
         except KeyError:
             return
+        if cleaning_cb is not None:
+            cleaning_cb()
         callback(metadata, profile)
 
     def onProgressError(self, progress_id, err_msg, profile):
         try:
-            del self._waiting_pids[progress_id]
+            dummy, cleaning_cb = self._waiting_pids[progress_id]
         except KeyError:
             return
+        else:
+            del self._waiting_pids[progress_id]
+            if cleaning_cb is not None:
+                cleaning_cb()
         # TODO: display message to user
         log.warning(u"Can't upload file: {}".format(err_msg))
 
@@ -618,23 +624,23 @@
             profile_key=profile
             )
 
-    def fileUploadCb(self, progress_data):
+    def fileUploadCb(self, progress_data, cleaning_cb):
         try:
             progress_id = progress_data['progress']
         except KeyError:
             xmlui = progress_data['xmlui']
             G.host.showUI(xmlui)
         else:
-            self._waiting_pids[progress_id] = self.fileUploadDone
+            self._waiting_pids[progress_id] = (self.fileUploadDone, cleaning_cb)
 
-    def onUploadOK(self, file_path):
+    def onUploadOK(self, file_path, cleaning_cb):
         G.host.bridge.fileUpload(
             file_path,
             "",
             "",
             {"ignore_tls_errors": C.BOOL_TRUE},  # FIXME: should not be the default
             self.profile,
-            callback = self.fileUploadCb
+            callback = lambda progress_data: self.fileUploadCb(progress_data, cleaning_cb)
             )
 
     def _mucJoinCb(self, joined_data):