aboutsummaryrefslogtreecommitdiff
path: root/src/RoomSettingsWindow.cpp
blob: e20e36ed18728c99661d3b945fba7fa4514cb58a (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
77
78
79
80
81
82
83
84
85
86
87
88
#include "../include/RoomSettingsWindow.hpp"
#include "../include/ChatWindow.hpp"
#include <gtkmm/button.h>
#include <gtkmm/togglebutton.h>
#include <gtkmm/clipboard.h>
#include <gtkmm/paned.h>
#include <assert.h>

namespace dchat
{
    RoomSettingsWindow::RoomSettingsWindow(ChatWindow *_chatWindow) : 
        chatWindow(_chatWindow)
    {
        assert(chatWindow);
        Gtk::Paned *sidePanels = Gtk::manage(new Gtk::Paned(Gtk::ORIENTATION_HORIZONTAL));
        sidePanels->get_style_context()->add_class("side-panels");
        sidePanels->set_vexpand(true);
        sidePanels->set_hexpand(true);
        attach(*sidePanels, 0, 0, 1, 1);

        setupLeftPanel(sidePanels);
        setupRightPanel(sidePanels);

        set_vexpand(true);
        set_hexpand(true);
    }

    void RoomSettingsWindow::selectRoom(std::shared_ptr<Room> room)
    {
        roomNameEntry.set_text(room->name);
        inviteKey.set_text(room->inviteKey);
    }

    void RoomSettingsWindow::setupLeftPanel(Gtk::Paned *sidePanels)
    {
        Gtk::Grid *leftPanel = Gtk::manage(new Gtk::Grid());
        leftPanel->set_vexpand(true);
        leftPanel->set_valign(Gtk::ALIGN_START);
        leftPanel->set_halign(Gtk::ALIGN_START);
        leftPanel->set_size_request(200);
        leftPanel->get_style_context()->add_class("left-panel");
        sidePanels->add1(*leftPanel);

        Gtk::Label *settingsLabel = Gtk::manage(new Gtk::Label("Settings"));
        leftPanel->attach(*settingsLabel, 0, 0, 1, 1);

        Gtk::ToggleButton *generalButton = Gtk::manage(new Gtk::ToggleButton("General"));
        leftPanel->attach_next_to(*generalButton, *settingsLabel, Gtk::POS_BOTTOM, 1, 1);

        Gtk::ToggleButton *returnToChatButton = Gtk::manage(new Gtk::ToggleButton("Return to chat"));
        returnToChatButton->signal_clicked().connect([this]
        {
            chatWindow->chatPage.show_all();
            chatWindow->stack.set_visible_child("chat");
        });
        leftPanel->attach_next_to(*returnToChatButton, *generalButton, Gtk::POS_BOTTOM, 1, 1);
    }

    void RoomSettingsWindow::setupRightPanel(Gtk::Paned *sidePanels)
    {
        Gtk::Grid *rightPanel = Gtk::manage(new Gtk::Grid());
        rightPanel->set_vexpand(true);
        rightPanel->set_valign(Gtk::ALIGN_START);
        rightPanel->set_halign(Gtk::ALIGN_START);
        sidePanels->add2(*rightPanel);

        Gtk::Label *roomNameLabel = Gtk::manage(new Gtk::Label("Room name"));
        rightPanel->attach(*roomNameLabel, 0, 0, 1, 1);

        roomNameEntry.set_editable(false);
        rightPanel->attach_next_to(roomNameEntry, *roomNameLabel, Gtk::POS_BOTTOM, 1, 1);

        Gtk::Label *inviteKeyLabel = Gtk::manage(new Gtk::Label("Invite key"));
        rightPanel->attach_next_to(*inviteKeyLabel, roomNameEntry, Gtk::POS_BOTTOM, 1, 1);

        inviteKey.set_selectable(true);
        inviteKey.set_line_wrap(true);
        inviteKey.set_line_wrap_mode(Pango::WRAP_WORD_CHAR);
        rightPanel->attach_next_to(inviteKey, *inviteKeyLabel, Gtk::POS_BOTTOM, 1, 1);

        Gtk::Button *copyInviteKeyButton = Gtk::manage(new Gtk::Button("_Copy", true));
        copyInviteKeyButton->signal_clicked().connect([this]
        {
            Gtk::Clipboard::get()->set_text(inviteKey.get_text());
        });
        rightPanel->attach_next_to(*copyInviteKeyButton, inviteKey, Gtk::POS_RIGHT, 1, 1);
    }
}