aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/datetime/snap.h4
-rw-r--r--src/main.cpp32
-rw-r--r--src/snap.cpp24
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<void(const Appointment&)> 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 <datetime/exporter.h>
#include <datetime/locations-settings.h>
#include <datetime/menu.h>
+#include <datetime/planner-aggregate.h>
+#include <datetime/planner-snooze.h>
#include <datetime/planner-range.h>
#include <datetime/settings-live.h>
#include <datetime/snap.h>
@@ -37,8 +39,6 @@
#include <glib/gi18n.h> // bindtextdomain()
#include <gio/gio.h>
-#include <url-dispatcher.h>
-
#include <locale.h>
#include <cstdlib> // exit()
@@ -90,6 +90,7 @@ namespace
}
std::shared_ptr<AlarmQueue> create_simple_alarm_queue(const std::shared_ptr<Clock>& clock,
+ const std::shared_ptr<Planner>& snooze_planner,
const std::shared_ptr<Engine>& engine,
const std::shared_ptr<Timezone>& 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<AggregatePlanner> planner = std::make_shared<AggregatePlanner>();
+ planner->add(upcoming_planner);
+ planner->add(snooze_planner);
+
auto wakeup_timer = std::make_shared<PowerdWakeupTimer>(clock);
- return std::make_shared<SimpleAlarmQueue>(clock, upcoming_planner, wakeup_timer);
+ return std::make_shared<SimpleAlarmQueue>(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<SnoozePlanner>(state->settings, state->clock);
auto notification_engine = std::make_shared<uin::Engine>("indicator-datetime-service");
std::unique_ptr<Snap> 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<std::shared_ptr<Menu>> 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<std::chrono::seconds>(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);
}
/***