Commit 657dce51 authored by William Jon McCann's avatar William Jon McCann Committed by Charles Lindsay

Clean up the password dialog

* Remove details section
* Fix plural problem
* Remove unnecessary labels
* Only allow to prompt for one password at a time, which was true in
  practice already, but the code is cleaner making that a requirement

Closes: bgo #720779
parent bd83b8bc
......@@ -65,12 +65,12 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
Geary.AccountInformation account_information,
out string? imap_password, out string? smtp_password,
out bool imap_remember_password, out bool smtp_remember_password) throws Error {
bool first_try = !account_information.imap_credentials.is_complete() ||
(account_information.smtp_credentials != null &&
!account_information.smtp_credentials.is_complete());
// Our dialog doesn't support asking for both at once, even though this
// API would indicate it does. We need to revamp the API.
assert(!services.has_imap() || !services.has_smtp());
PasswordDialog password_dialog = new PasswordDialog(account_information, first_try,
services);
PasswordDialog password_dialog = new PasswordDialog(services.has_smtp(),
account_information, services);
if (!password_dialog.run()) {
imap_password = null;
......@@ -82,10 +82,17 @@ public class SecretMediator : Geary.CredentialsMediator, Object {
// password_dialog.password should never be null at this point. It will only be null when
// password_dialog.run() returns false, in which case we have already returned.
imap_password = password_dialog.imap_password;
smtp_password = password_dialog.smtp_password;
imap_remember_password = password_dialog.remember_password;
smtp_remember_password = password_dialog.remember_password;
if (services.has_smtp()) {
imap_password = null;
imap_remember_password = false;
smtp_password = password_dialog.password;
smtp_remember_password = password_dialog.remember_password;
} else {
imap_password = password_dialog.password;
imap_remember_password = password_dialog.remember_password;
smtp_password = null;
smtp_remember_password = false;
}
return true;
}
}
......@@ -13,90 +13,46 @@ public class PasswordDialog {
// strings, and Glade doesn't support the "larger" size attribute. See this bug report for
// details: https://bugzilla.gnome.org/show_bug.cgi?id=679006
private const string PRIMARY_TEXT_MARKUP = "<span weight=\"bold\" size=\"larger\">%s</span>";
private const string PRIMARY_TEXT_FIRST_TRY = _("Please enter your email password");
private const string PRIMARY_TEXT_REPEATED_TRY = _("Unable to login to email server");
private const string PRIMARY_TEXT_FIRST_TRY = _("Please enter your password");
private Gtk.Dialog dialog;
private Gtk.Entry entry_imap_password;
private Gtk.Entry entry_password;
private Gtk.CheckButton check_remember_password;
private Gtk.Entry entry_smtp_password;
private Gtk.Button ok_button;
private Gtk.Grid grid_imap;
private Gtk.Grid grid_smtp;
private Geary.CredentialsMediator.ServiceFlag password_flags;
public string imap_password { get; private set; default = ""; }
public string smtp_password { get; private set; default = ""; }
public string password { get; private set; default = ""; }
public bool remember_password { get; private set; }
public PasswordDialog(Geary.AccountInformation account_information, bool first_try,
public PasswordDialog(bool smtp, Geary.AccountInformation account_information,
Geary.CredentialsMediator.ServiceFlag password_flags) {
this.password_flags = password_flags;
Gtk.Builder builder = GearyApplication.instance.create_builder("password-dialog.glade");
// Load dialog
dialog = (Gtk.Dialog) builder.get_object("PasswordDialog");
dialog.set_type_hint(Gdk.WindowTypeHint.DIALOG);
dialog.set_default_response(Gtk.ResponseType.OK);
// Load editable widgets
entry_imap_password = (Gtk.Entry) builder.get_object("entry: imap password");
entry_smtp_password = (Gtk.Entry) builder.get_object("entry: smtp password");
entry_password = (Gtk.Entry) builder.get_object("entry: password");
check_remember_password = (Gtk.CheckButton) builder.get_object("check: remember_password");
// Load non-editable widgets
Gtk.Label label_real_name = (Gtk.Label) builder.get_object("label: real_name");
Gtk.Label label_service = (Gtk.Label) builder.get_object("label: service");
grid_imap = (Gtk.Grid) builder.get_object("grid: imap");
Gtk.Label label_imap_username = (Gtk.Label) builder.get_object("label: imap username");
Gtk.Label label_imap_server = (Gtk.Label) builder.get_object("label: imap server");
Gtk.Label label_imap_port = (Gtk.Label) builder.get_object("label: imap port");
Gtk.Label label_imap_encryption = (Gtk.Label) builder.get_object("label: imap encryption");
grid_smtp = (Gtk.Grid) builder.get_object("grid: smtp");
Gtk.Label label_smtp_username = (Gtk.Label) builder.get_object("label: smtp username");
Gtk.Label label_smtp_server = (Gtk.Label) builder.get_object("label: smtp server");
Gtk.Label label_smtp_port = (Gtk.Label) builder.get_object("label: smtp port");
Gtk.Label label_smtp_encryption = (Gtk.Label) builder.get_object("label: smtp encryption");
Gtk.Label label_username = (Gtk.Label) builder.get_object("label: username");
Gtk.Label label_smtp = (Gtk.Label) builder.get_object("label: smtp");
// Load translated text for labels with markup unsupported by glade.
Gtk.Label primary_text_label = (Gtk.Label) builder.get_object("primary_text_label");
primary_text_label.set_markup(get_primary_text_markup(first_try));
// Find server configuration information
Geary.Endpoint imap_endpoint;
Geary.Endpoint smtp_endpoint;
imap_endpoint = account_information.get_imap_endpoint();
smtp_endpoint = account_information.get_smtp_endpoint();
primary_text_label.set_markup(PRIMARY_TEXT_MARKUP.printf(PRIMARY_TEXT_FIRST_TRY));
string imap_server_host = imap_endpoint.host_specifier;
uint16 imap_server_port = imap_endpoint.default_port;
string smtp_server_host = smtp_endpoint.host_specifier;
uint16 smtp_server_port = smtp_endpoint.default_port;
// Load initial values
label_real_name.set_text(account_information.real_name ?? "");
label_service.set_text(account_information.service_provider.display_name() ?? "");
label_imap_username.set_text(account_information.imap_credentials.user ?? "");
entry_imap_password.set_text(account_information.imap_credentials.pass ?? "");
label_imap_server.set_text(imap_server_host);
label_imap_port.set_text(imap_server_port.to_string());
label_imap_encryption.set_text(get_security_status(imap_endpoint.flags));
if (account_information.smtp_credentials != null) {
label_smtp_username.set_text(account_information.smtp_credentials.user ?? "");
entry_smtp_password.set_text(account_information.smtp_credentials.pass ?? "");
if (smtp) {
label_username.set_text(account_information.smtp_credentials.user ?? "");
entry_password.set_text(account_information.smtp_credentials.pass ?? "");
} else {
label_username.set_text(account_information.imap_credentials.user ?? "");
entry_password.set_text(account_information.imap_credentials.pass ?? "");
}
check_remember_password.active = (smtp ? account_information.smtp_remember_password
: account_information.imap_remember_password);
if (smtp)
label_smtp.show();
label_smtp_server.set_text(smtp_server_host);
label_smtp_port.set_text(smtp_server_port.to_string());
label_smtp_encryption.set_text(get_security_status(smtp_endpoint.flags));
check_remember_password.active = account_information.imap_remember_password;
// Add action buttons
Gtk.Button cancel_button = new Gtk.Button.from_stock(Stock._CANCEL);
ok_button = new Gtk.Button.from_stock(Stock._OK);
ok_button.can_default = true;
......@@ -104,48 +60,21 @@ public class PasswordDialog {
dialog.add_action_widget(ok_button, Gtk.ResponseType.OK);
dialog.set_default_response(Gtk.ResponseType.OK);
// Setup listeners
refresh_ok_button_sensitivity();
entry_imap_password.changed.connect(refresh_ok_button_sensitivity);
entry_smtp_password.changed.connect(refresh_ok_button_sensitivity);
}
private string get_primary_text_markup(bool first_try) {
return PRIMARY_TEXT_MARKUP.printf(first_try ? PRIMARY_TEXT_FIRST_TRY : PRIMARY_TEXT_REPEATED_TRY);
entry_password.changed.connect(refresh_ok_button_sensitivity);
}
private void refresh_ok_button_sensitivity() {
ok_button.sensitive = !Geary.String.is_empty_or_whitespace(entry_imap_password.get_text()) ||
!Geary.String.is_empty_or_whitespace(entry_smtp_password.get_text());
}
private string get_security_status(Geary.Endpoint.Flags flags) {
if (flags.is_all_set(Geary.Endpoint.Flags.SSL))
return _("SSL");
else if (flags.is_all_set(Geary.Endpoint.Flags.STARTTLS))
return _("STARTTLS");
return _("None");
ok_button.sensitive = !Geary.String.is_empty_or_whitespace(entry_password.get_text());
}
public bool run() {
dialog.show();
dialog.get_action_area().show_all();
if (!password_flags.has_imap()) {
grid_imap.hide();
entry_smtp_password.grab_focus();
}
if (!password_flags.has_smtp()) {
grid_smtp.hide();
entry_imap_password.grab_focus();
}
Gtk.ResponseType response = (Gtk.ResponseType) dialog.run();
if (response == Gtk.ResponseType.OK) {
imap_password = entry_imap_password.get_text();
smtp_password = entry_smtp_password.get_text();
password = entry_password.get_text();
remember_password = check_remember_password.active;
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment