diff options
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 | |||
| @@ -2,39 +2,68 @@ | |||
| 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 | #include "QtFileTransferListItemModel.h" | 7 | /* |
| 8 | * Copyright (c) 2015 Isode Limited. | ||
| 9 | * All rights reserved. | ||
| 10 | * See the COPYING file for more information. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <Swift/QtUI/QtFileTransferListItemModel.h> | ||
| 8 | 14 | ||
| 9 | #include <boost/bind.hpp> | 15 | #include <boost/bind.hpp> |
| 10 | #include <boost/cstdint.hpp> | 16 | #include <boost/cstdint.hpp> |
| 11 | 17 | ||
| 12 | #include <Swiften/Base/boost_bsignals.h> | ||
| 13 | #include <Swiften/Base/FileSize.h> | 18 | #include <Swiften/Base/FileSize.h> |
| 19 | #include <Swiften/Base/boost_bsignals.h> | ||
| 20 | |||
| 14 | #include <Swift/Controllers/FileTransfer/FileTransferController.h> | 21 | #include <Swift/Controllers/FileTransfer/FileTransferController.h> |
| 15 | #include <Swift/Controllers/FileTransfer/FileTransferOverview.h> | 22 | #include <Swift/Controllers/FileTransfer/FileTransferOverview.h> |
| 16 | #include "QtSwiftUtil.h" | 23 | |
| 24 | #include <Swift/QtUI/QtSwiftUtil.h> | ||
| 17 | 25 | ||
| 18 | namespace Swift { | 26 | namespace Swift { |
| 19 | 27 | ||
| 20 | QtFileTransferListItemModel::QtFileTransferListItemModel(QObject *parent) : QAbstractItemModel(parent), fileTransferOverview(0) { | 28 | QtFileTransferListItemModel::QtFileTransferListItemModel(QObject *parent) : QAbstractItemModel(parent), fileTransferOverview(0) { |
| 21 | } | 29 | } |
| 22 | 30 | ||
| 31 | QtFileTransferListItemModel::~QtFileTransferListItemModel() { | ||
| 32 | if (fileTransferOverview) { | ||
| 33 | fileTransferOverview->onNewFileTransferController.disconnect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1)); | ||
| 34 | fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this)); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 23 | void QtFileTransferListItemModel::setFileTransferOverview(FileTransferOverview *overview) { | 38 | void QtFileTransferListItemModel::setFileTransferOverview(FileTransferOverview *overview) { |
| 39 | if (fileTransferOverview) { | ||
| 40 | fileTransferOverview->onNewFileTransferController.disconnect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1)); | ||
| 41 | fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this)); | ||
| 42 | } | ||
| 24 | fileTransferOverview = overview; | 43 | fileTransferOverview = overview; |
| 25 | fileTransferOverview->onNewFileTransferController.connect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1)); | 44 | if (fileTransferOverview) { |
| 45 | fileTransferOverview->onNewFileTransferController.connect(boost::bind(&QtFileTransferListItemModel::handleNewFileTransferController, this, _1)); | ||
| 46 | fileTransferOverview->onFileTransferListChanged.connect(boost::bind(&QtFileTransferListItemModel::handleFileTransferListChanged, this)); | ||
| 47 | } | ||
| 48 | emit layoutAboutToBeChanged(); | ||
| 49 | emit layoutChanged(); | ||
| 26 | } | 50 | } |
| 27 | 51 | ||
| 28 | void QtFileTransferListItemModel::handleNewFileTransferController(FileTransferController* newController) { | 52 | void QtFileTransferListItemModel::handleNewFileTransferController(FileTransferController* newController) { |
| 29 | emit layoutAboutToBeChanged(); | 53 | emit layoutAboutToBeChanged(); |
| 30 | emit layoutChanged(); | 54 | emit layoutChanged(); |
| 31 | dataChanged(createIndex(0,0), createIndex(fileTransferOverview->getFileTransfers().size(),4)); | 55 | dataChanged(createIndex(0,0), createIndex(fileTransferOverview->getFileTransfers().size(),4)); |
| 32 | newController->onStateChage.connect(boost::bind(&QtFileTransferListItemModel::handleStateChange, this, fileTransferOverview->getFileTransfers().size() - 1)); | 56 | newController->onStateChanged.connect(boost::bind(&QtFileTransferListItemModel::handleStateChange, this, fileTransferOverview->getFileTransfers().size() - 1)); |
| 33 | newController->onProgressChange.connect(boost::bind(&QtFileTransferListItemModel::handleProgressChange, this, fileTransferOverview->getFileTransfers().size() - 1)); | 57 | newController->onProgressChange.connect(boost::bind(&QtFileTransferListItemModel::handleProgressChange, this, fileTransferOverview->getFileTransfers().size() - 1)); |
| 34 | } | 58 | } |
| 35 | 59 | ||
| 60 | void QtFileTransferListItemModel::handleFileTransferListChanged() { | ||
| 61 | emit layoutAboutToBeChanged(); | ||
| 62 | emit layoutChanged(); | ||
| 63 | } | ||
| 64 | |||
| 36 | void QtFileTransferListItemModel::handleStateChange(int index) { | 65 | void QtFileTransferListItemModel::handleStateChange(int index) { |
| 37 | emit dataChanged(createIndex(index, 2), createIndex(index, 2)); | 66 | emit dataChanged(createIndex(index, 2), createIndex(index, 2)); |
| 38 | } | 67 | } |
| 39 | 68 | ||
| 40 | void QtFileTransferListItemModel::handleProgressChange(int index) { | 69 | void QtFileTransferListItemModel::handleProgressChange(int index) { |
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 | |||
| @@ -2,10 +2,16 @@ | |||
| 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 <QAbstractItemModel> | 15 | #include <QAbstractItemModel> |
| 10 | 16 | ||
| 11 | namespace Swift { | 17 | namespace Swift { |
| @@ -15,10 +21,11 @@ class FileTransferOverview; | |||
| 15 | 21 | ||
| 16 | class QtFileTransferListItemModel : public QAbstractItemModel { | 22 | class QtFileTransferListItemModel : public QAbstractItemModel { |
| 17 | Q_OBJECT | 23 | Q_OBJECT |
| 18 | public: | 24 | public: |
| 19 | explicit QtFileTransferListItemModel(QObject *parent = 0); | 25 | explicit QtFileTransferListItemModel(QObject *parent = 0); |
| 26 | virtual ~QtFileTransferListItemModel(); | ||
| 20 | 27 | ||
| 21 | void setFileTransferOverview(FileTransferOverview*); | 28 | void setFileTransferOverview(FileTransferOverview*); |
| 22 | 29 | ||
| 23 | QVariant headerData(int section, Qt::Orientation orientation, int role) const; | 30 | QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
| 24 | int columnCount(const QModelIndex &parent) const; | 31 | int columnCount(const QModelIndex &parent) const; |
| @@ -37,10 +44,11 @@ private: | |||
| 37 | NoOfColumns | 44 | NoOfColumns |
| 38 | }; | 45 | }; |
| 39 | 46 | ||
| 40 | private: | 47 | private: |
| 41 | void handleNewFileTransferController(FileTransferController*); | 48 | void handleNewFileTransferController(FileTransferController*); |
| 49 | void handleFileTransferListChanged(); | ||
| 42 | void handleStateChange(int index); | 50 | void handleStateChange(int index); |
| 43 | void handleProgressChange(int index); | 51 | void handleProgressChange(int index); |
| 44 | 52 | ||
| 45 | signals: | 53 | signals: |
| 46 | 54 | ||
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 | |||
| @@ -2,18 +2,28 @@ | |||
| 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 | #include "QtFileTransferListWidget.h" | 7 | /* |
| 8 | * Copyright (c) 2015 Isode Limited. | ||
| 9 | * All rights reserved. | ||
| 10 | * See the COPYING file for more information. | ||
| 11 | */ | ||
| 8 | 12 | ||
| 9 | #include <Swift/QtUI/QtFileTransferListItemModel.h> | 13 | #include <Swift/QtUI/QtFileTransferListWidget.h> |
| 14 | |||
| 15 | #include <boost/bind.hpp> | ||
| 10 | 16 | ||
| 11 | #include <QVBoxLayout> | ||
| 12 | #include <QHBoxLayout> | 17 | #include <QHBoxLayout> |
| 13 | #include <QWidget> | ||
| 14 | #include <QPushButton> | 18 | #include <QPushButton> |
| 19 | #include <QVBoxLayout> | ||
| 20 | #include <QWidget> | ||
| 21 | |||
| 22 | #include <Swift/Controllers/FileTransfer/FileTransferOverview.h> | ||
| 23 | |||
| 24 | #include <Swift/QtUI/QtFileTransferListItemModel.h> | ||
| 15 | 25 | ||
| 16 | namespace Swift { | 26 | namespace Swift { |
| 17 | 27 | ||
| 18 | QtFileTransferListWidget::QtFileTransferListWidget() : fileTransferOverview(0) { | 28 | QtFileTransferListWidget::QtFileTransferListWidget() : fileTransferOverview(0) { |
| 19 | QVBoxLayout* layout = new QVBoxLayout(this); | 29 | QVBoxLayout* layout = new QVBoxLayout(this); |
| @@ -34,40 +44,60 @@ QtFileTransferListWidget::QtFileTransferListWidget() : fileTransferOverview(0) { | |||
| 34 | 44 | ||
| 35 | QHBoxLayout* buttonLayout = new QHBoxLayout(bottom); | 45 | QHBoxLayout* buttonLayout = new QHBoxLayout(bottom); |
| 36 | buttonLayout->setContentsMargins(10,0,20,0); | 46 | buttonLayout->setContentsMargins(10,0,20,0); |
| 37 | buttonLayout->setSpacing(0); | 47 | buttonLayout->setSpacing(0); |
| 38 | 48 | ||
| 39 | QPushButton* clearFinished = new QPushButton(tr("Clear Finished Transfers"), bottom); | 49 | clearFinished = new QPushButton(tr("Clear Inactive Transfers"), bottom); |
| 40 | clearFinished->setEnabled(false); | 50 | clearFinished->setEnabled(false); |
| 41 | //connect(clearButton, SIGNAL(clicked()), textEdit, SLOT(clear())); | 51 | connect(clearFinished, SIGNAL(clicked()), this, SLOT(clearInactiveTransfers())); |
| 42 | buttonLayout->addWidget(clearFinished); | 52 | buttonLayout->addWidget(clearFinished); |
| 43 | 53 | ||
| 44 | setWindowTitle(tr("File Transfer List")); | 54 | setWindowTitle(tr("File Transfer List")); |
| 45 | emit titleUpdated(); | 55 | emit titleUpdated(); |
| 46 | } | 56 | } |
| 47 | 57 | ||
| 48 | QtFileTransferListWidget::~QtFileTransferListWidget() { | 58 | QtFileTransferListWidget::~QtFileTransferListWidget() { |
| 59 | if (fileTransferOverview) { | ||
| 60 | fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this)); | ||
| 61 | fileTransferOverview = NULL; | ||
| 62 | } | ||
| 49 | delete itemModel; | 63 | delete itemModel; |
| 50 | } | 64 | } |
| 51 | 65 | ||
| 52 | void QtFileTransferListWidget::showEvent(QShowEvent* event) { | 66 | void QtFileTransferListWidget::showEvent(QShowEvent* event) { |
| 53 | emit windowOpening(); | 67 | emit windowOpening(); |
| 54 | emit titleUpdated(); /* This just needs to be somewhere after construction */ | 68 | emit titleUpdated(); /* This just needs to be somewhere after construction */ |
| 55 | QWidget::showEvent(event); | 69 | QWidget::showEvent(event); |
| 56 | } | 70 | } |
| 57 | 71 | ||
| 72 | void QtFileTransferListWidget::handleFileTransferListChanged() { | ||
| 73 | clearFinished->setEnabled(fileTransferOverview->isClearable()); | ||
| 74 | } | ||
| 75 | |||
| 76 | void QtFileTransferListWidget::clearInactiveTransfers() { | ||
| 77 | fileTransferOverview->clearFinished(); | ||
| 78 | } | ||
| 79 | |||
| 58 | void QtFileTransferListWidget::show() { | 80 | void QtFileTransferListWidget::show() { |
| 59 | QWidget::show(); | 81 | QWidget::show(); |
| 60 | emit windowOpening(); | 82 | emit windowOpening(); |
| 61 | } | 83 | } |
| 62 | 84 | ||
| 63 | void QtFileTransferListWidget::activate() { | 85 | void QtFileTransferListWidget::activate() { |
| 64 | emit wantsToActivate(); | 86 | emit wantsToActivate(); |
| 65 | } | 87 | } |
| 66 | 88 | ||
| 67 | void QtFileTransferListWidget::setFileTransferOverview(FileTransferOverview *overview) { | 89 | void QtFileTransferListWidget::setFileTransferOverview(FileTransferOverview *overview) { |
| 68 | fileTransferOverview = overview; | 90 | if (fileTransferOverview) { |
| 91 | fileTransferOverview->onFileTransferListChanged.disconnect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this)); | ||
| 92 | fileTransferOverview = NULL; | ||
| 93 | } | ||
| 94 | if (overview) { | ||
| 95 | fileTransferOverview = overview; | ||
| 96 | fileTransferOverview->onFileTransferListChanged.connect(boost::bind(&QtFileTransferListWidget::handleFileTransferListChanged, this)); | ||
| 97 | clearFinished->setEnabled(fileTransferOverview->isClearable()); | ||
| 98 | } | ||
| 69 | itemModel->setFileTransferOverview(overview); | 99 | itemModel->setFileTransferOverview(overview); |
| 70 | } | 100 | } |
| 71 | 101 | ||
| 72 | std::string QtFileTransferListWidget::getID() const { | 102 | std::string QtFileTransferListWidget::getID() const { |
| 73 | return "QtFileTransferListWidget"; | 103 | return "QtFileTransferListWidget"; |
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 | |||
| @@ -2,20 +2,27 @@ | |||
| 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 | #pragma once | 7 | /* |
| 8 | 8 | * Copyright (c) 2015 Isode Limited. | |
| 9 | #include "Swift/Controllers/UIInterfaces/FileTransferListWidget.h" | 9 | * All rights reserved. |
| 10 | * See the COPYING file for more information. | ||
| 11 | */ | ||
| 10 | 12 | ||
| 11 | #include "QtTabbable.h" | 13 | #pragma once |
| 12 | 14 | ||
| 13 | #include <QCloseEvent> | 15 | #include <QCloseEvent> |
| 16 | #include <QPushButton> | ||
| 14 | #include <QShowEvent> | 17 | #include <QShowEvent> |
| 15 | #include <QTreeView> | 18 | #include <QTreeView> |
| 16 | 19 | ||
| 20 | #include <Swift/Controllers/UIInterfaces/FileTransferListWidget.h> | ||
| 21 | |||
| 22 | #include <Swift/QtUI/QtTabbable.h> | ||
| 23 | |||
| 17 | namespace Swift { | 24 | namespace Swift { |
| 18 | 25 | ||
| 19 | class FileTransferOverview; | 26 | class FileTransferOverview; |
| 20 | class QtFileTransferListItemModel; | 27 | class QtFileTransferListItemModel; |
| 21 | 28 | ||
| @@ -34,14 +41,19 @@ public: | |||
| 34 | virtual std::string getID() const; | 41 | virtual std::string getID() const; |
| 35 | 42 | ||
| 36 | private: | 43 | private: |
| 37 | virtual void closeEvent(QCloseEvent* event); | 44 | virtual void closeEvent(QCloseEvent* event); |
| 38 | virtual void showEvent(QShowEvent* event); | 45 | virtual void showEvent(QShowEvent* event); |
| 46 | void handleFileTransferListChanged(); | ||
| 47 | |||
| 48 | private slots: | ||
| 49 | void clearInactiveTransfers(); | ||
| 39 | 50 | ||
| 40 | private: | 51 | private: |
| 41 | QTreeView* treeView; | 52 | QTreeView* treeView; |
| 42 | 53 | ||
| 43 | QtFileTransferListItemModel* itemModel; | 54 | QtFileTransferListItemModel* itemModel; |
| 44 | FileTransferOverview* fileTransferOverview; | 55 | FileTransferOverview* fileTransferOverview; |
| 56 | QPushButton* clearFinished; | ||
| 45 | }; | 57 | }; |
| 46 | 58 | ||
| 47 | } | 59 | } |
Swift