mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 08:48:07 -06:00
Detect Python interpreter on Windows (the search engine is now working!)
This commit is contained in:
@@ -916,6 +916,18 @@ public:
|
|||||||
settings.setValue(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), resolve);
|
settings.setValue(QString::fromUtf8("Preferences/Connection/ResolvePeerHostNames"), resolve);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
static void setPythonPath(QString path) {
|
||||||
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
|
settings.setValue(QString::fromUtf8("Preferences/Win32/PythonPath"), path);
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString getPythonPath() {
|
||||||
|
QSettings settings("qBittorrent", "qBittorrent");
|
||||||
|
return settings.value(QString::fromUtf8("Preferences/Win32/PythonPath"), "").toString();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PREFERENCES_H
|
#endif // PREFERENCES_H
|
||||||
|
|||||||
@@ -42,11 +42,17 @@
|
|||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QSortFilterProxyModel>
|
#include <QSortFilterProxyModel>
|
||||||
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
#include <stdlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "searchengine.h"
|
#include "searchengine.h"
|
||||||
#include "bittorrent.h"
|
#include "bittorrent.h"
|
||||||
#include "downloadthread.h"
|
#include "downloadthread.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
#include "preferences.h"
|
||||||
#include "searchlistdelegate.h"
|
#include "searchlistdelegate.h"
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
|
||||||
@@ -72,13 +78,11 @@ SearchEngine::SearchEngine(GUI *parent, Bittorrent *BTSession) : QWidget(parent)
|
|||||||
// Boolean initialization
|
// Boolean initialization
|
||||||
search_stopped = false;
|
search_stopped = false;
|
||||||
// Creating Search Process
|
// Creating Search Process
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
checkForPythonExe();
|
||||||
|
#endif
|
||||||
searchProcess = new QProcess(this);
|
searchProcess = new QProcess(this);
|
||||||
QStringList env = QProcess::systemEnvironment();
|
QStringList env = QProcess::systemEnvironment();
|
||||||
#ifdef Q_WS_WIN
|
|
||||||
// add qBittorrent executable folder to PATH environment variable
|
|
||||||
qDebug("qBittorrent executable path: %s", qPrintable(qApp->applicationDirPath()));
|
|
||||||
env.replaceInStrings(QRegExp("^PATH=(.*)", Qt::CaseInsensitive), "PATH=\\1;"+qApp->applicationDirPath());
|
|
||||||
#endif
|
|
||||||
searchProcess->setEnvironment(env);
|
searchProcess->setEnvironment(env);
|
||||||
connect(searchProcess, SIGNAL(started()), this, SLOT(searchStarted()));
|
connect(searchProcess, SIGNAL(started()), this, SLOT(searchStarted()));
|
||||||
connect(searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput()));
|
connect(searchProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(readSearchOutput()));
|
||||||
@@ -106,6 +110,62 @@ void SearchEngine::fillCatCombobox() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
void SearchEngine::checkForPythonExe() {
|
||||||
|
QString python_path = Preferences::getPythonPath();
|
||||||
|
if(python_path.isEmpty() || !QFile::exists(python_path+QDir::separator()+"python.exe")) {
|
||||||
|
// Attempt to detect python in standard location
|
||||||
|
QStringList filters;
|
||||||
|
filters << "Python25" << "Python26";
|
||||||
|
QStringList python_folders = QDir::root().entryList(filters, QDir::Dirs, QDir::Name);
|
||||||
|
if(!python_folders.isEmpty()) {
|
||||||
|
python_path = QDir::root().absoluteFilePath(python_folders.last());
|
||||||
|
qDebug("Detected python folder at %s", qPrintable(python_path));
|
||||||
|
} else {
|
||||||
|
filters.clear();
|
||||||
|
filters << "Python*";
|
||||||
|
python_folders = QDir::root().entryList(filters, QDir::Dirs, QDir::Name);
|
||||||
|
if(!python_folders.isEmpty()) {
|
||||||
|
python_path = QDir::root().absoluteFilePath(python_folders.last());
|
||||||
|
qDebug("Detected python folder at %s", qPrintable(python_path));
|
||||||
|
} else {
|
||||||
|
qDebug("Failed to detect Python folder");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(python_path.isEmpty() || !QFile::exists(python_path+QDir::separator()+"python.exe")) {
|
||||||
|
QMessageBox::warning(0, tr("Failed to locate the Python interpreter"), tr("The Python interpreter was not found.\nqBittorrent will now ask you to point to its correct location."));
|
||||||
|
QString python_exe_path = QFileDialog::getOpenFileName(0, tr("Please point to its location on your hard disk."),
|
||||||
|
QDir::root().absolutePath(), tr("Python executable (python.exe)"));
|
||||||
|
if(python_exe_path.isEmpty() || !QFile::exists(python_exe_path)) {
|
||||||
|
QMessageBox::warning(0, tr("No Python interpreter"), tr("The Python interpreter is missing. qBittorrent search engine will not work."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
qDebug("Python exe path is: %s", qPrintable(python_exe_path));
|
||||||
|
QStringList tmp_list = python_exe_path.split(QDir::separator());
|
||||||
|
if(tmp_list.size() == 1)
|
||||||
|
tmp_list = tmp_list.first().split("/");
|
||||||
|
tmp_list.removeLast();
|
||||||
|
python_path = tmp_list.join(QDir::separator());
|
||||||
|
qDebug("New Python path is: %s", qPrintable(python_path));
|
||||||
|
// Save python path
|
||||||
|
Preferences::setPythonPath(python_path);
|
||||||
|
}
|
||||||
|
// Add it to PATH envvar
|
||||||
|
QString path_envar = QString::fromLocal8Bit(getenv("PATH"));
|
||||||
|
if(path_envar.isNull()) {
|
||||||
|
path_envar = "";
|
||||||
|
} else {
|
||||||
|
if(!path_envar.endsWith(";"))
|
||||||
|
path_envar += ";";
|
||||||
|
}
|
||||||
|
path_envar += python_path+";";
|
||||||
|
qDebug("New PATH envvar is: %s", qPrintable(path_envar));
|
||||||
|
QString envar = "PATH="+path_envar;
|
||||||
|
putenv(envar.toLocal8Bit().data());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
QString SearchEngine::selectedCategory() const {
|
QString SearchEngine::selectedCategory() const {
|
||||||
return comboCategory->itemData(comboCategory->currentIndex()).toString();
|
return comboCategory->itemData(comboCategory->currentIndex()).toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,9 @@ protected slots:
|
|||||||
void createCompleter();
|
void createCompleter();
|
||||||
void fillCatCombobox();
|
void fillCatCombobox();
|
||||||
void searchTextEdited(QString);
|
void searchTextEdited(QString);
|
||||||
|
#ifdef Q_WS_WIN
|
||||||
|
void checkForPythonExe();
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ LANG_PATH = lang
|
|||||||
ICONS_PATH = Icons
|
ICONS_PATH = Icons
|
||||||
|
|
||||||
# Set the following variable to 1 to enable debug
|
# Set the following variable to 1 to enable debug
|
||||||
DEBUG_MODE = 1
|
DEBUG_MODE = 0
|
||||||
|
|
||||||
# Global
|
# Global
|
||||||
TEMPLATE = app
|
TEMPLATE = app
|
||||||
|
|||||||
@@ -39,6 +39,7 @@
|
|||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
@@ -139,6 +140,7 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void update() {
|
void update() {
|
||||||
QProcess nova;
|
QProcess nova;
|
||||||
|
nova.setEnvironment(QProcess::systemEnvironment());
|
||||||
QStringList params;
|
QStringList params;
|
||||||
params << misc::searchEngineLocation()+QDir::separator()+"nova2.py";
|
params << misc::searchEngineLocation()+QDir::separator()+"nova2.py";
|
||||||
params << "--capabilities";
|
params << "--capabilities";
|
||||||
@@ -149,6 +151,7 @@ public slots:
|
|||||||
QDomDocument xml_doc;
|
QDomDocument xml_doc;
|
||||||
if(!xml_doc.setContent(capabilities)) {
|
if(!xml_doc.setContent(capabilities)) {
|
||||||
std::cerr << "Could not parse Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data() << std::endl;
|
std::cerr << "Could not parse Nova search engine capabilities, msg: " << capabilities.toLocal8Bit().data() << std::endl;
|
||||||
|
std::cerr << "Error: " << nova.readAllStandardError().constData() << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QDomElement root = xml_doc.documentElement();
|
QDomElement root = xml_doc.documentElement();
|
||||||
|
|||||||
Reference in New Issue
Block a user