From 5f759e89b3d92f860014b57cfaed2167ac8b2699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 28 Jun 2019 20:13:59 +0200 Subject: [PATCH] GUI: Show information label if Cppcheck is outdated --- gui/gui.pro | 7 +++++-- gui/mainwindow.cpp | 24 ++++++++++++++++++++++++ gui/mainwindow.h | 3 +++ gui/mainwindow.ui | 21 ++++++++++++++++++++- gui/networkinfo.cpp | 31 +++++++++++++++++++++++++++++++ gui/networkinfo.h | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 gui/networkinfo.cpp create mode 100644 gui/networkinfo.h diff --git a/gui/gui.pro b/gui/gui.pro index 0cbaebf16..d57a237d4 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -9,6 +9,7 @@ INCLUDEPATH += . \ ../lib QT += widgets QT += printsupport +QT += network contains(LINKCORE, [yY][eE][sS]) { LIBS += -l../bin/cppcheck-core @@ -121,7 +122,8 @@ HEADERS += aboutdialog.h \ cppchecklibrarydata.h \ libraryaddfunctiondialog.h \ libraryeditargdialog.h \ - newsuppressiondialog.h + newsuppressiondialog.h \ + networkinfo.h SOURCES += aboutdialog.cpp \ application.cpp \ @@ -161,7 +163,8 @@ SOURCES += aboutdialog.cpp \ cppchecklibrarydata.cpp \ libraryaddfunctiondialog.cpp \ libraryeditargdialog.cpp \ - newsuppressiondialog.cpp + newsuppressiondialog.cpp \ + networkinfo.cpp win32 { RC_FILE = cppcheck-gui.rc diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 3b6ad7efd..eb22394a6 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -30,11 +30,13 @@ #include "mainwindow.h" #include "cppcheck.h" +#include "version.h" #include "applicationlist.h" #include "aboutdialog.h" #include "common.h" #include "threadhandler.h" +#include "networkinfo.h" #include "fileviewdialog.h" #include "projectfile.h" #include "projectfiledialog.h" @@ -76,6 +78,11 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) : mThread->setDataDir(getDataDir(settings)); mUI.mResults->initialize(mSettings, mApplications, mThread); + mUI.mLabelUpgradeCppcheck->setVisible(false); + NetworkInfo *networkInfo = new NetworkInfo(this); + connect(networkInfo, SIGNAL(cppcheckVersion(QString)), this, SLOT(networkCppcheckVersion(QString))); + networkInfo->start(); + // Filter timer to delay filtering results slightly while typing mFilterTimer = new QTimer(this); mFilterTimer->setInterval(500); @@ -1762,3 +1769,20 @@ void MainWindow::suppressIds(QStringList ids) mProjectFile->setSuppressions(suppressions); mProjectFile->write(); } + +void MainWindow::networkCppcheckVersion(QString version) +{ + qDebug() << "MainWindow::networkCppcheckVersion:" << version; + if (!QRegExp("Cppcheck [0-9]\\.[0-9][0-9]").exactMatch(version)) { + mUI.mLabelUpgradeCppcheck->setVisible(false); + return; + } + + version = version.mid(9,4); + if (version <= CPPCHECK_VERSION_STRING) + mUI.mLabelUpgradeCppcheck->setVisible(false); + else { + mUI.mLabelUpgradeCppcheck->setVisible(true); + mUI.mLabelUpgradeCppcheck->setText(tr("Newer Cppcheck version is available: %1").arg(version)); + } +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 6812b17c8..d5bef5bb4 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -225,6 +225,9 @@ protected slots: /** Suppress error ids */ void suppressIds(QStringList ids); + /** Cppcheck version received from network */ + void networkCppcheckVersion(QString version); + private: /** Get filename for last results */ diff --git a/gui/mainwindow.ui b/gui/mainwindow.ui index a34a3b4eb..17c91e6d1 100644 --- a/gui/mainwindow.ui +++ b/gui/mainwindow.ui @@ -50,10 +50,29 @@ 16777215 - + + + + + + 0 + 0 + + + + false + + + QLabel { background-color : rgb(239, 242, 172); } + + + This is not latest Cppcheck version. Latest Cppcheck version is 999.999 + + + diff --git a/gui/networkinfo.cpp b/gui/networkinfo.cpp new file mode 100644 index 000000000..915524a6f --- /dev/null +++ b/gui/networkinfo.cpp @@ -0,0 +1,31 @@ +#include "networkinfo.h" +#include +#include + +NetworkInfo::NetworkInfo(QObject *parent) : QObject(parent) +{ + mManager = new QNetworkAccessManager; + connect(mManager, SIGNAL(finished(QNetworkReply*)), + this, SLOT(managerFinished(QNetworkReply*))); +} + +NetworkInfo::~NetworkInfo() +{ + delete mManager; +} + +void NetworkInfo::start() +{ + //QNetworkRequest request; + request.setUrl(QUrl("http://cppcheck.sourceforge.net/version.txt")); + mManager->get(request); +} + +void NetworkInfo::managerFinished(QNetworkReply *reply) { + if (reply->error()) { + qDebug() << reply->errorString(); + return; + } + + emit cppcheckVersion(reply->readAll().trimmed()); +} diff --git a/gui/networkinfo.h b/gui/networkinfo.h new file mode 100644 index 000000000..8242f98c8 --- /dev/null +++ b/gui/networkinfo.h @@ -0,0 +1,33 @@ +#ifndef NETWORKINFO_H +#define NETWORKINFO_H + +#include +#include +#include +#include + +/// @addtogroup GUI +/// @{ + + +/** + * Network communications with cppcheck website to get current version etc + */ +class NetworkInfo : public QObject +{ + Q_OBJECT +public: + NetworkInfo(QObject *parent); + ~NetworkInfo(); + + void start(); +signals: + void cppcheckVersion(QString version); +private slots: + void managerFinished(QNetworkReply *reply); +private: + QNetworkAccessManager *mManager; + QNetworkRequest request; +}; +/// @} +#endif // NETWORKINFO_H