Browse Source

Fix coding style (Issue #2192).

adaptive-webui-19844
Vladimir Golovnev (Glassez) 9 years ago committed by Vladimir Golovnev (qlassez)
parent
commit
ac365c5efb
  1. 10
      src/base/searchengine.cpp
  2. 5
      src/base/searchengine.h
  3. 5
      src/gui/gui.pri
  4. 520
      src/gui/search/pluginselectdlg.cpp
  5. 35
      src/gui/search/pluginselectdlg.h
  6. 51
      src/gui/search/pluginsourcedlg.cpp
  7. 34
      src/gui/search/pluginsourcedlg.h
  8. 74
      src/gui/search/searchlistdelegate.cpp
  9. 47
      src/gui/search/searchlistdelegate.h
  10. 54
      src/gui/search/searchsortmodel.cpp
  11. 67
      src/gui/search/searchsortmodel.h
  12. 146
      src/gui/search/searchtab.cpp
  13. 60
      src/gui/search/searchtab.h
  14. 229
      src/gui/search/searchwidget.cpp
  15. 54
      src/gui/search/searchwidget.h
  16. 6
      src/gui/search/searchwidget.ui

10
src/base/searchengine.cpp

@ -30,8 +30,8 @@
#include <QDomDocument> #include <QDomDocument>
#include <QDomNode> #include <QDomNode>
#include <QDomElement> #include <QDomElement>
#include <QProcess>
#include <QDir> #include <QDir>
#include <QProcess>
#include <QDebug> #include <QDebug>
#include "base/utils/fs.h" #include "base/utils/fs.h"
@ -62,8 +62,8 @@ static inline void removePythonScriptIfExists(const QString &scriptPath)
const QHash<QString, QString> SearchEngine::m_categoryNames = SearchEngine::initializeCategoryNames(); const QHash<QString, QString> SearchEngine::m_categoryNames = SearchEngine::initializeCategoryNames();
SearchEngine::SearchEngine() SearchEngine::SearchEngine()
: m_searchStopped(false) : m_updateUrl(QString("https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/%1/engines/").arg(Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova"))
, m_updateUrl(QString("https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/%1/engines/").arg(Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova")) , m_searchStopped(false)
{ {
updateNova(); updateNova();
@ -71,7 +71,7 @@ SearchEngine::SearchEngine()
m_searchProcess->setEnvironment(QProcess::systemEnvironment()); m_searchProcess->setEnvironment(QProcess::systemEnvironment());
connect(m_searchProcess, SIGNAL(started()), this, SIGNAL(searchStarted())); connect(m_searchProcess, SIGNAL(started()), this, SIGNAL(searchStarted()));
connect(m_searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput())); connect(m_searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput()));
connect(m_searchProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(processFinished(int, QProcess::ExitStatus))); connect(m_searchProcess, SIGNAL(finished(int)), this, SLOT(processFinished(int)));
m_searchTimeout = new QTimer(this); m_searchTimeout = new QTimer(this);
m_searchTimeout->setSingleShot(true); m_searchTimeout->setSingleShot(true);
@ -315,7 +315,7 @@ QString SearchEngine::engineLocation()
// Slot called when QProcess is Finished // Slot called when QProcess is Finished
// QProcess can be finished for 3 reasons : // QProcess can be finished for 3 reasons :
// Error | Stopped by user | Finished normally // Error | Stopped by user | Finished normally
void SearchEngine::processFinished(int exitcode, QProcess::ExitStatus) void SearchEngine::processFinished(int exitcode)
{ {
m_searchTimeout->stop(); m_searchTimeout->stop();

5
src/base/searchengine.h

@ -30,11 +30,12 @@
#ifndef SEARCHENGINE_H #ifndef SEARCHENGINE_H
#define SEARCHENGINE_H #define SEARCHENGINE_H
#include <QObject>
#include <QHash> #include <QHash>
#include <QStringList> #include <QStringList>
#include <QProcess>
#include <QList> #include <QList>
class QProcess;
class QTimer; class QTimer;
struct PluginInfo struct PluginInfo
@ -104,7 +105,7 @@ signals:
private slots: private slots:
void onTimeout(); void onTimeout();
void readSearchOutput(); void readSearchOutput();
void processFinished(int exitcode, QProcess::ExitStatus); void processFinished(int exitcode);
void versionInfoDownloaded(const QString &url, const QByteArray &data); void versionInfoDownloaded(const QString &url, const QByteArray &data);
void versionInfoDownloadFailed(const QString &url, const QString &reason); void versionInfoDownloadFailed(const QString &url, const QString &reason);
void pluginDownloaded(const QString &url, QString filePath); void pluginDownloaded(const QString &url, QString filePath);

5
src/gui/gui.pri

@ -81,7 +81,10 @@ SOURCES += \
$$PWD/torrentcreatordlg.cpp \ $$PWD/torrentcreatordlg.cpp \
$$PWD/search/searchwidget.cpp \ $$PWD/search/searchwidget.cpp \
$$PWD/search/searchtab.cpp \ $$PWD/search/searchtab.cpp \
$$PWD/search/pluginselectdlg.cpp $$PWD/search/pluginselectdlg.cpp \
$$PWD/search/pluginsourcedlg.cpp \
$$PWD/search/searchlistdelegate.cpp \
$$PWD/search/searchsortmodel.cpp
win32|macx { win32|macx {
HEADERS += $$PWD/programupdater.h HEADERS += $$PWD/programupdater.h

520
src/gui/search/pluginselectdlg.cpp

@ -29,18 +29,6 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#include "pluginselectdlg.h"
#include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h"
#include "base/searchengine.h"
#include "ico.h"
#include "searchwidget.h"
#include "pluginsourcedlg.h"
#include "guiiconprovider.h"
#include "autoexpandabledialog.h"
#include <QProcess>
#include <QHeaderView> #include <QHeaderView>
#include <QMenu> #include <QMenu>
#include <QMessageBox> #include <QMessageBox>
@ -53,224 +41,264 @@
#include <QTableView> #include <QTableView>
#endif #endif
enum PluginColumns {PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_URL, PLUGIN_STATE, PLUGIN_ID}; #include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h"
#include "base/searchengine.h"
#include "ico.h"
#include "searchwidget.h"
#include "pluginsourcedlg.h"
#include "guiiconprovider.h"
#include "autoexpandabledialog.h"
#include "pluginselectdlg.h"
enum PluginColumns
{
PLUGIN_NAME,
PLUGIN_VERSION,
PLUGIN_URL,
PLUGIN_STATE,
PLUGIN_ID
};
PluginSelectDlg::PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent) PluginSelectDlg::PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent)
: QDialog(parent) : QDialog(parent)
, m_pluginManager(pluginManager) , m_pluginManager(pluginManager)
, m_asyncOps(0) , m_asyncOps(0)
{ {
setupUi(this); setupUi(this);
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
#ifdef QBT_USES_QT5 #ifdef QBT_USES_QT5
// This hack fixes reordering of first column with Qt5. // This hack fixes reordering of first column with Qt5.
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777 // https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused; QTableView unused;
unused.setVerticalHeader(pluginsTree->header()); unused.setVerticalHeader(pluginsTree->header());
pluginsTree->header()->setParent(pluginsTree); pluginsTree->header()->setParent(pluginsTree);
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
#endif #endif
pluginsTree->setRootIsDecorated(false); pluginsTree->setRootIsDecorated(false);
pluginsTree->header()->resizeSection(0, 160); pluginsTree->header()->resizeSection(0, 160);
pluginsTree->header()->resizeSection(1, 80); pluginsTree->header()->resizeSection(1, 80);
pluginsTree->header()->resizeSection(2, 200); pluginsTree->header()->resizeSection(2, 200);
pluginsTree->hideColumn(PLUGIN_ID); pluginsTree->hideColumn(PLUGIN_ID);
actionUninstall->setIcon(GuiIconProvider::instance()->getIcon("list-remove"));
actionUninstall->setIcon(GuiIconProvider::instance()->getIcon("list-remove"));
connect(actionEnable, SIGNAL(toggled(bool)), this, SLOT(enableSelection(bool)));
connect(pluginsTree, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContextMenu(const QPoint&))); connect(actionEnable, SIGNAL(toggled(bool)), this, SLOT(enableSelection(bool)));
connect(pluginsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(togglePluginState(QTreeWidgetItem*, int))); connect(pluginsTree, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(displayContextMenu(const QPoint&)));
connect(pluginsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(togglePluginState(QTreeWidgetItem*, int)));
loadSupportedSearchPlugins();
loadSupportedSearchPlugins();
connect(m_pluginManager, SIGNAL(pluginInstalled(QString)), SLOT(pluginInstalled(QString)));
connect(m_pluginManager, SIGNAL(pluginInstallationFailed(QString, QString)), SLOT(pluginInstallationFailed(QString, QString))); connect(m_pluginManager, SIGNAL(pluginInstalled(QString)), SLOT(pluginInstalled(QString)));
connect(m_pluginManager, SIGNAL(pluginUpdated(QString)), SLOT(pluginUpdated(QString))); connect(m_pluginManager, SIGNAL(pluginInstallationFailed(QString, QString)), SLOT(pluginInstallationFailed(QString, QString)));
connect(m_pluginManager, SIGNAL(pluginUpdateFailed(QString, QString)), SLOT(pluginUpdateFailed(QString, QString))); connect(m_pluginManager, SIGNAL(pluginUpdated(QString)), SLOT(pluginUpdated(QString)));
connect(m_pluginManager, SIGNAL(checkForUpdatesFinished(QHash<QString, qreal>)), SLOT(checkForUpdatesFinished(QHash<QString, qreal>))); connect(m_pluginManager, SIGNAL(pluginUpdateFailed(QString, QString)), SLOT(pluginUpdateFailed(QString, QString)));
connect(m_pluginManager, SIGNAL(checkForUpdatesFailed(QString)), SLOT(checkForUpdatesFailed(QString))); connect(m_pluginManager, SIGNAL(checkForUpdatesFinished(QHash<QString, qreal>)), SLOT(checkForUpdatesFinished(QHash<QString, qreal>)));
connect(m_pluginManager, SIGNAL(checkForUpdatesFailed(QString)), SLOT(checkForUpdatesFailed(QString)));
show();
show();
} }
PluginSelectDlg::~PluginSelectDlg() { PluginSelectDlg::~PluginSelectDlg()
emit pluginsChanged(); {
emit pluginsChanged();
} }
void PluginSelectDlg::dropEvent(QDropEvent *event) { void PluginSelectDlg::dropEvent(QDropEvent *event)
event->acceptProposedAction(); {
QStringList files; event->acceptProposedAction();
if (event->mimeData()->hasUrls()) {
const QList<QUrl> urls = event->mimeData()->urls(); QStringList files;
foreach (const QUrl &url, urls) { if (event->mimeData()->hasUrls()) {
if (!url.isEmpty()) { foreach (const QUrl &url, event->mimeData()->urls()) {
if (url.scheme().compare("file", Qt::CaseInsensitive) == 0) if (!url.isEmpty()) {
files << url.toLocalFile(); if (url.scheme().compare("file", Qt::CaseInsensitive) == 0)
else files << url.toLocalFile();
files << url.toString(); else
} files << url.toString();
}
}
}
else {
files = event->mimeData()->text().split(QLatin1String("\n"));
} }
}
else {
files = event->mimeData()->text().split(QString::fromUtf8("\n"));
}
if (files.isEmpty()) return; if (files.isEmpty()) return;
foreach (QString file, files) { foreach (QString file, files) {
qDebug("dropped %s", qPrintable(file)); qDebug("dropped %s", qPrintable(file));
startAsyncOp(); startAsyncOp();
m_pluginManager->installPlugin(file); m_pluginManager->installPlugin(file);
} }
} }
// Decode if we accept drag 'n drop or not // Decode if we accept drag 'n drop or not
void PluginSelectDlg::dragEnterEvent(QDragEnterEvent *event) { void PluginSelectDlg::dragEnterEvent(QDragEnterEvent *event)
QString mime; {
foreach (mime, event->mimeData()->formats()) { QString mime;
qDebug("mimeData: %s", qPrintable(mime)); foreach (mime, event->mimeData()->formats()) {
} qDebug("mimeData: %s", qPrintable(mime));
if (event->mimeData()->hasFormat(QString::fromUtf8("text/plain")) || event->mimeData()->hasFormat(QString::fromUtf8("text/uri-list"))) { }
event->acceptProposedAction();
} if (event->mimeData()->hasFormat(QLatin1String("text/plain")) || event->mimeData()->hasFormat(QLatin1String("text/uri-list"))) {
event->acceptProposedAction();
}
} }
void PluginSelectDlg::on_updateButton_clicked() { void PluginSelectDlg::on_updateButton_clicked()
startAsyncOp(); {
m_pluginManager->checkForUpdates(); startAsyncOp();
m_pluginManager->checkForUpdates();
} }
void PluginSelectDlg::togglePluginState(QTreeWidgetItem *item, int) { void PluginSelectDlg::togglePluginState(QTreeWidgetItem *item, int)
PluginInfo *plugin = m_pluginManager->pluginInfo(item->text(PLUGIN_ID)); {
m_pluginManager->enablePlugin(plugin->name, !plugin->enabled); PluginInfo *plugin = m_pluginManager->pluginInfo(item->text(PLUGIN_ID));
if (plugin->enabled) { m_pluginManager->enablePlugin(plugin->name, !plugin->enabled);
item->setText(PLUGIN_STATE, tr("Yes")); if (plugin->enabled) {
setRowColor(pluginsTree->indexOfTopLevelItem(item), "green"); item->setText(PLUGIN_STATE, tr("Yes"));
} else { setRowColor(pluginsTree->indexOfTopLevelItem(item), "green");
item->setText(PLUGIN_STATE, tr("No")); }
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red"); else {
} item->setText(PLUGIN_STATE, tr("No"));
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red");
}
} }
void PluginSelectDlg::displayContextMenu(const QPoint&) { void PluginSelectDlg::displayContextMenu(const QPoint&)
QMenu myContextMenu(this); {
// Enable/disable pause/start action given the DL state QMenu myContextMenu(this);
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); // Enable/disable pause/start action given the DL state
if (items.isEmpty()) return; QList<QTreeWidgetItem *> items = pluginsTree->selectedItems();
QString first_id = items.first()->text(PLUGIN_ID); if (items.isEmpty()) return;
actionEnable->setChecked(m_pluginManager->pluginInfo(first_id)->enabled);
myContextMenu.addAction(actionEnable); QString first_id = items.first()->text(PLUGIN_ID);
myContextMenu.addSeparator(); actionEnable->setChecked(m_pluginManager->pluginInfo(first_id)->enabled);
myContextMenu.addAction(actionUninstall); myContextMenu.addAction(actionEnable);
myContextMenu.exec(QCursor::pos()); myContextMenu.addSeparator();
myContextMenu.addAction(actionUninstall);
myContextMenu.exec(QCursor::pos());
} }
void PluginSelectDlg::on_closeButton_clicked() { void PluginSelectDlg::on_closeButton_clicked()
close(); {
close();
} }
void PluginSelectDlg::on_actionUninstall_triggered() { void PluginSelectDlg::on_actionUninstall_triggered()
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); {
QTreeWidgetItem *item; bool error = false;
bool error = false; foreach (QTreeWidgetItem *item, pluginsTree->selectedItems()) {
foreach (item, items) { int index = pluginsTree->indexOfTopLevelItem(item);
int index = pluginsTree->indexOfTopLevelItem(item); Q_ASSERT(index != -1);
Q_ASSERT(index != -1); QString id = item->text(PLUGIN_ID);
QString id = item->text(PLUGIN_ID); if (m_pluginManager->uninstallPlugin(id)) {
if (m_pluginManager->uninstallPlugin(id)) { delete item;
delete item; }
} else {
else { error = true;
error = true; // Disable it instead
// Disable it instead m_pluginManager->enablePlugin(id, false);
m_pluginManager->enablePlugin(id, false); item->setText(PLUGIN_STATE, tr("No"));
item->setText(PLUGIN_STATE, tr("No")); setRowColor(index, "red");
setRowColor(index, "red"); }
continue;
} }
}
if (error) if (error)
QMessageBox::warning(0, tr("Uninstall warning"), tr("Some plugins could not be uninstalled because they are included in qBittorrent. Only the ones you added yourself can be uninstalled.\nThose plugins were disabled.")); QMessageBox::warning(0, tr("Uninstall warning"), tr("Some plugins could not be uninstalled because they are included in qBittorrent. Only the ones you added yourself can be uninstalled.\nThose plugins were disabled."));
else else
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 PluginSelectDlg::enableSelection(bool enable) { void PluginSelectDlg::enableSelection(bool enable)
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); {
QTreeWidgetItem *item; foreach (QTreeWidgetItem *item, pluginsTree->selectedItems()) {
foreach (item, items) { int index = pluginsTree->indexOfTopLevelItem(item);
int index = pluginsTree->indexOfTopLevelItem(item); Q_ASSERT(index != -1);
Q_ASSERT(index != -1); QString id = item->text(PLUGIN_ID);
QString id = item->text(PLUGIN_ID); m_pluginManager->enablePlugin(id, enable);
m_pluginManager->enablePlugin(id, enable); if (enable) {
if (enable) { item->setText(PLUGIN_STATE, tr("Yes"));
item->setText(PLUGIN_STATE, tr("Yes")); setRowColor(index, "green");
setRowColor(index, "green"); }
} else { else {
item->setText(PLUGIN_STATE, tr("No")); item->setText(PLUGIN_STATE, tr("No"));
setRowColor(index, "red"); setRowColor(index, "red");
}
} }
}
} }
// Set the color of a row in data model // Set the color of a row in data model
void PluginSelectDlg::setRowColor(int row, QString color) { void PluginSelectDlg::setRowColor(int row, QString color)
QTreeWidgetItem *item = pluginsTree->topLevelItem(row); {
for (int i=0; i<pluginsTree->columnCount(); ++i) { QTreeWidgetItem *item = pluginsTree->topLevelItem(row);
item->setData(i, Qt::ForegroundRole, QVariant(QColor(color))); for (int i = 0; i < pluginsTree->columnCount(); ++i) {
} item->setData(i, Qt::ForegroundRole, QVariant(QColor(color)));
}
} }
QList<QTreeWidgetItem*> PluginSelectDlg::findItemsWithUrl(QString url) { QList<QTreeWidgetItem*> PluginSelectDlg::findItemsWithUrl(QString url)
QList<QTreeWidgetItem*> res; {
for (int i=0; i<pluginsTree->topLevelItemCount(); ++i) { QList<QTreeWidgetItem*> res;
QTreeWidgetItem *item = pluginsTree->topLevelItem(i);
if (url.startsWith(item->text(PLUGIN_URL), Qt::CaseInsensitive)) for (int i = 0; i < pluginsTree->topLevelItemCount(); ++i) {
res << item; QTreeWidgetItem *item = pluginsTree->topLevelItem(i);
} if (url.startsWith(item->text(PLUGIN_URL), Qt::CaseInsensitive))
return res; res << item;
}
return res;
} }
QTreeWidgetItem* PluginSelectDlg::findItemWithID(QString id) { QTreeWidgetItem* PluginSelectDlg::findItemWithID(QString id)
for (int i=0; i<pluginsTree->topLevelItemCount(); ++i) { {
QTreeWidgetItem *item = pluginsTree->topLevelItem(i); for (int i = 0; i < pluginsTree->topLevelItemCount(); ++i) {
if (id == item->text(PLUGIN_ID)) QTreeWidgetItem *item = pluginsTree->topLevelItem(i);
return item; if (id == item->text(PLUGIN_ID))
} return item;
return 0; }
return 0;
} }
void PluginSelectDlg::loadSupportedSearchPlugins() { void PluginSelectDlg::loadSupportedSearchPlugins()
// Some clean up first {
pluginsTree->clear(); // Some clean up first
foreach (QString name, m_pluginManager->allPlugins()) pluginsTree->clear();
addNewPlugin(name); foreach (QString name, m_pluginManager->allPlugins())
addNewPlugin(name);
} }
void PluginSelectDlg::addNewPlugin(QString engine_name) { void PluginSelectDlg::addNewPlugin(QString pluginName)
QTreeWidgetItem *item = new QTreeWidgetItem(pluginsTree); {
PluginInfo *plugin = m_pluginManager->pluginInfo(engine_name); QTreeWidgetItem *item = new QTreeWidgetItem(pluginsTree);
item->setText(PLUGIN_NAME, plugin->fullName); PluginInfo *plugin = m_pluginManager->pluginInfo(pluginName);
item->setText(PLUGIN_URL, plugin->url); item->setText(PLUGIN_NAME, plugin->fullName);
item->setText(PLUGIN_ID, plugin->name); item->setText(PLUGIN_URL, plugin->url);
if (plugin->enabled) { item->setText(PLUGIN_ID, plugin->name);
item->setText(PLUGIN_STATE, tr("Yes")); if (plugin->enabled) {
setRowColor(pluginsTree->indexOfTopLevelItem(item), "green"); item->setText(PLUGIN_STATE, tr("Yes"));
} else { setRowColor(pluginsTree->indexOfTopLevelItem(item), "green");
item->setText(PLUGIN_STATE, tr("No")); }
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red"); else {
} item->setText(PLUGIN_STATE, tr("No"));
// Handle icon setRowColor(pluginsTree->indexOfTopLevelItem(item), "red");
if (QFile::exists(plugin->iconPath)) { }
// Good, we already have the icon // Handle icon
item->setData(PLUGIN_NAME, Qt::DecorationRole, QVariant(QIcon(plugin->iconPath))); if (QFile::exists(plugin->iconPath)) {
} else { // Good, we already have the icon
// Icon is missing, we must download it item->setData(PLUGIN_NAME, Qt::DecorationRole, QVariant(QIcon(plugin->iconPath)));
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(plugin->url + "/favicon.ico", true); }
connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(iconDownloaded(QString, QString))); else {
connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(iconDownloadFailed(QString, QString))); // Icon is missing, we must download it
} Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(plugin->url + "/favicon.ico", true);
item->setText(PLUGIN_VERSION, QString::number(plugin->version, 'f', 2)); connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(iconDownloaded(QString, QString)));
connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(iconDownloadFailed(QString, QString)));
}
item->setText(PLUGIN_VERSION, QString::number(plugin->version, 'f', 2));
} }
void PluginSelectDlg::startAsyncOp() void PluginSelectDlg::startAsyncOp()
@ -287,75 +315,77 @@ void PluginSelectDlg::finishAsyncOp()
setCursor(QCursor(Qt::ArrowCursor)); setCursor(QCursor(Qt::ArrowCursor));
} }
void PluginSelectDlg::on_installButton_clicked() { void PluginSelectDlg::on_installButton_clicked()
PluginSourceDlg *dlg = new PluginSourceDlg(this); {
connect(dlg, SIGNAL(askForLocalFile()), this, SLOT(askForLocalPlugin())); PluginSourceDlg *dlg = new PluginSourceDlg(this);
connect(dlg, SIGNAL(askForUrl()), this, SLOT(askForPluginUrl())); connect(dlg, SIGNAL(askForLocalFile()), this, SLOT(askForLocalPlugin()));
connect(dlg, SIGNAL(askForUrl()), this, SLOT(askForPluginUrl()));
} }
void PluginSelectDlg::askForPluginUrl() { void PluginSelectDlg::askForPluginUrl()
bool ok(false); {
QString clipTxt = qApp->clipboard()->text(); bool ok = false;
QString defaultUrl = "http://"; QString clipTxt = qApp->clipboard()->text();
if (Utils::Misc::isUrl(clipTxt) && clipTxt.endsWith(".py")) QString defaultUrl = "http://";
defaultUrl = clipTxt; if (Utils::Misc::isUrl(clipTxt) && clipTxt.endsWith(".py"))
QString url = AutoExpandableDialog::getText(this, tr("New search engine plugin URL"), defaultUrl = clipTxt;
tr("URL:"), QLineEdit::Normal, QString url = AutoExpandableDialog::getText(
defaultUrl, &ok); this, tr("New search engine plugin URL"),
tr("URL:"), QLineEdit::Normal, defaultUrl, &ok
while(true) { );
if (!ok || url.isEmpty())
return; while (ok && !url.isEmpty() && !url.endsWith(".py")) {
if (!url.endsWith(".py")) { QMessageBox::warning(this, tr("Invalid link"), tr("The link doesn't seem to point to a search engine plugin."));
QMessageBox::warning(this, tr("Invalid link"), tr("The link doesn't seem to point to a search engine plugin.")); url = AutoExpandableDialog::getText(
url = AutoExpandableDialog::getText(this, tr("New search engine plugin URL"), this, tr("New search engine plugin URL"),
tr("URL:"), QLineEdit::Normal, tr("URL:"), QLineEdit::Normal, url, &ok
url, &ok); );
} }
else
break;
}
startAsyncOp(); if (ok && !url.isEmpty()) {
m_pluginManager->installPlugin(url); startAsyncOp();
m_pluginManager->installPlugin(url);
}
} }
void PluginSelectDlg::askForLocalPlugin() { void PluginSelectDlg::askForLocalPlugin()
QStringList pathsList = QFileDialog::getOpenFileNames(0, {
tr("Select search plugins"), QDir::homePath(), QStringList pathsList = QFileDialog::getOpenFileNames(
tr("qBittorrent search plugin")+QString::fromUtf8(" (*.py)")); 0, tr("Select search plugins"), QDir::homePath(),
foreach (QString path, pathsList) { tr("qBittorrent search plugin") + QLatin1String(" (*.py)")
startAsyncOp(); );
m_pluginManager->installPlugin(path); foreach (QString path, pathsList) {
} startAsyncOp();
m_pluginManager->installPlugin(path);
}
} }
void PluginSelectDlg::iconDownloaded(const QString &url, QString filePath) { void PluginSelectDlg::iconDownloaded(const QString &url, QString filePath)
filePath = Utils::Fs::fromNativePath(filePath); {
filePath = Utils::Fs::fromNativePath(filePath);
// Icon downloaded
QImage fileIcon; // Icon downloaded
if (fileIcon.load(filePath)) { QImage fileIcon;
QList<QTreeWidgetItem*> items = findItemsWithUrl(url); if (fileIcon.load(filePath)) {
QTreeWidgetItem *item; foreach (QTreeWidgetItem *item, findItemsWithUrl(url)) {
foreach (item, items) { QString id = item->text(PLUGIN_ID);
QString id = item->text(PLUGIN_ID); PluginInfo *plugin = m_pluginManager->pluginInfo(id);
PluginInfo *plugin = m_pluginManager->pluginInfo(id); if (!plugin) continue;
if (!plugin) continue;
QFile icon(filePath);
QFile icon(filePath); icon.open(QIODevice::ReadOnly);
icon.open(QIODevice::ReadOnly); QString iconPath = QString("%1/%2.%3").arg(SearchEngine::pluginsLocation()).arg(id).arg(ICOHandler::canRead(&icon) ? "ico" : "png");
QString iconPath = QString("%1/%2.%3").arg(SearchEngine::pluginsLocation()).arg(id).arg(ICOHandler::canRead(&icon) ? "ico" : "png"); if (QFile::copy(filePath, iconPath))
if (QFile::copy(filePath, iconPath)) item->setData(PLUGIN_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
item->setData(PLUGIN_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); }
} }
} // Delete tmp file
// Delete tmp file Utils::Fs::forceRemove(filePath);
Utils::Fs::forceRemove(filePath);
} }
void PluginSelectDlg::iconDownloadFailed(const QString &url, const QString &reason) { void PluginSelectDlg::iconDownloadFailed(const QString &url, const QString &reason)
qDebug("Could not download favicon: %s, reason: %s", qPrintable(url), qPrintable(reason)); {
qDebug("Could not download favicon: %s, reason: %s", qPrintable(url), qPrintable(reason));
} }
void PluginSelectDlg::checkForUpdatesFinished(const QHash<QString, qreal> &updateInfo) void PluginSelectDlg::checkForUpdatesFinished(const QHash<QString, qreal> &updateInfo)

35
src/gui/search/pluginselectdlg.h

@ -34,42 +34,36 @@
#include "ui_pluginselectdlg.h" #include "ui_pluginselectdlg.h"
QT_BEGIN_NAMESPACE
class QDropEvent; class QDropEvent;
QT_END_NAMESPACE
class SearchEngine; class SearchEngine;
class PluginSelectDlg : public QDialog, public Ui::PluginSelectDlg class PluginSelectDlg: public QDialog, private Ui::PluginSelectDlg
{ {
Q_OBJECT Q_OBJECT
private:
SearchEngine *m_pluginManager;
int m_asyncOps;
public: public:
PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent = 0); explicit PluginSelectDlg(SearchEngine *pluginManager, QWidget *parent = 0);
~PluginSelectDlg(); ~PluginSelectDlg();
QList<QTreeWidgetItem*> findItemsWithUrl(QString url); QList<QTreeWidgetItem*> findItemsWithUrl(QString url);
QTreeWidgetItem* findItemWithID(QString id); QTreeWidgetItem* findItemWithID(QString id);
signals: signals:
void pluginsChanged(); void pluginsChanged();
protected: protected:
void dropEvent(QDropEvent *event); void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event); void dragEnterEvent(QDragEnterEvent *event);
private slots: private slots:
void on_actionUninstall_triggered();
void on_updateButton_clicked();
void on_installButton_clicked();
void on_closeButton_clicked(); void on_closeButton_clicked();
void togglePluginState(QTreeWidgetItem*, int); void togglePluginState(QTreeWidgetItem*, int);
void setRowColor(int row, QString color); void setRowColor(int row, QString color);
void displayContextMenu(const QPoint& pos); void displayContextMenu(const QPoint& pos);
void enableSelection(bool enable); void enableSelection(bool enable);
void on_actionUninstall_triggered();
void on_updateButton_clicked();
void on_installButton_clicked();
void askForLocalPlugin(); void askForLocalPlugin();
void askForPluginUrl(); void askForPluginUrl();
void iconDownloaded(const QString &url, QString filePath); void iconDownloaded(const QString &url, QString filePath);
@ -82,11 +76,14 @@ class PluginSelectDlg : public QDialog, public Ui::PluginSelectDlg
void pluginUpdated(const QString &name); void pluginUpdated(const QString &name);
void pluginUpdateFailed(const QString &name, const QString &reason); void pluginUpdateFailed(const QString &name, const QString &reason);
private: private:
void loadSupportedSearchPlugins(); void loadSupportedSearchPlugins();
void addNewPlugin(QString engine_name); void addNewPlugin(QString pluginName);
void startAsyncOp(); void startAsyncOp();
void finishAsyncOp(); void finishAsyncOp();
SearchEngine *m_pluginManager;
int m_asyncOps;
}; };
#endif // PLUGINSELECTDLG_H #endif // PLUGINSELECTDLG_H

