Merge lp:~teemperor/pantheon-greeter/unittest-branch-truncating into lp:~elementary-pantheon/pantheon-greeter/trunk

Proposed by Cody Garver
Status: Work in progress
Proposed branch: lp:~teemperor/pantheon-greeter/unittest-branch-truncating
Merge into: lp:~elementary-pantheon/pantheon-greeter/trunk
Diff against target: 442 lines (+373/-0) (has conflicts)
6 files modified
CMakeLists.txt (+2/-0)
src/LoginBox.vala (+255/-0)
tests/CMakeLists.txt (+21/-0)
tests/Main.vala (+8/-0)
tests/NameTruncateTest.vala (+29/-0)
tests/TestCase.vala (+58/-0)
Text conflict in src/LoginBox.vala
To merge this branch: bzr merge lp:~teemperor/pantheon-greeter/unittest-branch-truncating
Reviewer Review Type Date Requested Status
Cody Garver (community) Needs Fixing
Review via email: mp+213420@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Cody Garver (codygarver) wrote :

Has conflicts

review: Needs Fixing

Unmerged revisions

225. By Raphael Isemann

added test-template and fixed some bugs with the truncating

224. By Raphael Isemann

first version of name truncating

223. By Raphael Isemann

Fixing codestyle

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-10-08 18:27:22 +0000
+++ CMakeLists.txt 2014-03-31 08:54:15 +0000
@@ -57,6 +57,8 @@
57 --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi57 --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi
58)58)
5959
60add_subdirectory (tests)
61
60add_subdirectory (po)62add_subdirectory (po)
6163
62include (GSettings)64include (GSettings)
6365
=== modified file 'src/LoginBox.vala'
--- src/LoginBox.vala 2014-03-13 19:52:33 +0000
+++ src/LoginBox.vala 2014-03-31 08:54:15 +0000
@@ -22,6 +22,7 @@
22using Gtk;22using Gtk;
2323
24public class LoginBox : GtkClutter.Actor {24public class LoginBox : GtkClutter.Actor {
25<<<<<<< TREE
25 public LoginOption user { get; private set; }26 public LoginOption user { get; private set; }
26 public string current_session {27 public string current_session {
27 get {28 get {
@@ -66,9 +67,54 @@
6667
67 public LoginBox (LoginOption user) {68 public LoginBox (LoginOption user) {
68 this.user = user;69 this.user = user;
70=======
71 public LightDM.User current_user { get; private set; }
72 public string current_session { get; private set; }
73
74 static int username_maxlength = 16;
75
76 public Gtk.EventBox avatar;
77 public Gtk.Label username;
78 public Gtk.Entry password;
79 public Gtk.Button login;
80 public Gtk.ToggleButton settings;
81 Gtk.Grid grid;
82 Gtk.Spinner spinner;
83 Gdk.Pixbuf image;
84
85 Granite.Drawing.BufferSurface buffer;
86 int shadow_blur = 25;
87 int shadow_x = 0;
88 int shadow_y = 6;
89 double shadow_alpha = 0.6;
90
91 LightDM.Greeter greeter;
92
93 bool _working;
94 public bool working {
95 get {
96 return _working;
97 } set {
98 _working = value;
99 grid.remove ((_working)?avatar as Gtk.Widget:spinner as Gtk.Widget);
100 grid.attach ((_working)?spinner as Gtk.Widget:avatar as Gtk.Widget, 0, 0, 1, 3);
101 grid.show_all ();
102 spinner.start ();
103 if (LightDM.get_sessions ().length () == 1)
104 settings.hide ();
105 }
106 }
107
108 public Gtk.Window draw_ref;
109
110 public LoginBox (LightDM.Greeter greeter) {
111 this.greeter = greeter;
112
113>>>>>>> MERGE-SOURCE
69 this.reactive = true;114 this.reactive = true;
70 this.scale_gravity = Clutter.Gravity.CENTER;115 this.scale_gravity = Clutter.Gravity.CENTER;
71116
117<<<<<<< TREE
72118
73 if (user.is_guest ()) {119 if (user.is_guest ()) {
74 credentials = new GuestLogin (user);120 credentials = new GuestLogin (user);
@@ -105,6 +151,174 @@
105 pass_focus ();151 pass_focus ();
106 if (user.avatar_ready) {152 if (user.avatar_ready) {
107 update_avatar ();153 update_avatar ();
154=======
155 try {
156 this.image = Gtk.IconTheme.get_default ().load_icon ("avatar-default", 92, 0);
157 } catch (Error e) {
158 warning (e.message);
159 }
160
161 this.avatar = new Gtk.EventBox ();
162 this.username = new Gtk.Label ("");
163 this.password = new Gtk.Entry ();
164 this.login = new Gtk.Button.with_label (_("Login"));
165 this.settings = new Gtk.ToggleButton ();
166
167 avatar.set_size_request (92, 92);
168 avatar.valign = Gtk.Align.START;
169 avatar.visible_window = false;
170 username.hexpand = true;
171 username.halign = Gtk.Align.START;
172 username.ellipsize = Pango.EllipsizeMode.END;
173 username.margin_top = 6;
174 username.height_request = 1;
175 login.expand = false;
176 login.height_request = 1;
177 login.width_request = 120;
178 login.margin_top = 26;
179 login.halign = Gtk.Align.END;
180 settings.valign = Gtk.Align.START;
181 settings.relief = Gtk.ReliefStyle.NONE;
182 settings.add (new Gtk.Image.from_icon_name ("application-menu-symbolic", Gtk.IconSize.MENU));
183 password.margin_top = 11;
184 password.caps_lock_warning = true;
185 password.set_visibility (false);
186 password.key_release_event.connect ((e) => {
187 if (e.keyval == Gdk.Key.Return || e.keyval == Gdk.Key.KP_Enter) {
188 login.clicked ();
189 return true;
190 } else {
191 return false;
192 }
193 });
194
195 spinner = new Gtk.Spinner ();
196 spinner.valign = Gtk.Align.CENTER;
197 spinner.start ();
198 spinner.set_size_request (92, 24);
199
200 grid = new Gtk.Grid ();
201
202 grid.attach (avatar, 0, 0, 1, 3);
203 grid.attach (settings, 2, 0, 1, 1);
204 grid.attach (username, 1, 0, 1, 1);
205 grid.attach (password, 1, 1, 2, 1);
206 grid.attach (login, 1, 2, 2, 1);
207
208 grid.margin = shadow_blur + 12;
209 grid.margin_top += 5;
210 grid.margin_bottom -= 12;
211 grid.column_spacing = 12;
212
213 avatar.draw.connect ((ctx) => {
214 Granite.Drawing.Utilities.cairo_rounded_rectangle (ctx, 0, 0,
215 avatar.get_allocated_width (), avatar.get_allocated_height (), 3);
216 Gdk.cairo_set_source_pixbuf (ctx, image, 0, 0);
217 ctx.fill_preserve ();
218 ctx.set_line_width (1);
219 ctx.set_source_rgba (0, 0, 0, 0.3);
220 ctx.stroke ();
221 return false;
222 });
223
224 PopOver pop = null;
225 /*session choose popover*/
226 this.settings.toggled.connect (() => {
227 if (!settings.active) {
228 pop.destroy ();
229 return;
230 }
231
232 pop = new PopOver ();
233
234 var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
235 (pop.get_content_area () as Gtk.Container).add (box);
236
237 var but = new Gtk.RadioButton.with_label (null, LightDM.get_sessions ().nth_data (0).name);
238 box.pack_start (but, false);
239 but.active = LightDM.get_sessions ().nth_data (0).key == current_session;
240
241 but.toggled.connect (() => {
242 if (but.active)
243 current_session = LightDM.get_sessions ().nth_data (0).key;
244 });
245
246 for (var i = 1;i < LightDM.get_sessions ().length (); i++) {
247 var rad = new Gtk.RadioButton.with_label_from_widget (but, LightDM.get_sessions ().nth_data (i).name);
248 box.pack_start (rad, false);
249 rad.active = LightDM.get_sessions ().nth_data (i).key == current_session;
250 var identifier = LightDM.get_sessions ().nth_data (i).key;
251 rad.toggled.connect ( () => {
252 if (rad.active)
253 current_session = identifier;
254 });
255 }
256
257 this.get_stage ().add_child (pop);
258
259 pop.x = this.x + this.width - 265;
260 pop.width = 245;
261 pop.y = this.y + 50;
262 pop.get_widget ().show_all ();
263 pop.destroy.connect (() => {
264 settings.active = false;
265 });
266 });
267
268 /* draw the window stylish! */
269 var css = new Gtk.CssProvider ();
270 try {
271 css.load_from_data (LIGHT_WINDOW_STYLE, -1);
272 } catch (Error e) {
273 warning (e.message);
274 }
275
276 draw_ref = new Gtk.Window ();
277 draw_ref.get_style_context ().add_class ("content-view-window");
278 draw_ref.get_style_context ().add_provider (css, Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK);
279
280 var w = -1; var h = -1;
281 this.get_widget ().size_allocate.connect (() => {
282 if (w == this.get_widget ().get_allocated_width () &&
283 h == this.get_widget ().get_allocated_height ())
284 return;
285
286 w = this.get_widget ().get_allocated_width ();
287 h = this.get_widget ().get_allocated_height ();
288
289 this.buffer = new Granite.Drawing.BufferSurface (w, h);
290
291 this.buffer.context.rectangle (shadow_blur + shadow_x + 3,
292 shadow_blur + shadow_y*2, w - shadow_blur*2 + shadow_x - 6, h - shadow_blur*2 - shadow_y);
293 this.buffer.context.set_source_rgba (0, 0, 0, shadow_alpha);
294 this.buffer.context.fill ();
295 this.buffer.exponential_blur (shadow_blur / 2-2);
296
297 draw_ref.get_style_context ().render_activity (this.buffer.context, shadow_blur + shadow_x,
298 shadow_blur + shadow_y -2, w - shadow_blur*2 + shadow_x, h - shadow_blur*2);
299 });
300
301 this.get_widget ().draw.connect ((ctx) => {
302 ctx.rectangle (0, 0, w, h);
303 ctx.set_operator (Cairo.Operator.SOURCE);
304 ctx.set_source_rgba (0, 0, 0, 0);
305 ctx.fill ();
306
307 ctx.set_source_surface (buffer.surface, 0, 0);
308 ctx.paint ();
309
310 return false;
311 });
312
313 ((Gtk.Container) this.get_widget ()).add (grid);
314 this.get_widget ().show_all ();
315 this.get_widget ().get_style_context ().add_class ("content-view");
316 }
317
318 public static string get_user_markup (LightDM.User? user, bool title=false) {
319 if (user.real_name != null && user != null) {
320 return "<span face='Open Sans Light' font='24'>" + shorten_user_name(user.real_name) + "</span>";
321>>>>>>> MERGE-SOURCE
108 } else {322 } else {
109 user.avatar_updated.connect (() => {323 user.avatar_updated.connect (() => {
110 update_avatar ();324 update_avatar ();
@@ -130,6 +344,47 @@
130 return credentials.userpassword;344 return credentials.userpassword;
131 }345 }
132346
347 public static string shorten_user_name (string iname) {
348 string name = iname.strip();
349 if(name.length < username_maxlength) {
350 return name;
351 } else {
352 if(name.contains (" ")) {
353 string[] tokens = name.split(" ");
354 string result = "";
355 int last_shortened = 1;
356 bool unable_to_shorten = false;
357 while(true) {
358 int length = 0;
359 for(int i = 0; i < tokens.length; i++) {
360 length += tokens[i].length;
361 }
362 if(length > username_maxlength) {
363 string token = tokens[last_shortened];
364 if(token.length > 2)
365 tokens[last_shortened] =
366 token.get_char(0).to_string() + ".";
367 last_shortened++;
368 if(last_shortened == tokens.length) {
369 unable_to_shorten = true;
370 break;
371 }
372 }
373 else
374 break;
375 }
376 for(int i = 0; i < tokens.length; i++) {
377 result += tokens[i] + " ";
378 }
379 if(unable_to_shorten)
380 return result.substring(0, username_maxlength - 1 ) + "…";
381 else
382 return result.strip();
383 }
384 return name.substring(0, username_maxlength - 1 ) + "…";
385 }
386 }
387
133 public void wrong_pw () {388 public void wrong_pw () {
134 credentials.reset_pw ();389 credentials.reset_pw ();
135 this.animate (Clutter.AnimationMode.EASE_IN_BOUNCE, 150, scale_x: 0.9f, scale_y: 0.9f).390 this.animate (Clutter.AnimationMode.EASE_IN_BOUNCE, 150, scale_x: 0.9f, scale_y: 0.9f).
136391
=== added directory 'tests'
=== added file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/CMakeLists.txt 2014-03-31 08:54:15 +0000
@@ -0,0 +1,21 @@
1enable_testing(true)
2include_directories(. ../src)
3
4find_package(PkgConfig)
5pkg_check_modules(GLIB REQUIRED glib-2.0 gee-1.0)
6add_definitions(${GLIB_CFLAGS} ${GLIB_CFLAGS_OTHER})
7link_libraries(${GLIB_LIBRARIES})
8link_directories(${GLIB_LIBRARY_DIRS})
9
10vala_precompile(VALA_C
11 Main.vala
12 TestCase.vala
13 NameTruncateTest.vala
14PACKAGES
15 glib-2.0
16 posix
17)
18
19add_executable(unittests ${VALA_C})
20target_link_libraries(unittests ${LIBS})
21add_test(unittests ${CMAKE_CURRENT_BINARY_DIR}/unittests)
0\ No newline at end of file22\ No newline at end of file
123
=== added file 'tests/Main.vala'
--- tests/Main.vala 1970-01-01 00:00:00 +0000
+++ tests/Main.vala 2014-03-31 08:54:15 +0000
@@ -0,0 +1,8 @@
1using GLib;
2
3public static int main(string[] args)
4{
5 Test.init(ref args);
6 TestSuite.get_root().add_suite(new NameTruncateTest().get_suite());
7 return Test.run();
8}
09
=== added file 'tests/NameTruncateTest.vala'
--- tests/NameTruncateTest.vala 1970-01-01 00:00:00 +0000
+++ tests/NameTruncateTest.vala 2014-03-31 08:54:15 +0000
@@ -0,0 +1,29 @@
1using GLib;
2
3public class NameTruncateTest : Gee.TestCase
4{
5
6 public NameTruncateTest()
7 {
8 // assign a name for this class
9 base("NameTruncateTest");
10 // add test methods
11 add_test("truncate_test", truncate_test);
12 }
13
14 public override void set_up()
15 {
16 // setup your test
17 }
18
19 public void truncate_test()
20 {
21 // add your expressions
22 assert(1 == 1);
23 }
24
25 public override void tear_down()
26 {
27 // tear down your test
28 }
29}
0\ No newline at end of file30\ No newline at end of file
131
=== added file 'tests/TestCase.vala'
--- tests/TestCase.vala 1970-01-01 00:00:00 +0000
+++ tests/TestCase.vala 2014-03-31 08:54:15 +0000
@@ -0,0 +1,58 @@
1public abstract class Gee.TestCase : Object {
2
3 private GLib.TestSuite suite;
4 private Adaptor[] adaptors = new Adaptor[0];
5
6 public delegate void TestMethod ();
7
8 public TestCase (string name) {
9 this.suite = new GLib.TestSuite (name);
10 }
11
12 public void add_test (string name, owned TestMethod test) {
13 var adaptor = new Adaptor (name, (owned)test, this);
14 this.adaptors += adaptor;
15
16 this.suite.add (new GLib.TestCase (adaptor.name,
17 adaptor.set_up,
18 adaptor.run,
19 adaptor.tear_down ));
20 }
21
22 public virtual void set_up () {
23 }
24
25 public virtual void tear_down () {
26 }
27
28 public GLib.TestSuite get_suite () {
29 return this.suite;
30 }
31
32 private class Adaptor {
33
34 public string name { get; private set; }
35 private TestMethod test;
36 private TestCase test_case;
37
38 public Adaptor (string name,
39 owned TestMethod test,
40 TestCase test_case) {
41 this.name = name;
42 this.test = (owned)test;
43 this.test_case = test_case;
44 }
45
46 public void set_up (void* fixture) {
47 this.test_case.set_up ();
48 }
49
50 public void run (void* fixture) {
51 this.test ();
52 }
53
54 public void tear_down (void* fixture) {
55 this.test_case.tear_down ();
56 }
57 }
58}
0\ No newline at end of file59\ No newline at end of file

Subscribers

People subscribed via source and target branches