sledgehammer999
9 years ago
37 changed files with 2353 additions and 2022 deletions
@ -0,0 +1,657 @@ |
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent. |
||||||
|
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> |
||||||
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or |
||||||
|
* modify it under the terms of the GNU General Public License |
||||||
|
* 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 <QDomDocument> |
||||||
|
#include <QDomNode> |
||||||
|
#include <QDomElement> |
||||||
|
#include <QDir> |
||||||
|
#include <QProcess> |
||||||
|
#include <QDebug> |
||||||
|
|
||||||
|
#include "base/utils/fs.h" |
||||||
|
#include "base/utils/misc.h" |
||||||
|
#include "base/preferences.h" |
||||||
|
#include "base/net/downloadmanager.h" |
||||||
|
#include "base/net/downloadhandler.h" |
||||||
|
#include "searchengine.h" |
||||||
|
|
||||||
|
enum SearchResultColumn |
||||||
|
{ |
||||||
|
PL_DL_LINK, |
||||||
|
PL_NAME, |
||||||
|
PL_SIZE, |
||||||
|
PL_SEEDS, |
||||||
|
PL_LEECHS, |
||||||
|
PL_ENGINE_URL, |
||||||
|
PL_DESC_LINK, |
||||||
|
NB_PLUGIN_COLUMNS |
||||||
|
}; |
||||||
|
|
||||||
|
static inline void removePythonScriptIfExists(const QString &scriptPath) |
||||||
|
{ |
||||||
|
Utils::Fs::forceRemove(scriptPath); |
||||||
|
Utils::Fs::forceRemove(scriptPath + "c"); |
||||||
|
} |
||||||
|
|
||||||
|
const QHash<QString, QString> SearchEngine::m_categoryNames = SearchEngine::initializeCategoryNames(); |
||||||
|
|
||||||
|
SearchEngine::SearchEngine() |
||||||
|
: 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(); |
||||||
|
|
||||||
|
m_searchProcess = new QProcess(this); |
||||||
|
m_searchProcess->setEnvironment(QProcess::systemEnvironment()); |
||||||
|
connect(m_searchProcess, SIGNAL(started()), this, SIGNAL(searchStarted())); |
||||||
|
connect(m_searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput())); |
||||||
|
connect(m_searchProcess, SIGNAL(finished(int)), this, SLOT(processFinished(int))); |
||||||
|
|
||||||
|
m_searchTimeout = new QTimer(this); |
||||||
|
m_searchTimeout->setSingleShot(true); |
||||||
|
connect(m_searchTimeout, SIGNAL(timeout()), this, SLOT(onTimeout())); |
||||||
|
|
||||||
|
update(); |
||||||
|
} |
||||||
|
|
||||||
|
SearchEngine::~SearchEngine() |
||||||
|
{ |
||||||
|
qDeleteAll(m_plugins.values()); |
||||||
|
cancelSearch(); |
||||||
|
} |
||||||
|
|
||||||
|
QStringList SearchEngine::allPlugins() const |
||||||
|
{ |
||||||
|
return m_plugins.keys(); |
||||||
|
} |
||||||
|
|
||||||
|
QStringList SearchEngine::enabledPlugins() const |
||||||
|
{ |
||||||
|
QStringList plugins; |
||||||
|
foreach (const PluginInfo *plugin, m_plugins.values()) { |
||||||
|
if (plugin->enabled) |
||||||
|
plugins << plugin->name; |
||||||
|
} |
||||||
|
|
||||||
|
return plugins; |
||||||
|
} |
||||||
|
|
||||||
|
QStringList SearchEngine::supportedCategories() const |
||||||
|
{ |
||||||
|
QStringList result; |
||||||
|
foreach (const PluginInfo *plugin, m_plugins.values()) { |
||||||
|
if (plugin->enabled) { |
||||||
|
foreach (QString cat, plugin->supportedCategories) { |
||||||
|
if (!result.contains(cat)) |
||||||
|
result << cat; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
PluginInfo *SearchEngine::pluginInfo(const QString &name) const |
||||||
|
{ |
||||||
|
return m_plugins.value(name, 0); |
||||||
|
} |
||||||
|
|
||||||
|
bool SearchEngine::isActive() const |
||||||
|
{ |
||||||
|
return (m_searchProcess->state() != QProcess::NotRunning); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::enablePlugin(const QString &name, bool enabled) |
||||||
|
{ |
||||||
|
PluginInfo *plugin = m_plugins.value(name, 0); |
||||||
|
if (plugin) { |
||||||
|
plugin->enabled = enabled; |
||||||
|
// Save to Hard disk
|
||||||
|
Preferences *const pref = Preferences::instance(); |
||||||
|
QStringList disabledPlugins = pref->getSearchEngDisabled(); |
||||||
|
if (enabled) |
||||||
|
disabledPlugins.removeAll(name); |
||||||
|
else if (!disabledPlugins.contains(name)) |
||||||
|
disabledPlugins.append(name); |
||||||
|
pref->setSearchEngDisabled(disabledPlugins); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Updates shipped plugin
|
||||||
|
void SearchEngine::updatePlugin(const QString &name) |
||||||
|
{ |
||||||
|
installPlugin(QString("%1%2.py").arg(m_updateUrl).arg(name)); |
||||||
|
} |
||||||
|
|
||||||
|
// Install or update plugin from file or url
|
||||||
|
void SearchEngine::installPlugin(const QString &source) |
||||||
|
{ |
||||||
|
qDebug("Asked to install plugin at %s", qPrintable(source)); |
||||||
|
|
||||||
|
if (Utils::Misc::isUrl(source)) { |
||||||
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(source, true); |
||||||
|
connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(pluginDownloaded(QString, QString))); |
||||||
|
connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(pluginDownloadFailed(QString, QString))); |
||||||
|
} |
||||||
|
else { |
||||||
|
QString path = source; |
||||||
|
if (path.startsWith("file:", Qt::CaseInsensitive)) |
||||||
|
path = QUrl(path).toLocalFile(); |
||||||
|
|
||||||
|
QString pluginName = Utils::Fs::fileName(path); |
||||||
|
pluginName.chop(pluginName.size() - pluginName.lastIndexOf(".")); |
||||||
|
|
||||||
|
if (!path.endsWith(".py", Qt::CaseInsensitive)) |
||||||
|
emit pluginInstallationFailed(pluginName, tr("Unknown search engine plugin file format.")); |
||||||
|
else |
||||||
|
installPlugin_impl(pluginName, path); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::installPlugin_impl(const QString &name, const QString &path) |
||||||
|
{ |
||||||
|
qreal newVersion = getPluginVersion(path); |
||||||
|
qDebug("Version to be installed: %.2f", newVersion); |
||||||
|
|
||||||
|
PluginInfo *plugin = pluginInfo(name); |
||||||
|
if (plugin && (plugin->version >= newVersion)) { |
||||||
|
qDebug("Apparently update is not needed, we have a more recent version"); |
||||||
|
emit pluginUpdateFailed(name, tr("A more recent version of this plugin is already installed.")); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// Process with install
|
||||||
|
QString destPath = pluginPath(name); |
||||||
|
bool updated = false; |
||||||
|
if (QFile::exists(destPath)) { |
||||||
|
// Backup in case install fails
|
||||||
|
QFile::copy(destPath, destPath + ".bak"); |
||||||
|
Utils::Fs::forceRemove(destPath); |
||||||
|
Utils::Fs::forceRemove(destPath + "c"); |
||||||
|
updated = true; |
||||||
|
} |
||||||
|
// Copy the plugin
|
||||||
|
QFile::copy(path, destPath); |
||||||
|
// Update supported plugins
|
||||||
|
update(); |
||||||
|
// Check if this was correctly installed
|
||||||
|
if (!m_plugins.contains(name)) { |
||||||
|
// Remove broken file
|
||||||
|
Utils::Fs::forceRemove(destPath); |
||||||
|
if (updated) { |
||||||
|
// restore backup
|
||||||
|
QFile::copy(destPath + ".bak", destPath); |
||||||
|
Utils::Fs::forceRemove(destPath + ".bak"); |
||||||
|
// Update supported plugins
|
||||||
|
update(); |
||||||
|
emit pluginUpdateFailed(name, tr("Plugin is not supported.")); |
||||||
|
} |
||||||
|
else { |
||||||
|
emit pluginInstallationFailed(name, tr("Plugin is not supported.")); |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
// Install was successful, remove backup
|
||||||
|
if (updated) |
||||||
|
Utils::Fs::forceRemove(destPath + ".bak"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
bool SearchEngine::uninstallPlugin(const QString &name) |
||||||
|
{ |
||||||
|
if (QFile::exists(":/nova/engines/" + name + ".py")) |
||||||
|
return false; |
||||||
|
|
||||||
|
// Proceed with uninstall
|
||||||
|
// remove it from hard drive
|
||||||
|
QDir pluginsFolder(pluginsLocation()); |
||||||
|
QStringList filters; |
||||||
|
filters << name + ".*"; |
||||||
|
QStringList files = pluginsFolder.entryList(filters, QDir::Files, QDir::Unsorted); |
||||||
|
QString file; |
||||||
|
foreach (file, files) |
||||||
|
Utils::Fs::forceRemove(pluginsFolder.absoluteFilePath(file)); |
||||||
|
// Remove it from supported engines
|
||||||
|
delete m_plugins.take(name); |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::checkForUpdates() |
||||||
|
{ |
||||||
|
// Download version file from update server on sourceforge
|
||||||
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(m_updateUrl + "versions.txt"); |
||||||
|
connect(handler, SIGNAL(downloadFinished(QString, QByteArray)), this, SLOT(versionInfoDownloaded(QString, QByteArray))); |
||||||
|
connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(versionInfoDownloadFailed(QString, QString))); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::cancelSearch() |
||||||
|
{ |
||||||
|
if (m_searchProcess->state() != QProcess::NotRunning) { |
||||||
|
#ifdef Q_OS_WIN |
||||||
|
m_searchProcess->kill(); |
||||||
|
#else |
||||||
|
m_searchProcess->terminate(); |
||||||
|
#endif |
||||||
|
m_searchStopped = true; |
||||||
|
m_searchTimeout->stop(); |
||||||
|
|
||||||
|
m_searchProcess->waitForFinished(1000); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::startSearch(const QString &pattern, const QString &category, const QStringList &usedPlugins) |
||||||
|
{ |
||||||
|
// Search process already running or
|
||||||
|
// No search pattern entered
|
||||||
|
if ((m_searchProcess->state() != QProcess::NotRunning) || pattern.isEmpty()) { |
||||||
|
emit searchFailed(); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// Reload environment variables (proxy)
|
||||||
|
m_searchProcess->setEnvironment(QProcess::systemEnvironment()); |
||||||
|
|
||||||
|
QStringList params; |
||||||
|
m_searchStopped = false; |
||||||
|
params << Utils::Fs::toNativePath(engineLocation() + "/nova2.py"); |
||||||
|
params << usedPlugins.join(","); |
||||||
|
params << category; |
||||||
|
params << pattern.split(" "); |
||||||
|
|
||||||
|
// Launch search
|
||||||
|
m_searchProcess->start(Utils::Misc::pythonExecutable(), params, QIODevice::ReadOnly); |
||||||
|
m_searchTimeout->start(180000); // 3min
|
||||||
|
} |
||||||
|
|
||||||
|
QString SearchEngine::categoryFullName(const QString &categoryName) |
||||||
|
{ |
||||||
|
return tr(m_categoryNames.value(categoryName).toUtf8().constData()); |
||||||
|
} |
||||||
|
|
||||||
|
QString SearchEngine::pluginsLocation() |
||||||
|
{ |
||||||
|
return QString("%1/engines").arg(engineLocation()); |
||||||
|
} |
||||||
|
|
||||||
|
QString SearchEngine::engineLocation() |
||||||
|
{ |
||||||
|
QString folder = "nova"; |
||||||
|
if (Utils::Misc::pythonVersion() >= 3) |
||||||
|
folder = "nova3"; |
||||||
|
const QString location = Utils::Fs::expandPathAbs(Utils::Fs::QDesktopServicesDataLocation() + folder); |
||||||
|
QDir locationDir(location); |
||||||
|
if (!locationDir.exists()) |
||||||
|
locationDir.mkpath(locationDir.absolutePath()); |
||||||
|
return location; |
||||||
|
} |
||||||
|
|
||||||
|
// Slot called when QProcess is Finished
|
||||||
|
// QProcess can be finished for 3 reasons :
|
||||||
|
// Error | Stopped by user | Finished normally
|
||||||
|
void SearchEngine::processFinished(int exitcode) |
||||||
|
{ |
||||||
|
m_searchTimeout->stop(); |
||||||
|
|
||||||
|
if (exitcode == 0) |
||||||
|
emit searchFinished(m_searchStopped); |
||||||
|
else |
||||||
|
emit searchFailed(); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::versionInfoDownloaded(const QString &url, const QByteArray &data) |
||||||
|
{ |
||||||
|
Q_UNUSED(url) |
||||||
|
parseVersionInfo(data); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::versionInfoDownloadFailed(const QString &url, const QString &reason) |
||||||
|
{ |
||||||
|
Q_UNUSED(url) |
||||||
|
emit checkForUpdatesFailed(tr("Update server is temporarily unavailable. %1").arg(reason)); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::pluginDownloaded(const QString &url, QString filePath) |
||||||
|
{ |
||||||
|
filePath = Utils::Fs::fromNativePath(filePath); |
||||||
|
|
||||||
|
QString pluginName = Utils::Fs::fileName(url); |
||||||
|
pluginName.chop(pluginName.size() - pluginName.lastIndexOf(".")); // Remove extension
|
||||||
|
installPlugin_impl(pluginName, filePath); |
||||||
|
Utils::Fs::forceRemove(filePath); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::pluginDownloadFailed(const QString &url, const QString &reason) |
||||||
|
{ |
||||||
|
QString pluginName = url.split('/').last(); |
||||||
|
pluginName.replace(".py", "", Qt::CaseInsensitive); |
||||||
|
if (pluginInfo(pluginName)) |
||||||
|
emit pluginUpdateFailed(pluginName, tr("Failed to download the plugin file. %1").arg(reason)); |
||||||
|
else |
||||||
|
emit pluginInstallationFailed(pluginName, tr("Failed to download the plugin file. %1").arg(reason)); |
||||||
|
} |
||||||
|
|
||||||
|
// Update nova.py search plugin if necessary
|
||||||
|
void SearchEngine::updateNova() |
||||||
|
{ |
||||||
|
qDebug("Updating nova"); |
||||||
|
|
||||||
|
// create nova directory if necessary
|
||||||
|
QDir searchDir(engineLocation()); |
||||||
|
QString novaFolder = Utils::Misc::pythonVersion() >= 3 ? "searchengine/nova3" : "searchengine/nova"; |
||||||
|
QFile packageFile(searchDir.absoluteFilePath("__init__.py")); |
||||||
|
packageFile.open(QIODevice::WriteOnly | QIODevice::Text); |
||||||
|
packageFile.close(); |
||||||
|
if (!searchDir.exists("engines")) |
||||||
|
searchDir.mkdir("engines"); |
||||||
|
Utils::Fs::removeDirRecursive(searchDir.absoluteFilePath("__pycache__")); |
||||||
|
|
||||||
|
QFile packageFile2(searchDir.absolutePath() + "/engines/__init__.py"); |
||||||
|
packageFile2.open(QIODevice::WriteOnly | QIODevice::Text); |
||||||
|
packageFile2.close(); |
||||||
|
|
||||||
|
// Copy search plugin files (if necessary)
|
||||||
|
QString filePath = searchDir.absoluteFilePath("nova2.py"); |
||||||
|
if (getPluginVersion(":/" + novaFolder + "/nova2.py") > getPluginVersion(filePath)) { |
||||||
|
removePythonScriptIfExists(filePath); |
||||||
|
QFile::copy(":/" + novaFolder + "/nova2.py", filePath); |
||||||
|
} |
||||||
|
|
||||||
|
filePath = searchDir.absoluteFilePath("fix_encoding.py"); |
||||||
|
QFile::copy(":/" + novaFolder + "/fix_encoding.py", filePath); |
||||||
|
|
||||||
|
filePath = searchDir.absoluteFilePath("novaprinter.py"); |
||||||
|
if (getPluginVersion(":/" + novaFolder + "/novaprinter.py") > getPluginVersion(filePath)) { |
||||||
|
removePythonScriptIfExists(filePath); |
||||||
|
QFile::copy(":/" + novaFolder + "/novaprinter.py", filePath); |
||||||
|
} |
||||||
|
|
||||||
|
filePath = searchDir.absoluteFilePath("helpers.py"); |
||||||
|
if (getPluginVersion(":/" + novaFolder + "/helpers.py") > getPluginVersion(filePath)) { |
||||||
|
removePythonScriptIfExists(filePath); |
||||||
|
QFile::copy(":/" + novaFolder + "/helpers.py", filePath); |
||||||
|
} |
||||||
|
|
||||||
|
filePath = searchDir.absoluteFilePath("socks.py"); |
||||||
|
removePythonScriptIfExists(filePath); |
||||||
|
QFile::copy(":/" + novaFolder + "/socks.py", filePath); |
||||||
|
|
||||||
|
if (novaFolder.endsWith("nova")) { |
||||||
|
filePath = searchDir.absoluteFilePath("fix_encoding.py"); |
||||||
|
removePythonScriptIfExists(filePath); |
||||||
|
QFile::copy(":/" + novaFolder + "/fix_encoding.py", filePath); |
||||||
|
} |
||||||
|
else if (novaFolder.endsWith("nova3")) { |
||||||
|
filePath = searchDir.absoluteFilePath("sgmllib3.py"); |
||||||
|
removePythonScriptIfExists(filePath); |
||||||
|
QFile::copy(":/" + novaFolder + "/sgmllib3.py", filePath); |
||||||
|
} |
||||||
|
|
||||||
|
QDir destDir(pluginsLocation()); |
||||||
|
Utils::Fs::removeDirRecursive(destDir.absoluteFilePath("__pycache__")); |
||||||
|
QDir shippedSubdir(":/" + novaFolder + "/engines/"); |
||||||
|
QStringList files = shippedSubdir.entryList(); |
||||||
|
foreach (const QString &file, files) { |
||||||
|
QString shippedFile = shippedSubdir.absoluteFilePath(file); |
||||||
|
// Copy python classes
|
||||||
|
if (file.endsWith(".py")) { |
||||||
|
const QString destFile = destDir.absoluteFilePath(file); |
||||||
|
if (getPluginVersion(shippedFile) > getPluginVersion(destFile) ) { |
||||||
|
qDebug("shipped %s is more recent then local plugin, updating...", qPrintable(file)); |
||||||
|
removePythonScriptIfExists(destFile); |
||||||
|
qDebug("%s copied to %s", qPrintable(shippedFile), qPrintable(destFile)); |
||||||
|
QFile::copy(shippedFile, destFile); |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
// Copy icons
|
||||||
|
if (file.endsWith(".png")) |
||||||
|
if (!QFile::exists(destDir.absoluteFilePath(file))) |
||||||
|
QFile::copy(shippedFile, destDir.absoluteFilePath(file)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::onTimeout() |
||||||
|
{ |
||||||
|
cancelSearch(); |
||||||
|
} |
||||||
|
|
||||||
|
// search QProcess return output as soon as it gets new
|
||||||
|
// stuff to read. We split it into lines and parse each
|
||||||
|
// line to SearchResult calling parseSearchResult().
|
||||||
|
void SearchEngine::readSearchOutput() |
||||||
|
{ |
||||||
|
QByteArray output = m_searchProcess->readAllStandardOutput(); |
||||||
|
output.replace("\r", ""); |
||||||
|
QList<QByteArray> lines = output.split('\n'); |
||||||
|
if (!m_searchResultLineTruncated.isEmpty()) |
||||||
|
lines.prepend(m_searchResultLineTruncated + lines.takeFirst()); |
||||||
|
m_searchResultLineTruncated = lines.takeLast().trimmed(); |
||||||
|
|
||||||
|
QList<SearchResult> searchResultList; |
||||||
|
foreach (const QByteArray &line, lines) { |
||||||
|
SearchResult searchResult; |
||||||
|
if (parseSearchResult(QString::fromUtf8(line), searchResult)) |
||||||
|
searchResultList << searchResult; |
||||||
|
} |
||||||
|
|
||||||
|
if (!searchResultList.isEmpty()) |
||||||
|
emit newSearchResults(searchResultList); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::update() |
||||||
|
{ |
||||||
|
QProcess nova; |
||||||
|
nova.setEnvironment(QProcess::systemEnvironment()); |
||||||
|
QStringList params; |
||||||
|
params << Utils::Fs::toNativePath(engineLocation() + "/nova2.py"); |
||||||
|
params << "--capabilities"; |
||||||
|
nova.start(Utils::Misc::pythonExecutable(), params, QIODevice::ReadOnly); |
||||||
|
nova.waitForStarted(); |
||||||
|
nova.waitForFinished(); |
||||||
|
|
||||||
|
QString capabilities = QString(nova.readAll()); |
||||||
|
QDomDocument xmlDoc; |
||||||
|
if (!xmlDoc.setContent(capabilities)) { |
||||||
|
qWarning() << "Could not parse Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data(); |
||||||
|
qWarning() << "Error: " << nova.readAllStandardError().constData(); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
QDomElement root = xmlDoc.documentElement(); |
||||||
|
if (root.tagName() != "capabilities") { |
||||||
|
qWarning() << "Invalid XML file for Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data(); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
for (QDomNode engineNode = root.firstChild(); !engineNode.isNull(); engineNode = engineNode.nextSibling()) { |
||||||
|
QDomElement engineElem = engineNode.toElement(); |
||||||
|
if (!engineElem.isNull()) { |
||||||
|
QString pluginName = engineElem.tagName(); |
||||||
|
|
||||||
|
PluginInfo *plugin = new PluginInfo; |
||||||
|
plugin->name = pluginName; |
||||||
|
plugin->version = getPluginVersion(pluginPath(pluginName)); |
||||||
|
plugin->fullName = engineElem.elementsByTagName("name").at(0).toElement().text(); |
||||||
|
plugin->url = engineElem.elementsByTagName("url").at(0).toElement().text(); |
||||||
|
|
||||||
|
foreach (QString cat, engineElem.elementsByTagName("categories").at(0).toElement().text().split(" ")) { |
||||||
|
cat = cat.trimmed(); |
||||||
|
if (!cat.isEmpty()) |
||||||
|
plugin->supportedCategories << cat; |
||||||
|
} |
||||||
|
|
||||||
|
QStringList disabledEngines = Preferences::instance()->getSearchEngDisabled(); |
||||||
|
plugin->enabled = !disabledEngines.contains(pluginName); |
||||||
|
|
||||||
|
// Handle icon
|
||||||
|
QString iconPath = QString("%1/%2.png").arg(pluginsLocation()).arg(pluginName); |
||||||
|
if (QFile::exists(iconPath)) { |
||||||
|
plugin->iconPath = iconPath; |
||||||
|
} |
||||||
|
else { |
||||||
|
iconPath = QString("%1/%2.ico").arg(pluginsLocation()).arg(pluginName); |
||||||
|
if (QFile::exists(iconPath)) |
||||||
|
plugin->iconPath = iconPath; |
||||||
|
} |
||||||
|
|
||||||
|
if (!m_plugins.contains(pluginName)) { |
||||||
|
m_plugins[pluginName] = plugin; |
||||||
|
emit pluginInstalled(pluginName); |
||||||
|
} |
||||||
|
else if (m_plugins[pluginName]->version != plugin->version) { |
||||||
|
delete m_plugins.take(pluginName); |
||||||
|
m_plugins[pluginName] = plugin; |
||||||
|
emit pluginUpdated(pluginName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Parse one line of search results list
|
||||||
|
// Line is in the following form:
|
||||||
|
// file url | file name | file size | nb seeds | nb leechers | Search engine url
|
||||||
|
bool SearchEngine::parseSearchResult(const QString &line, SearchResult &searchResult) |
||||||
|
{ |
||||||
|
const QStringList parts = line.split("|"); |
||||||
|
const int nbFields = parts.size(); |
||||||
|
if (nbFields < (NB_PLUGIN_COLUMNS - 1)) return false; // -1 because desc_link is optional
|
||||||
|
|
||||||
|
searchResult = SearchResult(); |
||||||
|
searchResult.fileUrl = parts.at(PL_DL_LINK).trimmed(); // download URL
|
||||||
|
searchResult.fileName = parts.at(PL_NAME).trimmed(); // Name
|
||||||
|
searchResult.fileSize = parts.at(PL_SIZE).trimmed().toLongLong(); // Size
|
||||||
|
bool ok = false; |
||||||
|
searchResult.nbSeeders = parts.at(PL_SEEDS).trimmed().toLongLong(&ok); // Seeders
|
||||||
|
if (!ok || (searchResult.nbSeeders < 0)) |
||||||
|
searchResult.nbSeeders = -1; |
||||||
|
searchResult.nbLeechers = parts.at(PL_LEECHS).trimmed().toLongLong(&ok); // Leechers
|
||||||
|
if (!ok || (searchResult.nbLeechers < 0)) |
||||||
|
searchResult.nbLeechers = -1; |
||||||
|
searchResult.siteUrl = parts.at(PL_ENGINE_URL).trimmed(); // Search site URL
|
||||||
|
if (nbFields == NB_PLUGIN_COLUMNS) |
||||||
|
searchResult.descrLink = parts.at(PL_DESC_LINK).trimmed(); // Description Link
|
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
void SearchEngine::parseVersionInfo(const QByteArray &info) |
||||||
|
{ |
||||||
|
qDebug("Checking if update is needed"); |
||||||
|
|
||||||
|
QHash<QString, qreal> updateInfo; |
||||||
|
bool dataCorrect = false; |
||||||
|
QList<QByteArray> lines = info.split('\n'); |
||||||
|
foreach (QByteArray line, lines) { |
||||||
|
line = line.trimmed(); |
||||||
|
if (line.isEmpty()) continue; |
||||||
|
if (line.startsWith("#")) continue; |
||||||
|
|
||||||
|
QList<QByteArray> list = line.split(' '); |
||||||
|
if (list.size() != 2) continue; |
||||||
|
|
||||||
|
QString pluginName = QString(list.first()); |
||||||
|
if (!pluginName.endsWith(":")) continue; |
||||||
|
|
||||||
|
pluginName.chop(1); // remove trailing ':'
|
||||||
|
bool ok; |
||||||
|
qreal version = list.last().toFloat(&ok); |
||||||
|
qDebug("read line %s: %.2f", qPrintable(pluginName), version); |
||||||
|
if (!ok) continue; |
||||||
|
|
||||||
|
dataCorrect = true; |
||||||
|
if (isUpdateNeeded(pluginName, version)) { |
||||||
|
qDebug("Plugin: %s is outdated", qPrintable(pluginName)); |
||||||
|
updateInfo[pluginName] = version; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!dataCorrect) |
||||||
|
emit checkForUpdatesFailed(tr("An incorrect update info received.")); |
||||||
|
else |
||||||
|
emit checkForUpdatesFinished(updateInfo); |
||||||
|
} |
||||||
|
|
||||||
|
bool SearchEngine::isUpdateNeeded(QString pluginName, qreal newVersion) const |
||||||
|
{ |
||||||
|
PluginInfo *plugin = pluginInfo(pluginName); |
||||||
|
if (!plugin) return true; |
||||||
|
|
||||||
|
qreal oldVersion = plugin->version; |
||||||
|
qDebug("IsUpdate needed? to be installed: %.2f, already installed: %.2f", newVersion, oldVersion); |
||||||
|
return (newVersion > oldVersion); |
||||||
|
} |
||||||
|
|
||||||
|
QString SearchEngine::pluginPath(const QString &name) |
||||||
|
{ |
||||||
|
return QString("%1/%2.py").arg(pluginsLocation()).arg(name); |
||||||
|
} |
||||||
|
|
||||||
|
QHash<QString, QString> SearchEngine::initializeCategoryNames() |
||||||
|
{ |
||||||
|
QHash<QString, QString> result; |
||||||
|
|
||||||
|
result["all"] = QT_TRANSLATE_NOOP("SearchEngine", "All categories"); |
||||||
|
result["movies"] = QT_TRANSLATE_NOOP("SearchEngine", "Movies"); |
||||||
|
result["tv"] = QT_TRANSLATE_NOOP("SearchEngine", "TV shows"); |
||||||
|
result["music"] = QT_TRANSLATE_NOOP("SearchEngine", "Music"); |
||||||
|
result["games"] = QT_TRANSLATE_NOOP("SearchEngine", "Games"); |
||||||
|
result["anime"] = QT_TRANSLATE_NOOP("SearchEngine", "Anime"); |
||||||
|
result["software"] = QT_TRANSLATE_NOOP("SearchEngine", "Software"); |
||||||
|
result["pictures"] = QT_TRANSLATE_NOOP("SearchEngine", "Pictures"); |
||||||
|
result["books"] = QT_TRANSLATE_NOOP("SearchEngine", "Books"); |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
qreal SearchEngine::getPluginVersion(QString filePath) |
||||||
|
{ |
||||||
|
QFile plugin(filePath); |
||||||
|
if (!plugin.exists()) { |
||||||
|
qDebug("%s plugin does not exist, returning 0.0", qPrintable(filePath)); |
||||||
|
return 0.0; |
||||||
|
} |
||||||
|
|
||||||
|
if (!plugin.open(QIODevice::ReadOnly | QIODevice::Text)) |
||||||
|
return 0.0; |
||||||
|
|
||||||
|
qreal version = 0.0; |
||||||
|
while (!plugin.atEnd()) { |
||||||
|
QByteArray line = plugin.readLine(); |
||||||
|
if (line.startsWith("#VERSION: ")) { |
||||||
|
line = line.split(' ').last().trimmed(); |
||||||
|
version = line.toFloat(); |
||||||
|
qDebug("plugin %s version: %.2f", qPrintable(filePath), version); |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return version; |
||||||
|
} |
@ -0,0 +1,137 @@ |
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent. |
||||||
|
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> |
||||||
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or |
||||||
|
* modify it under the terms of the GNU General Public License |
||||||
|
* 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 SEARCHENGINE_H |
||||||
|
#define SEARCHENGINE_H |
||||||
|
|
||||||
|
#include <QObject> |
||||||
|
#include <QHash> |
||||||
|
#include <QStringList> |
||||||
|
#include <QList> |
||||||
|
|
||||||
|
class QProcess; |
||||||
|
class QTimer; |
||||||
|
|
||||||
|
struct PluginInfo |
||||||
|
{ |
||||||
|
QString name; |
||||||
|
qreal version; |
||||||
|
QString fullName; |
||||||
|
QString url; |
||||||
|
QStringList supportedCategories; |
||||||
|
QString iconPath; |
||||||
|
bool enabled; |
||||||
|
}; |
||||||
|
|
||||||
|
struct SearchResult |
||||||
|
{ |
||||||
|
QString fileName; |
||||||
|
QString fileUrl; |
||||||
|
qlonglong fileSize; |
||||||
|
qlonglong nbSeeders; |
||||||
|
qlonglong nbLeechers; |
||||||
|
QString siteUrl; |
||||||
|
QString descrLink; |
||||||
|
}; |
||||||
|
|
||||||
|
class SearchEngine: public QObject |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
|
||||||
|
public: |
||||||
|
SearchEngine(); |
||||||
|
~SearchEngine(); |
||||||
|
|
||||||
|
QStringList allPlugins() const; |
||||||
|
QStringList enabledPlugins() const; |
||||||
|
QStringList supportedCategories() const; |
||||||
|
PluginInfo *pluginInfo(const QString &name) const; |
||||||
|
|
||||||
|
bool isActive() const; |
||||||
|
|
||||||
|
void enablePlugin(const QString &name, bool enabled = true); |
||||||
|
void updatePlugin(const QString &name); |
||||||
|
void installPlugin(const QString &source); |
||||||
|
bool uninstallPlugin(const QString &name); |
||||||
|
void checkForUpdates(); |
||||||
|
|
||||||
|
void startSearch(const QString &pattern, const QString &category, const QStringList &usedPlugins); |
||||||
|
void cancelSearch(); |
||||||
|
|
||||||
|
static qreal getPluginVersion(QString filePath); |
||||||
|
static QString categoryFullName(const QString &categoryName); |
||||||
|
static QString pluginsLocation(); |
||||||
|
|
||||||
|
signals: |
||||||
|
void searchStarted(); |
||||||
|
void searchFinished(bool cancelled); |
||||||
|
void searchFailed(); |
||||||
|
void newSearchResults(const QList<SearchResult> &results); |
||||||
|
|
||||||
|
void pluginInstalled(const QString &name); |
||||||
|
void pluginInstallationFailed(const QString &name, const QString &reason); |
||||||
|
void pluginUpdated(const QString &name); |
||||||
|
void pluginUpdateFailed(const QString &name, const QString &reason); |
||||||
|
|
||||||
|
void checkForUpdatesFinished(const QHash<QString, qreal> &updateInfo); |
||||||
|
void checkForUpdatesFailed(const QString &reason); |
||||||
|
|
||||||
|
private slots: |
||||||
|
void onTimeout(); |
||||||
|
void readSearchOutput(); |
||||||
|
void processFinished(int exitcode); |
||||||
|
void versionInfoDownloaded(const QString &url, const QByteArray &data); |
||||||
|
void versionInfoDownloadFailed(const QString &url, const QString &reason); |
||||||
|
void pluginDownloaded(const QString &url, QString filePath); |
||||||
|
void pluginDownloadFailed(const QString &url, const QString &reason); |
||||||
|
|
||||||
|
private: |
||||||
|
void update(); |
||||||
|
void updateNova(); |
||||||
|
bool parseSearchResult(const QString &line, SearchResult &searchResult); |
||||||
|
void parseVersionInfo(const QByteArray &info); |
||||||
|
void installPlugin_impl(const QString &name, const QString &path); |
||||||
|
bool isUpdateNeeded(QString pluginName, qreal newVersion) const; |
||||||
|
|
||||||
|
static QString engineLocation(); |
||||||
|
static QString pluginPath(const QString &name); |
||||||
|
static QHash<QString, QString> initializeCategoryNames(); |
||||||
|
|
||||||
|
static const QHash<QString, QString> m_categoryNames; |
||||||
|
|
||||||
|
const QString m_updateUrl; |
||||||
|
|
||||||
|
QHash<QString, PluginInfo*> m_plugins; |
||||||
|
QProcess *m_searchProcess; |
||||||
|
bool m_searchStopped; |
||||||
|
QTimer *m_searchTimeout; |
||||||
|
QByteArray m_searchResultLineTruncated; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // SEARCHENGINE_H
|
@ -0,0 +1,438 @@ |
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent. |
||||||
|
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> |
||||||
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or |
||||||
|
* modify it under the terms of the GNU General Public License |
||||||
|
* 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 <QHeaderView> |
||||||
|
#include <QMenu> |
||||||
|
#include <QMessageBox> |
||||||
|
#include <QFileDialog> |
||||||
|
#include <QDropEvent> |
||||||
|
#include <QTemporaryFile> |
||||||
|
#include <QMimeData> |
||||||
|
#include <QClipboard> |
||||||
|
#ifdef QBT_USES_QT5 |
||||||
|
#include <QTableView> |
||||||
|
#endif |
||||||
|
|
||||||
|
#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) |
||||||
|
: QDialog(parent) |
||||||
|
, m_pluginManager(pluginManager) |
||||||
|
, m_asyncOps(0) |
||||||
|
{ |
||||||
|
setupUi(this); |
||||||
|
setAttribute(Qt::WA_DeleteOnClose); |
||||||
|
|
||||||
|
#ifdef QBT_USES_QT5 |
||||||
|
// This hack fixes reordering of first column with Qt5.
|
||||||
|
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
|
||||||
|
QTableView unused; |
||||||
|
unused.setVerticalHeader(pluginsTree->header()); |
||||||
|
pluginsTree->header()->setParent(pluginsTree); |
||||||
|
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); |
||||||
|
#endif |
||||||
|
pluginsTree->setRootIsDecorated(false); |
||||||
|
pluginsTree->header()->resizeSection(0, 160); |
||||||
|
pluginsTree->header()->resizeSection(1, 80); |
||||||
|
pluginsTree->header()->resizeSection(2, 200); |
||||||
|
pluginsTree->hideColumn(PLUGIN_ID); |
||||||
|
|
||||||
|
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(pluginsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(togglePluginState(QTreeWidgetItem*, int))); |
||||||
|
|
||||||
|
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(pluginUpdated(QString)), SLOT(pluginUpdated(QString))); |
||||||
|
connect(m_pluginManager, SIGNAL(pluginUpdateFailed(QString, QString)), SLOT(pluginUpdateFailed(QString, QString))); |
||||||
|
connect(m_pluginManager, SIGNAL(checkForUpdatesFinished(QHash<QString, qreal>)), SLOT(checkForUpdatesFinished(QHash<QString, qreal>))); |
||||||
|
connect(m_pluginManager, SIGNAL(checkForUpdatesFailed(QString)), SLOT(checkForUpdatesFailed(QString))); |
||||||
|
|
||||||
|
show(); |
||||||
|
} |
||||||
|
|
||||||
|
PluginSelectDlg::~PluginSelectDlg() |
||||||
|
{ |
||||||
|
emit pluginsChanged(); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::dropEvent(QDropEvent *event) |
||||||
|
{ |
||||||
|
event->acceptProposedAction(); |
||||||
|
|
||||||
|
QStringList files; |
||||||
|
if (event->mimeData()->hasUrls()) { |
||||||
|
foreach (const QUrl &url, event->mimeData()->urls()) { |
||||||
|
if (!url.isEmpty()) { |
||||||
|
if (url.scheme().compare("file", Qt::CaseInsensitive) == 0) |
||||||
|
files << url.toLocalFile(); |
||||||
|
else |
||||||
|
files << url.toString(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
files = event->mimeData()->text().split(QLatin1String("\n")); |
||||||
|
} |
||||||
|
|
||||||
|
if (files.isEmpty()) return; |
||||||
|
|
||||||
|
foreach (QString file, files) { |
||||||
|
qDebug("dropped %s", qPrintable(file)); |
||||||
|
startAsyncOp(); |
||||||
|
m_pluginManager->installPlugin(file); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Decode if we accept drag 'n drop or not
|
||||||
|
void PluginSelectDlg::dragEnterEvent(QDragEnterEvent *event) |
||||||
|
{ |
||||||
|
QString mime; |
||||||
|
foreach (mime, event->mimeData()->formats()) { |
||||||
|
qDebug("mimeData: %s", qPrintable(mime)); |
||||||
|
} |
||||||
|
|
||||||
|
if (event->mimeData()->hasFormat(QLatin1String("text/plain")) || event->mimeData()->hasFormat(QLatin1String("text/uri-list"))) { |
||||||
|
event->acceptProposedAction(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::on_updateButton_clicked() |
||||||
|
{ |
||||||
|
startAsyncOp(); |
||||||
|
m_pluginManager->checkForUpdates(); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::togglePluginState(QTreeWidgetItem *item, int) |
||||||
|
{ |
||||||
|
PluginInfo *plugin = m_pluginManager->pluginInfo(item->text(PLUGIN_ID)); |
||||||
|
m_pluginManager->enablePlugin(plugin->name, !plugin->enabled); |
||||||
|
if (plugin->enabled) { |
||||||
|
item->setText(PLUGIN_STATE, tr("Yes")); |
||||||
|
setRowColor(pluginsTree->indexOfTopLevelItem(item), "green"); |
||||||
|
} |
||||||
|
else { |
||||||
|
item->setText(PLUGIN_STATE, tr("No")); |
||||||
|
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::displayContextMenu(const QPoint&) |
||||||
|
{ |
||||||
|
QMenu myContextMenu(this); |
||||||
|
// Enable/disable pause/start action given the DL state
|
||||||
|
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); |
||||||
|
if (items.isEmpty()) return; |
||||||
|
|
||||||
|
QString first_id = items.first()->text(PLUGIN_ID); |
||||||
|
actionEnable->setChecked(m_pluginManager->pluginInfo(first_id)->enabled); |
||||||
|
myContextMenu.addAction(actionEnable); |
||||||
|
myContextMenu.addSeparator(); |
||||||
|
myContextMenu.addAction(actionUninstall); |
||||||
|
myContextMenu.exec(QCursor::pos()); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::on_closeButton_clicked() |
||||||
|
{ |
||||||
|
close(); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::on_actionUninstall_triggered() |
||||||
|
{ |
||||||
|
bool error = false; |
||||||
|
foreach (QTreeWidgetItem *item, pluginsTree->selectedItems()) { |
||||||
|
int index = pluginsTree->indexOfTopLevelItem(item); |
||||||
|
Q_ASSERT(index != -1); |
||||||
|
QString id = item->text(PLUGIN_ID); |
||||||
|
if (m_pluginManager->uninstallPlugin(id)) { |
||||||
|
delete item; |
||||||
|
} |
||||||
|
else { |
||||||
|
error = true; |
||||||
|
// Disable it instead
|
||||||
|
m_pluginManager->enablePlugin(id, false); |
||||||
|
item->setText(PLUGIN_STATE, tr("No")); |
||||||
|
setRowColor(index, "red"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
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.")); |
||||||
|
else |
||||||
|
QMessageBox::information(0, tr("Uninstall success"), tr("All selected plugins were uninstalled successfully")); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::enableSelection(bool enable) |
||||||
|
{ |
||||||
|
foreach (QTreeWidgetItem *item, pluginsTree->selectedItems()) { |
||||||
|
int index = pluginsTree->indexOfTopLevelItem(item); |
||||||
|
Q_ASSERT(index != -1); |
||||||
|
QString id = item->text(PLUGIN_ID); |
||||||
|
m_pluginManager->enablePlugin(id, enable); |
||||||
|
if (enable) { |
||||||
|
item->setText(PLUGIN_STATE, tr("Yes")); |
||||||
|
setRowColor(index, "green"); |
||||||
|
} |
||||||
|
else { |
||||||
|
item->setText(PLUGIN_STATE, tr("No")); |
||||||
|
setRowColor(index, "red"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Set the color of a row in data model
|
||||||
|
void PluginSelectDlg::setRowColor(int row, QString color) |
||||||
|
{ |
||||||
|
QTreeWidgetItem *item = pluginsTree->topLevelItem(row); |
||||||
|
for (int i = 0; i < pluginsTree->columnCount(); ++i) { |
||||||
|
item->setData(i, Qt::ForegroundRole, QVariant(QColor(color))); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
QList<QTreeWidgetItem*> PluginSelectDlg::findItemsWithUrl(QString url) |
||||||
|
{ |
||||||
|
QList<QTreeWidgetItem*> res; |
||||||
|
|
||||||
|
for (int i = 0; i < pluginsTree->topLevelItemCount(); ++i) { |
||||||
|
QTreeWidgetItem *item = pluginsTree->topLevelItem(i); |
||||||
|
if (url.startsWith(item->text(PLUGIN_URL), Qt::CaseInsensitive)) |
||||||
|
res << item; |
||||||
|
} |
||||||
|
|
||||||
|
return res; |
||||||
|
} |
||||||
|
|
||||||
|
QTreeWidgetItem* PluginSelectDlg::findItemWithID(QString id) |
||||||
|
{ |
||||||
|
for (int i = 0; i < pluginsTree->topLevelItemCount(); ++i) { |
||||||
|
QTreeWidgetItem *item = pluginsTree->topLevelItem(i); |
||||||
|
if (id == item->text(PLUGIN_ID)) |
||||||
|
return item; |
||||||
|
} |
||||||
|
|
||||||
|
return 0; |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::loadSupportedSearchPlugins() |
||||||
|
{ |
||||||
|
// Some clean up first
|
||||||
|
pluginsTree->clear(); |
||||||
|
foreach (QString name, m_pluginManager->allPlugins()) |
||||||
|
addNewPlugin(name); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::addNewPlugin(QString pluginName) |
||||||
|
{ |
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem(pluginsTree); |
||||||
|
PluginInfo *plugin = m_pluginManager->pluginInfo(pluginName); |
||||||
|
item->setText(PLUGIN_NAME, plugin->fullName); |
||||||
|
item->setText(PLUGIN_URL, plugin->url); |
||||||
|
item->setText(PLUGIN_ID, plugin->name); |
||||||
|
if (plugin->enabled) { |
||||||
|
item->setText(PLUGIN_STATE, tr("Yes")); |
||||||
|
setRowColor(pluginsTree->indexOfTopLevelItem(item), "green"); |
||||||
|
} |
||||||
|
else { |
||||||
|
item->setText(PLUGIN_STATE, tr("No")); |
||||||
|
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red"); |
||||||
|
} |
||||||
|
// Handle icon
|
||||||
|
if (QFile::exists(plugin->iconPath)) { |
||||||
|
// Good, we already have the icon
|
||||||
|
item->setData(PLUGIN_NAME, Qt::DecorationRole, QVariant(QIcon(plugin->iconPath))); |
||||||
|
} |
||||||
|
else { |
||||||
|
// Icon is missing, we must download it
|
||||||
|
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(plugin->url + "/favicon.ico", true); |
||||||
|
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() |
||||||
|
{ |
||||||
|
++m_asyncOps; |
||||||
|
if (m_asyncOps == 1) |
||||||
|
setCursor(QCursor(Qt::WaitCursor)); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::finishAsyncOp() |
||||||
|
{ |
||||||
|
--m_asyncOps; |
||||||
|
if (m_asyncOps == 0) |
||||||
|
setCursor(QCursor(Qt::ArrowCursor)); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::on_installButton_clicked() |
||||||
|
{ |
||||||
|
PluginSourceDlg *dlg = new PluginSourceDlg(this); |
||||||
|
connect(dlg, SIGNAL(askForLocalFile()), this, SLOT(askForLocalPlugin())); |
||||||
|
connect(dlg, SIGNAL(askForUrl()), this, SLOT(askForPluginUrl())); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::askForPluginUrl() |
||||||
|
{ |
||||||
|
bool ok = false; |
||||||
|
QString clipTxt = qApp->clipboard()->text(); |
||||||
|
QString defaultUrl = "http://"; |
||||||
|
if (Utils::Misc::isUrl(clipTxt) && clipTxt.endsWith(".py")) |
||||||
|
defaultUrl = clipTxt; |
||||||
|
QString url = AutoExpandableDialog::getText( |
||||||
|
this, tr("New search engine plugin URL"), |
||||||
|
tr("URL:"), QLineEdit::Normal, defaultUrl, &ok |
||||||
|
); |
||||||
|
|
||||||
|
while (ok && !url.isEmpty() && !url.endsWith(".py")) { |
||||||
|
QMessageBox::warning(this, tr("Invalid link"), tr("The link doesn't seem to point to a search engine plugin.")); |
||||||
|
url = AutoExpandableDialog::getText( |
||||||
|
this, tr("New search engine plugin URL"), |
||||||
|
tr("URL:"), QLineEdit::Normal, url, &ok |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
if (ok && !url.isEmpty()) { |
||||||
|
startAsyncOp(); |
||||||
|
m_pluginManager->installPlugin(url); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::askForLocalPlugin() |
||||||
|
{ |
||||||
|
QStringList pathsList = QFileDialog::getOpenFileNames( |
||||||
|
0, tr("Select search plugins"), QDir::homePath(), |
||||||
|
tr("qBittorrent search plugin") + QLatin1String(" (*.py)") |
||||||
|
); |
||||||
|
foreach (QString path, pathsList) { |
||||||
|
startAsyncOp(); |
||||||
|
m_pluginManager->installPlugin(path); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::iconDownloaded(const QString &url, QString filePath) |
||||||
|
{ |
||||||
|
filePath = Utils::Fs::fromNativePath(filePath); |
||||||
|
|
||||||
|
// Icon downloaded
|
||||||
|
QImage fileIcon; |
||||||
|
if (fileIcon.load(filePath)) { |
||||||
|
foreach (QTreeWidgetItem *item, findItemsWithUrl(url)) { |
||||||
|
QString id = item->text(PLUGIN_ID); |
||||||
|
PluginInfo *plugin = m_pluginManager->pluginInfo(id); |
||||||
|
if (!plugin) continue; |
||||||
|
|
||||||
|
QFile icon(filePath); |
||||||
|
icon.open(QIODevice::ReadOnly); |
||||||
|
QString iconPath = QString("%1/%2.%3").arg(SearchEngine::pluginsLocation()).arg(id).arg(ICOHandler::canRead(&icon) ? "ico" : "png"); |
||||||
|
if (QFile::copy(filePath, iconPath)) |
||||||
|
item->setData(PLUGIN_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); |
||||||
|
} |
||||||
|
} |
||||||
|
// Delete tmp file
|
||||||
|
Utils::Fs::forceRemove(filePath); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::iconDownloadFailed(const QString &url, const QString &reason) |
||||||
|
{ |
||||||
|
qDebug("Could not download favicon: %s, reason: %s", qPrintable(url), qPrintable(reason)); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::checkForUpdatesFinished(const QHash<QString, qreal> &updateInfo) |
||||||
|
{ |
||||||
|
finishAsyncOp(); |
||||||
|
if (updateInfo.isEmpty()) { |
||||||
|
QMessageBox::information(this, tr("Search plugin update"), tr("All your plugins are already up to date.")); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
foreach (const QString &pluginName, updateInfo.keys()) { |
||||||
|
startAsyncOp(); |
||||||
|
m_pluginManager->updatePlugin(pluginName); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::checkForUpdatesFailed(const QString &reason) |
||||||
|
{ |
||||||
|
finishAsyncOp(); |
||||||
|
QMessageBox::warning(this, tr("Search plugin update"), tr("Sorry, couldn't check for plugin updates. %1").arg(reason)); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::pluginInstalled(const QString &name) |
||||||
|
{ |
||||||
|
addNewPlugin(name); |
||||||
|
finishAsyncOp(); |
||||||
|
QMessageBox::information(this, tr("Search plugin install"), tr("\"%1\" search engine plugin was successfully installed.", "%1 is the name of the search engine").arg(name)); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::pluginInstallationFailed(const QString &name, const QString &reason) |
||||||
|
{ |
||||||
|
finishAsyncOp(); |
||||||
|
QMessageBox::information(this, tr("Search plugin install"), tr("Couldn't install \"%1\" search engine plugin. %2").arg(name).arg(reason)); |
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::pluginUpdated(const QString &name) |
||||||
|
{ |
||||||
|
finishAsyncOp(); |
||||||
|
qreal version = m_pluginManager->pluginInfo(name)->version; |
||||||
|
QTreeWidgetItem *item = findItemWithID(name); |
||||||
|
item->setText(PLUGIN_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(name)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
void PluginSelectDlg::pluginUpdateFailed(const QString &name, const QString &reason) |
||||||
|
{ |
||||||
|
finishAsyncOp(); |
||||||
|
QMessageBox::information(this, tr("Search plugin update"), tr("Couldn't update \"%1\" search engine plugin. %2").arg(name).arg(reason)); |
||||||
|
} |
@ -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(); |
||||||
|
} |
@ -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> |
@ -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; |
||||||
|
} |
@ -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); |
||||||
|
} |
@ -0,0 +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 |
||||||
|
#define SEARCHSORTMODEL_H |
||||||
|
|
||||||
|
#include <QSortFilterProxyModel> |
||||||
|
#include "base/utils/string.h" |
||||||
|
|
||||||
|
class SearchSortModel: public QSortFilterProxyModel |
||||||
|
{ |
||||||
|
public: |
||||||
|
enum SearchColumn |
||||||
|
{ |
||||||
|
NAME, |
||||||
|
SIZE, |
||||||
|
SEEDS, |
||||||
|
LEECHS, |
||||||
|
ENGINE_URL, |
||||||
|
DL_LINK, |
||||||
|
DESC_LINK, |
||||||
|
NB_SEARCH_COLUMNS |
||||||
|
}; |
||||||
|
|
||||||
|
explicit SearchSortModel(QObject *parent = 0); |
||||||
|
|
||||||
|
protected: |
||||||
|
virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // SEARCHSORTMODEL_H
|
@ -0,0 +1,172 @@ |
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt4 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 <QDir> |
||||||
|
#include <QTreeView> |
||||||
|
#include <QStandardItemModel> |
||||||
|
#include <QHeaderView> |
||||||
|
#include <QSortFilterProxyModel> |
||||||
|
#include <QLabel> |
||||||
|
#include <QVBoxLayout> |
||||||
|
#ifdef QBT_USES_QT5 |
||||||
|
#include <QTableView> |
||||||
|
#endif |
||||||
|
|
||||||
|
#include "base/utils/misc.h" |
||||||
|
#include "base/preferences.h" |
||||||
|
#include "searchsortmodel.h" |
||||||
|
#include "searchlistdelegate.h" |
||||||
|
#include "searchwidget.h" |
||||||
|
#include "searchtab.h" |
||||||
|
|
||||||
|
SearchTab::SearchTab(SearchWidget *parent) |
||||||
|
: QWidget(parent) |
||||||
|
, m_parent(parent) |
||||||
|
{ |
||||||
|
m_box = new QVBoxLayout(this); |
||||||
|
m_resultsLbl = new QLabel(this); |
||||||
|
m_resultsBrowser = new QTreeView(this); |
||||||
|
#ifdef QBT_USES_QT5 |
||||||
|
// This hack fixes reordering of first column with Qt5.
|
||||||
|
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
|
||||||
|
QTableView unused; |
||||||
|
unused.setVerticalHeader(m_resultsBrowser->header()); |
||||||
|
m_resultsBrowser->header()->setParent(m_resultsBrowser); |
||||||
|
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); |
||||||
|
#endif |
||||||
|
m_resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection); |
||||||
|
m_box->addWidget(m_resultsLbl); |
||||||
|
m_box->addWidget(m_resultsBrowser); |
||||||
|
|
||||||
|
setLayout(m_box); |
||||||
|
|
||||||
|
// Set Search results list model
|
||||||
|
m_searchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS, this); |
||||||
|
m_searchListModel->setHeaderData(SearchSortModel::NAME, Qt::Horizontal, tr("Name", "i.e: file name")); |
||||||
|
m_searchListModel->setHeaderData(SearchSortModel::SIZE, Qt::Horizontal, tr("Size", "i.e: file size")); |
||||||
|
m_searchListModel->setHeaderData(SearchSortModel::SEEDS, Qt::Horizontal, tr("Seeders", "i.e: Number of full sources")); |
||||||
|
m_searchListModel->setHeaderData(SearchSortModel::LEECHS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources")); |
||||||
|
m_searchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine")); |
||||||
|
|
||||||
|
m_proxyModel = new SearchSortModel(this); |
||||||
|
m_proxyModel->setDynamicSortFilter(true); |
||||||
|
m_proxyModel->setSourceModel(m_searchListModel); |
||||||
|
m_resultsBrowser->setModel(m_proxyModel); |
||||||
|
|
||||||
|
m_searchDelegate = new SearchListDelegate(this); |
||||||
|
m_resultsBrowser->setItemDelegate(m_searchDelegate); |
||||||
|
|
||||||
|
m_resultsBrowser->hideColumn(SearchSortModel::DL_LINK); // Hide url column
|
||||||
|
m_resultsBrowser->hideColumn(SearchSortModel::DESC_LINK); |
||||||
|
|
||||||
|
m_resultsBrowser->setRootIsDecorated(false); |
||||||
|
m_resultsBrowser->setAllColumnsShowFocus(true); |
||||||
|
m_resultsBrowser->setSortingEnabled(true); |
||||||
|
|
||||||
|
// Connect signals to slots (search part)
|
||||||
|
connect(m_resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&))); |
||||||
|
|
||||||
|
// Load last columns width for search results list
|
||||||
|
if (!loadColWidthResultsList()) |
||||||
|
m_resultsBrowser->header()->resizeSection(0, 275); |
||||||
|
|
||||||
|
// Sort by Seeds
|
||||||
|
m_resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchTab::downloadSelectedItem(const QModelIndex &index) |
||||||
|
{ |
||||||
|
QString torrentUrl = m_proxyModel->data(m_proxyModel->index(index.row(), SearchSortModel::DL_LINK)).toString(); |
||||||
|
setRowColor(index.row(), "blue"); |
||||||
|
m_parent->downloadTorrent(torrentUrl); |
||||||
|
} |
||||||
|
|
||||||
|
QHeaderView* SearchTab::header() const |
||||||
|
{ |
||||||
|
return m_resultsBrowser->header(); |
||||||
|
} |
||||||
|
|
||||||
|
bool SearchTab::loadColWidthResultsList() |
||||||
|
{ |
||||||
|
QString line = Preferences::instance()->getSearchColsWidth(); |
||||||
|
if (line.isEmpty()) return false; |
||||||
|
|
||||||
|
QStringList widthList = line.split(' '); |
||||||
|
if (widthList.size() > m_searchListModel->columnCount()) |
||||||
|
return false; |
||||||
|
|
||||||
|
unsigned int listSize = widthList.size(); |
||||||
|
for (unsigned int i = 0; i < listSize; ++i) { |
||||||
|
m_resultsBrowser->header()->resizeSection(i, widthList.at(i).toInt()); |
||||||
|
} |
||||||
|
|
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
QLabel* SearchTab::getCurrentLabel() const |
||||||
|
{ |
||||||
|
return m_resultsLbl; |
||||||
|
} |
||||||
|
|
||||||
|
QTreeView* SearchTab::getCurrentTreeView() const |
||||||
|
{ |
||||||
|
return m_resultsBrowser; |
||||||
|
} |
||||||
|
|
||||||
|
QSortFilterProxyModel* SearchTab::getCurrentSearchListProxy() const |
||||||
|
{ |
||||||
|
return m_proxyModel; |
||||||
|
} |
||||||
|
|
||||||
|
QStandardItemModel* SearchTab::getCurrentSearchListModel() const |
||||||
|
{ |
||||||
|
return m_searchListModel; |
||||||
|
} |
||||||
|
|
||||||
|
// Set the color of a row in data model
|
||||||
|
void SearchTab::setRowColor(int row, QString color) |
||||||
|
{ |
||||||
|
m_proxyModel->setDynamicSortFilter(false); |
||||||
|
for (int i = 0; i < m_proxyModel->columnCount(); ++i) { |
||||||
|
m_proxyModel->setData(m_proxyModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); |
||||||
|
} |
||||||
|
|
||||||
|
m_proxyModel->setDynamicSortFilter(true); |
||||||
|
} |
||||||
|
|
||||||
|
QString SearchTab::status() const |
||||||
|
{ |
||||||
|
return m_status; |
||||||
|
} |
||||||
|
|
||||||
|
void SearchTab::setStatus(const QString &value) |
||||||
|
{ |
||||||
|
m_status = value; |
||||||
|
} |
@ -0,0 +1,413 @@ |
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent. |
||||||
|
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> |
||||||
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or |
||||||
|
* modify it under the terms of the GNU General Public License |
||||||
|
* 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 <QHeaderView> |
||||||
|
#include <QMessageBox> |
||||||
|
#include <QTemporaryFile> |
||||||
|
#include <QSystemTrayIcon> |
||||||
|
#include <QTimer> |
||||||
|
#include <QDir> |
||||||
|
#include <QMenu> |
||||||
|
#include <QClipboard> |
||||||
|
#include <QMimeData> |
||||||
|
#include <QStandardItemModel> |
||||||
|
#include <QSortFilterProxyModel> |
||||||
|
#include <QFileDialog> |
||||||
|
#include <QDesktopServices> |
||||||
|
#include <QClipboard> |
||||||
|
#include <QProcess> |
||||||
|
#include <QDebug> |
||||||
|
|
||||||
|
#include <iostream> |
||||||
|
#ifdef Q_OS_WIN |
||||||
|
#include <stdlib.h> |
||||||
|
#endif |
||||||
|
|
||||||
|
#include "base/bittorrent/session.h" |
||||||
|
#include "base/utils/fs.h" |
||||||
|
#include "base/utils/misc.h" |
||||||
|
#include "base/preferences.h" |
||||||
|
#include "base/searchengine.h" |
||||||
|
#include "searchlistdelegate.h" |
||||||
|
#include "mainwindow.h" |
||||||
|
#include "addnewtorrentdialog.h" |
||||||
|
#include "guiiconprovider.h" |
||||||
|
#include "lineedit.h" |
||||||
|
#include "pluginselectdlg.h" |
||||||
|
#include "searchsortmodel.h" |
||||||
|
#include "searchtab.h" |
||||||
|
#include "searchwidget.h" |
||||||
|
|
||||||
|
#define SEARCHHISTORY_MAXSIZE 50 |
||||||
|
#define URL_COLUMN 5 |
||||||
|
|
||||||
|
SearchWidget::SearchWidget(MainWindow *mainWindow) |
||||||
|
: QWidget(mainWindow) |
||||||
|
, m_mainWindow(mainWindow) |
||||||
|
{ |
||||||
|
setupUi(this); |
||||||
|
|
||||||
|
m_searchPattern = new LineEdit(this); |
||||||
|
searchBarLayout->insertWidget(0, m_searchPattern); |
||||||
|
connect(m_searchPattern, SIGNAL(returnPressed()), searchButton, SLOT(click())); |
||||||
|
|
||||||
|
// Icons
|
||||||
|
searchButton->setIcon(GuiIconProvider::instance()->getIcon("edit-find")); |
||||||
|
downloadButton->setIcon(GuiIconProvider::instance()->getIcon("download")); |
||||||
|
goToDescBtn->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl")); |
||||||
|
pluginsButton->setIcon(GuiIconProvider::instance()->getIcon("preferences-system-network")); |
||||||
|
copyURLBtn->setIcon(GuiIconProvider::instance()->getIcon("edit-copy")); |
||||||
|
tabWidget->setTabsClosable(true); |
||||||
|
connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); |
||||||
|
|
||||||
|
m_searchEngine = new SearchEngine; |
||||||
|
connect(m_searchEngine, SIGNAL(searchStarted()), SLOT(searchStarted())); |
||||||
|
connect(m_searchEngine, SIGNAL(newSearchResults(QList<SearchResult>)), SLOT(appendSearchResults(QList<SearchResult>))); |
||||||
|
connect(m_searchEngine, SIGNAL(searchFinished(bool)), SLOT(searchFinished(bool))); |
||||||
|
connect(m_searchEngine, SIGNAL(searchFailed()), SLOT(searchFailed())); |
||||||
|
|
||||||
|
// Fill in category combobox
|
||||||
|
fillCatCombobox(); |
||||||
|
fillPluginComboBox(); |
||||||
|
|
||||||
|
connect(m_searchPattern, SIGNAL(textEdited(QString)), this, SLOT(searchTextEdited(QString))); |
||||||
|
connect(selectPlugin, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(selectMultipleBox(const QString &))); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::fillCatCombobox() |
||||||
|
{ |
||||||
|
comboCategory->clear(); |
||||||
|
comboCategory->addItem(SearchEngine::categoryFullName("all"), QVariant("all")); |
||||||
|
foreach (QString cat, m_searchEngine->supportedCategories()) { |
||||||
|
qDebug("Supported category: %s", qPrintable(cat)); |
||||||
|
comboCategory->addItem(SearchEngine::categoryFullName(cat), QVariant(cat)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::fillPluginComboBox() |
||||||
|
{ |
||||||
|
selectPlugin->clear(); |
||||||
|
selectPlugin->addItem(tr("All enabled"), QVariant("enabled")); |
||||||
|
selectPlugin->addItem(tr("All plugins"), QVariant("all")); |
||||||
|
foreach (QString name, m_searchEngine->enabledPlugins()) |
||||||
|
selectPlugin->addItem(name, QVariant(name)); |
||||||
|
selectPlugin->addItem(tr("Multiple..."), QVariant("multi")); |
||||||
|
} |
||||||
|
|
||||||
|
QString SearchWidget::selectedCategory() const |
||||||
|
{ |
||||||
|
return comboCategory->itemData(comboCategory->currentIndex()).toString(); |
||||||
|
} |
||||||
|
|
||||||
|
QString SearchWidget::selectedPlugin() const |
||||||
|
{ |
||||||
|
return selectPlugin->itemData(selectPlugin->currentIndex()).toString(); |
||||||
|
} |
||||||
|
|
||||||
|
SearchWidget::~SearchWidget() |
||||||
|
{ |
||||||
|
qDebug("Search destruction"); |
||||||
|
delete m_searchEngine; |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::tab_changed(int t) |
||||||
|
{ |
||||||
|
//when we switch from a tab that is not empty to another that is empty the download button
|
||||||
|
//doesn't have to be available
|
||||||
|
if (t > -1) { |
||||||
|
//-1 = no more tab
|
||||||
|
m_currentSearchTab = m_allTabs.at(tabWidget->currentIndex()); |
||||||
|
if (m_currentSearchTab->getCurrentSearchListModel()->rowCount()) { |
||||||
|
downloadButton->setEnabled(true); |
||||||
|
goToDescBtn->setEnabled(true); |
||||||
|
copyURLBtn->setEnabled(true); |
||||||
|
} |
||||||
|
else { |
||||||
|
downloadButton->setEnabled(false); |
||||||
|
goToDescBtn->setEnabled(false); |
||||||
|
copyURLBtn->setEnabled(false); |
||||||
|
} |
||||||
|
searchStatus->setText(m_currentSearchTab->status()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::selectMultipleBox(const QString &text) |
||||||
|
{ |
||||||
|
if (text == tr("Multiple...")) |
||||||
|
on_pluginsButton_clicked(); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::on_pluginsButton_clicked() |
||||||
|
{ |
||||||
|
PluginSelectDlg *dlg = new PluginSelectDlg(m_searchEngine, this); |
||||||
|
connect(dlg, SIGNAL(pluginsChanged()), this, SLOT(fillCatCombobox())); |
||||||
|
connect(dlg, SIGNAL(pluginsChanged()), this, SLOT(fillPluginComboBox())); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::searchTextEdited(QString) |
||||||
|
{ |
||||||
|
// Enable search button
|
||||||
|
searchButton->setText(tr("Search")); |
||||||
|
m_isNewQueryString = true; |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::giveFocusToSearchInput() |
||||||
|
{ |
||||||
|
m_searchPattern->setFocus(); |
||||||
|
} |
||||||
|
|
||||||
|
// Function called when we click on search button
|
||||||
|
void SearchWidget::on_searchButton_clicked() |
||||||
|
{ |
||||||
|
if (Utils::Misc::pythonVersion() < 0) { |
||||||
|
m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Please install Python to use the Search Engine.")); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if (m_searchEngine->isActive()) { |
||||||
|
m_searchEngine->cancelSearch(); |
||||||
|
|
||||||
|
if (!m_isNewQueryString) { |
||||||
|
searchButton->setText(tr("Search")); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
m_isNewQueryString = false; |
||||||
|
|
||||||
|
const QString pattern = m_searchPattern->text().trimmed(); |
||||||
|
// No search pattern entered
|
||||||
|
if (pattern.isEmpty()) { |
||||||
|
QMessageBox::critical(0, tr("Empty search pattern"), tr("Please type a search pattern first")); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
// Tab Addition
|
||||||
|
m_currentSearchTab = new SearchTab(this); |
||||||
|
m_activeSearchTab = m_currentSearchTab; |
||||||
|
connect(m_currentSearchTab->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveResultsColumnsWidth())); |
||||||
|
m_allTabs.append(m_currentSearchTab); |
||||||
|
QString tabName = pattern; |
||||||
|
tabName.replace(QRegExp("&{1}"), "&&"); |
||||||
|
tabWidget->addTab(m_currentSearchTab, tabName); |
||||||
|
tabWidget->setCurrentWidget(m_currentSearchTab); |
||||||
|
|
||||||
|
QStringList plugins; |
||||||
|
if (selectedPlugin() == "all") plugins = m_searchEngine->allPlugins(); |
||||||
|
else if (selectedPlugin() == "enabled") plugins = m_searchEngine->enabledPlugins(); |
||||||
|
else if (selectedPlugin() == "multi") plugins = m_searchEngine->enabledPlugins(); |
||||||
|
else plugins << selectedPlugin(); |
||||||
|
|
||||||
|
qDebug("Search with category: %s", qPrintable(selectedCategory())); |
||||||
|
|
||||||
|
// Update SearchEngine widgets
|
||||||
|
m_noSearchResults = true; |
||||||
|
m_nbSearchResults = 0; |
||||||
|
|
||||||
|
// Changing the text of the current label
|
||||||
|
m_activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(0)); |
||||||
|
|
||||||
|
// Launch search
|
||||||
|
m_searchEngine->startSearch(pattern, selectedCategory(), plugins); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::saveResultsColumnsWidth() |
||||||
|
{ |
||||||
|
if (m_allTabs.isEmpty()) return; |
||||||
|
|
||||||
|
QTreeView *treeview = m_allTabs.first()->getCurrentTreeView(); |
||||||
|
QStringList newWidthList; |
||||||
|
short nbColumns = m_allTabs.first()->getCurrentSearchListModel()->columnCount(); |
||||||
|
for (short i = 0; i < nbColumns; ++i) |
||||||
|
if (treeview->columnWidth(i) > 0) |
||||||
|
newWidthList << QString::number(treeview->columnWidth(i)); |
||||||
|
// Don't save the width of the last column (auto column width)
|
||||||
|
newWidthList.removeLast(); |
||||||
|
Preferences::instance()->setSearchColsWidth(newWidthList.join(" ")); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::downloadTorrent(QString url) |
||||||
|
{ |
||||||
|
if (Preferences::instance()->useAdditionDialog()) |
||||||
|
AddNewTorrentDialog::show(url, this); |
||||||
|
else |
||||||
|
BitTorrent::Session::instance()->addTorrent(url); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::searchStarted() |
||||||
|
{ |
||||||
|
// Update SearchEngine widgets
|
||||||
|
m_activeSearchTab->setStatus(tr("Searching...")); |
||||||
|
searchStatus->setText(m_currentSearchTab->status()); |
||||||
|
searchStatus->repaint(); |
||||||
|
searchButton->setText(tr("Stop")); |
||||||
|
} |
||||||
|
|
||||||
|
// Slot called when search is Finished
|
||||||
|
// Search can be finished for 3 reasons :
|
||||||
|
// Error | Stopped by user | Finished normally
|
||||||
|
void SearchWidget::searchFinished(bool cancelled) |
||||||
|
{ |
||||||
|
if (Preferences::instance()->useProgramNotification() && (m_mainWindow->getCurrentTabWidget() != this)) |
||||||
|
m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished")); |
||||||
|
|
||||||
|
if (m_activeSearchTab.isNull()) return; // The active tab was closed
|
||||||
|
|
||||||
|
if (cancelled) |
||||||
|
m_activeSearchTab->setStatus(tr("Search aborted")); |
||||||
|
else if (m_noSearchResults) |
||||||
|
m_activeSearchTab->setStatus(tr("Search returned no results")); |
||||||
|
else |
||||||
|
m_activeSearchTab->setStatus(tr("Search has finished")); |
||||||
|
|
||||||
|
searchStatus->setText(m_currentSearchTab->status()); |
||||||
|
m_activeSearchTab = 0; |
||||||
|
searchButton->setText(tr("Search")); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::searchFailed() |
||||||
|
{ |
||||||
|
if (Preferences::instance()->useProgramNotification() && (m_mainWindow->getCurrentTabWidget() != this)) |
||||||
|
m_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has failed")); |
||||||
|
|
||||||
|
if (m_activeSearchTab.isNull()) return; // The active tab was closed
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN |
||||||
|
m_activeSearchTab->setStatus(tr("Search aborted")); |
||||||
|
#else |
||||||
|
m_activeSearchTab->setStatus(tr("An error occurred during search...")); |
||||||
|
#endif |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::appendSearchResults(const QList<SearchResult> &results) |
||||||
|
{ |
||||||
|
if (m_activeSearchTab.isNull()) { |
||||||
|
m_searchEngine->cancelSearch(); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
Q_ASSERT(m_activeSearchTab); |
||||||
|
|
||||||
|
QStandardItemModel *curModel = m_activeSearchTab->getCurrentSearchListModel(); |
||||||
|
Q_ASSERT(curModel); |
||||||
|
|
||||||
|
foreach (const SearchResult &result, results) { |
||||||
|
// Add item to search result list
|
||||||
|
int row = curModel->rowCount(); |
||||||
|
curModel->insertRow(row); |
||||||
|
|
||||||
|
curModel->setData(curModel->index(row, SearchSortModel::DL_LINK), result.fileUrl); // download URL
|
||||||
|
curModel->setData(curModel->index(row, SearchSortModel::NAME), result.fileName); // Name
|
||||||
|
curModel->setData(curModel->index(row, SearchSortModel::SIZE), result.fileSize); // Size
|
||||||
|
curModel->setData(curModel->index(row, SearchSortModel::SEEDS), result.nbSeeders); // Seeders
|
||||||
|
curModel->setData(curModel->index(row, SearchSortModel::LEECHS), result.nbLeechers); // Leechers
|
||||||
|
curModel->setData(curModel->index(row, SearchSortModel::ENGINE_URL), result.siteUrl); // Search site URL
|
||||||
|
curModel->setData(curModel->index(row, SearchSortModel::DESC_LINK), result.descrLink); // Description Link
|
||||||
|
} |
||||||
|
|
||||||
|
m_noSearchResults = false; |
||||||
|
m_nbSearchResults += results.size(); |
||||||
|
m_activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(m_nbSearchResults)); |
||||||
|
|
||||||
|
// Enable clear & download buttons
|
||||||
|
downloadButton->setEnabled(true); |
||||||
|
goToDescBtn->setEnabled(true); |
||||||
|
copyURLBtn->setEnabled(true); |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::closeTab(int index) |
||||||
|
{ |
||||||
|
// Search is run for active tab so if user decided to close it, then stop search
|
||||||
|
if (!m_activeSearchTab.isNull() && index == tabWidget->indexOf(m_activeSearchTab)) { |
||||||
|
qDebug("Closed active search Tab"); |
||||||
|
if (m_searchEngine->isActive()) |
||||||
|
m_searchEngine->cancelSearch(); |
||||||
|
m_activeSearchTab = 0; |
||||||
|
} |
||||||
|
|
||||||
|
delete m_allTabs.takeAt(index); |
||||||
|
|
||||||
|
if (!m_allTabs.size()) { |
||||||
|
downloadButton->setEnabled(false); |
||||||
|
goToDescBtn->setEnabled(false); |
||||||
|
searchStatus->setText(tr("Stopped")); |
||||||
|
copyURLBtn->setEnabled(false); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Download selected items in search results list
|
||||||
|
void SearchWidget::on_downloadButton_clicked() |
||||||
|
{ |
||||||
|
//QModelIndexList selectedIndexes = currentSearchTab->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
||||||
|
QModelIndexList selectedIndexes = m_allTabs.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); |
||||||
|
foreach (const QModelIndex &index, selectedIndexes) { |
||||||
|
if (index.column() == SearchSortModel::NAME) { |
||||||
|
// Get Item url
|
||||||
|
QSortFilterProxyModel *model = m_allTabs.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); |
||||||
|
QString torrentUrl = model->data(model->index(index.row(), URL_COLUMN)).toString(); |
||||||
|
downloadTorrent(torrentUrl); |
||||||
|
m_allTabs.at(tabWidget->currentIndex())->setRowColor(index.row(), "blue"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::on_goToDescBtn_clicked() |
||||||
|
{ |
||||||
|
QModelIndexList selectedIndexes = m_allTabs.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); |
||||||
|
foreach (const QModelIndex &index, selectedIndexes) { |
||||||
|
if (index.column() == SearchSortModel::NAME) { |
||||||
|
QSortFilterProxyModel *model = m_allTabs.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); |
||||||
|
const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString(); |
||||||
|
if (!descUrl.isEmpty()) |
||||||
|
QDesktopServices::openUrl(QUrl::fromEncoded(descUrl.toUtf8())); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void SearchWidget::on_copyURLBtn_clicked() |
||||||
|
{ |
||||||
|
QStringList urls; |
||||||
|
QModelIndexList selectedIndexes = m_allTabs.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); |
||||||
|
|
||||||
|
foreach (const QModelIndex &index, selectedIndexes) { |
||||||
|
if (index.column() == SearchSortModel::NAME) { |
||||||
|
QSortFilterProxyModel *model = m_allTabs.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); |
||||||
|
const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString(); |
||||||
|
if (!descUrl.isEmpty()) |
||||||
|
urls << descUrl.toUtf8(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (!urls.empty()) { |
||||||
|
QClipboard *clipboard = QApplication::clipboard(); |
||||||
|
clipboard->setText(urls.join("\n")); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,95 @@ |
|||||||
|
/*
|
||||||
|
* Bittorrent Client using Qt and libtorrent. |
||||||
|
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> |
||||||
|
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org> |
||||||
|
* |
||||||
|
* This program is free software; you can redistribute it and/or |
||||||
|
* modify it under the terms of the GNU General Public License |
||||||
|
* 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 |
||||||
|
*/ |
||||||
|
|
||||||
|
#ifndef SEARCHWIDGET_H |
||||||
|
#define SEARCHWIDGET_H |
||||||
|
|
||||||
|
#include <QList> |
||||||
|
#include <QPointer> |
||||||
|
|
||||||
|
#include "ui_searchwidget.h" |
||||||
|
|
||||||
|
class MainWindow; |
||||||
|
class LineEdit; |
||||||
|
class SearchEngine; |
||||||
|
struct SearchResult; |
||||||
|
class SearchTab; |
||||||
|
|
||||||
|
class SearchWidget: public QWidget, private Ui::SearchWidget |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
Q_DISABLE_COPY(SearchWidget) |
||||||
|
|
||||||
|
public: |
||||||
|
explicit SearchWidget(MainWindow *mainWindow); |
||||||
|
~SearchWidget(); |
||||||
|
|
||||||
|
void downloadTorrent(QString url); |
||||||
|
void giveFocusToSearchInput(); |
||||||
|
|
||||||
|
private slots: |
||||||
|
// Search slots
|
||||||
|
void tab_changed(int); //to prevent the use of the download button when the tab is empty
|
||||||
|
void on_searchButton_clicked(); |
||||||
|
void on_downloadButton_clicked(); |
||||||
|
void on_goToDescBtn_clicked(); |
||||||
|
void on_copyURLBtn_clicked(); |
||||||
|
void on_pluginsButton_clicked(); |
||||||
|
|
||||||
|
void closeTab(int index); |
||||||
|
void appendSearchResults(const QList<SearchResult> &results); |
||||||
|
void searchStarted(); |
||||||
|
void searchFinished(bool cancelled); |
||||||
|
void searchFailed(); |
||||||
|
void selectMultipleBox(const QString &text); |
||||||
|
|
||||||
|
void saveResultsColumnsWidth(); |
||||||
|
void fillCatCombobox(); |
||||||
|
void fillPluginComboBox(); |
||||||
|
void searchTextEdited(QString); |
||||||
|
|
||||||
|
private: |
||||||
|
QString selectedCategory() const; |
||||||
|
QString selectedPlugin() const; |
||||||
|
|
||||||
|
LineEdit *m_searchPattern; |
||||||
|
SearchEngine *m_searchEngine; |
||||||
|
QPointer<SearchTab> m_currentSearchTab; // Selected tab
|
||||||
|
QPointer<SearchTab> m_activeSearchTab; // Tab with running search
|
||||||
|
QList<QPointer<SearchTab> > m_allTabs; // To store all tabs
|
||||||
|
MainWindow *m_mainWindow; |
||||||
|
bool m_isNewQueryString; |
||||||
|
bool m_noSearchResults; |
||||||
|
QByteArray m_searchResultLineTruncated; |
||||||
|
unsigned long m_nbSearchResults; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // SEARCHWIDGET_H
|
@ -0,0 +1,50 @@ |
|||||||
|
<!DOCTYPE RCC><RCC version="1.0"> |
||||||
|
<qresource> |
||||||
|
<file>searchengine/nova/fix_encoding.py</file> |
||||||
|
<file>searchengine/nova/helpers.py</file> |
||||||
|
<file>searchengine/nova/nova2.py</file> |
||||||
|
<file>searchengine/nova/novaprinter.py</file> |
||||||
|
<file>searchengine/nova/socks.py</file> |
||||||
|
<file>searchengine/nova/engines/btdigg.png</file> |
||||||
|
<file>searchengine/nova/engines/btdigg.py</file> |
||||||
|
<file>searchengine/nova/engines/demonoid.png</file> |
||||||
|
<file>searchengine/nova/engines/demonoid.py</file> |
||||||
|
<file>searchengine/nova/engines/extratorrent.png</file> |
||||||
|
<file>searchengine/nova/engines/extratorrent.py</file> |
||||||
|
<file>searchengine/nova/engines/kickasstorrents.png</file> |
||||||
|
<file>searchengine/nova/engines/kickasstorrents.py</file> |
||||||
|
<file>searchengine/nova/engines/legittorrents.png</file> |
||||||
|
<file>searchengine/nova/engines/legittorrents.py</file> |
||||||
|
<file>searchengine/nova/engines/mininova.png</file> |
||||||
|
<file>searchengine/nova/engines/mininova.py</file> |
||||||
|
<file>searchengine/nova/engines/piratebay.png</file> |
||||||
|
<file>searchengine/nova/engines/piratebay.py</file> |
||||||
|
<file>searchengine/nova/engines/torrentreactor.png</file> |
||||||
|
<file>searchengine/nova/engines/torrentreactor.py</file> |
||||||
|
<file>searchengine/nova/engines/torrentz.png</file> |
||||||
|
<file>searchengine/nova/engines/torrentz.py</file> |
||||||
|
<file>searchengine/nova3/helpers.py</file> |
||||||
|
<file>searchengine/nova3/nova2.py</file> |
||||||
|
<file>searchengine/nova3/novaprinter.py</file> |
||||||
|
<file>searchengine/nova3/sgmllib3.py</file> |
||||||
|
<file>searchengine/nova3/socks.py</file> |
||||||
|
<file>searchengine/nova3/engines/btdigg.png</file> |
||||||
|
<file>searchengine/nova3/engines/btdigg.py</file> |
||||||
|
<file>searchengine/nova3/engines/demonoid.png</file> |
||||||
|
<file>searchengine/nova3/engines/demonoid.py</file> |
||||||
|
<file>searchengine/nova3/engines/extratorrent.png</file> |
||||||
|
<file>searchengine/nova3/engines/extratorrent.py</file> |
||||||
|
<file>searchengine/nova3/engines/kickasstorrents.png</file> |
||||||
|
<file>searchengine/nova3/engines/kickasstorrents.py</file> |
||||||
|
<file>searchengine/nova3/engines/legittorrents.png</file> |
||||||
|
<file>searchengine/nova3/engines/legittorrents.py</file> |
||||||
|
<file>searchengine/nova3/engines/mininova.png</file> |
||||||
|
<file>searchengine/nova3/engines/mininova.py</file> |
||||||
|
<file>searchengine/nova3/engines/piratebay.png</file> |
||||||
|
<file>searchengine/nova3/engines/piratebay.py</file> |
||||||
|
<file>searchengine/nova3/engines/torrentreactor.png</file> |
||||||
|
<file>searchengine/nova3/engines/torrentreactor.py</file> |
||||||
|
<file>searchengine/nova3/engines/torrentz.png</file> |
||||||
|
<file>searchengine/nova3/engines/torrentz.py</file> |
||||||
|
</qresource> |
||||||
|
</RCC> |
@ -1,519 +0,0 @@ |
|||||||
/*
|
|
||||||
* Bittorrent Client using Qt4 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 "engineselectdlg.h" |
|
||||||
#include "base/net/downloadmanager.h" |
|
||||||
#include "base/net/downloadhandler.h" |
|
||||||
#include "base/utils/fs.h" |
|
||||||
#include "base/utils/misc.h" |
|
||||||
#include "ico.h" |
|
||||||
#include "searchengine.h" |
|
||||||
#include "pluginsource.h" |
|
||||||
#include "guiiconprovider.h" |
|
||||||
#include "autoexpandabledialog.h" |
|
||||||
#include <QProcess> |
|
||||||
#include <QHeaderView> |
|
||||||
#include <QMenu> |
|
||||||
#include <QMessageBox> |
|
||||||
#include <QFileDialog> |
|
||||||
#include <QDropEvent> |
|
||||||
#include <QTemporaryFile> |
|
||||||
#include <QMimeData> |
|
||||||
#include <QClipboard> |
|
||||||
#ifdef QBT_USES_QT5 |
|
||||||
#include <QTableView> |
|
||||||
#endif |
|
||||||
|
|
||||||
enum EngineColumns {ENGINE_NAME, ENGINE_VERSION, ENGINE_URL, ENGINE_STATE, ENGINE_ID}; |
|
||||||
|
|
||||||
engineSelectDlg::engineSelectDlg(QWidget *parent, SupportedEngines *supported_engines) |
|
||||||
: QDialog(parent) |
|
||||||
, supported_engines(supported_engines) |
|
||||||
, m_updateUrl(QString("https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/") + (Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova") + "/engines/") |
|
||||||
{ |
|
||||||
setupUi(this); |
|
||||||
setAttribute(Qt::WA_DeleteOnClose); |
|
||||||
#ifdef QBT_USES_QT5 |
|
||||||
// This hack fixes reordering of first column with Qt5.
|
|
||||||
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
|
|
||||||
QTableView unused; |
|
||||||
unused.setVerticalHeader(pluginsTree->header()); |
|
||||||
pluginsTree->header()->setParent(pluginsTree); |
|
||||||
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); |
|
||||||
#endif |
|
||||||
pluginsTree->setRootIsDecorated(false); |
|
||||||
pluginsTree->header()->resizeSection(0, 160); |
|
||||||
pluginsTree->header()->resizeSection(1, 80); |
|
||||||
pluginsTree->header()->resizeSection(2, 200); |
|
||||||
pluginsTree->hideColumn(ENGINE_ID); |
|
||||||
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&))); |
|
||||||
loadSupportedSearchEngines(); |
|
||||||
connect(supported_engines, SIGNAL(newSupportedEngine(QString)), this, SLOT(addNewEngine(QString))); |
|
||||||
connect(pluginsTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), this, SLOT(toggleEngineState(QTreeWidgetItem*, int))); |
|
||||||
show(); |
|
||||||
} |
|
||||||
|
|
||||||
engineSelectDlg::~engineSelectDlg() { |
|
||||||
qDebug("Destroying engineSelectDlg"); |
|
||||||
emit enginesChanged(); |
|
||||||
qDebug("Engine plugins dialog destroyed"); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::dropEvent(QDropEvent *event) { |
|
||||||
event->acceptProposedAction(); |
|
||||||
QStringList files; |
|
||||||
if (event->mimeData()->hasUrls()) { |
|
||||||
const QList<QUrl> urls = event->mimeData()->urls(); |
|
||||||
foreach (const QUrl &url, urls) { |
|
||||||
if (!url.isEmpty()) { |
|
||||||
if (url.scheme().compare("file", Qt::CaseInsensitive) == 0) |
|
||||||
files << url.toLocalFile(); |
|
||||||
else |
|
||||||
files << url.toString(); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
else { |
|
||||||
files = event->mimeData()->text().split(QString::fromUtf8("\n")); |
|
||||||
} |
|
||||||
foreach (QString file, files) { |
|
||||||
qDebug("dropped %s", qPrintable(file)); |
|
||||||
if (Utils::Misc::isUrl(file)) { |
|
||||||
setCursor(QCursor(Qt::WaitCursor)); |
|
||||||
downloadFromUrl(file); |
|
||||||
continue; |
|
||||||
} |
|
||||||
if (file.endsWith(".py", Qt::CaseInsensitive)) { |
|
||||||
if (file.startsWith("file:", Qt::CaseInsensitive)) |
|
||||||
file = QUrl(file).toLocalFile(); |
|
||||||
QString plugin_name = Utils::Fs::fileName(file); |
|
||||||
plugin_name.chop(3); // Remove extension
|
|
||||||
installPlugin(file, plugin_name); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Decode if we accept drag 'n drop or not
|
|
||||||
void engineSelectDlg::dragEnterEvent(QDragEnterEvent *event) { |
|
||||||
QString 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(); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::on_updateButton_clicked() { |
|
||||||
// Download version file from update server on sourceforge
|
|
||||||
setCursor(QCursor(Qt::WaitCursor)); |
|
||||||
downloadFromUrl(m_updateUrl + "versions.txt"); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::toggleEngineState(QTreeWidgetItem *item, int) { |
|
||||||
SupportedEngine *engine = supported_engines->value(item->text(ENGINE_ID)); |
|
||||||
engine->setEnabled(!engine->isEnabled()); |
|
||||||
if (engine->isEnabled()) { |
|
||||||
item->setText(ENGINE_STATE, tr("Yes")); |
|
||||||
setRowColor(pluginsTree->indexOfTopLevelItem(item), "green"); |
|
||||||
} else { |
|
||||||
item->setText(ENGINE_STATE, tr("No")); |
|
||||||
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red"); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::displayContextMenu(const QPoint&) { |
|
||||||
QMenu myContextMenu(this); |
|
||||||
// Enable/disable pause/start action given the DL state
|
|
||||||
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); |
|
||||||
if (items.isEmpty()) return; |
|
||||||
QString first_id = items.first()->text(ENGINE_ID); |
|
||||||
actionEnable->setChecked(supported_engines->value(first_id)->isEnabled()); |
|
||||||
myContextMenu.addAction(actionEnable); |
|
||||||
myContextMenu.addSeparator(); |
|
||||||
myContextMenu.addAction(actionUninstall); |
|
||||||
myContextMenu.exec(QCursor::pos()); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::on_closeButton_clicked() { |
|
||||||
close(); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::on_actionUninstall_triggered() { |
|
||||||
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); |
|
||||||
QTreeWidgetItem *item; |
|
||||||
bool error = false; |
|
||||||
foreach (item, items) { |
|
||||||
int index = pluginsTree->indexOfTopLevelItem(item); |
|
||||||
Q_ASSERT(index != -1); |
|
||||||
QString id = item->text(ENGINE_ID); |
|
||||||
if (QFile::exists(":/nova/engines/"+id+".py")) { |
|
||||||
error = true; |
|
||||||
// Disable it instead
|
|
||||||
supported_engines->value(id)->setEnabled(false); |
|
||||||
item->setText(ENGINE_STATE, tr("No")); |
|
||||||
setRowColor(index, "red"); |
|
||||||
continue; |
|
||||||
}else { |
|
||||||
// Proceed with uninstall
|
|
||||||
// remove it from hard drive
|
|
||||||
QDir enginesFolder(Utils::Fs::searchEngineLocation() + "/engines"); |
|
||||||
QStringList filters; |
|
||||||
filters << id+".*"; |
|
||||||
QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted); |
|
||||||
QString file; |
|
||||||
foreach (file, files) { |
|
||||||
enginesFolder.remove(file); |
|
||||||
} |
|
||||||
// Remove it from supported engines
|
|
||||||
delete supported_engines->take(id); |
|
||||||
delete item; |
|
||||||
} |
|
||||||
} |
|
||||||
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.")); |
|
||||||
else |
|
||||||
QMessageBox::information(0, tr("Uninstall success"), tr("All selected plugins were uninstalled successfully")); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::enableSelection(bool enable) { |
|
||||||
QList<QTreeWidgetItem *> items = pluginsTree->selectedItems(); |
|
||||||
QTreeWidgetItem *item; |
|
||||||
foreach (item, items) { |
|
||||||
int index = pluginsTree->indexOfTopLevelItem(item); |
|
||||||
Q_ASSERT(index != -1); |
|
||||||
QString id = item->text(ENGINE_ID); |
|
||||||
supported_engines->value(id)->setEnabled(enable); |
|
||||||
if (enable) { |
|
||||||
item->setText(ENGINE_STATE, tr("Yes")); |
|
||||||
setRowColor(index, "green"); |
|
||||||
} else { |
|
||||||
item->setText(ENGINE_STATE, tr("No")); |
|
||||||
setRowColor(index, "red"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Set the color of a row in data model
|
|
||||||
void engineSelectDlg::setRowColor(int row, QString color) { |
|
||||||
QTreeWidgetItem *item = pluginsTree->topLevelItem(row); |
|
||||||
for (int i=0; i<pluginsTree->columnCount(); ++i) { |
|
||||||
item->setData(i, Qt::ForegroundRole, QVariant(QColor(color))); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
QList<QTreeWidgetItem*> engineSelectDlg::findItemsWithUrl(QString url) { |
|
||||||
QList<QTreeWidgetItem*> res; |
|
||||||
for (int i=0; i<pluginsTree->topLevelItemCount(); ++i) { |
|
||||||
QTreeWidgetItem *item = pluginsTree->topLevelItem(i); |
|
||||||
if (url.startsWith(item->text(ENGINE_URL), Qt::CaseInsensitive)) |
|
||||||
res << item; |
|
||||||
} |
|
||||||
return res; |
|
||||||
} |
|
||||||
|
|
||||||
QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id) { |
|
||||||
QList<QTreeWidgetItem*> res; |
|
||||||
for (int i=0; i<pluginsTree->topLevelItemCount(); ++i) { |
|
||||||
QTreeWidgetItem *item = pluginsTree->topLevelItem(i); |
|
||||||
if (id == item->text(ENGINE_ID)) |
|
||||||
return item; |
|
||||||
} |
|
||||||
return 0; |
|
||||||
} |
|
||||||
|
|
||||||
bool engineSelectDlg::isUpdateNeeded(QString plugin_name, qreal new_version) const { |
|
||||||
qreal old_version = SearchEngine::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + plugin_name + ".py"); |
|
||||||
qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version); |
|
||||||
return (new_version > old_version); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::installPlugin(QString path, QString plugin_name) { |
|
||||||
qDebug("Asked to install plugin at %s", qPrintable(path)); |
|
||||||
qreal new_version = SearchEngine::getPluginVersion(path); |
|
||||||
if (new_version == 0.0) { |
|
||||||
QMessageBox::warning(this, tr("Invalid plugin"), tr("The search engine plugin is invalid, please contact the author.")); |
|
||||||
return; |
|
||||||
} |
|
||||||
qDebug("Version to be installed: %.2f", new_version); |
|
||||||
if (!isUpdateNeeded(plugin_name, new_version)) { |
|
||||||
qDebug("Apparently update is not needed, we have a more recent version"); |
|
||||||
QMessageBox::information(this, tr("Search plugin install"), tr("A more recent version of '%1' search engine plugin is already installed.", "%1 is the name of the search engine").arg(plugin_name)); |
|
||||||
return; |
|
||||||
} |
|
||||||
// Process with install
|
|
||||||
QString dest_path = Utils::Fs::searchEngineLocation() + "/engines/" + plugin_name + ".py"; |
|
||||||
bool update = false; |
|
||||||
if (QFile::exists(dest_path)) { |
|
||||||
// Backup in case install fails
|
|
||||||
QFile::copy(dest_path, dest_path+".bak"); |
|
||||||
Utils::Fs::forceRemove(dest_path); |
|
||||||
Utils::Fs::forceRemove(dest_path+"c"); |
|
||||||
update = true; |
|
||||||
} |
|
||||||
// Copy the plugin
|
|
||||||
QFile::copy(path, dest_path); |
|
||||||
// Update supported plugins
|
|
||||||
supported_engines->update(); |
|
||||||
// Check if this was correctly installed
|
|
||||||
if (!supported_engines->contains(plugin_name)) { |
|
||||||
if (update) { |
|
||||||
// Remove broken file
|
|
||||||
Utils::Fs::forceRemove(dest_path); |
|
||||||
// restore backup
|
|
||||||
QFile::copy(dest_path+".bak", dest_path); |
|
||||||
Utils::Fs::forceRemove(dest_path+".bak"); |
|
||||||
QMessageBox::warning(this, tr("Search plugin install"), tr("'%1' search engine plugin could not be updated, keeping old version.", "%1 is the name of the search engine").arg(plugin_name)); |
|
||||||
return; |
|
||||||
} else { |
|
||||||
// Remove broken file
|
|
||||||
Utils::Fs::forceRemove(dest_path); |
|
||||||
QMessageBox::warning(this, tr("Search plugin install"), tr("'%1' search engine plugin could not be installed.", "%1 is the name of the search engine").arg(plugin_name)); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
// Install was successful, remove backup and update plugin version
|
|
||||||
if (update) { |
|
||||||
Utils::Fs::forceRemove(dest_path+".bak"); |
|
||||||
qreal version = SearchEngine::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + plugin_name + ".py"); |
|
||||||
QTreeWidgetItem *item = findItemWithID(plugin_name); |
|
||||||
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)); |
|
||||||
return; |
|
||||||
} else { |
|
||||||
QMessageBox::information(this, tr("Search plugin install"), tr("'%1' search engine plugin was successfully installed.", "%1 is the name of the search engine").arg(plugin_name)); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::loadSupportedSearchEngines() { |
|
||||||
// Some clean up first
|
|
||||||
pluginsTree->clear(); |
|
||||||
foreach (QString name, supported_engines->keys()) { |
|
||||||
addNewEngine(name); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::addNewEngine(QString engine_name) { |
|
||||||
QTreeWidgetItem *item = new QTreeWidgetItem(pluginsTree); |
|
||||||
SupportedEngine *engine = supported_engines->value(engine_name); |
|
||||||
item->setText(ENGINE_NAME, engine->getFullName()); |
|
||||||
item->setText(ENGINE_URL, engine->getUrl()); |
|
||||||
item->setText(ENGINE_ID, engine->getName()); |
|
||||||
if (engine->isEnabled()) { |
|
||||||
item->setText(ENGINE_STATE, tr("Yes")); |
|
||||||
setRowColor(pluginsTree->indexOfTopLevelItem(item), "green"); |
|
||||||
} else { |
|
||||||
item->setText(ENGINE_STATE, tr("No")); |
|
||||||
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red"); |
|
||||||
} |
|
||||||
// Handle icon
|
|
||||||
QString iconPath = Utils::Fs::searchEngineLocation() + "/engines/" + engine->getName() + ".png"; |
|
||||||
if (QFile::exists(iconPath)) { |
|
||||||
// Good, we already have the icon
|
|
||||||
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); |
|
||||||
} else { |
|
||||||
iconPath = Utils::Fs::searchEngineLocation() + "/engines/" + engine->getName() + ".ico"; |
|
||||||
if (QFile::exists(iconPath)) { // ICO support
|
|
||||||
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); |
|
||||||
} else { |
|
||||||
// Icon is missing, we must download it
|
|
||||||
downloadFromUrl(engine->getUrl() + "/favicon.ico"); |
|
||||||
} |
|
||||||
} |
|
||||||
// Load version
|
|
||||||
qreal version = SearchEngine::getPluginVersion(Utils::Fs::searchEngineLocation() + "/engines/" + engine->getName() + ".py"); |
|
||||||
item->setText(ENGINE_VERSION, QString::number(version, 'f', 2)); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::on_installButton_clicked() { |
|
||||||
pluginSourceDlg *dlg = new pluginSourceDlg(this); |
|
||||||
connect(dlg, SIGNAL(askForLocalFile()), this, SLOT(askForLocalPlugin())); |
|
||||||
connect(dlg, SIGNAL(askForUrl()), this, SLOT(askForPluginUrl())); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::askForPluginUrl() { |
|
||||||
bool ok(false); |
|
||||||
QString clipTxt = qApp->clipboard()->text(); |
|
||||||
QString defaultUrl = "http://"; |
|
||||||
if ((clipTxt.startsWith("http://", Qt::CaseInsensitive) |
|
||||||
|| clipTxt.startsWith("https://", Qt::CaseInsensitive) |
|
||||||
|| clipTxt.startsWith("ftp://", Qt::CaseInsensitive)) |
|
||||||
&& clipTxt.endsWith(".py")) |
|
||||||
defaultUrl = clipTxt; |
|
||||||
QString url = AutoExpandableDialog::getText(this, tr("New search engine plugin URL"), |
|
||||||
tr("URL:"), QLineEdit::Normal, |
|
||||||
defaultUrl, &ok); |
|
||||||
|
|
||||||
while(true) { |
|
||||||
if (!ok || url.isEmpty()) |
|
||||||
return; |
|
||||||
if (!url.endsWith(".py")) { |
|
||||||
QMessageBox::warning(this, tr("Invalid link"), tr("The link doesn't seem to point to a search engine plugin.")); |
|
||||||
url = AutoExpandableDialog::getText(this, tr("New search engine plugin URL"), |
|
||||||
tr("URL:"), QLineEdit::Normal, |
|
||||||
url, &ok); |
|
||||||
} |
|
||||||
else |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
setCursor(QCursor(Qt::WaitCursor)); |
|
||||||
downloadFromUrl(url); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::askForLocalPlugin() { |
|
||||||
QStringList pathsList = QFileDialog::getOpenFileNames(0, |
|
||||||
tr("Select search plugins"), QDir::homePath(), |
|
||||||
tr("qBittorrent search plugin")+QString::fromUtf8(" (*.py)")); |
|
||||||
foreach (QString path, pathsList) { |
|
||||||
if (path.endsWith(".py", Qt::CaseInsensitive)) { |
|
||||||
QString plugin_name = Utils::Fs::fileName(path); |
|
||||||
plugin_name.chop(3); // Remove extension
|
|
||||||
installPlugin(path, plugin_name); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
bool engineSelectDlg::parseVersionsFile(QString versions_file) { |
|
||||||
qDebug("Checking if update is needed"); |
|
||||||
bool file_correct = false; |
|
||||||
QFile versions(versions_file); |
|
||||||
if (!versions.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
||||||
qDebug("* Error: Could not read versions.txt file"); |
|
||||||
return false; |
|
||||||
} |
|
||||||
bool updated = false; |
|
||||||
while(!versions.atEnd()) { |
|
||||||
QByteArray line = versions.readLine(); |
|
||||||
line.replace("\n", ""); |
|
||||||
line = line.trimmed(); |
|
||||||
if (line.isEmpty()) continue; |
|
||||||
if (line.startsWith("#")) continue; |
|
||||||
QList<QByteArray> list = line.split(' '); |
|
||||||
if (list.size() != 2) continue; |
|
||||||
QString plugin_name = QString(list.first()); |
|
||||||
if (!plugin_name.endsWith(":")) continue; |
|
||||||
plugin_name.chop(1); // remove trailing ':'
|
|
||||||
bool ok; |
|
||||||
qreal version = list.last().toFloat(&ok); |
|
||||||
qDebug("read line %s: %.2f", qPrintable(plugin_name), version); |
|
||||||
if (!ok) continue; |
|
||||||
file_correct = true; |
|
||||||
if (isUpdateNeeded(plugin_name, version)) { |
|
||||||
qDebug("Plugin: %s is outdated", qPrintable(plugin_name)); |
|
||||||
// Downloading update
|
|
||||||
setCursor(QCursor(Qt::WaitCursor)); |
|
||||||
downloadFromUrl(m_updateUrl + plugin_name + ".py"); |
|
||||||
//downloadFromUrl(m_updateUrl + plugin_name + ".png");
|
|
||||||
updated = true; |
|
||||||
}else { |
|
||||||
qDebug("Plugin: %s is up to date", qPrintable(plugin_name)); |
|
||||||
} |
|
||||||
} |
|
||||||
// Close file
|
|
||||||
versions.close(); |
|
||||||
// Clean up tmp file
|
|
||||||
Utils::Fs::forceRemove(versions_file); |
|
||||||
if (file_correct && !updated) { |
|
||||||
QMessageBox::information(this, tr("Search plugin update"), tr("All your plugins are already up to date.")); |
|
||||||
} |
|
||||||
return file_correct; |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::downloadFromUrl(const QString &url) |
|
||||||
{ |
|
||||||
Net::DownloadHandler *handler = Net::DownloadManager::instance()->downloadUrl(url, true); |
|
||||||
connect(handler, SIGNAL(downloadFinished(QString, QString)), this, SLOT(processDownloadedFile(QString, QString))); |
|
||||||
connect(handler, SIGNAL(downloadFailed(QString, QString)), this, SLOT(handleDownloadFailure(QString, QString))); |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::processDownloadedFile(const QString &url, QString filePath) { |
|
||||||
filePath = Utils::Fs::fromNativePath(filePath); |
|
||||||
setCursor(QCursor(Qt::ArrowCursor)); |
|
||||||
qDebug("engineSelectDlg received %s", qPrintable(url)); |
|
||||||
if (url.endsWith("favicon.ico", Qt::CaseInsensitive)) { |
|
||||||
// Icon downloaded
|
|
||||||
QImage fileIcon; |
|
||||||
if (fileIcon.load(filePath)) { |
|
||||||
QList<QTreeWidgetItem*> items = findItemsWithUrl(url); |
|
||||||
QTreeWidgetItem *item; |
|
||||||
foreach (item, items) { |
|
||||||
QString id = item->text(ENGINE_ID); |
|
||||||
QString iconPath; |
|
||||||
QFile icon(filePath); |
|
||||||
icon.open(QIODevice::ReadOnly); |
|
||||||
if (ICOHandler::canRead(&icon)) |
|
||||||
iconPath = Utils::Fs::searchEngineLocation() + "/engines/" + id + ".ico"; |
|
||||||
else |
|
||||||
iconPath = Utils::Fs::searchEngineLocation() + "/engines/" + id + ".png"; |
|
||||||
QFile::copy(filePath, iconPath); |
|
||||||
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); |
|
||||||
} |
|
||||||
} |
|
||||||
// Delete tmp file
|
|
||||||
Utils::Fs::forceRemove(filePath); |
|
||||||
return; |
|
||||||
} |
|
||||||
if (url.endsWith("versions.txt")) { |
|
||||||
if (!parseVersionsFile(filePath)) { |
|
||||||
QMessageBox::warning(this, tr("Search plugin update"), tr("Sorry, update server is temporarily unavailable.")); |
|
||||||
} |
|
||||||
Utils::Fs::forceRemove(filePath); |
|
||||||
return; |
|
||||||
} |
|
||||||
if (url.endsWith(".py", Qt::CaseInsensitive)) { |
|
||||||
QString plugin_name = Utils::Fs::fileName(url); |
|
||||||
plugin_name.chop(3); // Remove extension
|
|
||||||
installPlugin(filePath, plugin_name); |
|
||||||
Utils::Fs::forceRemove(filePath); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void engineSelectDlg::handleDownloadFailure(const QString &url, const QString &reason) { |
|
||||||
setCursor(QCursor(Qt::ArrowCursor)); |
|
||||||
if (url.endsWith("favicon.ico", Qt::CaseInsensitive)) { |
|
||||||
qDebug("Could not download favicon: %s, reason: %s", qPrintable(url), qPrintable(reason)); |
|
||||||
return; |
|
||||||
} |
|
||||||
if (url.endsWith("versions.txt")) { |
|
||||||
QMessageBox::warning(this, tr("Search plugin update"), tr("Sorry, update server is temporarily unavailable.")); |
|
||||||
return; |
|
||||||
} |
|
||||||
if (url.endsWith(".py", Qt::CaseInsensitive)) { |
|
||||||
// a plugin update download has been failed
|
|
||||||
QString plugin_name = url.split('/').last(); |
|
||||||
plugin_name.replace(".py", "", Qt::CaseInsensitive); |
|
||||||
QMessageBox::warning(this, tr("Search plugin update"), tr("Sorry, '%1' search plugin installation failed.", "%1 is the name of the search engine").arg(plugin_name)); |
|
||||||
} |
|
||||||
} |
|
@ -1,61 +0,0 @@ |
|||||||
#VERSION: 1.20 |
|
||||||
|
|
||||||
# Author: |
|
||||||
# Christophe DUMEZ (chris@qbittorrent.org) |
|
||||||
|
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright notice, |
|
||||||
# this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer in the |
|
||||||
# documentation and/or other materials provided with the distribution. |
|
||||||
# * Neither the name of the author nor the names of its contributors may be |
|
||||||
# used to endorse or promote products derived from this software without |
|
||||||
# specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
||||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
||||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|
||||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
||||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
||||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
||||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
||||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
||||||
# POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
import sys |
|
||||||
import os |
|
||||||
import glob |
|
||||||
from helpers import download_file |
|
||||||
|
|
||||||
supported_engines = dict() |
|
||||||
|
|
||||||
engines = glob.glob(os.path.join(os.path.dirname(__file__), 'engines','*.py')) |
|
||||||
for engine in engines: |
|
||||||
e = engine.split(os.sep)[-1][:-3] |
|
||||||
if len(e.strip()) == 0: continue |
|
||||||
if e.startswith('_'): continue |
|
||||||
try: |
|
||||||
exec("from engines.%s import %s"%(e,e)) |
|
||||||
exec("engine_url = %s.url"%e) |
|
||||||
supported_engines[engine_url] = e |
|
||||||
except: |
|
||||||
pass |
|
||||||
|
|
||||||
if __name__ == '__main__': |
|
||||||
if len(sys.argv) < 3: |
|
||||||
raise SystemExit('./nova2dl.py engine_url download_parameter') |
|
||||||
engine_url = sys.argv[1].strip() |
|
||||||
download_param = sys.argv[2].strip() |
|
||||||
if engine_url not in list(supported_engines.keys()): |
|
||||||
raise SystemExit('./nova2dl.py: this engine_url was not recognized') |
|
||||||
exec("engine = %s()"%supported_engines[engine_url]) |
|
||||||
if hasattr(engine, 'download_torrent'): |
|
||||||
engine.download_torrent(download_param) |
|
||||||
else: |
|
||||||
print(download_file(download_param)) |
|
||||||
sys.exit(0) |
|
@ -1,61 +0,0 @@ |
|||||||
#VERSION: 1.20 |
|
||||||
|
|
||||||
# Author: |
|
||||||
# Christophe DUMEZ (chris@qbittorrent.org) |
|
||||||
|
|
||||||
# Redistribution and use in source and binary forms, with or without |
|
||||||
# modification, are permitted provided that the following conditions are met: |
|
||||||
# |
|
||||||
# * Redistributions of source code must retain the above copyright notice, |
|
||||||
# this list of conditions and the following disclaimer. |
|
||||||
# * Redistributions in binary form must reproduce the above copyright |
|
||||||
# notice, this list of conditions and the following disclaimer in the |
|
||||||
# documentation and/or other materials provided with the distribution. |
|
||||||
# * Neither the name of the author nor the names of its contributors may be |
|
||||||
# used to endorse or promote products derived from this software without |
|
||||||
# specific prior written permission. |
|
||||||
# |
|
||||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
||||||
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
||||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
||||||
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
|
||||||
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
||||||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
||||||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
||||||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
||||||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
||||||
# POSSIBILITY OF SUCH DAMAGE. |
|
||||||
|
|
||||||
import sys |
|
||||||
import os |
|
||||||
import glob |
|
||||||
from helpers import download_file |
|
||||||
|
|
||||||
supported_engines = dict() |
|
||||||
|
|
||||||
engines = glob.glob(os.path.join(os.path.dirname(__file__), 'engines','*.py')) |
|
||||||
for engine in engines: |
|
||||||
e = engine.split(os.sep)[-1][:-3] |
|
||||||
if len(e.strip()) == 0: continue |
|
||||||
if e.startswith('_'): continue |
|
||||||
try: |
|
||||||
exec("from engines.%s import %s"%(e,e)) |
|
||||||
exec("engine_url = %s.url"%e) |
|
||||||
supported_engines[engine_url] = e |
|
||||||
except: |
|
||||||
pass |
|
||||||
|
|
||||||
if __name__ == '__main__': |
|
||||||
if len(sys.argv) < 3: |
|
||||||
raise SystemExit('./nova2dl.py engine_url download_parameter') |
|
||||||
engine_url = sys.argv[1].strip() |
|
||||||
download_param = sys.argv[2].strip() |
|
||||||
if engine_url not in list(supported_engines.keys()): |
|
||||||
raise SystemExit('./nova2dl.py: this engine_url was not recognized') |
|
||||||
exec("engine = %s()"%supported_engines[engine_url]) |
|
||||||
if hasattr(engine, 'download_torrent'): |
|
||||||
engine.download_torrent(download_param) |
|
||||||
else: |
|
||||||
print(download_file(download_param)) |
|
||||||
sys.exit(0) |
|
@ -1,52 +0,0 @@ |
|||||||
<!DOCTYPE RCC><RCC version="1.0"> |
|
||||||
<qresource> |
|
||||||
<file>nova/fix_encoding.py</file> |
|
||||||
<file>nova/helpers.py</file> |
|
||||||
<file>nova/nova2.py</file> |
|
||||||
<file>nova/nova2dl.py</file> |
|
||||||
<file>nova/novaprinter.py</file> |
|
||||||
<file>nova/socks.py</file> |
|
||||||
<file>nova/engines/btdigg.png</file> |
|
||||||
<file>nova/engines/btdigg.py</file> |
|
||||||
<file>nova/engines/demonoid.png</file> |
|
||||||
<file>nova/engines/demonoid.py</file> |
|
||||||
<file>nova/engines/extratorrent.png</file> |
|
||||||
<file>nova/engines/extratorrent.py</file> |
|
||||||
<file>nova/engines/kickasstorrents.png</file> |
|
||||||
<file>nova/engines/kickasstorrents.py</file> |
|
||||||
<file>nova/engines/legittorrents.png</file> |
|
||||||
<file>nova/engines/legittorrents.py</file> |
|
||||||
<file>nova/engines/mininova.png</file> |
|
||||||
<file>nova/engines/mininova.py</file> |
|
||||||
<file>nova/engines/piratebay.png</file> |
|
||||||
<file>nova/engines/piratebay.py</file> |
|
||||||
<file>nova/engines/torrentreactor.png</file> |
|
||||||
<file>nova/engines/torrentreactor.py</file> |
|
||||||
<file>nova/engines/torrentz.png</file> |
|
||||||
<file>nova/engines/torrentz.py</file> |
|
||||||
<file>nova3/helpers.py</file> |
|
||||||
<file>nova3/nova2.py</file> |
|
||||||
<file>nova3/nova2dl.py</file> |
|
||||||
<file>nova3/novaprinter.py</file> |
|
||||||
<file>nova3/sgmllib3.py</file> |
|
||||||
<file>nova3/socks.py</file> |
|
||||||
<file>nova3/engines/btdigg.png</file> |
|
||||||
<file>nova3/engines/btdigg.py</file> |
|
||||||
<file>nova3/engines/demonoid.png</file> |
|
||||||
<file>nova3/engines/demonoid.py</file> |
|
||||||
<file>nova3/engines/extratorrent.png</file> |
|
||||||
<file>nova3/engines/extratorrent.py</file> |
|
||||||
<file>nova3/engines/kickasstorrents.png</file> |
|
||||||
<file>nova3/engines/kickasstorrents.py</file> |
|
||||||
<file>nova3/engines/legittorrents.png</file> |
|
||||||
<file>nova3/engines/legittorrents.py</file> |
|
||||||
<file>nova3/engines/mininova.png</file> |
|
||||||
<file>nova3/engines/mininova.py</file> |
|
||||||
<file>nova3/engines/piratebay.png</file> |
|
||||||
<file>nova3/engines/piratebay.py</file> |
|
||||||
<file>nova3/engines/torrentreactor.png</file> |
|
||||||
<file>nova3/engines/torrentreactor.py</file> |
|
||||||
<file>nova3/engines/torrentz.png</file> |
|
||||||
<file>nova3/engines/torrentz.py</file> |
|
||||||
</qresource> |
|
||||||
</RCC> |
|
@ -1,612 +0,0 @@ |
|||||||
/*
|
|
||||||
* Bittorrent Client using Qt4 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 <QStandardItemModel> |
|
||||||
#include <QHeaderView> |
|
||||||
#include <QMessageBox> |
|
||||||
#include <QTemporaryFile> |
|
||||||
#include <QSystemTrayIcon> |
|
||||||
#include <iostream> |
|
||||||
#include <QTimer> |
|
||||||
#include <QDir> |
|
||||||
#include <QMenu> |
|
||||||
#include <QClipboard> |
|
||||||
#include <QMimeData> |
|
||||||
#include <QSortFilterProxyModel> |
|
||||||
#include <QFileDialog> |
|
||||||
#include <QDesktopServices> |
|
||||||
#include <QClipboard> |
|
||||||
|
|
||||||
#ifdef Q_OS_WIN |
|
||||||
#include <stdlib.h> |
|
||||||
#endif |
|
||||||
|
|
||||||
#include "searchengine.h" |
|
||||||
#include "base/bittorrent/session.h" |
|
||||||
#include "base/utils/fs.h" |
|
||||||
#include "base/utils/misc.h" |
|
||||||
#include "base/preferences.h" |
|
||||||
#include "searchlistdelegate.h" |
|
||||||
#include "mainwindow.h" |
|
||||||
#include "addnewtorrentdialog.h" |
|
||||||
#include "guiiconprovider.h" |
|
||||||
#include "lineedit.h" |
|
||||||
|
|
||||||
#define SEARCHHISTORY_MAXSIZE 50 |
|
||||||
|
|
||||||
/*SEARCH ENGINE START*/ |
|
||||||
SearchEngine::SearchEngine(MainWindow* parent) |
|
||||||
: QWidget(parent) |
|
||||||
, search_pattern(new LineEdit(this)) |
|
||||||
, mp_mainWindow(parent) |
|
||||||
{ |
|
||||||
setupUi(this); |
|
||||||
searchBarLayout->insertWidget(0, search_pattern); |
|
||||||
connect(search_pattern, SIGNAL(returnPressed()), search_button, SLOT(click())); |
|
||||||
// Icons
|
|
||||||
search_button->setIcon(GuiIconProvider::instance()->getIcon("edit-find")); |
|
||||||
download_button->setIcon(GuiIconProvider::instance()->getIcon("download")); |
|
||||||
goToDescBtn->setIcon(GuiIconProvider::instance()->getIcon("application-x-mswinurl")); |
|
||||||
enginesButton->setIcon(GuiIconProvider::instance()->getIcon("preferences-system-network")); |
|
||||||
copyURLBtn->setIcon(GuiIconProvider::instance()->getIcon("edit-copy")); |
|
||||||
tabWidget->setTabsClosable(true); |
|
||||||
connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int))); |
|
||||||
// Boolean initialization
|
|
||||||
search_stopped = false; |
|
||||||
// Creating Search Process
|
|
||||||
searchProcess = new QProcess(this); |
|
||||||
searchProcess->setEnvironment(QProcess::systemEnvironment()); |
|
||||||
connect(searchProcess, SIGNAL(started()), this, SLOT(searchStarted())); |
|
||||||
connect(searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput())); |
|
||||||
connect(searchProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(searchFinished(int,QProcess::ExitStatus))); |
|
||||||
connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(tab_changed(int))); |
|
||||||
searchTimeout = new QTimer(this); |
|
||||||
searchTimeout->setSingleShot(true); |
|
||||||
connect(searchTimeout, SIGNAL(timeout()), this, SLOT(on_search_button_clicked())); |
|
||||||
// Update nova.py search plugin if necessary
|
|
||||||
updateNova(); |
|
||||||
supported_engines = new SupportedEngines(); |
|
||||||
// Fill in category combobox
|
|
||||||
fillCatCombobox(); |
|
||||||
fillEngineComboBox(); |
|
||||||
|
|
||||||
connect(search_pattern, SIGNAL(textEdited(QString)), this, SLOT(searchTextEdited(QString))); |
|
||||||
connect(selectEngine, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(selectMultipleBox(const QString &))); |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::fillCatCombobox() |
|
||||||
{ |
|
||||||
comboCategory->clear(); |
|
||||||
comboCategory->addItem(full_cat_names["all"], QVariant("all")); |
|
||||||
QStringList supported_cat = supported_engines->supportedCategories(); |
|
||||||
foreach (QString cat, supported_cat) { |
|
||||||
qDebug("Supported category: %s", qPrintable(cat)); |
|
||||||
comboCategory->addItem(full_cat_names[cat], QVariant(cat)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::fillEngineComboBox() |
|
||||||
{ |
|
||||||
selectEngine->clear(); |
|
||||||
selectEngine->addItem(tr("All enabled"), QVariant("enabled")); |
|
||||||
selectEngine->addItem(tr("All engines"), QVariant("all")); |
|
||||||
foreach (QString engi, supported_engines->enginesEnabled()) |
|
||||||
selectEngine->addItem(engi, QVariant(engi)); |
|
||||||
selectEngine->addItem(tr("Multiple..."), QVariant("multi")); |
|
||||||
} |
|
||||||
|
|
||||||
QString SearchEngine::selectedCategory() const |
|
||||||
{ |
|
||||||
return comboCategory->itemData(comboCategory->currentIndex()).toString(); |
|
||||||
} |
|
||||||
|
|
||||||
QString SearchEngine::selectedEngine() const |
|
||||||
{ |
|
||||||
return selectEngine->itemData(selectEngine->currentIndex()).toString(); |
|
||||||
} |
|
||||||
|
|
||||||
SearchEngine::~SearchEngine() |
|
||||||
{ |
|
||||||
qDebug("Search destruction"); |
|
||||||
searchProcess->kill(); |
|
||||||
searchProcess->waitForFinished(); |
|
||||||
foreach (QProcess *downloader, downloaders) { |
|
||||||
// Make sure we disconnect the SIGNAL/SLOT first
|
|
||||||
// To avoid qreal free
|
|
||||||
downloader->disconnect(); |
|
||||||
downloader->kill(); |
|
||||||
downloader->waitForFinished(); |
|
||||||
delete downloader; |
|
||||||
} |
|
||||||
delete search_pattern; |
|
||||||
delete searchTimeout; |
|
||||||
delete searchProcess; |
|
||||||
delete supported_engines; |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::tab_changed(int t) |
|
||||||
{ |
|
||||||
//when we switch from a tab that is not empty to another that is empty the download button
|
|
||||||
//doesn't have to be available
|
|
||||||
if (t > -1) { |
|
||||||
//-1 = no more tab
|
|
||||||
currentSearchTab = all_tab.at(tabWidget->currentIndex()); |
|
||||||
if (currentSearchTab->getCurrentSearchListModel()->rowCount()) { |
|
||||||
download_button->setEnabled(true); |
|
||||||
goToDescBtn->setEnabled(true); |
|
||||||
copyURLBtn->setEnabled(true); |
|
||||||
} |
|
||||||
else { |
|
||||||
download_button->setEnabled(false); |
|
||||||
goToDescBtn->setEnabled(false); |
|
||||||
copyURLBtn->setEnabled(false); |
|
||||||
} |
|
||||||
search_status->setText(currentSearchTab->status); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::selectMultipleBox(const QString &text) |
|
||||||
{ |
|
||||||
if (text == tr("Multiple...")) on_enginesButton_clicked(); |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::on_enginesButton_clicked() |
|
||||||
{ |
|
||||||
engineSelectDlg *dlg = new engineSelectDlg(this, supported_engines); |
|
||||||
connect(dlg, SIGNAL(enginesChanged()), this, SLOT(fillCatCombobox())); |
|
||||||
connect(dlg, SIGNAL(enginesChanged()), this, SLOT(fillEngineComboBox())); |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::searchTextEdited(QString) |
|
||||||
{ |
|
||||||
// Enable search button
|
|
||||||
search_button->setText(tr("Search")); |
|
||||||
newQueryString = true; |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::giveFocusToSearchInput() |
|
||||||
{ |
|
||||||
search_pattern->setFocus(); |
|
||||||
} |
|
||||||
|
|
||||||
// Function called when we click on search button
|
|
||||||
void SearchEngine::on_search_button_clicked() |
|
||||||
{ |
|
||||||
if (Utils::Misc::pythonVersion() < 0) { |
|
||||||
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Please install Python to use the Search Engine.")); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if (searchProcess->state() != QProcess::NotRunning) { |
|
||||||
#ifdef Q_OS_WIN |
|
||||||
searchProcess->kill(); |
|
||||||
#else |
|
||||||
searchProcess->terminate(); |
|
||||||
#endif |
|
||||||
search_stopped = true; |
|
||||||
if (searchTimeout->isActive()) |
|
||||||
searchTimeout->stop(); |
|
||||||
|
|
||||||
searchProcess->waitForFinished(1000); |
|
||||||
|
|
||||||
if (!newQueryString) { |
|
||||||
search_button->setText(tr("Search")); |
|
||||||
return; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
newQueryString = false; |
|
||||||
|
|
||||||
// Reload environment variables (proxy)
|
|
||||||
searchProcess->setEnvironment(QProcess::systemEnvironment()); |
|
||||||
|
|
||||||
const QString pattern = search_pattern->text().trimmed(); |
|
||||||
// No search pattern entered
|
|
||||||
if (pattern.isEmpty()) { |
|
||||||
QMessageBox::critical(0, tr("Empty search pattern"), tr("Please type a search pattern first")); |
|
||||||
return; |
|
||||||
} |
|
||||||
// Tab Addition
|
|
||||||
currentSearchTab = new SearchTab(this); |
|
||||||
activeSearchTab = currentSearchTab; |
|
||||||
connect(currentSearchTab->header(), SIGNAL(sectionResized(int, int, int)), this, SLOT(saveResultsColumnsWidth())); |
|
||||||
all_tab.append(currentSearchTab); |
|
||||||
QString tabName = pattern; |
|
||||||
tabName.replace(QRegExp("&{1}"), "&&"); |
|
||||||
tabWidget->addTab(currentSearchTab, tabName); |
|
||||||
tabWidget->setCurrentWidget(currentSearchTab); |
|
||||||
|
|
||||||
// Getting checked search engines
|
|
||||||
QStringList params; |
|
||||||
search_stopped = false; |
|
||||||
params << Utils::Fs::toNativePath(Utils::Fs::searchEngineLocation() + "/nova2.py"); |
|
||||||
if (selectedEngine() == "all") params << supported_engines->enginesAll().join(","); |
|
||||||
else if (selectedEngine() == "enabled") params << supported_engines->enginesEnabled().join(","); |
|
||||||
else if (selectedEngine() == "multi") params << supported_engines->enginesEnabled().join(","); |
|
||||||
else params << selectedEngine(); |
|
||||||
qDebug("Search with category: %s", qPrintable(selectedCategory())); |
|
||||||
params << selectedCategory(); |
|
||||||
params << pattern.split(" "); |
|
||||||
// Update SearchEngine widgets
|
|
||||||
no_search_results = true; |
|
||||||
nb_search_results = 0; |
|
||||||
search_result_line_truncated.clear(); |
|
||||||
// Changing the text of the current label
|
|
||||||
activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(0)); |
|
||||||
// Launch search
|
|
||||||
searchProcess->start(Utils::Misc::pythonExecutable(), params, QIODevice::ReadOnly); |
|
||||||
searchTimeout->start(180000); // 3min
|
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::saveResultsColumnsWidth() |
|
||||||
{ |
|
||||||
if (all_tab.isEmpty()) |
|
||||||
return; |
|
||||||
QTreeView* treeview = all_tab.first()->getCurrentTreeView(); |
|
||||||
Preferences* const pref = Preferences::instance(); |
|
||||||
QStringList new_width_list; |
|
||||||
short nbColumns = all_tab.first()->getCurrentSearchListModel()->columnCount(); |
|
||||||
for (short i = 0; i < nbColumns; ++i) |
|
||||||
if (treeview->columnWidth(i) > 0) |
|
||||||
new_width_list << QString::number(treeview->columnWidth(i)); |
|
||||||
// Don't save the width of the last column (auto column width)
|
|
||||||
new_width_list.removeLast(); |
|
||||||
pref->setSearchColsWidth(new_width_list.join(" ")); |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) |
|
||||||
{ |
|
||||||
if (torrent_url.startsWith("bc://bt/", Qt::CaseInsensitive)) { |
|
||||||
qDebug("Converting bc link to magnet link"); |
|
||||||
torrent_url = Utils::Misc::bcLinkToMagnet(torrent_url); |
|
||||||
} |
|
||||||
qDebug() << Q_FUNC_INFO << torrent_url; |
|
||||||
if (torrent_url.startsWith("magnet:")) { |
|
||||||
QStringList urls; |
|
||||||
urls << torrent_url; |
|
||||||
mp_mainWindow->downloadFromURLList(urls); |
|
||||||
} |
|
||||||
else { |
|
||||||
QProcess *downloadProcess = new QProcess(this); |
|
||||||
downloadProcess->setEnvironment(QProcess::systemEnvironment()); |
|
||||||
connect(downloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(downloadFinished(int,QProcess::ExitStatus))); |
|
||||||
downloaders << downloadProcess; |
|
||||||
QStringList params; |
|
||||||
params << Utils::Fs::toNativePath(Utils::Fs::searchEngineLocation() + "/nova2dl.py"); |
|
||||||
params << engine_url; |
|
||||||
params << torrent_url; |
|
||||||
// Launch search
|
|
||||||
downloadProcess->start(Utils::Misc::pythonExecutable(), params, QIODevice::ReadOnly); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::searchStarted() |
|
||||||
{ |
|
||||||
// Update SearchEngine widgets
|
|
||||||
activeSearchTab->status = tr("Searching..."); |
|
||||||
search_status->setText(currentSearchTab->status); |
|
||||||
search_status->repaint(); |
|
||||||
search_button->setText(tr("Stop")); |
|
||||||
} |
|
||||||
|
|
||||||
// search Qprocess return output as soon as it gets new
|
|
||||||
// stuff to read. We split it into lines and add each
|
|
||||||
// line to search results calling appendSearchResult().
|
|
||||||
void SearchEngine::readSearchOutput() |
|
||||||
{ |
|
||||||
QByteArray output = searchProcess->readAllStandardOutput(); |
|
||||||
output.replace("\r", ""); |
|
||||||
QList<QByteArray> lines_list = output.split('\n'); |
|
||||||
if (!search_result_line_truncated.isEmpty()) { |
|
||||||
QByteArray end_of_line = lines_list.takeFirst(); |
|
||||||
lines_list.prepend(search_result_line_truncated + end_of_line); |
|
||||||
} |
|
||||||
search_result_line_truncated = lines_list.takeLast().trimmed(); |
|
||||||
foreach (const QByteArray &line, lines_list) |
|
||||||
appendSearchResult(QString::fromUtf8(line)); |
|
||||||
activeSearchTab->getCurrentLabel()->setText(tr("Results <i>(%1)</i>:", "i.e: Search results").arg(nb_search_results)); |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) |
|
||||||
{ |
|
||||||
QProcess *downloadProcess = (QProcess*)sender(); |
|
||||||
if (exitcode == 0) { |
|
||||||
QString line = QString::fromUtf8(downloadProcess->readAllStandardOutput()).trimmed(); |
|
||||||
QStringList parts = line.split(' '); |
|
||||||
if (parts.size() == 2) { |
|
||||||
QString path = parts[0]; |
|
||||||
|
|
||||||
if (Preferences::instance()->useAdditionDialog()) |
|
||||||
AddNewTorrentDialog::show(path, mp_mainWindow); |
|
||||||
else |
|
||||||
BitTorrent::Session::instance()->addTorrent(path); |
|
||||||
} |
|
||||||
} |
|
||||||
qDebug("Deleting downloadProcess"); |
|
||||||
downloaders.removeOne(downloadProcess); |
|
||||||
delete downloadProcess; |
|
||||||
} |
|
||||||
|
|
||||||
static inline void removePythonScriptIfExists(const QString& script_path) |
|
||||||
{ |
|
||||||
Utils::Fs::forceRemove(script_path); |
|
||||||
Utils::Fs::forceRemove(script_path + "c"); |
|
||||||
} |
|
||||||
|
|
||||||
// Update nova.py search plugin if necessary
|
|
||||||
void SearchEngine::updateNova() |
|
||||||
{ |
|
||||||
qDebug("Updating nova"); |
|
||||||
// create nova directory if necessary
|
|
||||||
QDir search_dir(Utils::Fs::searchEngineLocation()); |
|
||||||
QString nova_folder = Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova"; |
|
||||||
QFile package_file(search_dir.absoluteFilePath("__init__.py")); |
|
||||||
package_file.open(QIODevice::WriteOnly | QIODevice::Text); |
|
||||||
package_file.close(); |
|
||||||
if (!search_dir.exists("engines")) |
|
||||||
search_dir.mkdir("engines"); |
|
||||||
Utils::Fs::removeDirRecursive(search_dir.absoluteFilePath("__pycache__")); |
|
||||||
|
|
||||||
QFile package_file2(search_dir.absolutePath() + "/engines/__init__.py"); |
|
||||||
package_file2.open(QIODevice::WriteOnly | QIODevice::Text); |
|
||||||
package_file2.close(); |
|
||||||
// Copy search plugin files (if necessary)
|
|
||||||
QString filePath = search_dir.absoluteFilePath("nova2.py"); |
|
||||||
if (getPluginVersion(":/" + nova_folder + "/nova2.py") > getPluginVersion(filePath)) { |
|
||||||
removePythonScriptIfExists(filePath); |
|
||||||
QFile::copy(":/" + nova_folder + "/nova2.py", filePath); |
|
||||||
} |
|
||||||
|
|
||||||
filePath = search_dir.absoluteFilePath("nova2dl.py"); |
|
||||||
if (getPluginVersion(":/" + nova_folder + "/nova2dl.py") > getPluginVersion(filePath)) { |
|
||||||
removePythonScriptIfExists(filePath); |
|
||||||
QFile::copy(":/" + nova_folder + "/nova2dl.py", filePath); |
|
||||||
} |
|
||||||
|
|
||||||
filePath = search_dir.absoluteFilePath("novaprinter.py"); |
|
||||||
if (getPluginVersion(":/" + nova_folder + "/novaprinter.py") > getPluginVersion(filePath)) { |
|
||||||
removePythonScriptIfExists(filePath); |
|
||||||
QFile::copy(":/" + nova_folder + "/novaprinter.py", filePath); |
|
||||||
} |
|
||||||
|
|
||||||
filePath = search_dir.absoluteFilePath("helpers.py"); |
|
||||||
if (getPluginVersion(":/" + nova_folder + "/helpers.py") > getPluginVersion(filePath)) { |
|
||||||
removePythonScriptIfExists(filePath); |
|
||||||
QFile::copy(":/" + nova_folder + "/helpers.py", filePath); |
|
||||||
} |
|
||||||
|
|
||||||
filePath = search_dir.absoluteFilePath("socks.py"); |
|
||||||
removePythonScriptIfExists(filePath); |
|
||||||
QFile::copy(":/" + nova_folder + "/socks.py", filePath); |
|
||||||
|
|
||||||
if (nova_folder == "nova") { |
|
||||||
filePath = search_dir.absoluteFilePath("fix_encoding.py"); |
|
||||||
removePythonScriptIfExists(filePath); |
|
||||||
QFile::copy(":/" + nova_folder + "/fix_encoding.py", filePath); |
|
||||||
} |
|
||||||
else if (nova_folder == "nova3") { |
|
||||||
filePath = search_dir.absoluteFilePath("sgmllib3.py"); |
|
||||||
removePythonScriptIfExists(filePath); |
|
||||||
QFile::copy(":/" + nova_folder + "/sgmllib3.py", filePath); |
|
||||||
} |
|
||||||
QDir destDir(QDir(Utils::Fs::searchEngineLocation()).absoluteFilePath("engines")); |
|
||||||
Utils::Fs::removeDirRecursive(destDir.absoluteFilePath("__pycache__")); |
|
||||||
QDir shipped_subDir(":/" + nova_folder + "/engines/"); |
|
||||||
QStringList files = shipped_subDir.entryList(); |
|
||||||
foreach (const QString &file, files) { |
|
||||||
QString shipped_file = shipped_subDir.absoluteFilePath(file); |
|
||||||
// Copy python classes
|
|
||||||
if (file.endsWith(".py")) { |
|
||||||
const QString dest_file = destDir.absoluteFilePath(file); |
|
||||||
if (getPluginVersion(shipped_file) > getPluginVersion(dest_file) ) { |
|
||||||
qDebug("shipped %s is more recent then local plugin, updating...", qPrintable(file)); |
|
||||||
removePythonScriptIfExists(dest_file); |
|
||||||
qDebug("%s copied to %s", qPrintable(shipped_file), qPrintable(dest_file)); |
|
||||||
QFile::copy(shipped_file, dest_file); |
|
||||||
} |
|
||||||
} |
|
||||||
else { |
|
||||||
// Copy icons
|
|
||||||
if (file.endsWith(".png")) |
|
||||||
if (!QFile::exists(destDir.absoluteFilePath(file))) |
|
||||||
QFile::copy(shipped_file, destDir.absoluteFilePath(file)); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Slot called when search is Finished
|
|
||||||
// Search can be finished for 3 reasons :
|
|
||||||
// Error | Stopped by user | Finished normally
|
|
||||||
void SearchEngine::searchFinished(int exitcode, QProcess::ExitStatus) |
|
||||||
{ |
|
||||||
if (searchTimeout->isActive()) |
|
||||||
searchTimeout->stop(); |
|
||||||
bool useNotificationBalloons = Preferences::instance()->useProgramNotification(); |
|
||||||
if (useNotificationBalloons && mp_mainWindow->getCurrentTabWidget() != this) |
|
||||||
mp_mainWindow->showNotificationBaloon(tr("Search Engine"), tr("Search has finished")); |
|
||||||
|
|
||||||
if (activeSearchTab.isNull()) |
|
||||||
// The active tab was closed
|
|
||||||
return; |
|
||||||
|
|
||||||
if (exitcode) { |
|
||||||
#ifdef Q_OS_WIN |
|
||||||
activeSearchTab->status = tr("Search aborted"); |
|
||||||
#else |
|
||||||
activeSearchTab->status = tr("An error occurred during search..."); |
|
||||||
#endif |
|
||||||
} |
|
||||||
else { |
|
||||||
if (search_stopped) { |
|
||||||
activeSearchTab->status = tr("Search aborted"); |
|
||||||
} |
|
||||||
else { |
|
||||||
if (no_search_results) |
|
||||||
activeSearchTab->status = tr("Search returned no results"); |
|
||||||
else |
|
||||||
activeSearchTab->status = tr("Search has finished"); |
|
||||||
} |
|
||||||
} |
|
||||||
search_status->setText(currentSearchTab->status); |
|
||||||
activeSearchTab = 0; |
|
||||||
search_button->setText(tr("Search")); |
|
||||||
} |
|
||||||
|
|
||||||
// SLOT to append one line to search results list
|
|
||||||
// Line is in the following form :
|
|
||||||
// file url | file name | file size | nb seeds | nb leechers | Search engine url
|
|
||||||
void SearchEngine::appendSearchResult(const QString &line) |
|
||||||
{ |
|
||||||
if (activeSearchTab.isNull()) { |
|
||||||
if (searchProcess->state() != QProcess::NotRunning) { |
|
||||||
#ifdef Q_OS_WIN |
|
||||||
searchProcess->kill(); |
|
||||||
#else |
|
||||||
searchProcess->terminate(); |
|
||||||
#endif |
|
||||||
searchProcess->waitForFinished(1000); |
|
||||||
} |
|
||||||
if (searchTimeout->isActive()) |
|
||||||
searchTimeout->stop(); |
|
||||||
search_stopped = true; |
|
||||||
return; |
|
||||||
} |
|
||||||
const QStringList parts = line.split("|"); |
|
||||||
const int nb_fields = parts.size(); |
|
||||||
if (nb_fields < NB_PLUGIN_COLUMNS - 1) //-1 because desc_link is optional
|
|
||||||
return; |
|
||||||
Q_ASSERT(activeSearchTab); |
|
||||||
// Add item to search result list
|
|
||||||
QStandardItemModel* cur_model = activeSearchTab->getCurrentSearchListModel(); |
|
||||||
Q_ASSERT(cur_model); |
|
||||||
int row = cur_model->rowCount(); |
|
||||||
cur_model->insertRow(row); |
|
||||||
|
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::DL_LINK), parts.at(PL_DL_LINK).trimmed()); // download URL
|
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::NAME), parts.at(PL_NAME).trimmed()); // Name
|
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::SIZE), parts.at(PL_SIZE).trimmed().toLongLong()); // Size
|
|
||||||
bool ok = false; |
|
||||||
qlonglong nb_seeders = parts.at(PL_SEEDS).trimmed().toLongLong(&ok); |
|
||||||
if (!ok || nb_seeders < 0) |
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::SEEDS), -1); // Seeders
|
|
||||||
else |
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::SEEDS), nb_seeders); // Seeders
|
|
||||||
qlonglong nb_leechers = parts.at(PL_LEECHS).trimmed().toLongLong(&ok); |
|
||||||
if (!ok || nb_leechers < 0) |
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::LEECHS), -1); // Leechers
|
|
||||||
else |
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::LEECHS), nb_leechers); // Leechers
|
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::ENGINE_URL), parts.at(PL_ENGINE_URL).trimmed()); // Engine URL
|
|
||||||
// Description Link
|
|
||||||
if (nb_fields == NB_PLUGIN_COLUMNS) |
|
||||||
cur_model->setData(cur_model->index(row, SearchSortModel::DESC_LINK), parts.at(PL_DESC_LINK).trimmed()); |
|
||||||
|
|
||||||
no_search_results = false; |
|
||||||
++nb_search_results; |
|
||||||
// Enable clear & download buttons
|
|
||||||
download_button->setEnabled(true); |
|
||||||
goToDescBtn->setEnabled(true); |
|
||||||
copyURLBtn->setEnabled(true); |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::closeTab(int index) |
|
||||||
{ |
|
||||||
// Search is run for active tab so if user decided to close it, then stop search
|
|
||||||
if (!activeSearchTab.isNull() && index == tabWidget->indexOf(activeSearchTab)) { |
|
||||||
qDebug("Closed active search Tab"); |
|
||||||
if (searchProcess->state() != QProcess::NotRunning) { |
|
||||||
#ifdef Q_OS_WIN |
|
||||||
searchProcess->kill(); |
|
||||||
#else |
|
||||||
searchProcess->terminate(); |
|
||||||
#endif |
|
||||||
searchProcess->waitForFinished(1000); |
|
||||||
} |
|
||||||
if (searchTimeout->isActive()) |
|
||||||
searchTimeout->stop(); |
|
||||||
search_stopped = true; |
|
||||||
activeSearchTab = 0; |
|
||||||
} |
|
||||||
delete all_tab.takeAt(index); |
|
||||||
if (!all_tab.size()) { |
|
||||||
download_button->setEnabled(false); |
|
||||||
goToDescBtn->setEnabled(false); |
|
||||||
search_status->setText(tr("Stopped")); |
|
||||||
copyURLBtn->setEnabled(false); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Download selected items in search results list
|
|
||||||
void SearchEngine::on_download_button_clicked() |
|
||||||
{ |
|
||||||
//QModelIndexList selectedIndexes = currentSearchTab->getCurrentTreeView()->selectionModel()->selectedIndexes();
|
|
||||||
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); |
|
||||||
foreach (const QModelIndex &index, selectedIndexes) { |
|
||||||
if (index.column() == SearchSortModel::NAME) { |
|
||||||
// Get Item url
|
|
||||||
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); |
|
||||||
QString torrent_url = model->data(model->index(index.row(), URL_COLUMN)).toString(); |
|
||||||
QString engine_url = model->data(model->index(index.row(), ENGINE_URL_COLUMN)).toString(); |
|
||||||
downloadTorrent(engine_url, torrent_url); |
|
||||||
all_tab.at(tabWidget->currentIndex())->setRowColor(index.row(), "blue"); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::on_goToDescBtn_clicked() |
|
||||||
{ |
|
||||||
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); |
|
||||||
foreach (const QModelIndex &index, selectedIndexes) { |
|
||||||
if (index.column() == SearchSortModel::NAME) { |
|
||||||
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); |
|
||||||
const QString desc_url = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString(); |
|
||||||
if (!desc_url.isEmpty()) |
|
||||||
QDesktopServices::openUrl(QUrl::fromEncoded(desc_url.toUtf8())); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
void SearchEngine::on_copyURLBtn_clicked() |
|
||||||
{ |
|
||||||
QStringList urls; |
|
||||||
QModelIndexList selectedIndexes = all_tab.at(tabWidget->currentIndex())->getCurrentTreeView()->selectionModel()->selectedIndexes(); |
|
||||||
foreach (const QModelIndex &index, selectedIndexes) { |
|
||||||
if (index.column() == SearchSortModel::NAME) { |
|
||||||
QSortFilterProxyModel* model = all_tab.at(tabWidget->currentIndex())->getCurrentSearchListProxy(); |
|
||||||
const QString descUrl = model->data(model->index(index.row(), SearchSortModel::DESC_LINK)).toString(); |
|
||||||
if (!descUrl.isEmpty()) |
|
||||||
urls << descUrl.toUtf8(); |
|
||||||
} |
|
||||||
} |
|
||||||
if (!urls.empty()) { |
|
||||||
QClipboard *clipboard = QApplication::clipboard(); |
|
||||||
clipboard->setText(urls.join("\n")); |
|
||||||
} |
|
||||||
} |
|
@ -1,133 +0,0 @@ |
|||||||
/*
|
|
||||||
* Bittorrent Client using Qt4 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 |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef SEARCH_H |
|
||||||
#define SEARCH_H |
|
||||||
|
|
||||||
#include <QProcess> |
|
||||||
#include <QList> |
|
||||||
#include <QPair> |
|
||||||
#include <QPointer> |
|
||||||
#include <QStringListModel> |
|
||||||
#include "ui_search.h" |
|
||||||
#include "engineselectdlg.h" |
|
||||||
#include "searchtab.h" |
|
||||||
#include "supportedengines.h" |
|
||||||
|
|
||||||
class SearchEngine; |
|
||||||
class MainWindow; |
|
||||||
class LineEdit; |
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE |
|
||||||
class QTimer; |
|
||||||
QT_END_NAMESPACE |
|
||||||
|
|
||||||
class SearchEngine : public QWidget, public Ui::search_engine{ |
|
||||||
Q_OBJECT |
|
||||||
Q_DISABLE_COPY(SearchEngine) |
|
||||||
|
|
||||||
private: |
|
||||||
enum PluginColumn { PL_DL_LINK, PL_NAME, PL_SIZE, PL_SEEDS, PL_LEECHS, PL_ENGINE_URL, PL_DESC_LINK, NB_PLUGIN_COLUMNS }; |
|
||||||
|
|
||||||
public: |
|
||||||
SearchEngine(MainWindow *mp_mainWindow); |
|
||||||
~SearchEngine(); |
|
||||||
QString selectedCategory() const; |
|
||||||
QString selectedEngine() const; |
|
||||||
|
|
||||||
static qreal getPluginVersion(QString filePath) { |
|
||||||
QFile plugin(filePath); |
|
||||||
if (!plugin.exists()) { |
|
||||||
qDebug("%s plugin does not exist, returning 0.0", qPrintable(filePath)); |
|
||||||
return 0.0; |
|
||||||
} |
|
||||||
if (!plugin.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
||||||
return 0.0; |
|
||||||
} |
|
||||||
qreal version = 0.0; |
|
||||||
while (!plugin.atEnd()) { |
|
||||||
QByteArray line = plugin.readLine(); |
|
||||||
if (line.startsWith("#VERSION: ")) { |
|
||||||
line = line.split(' ').last().trimmed(); |
|
||||||
version = line.toFloat(); |
|
||||||
qDebug("plugin %s version: %.2f", qPrintable(filePath), version); |
|
||||||
break; |
|
||||||
} |
|
||||||
} |
|
||||||
return version; |
|
||||||
} |
|
||||||
|
|
||||||
public slots: |
|
||||||
void on_download_button_clicked(); |
|
||||||
void downloadTorrent(QString engine_url, QString torrent_url); |
|
||||||
void giveFocusToSearchInput(); |
|
||||||
|
|
||||||
protected slots: |
|
||||||
// Search slots
|
|
||||||
void tab_changed(int);//to prevent the use of the download button when the tab is empty
|
|
||||||
void on_search_button_clicked(); |
|
||||||
void closeTab(int index); |
|
||||||
void appendSearchResult(const QString &line); |
|
||||||
void searchFinished(int exitcode,QProcess::ExitStatus); |
|
||||||
void readSearchOutput(); |
|
||||||
void searchStarted(); |
|
||||||
void updateNova(); |
|
||||||
void selectMultipleBox(const QString &text); |
|
||||||
void on_enginesButton_clicked(); |
|
||||||
void saveResultsColumnsWidth(); |
|
||||||
void downloadFinished(int exitcode, QProcess::ExitStatus); |
|
||||||
void fillCatCombobox(); |
|
||||||
void fillEngineComboBox(); |
|
||||||
void searchTextEdited(QString); |
|
||||||
|
|
||||||
private slots: |
|
||||||
void on_goToDescBtn_clicked(); |
|
||||||
void on_copyURLBtn_clicked(); |
|
||||||
|
|
||||||
private: |
|
||||||
// Search related
|
|
||||||
LineEdit* search_pattern; |
|
||||||
QProcess *searchProcess; |
|
||||||
QList<QProcess*> downloaders; |
|
||||||
bool search_stopped; |
|
||||||
bool no_search_results; |
|
||||||
QByteArray search_result_line_truncated; |
|
||||||
unsigned long nb_search_results; |
|
||||||
SupportedEngines *supported_engines; |
|
||||||
QTimer *searchTimeout; |
|
||||||
QPointer<SearchTab> currentSearchTab; // Selected tab
|
|
||||||
QPointer<SearchTab> activeSearchTab; // Tab with running search
|
|
||||||
QList<QPointer<SearchTab> > all_tab; // To store all tabs
|
|
||||||
const SearchCategories full_cat_names; |
|
||||||
MainWindow *mp_mainWindow; |
|
||||||
bool newQueryString; |
|
||||||
}; |
|
||||||
|
|
||||||
#endif |
|
@ -1,19 +0,0 @@ |
|||||||
INCLUDEPATH += $$PWD |
|
||||||
|
|
||||||
FORMS += $$PWD/search.ui \ |
|
||||||
$$PWD/engineselect.ui \ |
|
||||||
$$PWD/pluginsource.ui |
|
||||||
|
|
||||||
HEADERS += $$PWD/searchengine.h \ |
|
||||||
$$PWD/searchtab.h \ |
|
||||||
$$PWD/engineselectdlg.h \ |
|
||||||
$$PWD/pluginsource.h \ |
|
||||||
$$PWD/searchlistdelegate.h \ |
|
||||||
$$PWD/supportedengines.h \ |
|
||||||
$$PWD/searchsortmodel.h |
|
||||||
|
|
||||||
SOURCES += $$PWD/searchengine.cpp \ |
|
||||||
$$PWD/searchtab.cpp \ |
|
||||||
$$PWD/engineselectdlg.cpp |
|
||||||
|
|
||||||
RESOURCES += $$PWD/search.qrc |
|
@ -1,35 +0,0 @@ |
|||||||
#ifndef SEARCHSORTMODEL_H |
|
||||||
#define SEARCHSORTMODEL_H |
|
||||||
|
|
||||||
#include <QSortFilterProxyModel> |
|
||||||
#include "base/utils/string.h" |
|
||||||
|
|
||||||
class SearchSortModel : public QSortFilterProxyModel { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
enum SearchColumn { NAME, SIZE, SEEDS, LEECHS, ENGINE_URL, DL_LINK, DESC_LINK, NB_SEARCH_COLUMNS }; |
|
||||||
|
|
||||||
SearchSortModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {} |
|
||||||
|
|
||||||
protected: |
|
||||||
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
|
|
@ -1,165 +0,0 @@ |
|||||||
/*
|
|
||||||
* Bittorrent Client using Qt4 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 <QDir> |
|
||||||
#include <QTreeView> |
|
||||||
#include <QStandardItemModel> |
|
||||||
#include <QHeaderView> |
|
||||||
#include <QSortFilterProxyModel> |
|
||||||
#ifdef QBT_USES_QT5 |
|
||||||
#include <QTableView> |
|
||||||
#endif |
|
||||||
|
|
||||||
#include "searchtab.h" |
|
||||||
#include "searchlistdelegate.h" |
|
||||||
#include "base/utils/misc.h" |
|
||||||
#include "searchengine.h" |
|
||||||
#include "base/preferences.h" |
|
||||||
|
|
||||||
SearchTab::SearchTab(SearchEngine *parent) : QWidget(), parent(parent) |
|
||||||
{ |
|
||||||
box = new QVBoxLayout(); |
|
||||||
results_lbl = new QLabel(); |
|
||||||
resultsBrowser = new QTreeView(); |
|
||||||
#ifdef QBT_USES_QT5 |
|
||||||
// This hack fixes reordering of first column with Qt5.
|
|
||||||
// https://github.com/qtproject/qtbase/commit/e0fc088c0c8bc61dbcaf5928b24986cd61a22777
|
|
||||||
QTableView unused; |
|
||||||
unused.setVerticalHeader(resultsBrowser->header()); |
|
||||||
resultsBrowser->header()->setParent(resultsBrowser); |
|
||||||
unused.setVerticalHeader(new QHeaderView(Qt::Horizontal)); |
|
||||||
#endif |
|
||||||
resultsBrowser->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
||||||
box->addWidget(results_lbl); |
|
||||||
box->addWidget(resultsBrowser); |
|
||||||
|
|
||||||
setLayout(box); |
|
||||||
// Set Search results list model
|
|
||||||
SearchListModel = new QStandardItemModel(0, SearchSortModel::NB_SEARCH_COLUMNS); |
|
||||||
SearchListModel->setHeaderData(SearchSortModel::NAME, Qt::Horizontal, tr("Name", "i.e: file name")); |
|
||||||
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")); |
|
||||||
SearchListModel->setHeaderData(SearchSortModel::LEECHS, Qt::Horizontal, tr("Leechers", "i.e: Number of partial sources")); |
|
||||||
SearchListModel->setHeaderData(SearchSortModel::ENGINE_URL, Qt::Horizontal, tr("Search engine")); |
|
||||||
|
|
||||||
proxyModel = new SearchSortModel(); |
|
||||||
proxyModel->setDynamicSortFilter(true); |
|
||||||
proxyModel->setSourceModel(SearchListModel); |
|
||||||
resultsBrowser->setModel(proxyModel); |
|
||||||
|
|
||||||
SearchDelegate = new SearchListDelegate(); |
|
||||||
resultsBrowser->setItemDelegate(SearchDelegate); |
|
||||||
|
|
||||||
resultsBrowser->hideColumn(SearchSortModel::DL_LINK); // Hide url column
|
|
||||||
resultsBrowser->hideColumn(SearchSortModel::DESC_LINK); |
|
||||||
|
|
||||||
resultsBrowser->setRootIsDecorated(false); |
|
||||||
resultsBrowser->setAllColumnsShowFocus(true); |
|
||||||
resultsBrowser->setSortingEnabled(true); |
|
||||||
|
|
||||||
// Connect signals to slots (search part)
|
|
||||||
connect(resultsBrowser, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(downloadSelectedItem(const QModelIndex&))); |
|
||||||
|
|
||||||
// Load last columns width for search results list
|
|
||||||
if (!loadColWidthResultsList()) { |
|
||||||
resultsBrowser->header()->resizeSection(0, 275); |
|
||||||
} |
|
||||||
|
|
||||||
// Sort by Seeds
|
|
||||||
resultsBrowser->sortByColumn(SearchSortModel::SEEDS, Qt::DescendingOrder); |
|
||||||
} |
|
||||||
|
|
||||||
void SearchTab::downloadSelectedItem(const QModelIndex& index) { |
|
||||||
QString engine_url = proxyModel->data(proxyModel->index(index.row(), SearchSortModel::ENGINE_URL)).toString(); |
|
||||||
QString torrent_url = proxyModel->data(proxyModel->index(index.row(), SearchSortModel::DL_LINK)).toString(); |
|
||||||
setRowColor(index.row(), "blue"); |
|
||||||
parent->downloadTorrent(engine_url, torrent_url); |
|
||||||
} |
|
||||||
|
|
||||||
SearchTab::~SearchTab() { |
|
||||||
delete box; |
|
||||||
delete results_lbl; |
|
||||||
delete resultsBrowser; |
|
||||||
delete SearchListModel; |
|
||||||
delete proxyModel; |
|
||||||
delete SearchDelegate; |
|
||||||
} |
|
||||||
|
|
||||||
QHeaderView* SearchTab::header() const { |
|
||||||
return resultsBrowser->header(); |
|
||||||
} |
|
||||||
|
|
||||||
bool SearchTab::loadColWidthResultsList() { |
|
||||||
QString line = Preferences::instance()->getSearchColsWidth(); |
|
||||||
if (line.isEmpty()) |
|
||||||
return false; |
|
||||||
|
|
||||||
QStringList width_list = line.split(' '); |
|
||||||
if (width_list.size() > SearchListModel->columnCount()) |
|
||||||
return false; |
|
||||||
|
|
||||||
unsigned int listSize = width_list.size(); |
|
||||||
for (unsigned int i=0; i<listSize; ++i) { |
|
||||||
resultsBrowser->header()->resizeSection(i, width_list.at(i).toInt()); |
|
||||||
} |
|
||||||
|
|
||||||
return true; |
|
||||||
} |
|
||||||
|
|
||||||
QLabel* SearchTab::getCurrentLabel() |
|
||||||
{ |
|
||||||
return results_lbl; |
|
||||||
} |
|
||||||
|
|
||||||
QTreeView* SearchTab::getCurrentTreeView() |
|
||||||
{ |
|
||||||
return resultsBrowser; |
|
||||||
} |
|
||||||
|
|
||||||
QSortFilterProxyModel* SearchTab::getCurrentSearchListProxy() const |
|
||||||
{ |
|
||||||
return proxyModel; |
|
||||||
} |
|
||||||
|
|
||||||
QStandardItemModel* SearchTab::getCurrentSearchListModel() const |
|
||||||
{ |
|
||||||
return SearchListModel; |
|
||||||
} |
|
||||||
|
|
||||||
// Set the color of a row in data model
|
|
||||||
void SearchTab::setRowColor(int row, QString color) { |
|
||||||
proxyModel->setDynamicSortFilter(false); |
|
||||||
for (int i=0; i<proxyModel->columnCount(); ++i) { |
|
||||||
proxyModel->setData(proxyModel->index(row, i), QVariant(QColor(color)), Qt::ForegroundRole); |
|
||||||
} |
|
||||||
proxyModel->setDynamicSortFilter(true); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
@ -1,186 +0,0 @@ |
|||||||
/*
|
|
||||||
* Bittorrent Client using Qt4 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 |
|
||||||
*/ |
|
||||||
|
|
||||||
#ifndef SEARCHENGINES_H |
|
||||||
#define SEARCHENGINES_H |
|
||||||
|
|
||||||
#include <QHash> |
|
||||||
#include <QStringList> |
|
||||||
#include <QDomDocument> |
|
||||||
#include <QDomNode> |
|
||||||
#include <QDomElement> |
|
||||||
#include <QProcess> |
|
||||||
#include <QDir> |
|
||||||
#include <QApplication> |
|
||||||
#include <QDebug> |
|
||||||
|
|
||||||
#include "base/utils/fs.h" |
|
||||||
#include "base/utils/misc.h" |
|
||||||
#include "base/preferences.h" |
|
||||||
|
|
||||||
class SearchCategories: public QObject, public QHash<QString, QString> { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
public: |
|
||||||
SearchCategories() { |
|
||||||
(*this)["all"] = tr("All categories"); |
|
||||||
(*this)["movies"] = tr("Movies"); |
|
||||||
(*this)["tv"] = tr("TV shows"); |
|
||||||
(*this)["music"] = tr("Music"); |
|
||||||
(*this)["games"] = tr("Games"); |
|
||||||
(*this)["anime"] = tr("Anime"); |
|
||||||
(*this)["software"] = tr("Software"); |
|
||||||
(*this)["pictures"] = tr("Pictures"); |
|
||||||
(*this)["books"] = tr("Books"); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
class SupportedEngine { |
|
||||||
private: |
|
||||||
QString name; |
|
||||||
QString full_name; |
|
||||||
QString url; |
|
||||||
QStringList supported_categories; |
|
||||||
bool enabled; |
|
||||||
|
|
||||||
public: |
|
||||||
SupportedEngine(QDomElement engine_elem) { |
|
||||||
name = engine_elem.tagName(); |
|
||||||
full_name = engine_elem.elementsByTagName("name").at(0).toElement().text(); |
|
||||||
url = engine_elem.elementsByTagName("url").at(0).toElement().text(); |
|
||||||
supported_categories = engine_elem.elementsByTagName("categories").at(0).toElement().text().split(" "); |
|
||||||
QStringList disabled_engines = Preferences::instance()->getSearchEngDisabled(); |
|
||||||
enabled = !disabled_engines.contains(name); |
|
||||||
} |
|
||||||
|
|
||||||
QString getName() const { return name; } |
|
||||||
QString getUrl() const { return url; } |
|
||||||
QString getFullName() const { return full_name; } |
|
||||||
QStringList getSupportedCategories() const { return supported_categories; } |
|
||||||
bool isEnabled() const { return enabled; } |
|
||||||
void setEnabled(bool _enabled) { |
|
||||||
enabled = _enabled; |
|
||||||
// Save to Hard disk
|
|
||||||
Preferences* const pref = Preferences::instance(); |
|
||||||
QStringList disabled_engines = pref->getSearchEngDisabled(); |
|
||||||
if (enabled) { |
|
||||||
disabled_engines.removeAll(name); |
|
||||||
} else { |
|
||||||
disabled_engines.append(name); |
|
||||||
} |
|
||||||
pref->setSearchEngDisabled(disabled_engines); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
class SupportedEngines: public QObject, public QHash<QString, SupportedEngine*> { |
|
||||||
Q_OBJECT |
|
||||||
|
|
||||||
signals: |
|
||||||
void newSupportedEngine(QString name); |
|
||||||
|
|
||||||
public: |
|
||||||
SupportedEngines() { |
|
||||||
update(); |
|
||||||
} |
|
||||||
|
|
||||||
~SupportedEngines() { |
|
||||||
qDeleteAll(this->values()); |
|
||||||
} |
|
||||||
|
|
||||||
QStringList enginesAll() const { |
|
||||||
QStringList engines; |
|
||||||
foreach (const SupportedEngine *engine, values()) engines << engine->getName(); |
|
||||||
return engines; |
|
||||||
} |
|
||||||
|
|
||||||
QStringList enginesEnabled() const { |
|
||||||
QStringList engines; |
|
||||||
foreach (const SupportedEngine *engine, values()) { |
|
||||||
if (engine->isEnabled()) |
|
||||||
engines << engine->getName(); |
|
||||||
} |
|
||||||
return engines; |
|
||||||
} |
|
||||||
|
|
||||||
QStringList supportedCategories() const { |
|
||||||
QStringList supported_cat; |
|
||||||
foreach (const SupportedEngine *engine, values()) { |
|
||||||
if (engine->isEnabled()) { |
|
||||||
const QStringList &s = engine->getSupportedCategories(); |
|
||||||
foreach (QString cat, s) { |
|
||||||
cat = cat.trimmed(); |
|
||||||
if (!cat.isEmpty() && !supported_cat.contains(cat)) |
|
||||||
supported_cat << cat; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
return supported_cat; |
|
||||||
} |
|
||||||
|
|
||||||
public slots: |
|
||||||
void update() { |
|
||||||
QProcess nova; |
|
||||||
nova.setEnvironment(QProcess::systemEnvironment()); |
|
||||||
QStringList params; |
|
||||||
params << Utils::Fs::toNativePath(Utils::Fs::searchEngineLocation()+"/nova2.py"); |
|
||||||
params << "--capabilities"; |
|
||||||
nova.start(Utils::Misc::pythonExecutable(), params, QIODevice::ReadOnly); |
|
||||||
nova.waitForStarted(); |
|
||||||
nova.waitForFinished(); |
|
||||||
QString capabilities = QString(nova.readAll()); |
|
||||||
QDomDocument xml_doc; |
|
||||||
if (!xml_doc.setContent(capabilities)) { |
|
||||||
qWarning() << "Could not parse Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data(); |
|
||||||
qWarning() << "Error: " << nova.readAllStandardError().constData(); |
|
||||||
return; |
|
||||||
} |
|
||||||
QDomElement root = xml_doc.documentElement(); |
|
||||||
if (root.tagName() != "capabilities") { |
|
||||||
qWarning() << "Invalid XML file for Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data(); |
|
||||||
return; |
|
||||||
} |
|
||||||
for (QDomNode engine_node = root.firstChild(); !engine_node.isNull(); engine_node = engine_node.nextSibling()) { |
|
||||||
QDomElement engine_elem = engine_node.toElement(); |
|
||||||
if (!engine_elem.isNull()) { |
|
||||||
SupportedEngine *s = new SupportedEngine(engine_elem); |
|
||||||
if (this->contains(s->getName())) { |
|
||||||
// Already in the list
|
|
||||||
delete s; |
|
||||||
} else { |
|
||||||
qDebug("Supported search engine: %s", s->getFullName().toLocal8Bit().data()); |
|
||||||
(*this)[s->getName()] = s; |
|
||||||
emit newSupportedEngine(s->getName()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
#endif // SEARCHENGINES_H
|
|
Loading…
Reference in new issue