51
src/gui/search/pluginsourcedlg.cpp

@ -0,0 +1,51 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* 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 "pluginsourcedlg.h"
PluginSourceDlg::PluginSourceDlg(QWidget *parent)
: QDialog(parent)
{
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
show();
}
void PluginSourceDlg::on_localButton_clicked()
{
emit askForLocalFile();
close();
}
void PluginSourceDlg::on_urlButton_clicked()
{
emit askForUrl();
close();
}

34
src/gui/search/pluginsourcedlg.h

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -34,32 +34,20 @@
#include <QDialog> #include <QDialog>
#include "ui_pluginsourcedlg.h" #include "ui_pluginsourcedlg.h"
class PluginSourceDlg: public QDialog, private Ui::PluginSourceDlg { class PluginSourceDlg: public QDialog, private Ui::PluginSourceDlg
Q_OBJECT {
Q_OBJECT
signals: public:
explicit PluginSourceDlg(QWidget *parent = 0);
signals:
void askForUrl(); void askForUrl();
void askForLocalFile(); void askForLocalFile();
protected slots: private slots:
void on_localButton_clicked() { void on_localButton_clicked();
emit askForLocalFile(); void on_urlButton_clicked();
close();
}
void on_urlButton_clicked() {
emit askForUrl();
close();
}
public:
PluginSourceDlg(QWidget* parent): QDialog(parent) {
setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
show();
}
~PluginSourceDlg() {}
}; };
#endif // PLUGINSOURCEDLG_H #endif // PLUGINSOURCEDLG_H

