gui: Add validation for Python path

This commit adds to cppcheck-gui validation for the path to the Python
interpreter entered by the user.
This commit is contained in:
Georgy Komarov 2020-09-12 11:35:00 +03:00
parent 3880412c46
commit a3a2e574a5
No known key found for this signature in database
GPG Key ID: 195B8622FE88ED46
3 changed files with 53 additions and 11 deletions

View File

@ -292,17 +292,28 @@
<property name="title">
<string>Python binary (leave this empty to use python in the PATH)</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="mEditPythonPath"/>
</item>
<item>
<widget class="QPushButton" name="mBtnBrowsePythonPath">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<layout class="QVBoxLayout" name="verticalLayout_13">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLineEdit" name="mEditPythonPath"/>
</item>
<item>
<widget class="QPushButton" name="mBtnBrowsePythonPath">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="mPythonPathWarning">
<property name="text">
<string></string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -23,6 +23,7 @@
#include <QListWidgetItem>
#include <QSettings>
#include <QFileDialog>
#include <QFileInfo>
#include <QThread>
#include "settingsdialog.h"
#include "applicationdialog.h"
@ -41,6 +42,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
mTranslator(translator)
{
mUI.setupUi(this);
mUI.mPythonPathWarning->setStyleSheet("color: red");
QSettings settings;
mTempApplications->copy(list);
@ -56,6 +58,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
mUI.mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool()));
mUI.mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool()));
mUI.mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString());
validateEditPythonPath();
mUI.mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString());
#ifdef Q_OS_WIN
@ -69,6 +72,9 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
mCurrentStyle = new CodeEditorStyle(CodeEditorStyle::loadSettings(&settings));
manageStyleControls();
connect(mUI.mEditPythonPath, SIGNAL(textEdited(const QString &)),
this, SLOT(validateEditPythonPath()));
connect(mUI.mButtons, &QDialogButtonBox::accepted, this, &SettingsDialog::ok);
connect(mUI.mButtons, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
connect(mUI.mBtnAddApplication, SIGNAL(clicked()),
@ -194,6 +200,28 @@ void SettingsDialog::saveCheckboxValue(QSettings *settings, QCheckBox *box,
settings->setValue(name, checkStateToBool(box->checkState()));
}
void SettingsDialog::validateEditPythonPath()
{
const auto pythonPath = mUI.mEditPythonPath->text();
if (pythonPath.isEmpty()) {
mUI.mEditPythonPath->setStyleSheet("");
mUI.mPythonPathWarning->hide();
return;
}
QFileInfo pythonPathInfo(pythonPath);
if (!pythonPathInfo.exists() ||
!pythonPathInfo.isFile() ||
!pythonPathInfo.isExecutable()) {
mUI.mEditPythonPath->setStyleSheet("QLineEdit {border: 1px solid red}");
mUI.mPythonPathWarning->setText(tr("The executable file \"%1\" is not available").arg(pythonPath));
mUI.mPythonPathWarning->show();
} else {
mUI.mEditPythonPath->setStyleSheet("");
mUI.mPythonPathWarning->hide();
}
}
void SettingsDialog::addApplication()
{
Application app;

View File

@ -103,6 +103,9 @@ protected slots:
*/
void ok();
/** @brief Slot for validating input value in @c editPythonPath */
void validateEditPythonPath();
/**
* @brief Slot for adding a new application to the list
*