mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-05 07:02:31 -06:00
Move utilities to core/utils folder.
Also move the names to Utils namespace.
This commit is contained in:
@@ -31,8 +31,8 @@
|
||||
#include "engineselectdlg.h"
|
||||
#include "core/net/downloadmanager.h"
|
||||
#include "core/net/downloadhandler.h"
|
||||
#include "core/fs_utils.h"
|
||||
#include "core/misc.h"
|
||||
#include "core/utils/fs.h"
|
||||
#include "core/utils/misc.h"
|
||||
#include "ico.h"
|
||||
#include "searchengine.h"
|
||||
#include "pluginsource.h"
|
||||
@@ -48,7 +48,7 @@
|
||||
#include <QMimeData>
|
||||
|
||||
enum EngineColumns {ENGINE_NAME, ENGINE_URL, ENGINE_STATE, ENGINE_ID};
|
||||
const QString UPDATE_URL = QString("https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/") + (misc::pythonVersion() >= 3 ? "nova3" : "nova") + "/engines/";
|
||||
const QString UPDATE_URL = QString("https://raw.github.com/qbittorrent/qBittorrent/master/src/searchengine/") + (Utils::Misc::pythonVersion() >= 3 ? "nova3" : "nova") + "/engines/";
|
||||
|
||||
engineSelectDlg::engineSelectDlg(QWidget *parent, SupportedEngines *supported_engines) : QDialog(parent), supported_engines(supported_engines) {
|
||||
setupUi(this);
|
||||
@@ -76,7 +76,7 @@ void engineSelectDlg::dropEvent(QDropEvent *event) {
|
||||
QStringList files = event->mimeData()->text().split(QString::fromUtf8("\n"));
|
||||
foreach (QString file, files) {
|
||||
qDebug("dropped %s", qPrintable(file));
|
||||
if (misc::isUrl(file)) {
|
||||
if (Utils::Misc::isUrl(file)) {
|
||||
setCursor(QCursor(Qt::WaitCursor));
|
||||
downloadFromUrl(file);
|
||||
continue;
|
||||
@@ -84,7 +84,7 @@ void engineSelectDlg::dropEvent(QDropEvent *event) {
|
||||
if (file.endsWith(".py", Qt::CaseInsensitive)) {
|
||||
if (file.startsWith("file:", Qt::CaseInsensitive))
|
||||
file = QUrl(file).toLocalFile();
|
||||
QString plugin_name = fsutils::fileName(file);
|
||||
QString plugin_name = Utils::Fs::fileName(file);
|
||||
plugin_name.chop(3); // Remove extension
|
||||
installPlugin(file, plugin_name);
|
||||
}
|
||||
@@ -155,7 +155,7 @@ void engineSelectDlg::on_actionUninstall_triggered() {
|
||||
}else {
|
||||
// Proceed with uninstall
|
||||
// remove it from hard drive
|
||||
QDir enginesFolder(fsutils::searchEngineLocation() + "/engines");
|
||||
QDir enginesFolder(Utils::Fs::searchEngineLocation() + "/engines");
|
||||
QStringList filters;
|
||||
filters << id+".*";
|
||||
QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
@@ -221,7 +221,7 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id) {
|
||||
}
|
||||
|
||||
bool engineSelectDlg::isUpdateNeeded(QString plugin_name, qreal new_version) const {
|
||||
qreal old_version = SearchEngine::getPluginVersion(fsutils::searchEngineLocation() + "/engines/" + plugin_name + ".py");
|
||||
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);
|
||||
}
|
||||
@@ -236,13 +236,13 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
|
||||
return;
|
||||
}
|
||||
// Process with install
|
||||
QString dest_path = fsutils::searchEngineLocation() + "/engines/" + plugin_name + ".py";
|
||||
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");
|
||||
fsutils::forceRemove(dest_path);
|
||||
fsutils::forceRemove(dest_path+"c");
|
||||
Utils::Fs::forceRemove(dest_path);
|
||||
Utils::Fs::forceRemove(dest_path+"c");
|
||||
update = true;
|
||||
}
|
||||
// Copy the plugin
|
||||
@@ -253,22 +253,22 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
|
||||
if (!supported_engines->contains(plugin_name)) {
|
||||
if (update) {
|
||||
// Remove broken file
|
||||
fsutils::forceRemove(dest_path);
|
||||
Utils::Fs::forceRemove(dest_path);
|
||||
// restore backup
|
||||
QFile::copy(dest_path+".bak", dest_path);
|
||||
fsutils::forceRemove(dest_path+".bak");
|
||||
Utils::Fs::forceRemove(dest_path+".bak");
|
||||
QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), 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
|
||||
fsutils::forceRemove(dest_path);
|
||||
Utils::Fs::forceRemove(dest_path);
|
||||
QMessageBox::warning(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), 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
|
||||
if (update) {
|
||||
fsutils::forceRemove(dest_path+".bak");
|
||||
Utils::Fs::forceRemove(dest_path+".bak");
|
||||
}
|
||||
if (update) {
|
||||
QMessageBox::information(this, tr("Search plugin install")+" -- "+tr("qBittorrent"), tr("%1 search engine plugin was successfully updated.", "%1 is the name of the search engine").arg(plugin_name));
|
||||
@@ -301,12 +301,12 @@ void engineSelectDlg::addNewEngine(QString engine_name) {
|
||||
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red");
|
||||
}
|
||||
// Handle icon
|
||||
QString iconPath = fsutils::searchEngineLocation() + "/engines/" + engine->getName() + ".png";
|
||||
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 = fsutils::searchEngineLocation() + "/engines/" + engine->getName() + ".ico";
|
||||
iconPath = Utils::Fs::searchEngineLocation() + "/engines/" + engine->getName() + ".ico";
|
||||
if (QFile::exists(iconPath)) { // ICO support
|
||||
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
|
||||
} else {
|
||||
@@ -398,7 +398,7 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) {
|
||||
// Close file
|
||||
versions.close();
|
||||
// Clean up tmp file
|
||||
fsutils::forceRemove(versions_file);
|
||||
Utils::Fs::forceRemove(versions_file);
|
||||
if (file_correct && !updated) {
|
||||
QMessageBox::information(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("All your plugins are already up to date."));
|
||||
}
|
||||
@@ -413,7 +413,7 @@ void engineSelectDlg::downloadFromUrl(const QString &url)
|
||||
}
|
||||
|
||||
void engineSelectDlg::processDownloadedFile(const QString &url, QString filePath) {
|
||||
filePath = fsutils::fromNativePath(filePath);
|
||||
filePath = Utils::Fs::fromNativePath(filePath);
|
||||
setCursor(QCursor(Qt::ArrowCursor));
|
||||
qDebug("engineSelectDlg received %s", qPrintable(url));
|
||||
if (url.endsWith("favicon.ico", Qt::CaseInsensitive)) {
|
||||
@@ -428,29 +428,29 @@ void engineSelectDlg::processDownloadedFile(const QString &url, QString filePath
|
||||
QFile icon(filePath);
|
||||
icon.open(QIODevice::ReadOnly);
|
||||
if (ICOHandler::canRead(&icon))
|
||||
iconPath = fsutils::searchEngineLocation() + "/engines/" + id + ".ico";
|
||||
iconPath = Utils::Fs::searchEngineLocation() + "/engines/" + id + ".ico";
|
||||
else
|
||||
iconPath = fsutils::searchEngineLocation() + "/engines/" + id + ".png";
|
||||
iconPath = Utils::Fs::searchEngineLocation() + "/engines/" + id + ".png";
|
||||
QFile::copy(filePath, iconPath);
|
||||
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
|
||||
}
|
||||
}
|
||||
// Delete tmp file
|
||||
fsutils::forceRemove(filePath);
|
||||
Utils::Fs::forceRemove(filePath);
|
||||
return;
|
||||
}
|
||||
if (url.endsWith("versions.txt")) {
|
||||
if (!parseVersionsFile(filePath)) {
|
||||
QMessageBox::warning(this, tr("Search plugin update")+" -- "+tr("qBittorrent"), tr("Sorry, update server is temporarily unavailable."));
|
||||
}
|
||||
fsutils::forceRemove(filePath);
|
||||
Utils::Fs::forceRemove(filePath);
|
||||
return;
|
||||
}
|
||||
if (url.endsWith(".py", Qt::CaseInsensitive)) {
|
||||
QString plugin_name = fsutils::fileName(url);
|
||||
QString plugin_name = Utils::Fs::fileName(url);
|
||||
plugin_name.chop(3); // Remove extension
|
||||
installPlugin(filePath, plugin_name);
|
||||
fsutils::forceRemove(filePath);
|
||||
Utils::Fs::forceRemove(filePath);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user