74
src/gui/search/searchlistdelegate.cpp

@ -0,0 +1,74 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* 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 <QStyleOptionViewItemV2>
#include <QModelIndex>
#include <QPainter>
#include <QProgressBar>
#include "base/utils/misc.h"
#include "searchsortmodel.h"
#include "searchlistdelegate.h"
SearchListDelegate::SearchListDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
void SearchListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
switch(index.column()) {
case SearchSortModel::SIZE:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
break;
case SearchSortModel::SEEDS:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown"));
break;
case SearchSortModel::LEECHS:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown"));
break;
default:
QItemDelegate::paint(painter, option, index);
}
painter->restore();
}
QWidget *SearchListDelegate::createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
{
// No editor here
return 0;
}

47
src/gui/search/searchlistdelegate.h

@ -1,5 +1,5 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -32,47 +32,14 @@
#define SEARCHLISTDELEGATE_H #define SEARCHLISTDELEGATE_H
#include <QItemDelegate> #include <QItemDelegate>
#include <QStyleOptionViewItemV2>
#include <QModelIndex>
#include <QPainter>
#include <QProgressBar>
#include "base/utils/misc.h"
#include "searchwidget.h"
class SearchListDelegate: public QItemDelegate { class SearchListDelegate: public QItemDelegate
Q_OBJECT {
public:
explicit SearchListDelegate(QObject *parent = 0);
public: void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
SearchListDelegate(QObject *parent=0) : QItemDelegate(parent) {} QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const;
~SearchListDelegate() {}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const {
painter->save();
QStyleOptionViewItemV2 opt = QItemDelegate::setOptions(index, option);
switch(index.column()) {
case SearchSortModel::SIZE:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
break;
case SearchSortModel::SEEDS:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown"));
break;
case SearchSortModel::LEECHS:
QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, (index.data().toLongLong() >= 0) ? index.data().toString() : tr("Unknown"));
break;
default:
QItemDelegate::paint(painter, option, index);
}
painter->restore();
}
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const {
// No editor here
return 0;
}
}; };
#endif #endif

