Merge lp:~elementary-pantheon/pantheon-greeter/loginbox-ui-creation into lp:~elementary-pantheon/pantheon-greeter/trunk

Proposed by Danielle Foré
Status: Merged
Approved by: Corentin Noël
Approved revision: 436
Merged at revision: 428
Proposed branch: lp:~elementary-pantheon/pantheon-greeter/loginbox-ui-creation
Merge into: lp:~elementary-pantheon/pantheon-greeter/trunk
Diff against target: 391 lines (+118/-176)
2 files modified
src/CredentialsArea.vala (+0/-3)
src/LoginBox.vala (+118/-173)
To merge this branch: bzr merge lp:~elementary-pantheon/pantheon-greeter/loginbox-ui-creation
Reviewer Review Type Date Requested Status
Corentin Noël Approve
Review via email: mp+292189@code.launchpad.net

Commit message

LoginBox:
* Use grid row and column spacing instead of widget margins
* Code style cleanups
* Don't set label opacity because we either pack or don't
* Remove settings_dummy
* Remove unnecessary cairo drawing code
* Remove obvious comments
* Update license header
* Connect signals in a method
* Use Entry.activate instead of listening for specific keys
* Rename variables to make them more obvious
* Use bind instead of connect to show/hide popover

Description of the change

Trying to make this code more legible T_T

Instead of having 100 different methods to create widgets, just create them all as normal.

Something I have an open question about is if doing the if/else logic to pack widgets there makes sense or if there should be a method like "get_login_widget" so there is only one pack and the if/else happens far away.

Try to make some of these variable names more obvious. names like "label" and "pop" suck.

There's a lot of extra and unnecessary stuff here that is just handled by using Gtk instead of drawing everything manually in Clutter or Cairo. One of these is setting the label opacity. Since that's Gtk now, we either just pack it into the grid or we pack the entry. We don't have to worry about one overlapping the other.

To post a comment you must log in.
433. By Danielle Foré

use listbox for menuitems like the indicators

Revision history for this message
Corentin Noël (tintou) wrote :

I'm okay with the changes, just a few tips in the inline diff

434. By Danielle Foré

update with Corentin's comments

435. By Danielle Foré

use bind instead of connect to show/hide popover

436. By Danielle Foré

no need to declare variables in global scope

Revision history for this message
Corentin Noël (tintou) wrote :

