Browse Source

Fix search-related file/class names.

adaptive-webui-19844
Vladimir Golovnev (Glassez) 9 years ago
parent
commit
3797cc767f
  1. 4
      src/gui/mainwindow.cpp
  2. 4
      src/gui/mainwindow.h
  3. 62
      src/searchengine/engineselectdlg.cpp
  4. 9
      src/searchengine/engineselectdlg.h
  5. 4
      src/searchengine/engineselectdlg.ui
  6. 14
      src/searchengine/pluginsourcedlg.h
  7. 4
      src/searchengine/pluginsourcedlg.ui
  8. 12
      src/searchengine/searchengine.pri
  9. 2
      src/searchengine/searchlistdelegate.h
  10. 4
      src/searchengine/searchtab.cpp
  11. 21
      src/searchengine/searchtab.h
  12. 52
      src/searchengine/searchwidget.cpp
  13. 18
      src/searchengine/searchwidget.h
  14. 4
      src/searchengine/searchwidget.ui

4
src/gui/mainwindow.cpp

@ -53,7 +53,7 @@
#include "torrentcreatordlg.h" #include "torrentcreatordlg.h"
#include "downloadfromurldlg.h" #include "downloadfromurldlg.h"
#include "addnewtorrentdialog.h" #include "addnewtorrentdialog.h"
#include "searchengine.h" #include "searchwidget.h"
#include "rss_imp.h" #include "rss_imp.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h" #include "base/bittorrent/sessionstatus.h"
@ -526,7 +526,7 @@ void MainWindow::displaySearchTab(bool enable)
if (enable) { if (enable) {
// RSS tab // RSS tab
if (!searchEngine) { if (!searchEngine) {
searchEngine = new SearchEngine(this); searchEngine = new SearchWidget(this);
tabs->insertTab(1, searchEngine, GuiIconProvider::instance()->getIcon("edit-find"), tr("Search")); tabs->insertTab(1, searchEngine, GuiIconProvider::instance()->getIcon("edit-find"), tr("Search"));
} }
} }

4
src/gui/mainwindow.h

@ -38,7 +38,7 @@
#include "statsdialog.h" #include "statsdialog.h"
class downloadFromURL; class downloadFromURL;
class SearchEngine; class SearchWidget;
class RSSImp; class RSSImp;
class about; class about;
class options_imp; class options_imp;
@ -192,7 +192,7 @@ private:
QSplitter *hSplitter; QSplitter *hSplitter;
QSplitter *vSplitter; QSplitter *vSplitter;
// Search // Search
QPointer<SearchEngine> searchEngine; QPointer<SearchWidget> searchEngine;
// RSS // RSS
QPointer<RSSImp> rssWidget; QPointer<RSSImp> rssWidget;
// Execution Log // Execution Log

62
src/searchengine/engineselectdlg.cpp

