forked from palindromiq/YATE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.h
79 lines (60 loc) · 1.52 KB
/
updater.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef UPDATER_H
#define UPDATER_H
#include <QObject>
class QThread;
class QNetworkAccessManager;
class QNetworkReply;
namespace Yate {
class Downloader;
enum class UpdaterStatus {
Unknown,
Checking,
CheckFailed,
UpdateFailed,
UpdateAvailable,
Downloading,
Downloaded,
Installing,
PendingRestart,
UpToDate,
};
class Updater : public QObject
{
Q_OBJECT
public:
static Updater *getInstance(QObject *parent = nullptr);
Updater(const Updater &) = delete;
void operator=(const Updater &) = delete;
void checkUpdate();
QString getVersion() const;
UpdaterStatus status() const;
static QVector<int> parseVersion(QString ver);
const QString &latestVersion() const;
public slots:
void checkForUpdate();
void startUpdate();
private slots:
void onDownloadFinished(QString, QString);
void onDownloadFailed(QString);
void onManagerFinished(QNetworkReply *);
signals:
void updateAvailable();
void updateStatusUpdate(QString status);
void errorOccurred(QString err);
void onBusyUpdate(bool);
private:
explicit Updater(QObject *parent = nullptr);
void setStatus(UpdaterStatus newStatus);
void downloadUpdate();
void setLatestVersion(const QString &newLatestVersion);
static Updater *instance_;
static QThread *thread_;
QNetworkAccessManager *manager_;
UpdaterStatus status_;
Downloader *downloader_;
QString downloadHash_;
QString downloadUrl_;
QString latestVersion_;
};
}
#endif // UPDATER_H