-
Notifications
You must be signed in to change notification settings - Fork 39
/
creator.h
181 lines (162 loc) · 5.28 KB
/
creator.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
////////////////////////////////////////////////////////////////////////////////
// This file is part of LibreELEC - http://www.libreelec.tv
// Copyright (C) 2013-2015 RasPlex project
// Copyright (C) 2016 Team LibreELEC
//
// LibreELEC 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 2 of the License, or
// (at your option) any later version.
//
// LibreELEC 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 LibreELEC. If not, see <http://www.gnu.org/licenses/>.
////////////////////////////////////////////////////////////////////////////////
#ifndef CREATOR_H
#define CREATOR_H
#include <QCryptographicHash>
#include <QDialog>
#include <QNetworkAccessManager>
#include <QSettings>
#include <QFile>
#include <QStandardPaths>
#include <QElapsedTimer>
#include "downloadmanager.h"
#include "jsonparser.h"
#include "movingaverage.h"
#include "translator.h"
#ifdef Q_OS_MACOS
#include "privileges_unix.h"
#else
#include "privileges.h"
#endif
// useful macro
#define isFilled() isEmpty() == false
class QThread;
class DiskWriter;
class DeviceEnumerator;
namespace Ui {
class Creator;
}
class Creator : public QDialog
{
Q_OBJECT
public:
explicit Creator(Privileges &priv, QWidget *parent = 0);
~Creator();
void setArgFile(QString argFile);
void retranslateUi();
private:
Ui::Creator *ui;
DownloadManager* manager;
Translator *translator;
void parseAndSetLinks(const QByteArray &data);
void saveAndUpdateProgress(QNetworkReply *reply);
void disableControls(const int which);
bool isChecksumValid(const QString);
QByteArray rangeByteArray(qlonglong first, qlonglong last);
QNetworkRequest createRequest(QUrl &url, qlonglong first, qlonglong last);
unsigned int getUncompressedImageSize();
void setImageFileName(QString filename);
QString getDefaultSaveDir();
bool showRootMessageBox();
enum {
DISABLE_CONTROL_DOWNLOAD,
DISABLE_CONTROL_WRITE
};
enum {
RESPONSE_OK = 200,
RESPONSE_PARTIAL = 206,
RESPONSE_FOUND = 302,
RESPONSE_REDIRECT = 307,
RESPONSE_BAD_REQUEST = 400,
RESPONSE_NOT_FOUND = 404
};
enum {
STATE_IDLE,
STATE_GET_VERSION,
STATE_GET_RELEASES,
STATE_DOWNLOADING_IMAGE,
STATE_WRITING_IMAGE
} state;
enum {
STACK_WIDGET_MAIN = 0,
STACK_WIDGET_ABOUT = 1
};
int timerId;
QTimer *devicesTimer;
qlonglong bytesDownloaded;
QString imageFileName;
QCryptographicHash imageHash;
QFile imageFile;
QString downloadUrl;
QString downloadFileSize;
QString checksum;
QString selectedImage;
QMap<QString, QString> checksumMap;
DiskWriter *diskWriter;
QThread* diskWriterThread;
DeviceEnumerator* devEnumerator;
static const int timerValue;
static const QString releasesUrl;
static const QString versionUrl;
static const QString helpUrl;
JsonParser *parserData;
QSettings settings;
QElapsedTimer speedTime;
qlonglong bytesLast;
MovingAverage *averageSpeed;
unsigned int uncompressedImageSize;
Privileges privileges;
QString deviceEjected;
bool showLoadEject;
protected:
void timerEvent(QTimerEvent *event) override;
void keyPressEvent(QKeyEvent *) override;
void closeEvent(QCloseEvent *) override;
void dragEnterEvent(QDragEnterEvent *e) override;
void dropEvent(QDropEvent *e) override;
void changeEvent(QEvent *e) override;
signals:
void proceedToWriteImageToDevice(const QString& image, const QString& device, const QString& deviceText);
void error(const QString& message);
private slots:
void httpsUrlHandler(const QUrl &url);
void ejectUSB();
void loadUSB();
void removeUSB();
void showHelp();
void showAbout();
void closeAbout();
void handleDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
void handleFinishedDownload(const QByteArray& data);
void handlePartialData(const QByteArray& data, qlonglong total);
void handleDownloadError(const QString);
void downloadVersionCheck();
void checkNewVersion(const QString &version);
void downloadReleases();
void parseJsonAndSet(const QByteArray &data);
void setProjectImages();
void projectImagesShowAllChanged(int state);
void projectImagesChanged(const QString& version);
void refreshRemovablesList();
void downloadButtonClicked();
void getImageFileNameFromUser();
void writeFlashButtonClicked();
void writingSyncing();
void writingFinished();
void writingError(QString);
void reset(const QString& message = "");
void resetProgressBars();
void savePreferredImage(const QString &version);
void savePreferredRemovableDevice(int idx);
void languageChange();
void downloadProgressBarText(const QString &text);
void flashProgressBarText(const QString &text);
void handleWriteProgress(int written);
};
#endif // CREATOR_H