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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
#include "../include/UserSettingsWindow.hpp"
#include "../include/ChatWindow.hpp"
#include "../include/Window.hpp"
#include <gtkmm/button.h>
#include <gtkmm/togglebutton.h>
#include <gtkmm/button.h>
#include <gtkmm/paned.h>
#include <assert.h>
namespace dchat
{
UserSettingsWindow::UserSettingsWindow(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);
sidePanels->set_wide_handle(true);
attach(*sidePanels, 0, 0, 1, 1);
setupLeftPanel(sidePanels);
setupRightPanel(sidePanels);
set_vexpand(true);
set_hexpand(true);
}
void UserSettingsWindow::setAvatarUrl(const std::string &url)
{
avatarUrlEntry.set_text(url);
prevAvatarUrl = url;
}
void UserSettingsWindow::setNickname(const std::string &nickname)
{
nicknameEntry.set_text(nickname);
prevNickname = nickname;
}
void UserSettingsWindow::setupLeftPanel(Gtk::Paned *sidePanels)
{
Gtk::Grid *leftPanel = Gtk::manage(new Gtk::Grid());
leftPanel->set_vexpand(true);
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"));
leftPanel->attach_next_to(*returnToChatButton, *generalButton, Gtk::POS_BOTTOM, 1, 1);
returnToChatButton->signal_clicked().connect([this]
{
chatWindow->chatPage.show_all();
chatWindow->stack.set_visible_child("chat");
});
}
void UserSettingsWindow::setupRightPanel(Gtk::Paned *sidePanels)
{
Gtk::Grid *rightPanel = Gtk::manage(new Gtk::Grid());
rightPanel->get_style_context()->add_class("right-panel");
rightPanel->set_vexpand(true);
sidePanels->add2(*rightPanel);
Gtk::Label *nicknameLabel = Gtk::manage(new Gtk::Label("Nickname"));
nicknameLabel->set_valign(Gtk::ALIGN_START);
nicknameLabel->set_halign(Gtk::ALIGN_START);
rightPanel->attach(*nicknameLabel, 0, 0, 2, 1);
nicknameEntry.set_hexpand(true);
rightPanel->attach_next_to(nicknameEntry, *nicknameLabel, Gtk::POS_BOTTOM, 2, 1);
Gtk::Label *avatarUrlLabel = Gtk::manage(new Gtk::Label("Avatar url"));
avatarUrlLabel->set_halign(Gtk::ALIGN_START);
rightPanel->attach_next_to(*avatarUrlLabel, nicknameEntry, Gtk::POS_BOTTOM, 2, 1);
avatarUrlEntry.set_hexpand(true);
rightPanel->attach_next_to(avatarUrlEntry, *avatarUrlLabel, Gtk::POS_BOTTOM, 2, 1);
Gtk::Button *resetButton = Gtk::manage(new Gtk::Button("Rest"));
resetButton->set_halign(Gtk::ALIGN_END);
rightPanel->attach_next_to(*resetButton, avatarUrlEntry, Gtk::POS_BOTTOM, 1, 1);
resetButton->signal_clicked().connect([this]
{
avatarUrlEntry.set_text(prevAvatarUrl);
nicknameEntry.set_text(prevNickname);
});
Gtk::Button *saveButton = Gtk::manage(new Gtk::Button("Save"));
saveButton->set_halign(Gtk::ALIGN_END);
saveButton->get_style_context()->add_class("confirm-button");
rightPanel->attach_next_to(*saveButton, *resetButton, Gtk::POS_RIGHT, 1, 1);
saveButton->signal_clicked().connect([this]
{
Glib::ustring avatarUrl = avatarUrlEntry.get_text();
Glib::ustring nickname = nicknameEntry.get_text();
if(avatarUrl.size() < 5)
{
chatWindow->window->windowNotification->show("Invalid avatar url!");
return;
}
if(nickname.empty())
{
chatWindow->window->windowNotification->show("Invalid nickname!");
return;
}
bool changed = false;
if(avatarUrl != prevAvatarUrl)
{
prevAvatarUrl = avatarUrl;
chatWindow->currentRoom->setAvatarUrl(avatarUrl);
changed = true;
}
if(nickname != prevNickname)
{
prevNickname = nickname;
chatWindow->currentRoom->setNickname(nickname);
changed = true;
}
if(changed)
{
chatWindow->window->windowNotification->show("Saved changes!");
}
});
}
}
|