-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.h
97 lines (69 loc) · 2.47 KB
/
mainwindow.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
87
88
89
90
91
92
93
94
95
96
97
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "peer.h"
#include "message.h"
#include <ctime>
#include <QtWidgets>
#include <QtNetwork>
#include <QVector>
#include <QList>
#include <QKeyEvent>
#include <QTimer>
class MainWindow : public QWidget
{
Q_OBJECT
typedef QVector< QPair<time_t, QString> > HistoryType;
static const int PORT = 3141;
static const int SEND_INTERVAL = 1000; // 1000 ms = 1 s
static const int HELLO_INTERVAL = 10 * 1000; // 10 s
static const int KEEPALIVE_INTERVAL = 2 * 60 * 1000; // 2 min
static const int DELIEVER_INTERVAL = 60 * 1000; // 1 min
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
private:
// events:
void keyPressEvent(QKeyEvent *event);
// methods:
QString askUserForNickname();
void addSystemMessageToWidget(QString message);
void addMessageToWidget(QString author, QString message);
void sendString(QString what, QHostAddress where);
void sendToEverybody(QString what);
bool addToChatHistory(time_t time, QString author, QString msg);
void updateUserListWidget();
QString responseString();
private slots:
void sendButtonPressed();
void sendTimerExpired();
void handleSocketMessage();
void sendHello();
void sendResponse(QHostAddress to_whom);
void sendJoin(QString newcomer_nickname, QHostAddress newcomer_address);
void sendMessage(time_t time, QString msg);
void sendMessage(Message msg);
void sendAccepted(QHostAddress to_whom, QString nickname, time_t time);
void sendKeepalive();
void sendQuit();
void delieverMessages();
void delieverConfirmed(QString nickname, time_t time);
void addPeerToList(QString nickname, QHostAddress address);
void keepPeerAlive(QHostAddress peer_address);
void removePeerFromList(QHostAddress peer_address);
private:
QPushButton *send_button;
QTextEdit *messages_widget;
QLineEdit *input_line;
QListWidget *user_list_widget;
QTimer *send_timer;
QTimer *hello_timer;
QTimer *keepalive_timer;
QTimer *deliver_timer;
QUdpSocket *socket;
QString my_nickname;
QHostAddress my_address;
QList<Peer*> peer_list;
HistoryType chat_history;
QList<Message> undelivered_messages;
};
#endif // MAINWINDOW_H