54
src/gui/search/searchsortmodel.cpp

@ -0,0 +1,54 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 sledgehammer999 <hammered999@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* 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.
*/
#include "searchsortmodel.h"
SearchSortModel::SearchSortModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
bool SearchSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
if ((sortColumn() == NAME) || (sortColumn() == ENGINE_URL)) {
QVariant vL = sourceModel()->data(left);
QVariant vR = sourceModel()->data(right);
if (!(vL.isValid() && vR.isValid()))
return QSortFilterProxyModel::lessThan(left, right);
Q_ASSERT(vL.isValid());
Q_ASSERT(vR.isValid());
bool res = false;
if (Utils::String::naturalSort(vL.toString(), vR.toString(), res))
return res;
return QSortFilterProxyModel::lessThan(left, right);
}
return QSortFilterProxyModel::lessThan(left, right);
}

67
src/gui/search/searchsortmodel.h

@ -1,35 +1,56 @@
/*
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 sledgehammer999 <hammered999@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* In addition, as a special exception, the copyright holders give permission to
* link this program with the OpenSSL project's "OpenSSL" library (or with
* modified versions of it that use the same license as the "OpenSSL" library),
* and distribute the linked executables. You must obey the GNU General Public
* License in all respects for all of the code used other than "OpenSSL". If you
* 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.
*/
#ifndef SEARCHSORTMODEL_H #ifndef SEARCHSORTMODEL_H
#define SEARCHSORTMODEL_H #define SEARCHSORTMODEL_H
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include "base/utils/string.h" #include "base/utils/string.h"
class SearchSortModel : public QSortFilterProxyModel { class SearchSortModel: public QSortFilterProxyModel
Q_OBJECT {
public: public:
enum SearchColumn { NAME, SIZE, SEEDS, LEECHS, ENGINE_URL, DL_LINK, DESC_LINK, NB_SEARCH_COLUMNS }; enum SearchColumn
{
SearchSortModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {} NAME,
SIZE,
SEEDS,
LEECHS,
ENGINE_URL,
DL_LINK,
DESC_LINK,
NB_SEARCH_COLUMNS
};
explicit SearchSortModel(QObject *parent = 0);
protected: protected:
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const { virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
if (sortColumn() == NAME || sortColumn() == ENGINE_URL) {
QVariant vL = sourceModel()->data(left);
QVariant vR = sourceModel()->data(right);
if (!(vL.isValid() && vR.isValid()))
return QSortFilterProxyModel::lessThan(left, right);
Q_ASSERT(vL.isValid());
Q_ASSERT(vR.isValid());
bool res = false;
if (Utils::String::naturalSort(vL.toString(), vR.toString(), res))
return res;
return QSortFilterProxyModel::lessThan(left, right);
}
return QSortFilterProxyModel::lessThan(left, right);
}
}; };
#endif // SEARCHSORTMODEL_H #endif // SEARCHSORTMODEL_H

