GUI: Show information label if Cppcheck is outdated

This commit is contained in:
Daniel Marjamäki 2019-06-28 20:13:59 +02:00
parent c2144d73b3
commit 5f759e89b3
6 changed files with 116 additions and 3 deletions

View File

@ -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

View File

@ -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));
}
}

View File

@ -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 */

View File

@ -50,10 +50,29 @@
<height>16777215</height>
</size>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="ResultsView" name="mResults" native="true"/>
</item>
<item>
<widget class="QLabel" name="mLabelUpgradeCppcheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">QLabel { background-color : rgb(239, 242, 172); }</string>
</property>
<property name="text">
<string>This is not latest Cppcheck version. Latest Cppcheck version is 999.999</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="mMenuBar">

31
gui/networkinfo.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "networkinfo.h"
#include <QNetworkReply>
#include <QNetworkRequest>
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());
}

33
gui/networkinfo.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef NETWORKINFO_H
#define NETWORKINFO_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QString>
/// @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