From bcd8f964ebcd3e03710c8474cbcf4125fd9580e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 25 Jul 2019 09:29:29 -0700 Subject: [PATCH 1/5] IndividualView: Display email addresses --- src/IndividualView.vala | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/IndividualView.vala b/src/IndividualView.vala index cd2ede1..be0def1 100644 --- a/src/IndividualView.vala +++ b/src/IndividualView.vala @@ -21,6 +21,8 @@ public class Friends.IndividualView : Gtk.Grid { public Folks.Individual? individual { get; set; } + private Gtk.ListBox individual_emails; + construct { var placeholder = new Gtk.Label (_("No Contact Selected")); placeholder.expand = true; @@ -31,11 +33,16 @@ public class Friends.IndividualView : Gtk.Grid { var individual_name = new Gtk.Label (null); individual_name.ellipsize = Pango.EllipsizeMode.MIDDLE; - individual_name.expand = true; individual_name.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); + individual_emails = new Gtk.ListBox (); + update_emails (); + var details_grid = new Gtk.Grid (); + details_grid.halign = details_grid.valign = Gtk.Align.CENTER; + details_grid.orientation = Gtk.Orientation.VERTICAL; details_grid.add (individual_name); + details_grid.add (individual_emails); var stack = new Gtk.Stack (); stack.add (placeholder); @@ -48,9 +55,27 @@ public class Friends.IndividualView : Gtk.Grid { stack.visible_child = details_grid; individual_name.label = individual.display_name; + + update_emails (); } else { stack.visible_child = placeholder; } }); } + + private void update_emails () { + foreach (unowned Gtk.Widget child in individual_emails.get_children ()) { + child.destroy (); + } + + if (individual != null && individual.email_addresses != null) { + foreach (var email in individual.email_addresses) { + var email_row = new Gtk.Label (email.value); + email_row.halign = Gtk.Align.START; + + individual_emails.add (email_row); + } + individual_emails.show_all (); + } + } } From f419364daf004664189e2b2d1aaf94b9e9aebcb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 25 Jul 2019 10:15:09 -0700 Subject: [PATCH 2/5] Launch email app when clicked --- src/IndividualView.vala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/IndividualView.vala b/src/IndividualView.vala index be0def1..f3ce36b 100644 --- a/src/IndividualView.vala +++ b/src/IndividualView.vala @@ -50,6 +50,15 @@ public class Friends.IndividualView : Gtk.Grid { add (stack); + individual_emails.row_activated.connect ((row) => { + var email = (Gtk.Label) row.get_child (); + try { + GLib.AppInfo.launch_default_for_uri ("mailto:%s".printf (email.label), null); + } catch (Error e) { + critical (e.message); + } + }); + notify["individual"].connect (() => { if (individual != null) { stack.visible_child = details_grid; From f45fb4a17e5df89a648d797269daccb928fbf667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 25 Jul 2019 11:08:26 -0700 Subject: [PATCH 3/5] fucking wizardry --- src/IndividualView.vala | 73 +++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/src/IndividualView.vala b/src/IndividualView.vala index f3ce36b..e04cb46 100644 --- a/src/IndividualView.vala +++ b/src/IndividualView.vala @@ -21,7 +21,10 @@ public class Friends.IndividualView : Gtk.Grid { public Folks.Individual? individual { get; set; } - private Gtk.ListBox individual_emails; + private Gtk.Grid email_grid; + private Gtk.MenuButton email_button; + private Gtk.Popover email_popover; + private ulong? email_button_handler = null; construct { var placeholder = new Gtk.Label (_("No Contact Selected")); @@ -35,14 +38,23 @@ public class Friends.IndividualView : Gtk.Grid { individual_name.ellipsize = Pango.EllipsizeMode.MIDDLE; individual_name.get_style_context ().add_class (Granite.STYLE_CLASS_H3_LABEL); - individual_emails = new Gtk.ListBox (); + email_grid = new Gtk.Grid (); + email_grid.orientation = Gtk.Orientation.VERTICAL; + email_grid.margin_top = email_grid.margin_bottom = 3; update_emails (); + email_popover = new Gtk.Popover (null); + email_popover.add (email_grid); + + email_button = new Gtk.MenuButton (); + email_button.halign = Gtk.Align.CENTER; + email_button.image = new Gtk.Image.from_icon_name ("mail-send-symbolic", Gtk.IconSize.LARGE_TOOLBAR); + var details_grid = new Gtk.Grid (); details_grid.halign = details_grid.valign = Gtk.Align.CENTER; details_grid.orientation = Gtk.Orientation.VERTICAL; details_grid.add (individual_name); - details_grid.add (individual_emails); + details_grid.add (email_button); var stack = new Gtk.Stack (); stack.add (placeholder); @@ -50,15 +62,6 @@ public class Friends.IndividualView : Gtk.Grid { add (stack); - individual_emails.row_activated.connect ((row) => { - var email = (Gtk.Label) row.get_child (); - try { - GLib.AppInfo.launch_default_for_uri ("mailto:%s".printf (email.label), null); - } catch (Error e) { - critical (e.message); - } - }); - notify["individual"].connect (() => { if (individual != null) { stack.visible_child = details_grid; @@ -73,18 +76,52 @@ public class Friends.IndividualView : Gtk.Grid { } private void update_emails () { - foreach (unowned Gtk.Widget child in individual_emails.get_children ()) { + if (email_button_handler != null) { + email_button.disconnect (email_button_handler); + email_button_handler = null; + } + + foreach (unowned Gtk.Widget child in email_grid.get_children ()) { child.destroy (); } if (individual != null && individual.email_addresses != null) { - foreach (var email in individual.email_addresses) { - var email_row = new Gtk.Label (email.value); - email_row.halign = Gtk.Align.START; + if (individual.email_addresses.size == 0) { + email_button.sensitive = false; + return; + } else if (individual.email_addresses.size == 1) { + email_button.popover = null; + email_button.sensitive = true; + email_button_handler = email_button.toggled.connect (() => { + if (email_button.active) { + try { + GLib.AppInfo.launch_default_for_uri ("mailto:%s".printf (individual.email_addresses.to_array ()[0].value), null); + } catch (Error e) { + critical (e.message); + } + } + email_button.active = false; + }); + return; + } - individual_emails.add (email_row); + foreach (var email in individual.email_addresses) { + var email_row = new Gtk.ModelButton (); + email_row.text = email.value; + + email_grid.add (email_row); + + email_row.clicked.connect (() => { + try { + GLib.AppInfo.launch_default_for_uri ("mailto:%s".printf (email.value), null); + } catch (Error e) { + critical (e.message); + } + }); } - individual_emails.show_all (); + email_grid.show_all (); + + email_button.popover = email_popover; } } } From 61ae6e8d8c5a4dd9094809a2a78b7c75d67c730c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 25 Jul 2019 11:11:59 -0700 Subject: [PATCH 4/5] pretty --- src/IndividualView.vala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/IndividualView.vala b/src/IndividualView.vala index e04cb46..d6f8ce0 100644 --- a/src/IndividualView.vala +++ b/src/IndividualView.vala @@ -49,10 +49,13 @@ public class Friends.IndividualView : Gtk.Grid { email_button = new Gtk.MenuButton (); email_button.halign = Gtk.Align.CENTER; email_button.image = new Gtk.Image.from_icon_name ("mail-send-symbolic", Gtk.IconSize.LARGE_TOOLBAR); + email_button.tooltip_text = _("Send Email"); + email_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); var details_grid = new Gtk.Grid (); details_grid.halign = details_grid.valign = Gtk.Align.CENTER; details_grid.orientation = Gtk.Orientation.VERTICAL; + details_grid.row_spacing = 12; details_grid.add (individual_name); details_grid.add (email_button); From cd21e5438ae12f3bf145c82bc84e704bcb967fb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20For=C3=A9?= Date: Thu, 25 Jul 2019 11:37:07 -0700 Subject: [PATCH 5/5] Get address labels --- src/IndividualView.vala | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/IndividualView.vala b/src/IndividualView.vala index d6f8ce0..ff48318 100644 --- a/src/IndividualView.vala +++ b/src/IndividualView.vala @@ -109,8 +109,27 @@ public class Friends.IndividualView : Gtk.Grid { } foreach (var email in individual.email_addresses) { + string description = _("email"); + var parameter_values = email.get_parameter_values (Folks.AbstractFieldDetails.PARAM_TYPE); + if (parameter_values != null) { + description = parameter_values.to_array ()[0]; + } + + var description_label = new Gtk.Label (description); + description_label.halign = Gtk.Align.START; + + var address_label = new Gtk.Label ("%s".printf (email.value)); + address_label.halign = Gtk.Align.START; + address_label.use_markup = true; + address_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + + var grid = new Gtk.Grid (); + grid.attach (description_label, 0, 0); + grid.attach (address_label, 0, 1); + var email_row = new Gtk.ModelButton (); - email_row.text = email.value; + email_row.get_child ().destroy (); + email_row.add (grid); email_grid.add (email_row);