From 9b0ea3a0554b05404ebbbaa9af00d0df620f7abb Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Sat, 28 Mar 2015 01:59:20 +0200 Subject: [PATCH] Allow the user to disable filters from the side panel. --- src/core/preferences.cpp | 30 ++++++++++++ src/core/preferences.h | 8 ++++ src/gui/transferlistfilterswidget.cpp | 66 ++++++++++++++++++--------- src/gui/transferlistfilterswidget.h | 7 ++- 4 files changed, 87 insertions(+), 24 deletions(-) diff --git a/src/core/preferences.cpp b/src/core/preferences.cpp index 1f0fb2599..35293f9e3 100644 --- a/src/core/preferences.cpp +++ b/src/core/preferences.cpp @@ -2231,6 +2231,36 @@ void Preferences::setTorImportGeometry(const QByteArray &geometry) setValue("TorrentImportDlg/dimensions", geometry); } +bool Preferences::getStatusFilterState() const +{ + return value("TransferListFilters/statusFilterState", true).toBool(); +} + +void Preferences::setStatusFilterState(const bool checked) +{ + setValue("TransferListFilters/statusFilterState", checked); +} + +bool Preferences::getLabelFilterState() const +{ + return value("TransferListFilters/labelFilterState", true).toBool(); +} + +void Preferences::setLabelFilterState(const bool checked) +{ + setValue("TransferListFilters/labelFilterState", checked); +} + +bool Preferences::getTrackerFilterState() const +{ + return value("TransferListFilters/trackerFilterState", true).toBool(); +} + +void Preferences::setTrackerFilterState(const bool checked) +{ + setValue("TransferListFilters/trackerFilterState", checked); +} + int Preferences::getTransSelFilter() const { return value("TransferListFilters/selectedFilterIndex", 0).toInt(); diff --git a/src/core/preferences.h b/src/core/preferences.h index da4502c98..cf608982f 100644 --- a/src/core/preferences.h +++ b/src/core/preferences.h @@ -500,6 +500,9 @@ public: void setTorImportLastContentDir(const QString &path); QByteArray getTorImportGeometry() const; void setTorImportGeometry(const QByteArray &geometry); + bool getStatusFilterState() const; + bool getLabelFilterState() const; + bool getTrackerFilterState() const; int getTransSelFilter() const; void setTransSelFilter(const int &index); QByteArray getTransHeaderState() const; @@ -528,6 +531,11 @@ public: QList getHostNameCookies(const QString &host_name) const; QList getHostNameQNetworkCookies(const QString& host_name) const; void setHostNameCookies(const QString &host_name, const QList &cookies); + +public slots: + void setStatusFilterState(bool checked); + void setLabelFilterState(bool checked); + void setTrackerFilterState(bool checked); }; #endif // PREFERENCES_H diff --git a/src/gui/transferlistfilterswidget.cpp b/src/gui/transferlistfilterswidget.cpp index 0fc2e81a0..a74610731 100644 --- a/src/gui/transferlistfilterswidget.cpp +++ b/src/gui/transferlistfilterswidget.cpp @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include "transferlistdelegate.h" #include "transferlistwidget.h" @@ -84,6 +84,15 @@ QSize FiltersBase::minimumSizeHint() const return size; } +void FiltersBase::toggleFilter(bool checked) +{ + setVisible(checked); + if (checked) + applyFilter(currentRow()); + else + applyFilter(0); +} + StatusFiltersWidget::StatusFiltersWidget(QWidget *parent, TransferListWidget *transferList) : FiltersBase(parent, transferList) { @@ -117,7 +126,9 @@ StatusFiltersWidget::StatusFiltersWidget(QWidget *parent, TransferListWidget *tr inactive->setData(Qt::DisplayRole, QVariant(tr("Inactive") + " (0)")); inactive->setData(Qt::DecorationRole, QIcon(":/icons/skin/filterinactive.png")); - setCurrentRow(Preferences::instance()->getTransSelFilter(), QItemSelectionModel::SelectCurrent); + const Preferences* const pref = Preferences::instance(); + setCurrentRow(pref->getTransSelFilter(), QItemSelectionModel::SelectCurrent); + toggleFilter(pref->getStatusFilterState()); } StatusFiltersWidget::~StatusFiltersWidget() @@ -164,11 +175,13 @@ LabelFiltersList::LabelFiltersList(QWidget *parent, TransferListWidget *transfer noLabel->setData(Qt::DisplayRole, QVariant(tr("Unlabeled (0)"))); noLabel->setData(Qt::DecorationRole, IconProvider::instance()->getIcon("inode-directory")); - QStringList labelList = Preferences::instance()->getTorrentLabels(); + const Preferences* const pref = Preferences::instance(); + QStringList labelList = pref->getTorrentLabels(); for (int i=0; i < labelList.size(); ++i) addItem(labelList[i], false); setCurrentRow(0, QItemSelectionModel::SelectCurrent); + toggleFilter(pref->getLabelFilterState()); } LabelFiltersList::~LabelFiltersList() @@ -257,7 +270,6 @@ void LabelFiltersList::removeSelectedLabel() m_labels.remove(label); // Select first label setCurrentRow(0, QItemSelectionModel::SelectCurrent); - applyFilter(0); // Un display filter delete takeItem(labelRow); transferList->removeLabelFromRows(label); @@ -412,6 +424,7 @@ TrackerFiltersList::TrackerFiltersList(QWidget *parent, TransferListWidget *tran setCurrentRow(0, QItemSelectionModel::SelectCurrent); connect(m_downloader, SIGNAL(downloadFinished(QString, QString)), SLOT(handleFavicoDownload(QString, QString))); connect(m_downloader, SIGNAL(downloadFailure(QString, QString)), SLOT(handleFavicoFailure(QString, QString))); + toggleFilter(Preferences::instance()->getTrackerFilterState()); } TrackerFiltersList::~TrackerFiltersList() @@ -449,14 +462,14 @@ void TrackerFiltersList::addItem(const QString &tracker, const QString &hash) if (host == "") { trackerItem->setText(tr("Trackerless (%1)").arg(tmp.size())); if (currentRow() == 1) - emit currentRowChanged(1); + applyFilter(1); return; } trackerItem->setText(tr("%1 (%2)", "openbittorrent.com (10)").arg(host).arg(tmp.size())); if (exists) { if (currentRow() == rowFromTracker(host)) - emit currentRowChanged(currentRow()); + applyFilter(currentRow()); return; } @@ -507,7 +520,7 @@ void TrackerFiltersList::removeItem(const QString &tracker, const QString &hash) m_trackers.insert(host, tmp); if (currentRow() == row) - emit currentRowChanged(row); + applyFilter(row); } void TrackerFiltersList::changeTrackerless(bool trackerless, const QString &hash) @@ -577,7 +590,7 @@ void TrackerFiltersList::applyFilter(int row) { if (row == 0) transferList->applyTrackerFilterAll(); - else + else if (isVisible()) transferList->applyTrackerFilter(getHashes(row)); } @@ -653,41 +666,50 @@ TransferListFiltersWidget::TransferListFiltersWidget(QWidget *parent, TransferLi : QFrame(parent) , statusFilters(0) , trackerFilters(0) - , torrentsLabel(0) + , trackerLabel(0) { + Preferences* const pref = Preferences::instance(); // Construct lists QVBoxLayout *vLayout = new QVBoxLayout(this); vLayout->setContentsMargins(0, 4, 0, 0); QFont font; font.setBold(true); font.setCapitalization(QFont::SmallCaps); - torrentsLabel = new QLabel(tr("Torrents"), this); - torrentsLabel->setIndent(2); - torrentsLabel->setFont(font); - vLayout->addWidget(torrentsLabel); + QCheckBox * statusLabel = new QCheckBox(tr("Status"), this); + statusLabel->setChecked(pref->getStatusFilterState()); + statusLabel->setFont(font); + vLayout->addWidget(statusLabel); statusFilters = new StatusFiltersWidget(this, transferList); vLayout->addWidget(statusFilters); - QLabel *labelsLabel = new QLabel(tr("Labels"), this); - labelsLabel->setIndent(2); - labelsLabel->setFont(font); - vLayout->addWidget(labelsLabel); + QCheckBox *labelLabel = new QCheckBox(tr("Labels"), this); + labelLabel->setChecked(pref->getLabelFilterState()); + labelLabel->setFont(font); + vLayout->addWidget(labelLabel); LabelFiltersList *labelFilters = new LabelFiltersList(this, transferList); vLayout->addWidget(labelFilters); - QLabel *trackersLabel = new QLabel(tr("Trackers"), this); - trackersLabel->setIndent(2); - trackersLabel->setFont(font); - vLayout->addWidget(trackersLabel); + trackerLabel = new QCheckBox(tr("Trackers"), this); + trackerLabel->setChecked(pref->getTrackerFilterState()); + trackerLabel->setFont(font); + vLayout->addWidget(trackerLabel); trackerFilters = new TrackerFiltersList(this, transferList); vLayout->addWidget(trackerFilters); setLayout(vLayout); setContentsMargins(0,0,0,0); vLayout->setSpacing(2); + vLayout->addStretch(); + + connect(statusLabel, SIGNAL(toggled(bool)), statusFilters, SLOT(toggleFilter(bool))); + connect(statusLabel, SIGNAL(toggled(bool)), pref, SLOT(setStatusFilterState(const bool))); + connect(labelLabel, SIGNAL(toggled(bool)), labelFilters, SLOT(toggleFilter(bool))); + connect(labelLabel, SIGNAL(toggled(bool)), pref, SLOT(setLabelFilterState(const bool))); + connect(trackerLabel, SIGNAL(toggled(bool)), trackerFilters, SLOT(toggleFilter(bool))); + connect(trackerLabel, SIGNAL(toggled(bool)), pref, SLOT(setTrackerFilterState(const bool))); } void TransferListFiltersWidget::resizeEvent(QResizeEvent *event) { int height = event->size().height(); - int minHeight = statusFilters->height() + (3 * torrentsLabel->height()); + int minHeight = statusFilters->height() + (3 * trackerLabel->height()); trackerFilters->setMinimumHeight((height - minHeight) / 2); } diff --git a/src/gui/transferlistfilterswidget.h b/src/gui/transferlistfilterswidget.h index fdbdaf816..cfbe455c6 100644 --- a/src/gui/transferlistfilterswidget.h +++ b/src/gui/transferlistfilterswidget.h @@ -36,7 +36,7 @@ QT_BEGIN_NAMESPACE class QResizeEvent; -class QLabel; +class QCheckBox; QT_END_NAMESPACE class TransferListWidget; @@ -54,6 +54,9 @@ public: virtual QSize sizeHint() const; virtual QSize minimumSizeHint() const; +public slots: + void toggleFilter(bool checked); + protected: TransferListWidget *transferList; @@ -172,7 +175,7 @@ private: StatusFiltersWidget *statusFilters; TrackerFiltersList *trackerFilters; //for use in resizeEvent() - QLabel *torrentsLabel; + QCheckBox *trackerLabel; }; #endif // TRANSFERLISTFILTERSWIDGET_H