From 0e6beadc1b4427e8ab5109e52872f99a5f85c3d8 Mon Sep 17 00:00:00 2001
From: Tobias Markmann <tm@ayena.de>
Date: Sat, 20 Jun 2015 18:26:26 +0200
Subject: React to file transfer cancellation before the transfer started

Connect FileTransfer::onStateChanged signal earler to slot in
FileTransferController, so the slot will be called for state changes
that occur before a transfer started.

Test-Information:

Tested with two Swift instances and cancelling the sender side and
receiver side. Without this patch the receiver side UI does not change
if the receiver side cancels the transfer.

Change-Id: I1d4d3e1ac78689a16120bfa9ccdec30ab1191ee3

diff --git a/Swift/Controllers/FileTransfer/FileTransferController.cpp b/Swift/Controllers/FileTransfer/FileTransferController.cpp
index 0160a7a..076d3c0 100644
--- a/Swift/Controllers/FileTransfer/FileTransferController.cpp
+++ b/Swift/Controllers/FileTransfer/FileTransferController.cpp
@@ -4,18 +4,26 @@
  * See Documentation/Licenses/BSD-simplified.txt for more information.
  */
 
-#include "FileTransferController.h"
-#include "Swiften/FileTransfer/OutgoingJingleFileTransfer.h"
-#include "Swiften/FileTransfer/FileTransferManager.h"
-#include <Swiften/FileTransfer/FileReadBytestream.h>
-#include <Swiften/Base/boost_bsignals.h>
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <Swift/Controllers/FileTransfer/FileTransferController.h>
+
 #include <boost/bind.hpp>
 #include <boost/filesystem.hpp>
-#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <Swiften/FileTransfer/FileTransferManager.h>
+#include <Swiften/FileTransfer/OutgoingJingleFileTransfer.h>
 #include <Swiften/Base/Log.h>
-#include <Swift/Controllers/Intl.h>
+#include <Swiften/Base/boost_bsignals.h>
+#include <Swiften/FileTransfer/FileReadBytestream.h>
 
-#include <boost/smart_ptr/make_shared.hpp>
+#include <Swift/Controllers/UIInterfaces/ChatWindow.h>
+#include <Swift/Controllers/Intl.h>
 
 namespace Swift {
 
@@ -26,11 +34,12 @@ FileTransferController::FileTransferController(const JID& receipient, const std:
 
 FileTransferController::FileTransferController(IncomingFileTransfer::ref transfer) :
 	sending(false), otherParty(transfer->getSender()), filename(transfer->getFileName()), transfer(transfer), ftManager(0), ftProgressInfo(0), chatWindow(0), currentState(FileTransfer::State::WaitingForStart) {
-
+	transfer->onStateChanged.connect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
 }
 
 FileTransferController::~FileTransferController() {
 	delete ftProgressInfo;
+	transfer->onStateChanged.disconnect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
 }
 
 const JID &FileTransferController::getOtherParty() const {
@@ -95,7 +104,6 @@ void FileTransferController::accept(std::string& file) {
 
 		ftProgressInfo = new FileTransferProgressInfo(transfer->getFileSizeInBytes());
 		ftProgressInfo->onProgressPercentage.connect(boost::bind(&FileTransferController::handleProgressPercentageChange, this, _1));
-		transfer->onStateChanged.connect(boost::bind(&FileTransferController::handleFileTransferStateChange, this, _1));
 		transfer->onProcessedBytes.connect(boost::bind(&FileTransferProgressInfo::setBytesProcessed, ftProgressInfo, _1));
 		incomingTransfer->accept(fileWriteStream);
 	} else {
-- 
cgit v0.10.2-6-g49f6