146
src/gui/search/searchtab.cpp

@ -33,132 +33,140 @@
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QHeaderView> #include <QHeaderView>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QLabel>
#include <QVBoxLayout>
#ifdef QBT_USES_QT5 #ifdef QBT_USES_QT5
#include <QTableView> #include <QTableView>
#endif #endif
#include "searchtab.h"
#include "searchlistdelegate.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "searchwidget.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "searchsortmodel.h"
#include "searchlistdelegate.h"
#include "searchwidget.h"
#include "searchtab.h"
SearchTab::SearchTab(SearchWidget *parent) : QWidget(), parent(parent) SearchTab::SearchTab(SearchWidget *parent)
: QWidget(parent)
, m_parent(parent)
{ {
box = new QVBoxLayout(); m_box = new QVBoxLayout(this);
results_lbl = new QLabel(); m_resultsLbl = new QLabel(this);
resultsBrowser = new QTreeView(); m_resultsBrowser = new QTreeView(this);
#ifdef QBT_USES_QT5 #ifdef QBT_USES_QT5
// This hack fixes reordering of first column with Qt5. // This hack fixes reordering of first column with Qt5.
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777 // https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
QTableView unused; QTableView unused;
unused.setVerticalHeader(resultsBrowser->header()); unused.setVerticalHeader(m_resultsBrowser->header());
resultsBrowser->header()->setParent(resultsBrowser); m_resultsBrowser->header()->setParent(m_resultsBrowser);
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); unused.setVerticalHeader(new QHeaderView(Qt::Horizontal));
#endif #endif
resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection); m_resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection);
box->addWidget(results_lbl); m_box->addWidget(m_resultsLbl);
box->addWidget(resultsBrowser); m_box->addWidget(m_resultsBrowser);
setLayout(m_box);
setLayout(box);
// Set Search results list model // Set Search results list model
SearchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS); m_searchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS, this);
SearchListModel->setHeaderData(SearchSortModel::NAME, Qt::Horizontal, tr("Name", "i.e: file name")); m_searchListModel->setHeaderData(SearchSortModel::NAME, Qt::Horizontal, tr("Name", "i.e: file name"));
SearchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); m_searchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, tr("Size", "i.e: file size"));
SearchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources")); m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources"));
SearchListModel->setHeaderData(SearchSortModel::LEECHS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources")); m_searchListModel->setHeaderData(SearchSortModel::LEECHS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources"));
SearchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine")); m_searchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine"));
proxyModel = new SearchSortModel(); m_proxyModel = new SearchSortModel(this);
proxyModel->setDynamicSortFilter(true); m_proxyModel->setDynamicSortFilter(true);
proxyModel->setSourceModel(SearchListModel); m_proxyModel->setSourceModel(m_searchListModel);
resultsBrowser->setModel(proxyModel); m_resultsBrowser->setModel(m_proxyModel);
SearchDelegate = new SearchListDelegate(); m_searchDelegate = new SearchListDelegate(this);
resultsBrowser->setItemDelegate(SearchDelegate); m_resultsBrowser->setItemDelegate(m_searchDelegate);
resultsBrowser->hideColumn(SearchSortModel::DL_LINK); // Hide url column m_resultsBrowser->hideColumn(SearchSortModel::DL_LINK); // Hide url column
resultsBrowser->hideColumn(SearchSortModel::DESC_LINK); m_resultsBrowser->hideColumn(SearchSortModel::DESC_LINK);
resultsBrowser->setRootIsDecorated(false); m_resultsBrowser->setRootIsDecorated(false);
resultsBrowser->setAllColumnsShowFocus(true); m_resultsBrowser->setAllColumnsShowFocus(true);
resultsBrowser->setSortingEnabled(true); m_resultsBrowser->setSortingEnabled(true);
// Connect signals to slots (search part) // Connect signals to slots (search part)
connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&))); connect(m_resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&)));
// Load last columns width for search results list // Load last columns width for search results list
if (!loadColWidthResultsList()) { if (!loadColWidthResultsList())
resultsBrowser->header()->resizeSection(0, 275); m_resultsBrowser->header()->resizeSection(0, 275);
}
// Sort by Seeds // Sort by Seeds
resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder); m_resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder);
} }
void SearchTab::downloadSelectedItem(const QModelIndex& index) { void SearchTab::downloadSelectedItem(const QModelIndex &index)
QString torrent_url = proxyModel->data(proxyModel->index(index.row(), SearchSortModel::DL_LINK)).toString(); {
QString torrentUrl = m_proxyModel->data(m_proxyModel->index(index.row(), SearchSortModel::DL_LINK)).toString();
setRowColor(index.row(), "blue"); setRowColor(index.row(), "blue");
parent->downloadTorrent(torrent_url); m_parent->downloadTorrent(torrentUrl);
}
SearchTab::~SearchTab() {
delete box;
delete results_lbl;
delete resultsBrowser;
delete SearchListModel;
delete proxyModel;
delete SearchDelegate;
} }
QHeaderView* SearchTab::header() const { QHeaderView* SearchTab::header() const
return resultsBrowser->header(); {
return m_resultsBrowser->header();
} }
bool SearchTab::loadColWidthResultsList() { bool SearchTab::loadColWidthResultsList()
{
QString line = Preferences::instance()->getSearchColsWidth(); QString line = Preferences::instance()->getSearchColsWidth();
if (line.isEmpty()) if (line.isEmpty()) return false;
return false;
QStringList width_list = line.split(' '); QStringList widthList = line.split(' ');
if (width_list.size() > SearchListModel->columnCount()) if (widthList.size() > m_searchListModel->columnCount())
return false; return false;
unsigned int listSize = width_list.size(); unsigned int listSize = widthList.size();
for (unsigned int i=0; i<listSize; ++i) { for (unsigned int i = 0; i < listSize; ++i) {
resultsBrowser->header()->resizeSection(i, width_list.at(i).toInt()); m_resultsBrowser->header()->resizeSection(i, widthList.at(i).toInt());
} }
return true; return true;
} }
QLabel* SearchTab::getCurrentLabel() QLabel* SearchTab::getCurrentLabel() const
{ {
return results_lbl; return m_resultsLbl;
} }
QTreeView* SearchTab::getCurrentTreeView() QTreeView* SearchTab::getCurrentTreeView() const
{ {
return resultsBrowser; return m_resultsBrowser;
} }
QSortFilterProxyModel* SearchTab::getCurrentSearchListProxy() const QSortFilterProxyModel* SearchTab::getCurrentSearchListProxy() const
{ {
return proxyModel; return m_proxyModel;
} }
QStandardItemModel* SearchTab::getCurrentSearchListModel() const QStandardItemModel* SearchTab::getCurrentSearchListModel() const
{ {
return SearchListModel; return m_searchListModel;
} }
// Set the color of a row in data model // Set the color of a row in data model
void SearchTab::setRowColor(int row, QString color) { void SearchTab::setRowColor(int row, QString color)
proxyModel->setDynamicSortFilter(false); {
for (int i=0; i<proxyModel->columnCount(); ++i) { m_proxyModel->setDynamicSortFilter(false);
proxyModel->setData(proxyModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); for (int i = 0; i < m_proxyModel->columnCount(); ++i) {
} m_proxyModel->setData(m_proxyModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole);
proxyModel->setDynamicSortFilter(true); }
m_proxyModel->setDynamicSortFilter(true);
} }
QString SearchTab::status() const
{
return m_status;
}
void SearchTab::setStatus(const QString &value)
{
m_status = value;
}

60
src/gui/search/searchtab.h

