Skip to content

Commit

Permalink
Add version checker at opening.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Bieder committed Jan 15, 2021
1 parent 24363e7 commit 092735b
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
8 changes: 5 additions & 3 deletions qAgate.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
#-------------------------------------------------

QT += core gui opengl
QT += core gui opengl network

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport

Expand Down Expand Up @@ -105,7 +105,8 @@ SOURCES += \
qdos/qdos.cpp \
tools/coloritemdelegate.cpp \
dialogs/about.cpp \
tabs/multibinittab.cpp
tabs/multibinittab.cpp \
tools/versionchecker.cpp \

HEADERS += \
dialogs/mbgeneratordialog.h \
Expand Down Expand Up @@ -161,7 +162,8 @@ HEADERS += \
qdos/qdos.h \
tools/coloritemdelegate.h \
dialogs/about.h \
tabs/multibinittab.h
tabs/multibinittab.h \
tools/versionchecker.h \

FORMS += \
dialogs/mbgeneratordialog.ui \
Expand Down
11 changes: 11 additions & 0 deletions qagate/main_qagate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/exception.hpp"
#include "base/utils.hpp"
#include <QApplication>
#include <QCoreApplication>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
#include <QSurfaceFormat>
#else
Expand All @@ -18,6 +19,8 @@
#include <csignal>
#include "window/window.hpp"

#include "tools/versionchecker.h"

/**
* Simple function to display the name and version of the package and what window manager we use.
*/
Expand All @@ -32,6 +35,10 @@ void handle_signal (int para);
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setApplicationName("qAgate");
QCoreApplication::setOrganizationName("qAgate");
QCoreApplication::setOrganizationDomain("qAgate");
QCoreApplication::setApplicationVersion(QAGATE_VERSION);

Parser parser(argc,argv);
parser.setOption("config",'c',"","Configuration file to configure the animation.");
Expand Down Expand Up @@ -91,6 +98,9 @@ int main(int argc, char *argv[])
}

w.initInput(argc-1,(const char**) argv+1);
VersionChecker checker;
checker.checkAgate();
checker.checkqAgate();
w.show();
rvalue = a.exec();
}
Expand Down Expand Up @@ -166,4 +176,5 @@ void Version()
{
utils::Version();
std::cout << "Using Qt version " << qVersion() << std::endl;
std::cout << "qAgate version " << QAGATE_VERSION << std::endl;
}
67 changes: 67 additions & 0 deletions tools/versionchecker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include "versionchecker.h"
#include <QString>
#include "base/utils.hpp"
#include <QRegularExpressionMatch>
#include <QMessageBox>
#include <QCheckBox>
#include <QSettings>

VersionChecker::VersionChecker(QObject *parent) : QObject(parent)
{

}

void VersionChecker::checkAgate()
{
QString current=QString::fromStdString(utils::agateVersion());
QString last=QString::fromStdString(utils::agateLatestVersion());
if (current!=last)
{
QSettings settings;
if (settings.value("updates/agate_current").toString()!=current
|| settings.value("updates/agate_hide").toBool()==false
)
{
QMessageBox box;
box.setCheckBox(new QCheckBox(tr("Do not check again"),&box));
box.setText(tr("New version of agate is available: %0").arg(last));
box.setWindowTitle(tr("New Agate release !"));
box.exec();
settings.setValue("updates/agate_hide",box.checkBox()->isChecked());
settings.setValue("updates/agate_current",current);
}
}
}

void VersionChecker::checkqAgate()
{
const QString url="https://github.com/piti-diablotin/qAgate/releases/latest";
_request.setUrl(url);
_request.setAttribute(QNetworkRequest::RedirectPolicyAttribute,QNetworkRequest::ManualRedirectPolicy);
QObject::connect(&_manager,&QNetworkAccessManager::finished,
[this](QNetworkReply* reply){

QRegularExpression re("\\d+\\.\\d+\\.\\d+");
QRegularExpressionMatch match = re.match(reply->readAll());
if (match.hasMatch()){
if (match.captured() != QAGATE_VERSION) {
QSettings settings;
if (settings.value("updates/qagate_current").toString()!=QAGATE_VERSION
|| settings.value("updates/qagate_hide").toBool()==false
)
{
QMessageBox box;
box.setCheckBox(new QCheckBox(tr("Do not check again"),&box));
box.setText(tr("New version of qAgate is available: %0").arg(match.captured()));
box.setWindowTitle(tr("New qAgate release !"));
box.exec();
settings.setValue("updates/qagate_hide",box.checkBox()->isChecked());
settings.setValue("updates/qagate_current",QAGATE_VERSION);
}
}
}
}
);
_manager.get(_request);

}
24 changes: 24 additions & 0 deletions tools/versionchecker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef VERSIONCHECKER_H
#define VERSIONCHECKER_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>

class VersionChecker : public QObject
{
Q_OBJECT
public:
explicit VersionChecker(QObject *parent = nullptr);
void checkAgate();
void checkqAgate();

private:
QNetworkRequest _request;
QNetworkAccessManager _manager;

signals:

};

#endif // VERSIONCHECKER_H

0 comments on commit 092735b

Please sign in to comment.