mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-12 08:16:16 -07:00
Fix asking to install Python
The dialog asking users to install python is borked since the last refactor, this commit fixes it.
This commit is contained in:
parent
60ecc4fe8f
commit
7d808cfc99
4 changed files with 45 additions and 75 deletions
|
@ -77,7 +77,8 @@ namespace
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Python detected, version: %1").arg(info.version), Log::INFO);
|
LogMsg(QCoreApplication::translate("Utils::ForeignApps", "Python detected, executable name: '%1', version: %2")
|
||||||
|
.arg(info.executableName, info.version), Log::INFO);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,6 +237,14 @@ bool Utils::ForeignApps::PythonInfo::isValid() const
|
||||||
return (!executableName.isEmpty() && version.isValid());
|
return (!executableName.isEmpty() && version.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Utils::ForeignApps::PythonInfo::isSupportedVersion() const
|
||||||
|
{
|
||||||
|
const int majorVer = version.majorNumber();
|
||||||
|
return ((majorVer > 3)
|
||||||
|
|| ((majorVer == 3) && (version >= Version {3, 3, 0}))
|
||||||
|
|| ((majorVer == 2) && (version >= Version {2, 7, 9})));
|
||||||
|
}
|
||||||
|
|
||||||
PythonInfo Utils::ForeignApps::pythonInfo()
|
PythonInfo Utils::ForeignApps::pythonInfo()
|
||||||
{
|
{
|
||||||
static PythonInfo pyInfo;
|
static PythonInfo pyInfo;
|
||||||
|
|
|
@ -42,6 +42,7 @@ namespace Utils
|
||||||
using Version = Utils::Version<quint8, 3, 1>;
|
using Version = Utils::Version<quint8, 3, 1>;
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
bool isSupportedVersion() const;
|
||||||
|
|
||||||
QString executableName;
|
QString executableName;
|
||||||
Version version;
|
Version version;
|
||||||
|
|
|
@ -1784,67 +1784,50 @@ void MainWindow::on_actionRSSReader_triggered()
|
||||||
void MainWindow::on_actionSearchWidget_triggered()
|
void MainWindow::on_actionSearchWidget_triggered()
|
||||||
{
|
{
|
||||||
if (!m_hasPython && m_ui->actionSearchWidget->isChecked()) {
|
if (!m_hasPython && m_ui->actionSearchWidget->isChecked()) {
|
||||||
int majorVersion = Utils::ForeignApps::pythonInfo().version.majorNumber();
|
const Utils::ForeignApps::PythonInfo pyInfo = Utils::ForeignApps::pythonInfo();
|
||||||
|
|
||||||
|
// Not installed
|
||||||
|
if (!pyInfo.isValid()) {
|
||||||
|
m_ui->actionSearchWidget->setChecked(false);
|
||||||
|
Preferences::instance()->setSearchEnabled(false);
|
||||||
|
|
||||||
// Check if python is already in PATH
|
|
||||||
if (majorVersion > 0) {
|
|
||||||
// Prevent translators from messing with PATH
|
|
||||||
Logger::instance()->addMessage(tr("Python found in %1: %2", "Python found in PATH: /usr/local/bin:/usr/bin:/etc/bin")
|
|
||||||
.arg("PATH", qgetenv("PATH").constData()), Log::INFO);
|
|
||||||
}
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
else if (addPythonPathToEnv()) {
|
const QMessageBox::StandardButton buttonPressed = QMessageBox::question(this, tr("Missing Python Runtime")
|
||||||
majorVersion = Utils::ForeignApps::pythonInfo().version.majorNumber();
|
, tr("Python is required to use the search engine but it does not seem to be installed.\nDo you want to install it now?")
|
||||||
}
|
, (QMessageBox::Yes | QMessageBox::No), QMessageBox::Yes);
|
||||||
|
if (buttonPressed == QMessageBox::Yes)
|
||||||
|
installPython();
|
||||||
|
#else
|
||||||
|
QMessageBox::information(this, tr("Missing Python Runtime")
|
||||||
|
, tr("Python is required to use the search engine but it does not seem to be installed."));
|
||||||
#endif
|
#endif
|
||||||
else {
|
|
||||||
QMessageBox::information(this, tr("Undetermined Python version"), tr("Couldn't determine your Python version. Search engine disabled."));
|
|
||||||
m_ui->actionSearchWidget->setChecked(false);
|
|
||||||
Preferences::instance()->setSearchEnabled(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool res = false;
|
// Check version requirement
|
||||||
|
if (!pyInfo.isSupportedVersion()) {
|
||||||
|
m_ui->actionSearchWidget->setChecked(false);
|
||||||
|
Preferences::instance()->setSearchEnabled(false);
|
||||||
|
|
||||||
if ((majorVersion == 2) || (majorVersion == 3)) {
|
|
||||||
// Check Python minimum requirement: 2.7.9 / 3.3.0
|
|
||||||
using Version = Utils::ForeignApps::PythonInfo::Version;
|
|
||||||
const Version pyVersion = Utils::ForeignApps::pythonInfo().version;
|
|
||||||
|
|
||||||
if (((majorVersion == 2) && (pyVersion < Version {2, 7, 9}))
|
|
||||||
|| ((majorVersion == 3) && (pyVersion < Version {3, 3, 0}))) {
|
|
||||||
QMessageBox::information(this, tr("Old Python Interpreter"), tr("Your Python version (%1) is outdated. Please upgrade to latest version for search engines to work.\nMinimum requirement: 2.7.9 / 3.3.0.").arg(pyVersion));
|
|
||||||
m_ui->actionSearchWidget->setChecked(false);
|
|
||||||
Preferences::instance()->setSearchEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
res = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (res) {
|
|
||||||
m_hasPython = true;
|
|
||||||
}
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
else if (QMessageBox::question(this, tr("Missing Python Interpreter"),
|
const QMessageBox::StandardButton buttonPressed = QMessageBox::question(this, tr("Old Python Runtime")
|
||||||
tr("Python is required to use the search engine but it does not seem to be installed.\nDo you want to install it now?"),
|
, tr("Your Python version (%1) is outdated. Minimum requirement: 2.7.9 / 3.3.0.\nDo you want to install a newer version now?")
|
||||||
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
|
, (QMessageBox::Yes | QMessageBox::No), QMessageBox::Yes);
|
||||||
// Download and Install Python
|
if (buttonPressed == QMessageBox::Yes)
|
||||||
installPython();
|
installPython();
|
||||||
m_ui->actionSearchWidget->setChecked(false);
|
#else
|
||||||
Preferences::instance()->setSearchEnabled(false);
|
QMessageBox::information(this, tr("Old Python Runtime")
|
||||||
return;
|
, tr("Your Python version (%1) is outdated. Please upgrade to latest version for search engines to work.\nMinimum requirement: 2.7.9 / 3.3.0.")
|
||||||
}
|
.arg(pyInfo.version));
|
||||||
#endif
|
#endif
|
||||||
else {
|
|
||||||
#ifndef Q_OS_WIN
|
|
||||||
QMessageBox::information(this, tr("Missing Python Interpreter"), tr("Python is required to use the search engine but it does not seem to be installed."));
|
|
||||||
#endif
|
|
||||||
m_ui->actionSearchWidget->setChecked(false);
|
|
||||||
Preferences::instance()->setSearchEnabled(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_hasPython = true;
|
||||||
|
m_ui->actionSearchWidget->setChecked(true);
|
||||||
|
Preferences::instance()->setSearchEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
displaySearchTab(m_ui->actionSearchWidget->isChecked());
|
displaySearchTab(m_ui->actionSearchWidget->isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2061,25 +2044,6 @@ void MainWindow::checkProgramUpdate()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
bool MainWindow::addPythonPathToEnv()
|
|
||||||
{
|
|
||||||
if (m_hasPython) return true;
|
|
||||||
|
|
||||||
QString pythonPath = Preferences::getPythonPath();
|
|
||||||
if (!pythonPath.isEmpty()) {
|
|
||||||
Logger::instance()->addMessage(tr("Python found in '%1'").arg(Utils::Fs::toNativePath(pythonPath)), Log::INFO);
|
|
||||||
// Add it to PATH envvar
|
|
||||||
QString pathEnvar = QString::fromLocal8Bit(qgetenv("PATH").constData());
|
|
||||||
if (pathEnvar.isNull())
|
|
||||||
pathEnvar = "";
|
|
||||||
pathEnvar = pythonPath + ';' + pathEnvar;
|
|
||||||
qDebug("New PATH envvar is: %s", qUtf8Printable(pathEnvar));
|
|
||||||
qputenv("PATH", Utils::Fs::toNativePath(pathEnvar).toLocal8Bit());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::installPython()
|
void MainWindow::installPython()
|
||||||
{
|
{
|
||||||
setCursor(QCursor(Qt::WaitCursor));
|
setCursor(QCursor(Qt::WaitCursor));
|
||||||
|
@ -2123,10 +2087,7 @@ void MainWindow::pythonDownloadSuccess(const QString &url, const QString &filePa
|
||||||
else
|
else
|
||||||
Utils::Fs::forceRemove(filePath + ".msi");
|
Utils::Fs::forceRemove(filePath + ".msi");
|
||||||
// Reload search engine
|
// Reload search engine
|
||||||
m_hasPython = addPythonPathToEnv();
|
if (Utils::ForeignApps::pythonInfo().isSupportedVersion()) {
|
||||||
if (m_hasPython) {
|
|
||||||
// Make it print the version to Log
|
|
||||||
Utils::ForeignApps::pythonInfo();
|
|
||||||
m_ui->actionSearchWidget->setChecked(true);
|
m_ui->actionSearchWidget->setChecked(true);
|
||||||
displaySearchTab(true);
|
displaySearchTab(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,6 @@ private:
|
||||||
QIcon getSystrayIcon() const;
|
QIcon getSystrayIcon() const;
|
||||||
#endif
|
#endif
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
bool addPythonPathToEnv();
|
|
||||||
void installPython();
|
void installPython();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue