|
1
2
3
4
|
#ifndef CHATROOM_H
#define CHATROOM_H
#include <QMainWindow>
|
|
5
|
#include <QModelIndex>
|
|
6
7
8
9
|
#include <thread>
#include <mutex>
#include <condition_variable>
#include <map>
|
|
10
11
12
|
#include "loginscreen.h"
#include "chatwindow.h"
#include "Socket.h"
|
|
13
|
|
|
14
15
16
17
|
#define MSG_USER 0
#define MSG_STATUS 1
#define MSG_SERVER 2
|
|
18
19
20
21
22
23
24
25
26
27
|
namespace Ui {
class Chatroom;
}
class Chatroom : public QMainWindow
{
Q_OBJECT
public:
explicit Chatroom(QWidget *parent = 0);
|
|
28
29
|
bool getConnected();
QString getNickname();
|
|
30
31
32
|
void setNickname(QString nick);
void relayMsg(string msg);
void removeChat(QString &nickname);
|
|
33
|
void putMsgToPrintQueue(string& msg, int type);
|
|
34
|
void putMsgToSendQueue(QString& msg);
|
|
35
|
~Chatroom();
|
|
36
|
|
|
37
38
39
40
41
42
43
44
|
private:
Ui::Chatroom *ui;
Socket s;
bool connected;
std::thread *send;
std::thread *recv;
QString nickname;
list<string> printQueue;
|
|
45
46
|
list<string> printServerQueue;
list<string> printStatusQueue;
|
|
47
|
map<string,void*> activeChats;
|
|
48
|
map<string,void*> inactiveChats;
|
|
49
50
51
52
|
std::mutex chatMutex;
unique_lock<std::mutex>* chatLock;
std::condition_variable chatCreated;
string getSender(string msg);
|
|
53
|
void freeChats(bool active);
|
|
54
55
56
57
|
protected:
void closeEvent(QCloseEvent *event);
|
|
58
59
60
|
public slots:
void startSession();
void sendMsg();
|
|
61
62
|
void disconnectChatroom();
void launchChatWindow(QModelIndex index);
|
|
63
|
void setConnected(bool status);
|
|
64
65
|
private slots:
|
|
66
67
68
69
|
void printMsg();
void printServerMsg();
void printStatusMsg();
void newChat(QString peerNick);
|
|
70
|
void updateUserList(QString userlist);
|
|
71
72
73
|
signals:
void messagesToPrint();
|
|
74
75
|
void serverMessagesToPrint();
void statusMessagesToPrint();
|
|
76
|
void createChat(QString sender);
|
|
77
|
void toggleConnected(bool status);
|
|
78
|
void newUsers(QString);
|
|
79
|
|
|
80
81
|
};
|
|
82
83
|
void sendThread(Socket* s, Chatroom *chat);
void recvThread(Socket *s, Chatroom *chat);
|
|
84
|
|
|
85
|
#endif // CHATROOM_H
|