diff options
author | Tobias Markmann <tm@ayena.de> | 2015-06-17 20:40:41 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2015-07-10 14:56:43 (GMT) |
commit | b54aa689ffc6bec7987c193e28c641d2f0f73236 (patch) | |
tree | ad9984fc3f9633e21fe0ff5ef8728f6d420ca07f /Swift/QtUI | |
parent | 7af21fdd59af3b3112cff69996301605859af84c (diff) | |
download | swift-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/QtUI')
-rw-r--r-- | Swift/QtUI/QtFileTransferListItemModel.cpp | 39 | ||||
-rw-r--r-- | Swift/QtUI/QtFileTransferListItemModel.h | 8 | ||||
-rw-r--r-- | Swift/QtUI/QtFileTransferListWidget.cpp | 44 | ||||
-rw-r--r-- | Swift/QtUI/QtFileTransferListWidget.h | 20 |
4 files changed, 95 insertions, 16 deletions
diff --git a/Swift/QtUI/QtFileTransferListItemModel.cpp b/Swift/QtUI/QtFileTransferListItemModel.cpp index b9b9fd1..ef73f4f 100644 --- a/Swift/QtUI/QtFileTransferListItemModel.cpp +++ b/Swift/QtUI/QtFileTransferListItemModel.cpp @@ -4,35 +4,64 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "QtFileTransferListItemModel.h" +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swift/QtUI/QtFileTransferListItemModel.h> #include <boost/bind.hpp> #include <boost/cstdint.hpp> -#include <Swiften/Base/boost_bsignals.h> #include <Swiften/Base/FileSize.h> +#include <Swiften/Base/boost_bsignals.h> + #include <Swift/Controllers/FileTransfer/FileTransferController.h> #include <Swift/Controllers/FileTransfer/FileTransferOverview.h> -#include "QtSwiftUtil.h" + +#include <Swift/QtUI/QtSwiftUtil.h> namespace Swift { QtFileTransferListItemModel::QtFileTransferListItemModel(QObject *parent) : QAbstractItemModel(parent), fileTransferOverview(0) { } +QtFileTransferListItemModel::~QtFileTransferListItemModel() { + if (fileTransferOverview) { + fileTransferOverview->onNewFileTransferController.disconnect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1)); + fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this)); + } +} + void QtFileTransferListItemModel::setFileTransferOverview(FileTransferOverview *overview) { + if (fileTransferOverview) { + fileTransferOverview->onNewFileTransferController.disconnect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1)); + fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this)); + } fileTransferOverview = overview; - fileTransferOverview->onNewFileTransferController.connect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1)); + if (fileTransferOverview) { + fileTransferOverview->onNewFileTransferController.connect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1)); + fileTransferOverview->onFileTransferListChanged.connect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this)); + } + emit layoutAboutToBeChanged(); + emit layoutChanged(); } void QtFileTransferListItemModel::handleNewFileTransferController(FileTransferController* newController) { emit layoutAboutToBeChanged(); emit layoutChanged(); dataChanged(createIndex(0,0), createIndex(fileTransferOverview->getFileTransfers().size(),4)); - newController->onStateChage.connect(boost::bind(&QtFileTransferListItemModel::handleStateChange, this, fileTransferOverview->getFileTransfers().size() - 1)); + newController->onStateChanged.connect(boost::bind(&QtFileTransferListItemModel::handleStateChange, this, fileTransferOverview->getFileTransfers().size() - 1)); newController->onProgressChange.connect(boost::bind(&QtFileTransferListItemModel::handleProgressChange, this, fileTransferOverview->getFileTransfers().size() - 1)); } +void QtFileTransferListItemModel::handleFileTransferListChanged() { + emit layoutAboutToBeChanged(); + emit layoutChanged(); +} + void QtFileTransferListItemModel::handleStateChange(int index) { emit dataChanged(createIndex(index, 2), createIndex(index, 2)); } diff --git a/Swift/QtUI/QtFileTransferListItemModel.h b/Swift/QtUI/QtFileTransferListItemModel.h index 28f13f8..64cdca4 100644 --- a/Swift/QtUI/QtFileTransferListItemModel.h +++ b/Swift/QtUI/QtFileTransferListItemModel.h @@ -4,6 +4,12 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + #pragma once #include <QAbstractItemModel> @@ -17,6 +23,7 @@ class QtFileTransferListItemModel : public QAbstractItemModel { Q_OBJECT public: explicit QtFileTransferListItemModel(QObject *parent = 0); + virtual ~QtFileTransferListItemModel(); void setFileTransferOverview(FileTransferOverview*); @@ -39,6 +46,7 @@ private: private: void handleNewFileTransferController(FileTransferController*); + void handleFileTransferListChanged(); void handleStateChange(int index); void handleProgressChange(int index); diff --git a/Swift/QtUI/QtFileTransferListWidget.cpp b/Swift/QtUI/QtFileTransferListWidget.cpp index fb2b4de..729c95f 100644 --- a/Swift/QtUI/QtFileTransferListWidget.cpp +++ b/Swift/QtUI/QtFileTransferListWidget.cpp @@ -4,14 +4,24 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "QtFileTransferListWidget.h" +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ -#include <Swift/QtUI/QtFileTransferListItemModel.h> +#include <Swift/QtUI/QtFileTransferListWidget.h> + +#include <boost/bind.hpp> -#include <QVBoxLayout> #include <QHBoxLayout> -#include <QWidget> #include <QPushButton> +#include <QVBoxLayout> +#include <QWidget> + +#include <Swift/Controllers/FileTransfer/FileTransferOverview.h> + +#include <Swift/QtUI/QtFileTransferListItemModel.h> namespace Swift { @@ -36,9 +46,9 @@ QtFileTransferListWidget::QtFileTransferListWidget() : fileTransferOverview(0) { buttonLayout->setContentsMargins(10,0,20,0); buttonLayout->setSpacing(0); - QPushButton* clearFinished = new QPushButton(tr("Clear Finished Transfers"), bottom); + clearFinished = new QPushButton(tr("Clear Inactive Transfers"), bottom); clearFinished->setEnabled(false); - //connect(clearButton, SIGNAL(clicked()), textEdit, SLOT(clear())); + connect(clearFinished, SIGNAL(clicked()), this, SLOT(clearInactiveTransfers())); buttonLayout->addWidget(clearFinished); setWindowTitle(tr("File Transfer List")); @@ -46,6 +56,10 @@ QtFileTransferListWidget::QtFileTransferListWidget() : fileTransferOverview(0) { } QtFileTransferListWidget::~QtFileTransferListWidget() { + if (fileTransferOverview) { + fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this)); + fileTransferOverview = NULL; + } delete itemModel; } @@ -55,6 +69,14 @@ void QtFileTransferListWidget::showEvent(QShowEvent* event) { QWidget::showEvent(event); } +void QtFileTransferListWidget::handleFileTransferListChanged() { + clearFinished->setEnabled(fileTransferOverview->isClearable()); +} + +void QtFileTransferListWidget::clearInactiveTransfers() { + fileTransferOverview->clearFinished(); +} + void QtFileTransferListWidget::show() { QWidget::show(); emit windowOpening(); @@ -65,7 +87,15 @@ void QtFileTransferListWidget::activate() { } void QtFileTransferListWidget::setFileTransferOverview(FileTransferOverview *overview) { - fileTransferOverview = overview; + if (fileTransferOverview) { + fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this)); + fileTransferOverview = NULL; + } + if (overview) { + fileTransferOverview = overview; + fileTransferOverview->onFileTransferListChanged.connect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this)); + clearFinished->setEnabled(fileTransferOverview->isClearable()); + } itemModel->setFileTransferOverview(overview); } diff --git a/Swift/QtUI/QtFileTransferListWidget.h b/Swift/QtUI/QtFileTransferListWidget.h index 8adc009..740eb15 100644 --- a/Swift/QtUI/QtFileTransferListWidget.h +++ b/Swift/QtUI/QtFileTransferListWidget.h @@ -4,16 +4,23 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#pragma once - -#include "Swift/Controllers/UIInterfaces/FileTransferListWidget.h" +/* + * Copyright (c) 2015 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ -#include "QtTabbable.h" +#pragma once #include <QCloseEvent> +#include <QPushButton> #include <QShowEvent> #include <QTreeView> +#include <Swift/Controllers/UIInterfaces/FileTransferListWidget.h> + +#include <Swift/QtUI/QtTabbable.h> + namespace Swift { class FileTransferOverview; @@ -36,12 +43,17 @@ public: private: virtual void closeEvent(QCloseEvent* event); virtual void showEvent(QShowEvent* event); + void handleFileTransferListChanged(); + +private slots: + void clearInactiveTransfers(); private: QTreeView* treeView; QtFileTransferListItemModel* itemModel; FileTransferOverview* fileTransferOverview; + QPushButton* clearFinished; }; } |