-
Notifications
You must be signed in to change notification settings - Fork 3
/
ChatClient.h
69 lines (59 loc) · 1.71 KB
/
ChatClient.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
#pragma once
#include <QtWidgets/QMainWindow>
#include <QStandardItemModel>
#include <QTcpSocket>
#include <QInputDialog>
#include <QMessageBox>
#include <QHostAddress>
#include <QTime>
#include <QUuid>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonParseError>
#include <QFile>
#include "entities.h"
#include "client.h"
#include "ui_ChatClient.h"
const QString CONFIG_FILE_PATH = "./config.json";
QT_BEGIN_NAMESPACE
namespace Ui { class ChatClientUi; };
QT_END_NAMESPACE
class ChatClient : public QMainWindow
{
Q_OBJECT
Q_DISABLE_COPY(ChatClient)
public:
explicit ChatClient(QWidget *parent = nullptr);
~ChatClient();
void startClient();
private:
Message createMessage(QString nickame, QString text);
//-------Config-file-functions-------
void loadConfig(QString _path);
void saveConfig(QString _path);
void configFromJson(const QJsonDocument& config_json_);
QJsonObject configToJson();
private slots:
void attemptConnection();
void connectedToServer();
void attemptLogin(const QString& userName);
void loggedIn();
void loginFailed(const QString& reason);
void messageReceived(const QString& sender, const QString& text);
void sendMessage();
void disconnectedFromServer();
void userJoined(const QString& username);
void userLeft(const QString& username);
void errorSlot(QAbstractSocket::SocketError socketError);
void keepCurrentConfig();
private:
Ui::ChatClientUi *ui;
Client* client;
QStandardItemModel* chat_model;
QString last_user_name;
QString server_address;
quint16 server_port;
quint16 flood_limit;
QString msg_history_path;
};