Merge lp:~elementary-apps/pantheon-mail/password-dialog into lp:~elementary-apps/pantheon-mail/trunk

Proposed by Danielle Foré
Status: Merged
Approved by: Danielle Foré
Approved revision: 2070
Merged at revision: 2072
Proposed branch: lp:~elementary-apps/pantheon-mail/password-dialog
Merge into: lp:~elementary-apps/pantheon-mail/trunk
Diff against target: 509 lines (+125/-327)
6 files modified
data/ui/CMakeLists.txt (+0/-1)
data/ui/password-dialog.ui (+0/-241)
src/CMakeLists.txt (+1/-1)
src/client/application/secret-mediator.vala (+2/-2)
src/client/dialogs/PasswordDialog.vala (+122/-0)
src/client/dialogs/password-dialog.vala (+0/-82)
To merge this branch: bzr merge lp:~elementary-apps/pantheon-mail/password-dialog
Reviewer Review Type Date Requested Status
Zisu Andrei (community) Approve
Review via email: mp+296013@code.launchpad.net

Commit message

Port password-dialog.ui to PasswordDialog.vala

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

fix parenth space

2067. By Danielle Foré

fix parenth space again

2068. By Danielle Foré

get rid of duplicate if smtp

2069. By Danielle Foré

use equals instead of set

2070. By Danielle Foré

tabs to spaces

Revision history for this message
Zisu Andrei (matzipan) wrote :

Do we want to migrate UI builder components to Vala components?

Revision history for this message
Danielle Foré (danrabbit) wrote :

Yeah, this branch saves like 200 lines

Revision history for this message
Zisu Andrei (matzipan) wrote :

It's not about saving lines, it's about declarative components vs procedural components. Declarative are more upfront about what designer can expect the component to look like, and you can load it separately, without having to rung the whole application.

I was actually thinking of moving eds-sample towards declarative components as opposed to procedural ones.

Revision history for this message
Zisu Andrei (matzipan) wrote :

If we decide to move this way (I want at least a third opinion on this), I'd like us to move away from using the .margin property and do that in CSS.

review: Needs Fixing
Revision history for this message
Danielle Foré (danrabbit) wrote :

Personally, I hate Glade UI files. They are more complicated, take longer to write, and make very messy diffs. It's much easier to just code the UI. No serious web developer uses WYSIWYG tools like this, why would do it on the desktop? It just creates crap code.

It's not possible to do margin in Gtk.CSS

Revision history for this message
Zisu Andrei (matzipan) wrote :

I haven't used Glade in a while, and I've noticed it's gotten really buggy, but I see GNOME Builder is planning to have Glade integration, so maybe that's gonna give the project a reboot? But my main point is that the UI files themselves are more clear to a designer than a Vala file is. So you could have a designer write builder files and then those can be imported into the codebase and have the functionality plugged into it.

It will seem like a less flexible approach, but it allows greater separation in the UI.

> It's not possible to do margin in Gtk.CSS

Bummer.

