-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpsender.h
More file actions
112 lines (91 loc) · 2.27 KB
/
httpsender.h
File metadata and controls
112 lines (91 loc) · 2.27 KB
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
/**
This file (c) by : - Martin Hammerchmidt alias Imote
This file is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
If you have contributed to this file, add your name to authors list.
*/
#ifndef HTTPSENDER_H
#define HTTPSENDER_H
#include <QObject>
#include <QHttpMultiPart>
#include <QHttpPart>
#include <QNetworkRequest>
#include <QUrl>
#include <QFile>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QString>
#include <QThread>
class HttpSender : public QThread
{
Q_OBJECT
public:
enum Status
{
FILE_ERROR,
NO_ERROR
};
HttpSender();
void run() Q_DECL_OVERRIDE
{
Status status = this->sendFile();
if(status == Status::NO_ERROR)
this->exec();
emit statusChanged(status);
}
public slots:
/** Upload settings setters **/
void setHost(QString const &host, int port)
{
url.setUrl(host);
url.setPort(port);
}
void setFile(QString const &pathToFile)
{
this->pathToFile = pathToFile;
}
void setPasteSettings(QByteArray const &lang, QString const &langHR)
{
this->lang = lang;
this->langHR = langHR;
}
void setUsername(QString const &username)
{
this->username = username;
}
void setPrivateKey(QString const &privateKey)
{
this->privateKey = privateKey;
}
void setUplimgVersion(QString const &uplimgVersion)
{
this->uplimgVersion = uplimgVersion;
}
QString getResponse()
{
return QString(reply->readAll());
}
signals:
void finished();
void uploadProgress(qint64 bytesSent, qint64 bytesTotal);
void error(QNetworkReply::NetworkError);
void statusChanged(Status);
protected:
Status sendFile();
QUrl url;
QString pathToFile;
QString username;
QString privateKey;
QString uplimgVersion;
QFile * file;
/* Paste specific */
QByteArray lang;
QString langHR;
/* internal network objects */
QNetworkReply * reply;
QNetworkAccessManager * manager;
QHttpMultiPart * container;
};
#endif // HTTPSENDER_H