Everything is fine on my end, very nice cleanup

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CredentialsArea.vala'
2--- src/CredentialsArea.vala 2016-04-13 00:49:19 +0000
3+++ src/CredentialsArea.vala 2016-04-18 22:21:59 +0000
4@@ -36,7 +36,6 @@
5
6 void create_password_field () {
7 password = new Entry ();
8- password.margin_top = 24;
9
10 password.set_icon_from_icon_name (Gtk.EntryIconPosition.PRIMARY,
11 "dialog-password-symbolic");
12@@ -83,8 +82,6 @@
13 replied ("");
14 });
15
16- login_btn.margin_top = 32;
17-
18 login_btn.get_style_context ().add_class ("suggested-action");
19
20 attach (login_btn, 0, 1, 1, 1);
21
22=== modified file 'src/LoginBox.vala'
23--- src/LoginBox.vala 2016-04-18 18:23:18 +0000
24+++ src/LoginBox.vala 2016-04-18 22:21:59 +0000
25@@ -1,30 +1,29 @@
26 // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
27-/***
28- BEGIN LICENSE
29-
30- Copyright (C) 2011-2014 elementary Developers
31-
32- This program is free software: you can redistribute it and/or modify it
33- under the terms of the GNU Lesser General Public License version 3, as published
34- by the Free Software Foundation.
35-
36- This program is distributed in the hope that it will be useful, but
37- WITHOUT ANY WARRANTY; without even the implied warranties of
38- MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
39- PURPOSE. See the GNU General Public License for more details.
40-
41- You should have received a copy of the GNU General Public License along
42- with this program. If not, see <http://www.gnu.org/licenses/>
43-
44- END LICENSE
45-***/
46+/*
47+* Copyright (c) 2011-2016 elementary LLC. (http://launchpad.net/pantheon-greeter)
48+*
49+* This program is free software; you can redistribute it and/or
50+* modify it under the terms of the GNU General Public
51+* License as published by the Free Software Foundation; either
52+* version 2 of the License, or (at your option) any later version.
53+*
54+* This program is distributed in the hope that it will be useful,
55+* but WITHOUT ANY WARRANTY; without even the implied warranty of
56+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57+* General Public License for more details.
58+*
59+* You should have received a copy of the GNU General Public
60+* License along with this program; if not, write to the
61+* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
62+* Boston, MA 02111-1307, USA.
63+*
64+*/
65
66 public class LoginBox : GtkClutter.Actor, LoginMask {
67
68 SelectableAvatar avatar = null;
69
70 CredentialsAreaActor credentials_actor;
71- Gtk.Label label;
72
73 LoginOption user;
74
75@@ -39,23 +38,15 @@
76 credentials_actor.remove_credentials ();
77 if (value) {
78 opacity = 255;
79- if (avatar != null)
80+ if (avatar != null) {
81 avatar.select ();
82-
83- // LoginOption is not providing a name, so the CredentialsArea
84- // will display a Gtk.Entry for that and we need to hide
85- // the label that would otherwise be at the same position
86- // as the mentioned entry.
87- if (!user.provides_login_name) {
88- label.set_opacity (0);
89 }
90+
91 } else {
92
93 if (avatar != null) {
94 avatar.deselect ();
95 }
96-
97- label.set_opacity (255);
98 }
99
100 credentials_actor.save_easing_state ();
101@@ -108,14 +99,16 @@
102 }
103
104 void update_avatar () {
105- if (avatar != null)
106+ if (avatar != null) {
107 avatar.dismiss ();
108+ }
109
110 avatar = new SelectableAvatar (user);
111 add_child (avatar);
112
113- if (selected)
114+ if (selected) {
115 avatar.select ();
116+ }
117 }
118
119 public void pass_focus () {
120@@ -202,14 +195,11 @@
121 * LoginGateway.
122 */
123 public signal void replied (string text);
124-
125 public signal void entered_login_name (string name);
126
127 Gtk.Entry? login_name_entry = null;
128- Gtk.ToggleButton settings;
129-
130- // Grid that contains all elements of the ui
131 Gtk.Grid grid;
132+ Gtk.ListBox settings_list;
133
134 LoginBox login_box;
135
136@@ -225,53 +215,74 @@
137 height = 188;
138 credentials = null;
139
140+ var login_name_label = new Gtk.Label (login_option.get_markup ());
141+ login_name_label.get_style_context ().add_class ("h2");
142+ login_name_label.set_xalign (0);
143+ login_name_label.width_request = 260;
144+
145+ login_name_entry = new Gtk.Entry ();
146+ login_name_entry.halign = Gtk.Align.START;
147+ login_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.PRIMARY, "avatar-default-symbolic");
148+ login_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "go-jump-symbolic");
149+ login_name_entry.width_request = 260;
150+
151+ var settings = new Gtk.ToggleButton ();
152+ settings.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
153+ settings.image = new Gtk.Image.from_icon_name ("application-menu-symbolic", Gtk.IconSize.MENU);
154+ settings.set_size_request (32, 32);
155+ settings.valign = Gtk.Align.CENTER;
156+
157+ settings_list = new Gtk.ListBox ();
158+ settings_list.margin_bottom = 3;
159+ settings_list.margin_top = 3;
160+
161+ var settings_popover = new Gtk.Popover (settings);
162+ settings_popover.position = Gtk.PositionType.BOTTOM;
163+ settings_popover.add (settings_list);
164+ settings_popover.bind_property ("visible", settings, "active", GLib.BindingFlags.BIDIRECTIONAL);
165+
166 grid = new Gtk.Grid ();
167- grid.width_request = 260;
168+ grid.column_spacing = 6;
169+ grid.row_spacing = 12;
170
171- // If the login option doesn't provice a login name, we have to
172- // show a entry for the user to enter one.
173- // This is for example used in the manual login.
174 if (login_option.provides_login_name) {
175- var label = new Gtk.Label (login_option.get_markup ());
176- label.get_style_context ().add_class ("h2");
177- label.halign = Gtk.Align.START;
178-
179- grid.attach (label, 0, 0, 1, 1);
180+ grid.attach (login_name_label, 0, 0, 1, 1);
181 } else {
182- create_login_name_entry ();
183+ grid.attach (login_name_entry, 0, 0, 1, 1);
184 }
185
186- // Only show settings if we actually have more than one session
187- // to select from
188 if (LightDM.get_sessions ().length () > 1) {
189- create_settings ();
190- } else {
191- // Dummy for the settings-button or the grid-layout goes apeshit
192- create_settings_dummy ();
193+ create_settings_items ();
194+ grid.attach (settings, 1, 0, 1, 1);
195 }
196
197- var w = -1; var h = -1;
198- this.get_widget ().size_allocate.connect (() => {
199- w = this.get_widget ().get_allocated_width ();
200- h = this.get_widget ().get_allocated_height ();
201- });
202-
203- // We override the draw call and just paint a transparent
204- // rectangle. TODO: can we also just draw nothing?
205- // Shouldn't change anything...
206- this.get_widget ().draw.connect ((ctx) => {
207- ctx.rectangle (0, 0, w, h);
208- ctx.set_operator (Cairo.Operator.SOURCE);
209- ctx.set_source_rgba (0, 0, 0, 0);
210- ctx.fill ();
211-
212- return false;
213- });
214+ connect_signals ();
215
216 ((Gtk.Container) this.get_widget ()).add (grid);
217 this.get_widget ().show_all ();
218 }
219
220+ void connect_signals () {
221+ login_name_entry.activate.connect (() => {
222+ entered_login_name (login_name_entry.text);
223+ });
224+
225+ login_name_entry.focus_in_event.connect ((e) => {
226+ remove_credentials ();
227+ return false;
228+ });
229+
230+ login_name_entry.icon_press.connect ((pos, event) => {
231+ if (pos == Gtk.EntryIconPosition.SECONDARY) {
232+ entered_login_name (login_name_entry.text);
233+ }
234+ });
235+
236+ replied.connect ((answer) => {
237+ login_name_entry.sensitive = false;
238+ });
239+ }
240+
241 public void remove_credentials () {
242 if (credentials != null) {
243 grid.remove (credentials);
244@@ -323,109 +334,43 @@
245 login_name_entry.sensitive = true;
246 }
247
248- void create_login_name_entry () {
249- replied.connect ((answer) => {
250- login_name_entry.sensitive = false;
251- });
252- login_name_entry = new Gtk.Entry ();
253- login_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.PRIMARY,
254- "avatar-default-symbolic");
255- login_name_entry.hexpand = true;
256- login_name_entry.margin_top = 8;
257- login_name_entry.set_icon_from_icon_name (Gtk.EntryIconPosition.SECONDARY, "go-jump-symbolic");
258- login_name_entry.icon_press.connect ((pos, event) => {
259- if (pos == Gtk.EntryIconPosition.SECONDARY) {
260- entered_login_name (login_name_entry.text);
261- }
262- });
263- login_name_entry.key_release_event.connect ((e) => {
264- if (e.keyval == Gdk.Key.Return || e.keyval == Gdk.Key.KP_Enter) {
265- entered_login_name (login_name_entry.text);
266- return true;
267- } else {
268- return false;
269- }
270- });
271- login_name_entry.focus_in_event.connect ((e) => {
272- remove_credentials ();
273- return false;
274- });
275- grid.attach (login_name_entry, 0, 0, 1, 1);
276- }
277-
278- void create_settings () {
279- settings = new Gtk.ToggleButton ();
280- settings.margin_left = 6;
281- settings.margin_top = 6;
282- settings.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
283- settings.add (new Gtk.Image.from_icon_name ("application-menu-symbolic", Gtk.IconSize.MENU));
284- settings.valign = Gtk.Align.START;
285- settings.set_size_request (30, 30);
286- grid.attach (settings, 1, 0, 1, 1);
287- create_popup ();
288- }
289-
290- /**
291- * Creates a invisible settings-dummy that has
292- * the dimension of the settings-button but is invisible.
293- * Prevents that the layout is different when there are is
294- * no settings-menu.
295- */
296- void create_settings_dummy () {
297- var dummy_grid = new Gtk.Grid ();
298- dummy_grid.set_size_request (30, 30);
299- grid.attach (dummy_grid, 1, 0, 1, 1);
300- }
301-
302- void create_popup () {
303- Gtk.Popover pop = null;
304- /*session choose popover*/
305- this.settings.toggled.connect (() => {
306-
307- if (!settings.active) {
308- pop.destroy ();
309- return;
310- }
311-
312- pop = new Gtk.Popover (settings);
313- pop.set_position (Gtk.PositionType.BOTTOM);
314-
315- var grid = new Gtk.Grid ();
316- grid.margin_bottom = 3;
317- grid.margin_top = 3;
318- grid.orientation = Gtk.Orientation.VERTICAL;
319- pop.add (grid);
320-
321- var but = new Gtk.RadioButton.with_label (null, LightDM.get_sessions ().nth_data (0).name);
322- but.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUITEM);
323- grid.add (but);
324- but.active = LightDM.get_sessions ().nth_data (0).key == current_session;
325-
326- but.toggled.connect (() => {
327- if (but.active)
328- current_session = LightDM.get_sessions ().nth_data (0).key;
329- });
330-
331- for (var i = 1;i < LightDM.get_sessions ().length (); i++) {
332- var rad = new Gtk.RadioButton.with_label_from_widget (but, LightDM.get_sessions ().nth_data (i).name);
333- rad.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUITEM);
334- grid.add (rad);
335-
336- rad.active = LightDM.get_sessions ().nth_data (i).key == current_session;
337- var identifier = LightDM.get_sessions ().nth_data (i).key;
338- rad.toggled.connect ( () => {
339- if (rad.active)
340- current_session = identifier;
341- });
342- }
343-
344- pop.show_all ();
345-
346- pop.closed.connect (() => {
347- settings.active = false;
348- });
349- });
350- }
351-
352+ void create_settings_items () {
353+ var button = new Gtk.RadioButton.with_label (null, LightDM.get_sessions ().nth_data (0).name);
354+ button.margin_left = 6;
355+ button.margin_right = 6;
356+ button.active = LightDM.get_sessions ().nth_data (0).key == current_session;
357+
358+ button.toggled.connect (() => {
359+ if (button.active) {
360+ current_session = LightDM.get_sessions ().nth_data (0).key;
361+ }
362+ });
363+
364+ var button_row = new Gtk.ListBoxRow ();
365+ button_row.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUITEM);
366+ button_row.add (button);
367+ settings_list.add (button_row);
368+
369+ for (var i = 1; i < LightDM.get_sessions ().length (); i++) {
370+ var radio = new Gtk.RadioButton.with_label_from_widget (button, LightDM.get_sessions ().nth_data (i).name);
371+ radio.margin_left = 6;
372+ radio.margin_right = 6;
373+
374+ var radio_row = new Gtk.ListBoxRow ();
375+ radio_row.get_style_context ().add_class (Gtk.STYLE_CLASS_MENUITEM);
376+ radio_row.add (radio);
377+ settings_list.add (radio_row);
378+
379+ var identifier = LightDM.get_sessions ().nth_data (i).key;
380+ radio.active = identifier == current_session;
381+ radio.toggled.connect ( () => {
382+ if (radio.active) {
383+ current_session = identifier;
384+ }
385+ });
386+ }
387+
388+ settings_list.show_all ();
389+ }
390 }
391 }

Subscribers

People subscribed via source and target branches