|
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
33
|
void setNickname(QString nick);
void updateUserList(QString userlist);
void relayMsg(string msg);
void removeChat(QString &nickname);
|
|
34
|
void putMsgToPrintQueue(string& msg, int type);
|
|
35
|
void putMsgToSendQueue(QString& msg);
|
|
36
|
~Chatroom();
|
|
37
|
|
|
38
39
40
41
42
43
44
45
|
private:
Ui::Chatroom *ui;
Socket s;
bool connected;
std::thread *send;
std::thread *recv;
QString nickname;
list<string> printQueue;
|
|
46
47
|
list<string> printServerQueue;
list<string> printStatusQueue;
|
|
48
|
map<string,void*> activeChats;
|
|
49
|
map<string,void*> inactiveChats;
|
|
50
51
52
53
|
std::mutex chatMutex;
unique_lock<std::mutex>* chatLock;
std::condition_variable chatCreated;
string getSender(string msg);
|
|
54
|
void freeChats(bool active);
|
|
55
56
57
58
|
protected:
void closeEvent(QCloseEvent *event);
|
|
59
60
61
|
public slots:
void startSession();
void sendMsg();
|
|
62
63
|
void disconnectChatroom();
void launchChatWindow(QModelIndex index);
|
|
64
|
void setConnected(bool status);
|
|
65
66
|
private slots:
|
|
67
68
69
70
|
void printMsg();
void printServerMsg();
void printStatusMsg();
void newChat(QString peerNick);
|
|
71
72
73
|
signals:
void messagesToPrint();
|
|
74
75
|
void serverMessagesToPrint();
void statusMessagesToPrint();
|
|
76
|
void createChat(QString sender);
|
|
77
|
void toggleConnected(bool status);
|
|
78
|
|
|
79
80
|
};
|
|
81
82
|
void sendThread(Socket* s, Chatroom *chat);
void recvThread(Socket *s, Chatroom *chat);
|
|
83
|
|
|
84
|
#endif // CHATROOM_H
|