[california/wip/725792-quick-add] Create event with default values where not supplied
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/725792-quick-add] Create event with default values where not supplied
- Date: Fri, 18 Apr 2014 20:12:46 +0000 (UTC)
commit cc889f0aaad094340388d0f461cd755e13e67189
Author: Jim Nelson <jim yorba org>
Date: Fri Apr 18 13:12:35 2014 -0700
Create event with default values where not supplied
src/component/component-details-parser.vala | 43 +++++++++++++++++++++++++-
src/component/component-event.vala | 12 +++++++
vapi/libical.vapi | 2 +-
3 files changed, 54 insertions(+), 3 deletions(-)
---
diff --git a/src/component/component-details-parser.vala b/src/component/component-details-parser.vala
index de4fc46..55ac53a 100644
--- a/src/component/component-details-parser.vala
+++ b/src/component/component-details-parser.vala
@@ -112,15 +112,54 @@ public class DetailsParser : BaseObject {
add_text(tokens[ctr]);
}
+ // if a start time was described but not end time, use a 1 hour duration default
+ bool midnight_crossed = false;
+ if (start_time != null && end_time == null) {
+ if (duration != null)
+ end_time = start_time.adjust((int) duration.minutes, Calendar.TimeUnit.MINUTE, out
midnight_crossed);
+ else
+ end_time = start_time.adjust(1, Calendar.TimeUnit.HOUR, out midnight_crossed);
+ }
+
+ // if no start date was described but a start time was, assume for today
+ if (start_date == null && start_time != null)
+ start_date = Calendar.System.today;
+
+ // if no end date was describe, assume ends today as well (unless midnight was crossed
+ // due to duration)
+ if (start_date != null && end_date == null)
+ end_date = midnight_crossed ? start_date.adjust(1, Calendar.DateUnit.DAY) : start_date;
+
debug("start time: %s", (start_time != null) ? start_time.to_string() : "(null)");
debug("end time: %s", (end_time != null) ? end_time.to_string() : "(null)");
debug("duration: %s", (duration != null) ? duration.to_string() : "(null)");
debug("start date: %s", (start_date != null) ? start_date.to_string() : "(null)");
debug("end date: %s", (end_date != null) ? end_date.to_string() : "(null)");
- debug("title: \"%s\"", summary.str);
+ debug("summary: \"%s\"", summary.str);
debug("location: \"%s\"", location.str);
- return new Event.blank();
+ Component.Event event = new Component.Event.blank();
+
+ // fill in time/date, if specified
+ if (start_time != null && end_time != null) {
+ assert(start_date != null);
+ assert(end_date != null);
+
+ event.set_event_exact_time_span(new Calendar.ExactTimeSpan(
+ new Calendar.ExactTime(Calendar.System.timezone, start_date, start_time),
+ new Calendar.ExactTime(Calendar.System.timezone, end_date, end_time)
+ ));
+ } else if (start_date != null && end_date != null) {
+ event.set_event_date_span(new Calendar.DateSpan(start_date, end_date));
+ }
+
+ // other details
+ if (!String.is_empty(summary.str))
+ event.summary = summary.str;
+ if (!String.is_empty(location.str))
+ event.location = location.str;
+
+ return event;
}
private void add_text(string token) {
diff --git a/src/component/component-event.vala b/src/component/component-event.vala
index 08f0e69..a3b5b94 100644
--- a/src/component/component-event.vala
+++ b/src/component/component-event.vala
@@ -18,6 +18,7 @@ public class Event : Instance, Gee.Comparable<Event> {
public const string PROP_EXACT_TIME_SPAN = "exact-time-span";
public const string PROP_DATE_SPAN = "date-span";
public const string PROP_IS_ALL_DAY = "is-all-day";
+ public const string PROP_LOCATION = "location";
public const string PROP_STATUS = "status";
public enum Status {
@@ -62,6 +63,11 @@ public class Event : Instance, Gee.Comparable<Event> {
public bool is_all_day { get; private set; }
/**
+ * Location of an { link Event}.
+ */
+ public string? location { get; set; default = null; }
+
+ /**
* Status (confirmation) of an { link Event}.
*/
public Status status { get; set; default = Status.CONFIRMED; }
@@ -118,6 +124,8 @@ public class Event : Instance, Gee.Comparable<Event> {
// need to set this here because on_notify() doesn't update inside full update
is_all_day = (date_span != null);
+ location = ical_component.get_location();
+
switch (ical_component.get_status()) {
case iCal.icalproperty_status.TENTATIVE:
status = Status.TENTATIVE;
@@ -175,6 +183,10 @@ public class Event : Instance, Gee.Comparable<Event> {
is_all_day = (date_span != null);
break;
+ case PROP_LOCATION:
+ ical_component.set_location(location);
+ break;
+
case PROP_STATUS:
switch(status) {
case Status.TENTATIVE:
diff --git a/vapi/libical.vapi b/vapi/libical.vapi
index 14ea598..a04d261 100644
--- a/vapi/libical.vapi
+++ b/vapi/libical.vapi
@@ -109,7 +109,7 @@ namespace iCal {
[CCode (cname = "icalcomponent_get_inner")]
public unowned iCal.icalcomponent get_inner ();
[CCode (cname = "icalcomponent_get_location")]
- public unowned string get_location ();
+ public unowned string? get_location ();
[CCode (cname = "icalcomponent_get_method")]
public iCal.icalproperty_method get_method ();
[CCode (cname = "icalcomponent_get_next_component")]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]