Browse Source

Allow to filter torrent list by save path

PR #18600.
adaptive-webui-19844
Tom 2 years ago committed by GitHub
parent
commit
0bb0829a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      src/gui/mainwindow.cpp
  2. 3
      src/gui/mainwindow.h
  3. 2
      src/gui/transferlistmodel.h
  4. 4
      src/gui/transferlistwidget.cpp
  5. 4
      src/gui/transferlistwidget.h

36
src/gui/mainwindow.cpp

@ -35,11 +35,13 @@
#include <QActionGroup> #include <QActionGroup>
#include <QClipboard> #include <QClipboard>
#include <QCloseEvent> #include <QCloseEvent>
#include <QComboBox>
#include <QDebug> #include <QDebug>
#include <QDesktopServices> #include <QDesktopServices>
#include <QFileDialog> #include <QFileDialog>
#include <QFileSystemWatcher> #include <QFileSystemWatcher>
#include <QKeyEvent> #include <QKeyEvent>
#include <QLabel>
#include <QMessageBox> #include <QMessageBox>
#include <QMetaObject> #include <QMetaObject>
#include <QMimeData> #include <QMimeData>
@ -187,15 +189,23 @@ MainWindow::MainWindow(IGUIApplication *app, WindowState initialState)
hSplitter->setChildrenCollapsible(false); hSplitter->setChildrenCollapsible(false);
hSplitter->setFrameShape(QFrame::NoFrame); hSplitter->setFrameShape(QFrame::NoFrame);
// Name filter // Torrent filter
m_searchFilter = new LineEdit(this); m_searchFilter = new LineEdit(this);
m_searchFilter->setPlaceholderText(tr("Filter torrent names...")); m_searchFilter->setPlaceholderText(tr("Filter torrents..."));
m_searchFilter->setFixedWidth(200); m_searchFilter->setFixedWidth(200);
m_searchFilter->setContextMenuPolicy(Qt::CustomContextMenu); m_searchFilter->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_searchFilter, &QWidget::customContextMenuRequested, this, &MainWindow::showFilterContextMenu); connect(m_searchFilter, &QWidget::customContextMenuRequested, this, &MainWindow::showFilterContextMenu);
m_searchFilterAction = m_ui->toolBar->insertWidget(m_ui->actionLock, m_searchFilter); m_searchFilterAction = m_ui->toolBar->insertWidget(m_ui->actionLock, m_searchFilter);
auto *filterColumnWidget = new QWidget(this);
QWidget *spacer = new QWidget(this); auto *filterLabel = new QLabel(tr("Filter by:"));
filterLabel->setMargin(7);
m_filterColumnComboBox = new QComboBox(this);
QHBoxLayout *filterColumnLayout = new QHBoxLayout(this);
filterColumnLayout->addWidget(filterLabel);
filterColumnLayout->addWidget(m_filterColumnComboBox);
filterColumnWidget->setLayout(filterColumnLayout);
m_ui->toolBar->insertWidget(m_ui->actionLock, filterColumnWidget);
auto *spacer = new QWidget(this);
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
m_ui->toolBar->insertWidget(m_searchFilterAction, spacer); m_ui->toolBar->insertWidget(m_searchFilterAction, spacer);
@ -213,8 +223,15 @@ MainWindow::MainWindow(IGUIApplication *app, WindowState initialState)
UIThemeManager::instance()->getIcon(u"folder-remote"_qs), UIThemeManager::instance()->getIcon(u"folder-remote"_qs),
#endif #endif
tr("Transfers")); tr("Transfers"));
// Filter types
connect(m_searchFilter, &LineEdit::textChanged, m_transferListWidget, &TransferListWidget::applyNameFilter); const QVector<TransferListModel::Column> filterTypes = {TransferListModel::Column::TR_NAME, TransferListModel::Column::TR_SAVE_PATH};
for (const TransferListModel::Column type : filterTypes)
{
const QString typeName = m_transferListWidget->getSourceModel()->headerData(type, Qt::Horizontal, Qt::DisplayRole).value<QString>();
m_filterColumnComboBox->addItem(typeName, type);
}
connect(m_filterColumnComboBox, &QComboBox::currentIndexChanged, this, &MainWindow::applyTransferListFilter);
connect(m_searchFilter, &LineEdit::textChanged, this, &MainWindow::applyTransferListFilter);
connect(hSplitter, &QSplitter::splitterMoved, this, &MainWindow::saveSettings); connect(hSplitter, &QSplitter::splitterMoved, this, &MainWindow::saveSettings);
connect(m_splitter, &QSplitter::splitterMoved, this, &MainWindow::saveSplitterSettings); connect(m_splitter, &QSplitter::splitterMoved, this, &MainWindow::saveSplitterSettings);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackersChanged, m_propertiesWidget, &PropertiesWidget::loadTrackers); connect(BitTorrent::Session::instance(), &BitTorrent::Session::trackersChanged, m_propertiesWidget, &PropertiesWidget::loadTrackers);
@ -670,7 +687,7 @@ void MainWindow::showFilterContextMenu()
useRegexAct->setCheckable(true); useRegexAct->setCheckable(true);
useRegexAct->setChecked(pref->getRegexAsFilteringPatternForTransferList()); useRegexAct->setChecked(pref->getRegexAsFilteringPatternForTransferList());
connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPatternForTransferList); connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPatternForTransferList);
connect(useRegexAct, &QAction::toggled, this, [this]() { m_transferListWidget->applyNameFilter(m_searchFilter->text()); }); connect(useRegexAct, &QAction::toggled, this, &MainWindow::applyTransferListFilter);
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());
} }
@ -1917,6 +1934,11 @@ void MainWindow::updatePowerManagementState()
m_pwr->setActivityState(inhibitSuspend); m_pwr->setActivityState(inhibitSuspend);
} }
void MainWindow::applyTransferListFilter()
{
m_transferListWidget->applyFilter(m_searchFilter->text(), m_filterColumnComboBox->currentData().value<TransferListModel::Column>());
}
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS) #if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
void MainWindow::checkProgramUpdate(const bool invokedByUser) void MainWindow::checkProgramUpdate(const bool invokedByUser)
{ {

3
src/gui/mainwindow.h

@ -39,6 +39,7 @@
#include "windowstate.h" #include "windowstate.h"
class QCloseEvent; class QCloseEvent;
class QComboBox;
class QFileSystemWatcher; class QFileSystemWatcher;
class QSplitter; class QSplitter;
class QTabWidget; class QTabWidget;
@ -194,6 +195,7 @@ private:
void createTorrentTriggered(const Path &path); void createTorrentTriggered(const Path &path);
void showStatusBar(bool show); void showStatusBar(bool show);
void showFiltersSidebar(bool show); void showFiltersSidebar(bool show);
void applyTransferListFilter();
Ui::MainWindow *m_ui = nullptr; Ui::MainWindow *m_ui = nullptr;
@ -219,6 +221,7 @@ private:
bool m_unlockDlgShowing = false; bool m_unlockDlgShowing = false;
LineEdit *m_searchFilter = nullptr; LineEdit *m_searchFilter = nullptr;
QAction *m_searchFilterAction = nullptr; QAction *m_searchFilterAction = nullptr;
QComboBox *m_filterColumnComboBox = nullptr;
// Widgets // Widgets
QAction *m_queueSeparator = nullptr; QAction *m_queueSeparator = nullptr;
QAction *m_queueSeparatorMenu = nullptr; QAction *m_queueSeparatorMenu = nullptr;

2
src/gui/transferlistmodel.h

@ -143,3 +143,5 @@ private:
QIcon m_stalledUPIcon; QIcon m_stalledUPIcon;
QIcon m_uploadingIcon; QIcon m_uploadingIcon;
}; };
Q_DECLARE_METATYPE(TransferListModel::Column)

