~charlesk/indicator-datetime/lp-1233176

« back to all changes in this revision

Viewing changes to src/service.c

  • Committer: Charles Kerr
  • Date: 2013-10-10 02:33:15 UTC
  • Revision ID: charles.kerr@canonical.com-20131010023315-ghm3eckbwcbg2fal
preliminary implementation of snap decision

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include <glib/gi18n.h>
26
26
#include <gio/gio.h>
 
27
#include <libnotify/notify.h>
27
28
#include <url-dispatcher.h>
28
29
 
29
30
#include "dbus-shared.h"
431
432
  url_dispatch_send (appt->url, NULL, NULL);
432
433
}
433
434
 
434
 
/* Check for alarms that start at the current time.
435
 
   If we find any, we dispatch the URL associated with them. */
436
 
static void
437
 
dispatch_alarm_urls (IndicatorDatetimeService * self)
438
 
{
439
 
  GDateTime * now = indicator_datetime_service_get_localtime (self);
 
435
#if 0
 
436
static void
 
437
on_notification_closed (NotifyNotification * nn, gpointer gself)
 
438
{
 
439
  //IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (gself);
 
440
 
 
441
  g_message ("hello world");
 
442
 
 
443
  /* cleanup */
 
444
  g_signal_handlers_disconnect_by_data (nn, gself);
 
445
  g_object_unref (nn);
 
446
}
 
447
#endif
 
448
 
 
449
static void
 
450
on_alarm_popup_ok_clicked (NotifyNotification * nn G_GNUC_UNUSED, char * action G_GNUC_UNUSED, gpointer gurl)
 
451
{
 
452
  const char * url = gurl;
 
453
  url_dispatch_send (url, NULL, NULL);
 
454
}
 
455
 
 
456
#define ALARM_ICON_NAME "alarm-symbolic"
 
457
 
 
458
static void update_appointment_lists (IndicatorDatetimeService * self);
 
459
 
 
460
static gboolean
 
461
on_alarm_timer (gpointer gself)
 
462
{
 
463
  GDateTime * now;
440
464
  GSList * l;
 
465
  IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (gself);
441
466
 
 
467
  /* Check for alarms that start at the current time.
 
468
   * If we find one, trigger a snap decision displaying
 
469
   * the appointment text and a single button to dismiss */
 
470
  now = indicator_datetime_service_get_localtime (self);
442
471
  for (l=self->priv->upcoming_appointments; l!=NULL; l=l->next)
443
472
    {
 
473
      gchar * title;
 
474
      const gchar * body;
444
475
      const struct IndicatorDatetimeAppt * appt = l->data;
445
 
 
446
 
      if (appointment_has_alarm_url (appt) && datetimes_have_the_same_minute (now, appt->begin))
447
 
        dispatch_alarm_url (appt);
 
476
      NotifyNotification * nn;
 
477
      GError * error;
 
478
 
 
479
      if (!appointment_has_alarm_url (appt))
 
480
        continue;
 
481
 
 
482
      if (!datetimes_have_the_same_minute (now, appt->begin))
 
483
        continue;
 
484
 
 
485
      title = g_date_time_format (now, get_terse_time_format_string (now));
 
486
      body = appt->summary;
 
487
      nn = notify_notification_new (title, body, ALARM_ICON_NAME);
 
488
 
 
489
      notify_notification_set_hint (nn, "x-canonical-snap-decisions",
 
490
                                    g_variant_new_boolean(TRUE));
 
491
      notify_notification_set_hint (nn, "x-canonical-private-button-tint",
 
492
                                    g_variant_new_boolean(TRUE));
 
493
      notify_notification_add_action (nn, "ok", _("OK"),
 
494
                                      on_alarm_popup_ok_clicked,
 
495
                                      g_strdup (appt->url), g_free);
 
496
      //g_signal_connect (nn, "closed", G_CALLBACK(on_notification_closed), self);
 
497
 
 
498
      error = NULL;
 
499
      notify_notification_show (nn, &error);
 
500
      if (error != NULL)
 
501
        {
 
502
          g_warning ("Unable to show alarm '%s' popup: %s", body, error->message);
 
503
          g_error_free (error);
 
504
          dispatch_alarm_url (appt);
 
505
        }
 
506
      g_free (title);
448
507
    }
449
 
 
450
508
  g_date_time_unref (now);
451
 
}
452
 
 
453
 
static void update_appointment_lists (IndicatorDatetimeService * self);
454
 
 
455
 
static gboolean
456
 
on_alarm_timer (gpointer self)
457
 
{
458
 
  dispatch_alarm_urls (self);
459
509
 
460
510
  /* rebuild the alarm list asynchronously.
461
511
     when it's done, set_upcoming_appointments() will update the alarm timer */