From 35850dcd7c95e08b86052d5ac72ca23d00b5180f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 3 Feb 2014 00:32:03 -0600 Subject: from alarm dev branch: snap decision handler --- src/CMakeLists.txt | 1 + src/main.cpp | 9 +++++ src/snap.cpp | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 src/snap.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12a5b74..fdf3e5e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -28,6 +28,7 @@ add_library (${SERVICE_LIB} STATIC menu.cpp planner-eds.cpp settings-live.cpp + snap.cpp timezone-file.cpp timezone-geoclue.cpp timezones-live.cpp diff --git a/src/main.cpp b/src/main.cpp index 1534777..3c17923 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,11 +21,13 @@ #include #include +#include #include #include #include #include #include +#include #include #include @@ -67,6 +69,13 @@ main(int /*argc*/, char** /*argv*/) std::shared_ptr actions(new LiveActions(state)); MenuFactory factory(actions, state); + // snap decisions + ClockWatcherImpl clock_watcher(state); + Snap snap(state->clock); + clock_watcher.alarm_reached().connect([&snap](const Appointment& appt){ + snap(appt); + }); + // create the menus std::vector> menus; for(int i=0, n=Menu::NUM_PROFILES; i. + * + * Authors: + * Charles Kerr + */ + +#include +#include +#include + +#include + +#include + +#include +#include + +namespace unity { +namespace indicator { +namespace datetime { + +/*** +**** +***/ + +namespace +{ + +void dispatch_alarm_url(const Appointment& appointment) +{ + g_return_if_fail(!appointment.has_alarms); + + const auto fmt = appointment.begin.format("%F %T"); + g_debug("dispatching url \"%s\" for appointment \"%s\", which begins at %s", + appointment.url.c_str(), + appointment.summary.c_str(), + fmt.c_str()); + + url_dispatch_send(appointment.url.c_str(), nullptr, nullptr); +} + +void on_snap_decided(NotifyNotification * /*notification*/, + char * action, + gpointer gurl) +{ + g_debug("%s: %s", G_STRFUNC, action); + + if (!g_strcmp0(action, "show")) + { + const auto url = static_cast(gurl); + g_debug("dispatching url '%s'", url); + url_dispatch_send(url, nullptr, nullptr); + } +} + +} // unnamed namespace + +/*** +**** +***/ + +Snap::Snap(const std::shared_ptr& clock): + m_formatter(clock) +{ +} + +void Snap::operator()(const Appointment& appointment) +{ + const auto timestr = m_formatter.header.get(); + const auto body = appointment.summary; + gchar* title = g_strdup_printf(_("Alarm %s"), timestr.c_str()); + const gchar* icon_name = "clock"; + g_debug("creating a snap decision with title '%s', body '%s', icon '%s'", title, body.c_str(), icon_name); + + auto nn = notify_notification_new(title, body.c_str(), icon_name); + notify_notification_set_hint_string(nn, "x-canonical-snap-decisions", "true"); + notify_notification_set_hint_string(nn, "x-canonical-private-button-tint", "true"); + notify_notification_add_action(nn, "show", _("Show"), on_snap_decided, g_strdup(appointment.url.c_str()), g_free); + notify_notification_add_action(nn, "dismiss", _("Dismiss"), on_snap_decided, nullptr, nullptr); + + GError * error = nullptr; + notify_notification_show(nn, &error); + if (error != NULL) + { + g_warning("Unable to show alarm '%s' popup: %s", body.c_str(), error->message); + g_error_free(error); + dispatch_alarm_url(appointment); + } + + g_free(title); +} + +/*** +**** +***/ + +} // namespace datetime +} // namespace indicator +} // namespace unity -- cgit v1.2.3