@ -31,48 +31,50 @@
#ifndef SEARCHTAB_H #ifndef SEARCHTAB_H
#define SEARCHTAB_H #define SEARCHTAB_H
#include <QLabel> #include <QWidget>
#include <QVBoxLayout>
#include "searchsortmodel.h"
#define ENGINE_URL_COLUMN 4
#define URL_COLUMN 5
class SearchListDelegate;
class SearchWidget;
class QLabel;
class QTreeView; class QTreeView;
class QHeaderView; class QHeaderView;
class QStandardItemModel; class QStandardItemModel;
class QSortFilterProxyModel;
class QModelIndex;
class QVBoxLayout;
class SearchSortModel;
class SearchListDelegate;
class SearchWidget;
class SearchTab: public QWidget class SearchTab: public QWidget
{ {
Q_OBJECT Q_OBJECT
private:
QVBoxLayout *box;
QLabel *results_lbl;
QTreeView *resultsBrowser;
QStandardItemModel *SearchListModel;
SearchSortModel *proxyModel;
SearchListDelegate *SearchDelegate;
SearchWidget *parent;
protected slots:
void downloadSelectedItem(const QModelIndex& index);
public: public:
SearchTab(SearchWidget *parent); explicit SearchTab(SearchWidget *m_parent);
~SearchTab();
bool loadColWidthResultsList(); QLabel* getCurrentLabel() const;
QLabel * getCurrentLabel();
QStandardItemModel* getCurrentSearchListModel() const; QStandardItemModel* getCurrentSearchListModel() const;
QSortFilterProxyModel* getCurrentSearchListProxy() const; QSortFilterProxyModel* getCurrentSearchListProxy() const;
QTreeView * getCurrentTreeView(); QTreeView* getCurrentTreeView() const;
void setRowColor(int row, QString color);
QHeaderView* header() const; QHeaderView* header() const;
QString status; QString status() const;
bool loadColWidthResultsList();
void setRowColor(int row, QString color);
void setStatus(const QString &value);
private slots:
void downloadSelectedItem(const QModelIndex &index);
private:
QVBoxLayout *m_box;
QLabel *m_resultsLbl;
QTreeView *m_resultsBrowser;
QStandardItemModel *m_searchListModel;
SearchSortModel *m_proxyModel;
SearchListDelegate *m_searchDelegate;
SearchWidget *m_parent;
QString m_status;
}; };
#endif // SEARCHTAB_H #endif // SEARCHTAB_H

229
src/gui/search/searchwidget.cpp

