GUI: Detect when version is old
This commit is contained in:
parent
d1bfae989e
commit
94c3108494
|
@ -1,5 +1,5 @@
|
||||||
if (BUILD_GUI)
|
if (BUILD_GUI)
|
||||||
list(APPEND qt_components Core Gui Widgets PrintSupport LinguistTools Help)
|
list(APPEND qt_components Core Gui Widgets PrintSupport LinguistTools Help Network)
|
||||||
if (WITH_QCHART)
|
if (WITH_QCHART)
|
||||||
list(APPEND qt_components Charts)
|
list(APPEND qt_components Charts)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -28,6 +28,7 @@ if (QT_VERSION VERSION_LESS 5.15)
|
||||||
set(QT_HELP_LIB Qt5::Help)
|
set(QT_HELP_LIB Qt5::Help)
|
||||||
set(QT_PRINTSUPPORT_LIB Qt5::PrintSupport)
|
set(QT_PRINTSUPPORT_LIB Qt5::PrintSupport)
|
||||||
set(QT_CHARTS_LIB Qt5::Charts)
|
set(QT_CHARTS_LIB Qt5::Charts)
|
||||||
|
set(QT_NETWORK_LIB Qt5::Network)
|
||||||
else()
|
else()
|
||||||
# use "versionless" targets - no need for wrapper functions
|
# use "versionless" targets - no need for wrapper functions
|
||||||
|
|
||||||
|
@ -38,4 +39,5 @@ else()
|
||||||
set(QT_HELP_LIB Qt::Help)
|
set(QT_HELP_LIB Qt::Help)
|
||||||
set(QT_PRINTSUPPORT_LIB Qt::PrintSupport)
|
set(QT_PRINTSUPPORT_LIB Qt::PrintSupport)
|
||||||
set(QT_CHARTS_LIB Qt::Charts)
|
set(QT_CHARTS_LIB Qt::Charts)
|
||||||
endif()
|
set(QT_NETWORK_LIB Qt::Network)
|
||||||
|
endif()
|
||||||
|
|
|
@ -47,7 +47,7 @@ CheckOptions:
|
||||||
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
|
if(tinyxml2_FOUND AND NOT USE_BUNDLED_TINYXML2)
|
||||||
target_link_libraries(cppcheck-gui ${tinyxml2_LIBRARIES})
|
target_link_libraries(cppcheck-gui ${tinyxml2_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
target_link_libraries(cppcheck-gui ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_PRINTSUPPORT_LIB} ${QT_HELP_LIB})
|
target_link_libraries(cppcheck-gui ${QT_CORE_LIB} ${QT_GUI_LIB} ${QT_WIDGETS_LIB} ${QT_PRINTSUPPORT_LIB} ${QT_HELP_LIB} ${QT_NETWORK_LIB})
|
||||||
if(WITH_QCHART)
|
if(WITH_QCHART)
|
||||||
target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART)
|
target_compile_definitions (cppcheck-gui PRIVATE HAVE_QCHART)
|
||||||
target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB})
|
target_link_libraries(cppcheck-gui ${QT_CHARTS_LIB})
|
||||||
|
|
|
@ -89,6 +89,7 @@
|
||||||
#define SETTINGS_SHOW_ERROR_ID "Show error Id"
|
#define SETTINGS_SHOW_ERROR_ID "Show error Id"
|
||||||
#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"
|
||||||
|
|
||||||
// The maximum value for the progress bar
|
// The maximum value for the progress bar
|
||||||
#define PROGRESS_MAX 1024.0
|
#define PROGRESS_MAX 1024.0
|
||||||
|
|
|
@ -10,6 +10,7 @@ INCLUDEPATH += . \
|
||||||
QT += widgets
|
QT += widgets
|
||||||
QT += printsupport
|
QT += printsupport
|
||||||
QT += help
|
QT += help
|
||||||
|
QT += network
|
||||||
|
|
||||||
# Build online help
|
# Build online help
|
||||||
onlinehelp.target = online-help.qhc
|
onlinehelp.target = online-help.qhc
|
||||||
|
|
|
@ -66,6 +66,8 @@
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QtNetwork/QNetworkAccessManager>
|
||||||
|
#include <QtNetwork/QNetworkReply>
|
||||||
|
|
||||||
static const QString OnlineHelpURL("https://cppcheck.sourceforge.io/manual.html");
|
static const QString OnlineHelpURL("https://cppcheck.sourceforge.io/manual.html");
|
||||||
static const QString compile_commands_json("compile_commands.json");
|
static const QString compile_commands_json("compile_commands.json");
|
||||||
|
@ -246,6 +248,24 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
|
||||||
#endif
|
#endif
|
||||||
Platform &platform = mPlatforms.get((Settings::PlatformType)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
|
Platform &platform = mPlatforms.get((Settings::PlatformType)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
|
||||||
platform.mActMainWindow->setChecked(true);
|
platform.mActMainWindow->setChecked(true);
|
||||||
|
|
||||||
|
mNetworkAccessManager = new QNetworkAccessManager(this);
|
||||||
|
connect(mNetworkAccessManager, &QNetworkAccessManager::finished,
|
||||||
|
this, &MainWindow::replyFinished);
|
||||||
|
|
||||||
|
mUI->mLabelInformation->setVisible(false);
|
||||||
|
mUI->mButtonHideInformation->setVisible(false);
|
||||||
|
connect(mUI->mButtonHideInformation, &QPushButton::clicked,
|
||||||
|
this, &MainWindow::hideInformation);
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -1880,6 +1900,63 @@ void MainWindow::suppressIds(QStringList ids)
|
||||||
mProjectFile->write();
|
mProjectFile->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int getVersion(const QString& nameWithVersion) {
|
||||||
|
int ret = 0;
|
||||||
|
int v = 0;
|
||||||
|
int dot = 0;
|
||||||
|
for (const auto c: nameWithVersion) {
|
||||||
|
if (c == '\n' || c == '\r')
|
||||||
|
break;
|
||||||
|
else if (c == ' ')
|
||||||
|
dot = ret = v = 0;
|
||||||
|
else if (c == '.') {
|
||||||
|
++dot;
|
||||||
|
ret = ret * 1000 + v;
|
||||||
|
v = 0;
|
||||||
|
} else if (c >= '0' && c <= '9')
|
||||||
|
v = v * 10 + (c.toLatin1() - '0');
|
||||||
|
}
|
||||||
|
ret = ret * 1000 + v;
|
||||||
|
while (dot < 2) {
|
||||||
|
++dot;
|
||||||
|
ret *= 1000;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::replyFinished(QNetworkReply *reply) {
|
||||||
|
reply->deleteLater();
|
||||||
|
if (reply->error()) {
|
||||||
|
// TODO?
|
||||||
|
qDebug() << "Response: ERROR";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QString str = reply->readAll();
|
||||||
|
qDebug() << "Response: " << str;
|
||||||
|
if (reply->url().fileName() == "version.txt") {
|
||||||
|
QString nameWithVersion = QString("Cppcheck %1").arg(CppCheck::version());
|
||||||
|
if (!mCppcheckCfgProductName.isEmpty())
|
||||||
|
nameWithVersion = mCppcheckCfgProductName;
|
||||||
|
const int appVersion = getVersion(nameWithVersion);
|
||||||
|
const int latestVersion = getVersion(str.trimmed());
|
||||||
|
if (appVersion < latestVersion) {
|
||||||
|
if (mSettings->value(SETTINGS_CHECK_VERSION, 0).toInt() != latestVersion) {
|
||||||
|
mUI->mButtonHideInformation->setVisible(true);
|
||||||
|
mUI->mLabelInformation->setVisible(true);
|
||||||
|
mUI->mLabelInformation->setText(tr("New version available: %1").arg(str.trimmed()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::hideInformation() {
|
||||||
|
int version = getVersion(mUI->mLabelInformation->text());
|
||||||
|
mSettings->setValue(SETTINGS_CHECK_VERSION, version);
|
||||||
|
mUI->mLabelInformation->setVisible(false);
|
||||||
|
mUI->mButtonHideInformation->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
bool MainWindow::isCppcheckPremium() const {
|
bool MainWindow::isCppcheckPremium() const {
|
||||||
return mCppcheckCfgProductName.startsWith("Cppcheck Premium ");
|
return mCppcheckCfgProductName.startsWith("Cppcheck Premium ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ class QLineEdit;
|
||||||
class ImportProject;
|
class ImportProject;
|
||||||
class QCloseEvent;
|
class QCloseEvent;
|
||||||
class QObject;
|
class QObject;
|
||||||
|
class QNetworkAccessManager;
|
||||||
|
class QNetworkReply;
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
|
@ -228,6 +230,10 @@ protected slots:
|
||||||
/** Suppress error ids */
|
/** Suppress error ids */
|
||||||
void suppressIds(QStringList ids);
|
void suppressIds(QStringList ids);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void replyFinished(QNetworkReply *reply);
|
||||||
|
|
||||||
|
void hideInformation();
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool isCppcheckPremium() const;
|
bool isCppcheckPremium() const;
|
||||||
|
@ -465,6 +471,8 @@ private:
|
||||||
|
|
||||||
QString mCppcheckCfgAbout;
|
QString mCppcheckCfgAbout;
|
||||||
QString mCppcheckCfgProductName;
|
QString mCppcheckCfgProductName;
|
||||||
|
|
||||||
|
QNetworkAccessManager *mNetworkAccessManager = nullptr;
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
|
@ -50,9 +50,62 @@
|
||||||
<height>16777215</height>
|
<height>16777215</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="ResultsView" name="mResults" native="true"/>
|
<widget class="ResultsView" name="mResults" native="true">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetDefaultConstraint</enum>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="mLabelInformation">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="mButtonHideInformation">
|
||||||
|
<property name="text">
|
||||||
|
<string>Hide</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -62,7 +115,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>640</width>
|
<width>640</width>
|
||||||
<height>28</height>
|
<height>30</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="mMenuFile">
|
<widget class="QMenu" name="mMenuFile">
|
||||||
|
|
Loading…
Reference in New Issue