GUI: Add setting 'Check for updates'

This commit is contained in:
Daniel Marjamäki 2022-10-22 20:27:24 +02:00
parent 13d81cdd58
commit fba70683bc
5 changed files with 45 additions and 27 deletions

View File

@ -90,6 +90,7 @@
#define SETTINGS_SHOW_STATISTICS "Show statistics" #define SETTINGS_SHOW_STATISTICS "Show statistics"
#define SETTINGS_OPEN_PROJECT "Open Project" #define SETTINGS_OPEN_PROJECT "Open Project"
#define SETTINGS_CHECK_VERSION "Check Version" #define SETTINGS_CHECK_VERSION "Check Version"
#define SETTINGS_CHECK_FOR_UPDATES "Check for updates"
// The maximum value for the progress bar // The maximum value for the progress bar
#define PROGRESS_MAX 1024.0 #define PROGRESS_MAX 1024.0

View File

@ -258,13 +258,20 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
connect(mUI->mButtonHideInformation, &QPushButton::clicked, connect(mUI->mButtonHideInformation, &QPushButton::clicked,
this, &MainWindow::hideInformation); this, &MainWindow::hideInformation);
// Is there a new version? if (!mSettings->contains(SETTINGS_CHECK_FOR_UPDATES))
if (isCppcheckPremium()) { mSettings->setValue(SETTINGS_CHECK_FOR_UPDATES, isCppcheckPremium());
const QUrl url("https://files.cppchecksolutions.com/version.txt");
mNetworkAccessManager->get(QNetworkRequest(url)); if (mSettings->value(SETTINGS_CHECK_FOR_UPDATES, false).toBool()) {
// Is there a new version?
if (isCppcheckPremium()) {
const QUrl url("https://files.cppchecksolutions.com/version.txt");
mNetworkAccessManager->get(QNetworkRequest(url));
} else {
const QUrl url("https://cppcheck.sourceforge.io/version.txt");
mNetworkAccessManager->get(QNetworkRequest(url));
}
} else { } else {
const QUrl url("https://cppcheck.sourceforge.io/version.txt"); delete mUI->mLayoutInformation;
mNetworkAccessManager->get(QNetworkRequest(url));
} }
} }
@ -1956,6 +1963,7 @@ void MainWindow::hideInformation() {
mSettings->setValue(SETTINGS_CHECK_VERSION, version); mSettings->setValue(SETTINGS_CHECK_VERSION, version);
mUI->mLabelInformation->setVisible(false); mUI->mLabelInformation->setVisible(false);
mUI->mButtonHideInformation->setVisible(false); mUI->mButtonHideInformation->setVisible(false);
mUI->mLayoutInformation->deleteLater();
} }
bool MainWindow::isCppcheckPremium() const { bool MainWindow::isCppcheckPremium() const {

View File

@ -62,7 +62,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="mLayoutInformation">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SetDefaultConstraint</enum>
</property> </property>

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>589</width> <width>627</width>
<height>346</height> <height>411</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -157,6 +157,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="mCheckForUpdates">
<property name="text">
<string>Check for updates</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer_2"> <spacer name="verticalSpacer_2">
<property name="orientation"> <property name="orientation">
@ -293,27 +300,27 @@
<string>Python binary (leave this empty to use python in the PATH)</string> <string>Python binary (leave this empty to use python in the PATH)</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_13"> <layout class="QVBoxLayout" name="verticalLayout_13">
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLineEdit" name="mEditPythonPath"/> <widget class="QLineEdit" name="mEditPythonPath"/>
</item> </item>
<item> <item>
<widget class="QPushButton" name="mBtnBrowsePythonPath"> <widget class="QPushButton" name="mBtnBrowsePythonPath">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="mPythonPathWarning">
<property name="text"> <property name="text">
<string></string> <string>...</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout>
</item>
<item>
<widget class="QLabel" name="mPythonPathWarning">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -60,6 +60,7 @@ SettingsDialog::SettingsDialog(ApplicationList *list,
mUI->mEnableInconclusive->setCheckState(boolToCheckState(settings.value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool())); mUI->mEnableInconclusive->setCheckState(boolToCheckState(settings.value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool()));
mUI->mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool())); mUI->mShowStatistics->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_STATISTICS, false).toBool()));
mUI->mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool())); mUI->mShowErrorId->setCheckState(boolToCheckState(settings.value(SETTINGS_SHOW_ERROR_ID, false).toBool()));
mUI->mCheckForUpdates->setCheckState(boolToCheckState(settings.value(SETTINGS_CHECK_FOR_UPDATES, false).toBool()));
mUI->mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString()); mUI->mEditPythonPath->setText(settings.value(SETTINGS_PYTHON_PATH, QString()).toString());
validateEditPythonPath(); validateEditPythonPath();
mUI->mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString()); mUI->mEditMisraFile->setText(settings.value(SETTINGS_MISRA_FILE, QString()).toString());
@ -182,6 +183,7 @@ void SettingsDialog::saveSettingValues() const
saveCheckboxValue(&settings, mUI->mEnableInconclusive, SETTINGS_INCONCLUSIVE_ERRORS); saveCheckboxValue(&settings, mUI->mEnableInconclusive, SETTINGS_INCONCLUSIVE_ERRORS);
saveCheckboxValue(&settings, mUI->mShowStatistics, SETTINGS_SHOW_STATISTICS); saveCheckboxValue(&settings, mUI->mShowStatistics, SETTINGS_SHOW_STATISTICS);
saveCheckboxValue(&settings, mUI->mShowErrorId, SETTINGS_SHOW_ERROR_ID); saveCheckboxValue(&settings, mUI->mShowErrorId, SETTINGS_SHOW_ERROR_ID);
saveCheckboxValue(&settings, mUI->mCheckForUpdates, SETTINGS_CHECK_FOR_UPDATES);
settings.setValue(SETTINGS_PYTHON_PATH, mUI->mEditPythonPath->text()); settings.setValue(SETTINGS_PYTHON_PATH, mUI->mEditPythonPath->text());
settings.setValue(SETTINGS_MISRA_FILE, mUI->mEditMisraFile->text()); settings.setValue(SETTINGS_MISRA_FILE, mUI->mEditMisraFile->text());