[california/wip/731543-attendees] Fixups to show event popup
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/731543-attendees] Fixups to show event popup
- Date: Thu, 6 Nov 2014 00:35:44 +0000 (UTC)
commit e242571dc180d827e0af74b9ee0756e5c8a84dff
Author: Jim Nelson <jim yorba org>
Date: Wed Nov 5 13:12:16 2014 -0800
Fixups to show event popup
src/component/component-person.vala | 15 ++++++++++++---
src/host/host-show-event.vala | 22 +++++++++++++++-------
src/host/host.vala | 3 +++
src/util/util-string.vala | 4 ++++
4 files changed, 34 insertions(+), 10 deletions(-)
---
diff --git a/src/component/component-person.vala b/src/component/component-person.vala
index e2d5404..dce480c 100644
--- a/src/component/component-person.vala
+++ b/src/component/component-person.vala
@@ -54,9 +54,7 @@ public class Person : BaseObject, Gee.Hashable<Person> {
* This does not include the "mailto:" scheme but it will include the { link common_name} if
* present, i.e. "Bob Jones <bob example com>".
*/
- public string rfc822_mailbox { owned get {
- return String.is_empty(common_name) ? "<%s>".printf(mailbox) : "%s <%s>".printf(common_name,
mailbox);
- } }
+ public string full_mailbox { get; private set; }
private Gee.HashSet<string> parameters = new Gee.HashSet<string>(String.ci_hash, String.ci_equal);
@@ -68,6 +66,7 @@ public class Person : BaseObject, Gee.Hashable<Person> {
this.mailto = mailto;
this.common_name = common_name;
+ full_mailbox = make_full_address(mailto, common_name);
}
internal Person.from_property(iCal.icalproperty prop) throws Error {
@@ -107,6 +106,8 @@ public class Person : BaseObject, Gee.Hashable<Person> {
param = prop.get_next_parameter(iCal.icalparameter_kind.ANY_PARAMETER);
}
+
+ full_mailbox = make_full_address(mailto, common_name);
}
private static void validate_mailto(Soup.URI uri) throws ComponentError {
@@ -114,6 +115,14 @@ public class Person : BaseObject, Gee.Hashable<Person> {
throw new ComponentError.INVALID("Invalid mailto: %s", uri.to_string(false));
}
+ private static string make_full_address(Soup.URI mailto, string? common_name) {
+ // watch for common name simply being the email address
+ if (String.is_empty(common_name) || String.ascii_ci_equal(mailto.path, common_name))
+ return mailto.path;
+
+ return "%s <%s>".printf(common_name, mailto.path);
+ }
+
internal iCal.icalproperty as_ical_property() {
iCal.icalproperty prop = new iCal.icalproperty.attendee(mailto_text);
foreach (string parameter in parameters)
diff --git a/src/host/host-show-event.vala b/src/host/host-show-event.vala
index 439e1c7..4c985b4 100644
--- a/src/host/host-show-event.vala
+++ b/src/host/host-show-event.vala
@@ -171,7 +171,7 @@ public class ShowEvent : Gtk.Grid, Toolkit.Card {
Calendar.ExactTimeSpan.PrettyFlag.NONE, Calendar.Timezone.local));
// attendees
- set_label(who_label, who_text, event.attendees_to_string());
+ set_label(who_label, who_text,
traverse<Component.Person>(event.attendees).to_string(stringify_attendee));
// calendar
set_label(calendar_label, calendar_text, event.calendar_source != null ? event.calendar_source.title
: null);
@@ -215,10 +215,23 @@ public class ShowEvent : Gtk.Grid, Toolkit.Card {
return true;
}
+ private string? stringify_attendee(Component.Person attendee, bool is_first, bool is_last) {
+ return is_first ? attendee.mailbox : "%s%s".printf(EMAIL_SEPARATOR, attendee.full_mailbox);
+ }
+
// Note that text is not escaped, up to caller to determine if necessary or not.
private void set_label(Gtk.Label? label, Gtk.Label text, string? str) {
if (!String.is_empty(str)) {
text.label = str;
+
+ // build tooltip, each email address on a separate line, used if ellipsized (see
+ // on_label_drawn)
+ string tooltip = from_array<string>(str.split(EMAIL_SEPARATOR))
+ .transform(token => token.strip())
+ .filter(token => !String.is_empty(token))
+ .to_string((token, is_first, is_last) => { return is_last ? token : token + "\n"; });
+
+ text.set_data(DATA_TEXT, tooltip);
} else {
text.visible = false;
text.no_show_all = true;
@@ -229,17 +242,12 @@ public class ShowEvent : Gtk.Grid, Toolkit.Card {
label.no_show_all = true;
}
}
-
- text.set_data(DATA_TEXT, str);
}
private bool on_label_drawn(Gtk.Widget widget, Cairo.Context ctx) {
// if ellipsized, add a tooltip, otherwise remove it
Gtk.Label label = (Gtk.Label) widget;
- if (label.get_layout().is_ellipsized())
- label.set_tooltip_text(label.get_data(DATA_TEXT));
- else
- label.set_tooltip_text("");
+ label.set_tooltip_text(label.get_layout().is_ellipsized() ? label.get_data<string>(DATA_TEXT) : "");
return false;
}
diff --git a/src/host/host.vala b/src/host/host.vala
index 6e075a6..56cdcc2 100644
--- a/src/host/host.vala
+++ b/src/host/host.vala
@@ -14,6 +14,9 @@ namespace California.Host {
private int init_count = 0;
+// A common separator for email addresses, i.e. "alice example com, bob example com"
+private const string EMAIL_SEPARATOR = _(", ");
+
public void init() throws Error {
if (!Unit.do_init(ref init_count))
return;
diff --git a/src/util/util-string.vala b/src/util/util-string.vala
index b4ca45e..8aa676f 100644
--- a/src/util/util-string.vala
+++ b/src/util/util-string.vala
@@ -24,6 +24,10 @@ public bool ci_equal(string a, string b) {
return stricmp(a, b) == 0;
}
+public bool ascii_ci_equal(string a, string b) {
+ return a.ascii_casecmp(b) == 0;
+}
+
/**
* Removes redundant whitespace (including tabs and newlines) and strips whitespace from beginning
* and end of string.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]