Merge lp:~azzar1/unity/lockscreen-warning-after-authentication into lp:unity
- lockscreen-warning-after-authentication
- Merge into trunk
Proposed by
Andrea Azzarone
Status: | Merged |
---|---|
Approved by: | Marco Trevisan (Treviño) |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4134 |
Proposed branch: | lp:~azzar1/unity/lockscreen-warning-after-authentication |
Merge into: | lp:unity |
Prerequisite: | lp:~azzar1/unity/option-lockscreen-account-checking |
Diff against target: |
589 lines (+385/-14) 7 files modified
lockscreen/CMakeLists.txt (+1/-0) lockscreen/LockScreenButton.cpp (+148/-0) lockscreen/LockScreenButton.h (+70/-0) lockscreen/UserPromptView.cpp (+113/-13) lockscreen/UserPromptView.h (+9/-1) unity-shared/DashStyle.cpp (+39/-0) unity-shared/DashStyle.h (+5/-0) |
To merge this branch: | bzr merge lp:~azzar1/unity/lockscreen-warning-after-authentication |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marco Trevisan (Treviño) | Approve | ||
PS Jenkins bot | continuous-integration | Pending | |
Review via email: mp+298232@code.launchpad.net |
Commit message
Lockscreen: Make sure warning and errors are properly shown to the user
Description of the change
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lockscreen/CMakeLists.txt' | |||
2 | --- lockscreen/CMakeLists.txt 2016-03-31 09:59:30 +0000 | |||
3 | +++ lockscreen/CMakeLists.txt 2016-06-23 14:53:05 +0000 | |||
4 | @@ -23,6 +23,7 @@ | |||
5 | 23 | KylinLockScreenShield.cpp | 23 | KylinLockScreenShield.cpp |
6 | 24 | LockScreenController.cpp | 24 | LockScreenController.cpp |
7 | 25 | LockScreenBaseShield.cpp | 25 | LockScreenBaseShield.cpp |
8 | 26 | LockScreenButton.cpp | ||
9 | 26 | LockScreenSettings.cpp | 27 | LockScreenSettings.cpp |
10 | 27 | LockScreenShield.cpp | 28 | LockScreenShield.cpp |
11 | 28 | LockScreenShieldFactory.cpp | 29 | LockScreenShieldFactory.cpp |
12 | 29 | 30 | ||
13 | === added file 'lockscreen/LockScreenButton.cpp' | |||
14 | --- lockscreen/LockScreenButton.cpp 1970-01-01 00:00:00 +0000 | |||
15 | +++ lockscreen/LockScreenButton.cpp 2016-06-23 14:53:05 +0000 | |||
16 | @@ -0,0 +1,148 @@ | |||
17 | 1 | /* | ||
18 | 2 | * Copyright 2016 Canonical Ltd. | ||
19 | 3 | * | ||
20 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
21 | 5 | * under the terms of the GNU Lesser General Public License version 3, as | ||
22 | 6 | * published by the Free Software Foundation. | ||
23 | 7 | * | ||
24 | 8 | * This program is distributed in the hope that it will be useful, but | ||
25 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
26 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR | ||
27 | 11 | * PURPOSE. See the applicable version of the GNU Lesser General Public | ||
28 | 12 | * License for more details. | ||
29 | 13 | * | ||
30 | 14 | * You should have received a copy of both the GNU Lesser General Public | ||
31 | 15 | * License version 3 along with this program. If not, see | ||
32 | 16 | * <http://www.gnu.org/licenses/> | ||
33 | 17 | * | ||
34 | 18 | * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> | ||
35 | 19 | * | ||
36 | 20 | */ | ||
37 | 21 | |||
38 | 22 | #include "LockScreenButton.h" | ||
39 | 23 | |||
40 | 24 | #include <Nux/HLayout.h> | ||
41 | 25 | |||
42 | 26 | #include "unity-shared/DashStyle.h" | ||
43 | 27 | #include "unity-shared/IconTexture.h" | ||
44 | 28 | #include "LockScreenSettings.h" | ||
45 | 29 | |||
46 | 30 | namespace unity | ||
47 | 31 | { | ||
48 | 32 | namespace lockscreen | ||
49 | 33 | { | ||
50 | 34 | |||
51 | 35 | namespace | ||
52 | 36 | { | ||
53 | 37 | const RawPixel HLAYOUT_RIGHT_PADDING = 10_em; | ||
54 | 38 | const int FONT_PX_SIZE = 17; | ||
55 | 39 | } | ||
56 | 40 | |||
57 | 41 | NUX_IMPLEMENT_OBJECT_TYPE(LockScreenButton); | ||
58 | 42 | |||
59 | 43 | LockScreenButton::LockScreenButton(std::string const& label, NUX_FILE_LINE_DECL) | ||
60 | 44 | : nux::Button(NUX_FILE_LINE_PARAM) | ||
61 | 45 | , scale(1.0) | ||
62 | 46 | , label_(label) | ||
63 | 47 | { | ||
64 | 48 | hlayout_ = new nux::HLayout(NUX_TRACKER_LOCATION); | ||
65 | 49 | hlayout_->SetLeftAndRightPadding(0, HLAYOUT_RIGHT_PADDING.CP(scale)); | ||
66 | 50 | hlayout_->SetContentDistribution(nux::MAJOR_POSITION_END); | ||
67 | 51 | SetLayout(hlayout_); | ||
68 | 52 | |||
69 | 53 | activator_ = new IconTexture(dash::Style::Instance().GetLockScreenActivator(scale())); | ||
70 | 54 | hlayout_->AddView(activator_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); | ||
71 | 55 | |||
72 | 56 | InitTheme(); | ||
73 | 57 | |||
74 | 58 | scale.changed.connect([this] (double scale) { | ||
75 | 59 | activator_->SetTexture(dash::Style::Instance().GetLockScreenActivator(scale)); | ||
76 | 60 | hlayout_->SetLeftAndRightPadding(0, HLAYOUT_RIGHT_PADDING.CP(scale)); | ||
77 | 61 | InitTheme(); | ||
78 | 62 | }); | ||
79 | 63 | |||
80 | 64 | key_down.connect([this] (unsigned long, unsigned long, unsigned long, const char*, unsigned short) { | ||
81 | 65 | state_change.emit(this); | ||
82 | 66 | }); | ||
83 | 67 | } | ||
84 | 68 | |||
85 | 69 | void LockScreenButton::InitTheme() | ||
86 | 70 | { | ||
87 | 71 | SetMinimumHeight(Settings::GRID_SIZE.CP(scale)); | ||
88 | 72 | SetMaximumHeight(Settings::GRID_SIZE.CP(scale)); | ||
89 | 73 | |||
90 | 74 | nux::Geometry const& geo = GetGeometry(); | ||
91 | 75 | normal_.reset(new nux::CairoWrapper(geo, sigc::mem_fun(this, &LockScreenButton::RedrawTheme))); | ||
92 | 76 | } | ||
93 | 77 | |||
94 | 78 | void LockScreenButton::RedrawTheme(nux::Geometry const& geom, cairo_t* cr) | ||
95 | 79 | { | ||
96 | 80 | cairo_surface_set_device_scale(cairo_get_target(cr), scale, scale); | ||
97 | 81 | dash::Style::Instance().LockScreenButton(cr, label_, FONT_PX_SIZE); | ||
98 | 82 | } | ||
99 | 83 | |||
100 | 84 | long LockScreenButton::ComputeContentSize() | ||
101 | 85 | { | ||
102 | 86 | long ret = nux::Button::ComputeContentSize(); | ||
103 | 87 | nux::Geometry const& geo = GetGeometry(); | ||
104 | 88 | |||
105 | 89 | if (cached_geometry_ != geo) | ||
106 | 90 | { | ||
107 | 91 | normal_->Invalidate(geo); | ||
108 | 92 | cached_geometry_ = geo; | ||
109 | 93 | } | ||
110 | 94 | |||
111 | 95 | return ret; | ||
112 | 96 | } | ||
113 | 97 | |||
114 | 98 | void LockScreenButton::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) | ||
115 | 99 | { | ||
116 | 100 | if (IsFullRedraw()) | ||
117 | 101 | { | ||
118 | 102 | GfxContext.PushClippingRectangle(GetGeometry()); | ||
119 | 103 | hlayout_->ProcessDraw(GfxContext, force_draw); | ||
120 | 104 | GfxContext.PopClippingRectangle(); | ||
121 | 105 | } | ||
122 | 106 | } | ||
123 | 107 | |||
124 | 108 | void LockScreenButton::Draw(nux::GraphicsEngine& GfxContext, bool force_draw) | ||
125 | 109 | { | ||
126 | 110 | nux::Geometry const& geo = GetGeometry(); | ||
127 | 111 | GfxContext.PushClippingRectangle(geo); | ||
128 | 112 | gPainter.PaintBackground(GfxContext, geo); | ||
129 | 113 | |||
130 | 114 | nux::TexCoordXForm texxform; | ||
131 | 115 | texxform.SetWrap(nux::TEXWRAP_CLAMP, nux::TEXWRAP_CLAMP); | ||
132 | 116 | texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD); | ||
133 | 117 | |||
134 | 118 | unsigned int alpha = 0, src = 0, dest = 0; | ||
135 | 119 | GfxContext.GetRenderStates().GetBlend(alpha, src, dest); | ||
136 | 120 | GfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); | ||
137 | 121 | GfxContext.GetRenderStates().SetBlend(true); | ||
138 | 122 | |||
139 | 123 | nux::Color col(nux::color::Black); | ||
140 | 124 | col.alpha = 0; | ||
141 | 125 | GfxContext.QRP_Color(geo.x, geo.y, | ||
142 | 126 | geo.width, geo.height, | ||
143 | 127 | col); | ||
144 | 128 | |||
145 | 129 | nux::BaseTexture* texture = normal_->GetTexture(); | ||
146 | 130 | GfxContext.QRP_1Tex(geo.x, geo.y, | ||
147 | 131 | texture->GetWidth(), texture->GetHeight(), | ||
148 | 132 | texture->GetDeviceTexture(), | ||
149 | 133 | texxform, nux::color::White); | ||
150 | 134 | |||
151 | 135 | GfxContext.GetRenderStates().SetBlend(alpha, src, dest); | ||
152 | 136 | GfxContext.PopClippingRectangle(); | ||
153 | 137 | } | ||
154 | 138 | |||
155 | 139 | bool LockScreenButton::InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character) | ||
156 | 140 | { | ||
157 | 141 | if ((eventType == nux::NUX_KEYDOWN) && (key_sym == NUX_VK_ENTER)) | ||
158 | 142 | return true; | ||
159 | 143 | else | ||
160 | 144 | return false; | ||
161 | 145 | } | ||
162 | 146 | |||
163 | 147 | } // namespace lockscreen | ||
164 | 148 | } // namespace unity | ||
165 | 0 | \ No newline at end of file | 149 | \ No newline at end of file |
166 | 1 | 150 | ||
167 | === added file 'lockscreen/LockScreenButton.h' | |||
168 | --- lockscreen/LockScreenButton.h 1970-01-01 00:00:00 +0000 | |||
169 | +++ lockscreen/LockScreenButton.h 2016-06-23 14:53:05 +0000 | |||
170 | @@ -0,0 +1,70 @@ | |||
171 | 1 | /* | ||
172 | 2 | * Copyright 2016 Canonical Ltd. | ||
173 | 3 | * | ||
174 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
175 | 5 | * under the terms of the GNU Lesser General Public License version 3, as | ||
176 | 6 | * published by the Free Software Foundation. | ||
177 | 7 | * | ||
178 | 8 | * This program is distributed in the hope that it will be useful, but | ||
179 | 9 | * WITHOUT ANY WARRANTY; without even the implied warranties of | ||
180 | 10 | * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR | ||
181 | 11 | * PURPOSE. See the applicable version of the GNU Lesser General Public | ||
182 | 12 | * License for more details. | ||
183 | 13 | * | ||
184 | 14 | * You should have received a copy of both the GNU Lesser General Public | ||
185 | 15 | * License version 3 along with this program. If not, see | ||
186 | 16 | * <http://www.gnu.org/licenses/> | ||
187 | 17 | * | ||
188 | 18 | * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> | ||
189 | 19 | * | ||
190 | 20 | */ | ||
191 | 21 | |||
192 | 22 | #ifndef UNITY_LOCKSCREEN_BUTTON_H | ||
193 | 23 | #define UNITY_LOCKSCREEN_BUTTON_H | ||
194 | 24 | |||
195 | 25 | #include <Nux/Nux.h> | ||
196 | 26 | #include <Nux/Button.h> | ||
197 | 27 | #include <Nux/CairoWrapper.h> | ||
198 | 28 | |||
199 | 29 | namespace unity | ||
200 | 30 | { | ||
201 | 31 | |||
202 | 32 | class IconTexture; | ||
203 | 33 | |||
204 | 34 | namespace lockscreen | ||
205 | 35 | { | ||
206 | 36 | |||
207 | 37 | class LockScreenButton : public nux::Button | ||
208 | 38 | { | ||
209 | 39 | NUX_DECLARE_OBJECT_TYPE(LockScreenButton, nux::Button); | ||
210 | 40 | |||
211 | 41 | public: | ||
212 | 42 | LockScreenButton(std::string const&, NUX_FILE_LINE_PROTO); | ||
213 | 43 | |||
214 | 44 | nux::Property<double> scale; | ||
215 | 45 | |||
216 | 46 | protected: | ||
217 | 47 | long ComputeContentSize() override; | ||
218 | 48 | void Draw(nux::GraphicsEngine&, bool) override; | ||
219 | 49 | void DrawContent(nux::GraphicsEngine&, bool) override; | ||
220 | 50 | bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character) override; | ||
221 | 51 | |||
222 | 52 | private: | ||
223 | 53 | void InitTheme(); | ||
224 | 54 | void RedrawTheme(nux::Geometry const&, cairo_t*); | ||
225 | 55 | |||
226 | 56 | typedef std::unique_ptr<nux::CairoWrapper> NuxCairoPtr; | ||
227 | 57 | |||
228 | 58 | std::string label_; | ||
229 | 59 | nux::Geometry cached_geometry_; | ||
230 | 60 | |||
231 | 61 | NuxCairoPtr normal_; | ||
232 | 62 | |||
233 | 63 | nux::HLayout* hlayout_; | ||
234 | 64 | IconTexture* activator_; | ||
235 | 65 | }; | ||
236 | 66 | |||
237 | 67 | } // namespace lockscreen | ||
238 | 68 | } // namespace unity | ||
239 | 69 | |||
240 | 70 | #endif | ||
241 | 0 | 71 | ||
242 | === modified file 'lockscreen/UserPromptView.cpp' | |||
243 | --- lockscreen/UserPromptView.cpp 2016-03-16 10:47:16 +0000 | |||
244 | +++ lockscreen/UserPromptView.cpp 2016-06-23 14:53:05 +0000 | |||
245 | @@ -26,6 +26,7 @@ | |||
246 | 26 | #include <Nux/VLayout.h> | 26 | #include <Nux/VLayout.h> |
247 | 27 | 27 | ||
248 | 28 | #include "LockScreenSettings.h" | 28 | #include "LockScreenSettings.h" |
249 | 29 | #include "LockScreenButton.h" | ||
250 | 29 | #include "unity-shared/CairoTexture.h" | 30 | #include "unity-shared/CairoTexture.h" |
251 | 30 | #include "unity-shared/TextInput.h" | 31 | #include "unity-shared/TextInput.h" |
252 | 31 | #include "unity-shared/StaticCairoText.h" | 32 | #include "unity-shared/StaticCairoText.h" |
253 | @@ -41,6 +42,7 @@ | |||
254 | 41 | const RawPixel LAYOUT_MARGIN = 10_em; | 42 | const RawPixel LAYOUT_MARGIN = 10_em; |
255 | 42 | const RawPixel MSG_LAYOUT_MARGIN = 15_em; | 43 | const RawPixel MSG_LAYOUT_MARGIN = 15_em; |
256 | 43 | const RawPixel PROMPT_LAYOUT_MARGIN = 5_em; | 44 | const RawPixel PROMPT_LAYOUT_MARGIN = 5_em; |
257 | 45 | const RawPixel BUTTON_LAYOUT_MARGIN = 5_em; | ||
258 | 44 | const int PROMPT_FONT_SIZE = 13; | 46 | const int PROMPT_FONT_SIZE = 13; |
259 | 45 | 47 | ||
260 | 46 | nux::AbstractPaintLayer* CrateBackgroundLayer(double width, double height, double scale) | 48 | nux::AbstractPaintLayer* CrateBackgroundLayer(double width, double height, double scale) |
261 | @@ -105,20 +107,29 @@ | |||
262 | 105 | , username_(nullptr) | 107 | , username_(nullptr) |
263 | 106 | , msg_layout_(nullptr) | 108 | , msg_layout_(nullptr) |
264 | 107 | , prompt_layout_(nullptr) | 109 | , prompt_layout_(nullptr) |
265 | 110 | , button_layout_(nullptr) | ||
266 | 111 | , prompted_(false) | ||
267 | 112 | , unacknowledged_messages_(false) | ||
268 | 108 | { | 113 | { |
269 | 109 | user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){ | 114 | user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){ |
270 | 115 | prompted_ = true; | ||
271 | 116 | unacknowledged_messages_ = false; | ||
272 | 110 | AddPrompt(message, /* visible */ true, promise); | 117 | AddPrompt(message, /* visible */ true, promise); |
273 | 111 | }); | 118 | }); |
274 | 112 | 119 | ||
275 | 113 | user_authenticator_.echo_off_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){ | 120 | user_authenticator_.echo_off_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){ |
276 | 121 | prompted_ = true; | ||
277 | 122 | unacknowledged_messages_ = false; | ||
278 | 114 | AddPrompt(message, /* visible */ false, promise); | 123 | AddPrompt(message, /* visible */ false, promise); |
279 | 115 | }); | 124 | }); |
280 | 116 | 125 | ||
281 | 117 | user_authenticator_.message_requested.connect([this](std::string const& message){ | 126 | user_authenticator_.message_requested.connect([this](std::string const& message){ |
282 | 127 | unacknowledged_messages_ = true; | ||
283 | 118 | AddMessage(message, nux::color::White); | 128 | AddMessage(message, nux::color::White); |
284 | 119 | }); | 129 | }); |
285 | 120 | 130 | ||
286 | 121 | user_authenticator_.error_requested.connect([this](std::string const& message){ | 131 | user_authenticator_.error_requested.connect([this](std::string const& message){ |
287 | 132 | unacknowledged_messages_ = true; | ||
288 | 122 | AddMessage(message, nux::color::Red); | 133 | AddMessage(message, nux::color::Red); |
289 | 123 | }); | 134 | }); |
290 | 124 | 135 | ||
291 | @@ -131,8 +142,7 @@ | |||
292 | 131 | UpdateSize(); | 142 | UpdateSize(); |
293 | 132 | ResetLayout(); | 143 | ResetLayout(); |
294 | 133 | 144 | ||
297 | 134 | user_authenticator_.AuthenticateStart(session_manager_->UserName(), | 145 | StartAuthentication(); |
296 | 135 | sigc::mem_fun(this, &UserPromptView::AuthenticationCb)); | ||
298 | 136 | } | 146 | } |
299 | 137 | 147 | ||
300 | 138 | void UserPromptView::UpdateSize() | 148 | void UserPromptView::UpdateSize() |
301 | @@ -178,6 +188,19 @@ | |||
302 | 178 | } | 188 | } |
303 | 179 | } | 189 | } |
304 | 180 | 190 | ||
305 | 191 | if (button_layout_) | ||
306 | 192 | { | ||
307 | 193 | button_layout_->SetVerticalInternalMargin(BUTTON_LAYOUT_MARGIN.CP(scale)); | ||
308 | 194 | |||
309 | 195 | for (auto* area : button_layout_->GetChildren()) | ||
310 | 196 | { | ||
311 | 197 | auto* button = static_cast<LockScreenButton*>(area); | ||
312 | 198 | button->SetMinimumHeight(Settings::GRID_SIZE.CP(scale)); | ||
313 | 199 | button->SetMaximumHeight(Settings::GRID_SIZE.CP(scale)); | ||
314 | 200 | button->scale = scale(); | ||
315 | 201 | } | ||
316 | 202 | } | ||
317 | 203 | |||
318 | 181 | bg_layer_.reset(); | 204 | bg_layer_.reset(); |
319 | 182 | 205 | ||
320 | 183 | ComputeContentSize(); | 206 | ComputeContentSize(); |
321 | @@ -200,8 +223,13 @@ | |||
322 | 200 | 223 | ||
323 | 201 | void UserPromptView::ResetLayout() | 224 | void UserPromptView::ResetLayout() |
324 | 202 | { | 225 | { |
325 | 226 | bool keep_msg_layout = msg_layout_ && (!prompted_ || unacknowledged_messages_); | ||
326 | 227 | |||
327 | 203 | focus_queue_.clear(); | 228 | focus_queue_.clear(); |
328 | 204 | 229 | ||
329 | 230 | if (keep_msg_layout) | ||
330 | 231 | msg_layout_->Reference(); | ||
331 | 232 | |||
332 | 205 | SetLayout(new nux::VLayout()); | 233 | SetLayout(new nux::VLayout()); |
333 | 206 | 234 | ||
334 | 207 | GetLayout()->SetLeftAndRightPadding(PADDING.CP(scale)); | 235 | GetLayout()->SetLeftAndRightPadding(PADDING.CP(scale)); |
335 | @@ -216,34 +244,54 @@ | |||
336 | 216 | username_->SetFont("Ubuntu "+std::to_string(PROMPT_FONT_SIZE)); | 244 | username_->SetFont("Ubuntu "+std::to_string(PROMPT_FONT_SIZE)); |
337 | 217 | GetLayout()->AddView(username_); | 245 | GetLayout()->AddView(username_); |
338 | 218 | 246 | ||
342 | 219 | msg_layout_ = new nux::VLayout(); | 247 | if (!keep_msg_layout) |
343 | 220 | msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN.CP(scale)); | 248 | { |
344 | 221 | msg_layout_->SetReconfigureParentLayoutOnGeometryChange(true); | 249 | msg_layout_ = new nux::VLayout(); |
345 | 250 | msg_layout_->SetVerticalInternalMargin(MSG_LAYOUT_MARGIN.CP(scale)); | ||
346 | 251 | msg_layout_->SetReconfigureParentLayoutOnGeometryChange(true); | ||
347 | 252 | } | ||
348 | 253 | |||
349 | 222 | GetLayout()->AddLayout(msg_layout_); | 254 | GetLayout()->AddLayout(msg_layout_); |
350 | 223 | 255 | ||
351 | 256 | if (keep_msg_layout) | ||
352 | 257 | msg_layout_->UnReference(); | ||
353 | 258 | |||
354 | 224 | prompt_layout_ = new nux::VLayout(); | 259 | prompt_layout_ = new nux::VLayout(); |
355 | 225 | prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN.CP(scale)); | 260 | prompt_layout_->SetVerticalInternalMargin(PROMPT_LAYOUT_MARGIN.CP(scale)); |
356 | 226 | prompt_layout_->SetReconfigureParentLayoutOnGeometryChange(true); | 261 | prompt_layout_->SetReconfigureParentLayoutOnGeometryChange(true); |
357 | 227 | GetLayout()->AddLayout(prompt_layout_); | 262 | GetLayout()->AddLayout(prompt_layout_); |
358 | 228 | 263 | ||
359 | 264 | button_layout_ = new nux::VLayout(); | ||
360 | 265 | button_layout_->SetVerticalInternalMargin(BUTTON_LAYOUT_MARGIN.CP(scale)); | ||
361 | 266 | button_layout_->SetReconfigureParentLayoutOnGeometryChange(true); | ||
362 | 267 | |||
363 | 229 | QueueRelayout(); | 268 | QueueRelayout(); |
364 | 230 | QueueDraw(); | 269 | QueueDraw(); |
365 | 231 | } | 270 | } |
366 | 232 | 271 | ||
368 | 233 | void UserPromptView::AuthenticationCb(bool authenticated) | 272 | void UserPromptView::AuthenticationCb(bool is_authenticated) |
369 | 234 | { | 273 | { |
370 | 235 | ResetLayout(); | 274 | ResetLayout(); |
371 | 236 | 275 | ||
373 | 237 | if (authenticated) | 276 | if (is_authenticated) |
374 | 238 | { | 277 | { |
376 | 239 | session_manager_->unlock_requested.emit(); | 278 | if (prompted_ && !unacknowledged_messages_) |
377 | 279 | DoUnlock(); | ||
378 | 280 | else | ||
379 | 281 | ShowAuthenticated(true); | ||
380 | 240 | } | 282 | } |
381 | 241 | else | 283 | else |
382 | 242 | { | 284 | { |
387 | 243 | AddMessage(_("Invalid password, please try again"), nux::color::Red); | 285 | if (prompted_) |
388 | 244 | 286 | { | |
389 | 245 | user_authenticator_.AuthenticateStart(session_manager_->UserName(), | 287 | AddMessage(_("Invalid password, please try again"), nux::color::Red); |
390 | 246 | sigc::mem_fun(this, &UserPromptView::AuthenticationCb)); | 288 | StartAuthentication(); |
391 | 289 | } | ||
392 | 290 | else | ||
393 | 291 | { | ||
394 | 292 | AddMessage(_("Failed to authenticate"), nux::color::Red); | ||
395 | 293 | ShowAuthenticated(false); | ||
396 | 294 | } | ||
397 | 247 | } | 295 | } |
398 | 248 | } | 296 | } |
399 | 249 | 297 | ||
400 | @@ -299,7 +347,16 @@ | |||
401 | 299 | nux::View* UserPromptView::focus_view() | 347 | nux::View* UserPromptView::focus_view() |
402 | 300 | { | 348 | { |
403 | 301 | if (focus_queue_.empty()) | 349 | if (focus_queue_.empty()) |
405 | 302 | return nullptr; | 350 | { |
406 | 351 | if (button_layout_ && button_layout_->GetChildren().size() > 0) | ||
407 | 352 | { | ||
408 | 353 | return static_cast<nux::View*>(button_layout_->GetChildren().front()); | ||
409 | 354 | } | ||
410 | 355 | else | ||
411 | 356 | { | ||
412 | 357 | return nullptr; | ||
413 | 358 | } | ||
414 | 359 | } | ||
415 | 303 | 360 | ||
416 | 304 | for (auto* view : focus_queue_) | 361 | for (auto* view : focus_queue_) |
417 | 305 | if (view->text_entry()->HasKeyboardFocus()) | 362 | if (view->text_entry()->HasKeyboardFocus()) |
418 | @@ -378,5 +435,48 @@ | |||
419 | 378 | QueueDraw(); | 435 | QueueDraw(); |
420 | 379 | } | 436 | } |
421 | 380 | 437 | ||
422 | 438 | void UserPromptView::AddButton(std::string const& text, std::function<void()> const& cb) | ||
423 | 439 | { | ||
424 | 440 | auto* button = new LockScreenButton (text, NUX_TRACKER_LOCATION); | ||
425 | 441 | button->scale = scale(); | ||
426 | 442 | button_layout_->AddView(button, 1, nux::MINOR_POSITION_START, nux::MINOR_SIZE_FULL); | ||
427 | 443 | |||
428 | 444 | button->state_change.connect ([cb] (nux::View*) { | ||
429 | 445 | cb(); | ||
430 | 446 | }); | ||
431 | 447 | |||
432 | 448 | GetLayout()->ComputeContentPosition(0, 0); | ||
433 | 449 | ComputeContentSize(); | ||
434 | 450 | QueueRelayout(); | ||
435 | 451 | QueueDraw(); | ||
436 | 452 | } | ||
437 | 453 | |||
438 | 454 | void UserPromptView::ShowAuthenticated(bool successful) | ||
439 | 455 | { | ||
440 | 456 | prompted_ = true; | ||
441 | 457 | unacknowledged_messages_ = false; | ||
442 | 458 | |||
443 | 459 | if (successful) | ||
444 | 460 | AddButton(_("Unlock"), sigc::mem_fun(this, &UserPromptView::DoUnlock)); | ||
445 | 461 | else | ||
446 | 462 | AddButton(_("Retry"), sigc::mem_fun(this, &UserPromptView::StartAuthentication)); | ||
447 | 463 | |||
448 | 464 | GetLayout()->AddLayout(button_layout_); | ||
449 | 465 | } | ||
450 | 466 | |||
451 | 467 | void UserPromptView::StartAuthentication() | ||
452 | 468 | { | ||
453 | 469 | prompted_ = false; | ||
454 | 470 | unacknowledged_messages_ = false; | ||
455 | 471 | |||
456 | 472 | user_authenticator_.AuthenticateStart(session_manager_->UserName(), | ||
457 | 473 | sigc::mem_fun(this, &UserPromptView::AuthenticationCb)); | ||
458 | 474 | } | ||
459 | 475 | |||
460 | 476 | void UserPromptView::DoUnlock() | ||
461 | 477 | { | ||
462 | 478 | session_manager_->unlock_requested.emit(); | ||
463 | 479 | } | ||
464 | 480 | |||
465 | 381 | } | 481 | } |
466 | 382 | } | 482 | } |
467 | 383 | 483 | ||
468 | === modified file 'lockscreen/UserPromptView.h' | |||
469 | --- lockscreen/UserPromptView.h 2016-03-31 09:51:33 +0000 | |||
470 | +++ lockscreen/UserPromptView.h 2016-06-23 14:53:05 +0000 | |||
471 | @@ -52,6 +52,7 @@ | |||
472 | 52 | 52 | ||
473 | 53 | nux::View* focus_view(); | 53 | nux::View* focus_view(); |
474 | 54 | 54 | ||
475 | 55 | void AddButton(std::string const& text, std::function<void()> const& cb); | ||
476 | 55 | void AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const&); | 56 | void AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const&); |
477 | 56 | void AddMessage(std::string const& message, nux::Color const& color); | 57 | void AddMessage(std::string const& message, nux::Color const& color); |
478 | 57 | void AuthenticationCb(bool authenticated); | 58 | void AuthenticationCb(bool authenticated); |
479 | @@ -59,13 +60,16 @@ | |||
480 | 59 | protected: | 60 | protected: |
481 | 60 | void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) override; | 61 | void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) override; |
482 | 61 | void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) override; | 62 | void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) override; |
483 | 63 | bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character) override; | ||
484 | 62 | 64 | ||
485 | 63 | private: | 65 | private: |
486 | 64 | void ResetLayout(); | 66 | void ResetLayout(); |
487 | 65 | void UpdateSize(); | 67 | void UpdateSize(); |
488 | 66 | void EnsureBGLayer(); | 68 | void EnsureBGLayer(); |
489 | 67 | 69 | ||
491 | 68 | bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character); | 70 | void ShowAuthenticated(bool successful); |
492 | 71 | void StartAuthentication(); | ||
493 | 72 | void DoUnlock(); | ||
494 | 69 | 73 | ||
495 | 70 | session::Manager::Ptr session_manager_; | 74 | session::Manager::Ptr session_manager_; |
496 | 71 | UserAuthenticatorPam user_authenticator_; | 75 | UserAuthenticatorPam user_authenticator_; |
497 | @@ -73,9 +77,13 @@ | |||
498 | 73 | StaticCairoText* username_; | 77 | StaticCairoText* username_; |
499 | 74 | nux::VLayout* msg_layout_; | 78 | nux::VLayout* msg_layout_; |
500 | 75 | nux::VLayout* prompt_layout_; | 79 | nux::VLayout* prompt_layout_; |
501 | 80 | nux::VLayout* button_layout_; | ||
502 | 76 | std::deque<TextInput*> focus_queue_; | 81 | std::deque<TextInput*> focus_queue_; |
503 | 77 | 82 | ||
504 | 78 | nux::Geometry cached_focused_geo_; | 83 | nux::Geometry cached_focused_geo_; |
505 | 84 | |||
506 | 85 | bool prompted_; | ||
507 | 86 | bool unacknowledged_messages_; | ||
508 | 79 | }; | 87 | }; |
509 | 80 | 88 | ||
510 | 81 | } | 89 | } |
511 | 82 | 90 | ||
512 | === modified file 'unity-shared/DashStyle.cpp' | |||
513 | --- unity-shared/DashStyle.cpp 2016-05-10 16:07:03 +0000 | |||
514 | +++ unity-shared/DashStyle.cpp 2016-06-23 14:53:05 +0000 | |||
515 | @@ -1672,6 +1672,41 @@ | |||
516 | 1672 | return true; | 1672 | return true; |
517 | 1673 | } | 1673 | } |
518 | 1674 | 1674 | ||
519 | 1675 | bool Style::LockScreenButton(cairo_t* cr, std::string const& label, | ||
520 | 1676 | int font_px_size) | ||
521 | 1677 | { | ||
522 | 1678 | if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) | ||
523 | 1679 | return false; | ||
524 | 1680 | |||
525 | 1681 | if (cairo_surface_get_type(cairo_get_target(cr)) != CAIRO_SURFACE_TYPE_IMAGE) | ||
526 | 1682 | return false; | ||
527 | 1683 | |||
528 | 1684 | double w, h; | ||
529 | 1685 | get_actual_cairo_size(cr, &w, &h); | ||
530 | 1686 | |||
531 | 1687 | cairo_set_line_width(cr, 1); | ||
532 | 1688 | |||
533 | 1689 | double radius = 5.0; | ||
534 | 1690 | RoundedRect(cr, 1.0, 0.5, 0.5, radius, w - 1.0, h - 1.0); | ||
535 | 1691 | |||
536 | 1692 | cairo_set_source_rgba(cr, 0.0f, 0.0f, 0.0f, 0.35f); | ||
537 | 1693 | cairo_fill_preserve(cr); | ||
538 | 1694 | |||
539 | 1695 | cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 0.7f); | ||
540 | 1696 | cairo_stroke(cr); | ||
541 | 1697 | |||
542 | 1698 | static double internal_padding = 10.0f; | ||
543 | 1699 | |||
544 | 1700 | pimpl->Text(cr, | ||
545 | 1701 | nux::color::White, | ||
546 | 1702 | label, | ||
547 | 1703 | font_px_size, | ||
548 | 1704 | internal_padding, | ||
549 | 1705 | dash::Alignment::LEFT); | ||
550 | 1706 | |||
551 | 1707 | return true; | ||
552 | 1708 | } | ||
553 | 1709 | |||
554 | 1675 | nux::AbstractPaintLayer* Style::FocusOverlay(int width, int height) | 1710 | nux::AbstractPaintLayer* Style::FocusOverlay(int width, int height) |
555 | 1676 | { | 1711 | { |
556 | 1677 | nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, width, height); | 1712 | nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, width, height); |
557 | @@ -2211,6 +2246,10 @@ | |||
558 | 2211 | return pimpl->LoadScaledTexture("search_spin", scale); | 2246 | return pimpl->LoadScaledTexture("search_spin", scale); |
559 | 2212 | } | 2247 | } |
560 | 2213 | 2248 | ||
561 | 2249 | BaseTexturePtr Style::GetLockScreenActivator(double scale) const | ||
562 | 2250 | { | ||
563 | 2251 | return pimpl->LoadScaledTexture("arrow_right", scale); | ||
564 | 2252 | } | ||
565 | 2214 | 2253 | ||
566 | 2215 | RawPixel Style::GetButtonGarnishSize() const | 2254 | RawPixel Style::GetButtonGarnishSize() const |
567 | 2216 | { | 2255 | { |
568 | 2217 | 2256 | ||
569 | === modified file 'unity-shared/DashStyle.h' | |||
570 | --- unity-shared/DashStyle.h 2016-03-31 05:53:05 +0000 | |||
571 | +++ unity-shared/DashStyle.h 2016-06-23 14:53:05 +0000 | |||
572 | @@ -98,6 +98,9 @@ | |||
573 | 98 | 98 | ||
574 | 99 | static Style& Instance(); | 99 | static Style& Instance(); |
575 | 100 | 100 | ||
576 | 101 | virtual bool LockScreenButton(cairo_t* cr, std::string const& label, | ||
577 | 102 | int font_px_size); | ||
578 | 103 | |||
579 | 101 | virtual bool Button(cairo_t* cr, nux::ButtonVisualState state, | 104 | virtual bool Button(cairo_t* cr, nux::ButtonVisualState state, |
580 | 102 | std::string const& label, int font_px_size=-1, | 105 | std::string const& label, int font_px_size=-1, |
581 | 103 | Alignment alignment = Alignment::CENTER, | 106 | Alignment alignment = Alignment::CENTER, |
582 | @@ -196,6 +199,8 @@ | |||
583 | 196 | BaseTexturePtr GetSearchCloseIcon(double scale) const; | 199 | BaseTexturePtr GetSearchCloseIcon(double scale) const; |
584 | 197 | BaseTexturePtr GetSearchSpinIcon(double scale) const; | 200 | BaseTexturePtr GetSearchSpinIcon(double scale) const; |
585 | 198 | 201 | ||
586 | 202 | BaseTexturePtr GetLockScreenActivator(double scale) const; | ||
587 | 203 | |||
588 | 199 | BaseTexturePtr const& GetGroupUnexpandIcon() const; | 204 | BaseTexturePtr const& GetGroupUnexpandIcon() const; |
589 | 200 | BaseTexturePtr const& GetGroupExpandIcon() const; | 205 | BaseTexturePtr const& GetGroupExpandIcon() const; |
590 | 201 | 206 |
Good stuff, thanks!