-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.h
executable file
·86 lines (66 loc) · 1.99 KB
/
connection.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
/*
* This file is part of community judge client project developed by Shervin Kh.
* Copyright (C) 2014 Shervin Kh.
* License: GPLv3 Or Later
* Full license could be found in License file shipped with program or at http://www.gnu.org/licenses/
*/
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QObject>
#include <QUrl>
#include <QSharedPointer>
#include <QMap>
#include <QVariant>
#include "general.h"
#include "mainwidget.h"
class QTcpSocket;
class QSslSocket;
class QProgressDialog;
class Connection : public QObject
{
Q_OBJECT
public:
enum class State {Disconnected, Connected, Connecting};
private:
QString address;
quint16 port;
bool isSsl;
int resCode;
QTcpSocket *curSocket;
QTcpSocket *tcpSocket;
QSslSocket *sslSocket;
QDataStream server;
QByteArray sendingData;
QByteArray receivedData;
bool busy;
bool aborted;
int length;
DataTable auth;
QProgressDialog *progress;
bool progressShown;
void handleProgress();
signals:
void data(StatCode, QByteArray);
void stateChanged();
void unsuccessfullyDone();
public:
explicit Connection(QObject *parent = Q_NULLPTR);
void send();
State giveState() const;
bool isBusy() const {return busy;}
void setAuth(const QMap<QString, QVariant> &in) {auth = in; auth["version"] = MainWidget::version();}
void setAddress(const QUrl &url) {address = url.host(); port = url.port(); isSsl = (url.scheme() == "ssl");}
QUrl currentAddress() const {QUrl url; url.setHost(address); url.setPort(port); url.setScheme(isSsl ? "ssl" : "tcp"); return url;}
QSharedPointer<QDataStream> prepare(QObject *receiver, const char *slot, QObject *receiverFailed = Q_NULLPTR,
const char *slotFailed = Q_NULLPTR);
void showProgressDialog();
private slots:
void phase1();
void readData();
void failure();
void success();
void done();
public slots:
void disconnectFromServer();
};
#endif // CONNECTION_H