diff --git a/src/updatechecker.h b/src/updatechecker.h new file mode 100644 --- /dev/null +++ b/src/updatechecker.h @@ -0,0 +1,77 @@ +/* + Copyright © 2018 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#ifndef UPDATECHECKER_H +#define UPDATECHECKER_H + +#include +#include +#include +#include + +#include "versionnumber.h" + +class UpdateChecker : public QObject +{ + Q_OBJECT +public: + explicit UpdateChecker(QObject *parent = 0); + + bool isChecking() const; + +signals: + void checkFinished(bool found, QString newVersion, QString downloadUrl); + void checkFailed(QString errorMessage); + +public slots: + void checkUpdate(); + void cancelCheck(); + +private: + enum class FileArch + { + unknown, + _i386, + amd64, + arm + }; + + struct FileInfo + { + QString name; + QString link; + bool hasVersion; + VersionNumber version; + FileArch arch; + }; + + QNetworkAccessManager nam; + QNetworkReply* activeReply; + + /// Parses json and creates a list of files + bool parseData(const QJsonDocument& data, QList& files) const; + /// Finds the update file in the file list. Returns `-1` if no new version + /// is found. + bool findUpdate(const QList& files, FileInfo& foundFile) const; + +private slots: + void onReqFinished(QNetworkReply* reply); +}; + +#endif // UPDATECHECKER_H