-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuploader.h
71 lines (55 loc) · 1.41 KB
/
uploader.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
#ifndef UPLOADER_H
#define UPLOADER_H
#include <QObject>
#include <QString>
#include <QStringList>
class QThread;
class QTimer;
class UploaderWorker;
/// Outcome of an upload.
enum UploadResult {
UploadComplete = 0, ///< All records uploaded.
UploadIncomplete, ///< Some records uploaded.
UploadFailed ///< Upload failed.
};
/// Upload interface.
class Uploader: public QObject {
Q_OBJECT
Q_PROPERTY(bool uploading READ uploading NOTIFY uploadingChanged)
signals:
void uploadingChanged(bool changed);
public:
static Uploader *instance();
static void close();
bool uploading();
public slots:
void upload();
protected:
explicit Uploader(QObject *parent = 0);
~Uploader();
UploaderWorker *worker;
QThread *workerThread;
bool uploading_;
QTimer *uploadTimer;
protected slots:
void onUploadComplete(int result);
};
/// Do the real uploading work.
class UploaderWorker: public QObject {
Q_OBJECT
signals:
void uploadComplete(int result);
public:
explicit UploaderWorker(QObject *parent = 0);
virtual ~UploaderWorker();
/// Delete records where upload is complete.
/// @return Qsee UploadResult.
int deleteUploadedRecords();
public slots:
/// Upload some data.
void upload();
/// An upload batch has finished.
/// @param complete @see UploadResult.
void onUploadFinished(int result);
};
#endif // UPLOADER_H