-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsclient.h
48 lines (36 loc) · 1.04 KB
/
wsclient.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
#ifndef WSCLIENT_H
#define WSCLIENT_H
#include <QObject>
#include <QtWebSockets/QtWebSockets>
#include <QMap>
#include <QMessageBox>
#include "constvariables.h"
enum MessageType { TREE_MSG, AUTH_MSG, COPY_MSG, UNKOWN };
class WsClient : public QObject
{
Q_OBJECT
public:
WsClient(QSettings *settings, QObject *parent = Q_NULLPTR);
void sendTextMessage(QString message);
void getTree();
int copyRequest(int start, int end, QString hash);
void authorization(QString name, QString password);
bool connectToServer();
Q_SIGNALS:
void onTreeChange(QJsonDocument json);
void onCopyMessage(QJsonDocument json);
void onAuthResponse(QJsonDocument json);
protected:
void onClosed();
void onConnected();
void onTextMessageReceived(QString message);
int generateMessageId();
void registerMessage(int id, MessageType type);
MessageType unregisterMessage(int id);
private:
QSettings *settings;
QWebSocket *websocket;
bool authStatus;
QMap<int, MessageType> messages;
};
#endif // WSCLIENT_H