I'm gonna mark this as approved for the way that the code looks, but I'd like to hear another opinion on moving away from builder files before merging.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/ui/CMakeLists.txt'
2--- data/ui/CMakeLists.txt 2016-03-12 07:25:44 +0000
3+++ data/ui/CMakeLists.txt 2016-05-30 18:13:35 +0000
4@@ -12,7 +12,6 @@
5 install(FILES find_bar.ui DESTINATION ${UI_DEST})
6 install(FILES login.ui DESTINATION ${UI_DEST})
7 install(FILES message.ui DESTINATION ${UI_DEST})
8-install(FILES password-dialog.ui DESTINATION ${UI_DEST})
9 install(FILES remove_confirm.ui DESTINATION ${UI_DEST})
10 install(FILES context_empty_menu.ui DESTINATION ${UI_DEST})
11 install(FILES toolbar_mark_menu.ui DESTINATION ${UI_DEST})
12
13=== removed file 'data/ui/password-dialog.ui'
14--- data/ui/password-dialog.ui 2015-12-14 17:36:36 +0000
15+++ data/ui/password-dialog.ui 1970-01-01 00:00:00 +0000
16@@ -1,241 +0,0 @@
17-<?xml version="1.0" encoding="UTF-8"?>
18-<!-- Generated with glade 3.16.1 -->
19-<interface>
20- <requires lib="gtk+" version="3.10"/>
21- <object class="GtkDialog" id="PasswordDialog">
22- <property name="can_focus">False</property>
23- <property name="border_width">6</property>
24- <property name="resizable">False</property>
25- <property name="modal">True</property>
26- <property name="type_hint">dialog</property>
27- <property name="has_resize_grip">False</property>
28- <child internal-child="vbox">
29- <object class="GtkBox" id="dialog-vbox1">
30- <property name="can_focus">False</property>
31- <property name="margin_top">6</property>
32- <property name="orientation">vertical</property>
33- <property name="spacing">12</property>
34- <child>
35- <object class="GtkBox" id="box1">
36- <property name="visible">True</property>
37- <property name="can_focus">False</property>
38- <property name="border_width">6</property>
39- <property name="spacing">15</property>
40- <child>
41- <object class="GtkImage" id="image1">
42- <property name="visible">True</property>
43- <property name="can_focus">False</property>
44- <property name="yalign">0</property>
45- <property name="icon_name">dialog-password-symbolic</property>
46- <property name="use_fallback">True</property>
47- <property name="icon_size">6</property>
48- </object>
49- <packing>
50- <property name="expand">False</property>
51- <property name="fill">True</property>
52- <property name="position">0</property>
53- </packing>
54- </child>
55- <child>
56- <object class="GtkBox" id="box2">
57- <property name="visible">True</property>
58- <property name="can_focus">False</property>
59- <property name="orientation">vertical</property>
60- <property name="spacing">12</property>
61- <child>
62- <object class="GtkLabel" id="primary_text_label">
63- <property name="visible">True</property>
64- <property name="can_focus">False</property>
65- <property name="xalign">2.2351741291171123e-10</property>
66- <property name="yalign">0</property>
67- <property name="label">(set in password-dialog.vala)</property>
68- <property name="use_markup">True</property>
69- <property name="wrap">True</property>
70- <property name="wrap_mode">word-char</property>
71- </object>
72- <packing>
73- <property name="expand">False</property>
74- <property name="fill">True</property>
75- <property name="position">0</property>
76- </packing>
77- </child>
78- <child>
79- <object class="GtkGrid" id="grid">
80- <property name="visible">True</property>
81- <property name="can_focus">False</property>
82- <property name="row_spacing">6</property>
83- <property name="column_spacing">6</property>
84- <child>
85- <object class="GtkLabel" id="label: smtp">
86- <property name="can_focus">False</property>
87- <property name="no_show_all">True</property>
88- <property name="margin_bottom">4</property>
89- <property name="xalign">0</property>
90- <property name="label" translatable="yes">SMTP Credentials</property>
91- <attributes>
92- <attribute name="weight" value="bold"/>
93- </attributes>
94- </object>
95- <packing>
96- <property name="left_attach">0</property>
97- <property name="top_attach">0</property>
98- <property name="width">2</property>
99- <property name="height">1</property>
100- </packing>
101- </child>
102- <child>
103- <object class="GtkLabel" id="label for: username">
104- <property name="visible">True</property>
105- <property name="can_focus">False</property>
106- <property name="xalign">1</property>
107- <property name="label" translatable="yes">Username</property>
108- <style>
109- <class name="dim-label"/>
110- </style>
111- </object>
112- <packing>
113- <property name="left_attach">0</property>
114- <property name="top_attach">1</property>
115- <property name="width">1</property>
116- <property name="height">1</property>
117- </packing>
118- </child>
119- <child>
120- <object class="GtkLabel" id="label for: password">
121- <property name="visible">True</property>
122- <property name="can_focus">False</property>
123- <property name="xalign">1</property>
124- <property name="label" translatable="yes">Password</property>
125- <style>
126- <class name="dim-label"/>
127- </style>
128- </object>
129- <packing>
130- <property name="left_attach">0</property>
131- <property name="top_attach">2</property>
132- <property name="width">1</property>
133- <property name="height">1</property>
134- </packing>
135- </child>
136- <child>
137- <object class="GtkLabel" id="label: username">
138- <property name="visible">True</property>
139- <property name="can_focus">False</property>
140- <property name="xalign">0</property>
141- <property name="label">(set in password-dialog.vala)</property>
142- </object>
143- <packing>
144- <property name="left_attach">1</property>
145- <property name="top_attach">1</property>
146- <property name="width">1</property>
147- <property name="height">1</property>
148- </packing>
149- </child>
150- <child>
151- <object class="GtkEntry" id="entry: password">
152- <property name="visible">True</property>
153- <property name="can_focus">True</property>
154- <property name="hexpand">True</property>
155- <property name="visibility">False</property>
156- <property name="invisible_char">•</property>
157- <property name="activates_default">True</property>
158- </object>
159- <packing>
160- <property name="left_attach">1</property>
161- <property name="top_attach">2</property>
162- <property name="width">1</property>
163- <property name="height">1</property>
164- </packing>
165- </child>
166- <child>
167- <object class="GtkCheckButton" id="check: remember_password">
168- <property name="label" translatable="yes">_Remember password</property>
169- <property name="visible">True</property>
170- <property name="can_focus">True</property>
171- <property name="receives_default">False</property>
172- <property name="halign">end</property>
173- <property name="use_underline">True</property>
174- <property name="xalign">0.5</property>
175- <property name="draw_indicator">True</property>
176- </object>
177- <packing>
178- <property name="left_attach">0</property>
179- <property name="top_attach">3</property>
180- <property name="width">2</property>
181- <property name="height">1</property>
182- </packing>
183- </child>
184- </object>
185- <packing>
186- <property name="expand">False</property>
187- <property name="fill">True</property>
188- <property name="position">2</property>
189- </packing>
190- </child>
191- </object>
192- <packing>
193- <property name="expand">True</property>
194- <property name="fill">True</property>
195- <property name="position">2</property>
196- </packing>
197- </child>
198- </object>
199- <packing>
200- <property name="expand">False</property>
201- <property name="fill">True</property>
202- <property name="position">0</property>
203- </packing>
204- </child>
205- <child internal-child="action_area">
206- <object class="GtkButtonBox" id="dialog-action_area1">
207- <property name="can_focus">False</property>
208- <property name="valign">end</property>
209- <property name="layout_style">end</property>
210- <child>
211- <object class="GtkButton" id="cancel_button">
212- <property name="label" translatable="yes">_Cancel</property>
213- <property name="visible">True</property>
214- <property name="can_focus">True</property>
215- <property name="receives_default">False</property>
216- <property name="use_underline">True</property>
217- </object>
218- <packing>
219- <property name="expand">False</property>
220- <property name="fill">True</property>
221- <property name="position">0</property>
222- </packing>
223- </child>
224- <child>
225- <object class="GtkButton" id="authenticate_button">
226- <property name="label" translatable="yes">_Authenticate</property>
227- <property name="visible">True</property>
228- <property name="can_focus">True</property>
229- <property name="can_default">True</property>
230- <property name="receives_default">True</property>
231- <property name="use_underline">True</property>
232- <style>
233- <class name="suggested-action"/>
234- </style>
235- </object>
236- <packing>
237- <property name="expand">False</property>
238- <property name="fill">True</property>
239- <property name="position">1</property>
240- </packing>
241- </child>
242- </object>
243- <packing>
244- <property name="expand">False</property>
245- <property name="fill">True</property>
246- <property name="pack_type">end</property>
247- <property name="position">2</property>
248- </packing>
249- </child>
250- </object>
251- </child>
252- <action-widgets>
253- <action-widget response="-6">cancel_button</action-widget>
254- <action-widget response="-5">authenticate_button</action-widget>
255- </action-widgets>
256- </object>
257-</interface>
258
259=== modified file 'src/CMakeLists.txt'
260--- src/CMakeLists.txt 2016-05-27 17:56:12 +0000
261+++ src/CMakeLists.txt 2016-05-30 18:13:35 +0000
262@@ -366,7 +366,7 @@
263 client/dialogs/OpenAttachmentDialog.vala
264 client/dialogs/attachment-dialog.vala
265 client/dialogs/certificate-warning-dialog.vala
266-client/dialogs/password-dialog.vala
267+client/dialogs/PasswordDialog.vala
268 client/dialogs/preferences-dialog.vala
269 client/dialogs/upgrade-dialog.vala
270
271
272=== modified file 'src/client/application/secret-mediator.vala'
273--- src/client/application/secret-mediator.vala 2016-02-06 02:37:42 +0000
274+++ src/client/application/secret-mediator.vala 2016-05-30 18:13:35 +0000
275@@ -127,11 +127,10 @@
276
277 PasswordDialog password_dialog = new PasswordDialog(main_window, services.has_smtp(),
278 account_information, services);
279- bool result = password_dialog.run();
280
281 dialog_mutex.release(ref token);
282
283- if (!result) {
284+ if (password_dialog.run () != Gtk.ResponseType.OK) {
285 // user cancelled the dialog
286 imap_password = null;
287 smtp_password = null;
288@@ -153,6 +152,7 @@
289 smtp_password = null;
290 smtp_remember_password = false;
291 }
292+ password_dialog.destroy ();
293 return true;
294 }
295 }
296
297=== added file 'src/client/dialogs/PasswordDialog.vala'
298--- src/client/dialogs/PasswordDialog.vala 1970-01-01 00:00:00 +0000
299+++ src/client/dialogs/PasswordDialog.vala 2016-05-30 18:13:35 +0000
300@@ -0,0 +1,122 @@
301+/*
302+* Copyright (c) 2016 elementary LLC (http://launchpad.net/pantheon-mail
303+*
304+* This program is free software; you can redistribute it and/or
305+* modify it under the terms of the GNU General Public
306+* License as published by the Free Software Foundation; either
307+* version 2 of the License, or (at your option) any later version.
308+*
309+* This program is distributed in the hope that it will be useful,
310+* but WITHOUT ANY WARRANTY; without even the implied warranty of
311+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
312+* General Public License for more details.
313+*
314+* You should have received a copy of the GNU General Public
315+* License along with this program; if not, write to the
316+* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
317+* Boston, MA 02111-1307, USA.
318+*
319+* Authored by: Daniel Foré <daniel@elementary.io>
320+*/
321+
322+public class PasswordDialog : Gtk.Dialog {
323+ private Gtk.Button authenticate_button;
324+ private Gtk.CheckButton checkbox;
325+ private Gtk.Entry password_entry;
326+
327+ public string password { get; private set; default = ""; }
328+ public bool remember_password { get; private set; }
329+
330+ public PasswordDialog (Gtk.Window? parent, bool smtp, Geary.AccountInformation account_information, Geary.ServiceFlag password_flags) {
331+ border_width = 6;
332+ deletable = false;
333+ resizable = false;
334+ transient_for = parent;
335+
336+ var password_image = new Gtk.Image.from_icon_name ("dialog-password", Gtk.IconSize.DIALOG);
337+ password_image.valign = Gtk.Align.START;
338+
339+ var primary_label = new Gtk.Label (_("Mail requires your email password to continue"));
340+ primary_label.get_style_context ().add_class ("primary");
341+ primary_label.max_width_chars = 60;
342+ primary_label.wrap = true;
343+ primary_label.xalign = 0;
344+
345+ var username_label = new Gtk.Label (_("Username:"));
346+ username_label.halign = Gtk.Align.END;
347+
348+ var username_widget = new Gtk.Label ("");
349+ username_widget.hexpand = true;
350+ username_widget.xalign = 0;
351+
352+ var password_label = new Gtk.Label (_("Password:"));
353+ password_label.halign = Gtk.Align.END;
354+
355+ var smtp_label = new Gtk.Label (_("SMTP Credentials:"));
356+ smtp_label.no_show_all = true;
357+
358+ password_entry = new Gtk.Entry ();
359+ password_entry.set_input_purpose (Gtk.InputPurpose.PASSWORD);
360+ password_entry.visibility = false;
361+
362+ checkbox = new Gtk.CheckButton.with_label (_("Remember password"));
363+ checkbox.margin_top = 6;
364+ checkbox.active = (smtp ? account_information.smtp_remember_password : account_information.imap_remember_password);
365+
366+ if (smtp) {
367+ username_widget.label = account_information.smtp_credentials.user;
368+ password_entry.text = account_information.smtp_credentials.pass;
369+ smtp_label.show ();
370+ } else {
371+ username_widget.label = account_information.imap_credentials.user;
372+ password_entry.text = account_information.imap_credentials.pass;
373+ }
374+
375+ authenticate_button = new Gtk.Button.with_label (_("Authenticate"));
376+ authenticate_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
377+ authenticate_button.sensitive = false;
378+
379+ var layout = new Gtk.Grid ();
380+ layout.margin = 6;
381+ layout.margin_top = 0;
382+ layout.column_spacing = 12;
383+ layout.row_spacing = 6;
384+ layout.attach (password_image, 0, 0, 1, 4);
385+ layout.attach (primary_label, 1, 0, 2, 1);
386+ layout.attach (smtp_label, 1, 1, 2, 1);
387+ layout.attach (username_label, 1, 2, 1, 1);
388+ layout.attach (username_widget, 2, 2, 1, 1);
389+ layout.attach (password_label, 1, 3, 1, 1);
390+ layout.attach (password_entry, 2, 3, 1, 1);
391+ layout.attach (checkbox, 2, 4, 1, 1);
392+
393+ var content = get_content_area () as Gtk.Box;
394+ content.add (layout);
395+
396+ add_button (_("Cancel"), Gtk.ResponseType.CLOSE);
397+ add_action_widget (authenticate_button, Gtk.ResponseType.OK);
398+ show_all ();
399+
400+ response.connect (on_response);
401+ password_entry.changed.connect (refresh_ok_button_sensitivity);
402+ password_entry.activate.connect (() => {
403+ authenticate_button.activate ();
404+ });
405+ }
406+
407+ private void refresh_ok_button_sensitivity () {
408+ authenticate_button.sensitive = !Geary.String.is_empty_or_whitespace (password_entry.get_text ());
409+ }
410+
411+ private void on_response (Gtk.Dialog source, int response_id) {
412+ switch (response_id) {
413+ case Gtk.ResponseType.OK:
414+ password = password_entry.get_text ();
415+ remember_password = checkbox.active;
416+ break;
417+ case Gtk.ResponseType.CLOSE:
418+ destroy ();
419+ break;
420+ }
421+ }
422+}
423
424=== removed file 'src/client/dialogs/password-dialog.vala'
425--- src/client/dialogs/password-dialog.vala 2016-01-29 06:23:48 +0000
426+++ src/client/dialogs/password-dialog.vala 1970-01-01 00:00:00 +0000
427@@ -1,82 +0,0 @@
428-/* Copyright 2011-2015 Yorba Foundation
429- *
430- * This software is licensed under the GNU Lesser General Public License
431- * (version 2.1 or later). See the COPYING file in this distribution.
432- */
433-
434-/**
435- * Displays a dialog for collecting the user's password, without allowing them to change their
436- * other data.
437- */
438-public class PasswordDialog {
439- // We can't keep these in the glade file, because Gnome doesn't want markup in translatable
440- // strings, and Glade doesn't support the "larger" size attribute. See this bug report for
441- // details: https://bugzilla.gnome.org/show_bug.cgi?id=679006
442- private const string PRIMARY_TEXT_MARKUP = "<span weight=\"bold\" size=\"larger\">%s</span>";
443- private const string PRIMARY_TEXT_FIRST_TRY = _("Mail requires your email password to continue");
444-
445- private Gtk.Dialog dialog;
446- private Gtk.Entry entry_password;
447- private Gtk.CheckButton check_remember_password;
448- private Gtk.Button ok_button;
449-
450- public string password { get; private set; default = ""; }
451- public bool remember_password { get; private set; }
452-
453- public PasswordDialog(Gtk.Window? parent, bool smtp, Geary.AccountInformation account_information,
454- Geary.ServiceFlag password_flags) {
455- Gtk.Builder builder = GearyApplication.instance.create_builder("password-dialog.ui");
456-
457- dialog = (Gtk.Dialog) builder.get_object("PasswordDialog");
458- dialog.transient_for = parent;
459- dialog.set_type_hint(Gdk.WindowTypeHint.DIALOG);
460- dialog.set_default_response(Gtk.ResponseType.OK);
461-
462- entry_password = (Gtk.Entry) builder.get_object("entry: password");
463- check_remember_password = (Gtk.CheckButton) builder.get_object("check: remember_password");
464-
465- Gtk.Label label_username = (Gtk.Label) builder.get_object("label: username");
466- Gtk.Label label_smtp = (Gtk.Label) builder.get_object("label: smtp");
467-
468- // Load translated text for labels with markup unsupported by glade.
469- Gtk.Label primary_text_label = (Gtk.Label) builder.get_object("primary_text_label");
470- primary_text_label.set_markup(PRIMARY_TEXT_MARKUP.printf(PRIMARY_TEXT_FIRST_TRY));
471-
472- if (smtp) {
473- label_username.set_text(account_information.smtp_credentials.user ?? "");
474- entry_password.set_text(account_information.smtp_credentials.pass ?? "");
475- } else {
476- label_username.set_text(account_information.imap_credentials.user ?? "");
477- entry_password.set_text(account_information.imap_credentials.pass ?? "");
478- }
479- check_remember_password.active = (smtp ? account_information.smtp_remember_password
480- : account_information.imap_remember_password);
481- if (smtp)
482- label_smtp.show();
483-
484- ok_button = (Gtk.Button) builder.get_object("authenticate_button");
485-
486- refresh_ok_button_sensitivity();
487- entry_password.changed.connect(refresh_ok_button_sensitivity);
488- }
489-
490- private void refresh_ok_button_sensitivity() {
491- ok_button.sensitive = !Geary.String.is_empty_or_whitespace(entry_password.get_text());
492- }
493-
494- public bool run() {
495- dialog.show();
496- dialog.get_action_area().show_all();
497-
498- Gtk.ResponseType response = (Gtk.ResponseType) dialog.run();
499- if (response == Gtk.ResponseType.OK) {
500- password = entry_password.get_text();
501- remember_password = check_remember_password.active;
502- }
503-
504- dialog.destroy();
505-
506- return (response == Gtk.ResponseType.OK);
507- }
508-}
509-

Subscribers

People subscribed via source and target branches