diff src/cagou/plugins/plugin_wid_chat.py @ 98:4d8c122b86a6

menu (upload): send transfer (i.e. P2P transfer) is now working
author Goffi <goffi@goffi.org>
date Thu, 29 Dec 2016 23:47:10 +0100
parents 5d2289127bb7
children d7447c585603
line wrap: on
line diff
--- a/src/cagou/plugins/plugin_wid_chat.py	Thu Dec 29 23:47:07 2016 +0100
+++ b/src/cagou/plugins/plugin_wid_chat.py	Thu Dec 29 23:47:10 2016 +0100
@@ -633,15 +633,29 @@
         else:
             self._waiting_pids[progress_id] = (self.fileTransferDone, cleaning_cb)
 
-    def onTransferOK(self, file_path, cleaning_cb):
-        G.host.bridge.fileTransfer(
-            file_path,
-            "",
-            "",
-            {"ignore_tls_errors": C.BOOL_TRUE},  # FIXME: should not be the default
-            self.profile,
-            callback = lambda progress_data: self.fileTransferCb(progress_data, cleaning_cb)
-            )
+    def onTransferOK(self, file_path, cleaning_cb, transfer_type):
+        if transfer_type == C.TRANSFER_UPLOAD:
+            G.host.bridge.fileUpload(
+                file_path,
+                "",
+                "",
+                {"ignore_tls_errors": C.BOOL_TRUE},  # FIXME: should not be the default
+                self.profile,
+                callback = lambda progress_data: self.fileTransferCb(progress_data, cleaning_cb)
+                )
+        elif transfer_type == C.TRANSFER_SEND:
+            if self.type == C.CHAT_GROUP:
+                log.warning(u"P2P transfer is not possible for group chat")
+                # TODO: show an error dialog to user, or better hide the send button for MUC
+            else:
+                jid_ = self.target
+                if not jid_.resource:
+                    jid_ = G.host.contact_lists[self.profile].getFullJid(jid_)
+                G.host.bridge.fileSend(jid_, file_path, "", "", profile=self.profile)
+                # TODO: notification of sending/failing
+        else:
+            raise log.error(u"transfer of type {} are not handled".format(transfer_type))
+
 
     def _mucJoinCb(self, joined_data):
         joined, room_jid_s, occupants, user_nick, subject, profile = joined_data