aboutsummaryrefslogtreecommitdiff
path: root/src/snap.cpp
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 /src/snap.cpp
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
Diffstat (limited to 'src/snap.cpp')
-rw-r--r--src/snap.cpp112
1 files changed, 112 insertions, 0 deletions
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