[california/wip/725792-quick-add: 4/5] Connect everything up
- From: Jim Nelson <jnelson src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [california/wip/725792-quick-add: 4/5] Connect everything up
- Date: Wed, 23 Apr 2014 00:31:06 +0000 (UTC)
commit 8c49f0a443ef600b0a68317bb40d1dd35757cf46
Author: Jim Nelson <jim yorba org>
Date: Tue Apr 22 17:30:34 2014 -0700
Connect everything up
src/component/component-details-parser.vala | 13 +++----------
src/component/component-event.vala | 7 +++++++
src/component/component-instance.vala | 10 ++++++++++
src/host/host-create-update-event.vala | 16 +++++++++++++---
src/host/host-main-window.vala | 24 +++++++++++++++++++-----
src/host/host-quick-create-event.vala | 5 ++++-
src/tests/tests-quick-add.vala | 20 ++++++++++----------
7 files changed, 66 insertions(+), 29 deletions(-)
---
diff --git a/src/component/component-details-parser.vala b/src/component/component-details-parser.vala
index 2882a0e..2811fb5 100644
--- a/src/component/component-details-parser.vala
+++ b/src/component/component-details-parser.vala
@@ -74,7 +74,8 @@ public class DetailsParser : BaseObject {
*
* If the details string is empty, a blank Event is generated.
*/
- public DetailsParser(string? details) {
+ public DetailsParser(string? details, Backing.CalendarSource? calendar_source) {
+ event.calendar_source = calendar_source;
this.details = details ?? "";
// tokenize the string and arrange as a stack for the parser
@@ -187,15 +188,6 @@ public class DetailsParser : BaseObject {
if (start_date != null && end_date == null)
end_date = midnight_crossed ? start_date.adjust(1, Calendar.DateUnit.DAY) : start_date;
- debug("details: %s", details);
- 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("summary: \"%s\"", summary.str);
- debug("location: \"%s\"", location.str);
-
// Event start/end time, if specified
if (start_time != null && end_time != null) {
assert(start_date != null);
@@ -216,6 +208,7 @@ public class DetailsParser : BaseObject {
if (!String.is_empty(location.str))
event.location = location.str;
+ // store full detail text in the event description for user and for debugging
event.description = details;
}
diff --git a/src/component/component-event.vala b/src/component/component-event.vala
index a3b5b94..bd68069 100644
--- a/src/component/component-event.vala
+++ b/src/component/component-event.vala
@@ -251,6 +251,13 @@ public class Event : Instance, Gee.Comparable<Event> {
}
/**
+ * @inheritDoc
+ */
+ public override bool is_valid() {
+ return base.is_valid() && (date_span != null || exact_time_span != null);
+ }
+
+ /**
* Compares an { link Event} to another and returns which is chronologically first.
*
* The method attempts to compare DATE-TIMEs first, then DATEs, coercing a DATE-TIME into a DATE
diff --git a/src/component/component-instance.vala b/src/component/component-instance.vala
index 037f851..8c56076 100644
--- a/src/component/component-instance.vala
+++ b/src/component/component-instance.vala
@@ -352,6 +352,16 @@ public abstract class Instance : BaseObject, Gee.Hashable<Instance> {
}
/**
+ * Returns true if all the fields necessary for creating/updating the { link Instance} are
+ * present with proper values.
+ *
+ * The presence of { link calendar_source} is not necessary to deem an Instance valid.
+ */
+ public virtual bool is_valid() {
+ return dtstamp != null;
+ }
+
+ /**
* Equality is defined as { link Component.Instance}s having the same UID.
*
* Subclasses should override this and { link hash} if more definite equality is necessary.
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index 4e4d3e0..1e1fec8 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -93,6 +93,12 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
init();
}
+ public CreateUpdateEvent.finish(Component.Event event) {
+ this.event = event;
+
+ init();
+ }
+
private void init() {
if (event.summary != null)
summary_entry.text = event.summary;
@@ -111,14 +117,18 @@ public class CreateUpdateEvent : Gtk.Grid, Toolkit.Card {
event.exact_time_span.start_exact_time.to_timezone(Calendar.Timezone.local));
initial_end_time = new Calendar.WallTime.from_exact_time(
event.exact_time_span.end_exact_time.to_timezone(Calendar.Timezone.local));
- } else {
- assert(event.date_span != null);
-
+ } else if (event.date_span != null) {
all_day_toggle.active = true;
selected_date_span = event.date_span;
initial_start_time = new Calendar.WallTime.from_exact_time(Calendar.System.now);
initial_end_time = new Calendar.WallTime.from_exact_time(
Calendar.System.now.adjust_time(1, Calendar.TimeUnit.HOUR));
+ } else {
+ all_day_toggle.active = false;
+ selected_date_span = new Calendar.DateSpan(Calendar.System.today, Calendar.System.today);
+ initial_start_time = new Calendar.WallTime.from_exact_time(Calendar.System.now);
+ initial_end_time = new Calendar.WallTime.from_exact_time(
+ Calendar.System.now.adjust_time(1, Calendar.TimeUnit.HOUR));
}
// initialize start and end time (as in, wall clock time)
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index 59cfdad..f4f666d 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -139,7 +139,19 @@ public class MainWindow : Gtk.ApplicationWindow {
}
private void on_quick_create_event() {
- show_deck(quick_add_button, null, iterate<Toolkit.Card>(new QuickCreateEvent()).to_array_list());
+ QuickCreateEvent quick_create = new QuickCreateEvent();
+
+ quick_create.completed.connect(() => {
+ if (quick_create.parsed_event == null)
+ return;
+
+ if (quick_create.parsed_event.is_valid())
+ create_event_async.begin(quick_create.parsed_event, null);
+ else
+ create_event(null, null, quick_create.parsed_event, true, quick_add_button, null);
+ });
+
+ show_deck(quick_add_button, null, iterate<Toolkit.Card>(quick_create).to_array_list());
}
private void on_jump_to_today() {
@@ -156,16 +168,16 @@ public class MainWindow : Gtk.ApplicationWindow {
private void on_request_create_timed_event(Calendar.ExactTimeSpan initial, Gtk.Widget relative_to,
Gdk.Point? for_location) {
- create_event(initial, null, null, relative_to, for_location);
+ create_event(initial, null, null, false, relative_to, for_location);
}
private void on_request_create_all_day_event(Calendar.DateSpan initial, Gtk.Widget relative_to,
Gdk.Point? for_location) {
- create_event(null, initial, null, relative_to, for_location);
+ create_event(null, initial, null, false, relative_to, for_location);
}
private void create_event(Calendar.ExactTimeSpan? time_span, Calendar.DateSpan? date_span,
- Component.Event? existing, Gtk.Widget relative_to, Gdk.Point? for_location) {
+ Component.Event? existing, bool create_existing, Gtk.Widget relative_to, Gdk.Point? for_location) {
assert(time_span != null || date_span != null || existing != null);
CreateUpdateEvent create_update_event;
@@ -173,6 +185,8 @@ public class MainWindow : Gtk.ApplicationWindow {
create_update_event = new CreateUpdateEvent(time_span);
else if (date_span != null)
create_update_event = new CreateUpdateEvent.all_day(date_span);
+ else if (create_existing)
+ create_update_event = new CreateUpdateEvent.finish(existing);
else
create_update_event = new CreateUpdateEvent.update(existing);
@@ -219,7 +233,7 @@ public class MainWindow : Gtk.ApplicationWindow {
});
show_event.update_event.connect(() => {
- create_event(null, null, event, relative_to, for_location);
+ create_event(null, null, event, false, relative_to, for_location);
});
show_deck(relative_to, for_location, iterate<Toolkit.Card>(show_event).to_array_list());
diff --git a/src/host/host-quick-create-event.vala b/src/host/host-quick-create-event.vala
index 418c677..09c0273 100644
--- a/src/host/host-quick-create-event.vala
+++ b/src/host/host-quick-create-event.vala
@@ -14,6 +14,8 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
public string? title { get { return null; } }
+ public Component.Event? parsed_event { get; private set; default = null; }
+
public Gtk.Widget? default_widget { get { return create_button; } }
public Gtk.Widget? initial_focus { get { return details_entry; } }
@@ -64,7 +66,8 @@ public class QuickCreateEvent : Gtk.Grid, Toolkit.Card {
[GtkCallback]
private void on_create_button_clicked() {
- new Component.DetailsParser(details_entry.text);
+ Component.DetailsParser parser = new Component.DetailsParser(details_entry.text, model.active);
+ parsed_event = parser.event;
completed();
dismissed(true);
diff --git a/src/tests/tests-quick-add.vala b/src/tests/tests-quick-add.vala
index 30c76b2..c65302a 100644
--- a/src/tests/tests-quick-add.vala
+++ b/src/tests/tests-quick-add.vala
@@ -31,7 +31,7 @@ private class QuickAdd : UnitTest.Harness {
}
private bool summary() throws Error {
- Component.DetailsParser parser = new Component.DetailsParser("meet with Alice");
+ Component.DetailsParser parser = new Component.DetailsParser("meet with Alice", null);
return parser.event.summary == "meet with Alice"
&& parser.event.location == null
@@ -40,7 +40,7 @@ private class QuickAdd : UnitTest.Harness {
}
private bool summary_location() throws Error {
- Component.DetailsParser parser = new Component.DetailsParser("meet with Alice at Bob's");
+ Component.DetailsParser parser = new Component.DetailsParser("meet with Alice at Bob's", null);
return parser.event.summary == "meet with Alice at Bob's"
&& parser.event.location == "Bob's"
@@ -49,11 +49,11 @@ private class QuickAdd : UnitTest.Harness {
}
private bool with_12hr_time() throws Error {
- return with_time(new Component.DetailsParser("dinner at 7pm with Alice"));
+ return with_time(new Component.DetailsParser("dinner at 7pm with Alice", null));
}
private bool with_24hr_time() throws Error {
- return with_time(new Component.DetailsParser("dinner at 1900 with Alice"));
+ return with_time(new Component.DetailsParser("dinner at 1900 with Alice", null));
}
private bool with_time(Component.DetailsParser parser) {
@@ -70,7 +70,7 @@ private class QuickAdd : UnitTest.Harness {
}
private bool with_day_of_week() throws Error {
- Component.DetailsParser parser = new Component.DetailsParser("dinner Monday at Bob's with Alice");
+ Component.DetailsParser parser = new Component.DetailsParser("dinner Monday at Bob's with Alice",
null);
return parser.event.summary == "dinner at Bob's with Alice"
&& parser.event.location == "Bob's with Alice"
@@ -78,7 +78,7 @@ private class QuickAdd : UnitTest.Harness {
}
private bool with_delay() throws Error {
- Component.DetailsParser parser = new Component.DetailsParser("meet Alice in 3 hours");
+ Component.DetailsParser parser = new Component.DetailsParser("meet Alice in 3 hours", null);
Calendar.WallTime start = new Calendar.WallTime.from_exact_time(Calendar.System.now).adjust(
3, Calendar.TimeUnit.HOUR, null);
@@ -93,7 +93,7 @@ private class QuickAdd : UnitTest.Harness {
}
private bool with_duration() throws Error {
- Component.DetailsParser parser = new Component.DetailsParser("meet Alice for 2 hrs");
+ Component.DetailsParser parser = new Component.DetailsParser("meet Alice for 2 hrs", null);
Calendar.WallTime start = new Calendar.WallTime.from_exact_time(Calendar.System.now);
Calendar.WallTime end = start.adjust(2, Calendar.TimeUnit.HOUR, null);
@@ -104,7 +104,7 @@ private class QuickAdd : UnitTest.Harness {
}
private bool with_delay_and_duration() throws Error {
- Component.DetailsParser parser = new Component.DetailsParser("meet Alice in 3 hours for 30 min");
+ Component.DetailsParser parser = new Component.DetailsParser("meet Alice in 3 hours for 30 min",
null);
Calendar.WallTime start = new Calendar.WallTime.from_exact_time(Calendar.System.now.adjust_time(3,
Calendar.TimeUnit.HOUR));
Calendar.WallTime end = start.adjust(30, Calendar.TimeUnit.MINUTE, null);
@@ -115,7 +115,7 @@ private class QuickAdd : UnitTest.Harness {
}
private bool indeterminate_time() throws Error {
- Component.DetailsParser parser = new Component.DetailsParser("meet Alice 4");
+ Component.DetailsParser parser = new Component.DetailsParser("meet Alice 4", null);
return parser.event.summary == "meet Alice 4"
&& parser.event.exact_time_span == null
@@ -124,7 +124,7 @@ private class QuickAdd : UnitTest.Harness {
private bool dialog_example() throws Error {
Component.DetailsParser parser = new Component.DetailsParser(
- "Dinner at Tadich Grill 7:30pm tomorrow");
+ "Dinner at Tadich Grill 7:30pm tomorrow", null);
Calendar.ExactTime time = new Calendar.ExactTime(
Calendar.System.timezone,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]