4
src/gui/transferlistwidget.cpp

@ -64,7 +64,6 @@
#include "torrentoptionsdialog.h" #include "torrentoptionsdialog.h"
#include "trackerentriesdialog.h" #include "trackerentriesdialog.h"
#include "transferlistdelegate.h" #include "transferlistdelegate.h"
#include "transferlistmodel.h"
#include "transferlistsortmodel.h" #include "transferlistsortmodel.h"
#include "tristateaction.h" #include "tristateaction.h"
#include "uithememanager.h" #include "uithememanager.h"
@ -1299,8 +1298,9 @@ void TransferListWidget::applyTrackerFilter(const QSet<BitTorrent::TorrentID> &t
m_sortFilterModel->setTrackerFilter(torrentIDs); m_sortFilterModel->setTrackerFilter(torrentIDs);
} }
void TransferListWidget::applyNameFilter(const QString &name) void TransferListWidget::applyFilter(const QString &name, const TransferListModel::Column &type)
{ {
m_sortFilterModel->setFilterKeyColumn(type);
const QString pattern = (Preferences::instance()->getRegexAsFilteringPatternForTransferList() const QString pattern = (Preferences::instance()->getRegexAsFilteringPatternForTransferList()
? name : Utils::String::wildcardToRegexPattern(name)); ? name : Utils::String::wildcardToRegexPattern(name));
m_sortFilterModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption)); m_sortFilterModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption));

4
src/gui/transferlistwidget.h

@ -34,10 +34,10 @@
#include <QTreeView> #include <QTreeView>
#include "base/bittorrent/infohash.h" #include "base/bittorrent/infohash.h"
#include "transferlistmodel.h"
class MainWindow; class MainWindow;
class Path; class Path;
class TransferListModel;
class TransferListSortModel; class TransferListSortModel;
namespace BitTorrent namespace BitTorrent
@ -92,7 +92,7 @@ public slots:
void setTorrentOptions(); void setTorrentOptions();
void previewSelectedTorrents(); void previewSelectedTorrents();
void hideQueuePosColumn(bool hide); void hideQueuePosColumn(bool hide);
void applyNameFilter(const QString &name); void applyFilter(const QString &name, const TransferListModel::Column &type);
void applyStatusFilter(int f); void applyStatusFilter(int f);
void applyCategoryFilter(const QString &category); void applyCategoryFilter(const QString &category);
void applyTagFilter(const QString &tag); void applyTagFilter(const QString &tag);

Loading…
Cancel
Save