|
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
18
19
20
21
22
23
|
namespace Ui {
class Chatroom;
}
class Chatroom : public QMainWindow
{
Q_OBJECT
public:
explicit Chatroom(QWidget *parent = 0);
|
|
24
25
26
|
bool getConnected();
void setConnected(bool status);
QString getNickname();
|
|
27
28
29
30
|
void setNickname(QString nick);
void updateUserList(QString userlist);
void relayMsg(string msg);
void removeChat(QString &nickname);
|
|
31
|
void putMsgToPrintQueue(string& msg);
|
|
32
|
void putMsgToSendQueue(QString& msg);
|
|
33
|
~Chatroom();
|
|
34
|
|
|
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
private:
Ui::Chatroom *ui;
Socket s;
bool connected;
std::thread *send;
std::thread *recv;
QString nickname;
list<string> printQueue;
map<string,void*> activeChats;
std::mutex chatMutex;
unique_lock<std::mutex>* chatLock;
std::condition_variable chatCreated;
string getSender(string msg);
private slots:
void newChat(QString peerNick);
protected:
void closeEvent(QCloseEvent *event);
|
|
56
57
58
|
public slots:
void startSession();
void sendMsg();
|
|
59
60
|
void disconnectChatroom();
void launchChatWindow(QModelIndex index);
|
|
61
62
|
private slots:
|
|
63
|
void printMsg();
|
|
64
65
66
|
signals:
void messagesToPrint();
|
|
67
68
|
void createChat(QString sender);
|
|
69
70
|
};
|
|
71
72
|
void sendThread(Socket* s, Chatroom *chat);
void recvThread(Socket *s, Chatroom *chat);
|
|
73
|
|
|
74
|
#endif // CHATROOM_H
|