aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac2
-rw-r--r--debian/control1
-rw-r--r--src/main.c6
-rw-r--r--src/service.c78
4 files changed, 73 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac
index 8b95695..5b9dda6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,6 +51,7 @@ GEOCLUE_REQUIRED_VERSION=0.12.0
ICAL_REQUIRED_VERSION=0.48
ECAL_REQUIRED_VERSION=3.5
EDS_REQUIRED_VERSION=3.5
+LIBNOTIFY_REQUIRED_VERSION=0.7.6
URL_DISPATCHER_1_REQUIRED_VERSION=1
GTK3_REQUIRED_VERSION=3.1.4
@@ -61,6 +62,7 @@ PKG_CHECK_MODULES(SERVICE, [glib-2.0 >= $GLIB_REQUIRED_VERSION
libical >= $ICAL_REQUIRED_VERSION
libecal-1.2 >= $ECAL_REQUIRED_VERSION
libedataserver-1.2 >= EDS_REQUIRED_VERSION
+ libnotify >= $LIBNOTIFY_REQUIRED_VERSION
url-dispatcher-1 >= URL_DISPATCHER_1_REQUIRED_VERSION])
###########################
diff --git a/debian/control b/debian/control
index 67938bf..0815e1b 100644
--- a/debian/control
+++ b/debian/control
@@ -10,6 +10,7 @@ Build-Depends: debhelper (>= 9),
libxorg-gtest-dev,
libgtest-dev,
libglib2.0-dev (>= 2.35.4),
+ libnotify-dev (>= 0.7.6),
libido3-0.1-dev (>= 0.2.90),
libgeoclue-dev (>= 0.12.0),
libecal1.2-dev (>= 3.5),
diff --git a/src/main.c b/src/main.c
index 073c876..34e9b98 100644
--- a/src/main.c
+++ b/src/main.c
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
+#include <libnotify/notify.h>
#include "planner-eds.h"
#include "planner-mock.h"
@@ -52,6 +53,11 @@ main (int argc G_GNUC_UNUSED, char ** argv G_GNUC_UNUSED)
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
textdomain (GETTEXT_PACKAGE);
+ /* init libnotify */
+ if (!notify_init ("indicator-datetime-service"))
+ g_critical ("libnotify initialization failed");
+
+
/* get the planner */
if (g_getenv ("INDICATOR_DATETIME_USE_FAKE_PLANNER") != NULL)
{
diff --git a/src/service.c b/src/service.c
index 57d0a7e..c76b07e 100644
--- a/src/service.c
+++ b/src/service.c
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
+#include <libnotify/notify.h>
#include <url-dispatcher.h>
#include "dbus-shared.h"
@@ -431,31 +432,80 @@ dispatch_alarm_url (const struct IndicatorDatetimeAppt * appt)
url_dispatch_send (appt->url, NULL, NULL);
}
-/* Check for alarms that start at the current time.
- If we find any, we dispatch the URL associated with them. */
+#if 0
static void
-dispatch_alarm_urls (IndicatorDatetimeService * self)
+on_notification_closed (NotifyNotification * nn, gpointer gself)
{
- GDateTime * now = indicator_datetime_service_get_localtime (self);
- GSList * l;
+ //IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (gself);
- for (l=self->priv->upcoming_appointments; l!=NULL; l=l->next)
- {
- const struct IndicatorDatetimeAppt * appt = l->data;
+ g_message ("hello world");
- if (appointment_has_alarm_url (appt) && datetimes_have_the_same_minute (now, appt->begin))
- dispatch_alarm_url (appt);
- }
+ /* cleanup */
+ g_signal_handlers_disconnect_by_data (nn, gself);
+ g_object_unref (nn);
+}
+#endif
- g_date_time_unref (now);
+static void
+on_alarm_popup_ok_clicked (NotifyNotification * nn G_GNUC_UNUSED, char * action G_GNUC_UNUSED, gpointer gurl)
+{
+ const char * url = gurl;
+ url_dispatch_send (url, NULL, NULL);
}
+#define ALARM_ICON_NAME "alarm-symbolic"
+
static void update_appointment_lists (IndicatorDatetimeService * self);
static gboolean
-on_alarm_timer (gpointer self)
+on_alarm_timer (gpointer gself)
{
- dispatch_alarm_urls (self);
+ GDateTime * now;
+ GSList * l;
+ IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (gself);
+
+ /* Check for alarms that start at the current time.
+ * If we find one, trigger a snap decision displaying
+ * the appointment text and a single button to dismiss */
+ now = indicator_datetime_service_get_localtime (self);
+ for (l=self->priv->upcoming_appointments; l!=NULL; l=l->next)
+ {
+ gchar * title;
+ const gchar * body;
+ const struct IndicatorDatetimeAppt * appt = l->data;
+ NotifyNotification * nn;
+ GError * error;
+
+ if (!appointment_has_alarm_url (appt))
+ continue;
+
+ if (!datetimes_have_the_same_minute (now, appt->begin))
+ continue;
+
+ title = g_date_time_format (now, get_terse_time_format_string (now));
+ body = appt->summary;
+ nn = notify_notification_new (title, body, ALARM_ICON_NAME);
+
+ notify_notification_set_hint (nn, "x-canonical-snap-decisions",
+ g_variant_new_boolean(TRUE));
+ notify_notification_set_hint (nn, "x-canonical-private-button-tint",
+ g_variant_new_boolean(TRUE));
+ notify_notification_add_action (nn, "ok", _("OK"),
+ on_alarm_popup_ok_clicked,
+ g_strdup (appt->url), g_free);
+ //g_signal_connect (nn, "closed", G_CALLBACK(on_notification_closed), self);
+
+ error = NULL;
+ notify_notification_show (nn, &error);
+ if (error != NULL)
+ {
+ g_warning ("Unable to show alarm '%s' popup: %s", body, error->message);
+ g_error_free (error);
+ dispatch_alarm_url (appt);
+ }
+ g_free (title);
+ }
+ g_date_time_unref (now);
/* rebuild the alarm list asynchronously.
when it's done, set_upcoming_appointments() will update the alarm timer */