Browse Source

Update SearchEngine classes

Guaranteed to work with qt-style separators internally; guaranteed to call native OS environment using native separators
adaptive-webui-19844
Nick Tiskov 11 years ago
parent
commit
6346716df6
  1. 17
      src/searchengine/engineselectdlg.cpp
  2. 12
      src/searchengine/searchengine.cpp
  3. 2
      src/searchengine/supportedengines.h

17
src/searchengine/engineselectdlg.cpp

@ -158,7 +158,7 @@ void engineSelectDlg::on_actionUninstall_triggered() {
}else { }else {
// Proceed with uninstall // Proceed with uninstall
// remove it from hard drive // remove it from hard drive
QDir enginesFolder(fsutils::searchEngineLocation()+QDir::separator()+"engines"); QDir enginesFolder(fsutils::searchEngineLocation() + "/engines");
QStringList filters; QStringList filters;
filters << id+".*"; filters << id+".*";
QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted); QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted);
@ -224,7 +224,7 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id) {
} }
bool engineSelectDlg::isUpdateNeeded(QString plugin_name, qreal new_version) const { bool engineSelectDlg::isUpdateNeeded(QString plugin_name, qreal new_version) const {
qreal old_version = SearchEngine::getPluginVersion(fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py"); qreal old_version = SearchEngine::getPluginVersion(fsutils::searchEngineLocation() + "/engines/" + plugin_name + ".py");
qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version); qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version);
return (new_version > old_version); return (new_version > old_version);
} }
@ -239,7 +239,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
return; return;
} }
// Process with install // Process with install
QString dest_path = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py"; QString dest_path = fsutils::searchEngineLocation() + "/engines/" + plugin_name + ".py";
bool update = false; bool update = false;
if (QFile::exists(dest_path)) { if (QFile::exists(dest_path)) {
// Backup in case install fails // Backup in case install fails
@ -304,12 +304,12 @@ void engineSelectDlg::addNewEngine(QString engine_name) {
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red"); setRowColor(pluginsTree->indexOfTopLevelItem(item), "red");
} }
// Handle icon // Handle icon
QString iconPath = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".png"; QString iconPath = fsutils::searchEngineLocation() + "/engines/" + engine->getName() + ".png";
if (QFile::exists(iconPath)) { if (QFile::exists(iconPath)) {
// Good, we already have the icon // Good, we already have the icon
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} else { } else {
iconPath = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".ico"; iconPath = fsutils::searchEngineLocation() + "/engines/" + engine->getName() + ".ico";
if (QFile::exists(iconPath)) { // ICO support if (QFile::exists(iconPath)) { // ICO support
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} else { } else {
@ -355,7 +355,7 @@ void engineSelectDlg::askForLocalPlugin() {
QString path; QString path;
foreach (path, pathsList) { foreach (path, pathsList) {
if (path.endsWith(".py", Qt::CaseInsensitive)) { if (path.endsWith(".py", Qt::CaseInsensitive)) {
QString plugin_name = path.split(QDir::separator()).last(); QString plugin_name = path.split("/").last();
plugin_name.replace(".py", "", Qt::CaseInsensitive); plugin_name.replace(".py", "", Qt::CaseInsensitive);
installPlugin(path, plugin_name); installPlugin(path, plugin_name);
} }
@ -409,6 +409,7 @@ bool engineSelectDlg::parseVersionsFile(QString versions_file) {
} }
void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
filePath = fsutils::fromNativePath(filePath);
setCursor(QCursor(Qt::ArrowCursor)); setCursor(QCursor(Qt::ArrowCursor));
qDebug("engineSelectDlg received %s", qPrintable(url)); qDebug("engineSelectDlg received %s", qPrintable(url));
if (url.endsWith("favicon.ico", Qt::CaseInsensitive)) { if (url.endsWith("favicon.ico", Qt::CaseInsensitive)) {
@ -423,9 +424,9 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
QFile icon(filePath); QFile icon(filePath);
icon.open(QIODevice::ReadOnly); icon.open(QIODevice::ReadOnly);
if (ICOHandler::canRead(&icon)) if (ICOHandler::canRead(&icon))
iconPath = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+id+".ico"; iconPath = fsutils::searchEngineLocation() + "/engines/" + id + ".ico";
else else
iconPath = fsutils::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+id+".png"; iconPath = fsutils::searchEngineLocation() + "/engines/" + id + ".png";
QFile::copy(filePath, iconPath); QFile::copy(filePath, iconPath);
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath))); item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} }

12
src/searchengine/searchengine.cpp

@ -126,7 +126,7 @@ bool SearchEngine::addPythonPathToEnv() {
} }
path_envar = python_path+";"+path_envar; path_envar = python_path+";"+path_envar;
qDebug("New PATH envvar is: %s", qPrintable(path_envar)); qDebug("New PATH envvar is: %s", qPrintable(path_envar));
qputenv("PATH", path_envar.toLocal8Bit()); qputenv("PATH", fsutils::toNativePath(path_envar).toLocal8Bit());
return true; return true;
} }
return false; return false;
@ -148,7 +148,7 @@ void SearchEngine::pythonDownloadSuccess(QString url, QString file_path) {
QProcess installer; QProcess installer;
qDebug("Launching Python installer in passive mode..."); qDebug("Launching Python installer in passive mode...");
installer.start("msiexec.exe /passive /i "+file_path.replace("/", "\\")+".msi"); installer.start("msiexec.exe /passive /i " + fsutils::toNativePath(file_path) + ".msi");
// Wait for setup to complete // Wait for setup to complete
installer.waitForFinished(); installer.waitForFinished();
@ -275,7 +275,7 @@ void SearchEngine::on_search_button_clicked() {
// Getting checked search engines // Getting checked search engines
QStringList params; QStringList params;
search_stopped = false; search_stopped = false;
params << fsutils::searchEngineLocation()+QDir::separator()+"nova2.py"; params << fsutils::toNativePath(fsutils::searchEngineLocation() + "/nova2.py");
params << supported_engines->enginesEnabled().join(","); params << supported_engines->enginesEnabled().join(",");
qDebug("Search with category: %s", qPrintable(selectedCategory())); qDebug("Search with category: %s", qPrintable(selectedCategory()));
params << selectedCategory(); params << selectedCategory();
@ -343,7 +343,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) {
connect(downloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(downloadFinished(int,QProcess::ExitStatus))); connect(downloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(downloadFinished(int,QProcess::ExitStatus)));
downloaders << downloadProcess; downloaders << downloadProcess;
QStringList params; QStringList params;
params << fsutils::searchEngineLocation()+QDir::separator()+"nova2dl.py"; params << fsutils::toNativePath(fsutils::searchEngineLocation() + "/nova2dl.py");
params << engine_url; params << engine_url;
params << torrent_url; params << torrent_url;
// Launch search // Launch search
@ -396,7 +396,7 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) {
static void removePythonScriptIfExists(const QString& script_path) static void removePythonScriptIfExists(const QString& script_path)
{ {
fsutils::forceRemove(script_path); fsutils::forceRemove(script_path);
fsutils::forceRemove(script_path+"c"); fsutils::forceRemove(script_path + "c");
} }
// Update nova.py search plugin if necessary // Update nova.py search plugin if necessary
@ -411,7 +411,7 @@ void SearchEngine::updateNova() {
if (!search_dir.exists("engines")) { if (!search_dir.exists("engines")) {
search_dir.mkdir("engines"); search_dir.mkdir("engines");
} }
QFile package_file2(search_dir.absolutePath().replace("\\", "/")+"/engines/__init__.py"); QFile package_file2(search_dir.absolutePath() + "/engines/__init__.py");
package_file2.open(QIODevice::WriteOnly | QIODevice::Text); package_file2.open(QIODevice::WriteOnly | QIODevice::Text);
package_file2.close(); package_file2.close();
// Copy search plugin files (if necessary) // Copy search plugin files (if necessary)

2
src/searchengine/supportedengines.h

@ -144,7 +144,7 @@ public slots:
QProcess nova; QProcess nova;
nova.setEnvironment(QProcess::systemEnvironment()); nova.setEnvironment(QProcess::systemEnvironment());
QStringList params; QStringList params;
params << fsutils::searchEngineLocation()+QDir::separator()+"nova2.py"; params << fsutils::toNativePath(fsutils::searchEngineLocation()+"/nova2.py");
params << "--capabilities"; params << "--capabilities";
nova.start("python", params, QIODevice::ReadOnly); nova.start("python", params, QIODevice::ReadOnly);
nova.waitForStarted(); nova.waitForStarted();

Loading…
Cancel
Save