mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 05:08:05 -06:00
@@ -61,7 +61,7 @@ enum PluginColumns
|
||||
PLUGIN_ID
|
||||
};
|
||||
|
||||
PluginSelectDlg::PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent)
|
||||
PluginSelectDlg::PluginSelectDlg(SearchPluginManager *pluginManager, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, m_ui(new Ui::PluginSelectDlg())
|
||||
, m_pluginManager(pluginManager)
|
||||
@@ -90,12 +90,12 @@ PluginSelectDlg::PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent)
|
||||
|
||||
loadSupportedSearchPlugins();
|
||||
|
||||
connect(m_pluginManager, &SearchEngine::pluginInstalled, this, &PluginSelectDlg::pluginInstalled);
|
||||
connect(m_pluginManager, &SearchEngine::pluginInstallationFailed, this, &PluginSelectDlg::pluginInstallationFailed);
|
||||
connect(m_pluginManager, &SearchEngine::pluginUpdated, this, &PluginSelectDlg::pluginUpdated);
|
||||
connect(m_pluginManager, &SearchEngine::pluginUpdateFailed, this, &PluginSelectDlg::pluginUpdateFailed);
|
||||
connect(m_pluginManager, &SearchEngine::checkForUpdatesFinished, this, &PluginSelectDlg::checkForUpdatesFinished);
|
||||
connect(m_pluginManager, &SearchEngine::checkForUpdatesFailed, this, &PluginSelectDlg::checkForUpdatesFailed);
|
||||
connect(m_pluginManager, &SearchPluginManager::pluginInstalled, this, &PluginSelectDlg::pluginInstalled);
|
||||
connect(m_pluginManager, &SearchPluginManager::pluginInstallationFailed, this, &PluginSelectDlg::pluginInstallationFailed);
|
||||
connect(m_pluginManager, &SearchPluginManager::pluginUpdated, this, &PluginSelectDlg::pluginUpdated);
|
||||
connect(m_pluginManager, &SearchPluginManager::pluginUpdateFailed, this, &PluginSelectDlg::pluginUpdateFailed);
|
||||
connect(m_pluginManager, &SearchPluginManager::checkForUpdatesFinished, this, &PluginSelectDlg::checkForUpdatesFinished);
|
||||
connect(m_pluginManager, &SearchPluginManager::checkForUpdatesFailed, this, &PluginSelectDlg::checkForUpdatesFailed);
|
||||
|
||||
Utils::Gui::resize(this);
|
||||
show();
|
||||
@@ -387,7 +387,7 @@ void PluginSelectDlg::iconDownloaded(const QString &url, QString filePath)
|
||||
if (!plugin) continue;
|
||||
|
||||
QString iconPath = QString("%1/%2.%3")
|
||||
.arg(SearchEngine::pluginsLocation())
|
||||
.arg(SearchPluginManager::pluginsLocation())
|
||||
.arg(id)
|
||||
.arg(url.endsWith(".ico", Qt::CaseInsensitive) ? "ico" : "png");
|
||||
if (QFile::copy(filePath, iconPath)) {
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "base/searchengine.h"
|
||||
#include "base/search/searchpluginmanager.h"
|
||||
|
||||
class QDropEvent;
|
||||
class QStringList;
|
||||
@@ -50,7 +50,7 @@ class PluginSelectDlg: public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent = 0);
|
||||
explicit PluginSelectDlg(SearchPluginManager *pluginManager, QWidget *parent = 0);
|
||||
~PluginSelectDlg();
|
||||
|
||||
QList<QTreeWidgetItem*> findItemsWithUrl(QString url);
|
||||
@@ -89,7 +89,7 @@ private:
|
||||
void finishPluginUpdate();
|
||||
|
||||
Ui::PluginSelectDlg *m_ui;
|
||||
SearchEngine *m_pluginManager;
|
||||
SearchPluginManager *m_pluginManager;
|
||||
QStringList m_updatedPlugins;
|
||||
int m_asyncOps;
|
||||
int m_pendingUpdates;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2006 Christophe Dumez
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2018 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -24,37 +25,41 @@
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
#include <QMenu>
|
||||
#include <QTreeView>
|
||||
#include <QStandardItemModel>
|
||||
#include <QHeaderView>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QLabel>
|
||||
#include <QPalette>
|
||||
#include <QVBoxLayout>
|
||||
#include <QTableView>
|
||||
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/settingvalue.h"
|
||||
#include "guiiconprovider.h"
|
||||
#include "searchsortmodel.h"
|
||||
#include "searchlistdelegate.h"
|
||||
#include "searchwidget.h"
|
||||
#include "searchtab.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QClipboard>
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QMenu>
|
||||
#include <QPalette>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTableView>
|
||||
#include <QTreeView>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/search/searchdownloadhandler.h"
|
||||
#include "base/search/searchhandler.h"
|
||||
#include "base/search/searchpluginmanager.h"
|
||||
#include "base/settingvalue.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "addnewtorrentdialog.h"
|
||||
#include "guiiconprovider.h"
|
||||
#include "searchlistdelegate.h"
|
||||
#include "searchsortmodel.h"
|
||||
#include "ui_searchtab.h"
|
||||
|
||||
SearchTab::SearchTab(SearchWidget *parent)
|
||||
SearchTab::SearchTab(SearchHandler *searchHandler, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_ui(new Ui::SearchTab())
|
||||
, m_parent(parent)
|
||||
, m_status(Status::NoResults)
|
||||
, m_ui(new Ui::SearchTab)
|
||||
, m_searchHandler(searchHandler)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
@@ -84,6 +89,7 @@ SearchTab::SearchTab(SearchWidget *parent)
|
||||
m_proxyModel = new SearchSortModel(this);
|
||||
m_proxyModel->setDynamicSortFilter(true);
|
||||
m_proxyModel->setSourceModel(m_searchListModel);
|
||||
m_proxyModel->setNameFilter(searchHandler->pattern());
|
||||
m_ui->resultsBrowser->setModel(m_proxyModel);
|
||||
|
||||
m_searchDelegate = new SearchListDelegate(this);
|
||||
@@ -113,30 +119,41 @@ SearchTab::SearchTab(SearchWidget *parent)
|
||||
if ((m_ui->resultsBrowser->columnWidth(i) <= 0) && !m_ui->resultsBrowser->isColumnHidden(i))
|
||||
m_ui->resultsBrowser->resizeColumnToContents(i);
|
||||
|
||||
// Connect signals to slots (search part)
|
||||
connect(m_ui->resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadItem(const QModelIndex&)));
|
||||
|
||||
header()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(header(), SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(displayToggleColumnsMenu(const QPoint &)));
|
||||
connect(header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveSettings()));
|
||||
connect(header(), SIGNAL(sectionMoved(int, int, int)), this, SLOT(saveSettings()));
|
||||
connect(header(), SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(saveSettings()));
|
||||
connect(header(), &QWidget::customContextMenuRequested, this, &SearchTab::displayToggleColumnsMenu);
|
||||
connect(header(), &QHeaderView::sectionResized, this, &SearchTab::saveSettings);
|
||||
connect(header(), &QHeaderView::sectionMoved, this, &SearchTab::saveSettings);
|
||||
connect(header(), &QHeaderView::sortIndicatorChanged, this, &SearchTab::saveSettings);
|
||||
|
||||
fillFilterComboBoxes();
|
||||
|
||||
updateFilter();
|
||||
|
||||
connect(m_ui->filterMode, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
|
||||
connect(m_ui->minSeeds, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
|
||||
connect(m_ui->minSeeds, SIGNAL(valueChanged(int)), this, SLOT(updateFilter()));
|
||||
connect(m_ui->maxSeeds, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
|
||||
connect(m_ui->maxSeeds, SIGNAL(valueChanged(int)), this, SLOT(updateFilter()));
|
||||
connect(m_ui->minSize, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
|
||||
connect(m_ui->minSize, SIGNAL(valueChanged(double)), this, SLOT(updateFilter()));
|
||||
connect(m_ui->maxSize, SIGNAL(editingFinished()), this, SLOT(updateFilter()));
|
||||
connect(m_ui->maxSize, SIGNAL(valueChanged(double)), this, SLOT(updateFilter()));
|
||||
connect(m_ui->minSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
|
||||
connect(m_ui->maxSizeUnit, SIGNAL(currentIndexChanged(int)), this, SLOT(updateFilter()));
|
||||
connect(m_ui->filterMode, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
|
||||
, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->minSeeds, &QAbstractSpinBox::editingFinished, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->minSeeds, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged)
|
||||
, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->maxSeeds, &QAbstractSpinBox::editingFinished, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->maxSeeds, static_cast<void(QSpinBox::*)(int)>(&QSpinBox::valueChanged)
|
||||
, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->minSize, &QAbstractSpinBox::editingFinished, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->minSize, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged)
|
||||
, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->maxSize, &QAbstractSpinBox::editingFinished, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->maxSize, static_cast<void(QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged)
|
||||
, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->minSizeUnit, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
|
||||
, this, &SearchTab::updateFilter);
|
||||
connect(m_ui->maxSizeUnit, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
|
||||
, this, &SearchTab::updateFilter);
|
||||
|
||||
connect(m_ui->resultsBrowser, &QAbstractItemView::doubleClicked, this, &SearchTab::onItemDoubleClicked);
|
||||
|
||||
connect(searchHandler, &SearchHandler::newSearchResults, this, &SearchTab::appendSearchResults);
|
||||
connect(searchHandler, &SearchHandler::searchFinished, this, &SearchTab::searchFinished);
|
||||
connect(searchHandler, &SearchHandler::searchFailed, this, &SearchTab::searchFailed);
|
||||
connect(this, &QObject::destroyed, searchHandler, &QObject::deleteLater);
|
||||
}
|
||||
|
||||
SearchTab::~SearchTab()
|
||||
@@ -145,34 +162,17 @@ SearchTab::~SearchTab()
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void SearchTab::downloadItem(const QModelIndex &index)
|
||||
void SearchTab::onItemDoubleClicked(const QModelIndex &index)
|
||||
{
|
||||
QString torrentUrl = m_proxyModel->data(m_proxyModel->index(index.row(), SearchSortModel::DL_LINK)).toString();
|
||||
QString siteUrl = m_proxyModel->data(m_proxyModel->index(index.row(), SearchSortModel::ENGINE_URL)).toString();
|
||||
setRowColor(index.row(), QApplication::palette().color(QPalette::LinkVisited));
|
||||
m_parent->downloadTorrent(siteUrl, torrentUrl);
|
||||
downloadTorrent(index);
|
||||
}
|
||||
|
||||
QHeaderView* SearchTab::header() const
|
||||
QHeaderView *SearchTab::header() const
|
||||
{
|
||||
return m_ui->resultsBrowser->header();
|
||||
}
|
||||
|
||||
QTreeView* SearchTab::getCurrentTreeView() const
|
||||
{
|
||||
return m_ui->resultsBrowser;
|
||||
}
|
||||
|
||||
SearchSortModel* SearchTab::getCurrentSearchListProxy() const
|
||||
{
|
||||
return m_proxyModel;
|
||||
}
|
||||
|
||||
QStandardItemModel* SearchTab::getCurrentSearchListModel() const
|
||||
{
|
||||
return m_searchListModel;
|
||||
}
|
||||
|
||||
// Set the color of a row in data model
|
||||
void SearchTab::setRowColor(int row, const QColor &color)
|
||||
{
|
||||
@@ -188,37 +188,112 @@ SearchTab::Status SearchTab::status() const
|
||||
return m_status;
|
||||
}
|
||||
|
||||
int SearchTab::visibleResultsCount() const
|
||||
{
|
||||
return m_proxyModel->rowCount();
|
||||
}
|
||||
|
||||
void SearchTab::cancelSearch()
|
||||
{
|
||||
m_searchHandler->cancelSearch();
|
||||
}
|
||||
|
||||
void SearchTab::downloadTorrents()
|
||||
{
|
||||
const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()};
|
||||
for (const QModelIndex &rowIndex : rows)
|
||||
downloadTorrent(rowIndex);
|
||||
}
|
||||
|
||||
void SearchTab::openTorrentPages()
|
||||
{
|
||||
const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()};
|
||||
for (const QModelIndex &rowIndex : rows) {
|
||||
const QString descrLink = m_proxyModel->data(
|
||||
m_proxyModel->index(rowIndex.row(), SearchSortModel::DESC_LINK)).toString();
|
||||
if (!descrLink.isEmpty())
|
||||
QDesktopServices::openUrl(QUrl::fromEncoded(descrLink.toUtf8()));
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTab::copyTorrentURLs()
|
||||
{
|
||||
const QModelIndexList rows {m_ui->resultsBrowser->selectionModel()->selectedRows()};
|
||||
QStringList urls;
|
||||
for (const QModelIndex &rowIndex : rows) {
|
||||
const QString descrLink = m_proxyModel->data(
|
||||
m_proxyModel->index(rowIndex.row(), SearchSortModel::DESC_LINK)).toString();
|
||||
if (!descrLink.isEmpty())
|
||||
urls << descrLink;
|
||||
}
|
||||
|
||||
if (!urls.empty()) {
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setText(urls.join("\n"));
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTab::setStatus(Status value)
|
||||
{
|
||||
if (m_status == value) return;
|
||||
|
||||
m_status = value;
|
||||
setStatusTip(statusText(value));
|
||||
const int thisTabIndex = m_parent->searchTabs()->indexOf(this);
|
||||
m_parent->searchTabs()->setTabToolTip(thisTabIndex, statusTip());
|
||||
m_parent->searchTabs()->setTabIcon(thisTabIndex, GuiIconProvider::instance()->getIcon(statusIconName(value)));
|
||||
emit statusChanged();
|
||||
}
|
||||
|
||||
void SearchTab::downloadTorrent(const QModelIndex &rowIndex)
|
||||
{
|
||||
const QString torrentUrl = m_proxyModel->data(
|
||||
m_proxyModel->index(rowIndex.row(), SearchSortModel::DL_LINK)).toString();
|
||||
const QString siteUrl = m_proxyModel->data(
|
||||
m_proxyModel->index(rowIndex.row(), SearchSortModel::ENGINE_URL)).toString();
|
||||
|
||||
if (torrentUrl.startsWith("bc://bt/", Qt::CaseInsensitive) || torrentUrl.startsWith("magnet:", Qt::CaseInsensitive)) {
|
||||
addTorrentToSession(torrentUrl);
|
||||
}
|
||||
else {
|
||||
SearchDownloadHandler *downloadHandler = m_searchHandler->manager()->downloadTorrent(siteUrl, torrentUrl);
|
||||
connect(downloadHandler, &SearchDownloadHandler::downloadFinished, this, &SearchTab::addTorrentToSession);
|
||||
connect(downloadHandler, &SearchDownloadHandler::downloadFinished, downloadHandler, &SearchDownloadHandler::deleteLater);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTab::addTorrentToSession(const QString &source)
|
||||
{
|
||||
if (source.isEmpty()) return;
|
||||
|
||||
if (AddNewTorrentDialog::isEnabled())
|
||||
AddNewTorrentDialog::show(source, this);
|
||||
else
|
||||
BitTorrent::Session::instance()->addTorrent(source);
|
||||
}
|
||||
|
||||
void SearchTab::updateResultsCount()
|
||||
{
|
||||
const int totalResults = getCurrentSearchListModel() ? getCurrentSearchListModel()->rowCount(QModelIndex()) : 0;
|
||||
const int filteredResults = getCurrentSearchListProxy() ? getCurrentSearchListProxy()->rowCount(QModelIndex()) : totalResults;
|
||||
const int totalResults = m_searchListModel->rowCount();
|
||||
const int filteredResults = m_proxyModel->rowCount();
|
||||
m_ui->resultsLbl->setText(tr("Results (showing <i>%1</i> out of <i>%2</i>):", "i.e: Search results")
|
||||
.arg(filteredResults).arg(totalResults));
|
||||
|
||||
m_noSearchResults = (totalResults == 0);
|
||||
emit resultsCountUpdated();
|
||||
}
|
||||
|
||||
void SearchTab::updateFilter()
|
||||
{
|
||||
using Utils::Misc::SizeUnit;
|
||||
SearchSortModel* filterModel = getCurrentSearchListProxy();
|
||||
filterModel->enableNameFilter(filteringMode() == NameFilteringMode::OnlyNames);
|
||||
|
||||
m_proxyModel->enableNameFilter(filteringMode() == NameFilteringMode::OnlyNames);
|
||||
// we update size and seeds filter parameters in the model even if they are disabled
|
||||
filterModel->setSeedsFilter(m_ui->minSeeds->value(), m_ui->maxSeeds->value());
|
||||
filterModel->setSizeFilter(
|
||||
m_proxyModel->setSeedsFilter(m_ui->minSeeds->value(), m_ui->maxSeeds->value());
|
||||
m_proxyModel->setSizeFilter(
|
||||
sizeInBytes(m_ui->minSize->value(), static_cast<SizeUnit>(m_ui->minSizeUnit->currentIndex())),
|
||||
sizeInBytes(m_ui->maxSize->value(), static_cast<SizeUnit>(m_ui->maxSizeUnit->currentIndex())));
|
||||
|
||||
nameFilteringModeSetting() = filteringMode();
|
||||
|
||||
filterModel->invalidate();
|
||||
m_proxyModel->invalidate();
|
||||
updateResultsCount();
|
||||
}
|
||||
|
||||
@@ -273,24 +348,6 @@ QString SearchTab::statusText(SearchTab::Status st)
|
||||
}
|
||||
}
|
||||
|
||||
QString SearchTab::statusIconName(SearchTab::Status st)
|
||||
{
|
||||
switch (st) {
|
||||
case Status::Ongoing:
|
||||
return QLatin1String("task-ongoing");
|
||||
case Status::Finished:
|
||||
return QLatin1String("task-complete");
|
||||
case Status::Aborted:
|
||||
return QLatin1String("task-reject");
|
||||
case Status::Error:
|
||||
return QLatin1String("task-attention");
|
||||
case Status::NoResults:
|
||||
return QLatin1String("task-attention");
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
|
||||
SearchTab::NameFilteringMode SearchTab::filteringMode() const
|
||||
{
|
||||
return static_cast<NameFilteringMode>(m_ui->filterMode->itemData(m_ui->filterMode->currentIndex()).toInt());
|
||||
@@ -341,6 +398,40 @@ void SearchTab::displayToggleColumnsMenu(const QPoint&)
|
||||
}
|
||||
}
|
||||
|
||||
void SearchTab::searchFinished(bool cancelled)
|
||||
{
|
||||
if (cancelled)
|
||||
setStatus(Status::Aborted);
|
||||
else if (m_noSearchResults)
|
||||
setStatus(Status::NoResults);
|
||||
else
|
||||
setStatus(Status::Finished);
|
||||
}
|
||||
|
||||
void SearchTab::searchFailed()
|
||||
{
|
||||
setStatus(Status::Error);
|
||||
}
|
||||
|
||||
void SearchTab::appendSearchResults(const QList<SearchResult> &results)
|
||||
{
|
||||
for (const SearchResult &result : results) {
|
||||
// Add item to search result list
|
||||
int row = m_searchListModel->rowCount();
|
||||
m_searchListModel->insertRow(row);
|
||||
|
||||
m_searchListModel->setData(m_searchListModel->index(row, SearchSortModel::NAME), result.fileName); // Name
|
||||
m_searchListModel->setData(m_searchListModel->index(row, SearchSortModel::DL_LINK), result.fileUrl); // download URL
|
||||
m_searchListModel->setData(m_searchListModel->index(row, SearchSortModel::SIZE), result.fileSize); // Size
|
||||
m_searchListModel->setData(m_searchListModel->index(row, SearchSortModel::SEEDS), result.nbSeeders); // Seeders
|
||||
m_searchListModel->setData(m_searchListModel->index(row, SearchSortModel::LEECHES), result.nbLeechers); // Leechers
|
||||
m_searchListModel->setData(m_searchListModel->index(row, SearchSortModel::ENGINE_URL), result.siteUrl); // Search site URL
|
||||
m_searchListModel->setData(m_searchListModel->index(row, SearchSortModel::DESC_LINK), result.descrLink); // Description Link
|
||||
}
|
||||
|
||||
updateResultsCount();
|
||||
}
|
||||
|
||||
CachedSettingValue<SearchTab::NameFilteringMode> &SearchTab::nameFilteringModeSetting()
|
||||
{
|
||||
static CachedSettingValue<NameFilteringMode> setting("Search/FilteringMode", NameFilteringMode::OnlyNames);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt4 and libtorrent.
|
||||
* Copyright (C) 2006 Christophe Dumez
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2018 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -24,12 +25,9 @@
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#ifndef SEARCHTAB_H
|
||||
#define SEARCHTAB_H
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
@@ -38,46 +36,36 @@
|
||||
|
||||
class QLabel;
|
||||
class QModelIndex;
|
||||
class QTreeView;
|
||||
class QHeaderView;
|
||||
class QStandardItem;
|
||||
class QStandardItemModel;
|
||||
class QVBoxLayout;
|
||||
|
||||
template <typename T> class CachedSettingValue;
|
||||
|
||||
class SearchHandler;
|
||||
class SearchSortModel;
|
||||
class SearchListDelegate;
|
||||
class SearchWidget;
|
||||
struct SearchResult;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class SearchTab;
|
||||
}
|
||||
|
||||
class SearchTab: public QWidget
|
||||
class SearchTab : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(SearchTab)
|
||||
|
||||
public:
|
||||
|
||||
enum class NameFilteringMode
|
||||
{
|
||||
Everywhere,
|
||||
OnlyNames
|
||||
};
|
||||
|
||||
Q_ENUM(NameFilteringMode)
|
||||
|
||||
explicit SearchTab(SearchWidget *parent);
|
||||
~SearchTab();
|
||||
|
||||
QStandardItemModel* getCurrentSearchListModel() const;
|
||||
SearchSortModel* getCurrentSearchListProxy() const;
|
||||
QTreeView* getCurrentTreeView() const;
|
||||
QHeaderView* header() const;
|
||||
|
||||
void setRowColor(int row, const QColor &color);
|
||||
|
||||
enum class Status
|
||||
{
|
||||
Ongoing,
|
||||
@@ -87,36 +75,50 @@ public:
|
||||
NoResults
|
||||
};
|
||||
|
||||
void setStatus(Status value);
|
||||
explicit SearchTab(SearchHandler *searchHandler, QWidget *parent = nullptr);
|
||||
~SearchTab() override;
|
||||
|
||||
Status status() const;
|
||||
int visibleResultsCount() const;
|
||||
|
||||
void updateResultsCount();
|
||||
void cancelSearch();
|
||||
|
||||
public slots:
|
||||
void downloadItem(const QModelIndex &index);
|
||||
void downloadTorrents();
|
||||
void openTorrentPages();
|
||||
void copyTorrentURLs();
|
||||
|
||||
private slots:
|
||||
signals:
|
||||
void resultsCountUpdated();
|
||||
void statusChanged();
|
||||
|
||||
private:
|
||||
void loadSettings();
|
||||
void saveSettings() const;
|
||||
void updateFilter();
|
||||
void displayToggleColumnsMenu(const QPoint&);
|
||||
|
||||
private:
|
||||
void onItemDoubleClicked(const QModelIndex &index);
|
||||
void searchFinished(bool cancelled);
|
||||
void searchFailed();
|
||||
void appendSearchResults(const QList<SearchResult> &results);
|
||||
void updateResultsCount();
|
||||
void setStatus(Status value);
|
||||
void downloadTorrent(const QModelIndex &rowIndex);
|
||||
void addTorrentToSession(const QString &source);
|
||||
void fillFilterComboBoxes();
|
||||
NameFilteringMode filteringMode() const;
|
||||
static QString statusText(Status st);
|
||||
static QString statusIconName(Status st);
|
||||
QHeaderView *header() const;
|
||||
void setRowColor(int row, const QColor &color);
|
||||
|
||||
static QString statusText(Status st);
|
||||
static CachedSettingValue<NameFilteringMode>& nameFilteringModeSetting();
|
||||
|
||||
Ui::SearchTab *m_ui;
|
||||
SearchHandler *m_searchHandler;
|
||||
QStandardItemModel *m_searchListModel;
|
||||
SearchSortModel *m_proxyModel;
|
||||
SearchListDelegate *m_searchDelegate;
|
||||
SearchWidget *m_parent;
|
||||
Status m_status;
|
||||
Status m_status = Status::Ongoing;
|
||||
bool m_noSearchResults = true;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(SearchTab::NameFilteringMode)
|
||||
|
||||
#endif // SEARCHTAB_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2015, 2018 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -25,59 +25,76 @@
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#include "searchwidget.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QMessageBox>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTimer>
|
||||
#include <QDir>
|
||||
#include <QMenu>
|
||||
#include <QClipboard>
|
||||
#include <QMimeData>
|
||||
#include <QStandardItemModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QFileDialog>
|
||||
#include <QDesktopServices>
|
||||
#include <QClipboard>
|
||||
#include <QProcess>
|
||||
#include <QDebug>
|
||||
#include <QTextStream>
|
||||
#include <QTreeView>
|
||||
|
||||
#include <iostream>
|
||||
#ifdef Q_OS_WIN
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QHeaderView>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QMimeData>
|
||||
#include <QProcess>
|
||||
#include <QSignalMapper>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStandardItemModel>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
#include <QTreeView>
|
||||
|
||||
#include "base/bittorrent/session.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/search/searchpluginmanager.h"
|
||||
#include "base/search/searchhandler.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/searchengine.h"
|
||||
#include "searchlistdelegate.h"
|
||||
#include "mainwindow.h"
|
||||
#include "addnewtorrentdialog.h"
|
||||
#include "guiiconprovider.h"
|
||||
#include "mainwindow.h"
|
||||
#include "pluginselectdlg.h"
|
||||
#include "searchlistdelegate.h"
|
||||
#include "searchsortmodel.h"
|
||||
#include "searchtab.h"
|
||||
|
||||
#include "ui_searchwidget.h"
|
||||
|
||||
#define SEARCHHISTORY_MAXSIZE 50
|
||||
#define URL_COLUMN 5
|
||||
|
||||
namespace
|
||||
{
|
||||
QString statusIconName(SearchTab::Status st)
|
||||
{
|
||||
switch (st) {
|
||||
case SearchTab::Status::Ongoing:
|
||||
return QLatin1String("task-ongoing");
|
||||
case SearchTab::Status::Finished:
|
||||
return QLatin1String("task-complete");
|
||||
case SearchTab::Status::Aborted:
|
||||
return QLatin1String("task-reject");
|
||||
case SearchTab::Status::Error:
|
||||
return QLatin1String("task-attention");
|
||||
case SearchTab::Status::NoResults:
|
||||
return QLatin1String("task-attention");
|
||||
default:
|
||||
return QString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SearchWidget::SearchWidget(MainWindow *mainWindow)
|
||||
: QWidget(mainWindow)
|
||||
, m_ui(new Ui::SearchWidget())
|
||||
, m_tabStatusChangedMapper(new QSignalMapper(this))
|
||||
, m_mainWindow(mainWindow)
|
||||
, m_isNewQueryString(false)
|
||||
, m_noSearchResults(true)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
@@ -113,42 +130,42 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
|
||||
m_ui->tabWidget->setIconSize(iconSize);
|
||||
#endif
|
||||
connect(m_ui->tabWidget, &QTabWidget::tabCloseRequested, this, &SearchWidget::closeTab);
|
||||
connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SearchWidget::tabChanged);
|
||||
|
||||
m_searchEngine = new SearchEngine;
|
||||
connect(m_searchEngine, &SearchEngine::searchStarted, this, &SearchWidget::searchStarted);
|
||||
connect(m_searchEngine, &SearchEngine::newSearchResults, this, &SearchWidget::appendSearchResults);
|
||||
connect(m_searchEngine, &SearchEngine::searchFinished, this, &SearchWidget::searchFinished);
|
||||
connect(m_searchEngine, &SearchEngine::searchFailed, this, &SearchWidget::searchFailed);
|
||||
connect(m_searchEngine, &SearchEngine::torrentFileDownloaded, this, &SearchWidget::addTorrentToSession);
|
||||
connect(m_tabStatusChangedMapper, static_cast<void (QSignalMapper::*)(QWidget *)>(&QSignalMapper::mapped)
|
||||
, this, &SearchWidget::tabStatusChanged);
|
||||
|
||||
// NOTE: Although SearchManager is Application-wide component now, we still create it the legacy way.
|
||||
auto *searchManager = new SearchPluginManager;
|
||||
const auto onPluginChanged = [this]()
|
||||
{
|
||||
fillCatCombobox();
|
||||
fillPluginComboBox();
|
||||
selectActivePage();
|
||||
};
|
||||
connect(m_searchEngine, &SearchEngine::pluginInstalled, this, onPluginChanged);
|
||||
connect(m_searchEngine, &SearchEngine::pluginUninstalled, this, onPluginChanged);
|
||||
connect(m_searchEngine, &SearchEngine::pluginUpdated, this, onPluginChanged);
|
||||
connect(m_searchEngine, &SearchEngine::pluginEnabled, this, onPluginChanged);
|
||||
connect(searchManager, &SearchPluginManager::pluginInstalled, this, onPluginChanged);
|
||||
connect(searchManager, &SearchPluginManager::pluginUninstalled, this, onPluginChanged);
|
||||
connect(searchManager, &SearchPluginManager::pluginUpdated, this, onPluginChanged);
|
||||
connect(searchManager, &SearchPluginManager::pluginEnabled, this, onPluginChanged);
|
||||
|
||||
// Fill in category combobox
|
||||
onPluginChanged();
|
||||
|
||||
connect(m_ui->m_searchPattern, &LineEdit::returnPressed, m_ui->searchButton, &QPushButton::click);
|
||||
connect(m_ui->m_searchPattern, &LineEdit::textEdited, this, &SearchWidget::searchTextEdited);
|
||||
connect(m_ui->selectPlugin, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, &SearchWidget::selectMultipleBox);
|
||||
connect(m_ui->selectPlugin, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
|
||||
, this, &SearchWidget::selectMultipleBox);
|
||||
}
|
||||
|
||||
void SearchWidget::fillCatCombobox()
|
||||
{
|
||||
m_ui->comboCategory->clear();
|
||||
m_ui->comboCategory->addItem(SearchEngine::categoryFullName("all"), QVariant("all"));
|
||||
m_ui->comboCategory->addItem(SearchPluginManager::categoryFullName("all"), QVariant("all"));
|
||||
|
||||
using QStrPair = QPair<QString, QString>;
|
||||
QList<QStrPair> tmpList;
|
||||
foreach (const QString &cat, m_searchEngine->supportedCategories())
|
||||
tmpList << qMakePair(SearchEngine::categoryFullName(cat), cat);
|
||||
foreach (const QString &cat, SearchPluginManager::instance()->supportedCategories())
|
||||
tmpList << qMakePair(SearchPluginManager::categoryFullName(cat), cat);
|
||||
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (QString::localeAwareCompare(l.first, r.first) < 0); });
|
||||
|
||||
foreach (const QStrPair &p, tmpList) {
|
||||
@@ -169,8 +186,8 @@ void SearchWidget::fillPluginComboBox()
|
||||
|
||||
using QStrPair = QPair<QString, QString>;
|
||||
QList<QStrPair> tmpList;
|
||||
foreach (const QString &name, m_searchEngine->enabledPlugins())
|
||||
tmpList << qMakePair(m_searchEngine->pluginFullName(name), name);
|
||||
foreach (const QString &name, SearchPluginManager::instance()->enabledPlugins())
|
||||
tmpList << qMakePair(SearchPluginManager::instance()->pluginFullName(name), name);
|
||||
std::sort(tmpList.begin(), tmpList.end(), [](const QStrPair &l, const QStrPair &r) { return (l.first < r.first); } );
|
||||
|
||||
foreach (const QStrPair &p, tmpList)
|
||||
@@ -192,7 +209,7 @@ QString SearchWidget::selectedPlugin() const
|
||||
|
||||
void SearchWidget::selectActivePage()
|
||||
{
|
||||
if (m_searchEngine->allPlugins().isEmpty()) {
|
||||
if (SearchPluginManager::instance()->allPlugins().isEmpty()) {
|
||||
m_ui->stackedPages->setCurrentWidget(m_ui->emptyPage);
|
||||
m_ui->m_searchPattern->setEnabled(false);
|
||||
m_ui->comboCategory->setEnabled(false);
|
||||
@@ -211,36 +228,30 @@ void SearchWidget::selectActivePage()
|
||||
SearchWidget::~SearchWidget()
|
||||
{
|
||||
qDebug("Search destruction");
|
||||
delete m_searchEngine;
|
||||
delete SearchPluginManager::instance();
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void SearchWidget::downloadTorrent(const QString &siteUrl, const QString &url)
|
||||
void SearchWidget::updateButtons()
|
||||
{
|
||||
if (url.startsWith("bc://bt/", Qt::CaseInsensitive) || url.startsWith("magnet:", Qt::CaseInsensitive))
|
||||
addTorrentToSession(url);
|
||||
else
|
||||
m_searchEngine->downloadTorrent(siteUrl, url);
|
||||
if (m_currentSearchTab && (m_currentSearchTab->visibleResultsCount() > 0)) {
|
||||
m_ui->downloadButton->setEnabled(true);
|
||||
m_ui->goToDescBtn->setEnabled(true);
|
||||
m_ui->copyURLBtn->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
m_ui->downloadButton->setEnabled(false);
|
||||
m_ui->goToDescBtn->setEnabled(false);
|
||||
m_ui->copyURLBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void SearchWidget::tab_changed(int t)
|
||||
void SearchWidget::tabChanged(int index)
|
||||
{
|
||||
//when we switch from a tab that is not empty to another that is empty the download button
|
||||
//doesn't have to be available
|
||||
if (t > -1) {
|
||||
//-1 = no more tab
|
||||
m_currentSearchTab = m_allTabs.at(m_ui->tabWidget->currentIndex());
|
||||
if (m_currentSearchTab->getCurrentSearchListModel()->rowCount()) {
|
||||
m_ui->downloadButton->setEnabled(true);
|
||||
m_ui->goToDescBtn->setEnabled(true);
|
||||
m_ui->copyURLBtn->setEnabled(true);
|
||||
}
|
||||
else {
|
||||
m_ui->downloadButton->setEnabled(false);
|
||||
m_ui->goToDescBtn->setEnabled(false);
|
||||
m_ui->copyURLBtn->setEnabled(false);
|
||||
}
|
||||
}
|
||||
// when we switch from a tab that is not empty to another that is empty
|
||||
// the download button doesn't have to be available
|
||||
m_currentSearchTab = (index < 0 ? nullptr : m_allTabs.at(m_ui->tabWidget->currentIndex()));
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void SearchWidget::selectMultipleBox(int index)
|
||||
@@ -250,17 +261,9 @@ void SearchWidget::selectMultipleBox(int index)
|
||||
on_pluginsButton_clicked();
|
||||
}
|
||||
|
||||
void SearchWidget::addTorrentToSession(const QString &source)
|
||||
{
|
||||
if (AddNewTorrentDialog::isEnabled())
|
||||
AddNewTorrentDialog::show(source, this);
|
||||
else
|
||||
BitTorrent::Session::instance()->addTorrent(source);
|
||||
}
|
||||
|
||||
void SearchWidget::on_pluginsButton_clicked()
|
||||
{
|
||||
new PluginSelectDlg(m_searchEngine, this);
|
||||
new PluginSelectDlg(SearchPluginManager::instance(), this);
|
||||
}
|
||||
|
||||
void SearchWidget::searchTextEdited(QString)
|
||||
@@ -275,11 +278,6 @@ void SearchWidget::giveFocusToSearchInput()
|
||||
m_ui->m_searchPattern->setFocus();
|
||||
}
|
||||
|
||||
QTabWidget *SearchWidget::searchTabs() const
|
||||
{
|
||||
return m_ui->tabWidget;
|
||||
}
|
||||
|
||||
// Function called when we click on search button
|
||||
void SearchWidget::on_searchButton_clicked()
|
||||
{
|
||||
@@ -288,9 +286,8 @@ void SearchWidget::on_searchButton_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_searchEngine->isActive()) {
|
||||
m_searchEngine->cancelSearch();
|
||||
|
||||
if (m_activeSearchTab) {
|
||||
m_activeSearchTab->cancelSearch();
|
||||
if (!m_isNewQueryString) {
|
||||
m_ui->searchButton->setText(tr("Search"));
|
||||
return;
|
||||
@@ -306,173 +303,84 @@ void SearchWidget::on_searchButton_clicked()
|
||||
return;
|
||||
}
|
||||
|
||||
// Tab Addition
|
||||
m_currentSearchTab = new SearchTab(this);
|
||||
m_activeSearchTab = m_currentSearchTab;
|
||||
m_allTabs.append(m_currentSearchTab);
|
||||
QString tabName = pattern;
|
||||
tabName.replace(QRegExp("&{1}"), "&&");
|
||||
m_ui->tabWidget->addTab(m_currentSearchTab, tabName);
|
||||
m_ui->tabWidget->setCurrentWidget(m_currentSearchTab);
|
||||
m_currentSearchTab->getCurrentSearchListProxy()->setNameFilter(pattern);
|
||||
|
||||
QStringList plugins;
|
||||
if (selectedPlugin() == "all") plugins = m_searchEngine->allPlugins();
|
||||
else if (selectedPlugin() == "enabled") plugins = m_searchEngine->enabledPlugins();
|
||||
else if (selectedPlugin() == "multi") plugins = m_searchEngine->enabledPlugins();
|
||||
if (selectedPlugin() == "all") plugins = SearchPluginManager::instance()->allPlugins();
|
||||
else if (selectedPlugin() == "enabled") plugins = SearchPluginManager::instance()->enabledPlugins();
|
||||
else if (selectedPlugin() == "multi") plugins = SearchPluginManager::instance()->enabledPlugins();
|
||||
else plugins << selectedPlugin();
|
||||
|
||||
qDebug("Search with category: %s", qUtf8Printable(selectedCategory()));
|
||||
|
||||
// Update SearchEngine widgets
|
||||
m_noSearchResults = true;
|
||||
|
||||
// Changing the text of the current label
|
||||
m_activeSearchTab->updateResultsCount();
|
||||
|
||||
// Launch search
|
||||
m_searchEngine->startSearch(pattern, selectedCategory(), plugins);
|
||||
}
|
||||
auto *searchHandler = SearchPluginManager::instance()->startSearch(pattern, selectedCategory(), plugins);
|
||||
|
||||
// Tab Addition
|
||||
auto *newTab = new SearchTab(searchHandler, this);
|
||||
m_allTabs.append(newTab);
|
||||
|
||||
QString tabName = pattern;
|
||||
tabName.replace(QRegExp("&{1}"), "&&");
|
||||
m_ui->tabWidget->addTab(newTab, tabName);
|
||||
m_ui->tabWidget->setCurrentWidget(newTab);
|
||||
|
||||
connect(newTab, &SearchTab::resultsCountUpdated, this, &SearchWidget::resultsCountUpdated);
|
||||
connect(newTab, &SearchTab::statusChanged
|
||||
, m_tabStatusChangedMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
|
||||
m_tabStatusChangedMapper->setMapping(newTab, newTab);
|
||||
|
||||
void SearchWidget::searchStarted()
|
||||
{
|
||||
// Update SearchEngine widgets
|
||||
m_activeSearchTab->setStatus(SearchTab::Status::Ongoing);
|
||||
m_ui->searchButton->setText(tr("Stop"));
|
||||
m_activeSearchTab = newTab;
|
||||
tabStatusChanged(newTab);
|
||||
}
|
||||
|
||||
// Slot called when search is Finished
|
||||
// Search can be finished for 3 reasons :
|
||||
// Error | Stopped by user | Finished normally
|
||||
void SearchWidget::searchFinished(bool cancelled)
|
||||
void SearchWidget::resultsCountUpdated()
|
||||
{
|
||||
if (m_mainWindow->isNotificationsEnabled() && (m_mainWindow->currentTabWidget() != this))
|
||||
m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished"));
|
||||
|
||||
if (m_activeSearchTab.isNull()) return; // The active tab was closed
|
||||
|
||||
if (cancelled)
|
||||
m_activeSearchTab->setStatus(SearchTab::Status::Aborted);
|
||||
else if (m_noSearchResults)
|
||||
m_activeSearchTab->setStatus(SearchTab::Status::NoResults);
|
||||
else
|
||||
m_activeSearchTab->setStatus(SearchTab::Status::Finished);
|
||||
|
||||
m_activeSearchTab = 0;
|
||||
m_ui->searchButton->setText(tr("Search"));
|
||||
updateButtons();
|
||||
}
|
||||
|
||||
void SearchWidget::searchFailed()
|
||||
void SearchWidget::tabStatusChanged(QWidget *tab)
|
||||
{
|
||||
if (m_mainWindow->isNotificationsEnabled() && (m_mainWindow->currentTabWidget() != this))
|
||||
m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has failed"));
|
||||
const int tabIndex = m_ui->tabWidget->indexOf(tab);
|
||||
m_ui->tabWidget->setTabToolTip(tabIndex, tab->statusTip());
|
||||
m_ui->tabWidget->setTabIcon(tabIndex, GuiIconProvider::instance()->getIcon(
|
||||
statusIconName(static_cast<SearchTab *>(tab)->status())));
|
||||
|
||||
if (m_activeSearchTab.isNull()) return; // The active tab was closed
|
||||
if ((tab == m_activeSearchTab) && (m_activeSearchTab->status() != SearchTab::Status::Ongoing)) {
|
||||
Q_ASSERT(m_activeSearchTab->status() != SearchTab::Status::Ongoing);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
m_activeSearchTab->setStatus(SearchTab::Status::Aborted);
|
||||
#else
|
||||
m_activeSearchTab->setStatus(SearchTab::Status::Error);
|
||||
#endif
|
||||
}
|
||||
if (m_mainWindow->isNotificationsEnabled() && (m_mainWindow->currentTabWidget() != this)) {
|
||||
if (m_activeSearchTab->status() == SearchTab::Status::Error)
|
||||
m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has failed"));
|
||||
else
|
||||
m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished"));
|
||||
}
|
||||
|
||||
void SearchWidget::appendSearchResults(const QList<SearchResult> &results)
|
||||
{
|
||||
if (m_activeSearchTab.isNull()) {
|
||||
m_searchEngine->cancelSearch();
|
||||
return;
|
||||
m_activeSearchTab = nullptr;
|
||||
m_ui->searchButton->setText(tr("Search"));
|
||||
}
|
||||
|
||||
Q_ASSERT(m_activeSearchTab);
|
||||
|
||||
QStandardItemModel *curModel = m_activeSearchTab->getCurrentSearchListModel();
|
||||
Q_ASSERT(curModel);
|
||||
|
||||
foreach (const SearchResult &result, results) {
|
||||
// Add item to search result list
|
||||
int row = curModel->rowCount();
|
||||
curModel->insertRow(row);
|
||||
|
||||
curModel->setData(curModel->index(row, SearchSortModel::DL_LINK), result.fileUrl); // download URL
|
||||
curModel->setData(curModel->index(row, SearchSortModel::NAME), result.fileName); // Name
|
||||
curModel->setData(curModel->index(row, SearchSortModel::SIZE), result.fileSize); // Size
|
||||
curModel->setData(curModel->index(row, SearchSortModel::SEEDS), result.nbSeeders); // Seeders
|
||||
curModel->setData(curModel->index(row, SearchSortModel::LEECHES), result.nbLeechers); // Leechers
|
||||
curModel->setData(curModel->index(row, SearchSortModel::ENGINE_URL), result.siteUrl); // Search site URL
|
||||
curModel->setData(curModel->index(row, SearchSortModel::DESC_LINK), result.descrLink); // Description Link
|
||||
}
|
||||
|
||||
m_noSearchResults = false;
|
||||
m_activeSearchTab->updateResultsCount();
|
||||
|
||||
// Enable clear & download buttons
|
||||
m_ui->downloadButton->setEnabled(true);
|
||||
m_ui->goToDescBtn->setEnabled(true);
|
||||
m_ui->copyURLBtn->setEnabled(true);
|
||||
}
|
||||
|
||||
void SearchWidget::closeTab(int index)
|
||||
{
|
||||
// Search is run for active tab so if user decided to close it, then stop search
|
||||
if (!m_activeSearchTab.isNull() && index == m_ui->tabWidget->indexOf(m_activeSearchTab)) {
|
||||
qDebug("Closed active search Tab");
|
||||
if (m_searchEngine->isActive())
|
||||
m_searchEngine->cancelSearch();
|
||||
m_activeSearchTab = 0;
|
||||
}
|
||||
SearchTab *tab = m_allTabs.takeAt(index);
|
||||
if (tab == m_activeSearchTab)
|
||||
m_ui->searchButton->setText(tr("Search"));
|
||||
|
||||
delete m_allTabs.takeAt(index);
|
||||
|
||||
if (!m_allTabs.size()) {
|
||||
m_ui->downloadButton->setEnabled(false);
|
||||
m_ui->goToDescBtn->setEnabled(false);
|
||||
m_ui->copyURLBtn->setEnabled(false);
|
||||
}
|
||||
delete tab;
|
||||
}
|
||||
|
||||
// Download selected items in search results list
|
||||
void SearchWidget::on_downloadButton_clicked()
|
||||
{
|
||||
//QModelIndexList selectedIndexes = currentSearchTab->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
||||
QModelIndexList selectedIndexes =
|
||||
m_allTabs.at(m_ui->tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
||||
foreach (const QModelIndex &index, selectedIndexes) {
|
||||
if (index.column() == SearchSortModel::NAME)
|
||||
m_allTabs.at(m_ui->tabWidget->currentIndex())->downloadItem(index);
|
||||
}
|
||||
m_allTabs.at(m_ui->tabWidget->currentIndex())->downloadTorrents();
|
||||
}
|
||||
|
||||
void SearchWidget::on_goToDescBtn_clicked()
|
||||
{
|
||||
QModelIndexList selectedIndexes =
|
||||
m_allTabs.at(m_ui->tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
||||
foreach (const QModelIndex &index, selectedIndexes) {
|
||||
if (index.column() == SearchSortModel::NAME) {
|
||||
QSortFilterProxyModel *model = m_allTabs.at(m_ui->tabWidget->currentIndex())->getCurrentSearchListProxy();
|
||||
const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString();
|
||||
if (!descUrl.isEmpty())
|
||||
QDesktopServices::openUrl(QUrl::fromEncoded(descUrl.toUtf8()));
|
||||
}
|
||||
}
|
||||
m_allTabs.at(m_ui->tabWidget->currentIndex())->openTorrentPages();
|
||||
}
|
||||
|
||||
void SearchWidget::on_copyURLBtn_clicked()
|
||||
{
|
||||
QStringList urls;
|
||||
QModelIndexList selectedIndexes =
|
||||
m_allTabs.at(m_ui->tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
||||
|
||||
foreach (const QModelIndex &index, selectedIndexes) {
|
||||
if (index.column() == SearchSortModel::NAME) {
|
||||
QSortFilterProxyModel *model = m_allTabs.at(m_ui->tabWidget->currentIndex())->getCurrentSearchListProxy();
|
||||
const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString();
|
||||
if (!descUrl.isEmpty())
|
||||
urls << descUrl.toUtf8();
|
||||
}
|
||||
}
|
||||
|
||||
if (!urls.empty()) {
|
||||
QClipboard *clipboard = QApplication::clipboard();
|
||||
clipboard->setText(urls.join("\n"));
|
||||
}
|
||||
m_allTabs.at(m_ui->tabWidget->currentIndex())->copyTorrentURLs();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2015, 2018 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -25,22 +25,18 @@
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*
|
||||
* Contact : chris@qbittorrent.org
|
||||
*/
|
||||
|
||||
#ifndef SEARCHWIDGET_H
|
||||
#define SEARCHWIDGET_H
|
||||
#pragma once
|
||||
|
||||
#include <QList>
|
||||
#include <QPointer>
|
||||
#include <QWidget>
|
||||
|
||||
class QSignalMapper;
|
||||
class QTabWidget;
|
||||
|
||||
class MainWindow;
|
||||
class SearchEngine;
|
||||
struct SearchResult;
|
||||
class SearchTab;
|
||||
|
||||
namespace Ui
|
||||
@@ -48,56 +44,45 @@ namespace Ui
|
||||
class SearchWidget;
|
||||
}
|
||||
|
||||
class SearchWidget: public QWidget
|
||||
class SearchWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_DISABLE_COPY(SearchWidget)
|
||||
|
||||
public:
|
||||
explicit SearchWidget(MainWindow *mainWindow);
|
||||
~SearchWidget();
|
||||
~SearchWidget() override;
|
||||
|
||||
void downloadTorrent(const QString &siteUrl, const QString &url);
|
||||
void giveFocusToSearchInput();
|
||||
|
||||
QTabWidget* searchTabs() const;
|
||||
|
||||
private slots:
|
||||
// Search slots
|
||||
void tab_changed(int); //to prevent the use of the download button when the tab is empty
|
||||
void on_searchButton_clicked();
|
||||
void on_downloadButton_clicked();
|
||||
void on_goToDescBtn_clicked();
|
||||
void on_copyURLBtn_clicked();
|
||||
void on_pluginsButton_clicked();
|
||||
|
||||
private:
|
||||
void tabChanged(int index);
|
||||
void closeTab(int index);
|
||||
void appendSearchResults(const QList<SearchResult> &results);
|
||||
void searchStarted();
|
||||
void searchFinished(bool cancelled);
|
||||
void searchFailed();
|
||||
void resultsCountUpdated();
|
||||
void tabStatusChanged(QWidget *tab);
|
||||
void selectMultipleBox(int index);
|
||||
|
||||
void addTorrentToSession(const QString &source);
|
||||
|
||||
void fillCatCombobox();
|
||||
void fillPluginComboBox();
|
||||
void selectActivePage();
|
||||
void searchTextEdited(QString);
|
||||
void updateButtons();
|
||||
|
||||
private:
|
||||
QString selectedCategory() const;
|
||||
QString selectedPlugin() const;
|
||||
|
||||
Ui::SearchWidget *m_ui;
|
||||
SearchEngine *m_searchEngine;
|
||||
QSignalMapper *m_tabStatusChangedMapper;
|
||||
QPointer<SearchTab> m_currentSearchTab; // Selected tab
|
||||
QPointer<SearchTab> m_activeSearchTab; // Tab with running search
|
||||
QList<QPointer<SearchTab>> m_allTabs; // To store all tabs
|
||||
QList<SearchTab *> m_allTabs; // To store all tabs
|
||||
MainWindow *m_mainWindow;
|
||||
bool m_isNewQueryString;
|
||||
bool m_noSearchResults;
|
||||
QByteArray m_searchResultLineTruncated;
|
||||
};
|
||||
|
||||
#endif // SEARCHWIDGET_H
|
||||
|
||||
Reference in New Issue
Block a user