chatroom.h
1.87 KB
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
#ifndef CHATROOM_H
#define CHATROOM_H
#include <QMainWindow>
#include <QModelIndex>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <map>
#include "loginscreen.h"
#include "chatwindow.h"
#include "Socket.h"
#define MSG_USER 0
#define MSG_STATUS 1
#define MSG_SERVER 2
namespace Ui {
class Chatroom;
}
class Chatroom : public QMainWindow
{
Q_OBJECT
public:
explicit Chatroom(QWidget *parent = 0);
bool getConnected();
QString getNickname();
void setNickname(QString nick);
void relayMsg(string msg);
void removeChat(QString &nickname);
void putMsgToPrintQueue(string& msg, int type);
void putMsgToSendQueue(QString& msg);
~Chatroom();
private:
Ui::Chatroom *ui;
Socket s;
bool connected;
std::thread *send;
std::thread *recv;
QString nickname;
list<string> printQueue;
list<string> printServerQueue;
list<string> printStatusQueue;
map<string,void*> activeChats;
map<string,void*> inactiveChats;
std::mutex chatMutex;
unique_lock<std::mutex>* chatLock;
std::condition_variable chatCreated;
string getSender(string msg);
void freeChats(bool active);
protected:
void closeEvent(QCloseEvent *event);
public slots:
void startSession();
void sendMsg();
void disconnectChatroom();
void launchChatWindow(QModelIndex index);
void setConnected(bool status);
private slots:
void printMsg();
void printServerMsg();
void printStatusMsg();
void newChat(QString peerNick);
void updateUserList(QString userlist);
signals:
void messagesToPrint();
void serverMessagesToPrint();
void statusMessagesToPrint();
void createChat(QString sender);
void toggleConnected(bool status);
void newUsers(QString);
};
void sendThread(Socket* s, Chatroom *chat);
void recvThread(Socket *s, Chatroom *chat);
#endif // CHATROOM_H