34
const std::string FONT = "Ubuntu Light";
35
const std::string TITLE_FONT = FONT+" 15";
36
const std::string SUBTITLE_FONT = FONT+" 12";
35
std::string const FONT = "Ubuntu Light";
36
std::string const TITLE_FONT = FONT+" 15";
37
std::string const SUBTITLE_FONT = FONT+" 12";
38
const unsigned LEFT_RIGHT_PADDING = 30;
39
const unsigned TOP_PADDING = 19;
40
const unsigned BOTTOM_PADDING = 12;
41
const unsigned MAIN_SPACE = 10;
42
const unsigned BUTTONS_SPACE = 20;
39
RawPixel const LEFT_RIGHT_PADDING = 30_em;
40
RawPixel const TOP_PADDING = 19_em;
41
RawPixel const BOTTOM_PADDING = 12_em;
42
RawPixel const MAIN_SPACE = 10_em;
43
RawPixel const BUTTONS_SPACE = 20_em;
45
46
NUX_IMPLEMENT_OBJECT_TYPE(View);
51
52
, key_focus_area_(this)
54
auto main_layout = new nux::VLayout();
55
main_layout->SetTopAndBottomPadding(style::TOP_PADDING, style::BOTTOM_PADDING);
56
main_layout->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING);
57
main_layout->SetSpaceBetweenChildren(style::MAIN_SPACE);
58
SetLayout(main_layout);
55
main_layout_ = new nux::VLayout();
56
SetLayout(main_layout_);
60
58
title_ = new StaticCairoText("");
61
59
title_->SetFont(style::TITLE_FONT);
62
60
title_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
63
61
title_->SetInputEventSensitivity(false);
64
62
title_->SetVisible(false);
65
main_layout->AddView(title_);
63
main_layout_->AddView(title_);
67
65
subtitle_ = new StaticCairoText("");
68
66
subtitle_->SetFont(style::SUBTITLE_FONT);
70
68
subtitle_->SetInputEventSensitivity(false);
71
69
subtitle_->SetLines(std::numeric_limits<int>::min());
72
70
subtitle_->SetLineSpacing(2);
73
main_layout->AddView(subtitle_);
71
main_layout_->AddView(subtitle_);
75
73
buttons_layout_ = new nux::HLayout();
76
buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE);
77
main_layout->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f);
74
main_layout_->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f);
79
76
GetBoundingArea()->mouse_click.connect([this] (int, int, unsigned long, unsigned long) { request_close.emit(); });
81
78
have_inhibitors.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateText)));
79
manager_->have_other_open_sessions.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateText)));
83
81
mode.SetSetterFunction([this] (Mode& target, Mode new_mode) {
84
82
if (new_mode == Mode::SHUTDOWN && !manager_->CanShutdown())
99
scale.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateViewSize)));
106
void View::UpdateViewSize()
108
main_layout_->SetTopAndBottomPadding(style::TOP_PADDING.CP(scale()), style::BOTTOM_PADDING.CP(scale()));
109
main_layout_->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING.CP(scale()));
110
main_layout_->SetSpaceBetweenChildren(style::MAIN_SPACE.CP(scale()));
112
title_->SetScale(scale());
113
subtitle_->SetScale(scale());
115
ReloadCloseButtonTexture();
117
buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE.CP(scale()));
119
for (auto* area : buttons_layout_->GetChildren())
121
auto* button = static_cast<Button*>(area);
122
button->scale = scale();
105
126
void View::UpdateText()
107
const char* message = nullptr;
129
std::string other_users_msg;
108
130
auto const& real_name = manager_->RealName();
109
131
auto const& name = (real_name.empty() ? manager_->UserName() : real_name);
133
other_users_msg = _("Other users are logged in. Restarting or shutting down will close their open applications and may cause them to lose work.\n\n");
111
135
if (mode() == Mode::SHUTDOWN)
113
137
title_->SetText(_("Shut Down"));
114
138
title_->SetVisible(true);
140
if (manager_->have_other_open_sessions())
142
message += other_users_msg;
116
145
if (have_inhibitors())
118
message = _("Hi %s, you have open files that you might want to save " \
119
"before shutting down. Are you sure you want to continue?");
147
message += _("Hi %s, you have open files that you might want to save " \
148
"before shutting down. Are you sure you want to continue?");
123
message = _("Goodbye, %s. Are you sure you want to close all programs " \
124
"and shut down the computer?");
152
message += _("Goodbye, %s. Are you sure you want to close all programs " \
153
"and shut down the computer?");
127
156
else if (mode() == Mode::LOGOUT)
145
174
title_->SetVisible(false);
176
if (manager_->have_other_open_sessions())
178
message += other_users_msg;
147
181
if (have_inhibitors())
149
183
if (buttons_layout_->GetChildren().size() > 3)
151
185
// We have enough buttons to show the message without a new line.
152
message = _("Hi %s, you have open files you might want to save. " \
186
message += _("Hi %s, you have open files you might want to save. " \
153
187
"Would you like to…");
157
message = _("Hi %s, you have open files you might want to save.\n" \
191
message += _("Hi %s, you have open files you might want to save.\n" \
158
192
"Would you like to…");
163
message = _("Goodbye, %s. Would you like to…");
197
message += _("Goodbye, %s. Would you like to…");
167
subtitle_->SetText(glib::String(g_strdup_printf(message, name.c_str())).Str());
201
subtitle_->SetText(glib::String(g_strdup_printf(message.c_str(), name.c_str())).Str());
170
204
void View::Populate()
189
224
if (mode() == Mode::FULL)
191
226
auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
227
button->scale = scale();
192
228
button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
193
229
AddButton(button);
195
231
if (manager_->CanSuspend())
197
233
button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION);
234
button->scale = scale();
198
235
button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend));
199
236
AddButton(button);
210
248
if (manager_->CanShutdown())
212
250
auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION);
251
button->scale = scale();
213
252
button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot));
214
253
AddButton(button);
216
255
button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION);
256
button->scale = scale();
217
257
button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown));
218
258
key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_;
219
259
AddButton(button);