@ -29,17 +29,16 @@
* Contact : chris@qbittorrent.org * Contact : chris@qbittorrent.org
*/ */
#include <QStandardItemModel>
#include <QHeaderView> #include <QHeaderView>
#include <QMessageBox> #include <QMessageBox>
#include <QTemporaryFile> #include <QTemporaryFile>
#include <QSystemTrayIcon> #include <QSystemTrayIcon>
#include <iostream>
#include <QTimer> #include <QTimer>
#include <QDir> #include <QDir>
#include <QMenu> #include <QMenu>
#include <QClipboard> #include <QClipboard>
#include <QMimeData> #include <QMimeData>
#include <QStandardItemModel>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QFileDialog> #include <QFileDialog>
#include <QDesktopServices> #include <QDesktopServices>
@ -47,6 +46,7 @@
#include <QProcess> #include <QProcess>
#include <QDebug> #include <QDebug>
#include <iostream>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <stdlib.h> #include <stdlib.h>
#endif #endif
@ -61,22 +61,27 @@
#include "addnewtorrentdialog.h" #include "addnewtorrentdialog.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "lineedit.h" #include "lineedit.h"
#include "pluginselectdlg.h"
#include "searchsortmodel.h"
#include "searchtab.h"
#include "searchwidget.h" #include "searchwidget.h"
#define SEARCHHISTORY_MAXSIZE 50 #define SEARCHHISTORY_MAXSIZE 50
#define URL_COLUMN 5
/*SEARCH ENGINE START*/ SearchWidget::SearchWidget(MainWindow *mainWindow)
SearchWidget::SearchWidget(MainWindow* parent) : QWidget(mainWindow)
: QWidget(parent) , m_mainWindow(mainWindow)
, search_pattern(new LineEdit(this))
, mp_mainWindow(parent)
{ {
setupUi(this); setupUi(this);
searchBarLayout->insertWidget(0, search_pattern);
connect(search_pattern, SIGNAL(returnPressed()), search_button, SLOT(click())); m_searchPattern = new LineEdit(this);
searchBarLayout->insertWidget(0, m_searchPattern);
connect(m_searchPattern, SIGNAL(returnPressed()), searchButton, SLOT(click()));
// Icons // Icons
search_button->setIcon(GuiIconProvider::instance()->getIcon("edit-find")); searchButton->setIcon(GuiIconProvider::instance()->getIcon("edit-find"));
download_button->setIcon(GuiIconProvider::instance()->getIcon("download")); downloadButton->setIcon(GuiIconProvider::instance()->getIcon("download"));
goToDescBtn->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl")); goToDescBtn->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl"));
pluginsButton->setIcon(GuiIconProvider::instance()->getIcon("preferences-system-network")); pluginsButton->setIcon(GuiIconProvider::instance()->getIcon("preferences-system-network"));
copyURLBtn->setIcon(GuiIconProvider::instance()->getIcon("edit-copy")); copyURLBtn->setIcon(GuiIconProvider::instance()->getIcon("edit-copy"));
@ -93,7 +98,7 @@ SearchWidget::SearchWidget(MainWindow* parent)
fillCatCombobox(); fillCatCombobox();
fillPluginComboBox(); fillPluginComboBox();
connect(search_pattern, SIGNAL(textEdited(QString)), this, SLOT(searchTextEdited(QString))); connect(m_searchPattern, SIGNAL(textEdited(QString)), this, SLOT(searchTextEdited(QString)));
connect(selectPlugin, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(selectMultipleBox(const QString &))); connect(selectPlugin, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(selectMultipleBox(const QString &)));
} }
@ -101,8 +106,7 @@ void SearchWidget::fillCatCombobox()
{ {
comboCategory->clear(); comboCategory->clear();
comboCategory->addItem(SearchEngine::categoryFullName("all"), QVariant("all")); comboCategory->addItem(SearchEngine::categoryFullName("all"), QVariant("all"));
QStringList supported_cat = m_searchEngine->supportedCategories(); foreach (QString cat, m_searchEngine->supportedCategories()) {
foreach (QString cat, supported_cat) {
qDebug("Supported category: %s", qPrintable(cat)); qDebug("Supported category: %s", qPrintable(cat));
comboCategory->addItem(SearchEngine::categoryFullName(cat), QVariant(cat)); comboCategory->addItem(SearchEngine::categoryFullName(cat), QVariant(cat));
} }
@ -123,7 +127,7 @@ QString SearchWidget::selectedCategory() const
return comboCategory->itemData(comboCategory->currentIndex()).toString(); return comboCategory->itemData(comboCategory->currentIndex()).toString();
} }
QString SearchWidget::selectedEngine() const QString SearchWidget::selectedPlugin() const
{ {
return selectPlugin->itemData(selectPlugin->currentIndex()).toString(); return selectPlugin->itemData(selectPlugin->currentIndex()).toString();
} }
@ -131,8 +135,6 @@ QString SearchWidget::selectedEngine() const
SearchWidget::~SearchWidget() SearchWidget::~SearchWidget()
{ {
qDebug("Search destruction"); qDebug("Search destruction");
delete search_pattern;
delete m_searchEngine; delete m_searchEngine;
} }
@ -142,24 +144,25 @@ void SearchWidget::tab_changed(int t)
//doesn't have to be available //doesn't have to be available
if (t > -1) { if (t > -1) {
//-1 = no more tab //-1 = no more tab
currentSearchTab = all_tab.at(tabWidget->currentIndex()); m_currentSearchTab = m_allTabs.at(tabWidget->currentIndex());
if (currentSearchTab->getCurrentSearchListModel()->rowCount()) { if (m_currentSearchTab->getCurrentSearchListModel()->rowCount()) {
download_button->setEnabled(true); downloadButton->setEnabled(true);
goToDescBtn->setEnabled(true); goToDescBtn->setEnabled(true);
copyURLBtn->setEnabled(true); copyURLBtn->setEnabled(true);
} }
else { else {
download_button->setEnabled(false); downloadButton->setEnabled(false);
goToDescBtn->setEnabled(false); goToDescBtn->setEnabled(false);
copyURLBtn->setEnabled(false); copyURLBtn->setEnabled(false);
} }
search_status->setText(currentSearchTab->status); searchStatus->setText(m_currentSearchTab->status());
} }
} }
void SearchWidget::selectMultipleBox(const QString &text) void SearchWidget::selectMultipleBox(const QString &text)
{ {
if (text == tr("Multiple...")) on_pluginsButton_clicked(); if (text == tr("Multiple..."))
on_pluginsButton_clicked();
} }
void SearchWidget::on_pluginsButton_clicked() void SearchWidget::on_pluginsButton_clicked()
@ -172,35 +175,35 @@ void SearchWidget::on_pluginsButton_clicked()
void SearchWidget::searchTextEdited(QString) void SearchWidget::searchTextEdited(QString)
{ {
// Enable search button // Enable search button
search_button->setText(tr("Search")); searchButton->setText(tr("Search"));
newQueryString = true; m_isNewQueryString = true;
} }
void SearchWidget::giveFocusToSearchInput() void SearchWidget::giveFocusToSearchInput()
{ {
search_pattern->setFocus(); m_searchPattern->setFocus();
} }
// Function called when we click on search button // Function called when we click on search button
void SearchWidget::on_search_button_clicked() void SearchWidget::on_searchButton_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.")); m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Please install Python to use the Search Engine."));
return; return;
} }
if (m_searchEngine->isActive()) { if (m_searchEngine->isActive()) {
m_searchEngine->cancelSearch(); m_searchEngine->cancelSearch();
if (!newQueryString) { if (!m_isNewQueryString) {
search_button->setText(tr("Search")); searchButton->setText(tr("Search"));
return; return;
} }
} }
newQueryString = false; m_isNewQueryString = false;
const QString pattern = search_pattern->text().trimmed(); const QString pattern = m_searchPattern->text().trimmed();
// No search pattern entered // No search pattern entered
if (pattern.isEmpty()) { if (pattern.isEmpty()) {
QMessageBox::critical(0, tr("Empty search pattern"), tr("Please type a search pattern first")); QMessageBox::critical(0, tr("Empty search pattern"), tr("Please type a search pattern first"));
@ -208,29 +211,29 @@ void SearchWidget::on_search_button_clicked()
} }
// Tab Addition // Tab Addition
currentSearchTab = new SearchTab(this); m_currentSearchTab = new SearchTab(this);
activeSearchTab = currentSearchTab; m_activeSearchTab = m_currentSearchTab;
connect(currentSearchTab->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveResultsColumnsWidth())); connect(m_currentSearchTab->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveResultsColumnsWidth()));
all_tab.append(currentSearchTab); m_allTabs.append(m_currentSearchTab);
QString tabName = pattern; QString tabName = pattern;
tabName.replace(QRegExp("&{1}"), "&&"); tabName.replace(QRegExp("&{1}"), "&&");
tabWidget->addTab(currentSearchTab, tabName); tabWidget->addTab(m_currentSearchTab, tabName);
tabWidget->setCurrentWidget(currentSearchTab); tabWidget->setCurrentWidget(m_currentSearchTab);
QStringList plugins; QStringList plugins;
if (selectedEngine() == "all") plugins = m_searchEngine->allPlugins(); if (selectedPlugin() == "all") plugins = m_searchEngine->allPlugins();
else if (selectedEngine() == "enabled") plugins = m_searchEngine->enabledPlugins(); else if (selectedPlugin() == "enabled") plugins = m_searchEngine->enabledPlugins();
else if (selectedEngine() == "multi") plugins = m_searchEngine->enabledPlugins(); else if (selectedPlugin() == "multi") plugins = m_searchEngine->enabledPlugins();
else plugins << selectedEngine(); else plugins << selectedPlugin();
qDebug("Search with category: %s", qPrintable(selectedCategory())); qDebug("Search with category: %s", qPrintable(selectedCategory()));
// Update SearchEngine widgets // Update SearchEngine widgets
no_search_results = true; m_noSearchResults = true;
nb_search_results = 0; m_nbSearchResults = 0;
// Changing the text of the current label // Changing the text of the current label
activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(0)); m_activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(0));
// Launch search // Launch search
m_searchEngine->startSearch(pattern, selectedCategory(), plugins); m_searchEngine->startSearch(pattern, selectedCategory(), plugins);
@ -238,18 +241,17 @@ void SearchWidget::on_search_button_clicked()
void SearchWidget::saveResultsColumnsWidth() void SearchWidget::saveResultsColumnsWidth()
{ {
if (all_tab.isEmpty()) if (m_allTabs.isEmpty()) return;
return;
QTreeView* treeview = all_tab.first()->getCurrentTreeView(); QTreeView *treeview = m_allTabs.first()->getCurrentTreeView();
Preferences* const pref = Preferences::instance(); QStringList newWidthList;
QStringList new_width_list; short nbColumns = m_allTabs.first()->getCurrentSearchListModel()->columnCount();
short nbColumns = all_tab.first()->getCurrentSearchListModel()->columnCount();
for (short i = 0; i < nbColumns; ++i) for (short i = 0; i < nbColumns; ++i)
if (treeview->columnWidth(i) > 0) if (treeview->columnWidth(i) > 0)
new_width_list << QString::number(treeview->columnWidth(i)); newWidthList << QString::number(treeview->columnWidth(i));
// Don't save the width of the last column (auto column width) // Don't save the width of the last column (auto column width)
new_width_list.removeLast(); newWidthList.removeLast();
pref->setSearchColsWidth(new_width_list.join(" ")); Preferences::instance()->setSearchColsWidth(newWidthList.join(" "));
} }
void SearchWidget::downloadTorrent(QString url) void SearchWidget::downloadTorrent(QString url)
@ -263,10 +265,10 @@ void SearchWidget::downloadTorrent(QString url)
void SearchWidget::searchStarted() void SearchWidget::searchStarted()
{ {
// Update SearchEngine widgets // Update SearchEngine widgets
activeSearchTab->status = tr("Searching..."); m_activeSearchTab->setStatus(tr("Searching..."));
search_status->setText(currentSearchTab->status); searchStatus->setText(m_currentSearchTab->status());
search_status->repaint(); searchStatus->repaint();
search_button->setText(tr("Stop")); searchButton->setText(tr("Stop"));
} }
// Slot called when search is Finished // Slot called when search is Finished
@ -274,72 +276,69 @@ void SearchWidget::searchStarted()
// Error | Stopped by user | Finished normally // Error | Stopped by user | Finished normally
void SearchWidget::searchFinished(bool cancelled) void SearchWidget::searchFinished(bool cancelled)
{ {
bool useNotificationBalloons = Preferences::instance()->useProgramNotification(); if (Preferences::instance()->useProgramNotification() && (m_mainWindow->getCurrentTabWidget() != this))
if (useNotificationBalloons && mp_mainWindow->getCurrentTabWidget() != this) m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished"));
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished"));
if (activeSearchTab.isNull()) return; // The active tab was closed if (m_activeSearchTab.isNull()) return; // The active tab was closed
if (cancelled) if (cancelled)
activeSearchTab->status = tr("Search aborted"); m_activeSearchTab->setStatus(tr("Search aborted"));
else if (no_search_results) else if (m_noSearchResults)
activeSearchTab->status = tr("Search returned no results"); m_activeSearchTab->setStatus(tr("Search returned no results"));
else else
activeSearchTab->status = tr("Search has finished"); m_activeSearchTab->setStatus(tr("Search has finished"));
search_status->setText(currentSearchTab->status); searchStatus->setText(m_currentSearchTab->status());
activeSearchTab = 0; m_activeSearchTab = 0;
search_button->setText(tr("Search")); searchButton->setText(tr("Search"));
} }
void SearchWidget::searchFailed() void SearchWidget::searchFailed()
{ {
bool useNotificationBalloons = Preferences::instance()->useProgramNotification(); if (Preferences::instance()->useProgramNotification() && (m_mainWindow->getCurrentTabWidget() != this))
if (useNotificationBalloons && mp_mainWindow->getCurrentTabWidget() != this) m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has failed"));
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has failed"));
if (activeSearchTab.isNull()) return; // The active tab was closed if (m_activeSearchTab.isNull()) return; // The active tab was closed
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
activeSearchTab->status = tr("Search aborted"); m_activeSearchTab->setStatus(tr("Search aborted"));
#else #else
activeSearchTab->status = tr("An error occurred during search..."); m_activeSearchTab->setStatus(tr("An error occurred during search..."));
#endif #endif
} }
// SLOT to append one line to search results list
void SearchWidget::appendSearchResults(const QList<SearchResult> &results) void SearchWidget::appendSearchResults(const QList<SearchResult> &results)
{ {
if (activeSearchTab.isNull()) { if (m_activeSearchTab.isNull()) {
m_searchEngine->cancelSearch(); m_searchEngine->cancelSearch();
return; return;
} }
Q_ASSERT(activeSearchTab); Q_ASSERT(m_activeSearchTab);
QStandardItemModel* cur_model = activeSearchTab->getCurrentSearchListModel(); QStandardItemModel *curModel = m_activeSearchTab->getCurrentSearchListModel();
Q_ASSERT(cur_model); Q_ASSERT(curModel);
foreach (const SearchResult &result, results) { foreach (const SearchResult &result, results) {
// Add item to search result list // Add item to search result list
int row = cur_model->rowCount(); int row = curModel->rowCount();
cur_model->insertRow(row); curModel->insertRow(row);
cur_model->setData(cur_model->index(row, SearchSortModel::DL_LINK), result.fileUrl); // download URL curModel->setData(curModel->index(row, SearchSortModel::DL_LINK), result.fileUrl); // download URL
cur_model->setData(cur_model->index(row, SearchSortModel::NAME), result.fileName); // Name curModel->setData(curModel->index(row, SearchSortModel::NAME), result.fileName); // Name
cur_model->setData(cur_model->index(row, SearchSortModel::SIZE), result.fileSize); // Size curModel->setData(curModel->index(row, SearchSortModel::SIZE), result.fileSize); // Size
cur_model->setData(cur_model->index(row, SearchSortModel::SEEDS), result.nbSeeders); // Seeders curModel->setData(curModel->index(row, SearchSortModel::SEEDS), result.nbSeeders); // Seeders
cur_model->setData(cur_model->index(row, SearchSortModel::LEECHS), result.nbLeechers); // Leechers curModel->setData(curModel->index(row, SearchSortModel::LEECHS), result.nbLeechers); // Leechers
cur_model->setData(cur_model->index(row, SearchSortModel::ENGINE_URL), result.siteUrl); // Search site URL curModel->setData(curModel->index(row, SearchSortModel::ENGINE_URL), result.siteUrl); // Search site URL
cur_model->setData(cur_model->index(row, SearchSortModel::DESC_LINK), result.descrLink); // Description Link curModel->setData(curModel->index(row, SearchSortModel::DESC_LINK), result.descrLink); // Description Link
} }
no_search_results = false; m_noSearchResults = false;
nb_search_results += results.size(); m_nbSearchResults += results.size();
activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(nb_search_results)); m_activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(m_nbSearchResults));
// Enable clear & download buttons // Enable clear & download buttons
download_button->setEnabled(true); downloadButton->setEnabled(true);
goToDescBtn->setEnabled(true); goToDescBtn->setEnabled(true);
copyURLBtn->setEnabled(true); copyURLBtn->setEnabled(true);
} }
@ -347,46 +346,48 @@ void SearchWidget::appendSearchResults(const QList<SearchResult> &results)
void SearchWidget::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 (!m_activeSearchTab.isNull() && index == tabWidget->indexOf(m_activeSearchTab)) {
qDebug("Closed active search Tab"); qDebug("Closed active search Tab");
if (m_searchEngine->isActive()) if (m_searchEngine->isActive())
m_searchEngine->cancelSearch(); m_searchEngine->cancelSearch();
activeSearchTab = 0; m_activeSearchTab = 0;
} }
delete all_tab.takeAt(index);
if (!all_tab.size()) { delete m_allTabs.takeAt(index);
download_button->setEnabled(false);
if (!m_allTabs.size()) {
downloadButton->setEnabled(false);
goToDescBtn->setEnabled(false); goToDescBtn->setEnabled(false);
search_status->setText(tr("Stopped")); searchStatus->setText(tr("Stopped"));
copyURLBtn->setEnabled(false); copyURLBtn->setEnabled(false);
} }
} }
// Download selected items in search results list // Download selected items in search results list
void SearchWidget::on_download_button_clicked() void SearchWidget::on_downloadButton_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 = m_allTabs.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
foreach (const QModelIndex &index, selectedIndexes) { foreach (const QModelIndex &index, selectedIndexes) {
if (index.column() == SearchSortModel::NAME) { if (index.column() == SearchSortModel::NAME) {
// Get Item url // Get Item url
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); QSortFilterProxyModel *model = m_allTabs.at(tabWidget->currentIndex())->getCurrentSearchListProxy();
QString torrent_url = model->data(model->index(index.row(), URL_COLUMN)).toString(); QString torrentUrl = model->data(model->index(index.row(), URL_COLUMN)).toString();
downloadTorrent(torrent_url); downloadTorrent(torrentUrl);
all_tab.at(tabWidget->currentIndex())->setRowColor(index.row(), "blue"); m_allTabs.at(tabWidget->currentIndex())->setRowColor(index.row(), "blue");
} }
} }
} }
void SearchWidget::on_goToDescBtn_clicked() void SearchWidget::on_goToDescBtn_clicked()
{ {
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = m_allTabs.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
foreach (const QModelIndex &index, selectedIndexes) { foreach (const QModelIndex &index, selectedIndexes) {
if (index.column() == SearchSortModel::NAME) { if (index.column() == SearchSortModel::NAME) {
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); QSortFilterProxyModel *model = m_allTabs.at(tabWidget->currentIndex())->getCurrentSearchListProxy();
const QString desc_url = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString(); const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString();
if (!desc_url.isEmpty()) if (!descUrl.isEmpty())
QDesktopServices::openUrl(QUrl::fromEncoded(desc_url.toUtf8())); QDesktopServices::openUrl(QUrl::fromEncoded(descUrl.toUtf8()));
} }
} }
} }
@ -394,15 +395,17 @@ void SearchWidget::on_goToDescBtn_clicked()
void SearchWidget::on_copyURLBtn_clicked() void SearchWidget::on_copyURLBtn_clicked()
{ {
QStringList urls; QStringList urls;
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); QModelIndexList selectedIndexes = m_allTabs.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes();
foreach (const QModelIndex &index, selectedIndexes) { foreach (const QModelIndex &index, selectedIndexes) {
if (index.column() == SearchSortModel::NAME) { if (index.column() == SearchSortModel::NAME) {
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); QSortFilterProxyModel *model = m_allTabs.at(tabWidget->currentIndex())->getCurrentSearchListProxy();
const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString(); const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString();
if (!descUrl.isEmpty()) if (!descUrl.isEmpty())
urls << descUrl.toUtf8(); urls << descUrl.toUtf8();
} }
} }
if (!urls.empty()) { if (!urls.empty()) {
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(urls.join("\n")); clipboard->setText(urls.join("\n"));

54
src/gui/search/searchwidget.h

@ -33,69 +33,63 @@
#define SEARCHWIDGET_H #define SEARCHWIDGET_H
#include <QList> #include <QList>
#include <QPair>
#include <QPointer> #include <QPointer>
#include <QStringListModel>
#include "ui_searchwidget.h" #include "ui_searchwidget.h"
#include "pluginselectdlg.h"
#include "searchtab.h"
class SearchWidget;
class MainWindow; class MainWindow;
class LineEdit; class LineEdit;
class SearchEngine; class SearchEngine;
struct SearchResult; struct SearchResult;
class SearchTab;
QT_BEGIN_NAMESPACE class SearchWidget: public QWidget, private Ui::SearchWidget
class QTimer; {
QT_END_NAMESPACE
class SearchWidget : public QWidget, private Ui::SearchWidget{
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(SearchWidget) Q_DISABLE_COPY(SearchWidget)
public: public:
SearchWidget(MainWindow *mp_mainWindow); explicit SearchWidget(MainWindow *mainWindow);
~SearchWidget(); ~SearchWidget();
QString selectedCategory() const;
QString selectedEngine() const;
public slots:
void downloadTorrent(QString url); void downloadTorrent(QString url);
void giveFocusToSearchInput(); void giveFocusToSearchInput();
private slots: private slots:
// Search slots // Search slots
void tab_changed(int);//to prevent the use of the download button when the tab is empty void tab_changed(int); //to prevent the use of the download button when the tab is empty
void on_search_button_clicked(); void on_searchButton_clicked();
void on_download_button_clicked(); void on_downloadButton_clicked();
void on_goToDescBtn_clicked();
void on_copyURLBtn_clicked();
void on_pluginsButton_clicked();
void closeTab(int index); void closeTab(int index);
void appendSearchResults(const QList<SearchResult> &results); void appendSearchResults(const QList<SearchResult> &results);
void searchStarted(); void searchStarted();
void searchFinished(bool cancelled); void searchFinished(bool cancelled);
void searchFailed(); void searchFailed();
void selectMultipleBox(const QString &text); void selectMultipleBox(const QString &text);
void on_pluginsButton_clicked();
void saveResultsColumnsWidth(); void saveResultsColumnsWidth();
void fillCatCombobox(); void fillCatCombobox();
void fillPluginComboBox(); void fillPluginComboBox();
void searchTextEdited(QString); void searchTextEdited(QString);
void on_goToDescBtn_clicked();
void on_copyURLBtn_clicked();
private: private:
// Search related QString selectedCategory() const;
LineEdit* search_pattern; QString selectedPlugin() const;
bool no_search_results; LineEdit *m_searchPattern;
QByteArray search_result_line_truncated;
unsigned long nb_search_results;
SearchEngine *m_searchEngine; SearchEngine *m_searchEngine;
QPointer<SearchTab> currentSearchTab; // Selected tab QPointer<SearchTab> m_currentSearchTab; // Selected tab
QPointer<SearchTab> activeSearchTab; // Tab with running search QPointer<SearchTab> m_activeSearchTab; // Tab with running search
QList<QPointer<SearchTab> > all_tab; // To store all tabs QList<QPointer<SearchTab> > m_allTabs; // To store all tabs
MainWindow *mp_mainWindow; MainWindow *m_mainWindow;
bool newQueryString; bool m_isNewQueryString;
bool m_noSearchResults;
QByteArray m_searchResultLineTruncated;
unsigned long m_nbSearchResults;
}; };
#endif // SEARCHWIDGET_H #endif // SEARCHWIDGET_H

6
src/gui/search/searchwidget.ui

@ -23,7 +23,7 @@
<widget class="QComboBox" name="selectPlugin"/> <widget class="QComboBox" name="selectPlugin"/>
</item> </item>
<item> <item>
<widget class="QPushButton" name="search_button"> <widget class="QPushButton" name="searchButton">
<property name="text"> <property name="text">
<string>Search</string> <string>Search</string>
</property> </property>
@ -53,7 +53,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="search_status"> <widget class="QLabel" name="searchStatus">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>200</width> <width>200</width>
@ -99,7 +99,7 @@
<item> <item>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<item> <item>
<widget class="QPushButton" name="download_button"> <widget class="QPushButton" name="downloadButton">
<property name="enabled"> <property name="enabled">
<bool>false</bool> <bool>false</bool>
</property> </property>

Loading…
Cancel
Save