From 000f91caf98706d21868e0b41e42388ef68fc9e5 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 11:16:01 -0500 Subject: update Snap Decisions to include snooze --- include/datetime/snap.h | 4 ++-- src/main.cpp | 32 ++++++++++++++++---------------- src/snap.cpp | 24 +++++++++++------------- 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/include/datetime/snap.h b/include/datetime/snap.h index ef5c868..572158d 100644 --- a/include/datetime/snap.h +++ b/include/datetime/snap.h @@ -44,8 +44,8 @@ public: typedef std::function appointment_func; void operator()(const Appointment& appointment, - appointment_func show, - appointment_func dismiss); + appointment_func snooze, + appointment_func ok); private: class Impl; diff --git a/src/main.cpp b/src/main.cpp index 48d3d20..54517c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -37,8 +39,6 @@ #include // bindtextdomain() #include -#include - #include #include // exit() @@ -90,6 +90,7 @@ namespace } std::shared_ptr create_simple_alarm_queue(const std::shared_ptr& clock, + const std::shared_ptr& snooze_planner, const std::shared_ptr& engine, const std::shared_ptr& tz) { @@ -102,8 +103,14 @@ namespace upcoming_planner->date().set(now); }); + // create an aggregate planner that folds together the above + // upcoming-events planner and locally-generated snooze events + std::shared_ptr planner = std::make_shared(); + planner->add(upcoming_planner); + planner->add(snooze_planner); + auto wakeup_timer = std::make_shared(clock); - return std::make_shared(clock, upcoming_planner, wakeup_timer); + return std::make_shared(clock, planner, wakeup_timer); } } @@ -126,21 +133,14 @@ main(int /*argc*/, char** /*argv*/) MenuFactory factory(actions, state); // set up the snap decisions + auto snooze_planner = std::make_shared(state->settings, state->clock); auto notification_engine = std::make_shared("indicator-datetime-service"); std::unique_ptr snap (new Snap(notification_engine, state->settings)); - auto alarm_queue = create_simple_alarm_queue(state->clock, engine, timezone); - alarm_queue->alarm_reached().connect([&snap](const Appointment& appt){ - auto snap_show = [](const Appointment& a){ - const char* url; - if(!a.url.empty()) - url = a.url.c_str(); - else // alarm doesn't have a URl associated with it; use a fallback - url = "appid://com.ubuntu.clock/clock/current-user-version"; - url_dispatch_send(url, nullptr, nullptr); - }; - auto snap_dismiss = [](const Appointment&){}; - (*snap)(appt, snap_show, snap_dismiss); - }); + auto alarm_queue = create_simple_alarm_queue(state->clock, snooze_planner, engine, timezone); + auto on_snooze = [snooze_planner](const Appointment& a) {snooze_planner->add(a);}; + auto on_ok = [](const Appointment&){}; + auto on_alarm_reached = [&snap, &on_snooze, &on_ok](const Appointment& a) {(*snap)(a, on_snooze, on_ok);}; + alarm_queue->alarm_reached().connect(on_alarm_reached); // create the menus std::vector> menus; diff --git a/src/snap.cpp b/src/snap.cpp index 0b2322a..2a0fb5b 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -59,12 +59,12 @@ public: } void operator()(const Appointment& appointment, - appointment_func show, - appointment_func dismiss) + appointment_func snooze, + appointment_func ok) { if (!appointment.has_alarms) { - dismiss(appointment); + ok(appointment); return; } @@ -98,26 +98,24 @@ public: g_free (title); b.set_timeout (std::chrono::duration_cast(minutes)); if (interactive) { - b.add_action ("show", _("Show")); - b.add_action ("dismiss", _("Dismiss")); + b.add_action ("snooze", _("Snooze")); + b.add_action ("ok", _("OK")); } // add 'sound', 'haptic', and 'awake' objects to the capture so // they stay alive until the closed callback is called; i.e., // for the lifespan of the notficiation - b.set_closed_callback([appointment, show, dismiss, sound, awake, haptic] + b.set_closed_callback([appointment, snooze, ok, sound, awake, haptic] (const std::string& action){ - if (action == "show") - show(appointment); + if (action == "snooze") + snooze(appointment); else - dismiss(appointment); + ok(appointment); }); const auto key = m_engine->show(b); if (key) m_notifications.insert (key); - else - show(appointment); } private: @@ -177,9 +175,9 @@ Snap::~Snap() void Snap::operator()(const Appointment& appointment, appointment_func show, - appointment_func dismiss) + appointment_func ok) { - (*impl)(appointment, show, dismiss); + (*impl)(appointment, show, ok); } /*** -- cgit v1.2.3