-
Notifications
You must be signed in to change notification settings - Fork 4
/
upload_manager.h
66 lines (53 loc) · 1.49 KB
/
upload_manager.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
#ifndef UPLOAD_MANAGER_H
#define UPLOAD_MANAGER_H
#include <QObject>
#include <QMutex>
#include <QtNetwork/QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QJsonDocument>
#include "math.h"
#include "payload.h"
#define xstr(s) str(s)
#define str(s) #s
#define VERSION xstr(GIT_VERSION)
#define USER_AGENT "rgup " xstr(GIT_VERSION)
class UploadManager : public QObject
{
Q_OBJECT
public:
UploadManager(QObject* parent = 0);
void prepareUpload();
void startUpload();
QFile * upload_file;
Payload * payload;
QString session = "";
qint64 current_progress = 0;
QString current_progress_descr = "";
public slots:
void hostRequestFinished();
void sendFileRequestFinished();
void toggleUploadState();
void updateUploadList();
void updateUploadProgress(qint64 bytesSent, qint64 totalBytes);
signals:
void updatedCurrentUploadState();
private:
//Progressbar stuff
QDateTime start_date, last_date;
float maximum_speed, average_speed;
qint64 bytes_sent = 0;
QStringList suffixes;
//HTTP stuff
QNetworkAccessManager network_manager;
QNetworkReply * network_reply;
QJsonDocument json_document;
void startUploadSequence();
bool assignFileForUpload();
void sendFile();
void failCurrentUpload(QString message, bool startNext = true);
void setDefaultHeaders(QNetworkRequest * request);
bool parseResponse();
void recordSpeed(qint64 new_bytes_sent);
};
#endif // UPLOAD_MANAGER_H