[california/wip/731543-attendees] Distinguish between ATTENDEE and ORGANIZER
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/731543-attendees] Distinguish between ATTENDEE and ORGANIZER
- Date: Thu, 13 Nov 2014 03:07:38 +0000 (UTC)
commit 0fa3b1521b7c7c8c1eea5109b6da87b77ebe3f83
Author: Jim Nelson <jim yorba org>
Date: Wed Nov 12 18:43:47 2014 -0800
Distinguish between ATTENDEE and ORGANIZER
src/component/component-person.vala | 58 ++++++++++++++++++++++++++++++++---
src/host/host-attendees-editor.vala | 3 +-
2 files changed, 55 insertions(+), 6 deletions(-)
---
diff --git a/src/component/component-person.vala b/src/component/component-person.vala
index 78a81f6..12b6d0c 100644
--- a/src/component/component-person.vala
+++ b/src/component/component-person.vala
@@ -23,6 +23,19 @@ namespace California.Component {
public class Person : BaseObject, Gee.Hashable<Person>, Gee.Comparable<Person> {
/**
+ * The relationship of this { link Person} to the { link Instance}.
+ */
+ public enum Relationship {
+ ORGANIZER,
+ ATTENDEE
+ }
+
+ /**
+ * The { link Person}'s { link Relationship} to the { link Instance}.
+ */
+ public Relationship relationship { get; private set; }
+
+ /**
* The mailto: of the { link Person}, the only required value for the property.
*/
public Soup.URI mailto { get; private set; }
@@ -71,11 +84,12 @@ public class Person : BaseObject, Gee.Hashable<Person>, Gee.Comparable<Person> {
/**
* Create a { link Person} with the required { link mailto} and optional { link common_name}.
*/
- public Person(Soup.URI mailto, string? common_name = null,
+ public Person(Relationship relationship, Soup.URI mailto, string? common_name = null,
iCal.icalparameter_role role = iCal.icalparameter_role.REQPARTICIPANT, bool rsvp = false)
throws ComponentError {
validate_mailto(mailto);
+ this.relationship = relationship;
this.mailto = mailto;
this.common_name = common_name;
this.role = role;
@@ -94,6 +108,20 @@ public class Person : BaseObject, Gee.Hashable<Person>, Gee.Comparable<Person> {
}
internal Person.from_property(iCal.icalproperty prop) throws Error {
+ switch (prop.isa()) {
+ case iCal.icalproperty_kind.ATTENDEE_PROPERTY:
+ relationship = Relationship.ATTENDEE;
+ break;
+
+ case iCal.icalproperty_kind.ORGANIZER_PROPERTY:
+ relationship = Relationship.ORGANIZER;
+ break;
+
+ default:
+ throw new ComponentError.INVALID("Property must be an ATTENDEE or ORGANIZER: %s",
+ prop.isa().to_string());
+ }
+
unowned iCal.icalvalue? prop_value = prop.get_value();
if (prop_value == null || prop_value.is_valid() == 0) {
throw new ComponentError.INVALID("Property of kind %s has no associated value",
@@ -156,7 +184,20 @@ public class Person : BaseObject, Gee.Hashable<Person>, Gee.Comparable<Person> {
}
internal iCal.icalproperty as_ical_property() {
- iCal.icalproperty prop = new iCal.icalproperty.attendee(mailto_text);
+ iCal.icalproperty prop;
+ switch (relationship) {
+ case Relationship.ATTENDEE:
+ prop = new iCal.icalproperty.attendee(mailto_text);
+ break;
+
+ case Relationship.ORGANIZER:
+ prop = new iCal.icalproperty.organizer(mailto_text);
+ break;
+
+ default:
+ assert_not_reached();
+ }
+
foreach (string parameter in parameters)
prop.add_parameter(new iCal.icalparameter.from_string(parameter));
@@ -164,11 +205,14 @@ public class Person : BaseObject, Gee.Hashable<Person>, Gee.Comparable<Person> {
}
public uint hash() {
- return String.ci_hash(mailto.path);
+ return String.ci_hash(mailto.path) ^ relationship;
}
public bool equal_to(Person other) {
- return (this != other) ? String.ci_equal(mailto.path, other.mailto.path) : true;
+ if (this == other)
+ return true;
+
+ return relationship == other.relationship && String.ci_equal(mailto.path, other.mailto.path);
}
public int compare_to(Person other) {
@@ -182,7 +226,11 @@ public class Person : BaseObject, Gee.Hashable<Person>, Gee.Comparable<Person> {
return compare;
}
- return String.stricmp(mailbox, other.mailbox);
+ int compare = String.stricmp(mailbox, other.mailbox);
+ if (compare != 0)
+ return compare;
+
+ return relationship - other.relationship;
}
public override string to_string() {
diff --git a/src/host/host-attendees-editor.vala b/src/host/host-attendees-editor.vala
index 5e2646d..9031e83 100644
--- a/src/host/host-attendees-editor.vala
+++ b/src/host/host-attendees-editor.vala
@@ -79,7 +79,8 @@ public class AttendeesEditor : Gtk.Box, Toolkit.Card {
try {
// add to model (which adds to listbox) and clear entry
- guest_model.add(new Component.Person(URI.generate_mailto(add_guest_entry.text)));
+ guest_model.add(new Component.Person(Component.Person.Relationship.ATTENDEE,
+ URI.generate_mailto(add_guest_entry.text)));
add_guest_entry.text = "";
} catch (Error err) {
debug("Unable to generate mailto: %s", err.message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]