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

Subscribers

People subscribed via source and target branches