@ -34,8 +34,8 @@
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "ico.h" #include "ico.h"
#include "searchengine.h" #include "searchwidget.h"
#include "pluginsource.h" #include "pluginsourcedlg.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "autoexpandabledialog.h" #include "autoexpandabledialog.h"
#include <QProcess> #include <QProcess>
@ -53,7 +53,7 @@
enum EngineColumns {ENGINE_NAME, ENGINE_VERSION, ENGINE_URL, ENGINE_STATE, ENGINE_ID}; enum EngineColumns {ENGINE_NAME, ENGINE_VERSION, ENGINE_URL, ENGINE_STATE, ENGINE_ID};
engineSelectDlg::engineSelectDlg(QWidget *parent, SupportedEngines *supported_engines) EngineSelectDlg::EngineSelectDlg(QWidget *parent, SupportedEngines *supported_engines)
: QDialog(parent) : QDialog(parent)
, supported_engines(supported_engines) , supported_engines(supported_engines)
, m_updateUrl(QString("https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/") + (Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova") + "/engines/") , m_updateUrl(QString("https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/") + (Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova") + "/engines/")
@ -82,13 +82,13 @@ engineSelectDlg::engineSelectDlg(QWidget *parent, SupportedEngines *supported_en
show(); show();
} }
engineSelectDlg::~engineSelectDlg() { EngineSelectDlg::~EngineSelectDlg() {
qDebug("Destroying engineSelectDlg"); qDebug("Destroying engineSelectDlg");
emit enginesChanged(); emit enginesChanged();
qDebug("Engine plugins dialog destroyed"); qDebug("Engine plugins dialog destroyed");
} }
void engineSelectDlg::dropEvent(QDropEvent *event) { void EngineSelectDlg::dropEvent(QDropEvent *event) {
event->acceptProposedAction(); event->acceptProposedAction();
QStringList files; QStringList files;
if (event->mimeData()->hasUrls()) { if (event->mimeData()->hasUrls()) {
@ -123,7 +123,7 @@ void engineSelectDlg::dropEvent(QDropEvent *event) {
} }
// Decode if we accept drag 'n drop or not // Decode if we accept drag 'n drop or not
void engineSelectDlg::dragEnterEvent(QDragEnterEvent *event) { void EngineSelectDlg::dragEnterEvent(QDragEnterEvent *event) {
QString mime; QString mime;
foreach (mime, event->mimeData()->formats()) { foreach (mime, event->mimeData()->formats()) {
qDebug("mimeData: %s", qPrintable(mime)); qDebug("mimeData: %s", qPrintable(mime));
@ -133,13 +133,13 @@ void engineSelectDlg::dragEnterEvent(QDragEnterEvent *event) {
} }
} }
void engineSelectDlg::on_updateButton_clicked() { void EngineSelectDlg::on_updateButton_clicked() {
// Download version file from update server on sourceforge // Download version file from update server on sourceforge
setCursor(QCursor(Qt::WaitCursor)); setCursor(QCursor(Qt::WaitCursor));
downloadFromUrl(m_updateUrl + "versions.txt"); downloadFromUrl(m_updateUrl + "versions.txt");
} }
void engineSelectDlg::toggleEngineState(QTreeWidgetItem *item, int) { void EngineSelectDlg::toggleEngineState(QTreeWidgetItem *item, int) {
SupportedEngine *engine = supported_engines->value(item->text(ENGINE_ID)); SupportedEngine *engine = supported_engines->value(item->text(ENGINE_ID));
engine->setEnabled(!engine->isEnabled()); engine->setEnabled(!engine->isEnabled());
if (engine->isEnabled()) { if (engine->isEnabled()) {
@ -151,7 +151,7 @@ void engineSelectDlg::toggleEngineState(QTreeWidgetItem *item, int) {
} }
} }
void engineSelectDlg::displayContextMenu(const QPoint&) { void EngineSelectDlg::displayContextMenu(const QPoint&) {
QMenu myContextMenu(this); QMenu myContextMenu(this);
// Enable/disable pause/start action given the DL state // Enable/disable pause/start action given the DL state
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); QList<QTreeWidgetItem *> items = pluginsTree->selectedItems();
@ -164,11 +164,11 @@ void engineSelectDlg::displayContextMenu(const QPoint&) {
myContextMenu.exec(QCursor::pos()); myContextMenu.exec(QCursor::pos());
} }
void engineSelectDlg::on_closeButton_clicked() { void EngineSelectDlg::on_closeButton_clicked() {
close(); close();
} }
void engineSelectDlg::on_actionUninstall_triggered() { void EngineSelectDlg::on_actionUninstall_triggered() {
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); QList<QTreeWidgetItem *> items = pluginsTree->selectedItems();
QTreeWidgetItem *item; QTreeWidgetItem *item;
bool error = false; bool error = false;
@ -205,7 +205,7 @@ void engineSelectDlg::on_actionUninstall_triggered() {
QMessageBox::information(0, tr("Uninstall success"), tr("All selected plugins were uninstalled successfully")); QMessageBox::information(0, tr("Uninstall success"), tr("All selected plugins were uninstalled successfully"));
} }
void engineSelectDlg::enableSelection(bool enable) { void EngineSelectDlg::enableSelection(bool enable) {
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); QList<QTreeWidgetItem *> items = pluginsTree->selectedItems();
QTreeWidgetItem *item; QTreeWidgetItem *item;
foreach (item, items) { foreach (item, items) {
@ -224,14 +224,14 @@ void engineSelectDlg::enableSelection(bool enable) {
} }
// Set the color of a row in data model // Set the color of a row in data model
void engineSelectDlg::setRowColor(int row, QString color) { void EngineSelectDlg::setRowColor(int row, QString color) {
QTreeWidgetItem *item = pluginsTree->topLevelItem(row); QTreeWidgetItem *item = pluginsTree->topLevelItem(row);
for (int i=0; i<pluginsTree->columnCount(); ++i) { for (int i=0; i<pluginsTree->columnCount(); ++i) {
item->setData(i, Qt::ForegroundRole, QVariant(QColor(color))); item->setData(i, Qt::ForegroundRole, QVariant(QColor(color)));
} }
} }
QList<QTreeWidgetItem*> engineSelectDlg::findItemsWithUrl(QString url) { QList<QTreeWidgetItem*> EngineSelectDlg::findItemsWithUrl(QString url) {
QList<QTreeWidgetItem*> res; QList<QTreeWidgetItem*> res;
for (int i=0; i<pluginsTree->topLevelItemCount(); ++i) { for (int i=0; i<pluginsTree->topLevelItemCount(); ++i) {
QTreeWidgetItem *item = pluginsTree->topLevelItem(i); QTreeWidgetItem *item = pluginsTree->topLevelItem(i);
@ -241,7 +241,7 @@ QList<QTreeWidgetItem*> engineSelectDlg::findItemsWithUrl(QString url) {
return res; return res;
} }
QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id) { QTreeWidgetItem* EngineSelectDlg::findItemWithID(QString id) {
QList<QTreeWidgetItem*> res; QList<QTreeWidgetItem*> res;
for (int i=0; i<pluginsTree->topLevelItemCount(); ++i) { for (int i=0; i<pluginsTree->topLevelItemCount(); ++i) {
QTreeWidgetItem *item = pluginsTree->topLevelItem(i); QTreeWidgetItem *item = pluginsTree->topLevelItem(i);
@ -251,15 +251,15 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id) {
return 0; return 0;
} }
bool engineSelectDlg::isUpdateNeeded(QString plugin_name, qreal new_version) const { bool EngineSelectDlg::isUpdateNeeded(QString plugin_name, qreal new_version) const {
qreal old_version = SearchEngine::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + plugin_name + ".py"); qreal old_version = SearchWidget::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + plugin_name + ".py");
qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version); qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version);
return (new_version > old_version); return (new_version > old_version);
} }
void engineSelectDlg::installPlugin(QString path, QString plugin_name) { void EngineSelectDlg::installPlugin(QString path, QString plugin_name) {
qDebug("Asked to install plugin at %s", qPrintable(path)); qDebug("Asked to install plugin at %s", qPrintable(path));
qreal new_version = SearchEngine::getPluginVersion(path); qreal new_version = SearchWidget::getPluginVersion(path);
if (new_version == 0.0) { if (new_version == 0.0) {
QMessageBox::warning(this, tr("Invalid plugin"), tr("The search engine plugin is invalid, please contact the author.")); QMessageBox::warning(this, tr("Invalid plugin"), tr("The search engine plugin is invalid, please contact the author."));
return; return;
@ -304,7 +304,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
// Install was successful, remove backup and update plugin version // Install was successful, remove backup and update plugin version
if (update) { if (update) {
Utils::Fs::forceRemove(dest_path+".bak"); Utils::Fs::forceRemove(dest_path+".bak");
qreal version = SearchEngine::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + plugin_name + ".py"); qreal version = SearchWidget::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + plugin_name + ".py");
QTreeWidgetItem *item = findItemWithID(plugin_name); QTreeWidgetItem *item = findItemWithID(plugin_name);
item->setText(ENGINE_VERSION, QString::number(version, 'f', 2)); item->setText(ENGINE_VERSION, QString::number(version, 'f', 2));
QMessageBox::information(this, tr("Search plugin install"), tr("'%1' search engine plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name)); QMessageBox::information(this, tr("Search plugin install"), tr("'%1' search engine plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name));
@ -315,7 +315,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
} }
} }
void engineSelectDlg::loadSupportedSearchEngines() { void EngineSelectDlg::loadSupportedSearchEngines() {
// Some clean up first // Some clean up first
pluginsTree->clear(); pluginsTree->clear();
foreach (QString name, supported_engines->keys()) { foreach (QString name, supported_engines->keys()) {
@ -323,7 +323,7 @@ void engineSelectDlg::loadSupportedSearchEngines() {
} }
} }
void engineSelectDlg::addNewEngine(QString engine_name) { void EngineSelectDlg::addNewEngine(QString engine_name) {
QTreeWidgetItem *item = new QTreeWidgetItem(pluginsTree); QTreeWidgetItem *item = new QTreeWidgetItem(pluginsTree);
SupportedEngine *engine = supported_engines->value(engine_name); SupportedEngine *engine = supported_engines->value(engine_name);
item->setText(ENGINE_NAME, engine->getFullName()); item->setText(ENGINE_NAME, engine->getFullName());
@ -351,17 +351,17 @@ void engineSelectDlg::addNewEngine(QString engine_name) {
} }
} }
// Load version // Load version
qreal version = SearchEngine::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + engine->getName() + ".py"); qreal version = SearchWidget::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + engine->getName() + ".py");
item->setText(ENGINE_VERSION, QString::number(version, 'f', 2)); item->setText(ENGINE_VERSION, QString::number(version, 'f', 2));
} }
void engineSelectDlg::on_installButton_clicked() { void EngineSelectDlg::on_installButton_clicked() {
pluginSourceDlg *dlg = new pluginSourceDlg(this); PluginSourceDlg *dlg = new PluginSourceDlg(this);
connect(dlg, SIGNAL(askForLocalFile()), this, SLOT(askForLocalPlugin())); connect(dlg, SIGNAL(askForLocalFile()), this, SLOT(askForLocalPlugin()));
connect(dlg, SIGNAL(askForUrl()), this, SLOT(askForPluginUrl())); connect(dlg, SIGNAL(askForUrl()), this, SLOT(askForPluginUrl()));
} }
void engineSelectDlg::askForPluginUrl() { void EngineSelectDlg::askForPluginUrl() {
bool ok(false); bool ok(false);
QString clipTxt = qApp->clipboard()->text(); QString clipTxt = qApp->clipboard()->text();
QString defaultUrl = "http://"; QString defaultUrl = "http://";
@ -391,7 +391,7 @@ void engineSelectDlg::askForPluginUrl() {
downloadFromUrl(url); downloadFromUrl(url);
} }
void engineSelectDlg::askForLocalPlugin() { void EngineSelectDlg::askForLocalPlugin() {
QStringList pathsList = QFileDialog::getOpenFileNames(0, QStringList pathsList = QFileDialog::getOpenFileNames(0,
tr("Select search plugins"), QDir::homePath(), tr("Select search plugins"), QDir::homePath(),
tr("qBittorrent search plugin")+QString::fromUtf8(" (*.py)")); tr("qBittorrent search plugin")+QString::fromUtf8(" (*.py)"));
@ -404,7 +404,7 @@ void engineSelectDlg::askForLocalPlugin() {
} }
} }
bool engineSelectDlg::parseVersionsFile(QString versions_file) { bool EngineSelectDlg::parseVersionsFile(QString versions_file) {
qDebug("Checking if update is needed"); qDebug("Checking if update is needed");
bool file_correct = false; bool file_correct = false;
QFile versions(versions_file); QFile versions(versions_file);
@ -450,14 +450,14 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) {
return file_correct; return file_correct;
} }
void engineSelectDlg::downloadFromUrl(const QString &url) void EngineSelectDlg::downloadFromUrl(const QString &url)
{ {
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(url, true); Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(url, true);
connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString)));
connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString)));
} }
void engineSelectDlg::processDownloadedFile(const QString &url, QString filePath) { void EngineSelectDlg::processDownloadedFile(const QString &url, QString filePath) {
filePath = Utils::Fs::fromNativePath(filePath); filePath = Utils::Fs::fromNativePath(filePath);
setCursor(QCursor(Qt::ArrowCursor)); setCursor(QCursor(Qt::ArrowCursor));
qDebug("engineSelectDlg received %s", qPrintable(url)); qDebug("engineSelectDlg received %s", qPrintable(url));
@ -500,7 +500,7 @@ void engineSelectDlg::processDownloadedFile(const QString &url, QString filePath
} }
} }
void engineSelectDlg::handleDownloadFailure(const QString &url, const QString &reason) { void EngineSelectDlg::handleDownloadFailure(const QString &url, const QString &reason) {
setCursor(QCursor(Qt::ArrowCursor)); setCursor(QCursor(Qt::ArrowCursor));
if (url.endsWith("favicon.ico", Qt::CaseInsensitive)) { if (url.endsWith("favicon.ico", Qt::CaseInsensitive)) {
qDebug("Could not download favicon: %s, reason: %s", qPrintable(url), qPrintable(reason)); qDebug("Could not download favicon: %s, reason: %s", qPrintable(url), qPrintable(reason));

9
src/searchengine/engineselectdlg.h

@ -31,14 +31,15 @@
#ifndef ENGINE_SELECT_DLG_H #ifndef ENGINE_SELECT_DLG_H
#define ENGINE_SELECT_DLG_H #define ENGINE_SELECT_DLG_H
#include "ui_engineselect.h" #include "ui_engineselectdlg.h"
#include "supportedengines.h" #include "supportedengines.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QDropEvent; class QDropEvent;
QT_END_NAMESPACE QT_END_NAMESPACE
class engineSelectDlg : public QDialog, public Ui::engineSelect{ class EngineSelectDlg : public QDialog, public Ui::EngineSelectDlg
{
Q_OBJECT Q_OBJECT
private: private:
@ -48,8 +49,8 @@ class engineSelectDlg : public QDialog, public Ui::engineSelect{
const QString m_updateUrl; const QString m_updateUrl;
public: public:
engineSelectDlg(QWidget *parent, SupportedEngines *supported_engines); EngineSelectDlg(QWidget *parent, SupportedEngines *supported_engines);
~engineSelectDlg(); ~EngineSelectDlg();
QList<QTreeWidgetItem*> findItemsWithUrl(QString url); QList<QTreeWidgetItem*> findItemsWithUrl(QString url);
QTreeWidgetItem* findItemWithID(QString id); QTreeWidgetItem* findItemWithID(QString id);

4
src/searchengine/engineselect.ui → src/searchengine/engineselectdlg.ui

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>engineSelect</class> <class>EngineSelectDlg</class>
<widget class="QDialog" name="engineSelect"> <widget class="QDialog" name="EngineSelectDlg">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>

14
src/searchengine/pluginsource.h → src/searchengine/pluginsourcedlg.h

@ -28,13 +28,13 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#ifndef PLUGIN_SOURCE_H #ifndef PLUGINSOURCEDLG_H
#define PLUGIN_SOURCE_H #define PLUGINSOURCEDLG_H
#include <QDialog> #include <QDialog>
#include "ui_pluginsource.h" #include "ui_pluginsourcedlg.h"
class pluginSourceDlg: public QDialog, private Ui::pluginSourceDlg { class PluginSourceDlg: public QDialog, private Ui::PluginSourceDlg {
Q_OBJECT Q_OBJECT
signals: signals:
@ -53,13 +53,13 @@ class pluginSourceDlg: public QDialog, private Ui::pluginSourceDlg {
} }
public: public:
pluginSourceDlg(QWidget* parent): QDialog(parent) { PluginSourceDlg(QWidget* parent): QDialog(parent) {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
show(); show();
} }
~pluginSourceDlg() {} ~PluginSourceDlg() {}
}; };
#endif #endif // PLUGINSOURCEDLG_H

4
src/searchengine/pluginsource.ui → src/searchengine/pluginsourcedlg.ui

@ -1,6 +1,6 @@
<ui version="4.0" > <ui version="4.0" >
<class>pluginSourceDlg</class> <class>PluginSourceDlg</class>
<widget class="QDialog" name="pluginSourceDlg" > <widget class="QDialog" name="PluginSourceDlg" >
<property name="geometry" > <property name="geometry" >
<rect> <rect>
<x>0</x> <x>0</x>

12
src/searchengine/searchengine.pri

@ -1,18 +1,18 @@
INCLUDEPATH += $$PWD INCLUDEPATH += $$PWD
FORMS += $$PWD/search.ui \ FORMS += $$PWD/searchwidget.ui \
$$PWD/engineselect.ui \ $$PWD/engineselectdlg.ui \
$$PWD/pluginsource.ui $$PWD/pluginsourcedlg.ui
HEADERS += $$PWD/searchengine.h \ HEADERS += $$PWD/searchwidget.h \
$$PWD/searchtab.h \ $$PWD/searchtab.h \
$$PWD/engineselectdlg.h \ $$PWD/engineselectdlg.h \
$$PWD/pluginsource.h \ $$PWD/pluginsourcedlg.h \
$$PWD/searchlistdelegate.h \ $$PWD/searchlistdelegate.h \
$$PWD/supportedengines.h \ $$PWD/supportedengines.h \
$$PWD/searchsortmodel.h $$PWD/searchsortmodel.h
SOURCES += $$PWD/searchengine.cpp \ SOURCES += $$PWD/searchwidget.cpp \
$$PWD/searchtab.cpp \ $$PWD/searchtab.cpp \
$$PWD/engineselectdlg.cpp $$PWD/engineselectdlg.cpp

2
src/searchengine/searchlistdelegate.h

@ -37,7 +37,7 @@
#include <QPainter> #include <QPainter>
#include <QProgressBar> #include <QProgressBar>
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "searchengine.h" #include "searchwidget.h"
class SearchListDelegate: public QItemDelegate { class SearchListDelegate: public QItemDelegate {
Q_OBJECT Q_OBJECT

4
src/searchengine/searchtab.cpp

@ -40,10 +40,10 @@
#include "searchtab.h" #include "searchtab.h"
#include "searchlistdelegate.h" #include "searchlistdelegate.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "searchengine.h" #include "searchwidget.h"
#include "base/preferences.h" #include "base/preferences.h"
SearchTab::SearchTab(SearchEngine *parent) : QWidget(), parent(parent) SearchTab::SearchTab(SearchWidget *parent) : QWidget(), parent(parent)
{ {
box = new QVBoxLayout(); box = new QVBoxLayout();
results_lbl = new QLabel(); results_lbl = new QLabel();

21
src/searchengine/searchtab.h

@ -28,25 +28,26 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#ifndef SEARCH_TAB_H #ifndef SEARCHTAB_H
#define SEARCH_TAB_H #define SEARCHTAB_H
#include <QLabel>
#include <QVBoxLayout>
#include "ui_search.h"
#include "searchsortmodel.h" #include "searchsortmodel.h"
#define ENGINE_URL_COLUMN 4 #define ENGINE_URL_COLUMN 4
#define URL_COLUMN 5 #define URL_COLUMN 5
class SearchListDelegate; class SearchListDelegate;
class SearchEngine; class SearchWidget;
QT_BEGIN_NAMESPACE
class QTreeView; class QTreeView;
class QHeaderView; class QHeaderView;
class QStandardItemModel; class QStandardItemModel;
QT_END_NAMESPACE
class SearchTab: public QWidget, public Ui::search_engine { class SearchTab: public QWidget
{
Q_OBJECT Q_OBJECT
private: private:
@ -56,13 +57,13 @@ private:
QStandardItemModel *SearchListModel; QStandardItemModel *SearchListModel;
SearchSortModel *proxyModel; SearchSortModel *proxyModel;
SearchListDelegate *SearchDelegate; SearchListDelegate *SearchDelegate;
SearchEngine *parent; SearchWidget *parent;
protected slots: protected slots:
void downloadSelectedItem(const QModelIndex& index); void downloadSelectedItem(const QModelIndex& index);
public: public:
SearchTab(SearchEngine *parent); SearchTab(SearchWidget *parent);
~SearchTab(); ~SearchTab();
bool loadColWidthResultsList(); bool loadColWidthResultsList();
QLabel * getCurrentLabel(); QLabel * getCurrentLabel();
@ -74,5 +75,5 @@ public:
QString status; QString status;
}; };
#endif #endif // SEARCHTAB_H

52
src/searchengine/searchengine.cpp → src/searchengine/searchwidget.cpp

@ -48,7 +48,6 @@
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include "searchengine.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
@ -58,11 +57,12 @@
#include "addnewtorrentdialog.h" #include "addnewtorrentdialog.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "lineedit.h" #include "lineedit.h"
#include "searchwidget.h"
#define SEARCHHISTORY_MAXSIZE 50 #define SEARCHHISTORY_MAXSIZE 50
/*SEARCH ENGINE START*/ /*SEARCH ENGINE START*/
SearchEngine::SearchEngine(MainWindow* parent) SearchWidget::SearchWidget(MainWindow* parent)
: QWidget(parent) : QWidget(parent)
, search_pattern(new LineEdit(this)) , search_pattern(new LineEdit(this))
, mp_mainWindow(parent) , mp_mainWindow(parent)
@ -101,7 +101,7 @@ SearchEngine::SearchEngine(MainWindow* parent)
connect(selectEngine, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(selectMultipleBox(const QString &))); connect(selectEngine, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(selectMultipleBox(const QString &)));
} }
void SearchEngine::fillCatCombobox() void SearchWidget::fillCatCombobox()
{ {
comboCategory->clear(); comboCategory->clear();
comboCategory->addItem(full_cat_names["all"], QVariant("all")); comboCategory->addItem(full_cat_names["all"], QVariant("all"));
@ -112,7 +112,7 @@ void SearchEngine::fillCatCombobox()
} }
} }
void SearchEngine::fillEngineComboBox() void SearchWidget::fillEngineComboBox()
{ {
selectEngine->clear(); selectEngine->clear();
selectEngine->addItem(tr("All enabled"), QVariant("enabled")); selectEngine->addItem(tr("All enabled"), QVariant("enabled"));
@ -122,17 +122,17 @@ void SearchEngine::fillEngineComboBox()
selectEngine->addItem(tr("Multiple..."), QVariant("multi")); selectEngine->addItem(tr("Multiple..."), QVariant("multi"));
} }
QString SearchEngine::selectedCategory() const QString SearchWidget::selectedCategory() const
{ {
return comboCategory->itemData(comboCategory->currentIndex()).toString(); return comboCategory->itemData(comboCategory->currentIndex()).toString();
} }
QString SearchEngine::selectedEngine() const QString SearchWidget::selectedEngine() const
{ {
return selectEngine->itemData(selectEngine->currentIndex()).toString(); return selectEngine->itemData(selectEngine->currentIndex()).toString();
} }
SearchEngine::~SearchEngine() SearchWidget::~SearchWidget()
{ {
qDebug("Search destruction"); qDebug("Search destruction");
searchProcess->kill(); searchProcess->kill();
@ -151,7 +151,7 @@ SearchEngine::~SearchEngine()
delete supported_engines; delete supported_engines;
} }
void SearchEngine::tab_changed(int t) void SearchWidget::tab_changed(int t)
{ {
//when we switch from a tab that is not empty to another that is empty the download button //when we switch from a tab that is not empty to another that is empty the download button
//doesn't have to be available //doesn't have to be available
@ -172,32 +172,32 @@ void SearchEngine::tab_changed(int t)
} }
} }
void SearchEngine::selectMultipleBox(const QString &text) void SearchWidget::selectMultipleBox(const QString &text)
{ {
if (text == tr("Multiple...")) on_enginesButton_clicked(); if (text == tr("Multiple...")) on_enginesButton_clicked();
} }
void SearchEngine::on_enginesButton_clicked() void SearchWidget::on_enginesButton_clicked()
{ {
engineSelectDlg *dlg = new engineSelectDlg(this, supported_engines); EngineSelectDlg *dlg = new EngineSelectDlg(this, supported_engines);
connect(dlg, SIGNAL(enginesChanged()), this, SLOT(fillCatCombobox())); connect(dlg, SIGNAL(enginesChanged()), this, SLOT(fillCatCombobox()));
connect(dlg, SIGNAL(enginesChanged()), this, SLOT(fillEngineComboBox())); connect(dlg, SIGNAL(enginesChanged()), this, SLOT(fillEngineComboBox()));
} }
void SearchEngine::searchTextEdited(QString) void SearchWidget::searchTextEdited(QString)
{ {
// Enable search button // Enable search button
search_button->setText(tr("Search")); search_button->setText(tr("Search"));
newQueryString = true; newQueryString = true;
} }
void SearchEngine::giveFocusToSearchInput() void SearchWidget::giveFocusToSearchInput()
{ {
search_pattern->setFocus(); search_pattern->setFocus();
} }
// Function called when we click on search button // Function called when we click on search button
void SearchEngine::on_search_button_clicked() void SearchWidget::on_search_button_clicked()
{ {
if (Utils::Misc::pythonVersion() < 0) { if (Utils::Misc::pythonVersion() < 0) {
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Please install Python to use the Search Engine.")); mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Please install Python to use the Search Engine."));
@ -265,7 +265,7 @@ void SearchEngine::on_search_button_clicked()
searchTimeout->start(180000); // 3min searchTimeout->start(180000); // 3min
} }
void SearchEngine::saveResultsColumnsWidth() void SearchWidget::saveResultsColumnsWidth()
{ {
if (all_tab.isEmpty()) if (all_tab.isEmpty())
return; return;
@ -281,7 +281,7 @@ void SearchEngine::saveResultsColumnsWidth()
pref->setSearchColsWidth(new_width_list.join(" ")); pref->setSearchColsWidth(new_width_list.join(" "));
} }
void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) void SearchWidget::downloadTorrent(QString engine_url, QString torrent_url)
{ {
if (torrent_url.startsWith("bc://bt/", Qt::CaseInsensitive)) { if (torrent_url.startsWith("bc://bt/", Qt::CaseInsensitive)) {
qDebug("Converting bc link to magnet link"); qDebug("Converting bc link to magnet link");
@ -307,7 +307,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url)
} }
} }
void SearchEngine::searchStarted() void SearchWidget::searchStarted()
{ {
// Update SearchEngine widgets // Update SearchEngine widgets
activeSearchTab->status = tr("Searching..."); activeSearchTab->status = tr("Searching...");
@ -319,7 +319,7 @@ void SearchEngine::searchStarted()
// search Qprocess return output as soon as it gets new // search Qprocess return output as soon as it gets new
// stuff to read. We split it into lines and add each // stuff to read. We split it into lines and add each
// line to search results calling appendSearchResult(). // line to search results calling appendSearchResult().
void SearchEngine::readSearchOutput() void SearchWidget::readSearchOutput()
{ {
QByteArray output = searchProcess->readAllStandardOutput(); QByteArray output = searchProcess->readAllStandardOutput();
output.replace("\r", ""); output.replace("\r", "");
@ -334,7 +334,7 @@ void SearchEngine::readSearchOutput()
activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(nb_search_results)); activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(nb_search_results));
} }
void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) void SearchWidget::downloadFinished(int exitcode, QProcess::ExitStatus)
{ {
QProcess *downloadProcess = (QProcess*)sender(); QProcess *downloadProcess = (QProcess*)sender();
if (exitcode == 0) { if (exitcode == 0) {
@ -361,7 +361,7 @@ static inline void removePythonScriptIfExists(const QString& script_path)
} }
// Update nova.py search plugin if necessary // Update nova.py search plugin if necessary
void SearchEngine::updateNova() void SearchWidget::updateNova()
{ {
qDebug("Updating nova"); qDebug("Updating nova");
// create nova directory if necessary // create nova directory if necessary
@ -444,7 +444,7 @@ void SearchEngine::updateNova()
// Slot called when search is Finished // Slot called when search is Finished
// Search can be finished for 3 reasons : // Search can be finished for 3 reasons :
// Error | Stopped by user | Finished normally // Error | Stopped by user | Finished normally
void SearchEngine::searchFinished(int exitcode, QProcess::ExitStatus) void SearchWidget::searchFinished(int exitcode, QProcess::ExitStatus)
{ {
if (searchTimeout->isActive()) if (searchTimeout->isActive())
searchTimeout->stop(); searchTimeout->stop();
@ -482,7 +482,7 @@ void SearchEngine::searchFinished(int exitcode, QProcess::ExitStatus)
// SLOT to append one line to search results list // SLOT to append one line to search results list
// Line is in the following form : // Line is in the following form :
// file url | file name | file size | nb seeds | nb leechers | Search engine url // file url | file name | file size | nb seeds | nb leechers | Search engine url
void SearchEngine::appendSearchResult(const QString &line) void SearchWidget::appendSearchResult(const QString &line)
{ {
if (activeSearchTab.isNull()) { if (activeSearchTab.isNull()) {
if (searchProcess->state() != QProcess::NotRunning) { if (searchProcess->state() != QProcess::NotRunning) {
@ -536,7 +536,7 @@ void SearchEngine::appendSearchResult(const QString &line)
copyURLBtn->setEnabled(true); copyURLBtn->setEnabled(true);
} }
void SearchEngine::closeTab(int index) void SearchWidget::closeTab(int index)
{ {
// Search is run for active tab so if user decided to close it, then stop search // Search is run for active tab so if user decided to close it, then stop search
if (!activeSearchTab.isNull() && index == tabWidget->indexOf(activeSearchTab)) { if (!activeSearchTab.isNull() && index == tabWidget->indexOf(activeSearchTab)) {
@ -564,7 +564,7 @@ void SearchEngine::closeTab(int index)
} }
// Download selected items in search results list // Download selected items in search results list
void SearchEngine::on_download_button_clicked() void SearchWidget::on_download_button_clicked()
{ {
//QModelIndexList selectedIndexes = currentSearchTab->getCurrentTreeView()->selectionModel()->selectedIndexes(); //QModelIndexList selectedIndexes = currentSearchTab->getCurrentTreeView()->selectionModel()->selectedIndexes();
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
@ -580,7 +580,7 @@ void SearchEngine::on_download_button_clicked()
} }
} }
void SearchEngine::on_goToDescBtn_clicked() void SearchWidget::on_goToDescBtn_clicked()
{ {
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
foreach (const QModelIndex &index, selectedIndexes) { foreach (const QModelIndex &index, selectedIndexes) {
@ -593,7 +593,7 @@ void SearchEngine::on_goToDescBtn_clicked()
} }
} }
void SearchEngine::on_copyURLBtn_clicked() void SearchWidget::on_copyURLBtn_clicked()
{ {
QStringList urls; QStringList urls;
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();

18
src/searchengine/searchengine.h → src/searchengine/searchwidget.h

@ -28,20 +28,20 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#ifndef SEARCH_H #ifndef SEARCHWIDGET_H
#define SEARCH_H #define SEARCHWIDGET_H
#include <QProcess> #include <QProcess>
#include <QList> #include <QList>
#include <QPair> #include <QPair>
#include <QPointer> #include <QPointer>
#include <QStringListModel> #include <QStringListModel>
#include "ui_search.h" #include "ui_searchwidget.h"
#include "engineselectdlg.h" #include "engineselectdlg.h"
#include "searchtab.h" #include "searchtab.h"
#include "supportedengines.h" #include "supportedengines.h"
class SearchEngine; class SearchWidget;
class MainWindow; class MainWindow;
class LineEdit; class LineEdit;
@ -49,16 +49,16 @@ QT_BEGIN_NAMESPACE
class QTimer; class QTimer;
QT_END_NAMESPACE QT_END_NAMESPACE
class SearchEngine : public QWidget, public Ui::search_engine{ class SearchWidget : public QWidget, private Ui::SearchWidget{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(SearchEngine) Q_DISABLE_COPY(SearchWidget)
private: private:
enum PluginColumn { PL_DL_LINK, PL_NAME, PL_SIZE, PL_SEEDS, PL_LEECHS, PL_ENGINE_URL, PL_DESC_LINK, NB_PLUGIN_COLUMNS }; enum PluginColumn { PL_DL_LINK, PL_NAME, PL_SIZE, PL_SEEDS, PL_LEECHS, PL_ENGINE_URL, PL_DESC_LINK, NB_PLUGIN_COLUMNS };
public: public:
SearchEngine(MainWindow *mp_mainWindow); SearchWidget(MainWindow *mp_mainWindow);
~SearchEngine(); ~SearchWidget();
QString selectedCategory() const; QString selectedCategory() const;
QString selectedEngine() const; QString selectedEngine() const;
@ -130,4 +130,4 @@ private:
bool newQueryString; bool newQueryString;
}; };
#endif #endif // SEARCHWIDGET_H

4
src/searchengine/search.ui → src/searchengine/searchwidget.ui

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>search_engine</class> <class>SearchWidget</class>
<widget class="QWidget" name="search_engine"> <widget class="QWidget" name="SearchWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
Loading…
Cancel
Save