summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2015-06-17 20:40:41 (GMT)
committerTobias Markmann <tm@ayena.de>2015-07-10 14:56:43 (GMT)
commitb54aa689ffc6bec7987c193e28c641d2f0f73236 (patch)
treead9984fc3f9633e21fe0ff5ef8728f6d420ca07f /Swift/Controllers/FileTransfer
parent7af21fdd59af3b3112cff69996301605859af84c (diff)
downloadswift-b54aa689ffc6bec7987c193e28c641d2f0f73236.zip
swift-b54aa689ffc6bec7987c193e28c641d2f0f73236.tar.bz2
Implement logic behind 'Clear all' button
The 'Clear all' button in the file transfer overview window was only present in the UI, without any logic behind. That's fixed now. Test-Information: Send a file in between two Swift instances. Verified that the button is enabled/disabled at appropriate times and works as expected if pressed. Change-Id: Ib92621cba479683ade8d815ce5ace9768449a499
Diffstat (limited to 'Swift/Controllers/FileTransfer')
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferController.cpp2
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferController.h19
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferOverview.cpp58
-rw-r--r--Swift/Controllers/FileTransfer/FileTransferOverview.h15
4 files changed, 80 insertions, 14 deletions
diff --git a/Swift/Controllers/FileTransfer/FileTransferController.cpp b/Swift/Controllers/FileTransfer/FileTransferController.cpp
index f7ce8e6..c21c364 100644
--- a/Swift/Controllers/FileTransfer/FileTransferController.cpp
+++ b/Swift/Controllers/FileTransfer/FileTransferController.cpp
@@ -119,11 +119,11 @@ void FileTransferController::cancel() {
119 } 119 }
120} 120}
121 121
122void FileTransferController::handleFileTransferStateChange(FileTransfer::State state) { 122void FileTransferController::handleFileTransferStateChange(FileTransfer::State state) {
123 currentState = state; 123 currentState = state;
124 onStateChage(); 124 onStateChanged();
125 switch(state.type) { 125 switch(state.type) {
126 case FileTransfer::State::Initial: 126 case FileTransfer::State::Initial:
127 assert(false); 127 assert(false);
128 return; 128 return;
129 case FileTransfer::State::Negotiating: 129 case FileTransfer::State::Negotiating:
diff --git a/Swift/Controllers/FileTransfer/FileTransferController.h b/Swift/Controllers/FileTransfer/FileTransferController.h
index 3d6f7d5..490773d 100644
--- a/Swift/Controllers/FileTransfer/FileTransferController.h
+++ b/Swift/Controllers/FileTransfer/FileTransferController.h
@@ -2,22 +2,29 @@
2 * Copyright (c) 2011 Tobias Markmann 2 * Copyright (c) 2011 Tobias Markmann
3 * Licensed under the simplified BSD license. 3 * Licensed under the simplified BSD license.
4 * See Documentation/Licenses/BSD-simplified.txt for more information. 4 * See Documentation/Licenses/BSD-simplified.txt for more information.
5 */ 5 */
6 6
7/*
8 * Copyright (c) 2015 Isode Limited.
9 * All rights reserved.
10 * See the COPYING file for more information.
11 */
12
7#pragma once 13#pragma once
8 14
9#include <string> 15#include <string>
10 16
11#include <boost/shared_ptr.hpp>
12#include <boost/cstdint.hpp> 17#include <boost/cstdint.hpp>
18#include <boost/shared_ptr.hpp>
13 19
14#include <Swiften/JID/JID.h>
15#include <Swiften/FileTransfer/FileTransfer.h>
16#include <Swiften/FileTransfer/IncomingFileTransfer.h>
17#include <Swiften/FileTransfer/FileReadBytestream.h> 20#include <Swiften/FileTransfer/FileReadBytestream.h>
21#include <Swiften/FileTransfer/FileTransfer.h>
18#include <Swiften/FileTransfer/FileWriteBytestream.h> 22#include <Swiften/FileTransfer/FileWriteBytestream.h>
23#include <Swiften/FileTransfer/IncomingFileTransfer.h>
24#include <Swiften/JID/JID.h>
25
19#include <Swift/Controllers/FileTransfer/FileTransferProgressInfo.h> 26#include <Swift/Controllers/FileTransfer/FileTransferProgressInfo.h>
20 27
21namespace Swift { 28namespace Swift {
22 29
23class FileTransferManager; 30class FileTransferManager;
@@ -47,18 +54,18 @@ public:
47 bool isIncoming() const; 54 bool isIncoming() const;
48 FileTransfer::State getState() const; 55 FileTransfer::State getState() const;
49 int getProgress() const; 56 int getProgress() const;
50 boost::uintmax_t getSize() const; 57 boost::uintmax_t getSize() const;
51 58
52 boost::signal<void ()> onStateChage; 59 boost::signal<void ()> onStateChanged;
53 boost::signal<void ()> onProgressChange; 60 boost::signal<void ()> onProgressChange;
54 61
55private: 62private:
56 void handleFileTransferStateChange(FileTransfer::State); 63 void handleFileTransferStateChange(FileTransfer::State);
57 void handleProgressPercentageChange(int percentage); 64 void handleProgressPercentageChange(int percentage);
58 65
59private: 66private:
60 bool sending; 67 bool sending;
61 JID otherParty; 68 JID otherParty;
62 std::string filename; 69 std::string filename;
63 FileTransfer::ref transfer; 70 FileTransfer::ref transfer;
64 boost::shared_ptr<FileReadBytestream> fileReadStream; 71 boost::shared_ptr<FileReadBytestream> fileReadStream;
diff --git a/Swift/Controllers/FileTransfer/FileTransferOverview.cpp b/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
index 2a8c319..b2afea9 100644
--- a/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
+++ b/Swift/Controllers/FileTransfer/FileTransferOverview.cpp
@@ -2,43 +2,91 @@
2 * Copyright (c) 2011 Tobias Markmann 2 * Copyright (c) 2011 Tobias Markmann
3 * Licensed under the simplified BSD license. 3 * Licensed under the simplified BSD license.
4 * See Documentation/Licenses/BSD-simplified.txt for more information. 4 * See Documentation/Licenses/BSD-simplified.txt for more information.
5 */ 5 */
6 6
7/*
8 * Copyright (c) 2015 Isode Limited.
9 * All rights reserved.
10 * See the COPYING file for more information.
11 */
12
7#include "FileTransferOverview.h" 13#include "FileTransferOverview.h"
8 14
9#include <boost/bind.hpp> 15#include <boost/bind.hpp>
10#include <boost/filesystem.hpp> 16#include <boost/filesystem.hpp>
11#include <Swiften/Base/boost_bsignals.h>
12 17
18#include <Swiften/Base/Log.h>
19#include <Swiften/Base/boost_bsignals.h>
20#include <Swiften/Base/foreach.h>
13#include <Swiften/FileTransfer/FileTransferManager.h> 21#include <Swiften/FileTransfer/FileTransferManager.h>
14 22
15namespace Swift { 23namespace Swift {
16 24
17FileTransferOverview::FileTransferOverview(FileTransferManager* ftm) : fileTransferManager(ftm) { 25FileTransferOverview::FileTransferOverview(FileTransferManager* ftm) : fileTransferManager(ftm) {
18 fileTransferManager->onIncomingFileTransfer.connect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1)); 26 fileTransferManager->onIncomingFileTransfer.connect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1));
27 onNewFileTransferController.connect(boost::bind(&FileTransferOverview::handleNewFileTransferController, this, _1));
19} 28}
20 29
21FileTransferOverview::~FileTransferOverview() { 30FileTransferOverview::~FileTransferOverview() {
22 31 onNewFileTransferController.disconnect(boost::bind(&FileTransferOverview::handleNewFileTransferController, this, _1));
32 fileTransferManager->onIncomingFileTransfer.disconnect(boost::bind(&FileTransferOverview::handleIncomingFileTransfer, this, _1));
33 foreach(FileTransferController* controller, fileTransfers) {
34 controller->onStateChanged.disconnect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
35 }
23} 36}
24 37
25void FileTransferOverview::sendFile(const JID& jid, const std::string& filename) { 38void FileTransferOverview::sendFile(const JID& jid, const std::string& filename) {
26 if (boost::filesystem::exists(filename) && boost::filesystem::file_size(filename) > 0) { 39 if (boost::filesystem::exists(filename) && boost::filesystem::file_size(filename) > 0) {
27 FileTransferController* controller = new FileTransferController(jid, filename, fileTransferManager); 40 FileTransferController* controller = new FileTransferController(jid, filename, fileTransferManager);
28 fileTransfers.push_back(controller);
29
30 onNewFileTransferController(controller); 41 onNewFileTransferController(controller);
31 } 42 }
32} 43}
33 44
34void FileTransferOverview::handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) { 45void FileTransferOverview::handleIncomingFileTransfer(IncomingFileTransfer::ref transfer) {
35 FileTransferController* controller = new FileTransferController(transfer); 46 FileTransferController* controller = new FileTransferController(transfer);
36 fileTransfers.push_back(controller);
37 onNewFileTransferController(controller); 47 onNewFileTransferController(controller);
38} 48}
39 49
50void FileTransferOverview::handleNewFileTransferController(FileTransferController* controller) {
51 fileTransfers.push_back(controller);
52 controller->onStateChanged.connect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
53}
54
55void FileTransferOverview::handleFileTransferStateChanged() {
56 onFileTransferListChanged();
57}
58
40const std::vector<FileTransferController*>& FileTransferOverview::getFileTransfers() const { 59const std::vector<FileTransferController*>& FileTransferOverview::getFileTransfers() const {
41 return fileTransfers; 60 return fileTransfers;
42} 61}
43 62
63void FileTransferOverview::clearFinished() {
64 for (std::vector<FileTransferController*>::iterator it = fileTransfers.begin(); it != fileTransfers.end(); ) {
65 if((*it)->getState().type == FileTransfer::State::Finished
66 || (*it)->getState().type == FileTransfer::State::Failed
67 || (*it)->getState().type == FileTransfer::State::Canceled) {
68 FileTransferController* controller = *it;
69 it = fileTransfers.erase(it);
70 controller->onStateChanged.disconnect(boost::bind(&FileTransferOverview::handleFileTransferStateChanged, this));
71 delete controller;
72 } else {
73 ++it;
74 }
75 }
76 onFileTransferListChanged();
77}
78
79bool FileTransferOverview::isClearable() const {
80 bool isClearable = false;
81 foreach (FileTransferController* controller, fileTransfers) {
82 if(controller->getState().type == FileTransfer::State::Finished
83 || controller->getState().type == FileTransfer::State::Failed
84 || controller->getState().type == FileTransfer::State::Canceled) {
85 isClearable = true;
86 break;
87 }
88 }
89 return isClearable;
90}
91
44} 92}
diff --git a/Swift/Controllers/FileTransfer/FileTransferOverview.h b/Swift/Controllers/FileTransfer/FileTransferOverview.h
index 716666a..e3cbf81 100644
--- a/Swift/Controllers/FileTransfer/FileTransferOverview.h
+++ b/Swift/Controllers/FileTransfer/FileTransferOverview.h
@@ -2,18 +2,24 @@
2 * Copyright (c) 2011 Tobias Markmann 2 * Copyright (c) 2011 Tobias Markmann
3 * Licensed under the simplified BSD license. 3 * Licensed under the simplified BSD license.
4 * See Documentation/Licenses/BSD-simplified.txt for more information. 4 * See Documentation/Licenses/BSD-simplified.txt for more information.
5 */ 5 */
6 6
7/*
8 * Copyright (c) 2015 Isode Limited.
9 * All rights reserved.
10 * See the COPYING file for more information.
11 */
12
7#pragma once 13#pragma once
8 14
9#include <vector> 15#include <vector>
10 16
11#include "Swift/Controllers/FileTransfer/FileTransferController.h"
12
13#include <Swiften/Base/boost_bsignals.h> 17#include <Swiften/Base/boost_bsignals.h>
14 18
19#include <Swift/Controllers/FileTransfer/FileTransferController.h>
20
15namespace Swift { 21namespace Swift {
16 22
17class ChatsManager; 23class ChatsManager;
18class FileTransferManager; 24class FileTransferManager;
19 25
@@ -22,15 +28,20 @@ public:
22 FileTransferOverview(FileTransferManager*); 28 FileTransferOverview(FileTransferManager*);
23 ~FileTransferOverview(); 29 ~FileTransferOverview();
24 30
25 void sendFile(const JID&, const std::string&); 31 void sendFile(const JID&, const std::string&);
26 const std::vector<FileTransferController*>& getFileTransfers() const; 32 const std::vector<FileTransferController*>& getFileTransfers() const;
33 void clearFinished();
34 bool isClearable() const;
27 35
28 boost::signal<void (FileTransferController*)> onNewFileTransferController; 36 boost::signal<void (FileTransferController*)> onNewFileTransferController;
37 boost::signal<void ()> onFileTransferListChanged;
29 38
30private: 39private:
31 void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer); 40 void handleIncomingFileTransfer(IncomingFileTransfer::ref transfer);
41 void handleNewFileTransferController(FileTransferController* controller);
42 void handleFileTransferStateChanged();
32 43
33private: 44private:
34 std::vector<FileTransferController*> fileTransfers; 45 std::vector<FileTransferController*> fileTransfers;
35 FileTransferManager *fileTransferManager; 46 FileTransferManager *fileTransferManager;
36}; 47};