#ifndef CHATROOM_H #define CHATROOM_H #include #include #include #include #include #include #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 updateUserList(QString userlist); 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 printQueue; list printServerQueue; list printStatusQueue; map activeChats; map inactiveChats; std::mutex chatMutex; unique_lock* 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); signals: void messagesToPrint(); void serverMessagesToPrint(); void statusMessagesToPrint(); void createChat(QString sender); void toggleConnected(bool status); }; void sendThread(Socket* s, Chatroom *chat); void recvThread(Socket *s, Chatroom *chat); #endif // CHATROOM_H