aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-02-03 00:32:03 -0600
committerCharles Kerr <charles.kerr@canonical.com>2014-02-03 00:32:03 -0600
commit35850dcd7c95e08b86052d5ac72ca23d00b5180f (patch)
treebf69548baa35fbf814cb23567aef04a80cce4976
parentc4e010f1cd307a5919cace98f82941a57bc91573 (diff)
downloadayatana-indicator-datetime-35850dcd7c95e08b86052d5ac72ca23d00b5180f.tar.gz
ayatana-indicator-datetime-35850dcd7c95e08b86052d5ac72ca23d00b5180f.tar.bz2
ayatana-indicator-datetime-35850dcd7c95e08b86052d5ac72ca23d00b5180f.zip
from alarm dev branch: snap decision handler
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/main.cpp9
-rw-r--r--src/snap.cpp112
3 files changed, 122 insertions, 0 deletions
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 <datetime/actions-live.h>
#include <datetime/clock.h>
+#include <datetime/clock-watcher.h>
#include <datetime/exporter.h>
#include <datetime/locations-settings.h>
#include <datetime/menu.h>
#include <datetime/planner-eds.h>
#include <datetime/settings-live.h>
+#include <datetime/snap.h>
#include <datetime/state.h>
#include <datetime/timezones-live.h>
@@ -67,6 +69,13 @@ main(int /*argc*/, char** /*argv*/)
std::shared_ptr<Actions> 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<std::shared_ptr<Menu>> menus;
for(int i=0, n=Menu::NUM_PROFILES; i<n; i++)
diff --git a/src/snap.cpp b/src/snap.cpp
new file mode 100644
index 0000000..bac8958
--- /dev/null
+++ b/src/snap.cpp
@@ -0,0 +1,112 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#include <datetime/appointment.h>
+#include <datetime/formatter.h>
+#include <datetime/snap.h>
+
+#include <url-dispatcher.h>
+
+#include <libnotify/notify.h>
+
+#include <glib/gi18n.h>
+#include <glib.h>
+
+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<const gchar*>(gurl);
+ g_debug("dispatching url '%s'", url);
+ url_dispatch_send(url, nullptr, nullptr);
+ }
+}
+
+} // unnamed namespace
+
+/***
+****
+***/
+
+Snap::Snap(const std::shared_ptr<Clock>& 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