summaryrefslogtreecommitdiffstats
blob: 4f85b8183ceb8fecb6ecbae61e5f9827cc5228b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * Copyright (c) 2011 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

/*
 * Copyright (c) 2016 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swift/Controllers/FileTransferListController.h>

#include <boost/bind.hpp>

#include <Swift/Controllers/UIEvents/RequestFileTransferListUIEvent.h>
#include <Swift/Controllers/UIInterfaces/FileTransferListWidgetFactory.h>

namespace Swift {

FileTransferListController::FileTransferListController(UIEventStream* uiEventStream, FileTransferListWidgetFactory* fileTransferListWidgetFactory) : fileTransferListWidgetFactory(fileTransferListWidgetFactory), fileTransferListWidget(nullptr), fileTransferOverview(nullptr) {
    uiEventStream->onUIEvent.connect(boost::bind(&FileTransferListController::handleUIEvent, this, _1));
}

FileTransferListController::~FileTransferListController() {
    delete fileTransferListWidget;
}

void FileTransferListController::setFileTransferOverview(FileTransferOverview *overview) {
    fileTransferOverview = overview;
    if (fileTransferListWidget) {
        fileTransferListWidget->setFileTransferOverview(fileTransferOverview);
    }
}

void FileTransferListController::handleUIEvent(std::shared_ptr<UIEvent> rawEvent) {
    std::shared_ptr<RequestFileTransferListUIEvent> event = std::dynamic_pointer_cast<RequestFileTransferListUIEvent>(rawEvent);
    if (event != nullptr) {
        if (fileTransferListWidget == nullptr) {
            fileTransferListWidget = fileTransferListWidgetFactory->createFileTransferListWidget();
            if (fileTransferOverview) {
                fileTransferListWidget->setFileTransferOverview(fileTransferOverview);
            }
        }
        fileTransferListWidget->show();
        fileTransferListWidget->activate();
    }
}

}