[geary/wip/714922-multiple-addresses-2: 30/30] Parse emails better, secondary delete icon in entry box
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/wip/714922-multiple-addresses-2: 30/30] Parse emails better, secondary delete icon in entry box
- Date: Wed, 4 Mar 2015 03:02:44 +0000 (UTC)
commit 1f9ecc05c2cc7c39e3646d51e1cfb4a597d818dd
Author: Jim Nelson <jim yorba org>
Date: Tue Mar 3 18:59:19 2015 -0800
Parse emails better, secondary delete icon in entry box
.../account-dialog-edit-alternate-emails-pane.vala | 69 ++++++++++++++++----
1 files changed, 55 insertions(+), 14 deletions(-)
---
diff --git a/src/client/accounts/account-dialog-edit-alternate-emails-pane.vala
b/src/client/accounts/account-dialog-edit-alternate-emails-pane.vala
index 8b387a7..295c850 100644
--- a/src/client/accounts/account-dialog-edit-alternate-emails-pane.vala
+++ b/src/client/accounts/account-dialog-edit-alternate-emails-pane.vala
@@ -6,12 +6,12 @@
public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
private class ListItem : Gtk.Label {
- public Geary.RFC822.MailboxAddress mailbox;
+ public string address;
- public ListItem(Geary.RFC822.MailboxAddress mailbox) {
- this.mailbox = mailbox;
+ public ListItem(string address) {
+ this.address = address;;
- label = "<b>%s</b>".printf(Geary.HTML.escape_markup(mailbox.address));
+ label = "<b>%s</b>".printf(Geary.HTML.escape_markup(address));
use_markup = true;
ellipsize = Pango.EllipsizeMode.END;
xalign = 0.0f;
@@ -54,8 +54,15 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
cancel_button = (Gtk.Button) builder.get_object("cancel_button");
update_button = (Gtk.Button) builder.get_object("update_button");
+ // Clear text when the secondary icon (not always available) is pressed
+ email_entry.icon_release.connect((pos) => {
+ if (pos == Gtk.EntryIconPosition.SECONDARY)
+ email_entry.text = "";
+ });
+
email_entry.bind_property("text", add_button, "sensitive", BindingFlags.SYNC_CREATE,
transform_email_to_sensitive);
+ email_entry.notify["text-length"].connect(on_email_entry_text_length_changed);
bind_property("changed", update_button, "sensitive", BindingFlags.SYNC_CREATE);
delete_button.sensitive = false;
@@ -67,12 +74,45 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
update_button.clicked.connect(on_update_clicked);
}
+ private bool validate_address_text(string email_address, out string? parsed) {
+ parsed = null;
+
+ Geary.RFC822.MailboxAddresses mailboxes = new Geary.RFC822.MailboxAddresses.from_rfc822_string(
+ email_address);
+ if (mailboxes.size != 1)
+ return false;
+
+ Geary.RFC822.MailboxAddress mailbox = mailboxes.get(0);
+
+ if (!mailbox.is_valid())
+ return false;
+
+ if (Geary.String.stri_equal(mailbox.address, primary_mailbox.address))
+ return false;
+
+ if (Geary.String.is_empty(mailbox.address))
+ return false;
+
+ parsed = mailbox.address;
+
+ return true;
+ }
+
private bool transform_email_to_sensitive(Binding binding, Value source, ref Value target) {
- target = Geary.RFC822.MailboxAddress.is_valid_address(email_entry.text);
+ string? parsed;
+ target = validate_address_text(email_entry.text, out parsed) && !email_addresses.contains(parsed);
return true;
}
+ private void on_email_entry_text_length_changed() {
+ bool has_text = email_entry.text_length != 0;
+
+ email_entry.secondary_icon_name = has_text ? "edit-clear-symbolic" : null;
+ email_entry.secondary_icon_sensitive = has_text;
+ email_entry.secondary_icon_activatable = has_text;
+ }
+
public void set_account(Geary.AccountInformation account_info) {
this.account_info = account_info;
@@ -103,18 +143,19 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
}
private void add_email_address(string email_address, bool is_change) {
- if (email_addresses.contains(email_address))
+ string? parsed_address;
+ if (!validate_address_text(email_address, out parsed_address))
return;
- if (!Geary.RFC822.MailboxAddress.is_valid_address(email_address))
+ if (Geary.String.is_empty(parsed_address))
return;
- if (Geary.String.stri_equal(email_address, primary_mailbox.address))
+ if (email_addresses.contains(parsed_address))
return;
- email_addresses.add(email_address);
+ email_addresses.add(parsed_address);
- ListItem item = new ListItem(new Geary.RFC822.MailboxAddress(null, email_address));
+ ListItem item = new ListItem(parsed_address);
item.show_all();
address_listbox.add(item);
@@ -122,15 +163,15 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
changed = true;
}
- private void remove_email_address(Geary.RFC822.MailboxAddress mailbox) {
- if (!email_addresses.remove(mailbox.address))
+ private void remove_email_address(string address) {
+ if (!email_addresses.remove(address))
return;
foreach (Gtk.Widget widget in address_listbox.get_children()) {
Gtk.ListBoxRow row = (Gtk.ListBoxRow) widget;
ListItem item = (ListItem) row.get_child();
- if (item.mailbox.address == mailbox.address) {
+ if (item.address == address) {
address_listbox.remove(widget);
changed = true;
@@ -156,7 +197,7 @@ public class AccountDialogEditAlternateEmailsPane : AccountDialogPane {
private void on_delete_clicked() {
if (selected_item != null)
- remove_email_address(selected_item.mailbox);
+ remove_email_address(selected_item.address);
}
private void on_update_clicked() {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]