From 15a383a7b027d281dcdaa85a43eb3563031366bf Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 10:35:27 -0500 Subject: add SnoozePlanner, AggregatePlanner --- include/datetime/planner-aggregate.h | 52 ++++++++++++++++ include/datetime/planner-snooze.h | 56 +++++++++++++++++ include/datetime/planner.h | 3 + src/planner-aggregate.cpp | 106 ++++++++++++++++++++++++++++++++ src/planner-snooze.cpp | 115 +++++++++++++++++++++++++++++++++++ src/planner.cpp | 88 +++++++++++++++++++++++++++ 6 files changed, 420 insertions(+) create mode 100644 include/datetime/planner-aggregate.h create mode 100644 include/datetime/planner-snooze.h create mode 100644 src/planner-aggregate.cpp create mode 100644 src/planner-snooze.cpp create mode 100644 src/planner.cpp diff --git a/include/datetime/planner-aggregate.h b/include/datetime/planner-aggregate.h new file mode 100644 index 0000000..eeca9b7 --- /dev/null +++ b/include/datetime/planner-aggregate.h @@ -0,0 +1,52 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_PLANNER_AGGREGATE_H +#define INDICATOR_DATETIME_PLANNER_AGGREGATE_H + +#include + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * \brief Aggregates one or more Planners + */ +class AggregatePlanner: public Planner +{ +public: + AggregatePlanner(); + virtual ~AggregatePlanner(); + void add(const std::shared_ptr&); + + core::Property>& appointments(); + +protected: + class Impl; + std::unique_ptr impl; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_PLANNER_AGGREGATE_H diff --git a/include/datetime/planner-snooze.h b/include/datetime/planner-snooze.h new file mode 100644 index 0000000..889c4f8 --- /dev/null +++ b/include/datetime/planner-snooze.h @@ -0,0 +1,56 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#ifndef INDICATOR_DATETIME_PLANNER_SNOOZE_H +#define INDICATOR_DATETIME_PLANNER_SNOOZE_H + +#include +#include +#include + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/** + * A planner to hold 'Snooze' copies of other appointments + */ +class SnoozePlanner: public Planner +{ +public: + SnoozePlanner(const std::shared_ptr&, + const std::shared_ptr&); + ~SnoozePlanner(); + void add(const Appointment&); + + core::Property>& appointments(); + +protected: + class Impl; + friend class Impl; + std::unique_ptr impl; +}; + +} // namespace datetime +} // namespace indicator +} // namespace unity + +#endif // INDICATOR_DATETIME_PLANNER_H diff --git a/include/datetime/planner.h b/include/datetime/planner.h index e6ef927..43991ec 100644 --- a/include/datetime/planner.h +++ b/include/datetime/planner.h @@ -38,10 +38,13 @@ class Planner { public: virtual ~Planner() =default; + virtual core::Property>& appointments() =0; protected: Planner() =default; + static void sort(std::vector&); + static void trim(std::vector&, const DateTime& begin, const DateTime& end); }; } // namespace datetime diff --git a/src/planner-aggregate.cpp b/src/planner-aggregate.cpp new file mode 100644 index 0000000..7458f0c --- /dev/null +++ b/src/planner-aggregate.cpp @@ -0,0 +1,106 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +class AggregatePlanner::Impl +{ +public: + Impl(AggregatePlanner* owner): + m_owner(owner) + { + } + + ~Impl() =default; + + core::Property>& appointments() + { + return m_appointments; + } + + void add(const std::shared_ptr& planner) + { + m_planners.push_back(planner); + + auto on_changed = [this](const std::vector&){rebuild();}; + auto connection = planner->appointments().changed().connect(on_changed); + m_connections.push_back(connection); + } + +private: + + void rebuild() + { + // use a sorted aggregate vector of all our planners + std::vector all; + for (const auto& planner : m_planners) { + const auto& walk = planner->appointments().get(); + all.insert(std::end(all), std::begin(walk), std::end(walk)); + } + m_owner->sort(all); + m_appointments.set(all); + } + + const AggregatePlanner* m_owner = nullptr; + core::Property> m_appointments; + std::vector> m_planners; + std::vector m_connections; +}; + +/*** +**** +***/ + +AggregatePlanner::AggregatePlanner(): + impl(new Impl{this}) +{ +} + +AggregatePlanner::~AggregatePlanner() +{ +} + +core::Property>& +AggregatePlanner::appointments() +{ + return impl->appointments(); +} + +void +AggregatePlanner::add(const std::shared_ptr& planner) +{ + return impl->add(planner); +} + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity + diff --git a/src/planner-snooze.cpp b/src/planner-snooze.cpp new file mode 100644 index 0000000..6d427ca --- /dev/null +++ b/src/planner-snooze.cpp @@ -0,0 +1,115 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#include + +#include // e_uid_new() + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +class SnoozePlanner::Impl +{ +public: + + Impl(SnoozePlanner* owner, + const std::shared_ptr& settings, + const std::shared_ptr& clock): + m_owner(owner), + m_settings(settings), + m_clock(clock) + { + } + + ~Impl() + { + } + + virtual core::Property>& appointments() + { + return m_appointments; + } + + void add(const Appointment& appt_in) + { + Appointment appt = appt_in; + + // adjust the time + const auto appt_length_secs = appt.end - appt.begin; + appt.begin = m_clock->localtime().add_full(0,0,0,0,m_settings->snooze_duration.get(),0); + appt.end = appt.begin.add_full(0,0,0,0,0,appt_length_secs); + + // give it a new ID + gchar* uid = e_uid_new(); + appt.uid = uid; + g_free(uid); + + // add it to our appointment list + auto tmp = appointments().get(); + tmp.push_back(appt); + m_owner->sort(tmp); + m_appointments.set(tmp); + } + +private: + + const SnoozePlanner* const m_owner; + const std::shared_ptr m_settings; + const std::shared_ptr m_clock; + core::Property> m_appointments; +}; + +/*** +**** +***/ + +SnoozePlanner::SnoozePlanner(const std::shared_ptr& settings, + const std::shared_ptr& clock): + impl(new Impl{this, settings, clock}) +{ +} + +SnoozePlanner::~SnoozePlanner() +{ +} + +void +SnoozePlanner::add(const Appointment& appointment) +{ + impl->add(appointment); +} + +core::Property>& +SnoozePlanner::appointments() +{ + return impl->appointments(); +} + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity diff --git a/src/planner.cpp b/src/planner.cpp new file mode 100644 index 0000000..3f73030 --- /dev/null +++ b/src/planner.cpp @@ -0,0 +1,88 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + * Authors: + * Charles Kerr + */ + +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +Planner::Planner() +{ +} + +Planner::~Planner() +{ +} + +void +Planner::set_range_to_calendar_month(const DateTime& dt) +{ + // use appointments that occur in dt's calendar month + impl->set_range_to_upcoming_month(dt.add_full(0, // no years + 0, // no months + -(dt.day_of_month()-1), + -dt.hour(), + -dt.minute(), + -dt.seconds()); +} + +void +Planner::set_range_to_upcoming_month(const DateTime& begin) +{ + // use appointments that occur in [dt...dt+1month] + const auto end = begin.add_full(0, 1, 0, 0, 0, -0.1); + const char * fmt = "%F %T"; + g_debug("RangePlanner %p setting range [%s..%s]", + this, + begin.format(fmt).c_str(), + end.format(fmt).c_str()); + range().set(std::make_pair(begin,end)); +} + +void +Planner::sort(std::vector& appts) +{ + std::sort(std::begin(appts), + std::end(appts), + [](const Appointment& a, const Appointment& b){return a.begin < b.begin;}); +} + +void +Planner::trim(std::vector& appts, + const DateTime& begin, + const DateTime& end) +{ + decltype(appts) tmp; + auto predicate = [begin,end](const Appointment& a){return begin<=a.begin && a.begin<=end;} + std::copy(std::begin(appts), std::end(appts), std::back_inserter(tmp), predicate); + appts.swap(tmp); +} + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity -- cgit v1.2.3 From d3732ff1a0d149544f89d08fa489e4f0fca8da07 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 10:37:03 -0500 Subject: add snooze properties to our schema; export it on the bus; add tests --- data/com.canonical.indicator.datetime.AlarmProperties.xml | 8 ++++++++ data/com.canonical.indicator.datetime.gschema.xml.in | 8 ++++++++ include/datetime/settings-live.h | 1 + include/datetime/settings-shared.h | 1 + include/datetime/settings.h | 1 + src/CMakeLists.txt | 2 ++ src/exporter.cpp | 1 + src/settings-live.cpp | 12 ++++++++++++ tests/test-exporter.cpp | 11 ++++++++++- tests/test-settings.cpp | 1 + 10 files changed, 45 insertions(+), 1 deletion(-) diff --git a/data/com.canonical.indicator.datetime.AlarmProperties.xml b/data/com.canonical.indicator.datetime.AlarmProperties.xml index 9b38af9..7ba0e5e 100644 --- a/data/com.canonical.indicator.datetime.AlarmProperties.xml +++ b/data/com.canonical.indicator.datetime.AlarmProperties.xml @@ -36,5 +36,13 @@ + + + + How many minutes to wait when the Snooze button is pressed. [Range: 1-15] + + + + diff --git a/data/com.canonical.indicator.datetime.gschema.xml.in b/data/com.canonical.indicator.datetime.gschema.xml.in index 4e4acd8..edcede2 100644 --- a/data/com.canonical.indicator.datetime.gschema.xml.in +++ b/data/com.canonical.indicator.datetime.gschema.xml.in @@ -154,5 +154,13 @@ How long the alarm's sound will be looped if its snap decision is not dismissed by the user. + + + 5 + <_summary>The snooze duration. + <_description> + How long to wait when the user hits the Snooze button. + + diff --git a/include/datetime/settings-live.h b/include/datetime/settings-live.h index 4850e69..bb4cd8d 100644 --- a/include/datetime/settings-live.h +++ b/include/datetime/settings-live.h @@ -59,6 +59,7 @@ private: void update_alarm_volume(); void update_alarm_duration(); void update_alarm_haptic(); + void update_snooze_duration(); GSettings* m_settings; diff --git a/include/datetime/settings-shared.h b/include/datetime/settings-shared.h index a211821..c18cfaf 100644 --- a/include/datetime/settings-shared.h +++ b/include/datetime/settings-shared.h @@ -49,5 +49,6 @@ TimeFormatMode; #define SETTINGS_ALARM_VOLUME_S "alarm-default-volume" #define SETTINGS_ALARM_DURATION_S "alarm-duration-minutes" #define SETTINGS_ALARM_HAPTIC_S "alarm-haptic-feedback" +#define SETTINGS_SNOOZE_DURATION_S "snooze-duration-minutes" #endif // INDICATOR_DATETIME_SETTINGS_SHARED diff --git a/include/datetime/settings.h b/include/datetime/settings.h index c6fe13b..0294f60 100644 --- a/include/datetime/settings.h +++ b/include/datetime/settings.h @@ -60,6 +60,7 @@ public: core::Property alarm_haptic; core::Property alarm_volume; core::Property alarm_duration; + core::Property snooze_duration; }; } // namespace datetime diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e583334..2852a75 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,8 @@ set (SERVICE_CXX_SOURCES locations-settings.cpp menu.cpp notifications.cpp + planner-aggregate.cpp + planner-snooze.cpp planner-month.cpp planner-range.cpp planner-upcoming.cpp diff --git a/src/exporter.cpp b/src/exporter.cpp index 1d45705..05b21eb 100644 --- a/src/exporter.cpp +++ b/src/exporter.cpp @@ -145,6 +145,7 @@ private: bind_uint_property(m_alarm_props, "default-volume", m_settings->alarm_volume); bind_string_property(m_alarm_props, "default-sound", m_settings->alarm_sound); bind_string_property(m_alarm_props, "haptic-feedback", m_settings->alarm_haptic); + bind_uint_property(m_alarm_props, "snooze-duration", m_settings->snooze_duration); } /*** diff --git a/src/settings-live.cpp b/src/settings-live.cpp index a8338ed..8ea06a4 100644 --- a/src/settings-live.cpp +++ b/src/settings-live.cpp @@ -56,6 +56,7 @@ LiveSettings::LiveSettings(): update_alarm_volume(); update_alarm_duration(); update_alarm_haptic(); + update_snooze_duration(); // now listen for clients to change the properties s.t. we can sync update GSettings @@ -135,6 +136,10 @@ LiveSettings::LiveSettings(): alarm_haptic.changed().connect([this](const std::string& value){ g_settings_set_string(m_settings, SETTINGS_ALARM_HAPTIC_S, value.c_str()); }); + + snooze_duration.changed().connect([this](unsigned int value){ + g_settings_set_uint(m_settings, SETTINGS_SNOOZE_DURATION_S, value); + }); } /*** @@ -249,6 +254,11 @@ void LiveSettings::update_alarm_haptic() g_free(val); } +void LiveSettings::update_snooze_duration() +{ + snooze_duration.set(g_settings_get_uint(m_settings, SETTINGS_SNOOZE_DURATION_S)); +} + /*** **** ***/ @@ -298,6 +308,8 @@ void LiveSettings::update_key(const std::string& key) update_alarm_duration(); else if (key == SETTINGS_ALARM_HAPTIC_S) update_alarm_haptic(); + else if (key == SETTINGS_SNOOZE_DURATION_S) + update_snooze_duration(); } /*** diff --git a/tests/test-exporter.cpp b/tests/test-exporter.cpp index 96665cf..ec19ef4 100644 --- a/tests/test-exporter.cpp +++ b/tests/test-exporter.cpp @@ -184,11 +184,13 @@ TEST_F(ExporterFixture, AlarmProperties) ***/ auto expected_volume = 1; - int expected_duration = 60; + int expected_duration = 4; + int expected_snooze_duration = 5; const char * expected_sound = "/tmp/foo.wav"; const char * expected_haptic = "pulse"; settings->alarm_volume.set(expected_volume); settings->alarm_duration.set(expected_duration); + settings->snooze_duration.set(expected_snooze_duration); settings->alarm_sound.set(expected_sound); settings->alarm_haptic.set(expected_haptic); wait_msec(); @@ -197,20 +199,24 @@ TEST_F(ExporterFixture, AlarmProperties) static constexpr const char* const VOLUME_PROP {"default-volume"}; static constexpr const char* const DURATION_PROP {"duration"}; static constexpr const char* const HAPTIC_PROP {"haptic-feedback"}; + static constexpr const char* const SNOOZE_PROP {"snooze-duration"}; char* sound = nullptr; char* haptic = nullptr; int volume = -1; int duration = -1; + int snooze = -1; g_object_get(proxy, SOUND_PROP, &sound, HAPTIC_PROP, &haptic, VOLUME_PROP, &volume, DURATION_PROP, &duration, + SNOOZE_PROP, &snooze, nullptr); EXPECT_STREQ(expected_sound, sound); EXPECT_STREQ(expected_haptic, haptic); EXPECT_EQ(expected_volume, volume); EXPECT_EQ(expected_duration, duration); + EXPECT_EQ(expected_snooze_duration, snooze); g_clear_pointer (&sound, g_free); g_clear_pointer (&haptic, g_free); @@ -223,10 +229,12 @@ TEST_F(ExporterFixture, AlarmProperties) expected_duration = 30; expected_sound = "/tmp/bar.wav"; expected_haptic = "none"; + expected_snooze_duration = 5; g_object_set(proxy, SOUND_PROP, expected_sound, HAPTIC_PROP, expected_haptic, VOLUME_PROP, expected_volume, DURATION_PROP, expected_duration, + SNOOZE_PROP, expected_snooze_duration, nullptr); wait_msec(); @@ -234,6 +242,7 @@ TEST_F(ExporterFixture, AlarmProperties) EXPECT_STREQ(expected_haptic, settings->alarm_haptic.get().c_str()); EXPECT_EQ(expected_volume, settings->alarm_volume.get()); EXPECT_EQ(expected_duration, settings->alarm_duration.get()); + EXPECT_EQ(expected_snooze_duration, settings->snooze_duration.get()); // cleanup g_clear_object(&proxy); diff --git a/tests/test-settings.cpp b/tests/test-settings.cpp index 4fb0a08..5dfb5ae 100644 --- a/tests/test-settings.cpp +++ b/tests/test-settings.cpp @@ -152,6 +152,7 @@ TEST_F(SettingsFixture, UIntProperties) { TestUIntProperty(m_settings->alarm_duration, SETTINGS_ALARM_DURATION_S); TestUIntProperty(m_settings->alarm_volume, SETTINGS_ALARM_VOLUME_S); + TestUIntProperty(m_settings->snooze_duration, SETTINGS_SNOOZE_DURATION_S); } TEST_F(SettingsFixture, StringProperties) -- cgit v1.2.3 From 63493709a92c76169ad065cc3804b13dbd786537 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 11:15:58 -0500 Subject: add planner.cpp to the build --- include/datetime/planner.h | 5 ++--- src/CMakeLists.txt | 1 + src/planner.cpp | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/datetime/planner.h b/include/datetime/planner.h index 43991ec..55e72e7 100644 --- a/include/datetime/planner.h +++ b/include/datetime/planner.h @@ -37,12 +37,11 @@ namespace datetime { class Planner { public: - virtual ~Planner() =default; - + virtual ~Planner(); virtual core::Property>& appointments() =0; protected: - Planner() =default; + Planner(); static void sort(std::vector&); static void trim(std::vector&, const DateTime& begin, const DateTime& end); }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2852a75..512cc5c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,7 @@ set (SERVICE_CXX_SOURCES locations-settings.cpp menu.cpp notifications.cpp + planner.cpp planner-aggregate.cpp planner-snooze.cpp planner-month.cpp diff --git a/src/planner.cpp b/src/planner.cpp index 3f73030..15dab52 100644 --- a/src/planner.cpp +++ b/src/planner.cpp @@ -19,6 +19,8 @@ #include +#include + namespace unity { namespace indicator { namespace datetime { @@ -35,6 +37,7 @@ Planner::~Planner() { } +#if 0 void Planner::set_range_to_calendar_month(const DateTime& dt) { @@ -59,6 +62,7 @@ Planner::set_range_to_upcoming_month(const DateTime& begin) end.format(fmt).c_str()); range().set(std::make_pair(begin,end)); } +#endif void Planner::sort(std::vector& appts) @@ -73,9 +77,9 @@ Planner::trim(std::vector& appts, const DateTime& begin, const DateTime& end) { - decltype(appts) tmp; - auto predicate = [begin,end](const Appointment& a){return begin<=a.begin && a.begin<=end;} - std::copy(std::begin(appts), std::end(appts), std::back_inserter(tmp), predicate); + std::vector tmp; + auto predicate = [begin,end](const Appointment& a){return begin<=a.begin && a.begin<=end;}; + std::copy_if(std::begin(appts), std::end(appts), std::back_inserter(tmp), predicate); appts.swap(tmp); } -- cgit v1.2.3 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 From 84a8bb0debeb68d92049ccb8731d4d07aee7e2f9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 23:17:38 -0500 Subject: add manual test for snooze --- tests/manual | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/manual b/tests/manual index c932004..64d59c3 100644 --- a/tests/manual +++ b/tests/manual @@ -33,6 +33,16 @@ Test-case indicator-datetime/new-alarm-wakeup
If the device supports haptic feedback, confirm the alarm vibrates.
+Test-case indicator-datetime/snooze +
+
Create and save an upcoming alarm in ubuntu-clock-app
+
When the alarm goes off, press the 'Snooze' button
+
The alarm should go away, then reappear N minutes later. + By default the N is 5 minutes but will be configurable from ubuntu-clock-app.
+
When the snoozed alarm reappears, press the 'OK' button
+
This time when the alarm is dismissed, it should not reappear.
+
+ Test-case indicator-datetime/edited-alarm-wakeup
Edit an alarm that's already passed. (see previous test)
-- cgit v1.2.3 From b0b9b94246fad179165cca2f4d5026409349fde0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 23:19:58 -0500 Subject: reverse OK/snooze button order --- src/snap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snap.cpp b/src/snap.cpp index 2a0fb5b..505980c 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -98,8 +98,8 @@ public: g_free (title); b.set_timeout (std::chrono::duration_cast(minutes)); if (interactive) { - b.add_action ("snooze", _("Snooze")); b.add_action ("ok", _("OK")); + b.add_action ("snooze", _("Snooze")); } // add 'sound', 'haptic', and 'awake' objects to the capture so -- cgit v1.2.3 From 7b42ea114c18dab35129a5c98b196ff173892498 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 23:22:04 -0500 Subject: update manual-test-snap's diagnostic text to reflect snooze/ok buttons --- tests/manual-test-snap.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp index 7d4403d..369e6cd 100644 --- a/tests/manual-test-snap.cpp +++ b/tests/manual-test-snap.cpp @@ -78,12 +78,12 @@ int main(int argc, const char* argv[]) g_date_time_unref(begin); auto loop = g_main_loop_new(nullptr, false); - auto show = [loop](const Appointment& appt){ - g_message("You clicked 'show' for appt url '%s'", appt.url.c_str()); + auto on_snooze = [loop](const Appointment& appt){ + g_message("You clicked 'Snooze' for appt url '%s'", appt.url.c_str()); g_idle_add(quit_idle, loop); }; - auto dismiss = [loop](const Appointment&){ - g_message("You clicked 'dismiss'"); + auto on_ok = [loop](const Appointment&){ + g_message("You clicked 'OK'"); g_idle_add(quit_idle, loop); }; @@ -97,7 +97,7 @@ int main(int argc, const char* argv[]) auto notification_engine = std::make_shared("indicator-datetime-service"); Snap snap (notification_engine, settings); - snap(a, show, dismiss); + snap(a, on_snooze, on_ok); g_main_loop_run(loop); g_main_loop_unref(loop); -- cgit v1.2.3 From a209741aaf8d0ece778e1e2b9e5a8d1632339ad2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 23:37:02 -0500 Subject: use the 'override' keyword in the new planner class declarations --- include/datetime/planner-aggregate.h | 2 +- include/datetime/planner-snooze.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/datetime/planner-aggregate.h b/include/datetime/planner-aggregate.h index eeca9b7..892e71a 100644 --- a/include/datetime/planner-aggregate.h +++ b/include/datetime/planner-aggregate.h @@ -38,7 +38,7 @@ public: virtual ~AggregatePlanner(); void add(const std::shared_ptr&); - core::Property>& appointments(); + core::Property>& appointments() override; protected: class Impl; diff --git a/include/datetime/planner-snooze.h b/include/datetime/planner-snooze.h index 889c4f8..e2619fa 100644 --- a/include/datetime/planner-snooze.h +++ b/include/datetime/planner-snooze.h @@ -41,7 +41,7 @@ public: ~SnoozePlanner(); void add(const Appointment&); - core::Property>& appointments(); + core::Property>& appointments() override; protected: class Impl; -- cgit v1.2.3 From db764f321a1450da886c672b3ccd82d1e5dfedd6 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 23:37:35 -0500 Subject: remove the new code that we're not using yet --- include/datetime/planner.h | 1 - src/planner.cpp | 38 -------------------------------------- 2 files changed, 39 deletions(-) diff --git a/include/datetime/planner.h b/include/datetime/planner.h index 55e72e7..22b6381 100644 --- a/include/datetime/planner.h +++ b/include/datetime/planner.h @@ -43,7 +43,6 @@ public: protected: Planner(); static void sort(std::vector&); - static void trim(std::vector&, const DateTime& begin, const DateTime& end); }; } // namespace datetime diff --git a/src/planner.cpp b/src/planner.cpp index 15dab52..6ca9ca7 100644 --- a/src/planner.cpp +++ b/src/planner.cpp @@ -37,33 +37,6 @@ Planner::~Planner() { } -#if 0 -void -Planner::set_range_to_calendar_month(const DateTime& dt) -{ - // use appointments that occur in dt's calendar month - impl->set_range_to_upcoming_month(dt.add_full(0, // no years - 0, // no months - -(dt.day_of_month()-1), - -dt.hour(), - -dt.minute(), - -dt.seconds()); -} - -void -Planner::set_range_to_upcoming_month(const DateTime& begin) -{ - // use appointments that occur in [dt...dt+1month] - const auto end = begin.add_full(0, 1, 0, 0, 0, -0.1); - const char * fmt = "%F %T"; - g_debug("RangePlanner %p setting range [%s..%s]", - this, - begin.format(fmt).c_str(), - end.format(fmt).c_str()); - range().set(std::make_pair(begin,end)); -} -#endif - void Planner::sort(std::vector& appts) { @@ -72,17 +45,6 @@ Planner::sort(std::vector& appts) [](const Appointment& a, const Appointment& b){return a.begin < b.begin;}); } -void -Planner::trim(std::vector& appts, - const DateTime& begin, - const DateTime& end) -{ - std::vector tmp; - auto predicate = [begin,end](const Appointment& a){return begin<=a.begin && a.begin<=end;}; - std::copy_if(std::begin(appts), std::end(appts), std::back_inserter(tmp), predicate); - appts.swap(tmp); -} - /*** **** ***/ -- cgit v1.2.3 From 593c16de05fe3806edeeb3bc105ce63b71b8b545 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 2 Sep 2014 23:44:00 -0500 Subject: minor copyediting: rename a variable for better clarity --- src/planner-snooze.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/planner-snooze.cpp b/src/planner-snooze.cpp index 6d427ca..51ad0d2 100644 --- a/src/planner-snooze.cpp +++ b/src/planner-snooze.cpp @@ -55,10 +55,10 @@ public: { Appointment appt = appt_in; - // adjust the time - const auto appt_length_secs = appt.end - appt.begin; + // reschedule the alarm to go off N minutes from now + const auto alarm_duration_secs = appt.end - appt.begin; appt.begin = m_clock->localtime().add_full(0,0,0,0,m_settings->snooze_duration.get(),0); - appt.end = appt.begin.add_full(0,0,0,0,0,appt_length_secs); + appt.end = appt.begin.add_full(0,0,0,0,0,alarm_duration_secs); // give it a new ID gchar* uid = e_uid_new(); -- cgit v1.2.3