aboutsummaryrefslogtreecommitdiff
path: root/include/ChatWindow.hpp
blob: b0f4001e77df6c0b211559f52f020965ac8fed4f (plain)
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
#pragma once

#include "ImageButton.hpp"
#include "RoomSettingsWindow.hpp"
#include "RoomNotificationsWindow.hpp"
#include <dchat/Room.hpp>
#include <gtkmm/label.h>
#include <gtkmm/radiobutton.h>
#include <gtkmm/grid.h>
#include <gtkmm/entry.h>
#include "ResponsivePaned.hpp"
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/stack.h>
#include <gtkmm/textview.h>
#include <odhtdb/Hash.hpp>
#include <odhtdb/Signature.hpp>

namespace dchat
{
    class ChatMessage;
    class Window;
    class Topbar;

    class ChatWindow : public Gtk::Grid
    {
    public:
        ChatWindow(Window *window);
        ~ChatWindow();
        void addRoom(std::shared_ptr<Room> room);
        void addMessage(const RoomAddMessageRequest &request);
        void addUser(const RoomAddUserRequest &request);
        void setUserNickname(const UserChangeNicknameRequest &request);
        void changeRoomName(const RoomChangeNameRequest &request);
        void addInviteRequest(const InviteUserRequest &request);
        void scrollToBottom();

        Topbar *topbar;
        Gtk::Stack stack;
        Gtk::Grid chatPage;
        RoomSettingsWindow roomSettingsWindow;
        RoomNotificationsWindow roomNotificationsWindow;
        Window *window;
    private:
        void setupTopbar();
        void setupLeftPanel(Gtk::ResponsivePaned *sidePanels);
        void setupMessageArea(Gtk::Grid *rightPanel);
        void setupChatInput(Gtk::Grid *rightPanel);

        void setCurrentRoom(std::shared_ptr<Room> room);
    private:
        Gtk::Grid leftPanelChannels;
        Gtk::Stack leftPanelUsersStack;
        ImageButton createRoomButton;
        ImageButton joinRoomButton;
        ImageButton userSettingsButton;
        Gtk::ScrolledWindow messageArea;
        Gtk::Stack messageAreaStack;
        Gtk::TextView chatInput;

        struct RoomData
        {
            Gtk::Grid *leftPanelUsersLayout;
            Gtk::Grid *messageAreaLayout;
            Gtk::RadioButton *button;
        };

        odhtdb::MapHash<RoomData*> roomDataById;
        odhtdb::MapHash<ChatMessage*> messageById;
        int chatPrevNumLines;
        int roomCount;
        RoomData *currentRoomData;
        std::shared_ptr<Room> currentRoom;
        bool chatInputShowPlaceholder;
        bool chatInputChangeByPlaceholder;
    };
}