Merge lp:~3v1n0/unity/session-labels-fix into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 3230
Proposed branch: lp:~3v1n0/unity/session-labels-fix
Merge into: lp:unity
Diff against target: 399 lines (+129/-39)
6 files modified
po/POTFILES.in (+1/-0)
shutdown/SessionButton.cpp (+35/-3)
shutdown/SessionButton.h (+13/-1)
shutdown/SessionView.cpp (+8/-8)
tests/test_session_button.cpp (+47/-2)
tests/test_session_view.cpp (+25/-25)
To merge this branch: bzr merge lp:~3v1n0/unity/session-labels-fix
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Andrea Azzarone (community) Approve
Review via email: mp+154113@code.launchpad.net

Commit message

SessionView: rename the Logout and Shutdown buttons as requested

Plus some code cleanup, using button-type to generate them instead of magic strings

Description of the change

Changed the labels of the session dialogs as requested by design. Also moved the textures/labels code generation to the SessionButton itself, that now can be generated by an Action type.

Added new tests, updating the old ones.

Screenshots:
http://ubuntuone.com/45dTsdpSJOKB1HEpVfyM69
http://ubuntuone.com/2DQ9uhmKOLLdJUCi1byYtQ

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'po/POTFILES.in'
2--- po/POTFILES.in 2013-03-07 22:48:41 +0000
3+++ po/POTFILES.in 2013-03-19 15:04:28 +0000
4@@ -33,6 +33,7 @@
5 shortcuts/ShortcutView.cpp
6 shortcuts/CompizShortcutModeller.cpp
7 shutdown/SessionView.cpp
8+shutdown/SessionButton.cpp
9 services/panel-service.c
10 unity-shared/DashStyle.cpp
11 unity-shared/SearchBar.cpp
12
13=== modified file 'shutdown/SessionButton.cpp'
14--- shutdown/SessionButton.cpp 2013-03-07 19:26:40 +0000
15+++ shutdown/SessionButton.cpp 2013-03-19 15:04:28 +0000
16@@ -22,7 +22,7 @@
17
18 #include <Nux/VLayout.h>
19 #include <UnityCore/Variant.h>
20-
21+#include <glib/gi18n-lib.h>
22
23 namespace unity
24 {
25@@ -38,15 +38,47 @@
26
27 NUX_IMPLEMENT_OBJECT_TYPE(Button);
28
29-Button::Button(std::string const& label, std::string const& texture_name, NUX_FILE_LINE_DECL)
30+Button::Button(Action action, NUX_FILE_LINE_DECL)
31 : nux::View(NUX_FILE_LINE_PARAM)
32 , highlighted(false)
33+ , action([this] { return action_; })
34 , label([this] { return label_view_->GetText(); })
35+ , action_(action)
36 {
37 SetAcceptKeyNavFocusOnMouseDown(false);
38 SetAcceptKeyNavFocusOnMouseEnter(true);
39
40- std::string texture_prefix = PKGDATADIR"/" + texture_name;
41+ std::string texture_prefix = PKGDATADIR"/";
42+ std::string label;
43+
44+ switch (action_)
45+ {
46+ case Action::LOCK:
47+ texture_prefix += "lockscreen";
48+ label = _("Lock");
49+ break;
50+ case Action::LOGOUT:
51+ texture_prefix += "logout";
52+ label = _("Log Out");
53+ break;
54+ case Action::SUSPEND:
55+ texture_prefix += "suspend";
56+ label = _("Suspend");
57+ break;
58+ case Action::HIBERNATE:
59+ texture_prefix += "hibernate";
60+ label = _("Hibernate");
61+ break;
62+ case Action::SHUTDOWN:
63+ texture_prefix += "shutdown";
64+ label = _("Shut Down");
65+ break;
66+ case Action::REBOOT:
67+ texture_prefix += "restart";
68+ label = _("Restart");
69+ break;
70+ }
71+
72 normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), -1, true));
73 highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), -1, true));
74
75
76=== modified file 'shutdown/SessionButton.h'
77--- shutdown/SessionButton.h 2013-03-07 19:26:40 +0000
78+++ shutdown/SessionButton.h 2013-03-19 15:04:28 +0000
79@@ -37,9 +37,20 @@
80 {
81 NUX_DECLARE_OBJECT_TYPE(Button, nux::View);
82 public:
83- Button(std::string const& label, std::string const& texture_name, NUX_FILE_LINE_PROTO);
84+ enum class Action
85+ {
86+ LOCK,
87+ LOGOUT,
88+ SUSPEND,
89+ HIBERNATE,
90+ SHUTDOWN,
91+ REBOOT
92+ };
93+
94+ Button(Action, NUX_FILE_LINE_PROTO);
95
96 nux::Property<bool> highlighted;
97+ nux::ROProperty<Action> action;
98 nux::ROProperty<std::string> label;
99
100 sigc::signal<void> activated;
101@@ -54,6 +65,7 @@
102 private:
103 friend class TestSessionButton;
104
105+ Action action_;
106 IconTexture* image_view_;
107 StaticCairoText* label_view_;
108 nux::ObjectPtr<nux::BaseTexture> normal_tex_;
109
110=== modified file 'shutdown/SessionView.cpp'
111--- shutdown/SessionView.cpp 2013-03-11 07:17:56 +0000
112+++ shutdown/SessionView.cpp 2013-03-19 15:04:28 +0000
113@@ -173,11 +173,11 @@
114
115 if (mode() == Mode::LOGOUT)
116 {
117- auto* button = new Button(_("Lock"), "lockscreen", NUX_TRACKER_LOCATION);
118+ auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
119 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
120 AddButton(button);
121
122- button = new Button(_("Logout"), "logout", NUX_TRACKER_LOCATION);
123+ button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);
124 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));
125 AddButton(button);
126 }
127@@ -185,20 +185,20 @@
128 {
129 if (mode() == Mode::FULL)
130 {
131- auto* button = new Button(_("Lock"), "lockscreen", NUX_TRACKER_LOCATION);
132+ auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
133 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
134 AddButton(button);
135
136 if (manager_->CanSuspend())
137 {
138- button = new Button(_("Suspend"), "suspend", NUX_TRACKER_LOCATION);
139+ button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION);
140 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend));
141 AddButton(button);
142 }
143
144 if (manager_->CanHibernate())
145 {
146- button = new Button(_("Hibernate"), "hibernate", NUX_TRACKER_LOCATION);
147+ button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);
148 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));
149 AddButton(button);
150 }
151@@ -206,17 +206,17 @@
152
153 if (manager_->CanShutdown())
154 {
155- auto* button = new Button(_("Shutdown"), "shutdown", NUX_TRACKER_LOCATION);
156+ auto* button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION);
157 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown));
158 AddButton(button);
159
160- button = new Button(_("Restart"), "restart", NUX_TRACKER_LOCATION);
161+ button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION);
162 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot));
163 AddButton(button);
164 }
165 else if (mode() == Mode::FULL)
166 {
167- auto* button = new Button(_("Logout"), "logout", NUX_TRACKER_LOCATION);
168+ auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);
169 button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));
170 AddButton(button);
171 }
172
173=== modified file 'tests/test_session_button.cpp'
174--- tests/test_session_button.cpp 2013-03-07 18:21:58 +0000
175+++ tests/test_session_button.cpp 2013-03-19 15:04:28 +0000
176@@ -31,7 +31,7 @@
177 {
178 struct ButtonWrap : Button
179 {
180- ButtonWrap() : Button("ButtonLabel", "hibernate") {}
181+ ButtonWrap() : Button(Action::LOCK) {}
182
183 using Button::AcceptKeyNavFocusOnMouseEnter;
184 using Button::AcceptKeyNavFocusOnMouseDown;
185@@ -46,8 +46,8 @@
186
187 TEST_F(TestSessionButton, Construct)
188 {
189+ EXPECT_EQ(button.action(), Button::Action::LOCK);
190 EXPECT_FALSE(button.highlighted());
191- EXPECT_EQ(button.label(), "ButtonLabel");
192 EXPECT_TRUE(button.AcceptKeyNavFocusOnMouseEnter());
193 EXPECT_FALSE(button.AcceptKeyNavFocusOnMouseDown());
194 }
195@@ -120,5 +120,50 @@
196 EXPECT_TRUE(activated);
197 }
198
199+// Action typed buttons tests
200+
201+struct ActionButton : public testing::TestWithParam<Button::Action> {
202+ ActionButton()
203+ : button(GetParam())
204+ {}
205+
206+ std::string GetExpectedLabel()
207+ {
208+ switch (GetParam())
209+ {
210+ case Button::Action::LOCK:
211+ return "Lock";
212+ case Button::Action::LOGOUT:
213+ return "Log Out";
214+ case Button::Action::SUSPEND:
215+ return "Suspend";
216+ case Button::Action::HIBERNATE:
217+ return "Hibernate";
218+ case Button::Action::SHUTDOWN:
219+ return "Shut Down";
220+ case Button::Action::REBOOT:
221+ return "Restart";
222+ }
223+
224+ return "";
225+ }
226+
227+ Button button;
228+};
229+
230+INSTANTIATE_TEST_CASE_P(TestSessionButtonTypes, ActionButton,
231+ testing::Values(Button::Action::LOCK, Button::Action::LOGOUT, Button::Action::SUSPEND,
232+ Button::Action::HIBERNATE, Button::Action::SHUTDOWN, Button::Action::REBOOT));
233+
234+TEST_P(/*TestSessionButtonTypes*/ActionButton, Label)
235+{
236+ EXPECT_EQ(button.label(), GetExpectedLabel());
237+}
238+
239+TEST_P(/*TestSessionButtonTypes*/ActionButton, Action)
240+{
241+ EXPECT_EQ(button.action(), GetParam());
242+}
243+
244 } // session
245 } // unity
246\ No newline at end of file
247
248=== modified file 'tests/test_session_view.cpp'
249--- tests/test_session_view.cpp 2013-03-07 22:42:29 +0000
250+++ tests/test_session_view.cpp 2013-03-19 15:04:28 +0000
251@@ -60,11 +60,11 @@
252 return buttons;
253 }
254
255- Button* GetButtonByLabel(std::string const& label) const
256+ Button* GetButtonByAction(Button::Action action) const
257 {
258 for (auto const& button : GetButtons())
259 {
260- if (button->label() == label)
261+ if (button->action() == action)
262 return button;
263 }
264
265@@ -129,29 +129,29 @@
266 ON_CALL(*manager, CanHibernate()).WillByDefault(testing::Return(true));
267 view.mode.changed.emit(View::Mode::FULL);
268
269- EXPECT_EQ(view.GetButtonByLabel("Logout"), nullptr);
270- EXPECT_NE(view.GetButtonByLabel("Lock"), nullptr);
271- EXPECT_NE(view.GetButtonByLabel("Suspend"), nullptr);
272- EXPECT_NE(view.GetButtonByLabel("Hibernate"), nullptr);
273- EXPECT_NE(view.GetButtonByLabel("Shutdown"), nullptr);
274- EXPECT_NE(view.GetButtonByLabel("Restart"), nullptr);
275+ EXPECT_EQ(view.GetButtonByAction(Button::Action::LOGOUT), nullptr);
276+ EXPECT_NE(view.GetButtonByAction(Button::Action::LOCK), nullptr);
277+ EXPECT_NE(view.GetButtonByAction(Button::Action::SUSPEND), nullptr);
278+ EXPECT_NE(view.GetButtonByAction(Button::Action::HIBERNATE), nullptr);
279+ EXPECT_NE(view.GetButtonByAction(Button::Action::SHUTDOWN), nullptr);
280+ EXPECT_NE(view.GetButtonByAction(Button::Action::REBOOT), nullptr);
281
282 ON_CALL(*manager, CanShutdown()).WillByDefault(testing::Return(false));
283 view.mode.changed.emit(View::Mode::FULL);
284
285- EXPECT_NE(view.GetButtonByLabel("Logout"), nullptr);
286- EXPECT_EQ(view.GetButtonByLabel("Shutdown"), nullptr);
287- EXPECT_EQ(view.GetButtonByLabel("Restart"), nullptr);
288+ EXPECT_NE(view.GetButtonByAction(Button::Action::LOGOUT), nullptr);
289+ EXPECT_EQ(view.GetButtonByAction(Button::Action::SHUTDOWN), nullptr);
290+ EXPECT_EQ(view.GetButtonByAction(Button::Action::REBOOT), nullptr);
291
292 ON_CALL(*manager, CanSuspend()).WillByDefault(testing::Return(false));
293 view.mode.changed.emit(View::Mode::FULL);
294
295- EXPECT_EQ(view.GetButtonByLabel("Suspend"), nullptr);
296+ EXPECT_EQ(view.GetButtonByAction(Button::Action::SUSPEND), nullptr);
297
298 ON_CALL(*manager, CanHibernate()).WillByDefault(testing::Return(false));
299 view.mode.changed.emit(View::Mode::FULL);
300
301- EXPECT_EQ(view.GetButtonByLabel("Hibernate"), nullptr);
302+ EXPECT_EQ(view.GetButtonByAction(Button::Action::HIBERNATE), nullptr);
303 }
304
305 TEST_F(TestSessionView, ShutdownModeButtons)
306@@ -160,8 +160,8 @@
307 view.mode = View::Mode::SHUTDOWN;
308
309 EXPECT_EQ(view.GetButtons().size(), 2);
310- EXPECT_NE(view.GetButtonByLabel("Shutdown"), nullptr);
311- EXPECT_NE(view.GetButtonByLabel("Restart"), nullptr);
312+ EXPECT_NE(view.GetButtonByAction(Button::Action::SHUTDOWN), nullptr);
313+ EXPECT_NE(view.GetButtonByAction(Button::Action::REBOOT), nullptr);
314 }
315
316 TEST_F(TestSessionView, LogoutModeButtons)
317@@ -169,8 +169,8 @@
318 view.mode = View::Mode::LOGOUT;
319
320 EXPECT_EQ(view.GetButtons().size(), 2);
321- EXPECT_NE(view.GetButtonByLabel("Logout"), nullptr);
322- EXPECT_NE(view.GetButtonByLabel("Lock"), nullptr);
323+ EXPECT_NE(view.GetButtonByAction(Button::Action::LOGOUT), nullptr);
324+ EXPECT_NE(view.GetButtonByAction(Button::Action::LOCK), nullptr);
325 }
326
327 TEST_F(TestSessionView, FullModeTitle)
328@@ -198,7 +198,7 @@
329 bool request_hide = false;
330 view.request_hide.connect([&request_hide] { request_hide = true; });
331
332- auto button = view.GetButtonByLabel("Lock");
333+ auto button = view.GetButtonByAction(Button::Action::LOCK);
334 ASSERT_NE(button, nullptr);
335 button->activated.emit();
336
337@@ -207,7 +207,7 @@
338
339 TEST_F(TestSessionView, ButtonsActivateDeselectButton)
340 {
341- auto button = view.GetButtonByLabel("Lock");
342+ auto button = view.GetButtonByAction(Button::Action::LOCK);
343 ASSERT_NE(button, nullptr);
344 button->highlighted = true;
345 button->activated.emit();
346@@ -218,7 +218,7 @@
347 TEST_F(TestSessionView, LockButtonActivateLocks)
348 {
349 EXPECT_CALL(*manager, LockScreen());
350- auto button = view.GetButtonByLabel("Lock");
351+ auto button = view.GetButtonByAction(Button::Action::LOCK);
352 ASSERT_NE(button, nullptr);
353 button->activated.emit();
354 }
355@@ -227,7 +227,7 @@
356 {
357 view.mode = View::Mode::LOGOUT;
358 EXPECT_CALL(*manager, Logout());
359- auto button = view.GetButtonByLabel("Logout");
360+ auto button = view.GetButtonByAction(Button::Action::LOGOUT);
361 ASSERT_NE(button, nullptr);
362 button->activated.emit();
363 }
364@@ -238,7 +238,7 @@
365 view.mode.changed.emit(View::Mode::FULL);
366
367 EXPECT_CALL(*manager, Suspend());
368- auto button = view.GetButtonByLabel("Suspend");
369+ auto button = view.GetButtonByAction(Button::Action::SUSPEND);
370 ASSERT_NE(button, nullptr);
371 button->activated.emit();
372 }
373@@ -249,7 +249,7 @@
374 view.mode.changed.emit(View::Mode::FULL);
375
376 EXPECT_CALL(*manager, Hibernate());
377- auto button = view.GetButtonByLabel("Hibernate");
378+ auto button = view.GetButtonByAction(Button::Action::HIBERNATE);
379 ASSERT_NE(button, nullptr);
380 button->activated.emit();
381 }
382@@ -260,7 +260,7 @@
383 view.mode = View::Mode::SHUTDOWN;
384
385 EXPECT_CALL(*manager, Shutdown());
386- auto button = view.GetButtonByLabel("Shutdown");
387+ auto button = view.GetButtonByAction(Button::Action::SHUTDOWN);
388 ASSERT_NE(button, nullptr);
389 button->activated.emit();
390 }
391@@ -271,7 +271,7 @@
392 view.mode = View::Mode::SHUTDOWN;
393
394 EXPECT_CALL(*manager, Reboot());
395- auto button = view.GetButtonByLabel("Restart");
396+ auto button = view.GetButtonByAction(Button::Action::REBOOT);
397 ASSERT_NE(button, nullptr);
398 button->activated.emit();
399 }