chatroom.h 1.2 KB
#ifndef CHATROOM_H
#define CHATROOM_H

#include <QMainWindow>
#include "Socket.h"
#include "loginscreen.h"
#include <thread>
#include <mutex>
#include <condition_variable>
#include "chatwindow.h"
#include <map>

namespace Ui {
class Chatroom;
}

class Chatroom : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit Chatroom(QWidget *parent = 0);
    bool getConnected();
    void setConnected(bool status);
    void relayMsg(string& msg);
    void setNickname(QString nick);
    QString getNickname();
    void putMsgToPrintQueue(string& msg);
    ~Chatroom();

public slots:
    void startSession();
    void sendMsg();
    void printMsg();

private slots:
    void finishThreads(bool exit);
    void finish();
    void disconnectChatroom();

signals:
    void threadsFinished(bool exit);
    void messagesToPrint();
    
private:
    Ui::Chatroom *ui;
    map<string,ChatWindow> activeChats;
    bool connected;
    string getSender(string& msg);
    void putMsgToSendQueue(QString& msg);
    std::thread *send;
    std::thread *recv;
    Socket s;
    QString nickname;
    list<string> printQueue;
};

void sendThread(Socket* s, Chatroom *chat);
void recvThread(Socket *s, Chatroom *chat);

#endif // CHATROOM_H