-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jordan Bieder
committed
Jan 15, 2021
1 parent
24363e7
commit 092735b
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |