Blame view

QChatClient/chatroom.h 1.77 KB
1
2
3
4
#ifndef CHATROOM_H
#define CHATROOM_H

#include <QMainWindow>
Imanol-Mikel Barba Sabariego authored
5
#include <QModelIndex>
6
7
8
9
#include <thread>
#include <mutex>
#include <condition_variable>
#include <map>
Imanol-Mikel Barba Sabariego authored
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();
Imanol-Mikel Barba Sabariego authored
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);
Imanol-Mikel Barba Sabariego authored
35
    void putMsgToSendQueue(QString& msg);
36
    ~Chatroom();
37
Imanol-Mikel Barba Sabariego authored
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;
Imanol-Mikel Barba Sabariego authored
48
49
50
51
52
53
54
55
56
    map<string,void*> activeChats;
    std::mutex chatMutex;
    unique_lock<std::mutex>* chatLock;
    std::condition_variable chatCreated;
    string getSender(string msg);

protected:
    void closeEvent(QCloseEvent *event);
57
58
59
public slots:
    void startSession();
    void sendMsg();
Imanol-Mikel Barba Sabariego authored
60
61
    void disconnectChatroom();
    void launchChatWindow(QModelIndex index);
62
    void setConnected(bool status);
63
64

private slots:
65
66
67
68
    void printMsg();
    void printServerMsg();
    void printStatusMsg();
    void newChat(QString peerNick);
69
70
71

signals:
    void messagesToPrint();
72
73
    void serverMessagesToPrint();
    void statusMessagesToPrint();
Imanol-Mikel Barba Sabariego authored
74
    void createChat(QString sender);
75
    void toggleConnected(bool status);
Imanol-Mikel Barba Sabariego authored
76
77
78
};
79
80
void sendThread(Socket* s, Chatroom *chat);
void recvThread(Socket *s, Chatroom *chat);
81
82
#endif // CHATROOM_H