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

12
src/searchengine/searchengine.cpp

@ -126,7 +126,7 @@ bool SearchEngine::addPythonPathToEnv() { @@ -126,7 +126,7 @@ bool SearchEngine::addPythonPathToEnv() {
}
path_envar = python_path+";"+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 false;
@ -148,7 +148,7 @@ void SearchEngine::pythonDownloadSuccess(QString url, QString file_path) { @@ -148,7 +148,7 @@ void SearchEngine::pythonDownloadSuccess(QString url, QString file_path) {
QProcess installer;
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
installer.waitForFinished();
@ -275,7 +275,7 @@ void SearchEngine::on_search_button_clicked() { @@ -275,7 +275,7 @@ void SearchEngine::on_search_button_clicked() {
// Getting checked search engines
QStringList params;
search_stopped = false;
params << fsutils::searchEngineLocation()+QDir::separator()+"nova2.py";
params << fsutils::toNativePath(fsutils::searchEngineLocation() + "/nova2.py");
params << supported_engines->enginesEnabled().join(",");
qDebug("Search with category: %s", qPrintable(selectedCategory()));
params << selectedCategory();
@ -343,7 +343,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) { @@ -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)));
downloaders << downloadProcess;
QStringList params;
params << fsutils::searchEngineLocation()+QDir::separator()+"nova2dl.py";
params << fsutils::toNativePath(fsutils::searchEngineLocation() + "/nova2dl.py");
params << engine_url;
params << torrent_url;
// Launch search
@ -396,7 +396,7 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) { @@ -396,7 +396,7 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) {
static void removePythonScriptIfExists(const QString& script_path)
{
fsutils::forceRemove(script_path);
fsutils::forceRemove(script_path+"c");
fsutils::forceRemove(script_path + "c");
}
// Update nova.py search plugin if necessary
@ -411,7 +411,7 @@ void SearchEngine::updateNova() { @@ -411,7 +411,7 @@ void SearchEngine::updateNova() {
if (!search_dir.exists("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.close();
// Copy search plugin files (if necessary)

2
src/searchengine/supportedengines.h

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

Loading…
Cancel
Save