From 414c9ee4a5d04c7d8b1aa893ba68936c3107430b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 8 Oct 2013 20:53:10 -0500 Subject: add a timer to periodically check to see if EDS alarms have been reached. --- src/service.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index e8d4764..1123c51 100644 --- a/src/service.c +++ b/src/service.c @@ -107,6 +107,7 @@ struct _IndicatorDatetimeServicePrivate guint header_timer; guint timezone_timer; + guint alarm_timer; /* Which year/month to show in the calendar, and which day should get the cursor. @@ -376,6 +377,96 @@ start_header_timer (IndicatorDatetimeService * self) g_date_time_unref (now); } +/*** +**** +***/ + +static void start_alarm_timer (IndicatorDatetimeService * self); + +static gboolean +datetimes_have_the_same_minute (GDateTime * a, GDateTime * b) +{ + int ay, am, ad; + int by, bm, bd; + + g_date_time_get_ymd (a, &ay, &am, &ad); + g_date_time_get_ymd (b, &by, &bm, &bd); + + return (ay == by) && + (am == bm) && + (ad == ad) && + (g_date_time_get_hour (a) == g_date_time_get_hour (b)) && + (g_date_time_get_minute (a) == g_date_time_get_minute (b)); +} + +/* This is called on the minute, every minute. + We check for alarms that start at the current time. + If we find any, we dispatch the URL associated with them. */ +static void +dispatch_alarm_urls (IndicatorDatetimeService * self) +{ + GDateTime * now = indicator_datetime_service_get_localtime (self); + GSList * l; + + for (l=self->priv->upcoming_appointments; l!=NULL; l=l->next) + { + const struct IndicatorDatetimeAppt * appt = l->data; + + if ((appt->has_alarms) && + (appt->url != NULL) && + (g_str_has_prefix (appt->url, "alarm:///")) && + (datetimes_have_the_same_minute (now, appt->begin))) + { + gchar * str = g_date_time_format (appt->begin, "%F %H:%M"); + g_debug ("at %s, dispatching url \"%s\" for appointment \"%s\"", str, appt->url, appt->summary); + url_dispatch_send (appt->url, NULL, NULL); + g_free (str); + } + } + + g_date_time_unref (now); +} + +static gboolean +on_alarm_timer (gpointer self) +{ + dispatch_alarm_urls (self); + + /* Restarting the timer to recalculate the interval. This helps us to hit + our marks despite clock skew, suspend+resume, leap seconds, etc */ + start_alarm_timer (self); + return G_SOURCE_REMOVE; +} + +static void +start_alarm_timer (IndicatorDatetimeService * self) +{ + priv_t * p; + GDateTime * now; + guint interval_msec; + + p = self->priv; + + indicator_clear_timer (&p->alarm_timer); + + now = indicator_datetime_service_get_localtime (self); + interval_msec = calculate_milliseconds_until_next_minute (now); + interval_msec += 50; /* add a small margin to ensure the callback + fires /after/ next is reached */ + + p->alarm_timer = g_timeout_add_full (G_PRIORITY_HIGH, + interval_msec, + on_alarm_timer, + self, + NULL); + + g_date_time_unref (now); +} + +/*** +**** +***/ + /** * General purpose handler for rebuilding sections and restarting their timers * when time jumps for whatever reason: @@ -1782,6 +1873,7 @@ my_dispose (GObject * o) indicator_clear_timer (&p->rebuild_id); indicator_clear_timer (&p->timezone_timer); indicator_clear_timer (&p->header_timer); + indicator_clear_timer (&p->alarm_timer); if (p->settings != NULL) { @@ -1948,6 +2040,8 @@ indicator_datetime_service_init (IndicatorDatetimeService * self) on_local_time_jumped (self); + start_alarm_timer (self); + for (i=0; i Date: Wed, 9 Oct 2013 08:22:09 -0500 Subject: instead of testing for alarms once per minute, set a timer for the next alarm occurence. --- src/service.c | 119 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 89 insertions(+), 30 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 1123c51..07f6a51 100644 --- a/src/service.c +++ b/src/service.c @@ -381,7 +381,15 @@ start_header_timer (IndicatorDatetimeService * self) **** ***/ -static void start_alarm_timer (IndicatorDatetimeService * self); +static void set_alarm_timer (IndicatorDatetimeService * self); + +static gboolean +appointment_has_alarm_url (const struct IndicatorDatetimeAppt * appt) +{ + return (appt->has_alarms) && + (appt->url != NULL);// && + //(g_str_has_prefix (appt->url, "alarm:///")); +} static gboolean datetimes_have_the_same_minute (GDateTime * a, GDateTime * b) @@ -394,13 +402,12 @@ datetimes_have_the_same_minute (GDateTime * a, GDateTime * b) return (ay == by) && (am == bm) && - (ad == ad) && + (ad == bd) && (g_date_time_get_hour (a) == g_date_time_get_hour (b)) && (g_date_time_get_minute (a) == g_date_time_get_minute (b)); } -/* This is called on the minute, every minute. - We check for alarms that start at the current time. +/* Check for alarms that start at the current time. If we find any, we dispatch the URL associated with them. */ static void dispatch_alarm_urls (IndicatorDatetimeService * self) @@ -412,13 +419,12 @@ dispatch_alarm_urls (IndicatorDatetimeService * self) { const struct IndicatorDatetimeAppt * appt = l->data; - if ((appt->has_alarms) && - (appt->url != NULL) && - (g_str_has_prefix (appt->url, "alarm:///")) && - (datetimes_have_the_same_minute (now, appt->begin))) + if (appointment_has_alarm_url (appt) && + datetimes_have_the_same_minute (now, appt->begin)) { - gchar * str = g_date_time_format (appt->begin, "%F %H:%M"); - g_debug ("at %s, dispatching url \"%s\" for appointment \"%s\"", str, appt->url, appt->summary); + gchar * str = g_date_time_format (appt->begin, "%F %T"); + g_debug ("at %s, dispatching url \"%s\" for appointment \"%s\"", + str, appt->url, appt->summary); url_dispatch_send (appt->url, NULL, NULL); g_free (str); } @@ -427,38 +433,73 @@ dispatch_alarm_urls (IndicatorDatetimeService * self) g_date_time_unref (now); } +static void update_appointment_lists (IndicatorDatetimeService * self); + static gboolean on_alarm_timer (gpointer self) { dispatch_alarm_urls (self); - - /* Restarting the timer to recalculate the interval. This helps us to hit - our marks despite clock skew, suspend+resume, leap seconds, etc */ - start_alarm_timer (self); + + /* rebuild the alarm list asynchronously. + when it's done, set_upcoming_appointments() will update the alarm timer */ + update_appointment_lists (self); + return G_SOURCE_REMOVE; } +/* if there are upcoming alarms, set the alarm timer to the nearest one. + otherwise, unset the alarm timer. */ static void -start_alarm_timer (IndicatorDatetimeService * self) +set_alarm_timer (IndicatorDatetimeService * self) { priv_t * p; GDateTime * now; - guint interval_msec; - - p = self->priv; + GDateTime * alarm_time; + GSList * l; + p = self->priv; indicator_clear_timer (&p->alarm_timer); now = indicator_datetime_service_get_localtime (self); - interval_msec = calculate_milliseconds_until_next_minute (now); - interval_msec += 50; /* add a small margin to ensure the callback - fires /after/ next is reached */ - p->alarm_timer = g_timeout_add_full (G_PRIORITY_HIGH, - interval_msec, - on_alarm_timer, - self, - NULL); + /* find the time of the next alarm on our calendar */ + alarm_time = NULL; + for (l=p->upcoming_appointments; l!=NULL; l=l->next) + { + const struct IndicatorDatetimeAppt * appt = l->data; + + if (appointment_has_alarm_url (appt)) + if (g_date_time_compare (appt->begin, now) > 0) + if (!alarm_time || g_date_time_compare (alarm_time, appt->begin) > 0) + alarm_time = appt->begin; + } + + /* if there's an upcoming alarm, set a timer to wake up at that time */ + if (alarm_time != NULL) + { + GTimeSpan interval_msec; + gchar * str; + GDateTime * then; + + interval_msec = g_date_time_difference (alarm_time, now); + interval_msec += G_USEC_PER_SEC; /* fire a moment after alarm_time */ + interval_msec /= 1000; /* convert from usec to msec */ + + str = g_date_time_format (alarm_time, "%F %T"); + g_debug ("%s is the next alarm time", str); + g_free (str); + then = g_date_time_add_seconds (now, interval_msec/1000); + str = g_date_time_format (then, "%F %T"); + g_debug ("%s is when we'll wake up for it", str); + g_free (str); + g_date_time_unref (then); + + p->alarm_timer = g_timeout_add_full (G_PRIORITY_HIGH, + (guint) interval_msec, + on_alarm_timer, + self, + NULL); + } g_date_time_unref (now); } @@ -810,20 +851,33 @@ static void add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean terse) { const int MAX_APPTS = 5; - GDateTime * now = indicator_datetime_service_get_localtime (self); + GDateTime * now; + GHashTable * added; GSList * appts; GSList * l; int i; + now = indicator_datetime_service_get_localtime (self); + + added = g_hash_table_new (g_str_hash, g_str_equal); + /* build appointment menuitems */ appts = self->priv->upcoming_appointments; for (l=appts, i=0; l!=NULL && inext, i++) { struct IndicatorDatetimeAppt * appt = l->data; - char * fmt = get_appointment_time_format (appt, now, self->priv->settings, terse); - const gint64 unix_time = g_date_time_to_unix (appt->begin); + char * fmt; + gint64 unix_time; GMenuItem * menu_item; + if (g_hash_table_contains (added, appt->uid)) + continue; + + g_hash_table_add (added, appt->uid); + + fmt = get_appointment_time_format (appt, now, self->priv->settings, terse); + unix_time = g_date_time_to_unix (appt->begin); + menu_item = g_menu_item_new (appt->summary, NULL); if (appt->color && !appt->has_alarms) @@ -846,6 +900,7 @@ add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean terse) } /* cleanup */ + g_hash_table_unref (added); g_date_time_unref (now); } @@ -1661,6 +1716,10 @@ set_upcoming_appointments (IndicatorDatetimeService * self, /* sync the menus/actions */ rebuild_appointments_section_soon (self); + + /* alarm timer is keyed off of the next alarm time, + so it needs to be rebuilt when tehe appointment list changes */ + set_alarm_timer (self); } static void @@ -2040,7 +2099,7 @@ indicator_datetime_service_init (IndicatorDatetimeService * self) on_local_time_jumped (self); - start_alarm_timer (self); + set_alarm_timer (self); for (i=0; i Date: Wed, 9 Oct 2013 13:28:15 +0000 Subject: remove debugging stubs --- src/service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 07f6a51..28ef32d 100644 --- a/src/service.c +++ b/src/service.c @@ -387,8 +387,8 @@ static gboolean appointment_has_alarm_url (const struct IndicatorDatetimeAppt * appt) { return (appt->has_alarms) && - (appt->url != NULL);// && - //(g_str_has_prefix (appt->url, "alarm:///")); + (appt->url != NULL) && + (g_str_has_prefix (appt->url, "alarm:///")); } static gboolean -- cgit v1.2.3 From 1282befc5d9629ba0daacc2099811ccf19e4ed1b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 11:39:36 -0500 Subject: add url activation for appointment menuitems on the phone profile. --- src/service.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 15 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 28ef32d..1de4617 100644 --- a/src/service.c +++ b/src/service.c @@ -378,7 +378,7 @@ start_header_timer (IndicatorDatetimeService * self) } /*** -**** +**** ALARMS ***/ static void set_alarm_timer (IndicatorDatetimeService * self); @@ -407,6 +407,22 @@ datetimes_have_the_same_minute (GDateTime * a, GDateTime * b) (g_date_time_get_minute (a) == g_date_time_get_minute (b)); } +static void +dispatch_alarm_url (const struct IndicatorDatetimeAppt * appt) +{ + gchar * str; + + g_return_if_fail (appt != NULL); + g_return_if_fail (appointment_has_alarm_url (appt)); + + str = g_date_time_format (appt->begin, "%F %T"); + g_debug ("dispatching url \"%s\" for appointment \"%s\", which begins at %s", + appt->url, appt->summary, str); + g_free (str); + + 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. */ static void @@ -419,15 +435,8 @@ dispatch_alarm_urls (IndicatorDatetimeService * self) { const struct IndicatorDatetimeAppt * appt = l->data; - if (appointment_has_alarm_url (appt) && - datetimes_have_the_same_minute (now, appt->begin)) - { - gchar * str = g_date_time_format (appt->begin, "%F %T"); - g_debug ("at %s, dispatching url \"%s\" for appointment \"%s\"", - str, appt->url, appt->summary); - url_dispatch_send (appt->url, NULL, NULL); - g_free (str); - } + if (appointment_has_alarm_url (appt) && datetimes_have_the_same_minute (now, appt->begin)) + dispatch_alarm_url (appt); } g_date_time_unref (now); @@ -848,7 +857,7 @@ get_appointment_time_format (struct IndicatorDatetimeAppt * appt, } static void -add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean terse) +add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean phone) { const int MAX_APPTS = 5; GDateTime * now; @@ -875,7 +884,7 @@ add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean terse) g_hash_table_add (added, appt->uid); - fmt = get_appointment_time_format (appt, now, self->priv->settings, terse); + fmt = get_appointment_time_format (appt, now, self->priv->settings, phone); unix_time = g_date_time_to_unix (appt->begin); menu_item = g_menu_item_new (appt->summary, NULL); @@ -891,9 +900,15 @@ add_appointments (IndicatorDatetimeService * self, GMenu * menu, gboolean terse) g_menu_item_set_attribute (menu_item, "x-canonical-type", "s", appt->has_alarms ? "com.canonical.indicator.alarm" : "com.canonical.indicator.appointment"); - g_menu_item_set_action_and_target_value (menu_item, - "indicator.activate-planner", - g_variant_new_int64 (unix_time)); + + if (phone) + g_menu_item_set_action_and_target_value (menu_item, + "indicator.activate-appointment", + g_variant_new_string (appt->uid)); + else + g_menu_item_set_action_and_target_value (menu_item, + "indicator.activate-planner", + g_variant_new_int64 (unix_time)); g_menu_append_item (menu, menu_item); g_object_unref (menu_item); g_free (fmt); @@ -1432,6 +1447,34 @@ on_phone_settings_activated (GSimpleAction * a G_GNUC_UNUSED, url_dispatch_send ("settings:///system/time-date", NULL, NULL); } +static void +on_activate_appointment (GSimpleAction * a G_GNUC_UNUSED, + GVariant * param, + gpointer gself) +{ + priv_t * p = INDICATOR_DATETIME_SERVICE(gself)->priv; + const gchar * uid = g_variant_get_string (param, NULL); + + if (uid != NULL) + { + const struct IndicatorDatetimeAppt * appt; + GSList * l; + + /* find the appointment that matches that uid */ + for (l=p->upcoming_appointments, appt=NULL; l && !appt; l=l->next) + { + const struct IndicatorDatetimeAppt * tmp = l->data; + if (!g_strcmp0 (uid, tmp->uid)) + appt = tmp; + } + + /* if that appointment's an alarm, dispatch its url */ + g_debug ("%s: uri '%s'; matching appt is %p", G_STRFUNC, uid, appt); + if (appt && appointment_has_alarm_url (appt)) + dispatch_alarm_url (appt); + } +} + static void on_activate_planner (GSimpleAction * a G_GNUC_UNUSED, GVariant * param, @@ -1486,6 +1529,7 @@ init_gactions (IndicatorDatetimeService * self) { "activate-desktop-settings", on_desktop_settings_activated }, { "activate-phone-settings", on_phone_settings_activated }, { "activate-planner", on_activate_planner, "x", NULL }, + { "activate-appointment", on_activate_appointment, "s", NULL }, { "set-location", on_set_location, "s" } }; -- cgit v1.2.3 From 70487ccce4dbcf04f9dfb02ba50f7e88e428f14a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 21:02:17 -0500 Subject: move planner instantiation to main.c so that we can prepare to pass in a mock planner for testing --- src/service.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 103 insertions(+), 20 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 1de4617..57d0a7e 100644 --- a/src/service.c +++ b/src/service.c @@ -27,7 +27,6 @@ #include #include "dbus-shared.h" -#include "planner-eds.h" #include "timezone-file.h" #include "timezone-geoclue.h" #include "service.h" @@ -49,6 +48,15 @@ enum static guint signals[LAST_SIGNAL] = { 0 }; +enum +{ + PROP_0, + PROP_PLANNER, + PROP_LAST +}; + +static GParamSpec * properties[PROP_LAST] = { 0 }; + enum { SECTION_HEADER = (1<<0), @@ -1935,6 +1943,45 @@ on_name_lost (GDBusConnection * connection G_GNUC_UNUSED, **** GObject virtual functions ***/ +static void +my_get_property (GObject * o, + guint property_id, + GValue * value, + GParamSpec * pspec) +{ + IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (o); + + switch (property_id) + { + case PROP_PLANNER: + g_value_set_object (value, self->priv->planner); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + } +} + +static void +my_set_property (GObject * o, + guint property_id, + const GValue * value, + GParamSpec * pspec) +{ + IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (o); + + switch (property_id) + { + case PROP_PLANNER: + indicator_datetime_service_set_planner (self, g_value_get_object (value)); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (o, property_id, pspec); + } +} + + static void my_dispose (GObject * o) { @@ -1958,13 +2005,7 @@ my_dispose (GObject * o) set_detect_location_enabled (self, FALSE); - if (p->planner != NULL) - { - g_signal_handlers_disconnect_by_data (p->planner, self); - g_clear_object (&p->planner); - } - g_clear_pointer (&p->upcoming_appointments, indicator_datetime_planner_free_appointments); - g_clear_pointer (&p->calendar_appointments, indicator_datetime_planner_free_appointments); + indicator_datetime_service_set_planner (self, NULL); if (p->login1_manager != NULL) { @@ -2064,16 +2105,6 @@ indicator_datetime_service_init (IndicatorDatetimeService * self) p->cancellable = g_cancellable_new (); - /*** - **** Create the planner and listen for changes - ***/ - - p->planner = indicator_datetime_planner_eds_new (); - - g_signal_connect_swapped (p->planner, "appointments-changed", - G_CALLBACK(update_appointment_lists), self); - - /*** **** Create the settings object and listen for changes ***/ @@ -2155,9 +2186,12 @@ static void indicator_datetime_service_class_init (IndicatorDatetimeServiceClass * klass) { GObjectClass * object_class = G_OBJECT_CLASS (klass); + const GParamFlags flags = G_PARAM_CONSTRUCT | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS; object_class->dispose = my_dispose; object_class->finalize = my_finalize; + object_class->get_property = my_get_property; + object_class->set_property = my_set_property; g_type_class_add_private (klass, sizeof (IndicatorDatetimeServicePrivate)); @@ -2169,6 +2203,18 @@ indicator_datetime_service_class_init (IndicatorDatetimeServiceClass * klass) NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + /* install properties */ + + properties[PROP_0] = NULL; + + properties[PROP_PLANNER] = g_param_spec_object ("planner", + "Planner", + "The appointment provider", + INDICATOR_TYPE_DATETIME_PLANNER, + flags); + + g_object_class_install_properties (object_class, PROP_LAST, properties); } /*** @@ -2176,9 +2222,11 @@ indicator_datetime_service_class_init (IndicatorDatetimeServiceClass * klass) ***/ IndicatorDatetimeService * -indicator_datetime_service_new (void) +indicator_datetime_service_new (IndicatorDatetimePlanner * planner) { - GObject * o = g_object_new (INDICATOR_TYPE_DATETIME_SERVICE, NULL); + GObject * o = g_object_new (INDICATOR_TYPE_DATETIME_SERVICE, + "planner", planner, + NULL); return INDICATOR_DATETIME_SERVICE (o); } @@ -2209,3 +2257,38 @@ indicator_datetime_service_set_calendar_date (IndicatorDatetimeService * self, if (dirty) update_appointment_lists (self); } + +void +indicator_datetime_service_set_planner (IndicatorDatetimeService * self, + IndicatorDatetimePlanner * planner) +{ + priv_t * p; + + g_return_if_fail (INDICATOR_IS_DATETIME_SERVICE (self)); + g_return_if_fail (INDICATOR_IS_DATETIME_PLANNER (planner)); + + p = self->priv; + + /* clear the old planner & appointments */ + + if (p->planner != NULL) + { + g_signal_handlers_disconnect_by_data (p->planner, self); + g_clear_object (&p->planner); + } + + g_clear_pointer (&p->upcoming_appointments, indicator_datetime_planner_free_appointments); + g_clear_pointer (&p->calendar_appointments, indicator_datetime_planner_free_appointments); + + /* set the new planner & begin fetching appointments from it */ + + if (planner != NULL) + { + p->planner = g_object_ref (planner); + + g_signal_connect_swapped (p->planner, "appointments-changed", + G_CALLBACK(update_appointment_lists), self); + + update_appointment_lists (self); + } +} -- cgit v1.2.3 From a52e3b86ee0dbce56221d1327c6c62a6d8e163e3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 21:33:15 -0500 Subject: preliminary implementation of snap decision --- src/service.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 14 deletions(-) (limited to 'src/service.c') 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 #include +#include #include #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 */ -- cgit v1.2.3 From dae4fdd39e5381083345e87759dbaffddabe14e4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 22:55:26 -0500 Subject: more wiring in of mock objects --- src/service.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index c76b07e..61d50aa 100644 --- a/src/service.c +++ b/src/service.c @@ -472,6 +472,7 @@ on_alarm_timer (gpointer gself) { gchar * title; const gchar * body; + const gchar * icon_name; const struct IndicatorDatetimeAppt * appt = l->data; NotifyNotification * nn; GError * error; @@ -484,8 +485,10 @@ on_alarm_timer (gpointer gself) title = g_date_time_format (now, get_terse_time_format_string (now)); body = appt->summary; - nn = notify_notification_new (title, body, ALARM_ICON_NAME); - + icon_name = ALARM_ICON_NAME; + g_debug ("creating a snap decision with title '%s', body '%s', icon '%s'", + title, body, icon_name); + nn = notify_notification_new (title, body, 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", -- cgit v1.2.3 From da87e44c2fedfea688a77137b7e10e227538e63a Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 9 Oct 2013 23:26:26 -0500 Subject: extract-method: show_snap_decision_for_alarm --- src/service.c | 73 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 61d50aa..37f5756 100644 --- a/src/service.c +++ b/src/service.c @@ -453,7 +453,40 @@ on_alarm_popup_ok_clicked (NotifyNotification * nn G_GNUC_UNUSED, char * action url_dispatch_send (url, NULL, NULL); } -#define ALARM_ICON_NAME "alarm-symbolic" +static void +show_snap_decision_for_alarm (const struct IndicatorDatetimeAppt * appt) +{ + gchar * title; + const gchar * body; + const gchar * icon_name; + NotifyNotification * nn; + GError * error; + + title = g_date_time_format (appt->begin, + get_terse_time_format_string (appt->begin)); + body = appt->summary; + icon_name = "alarm-symbolic"; + g_debug ("creating a snap decision with title '%s', body '%s', icon '%s'", + title, body, icon_name); + nn = notify_notification_new (title, body, 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); + 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); +} static void update_appointment_lists (IndicatorDatetimeService * self); @@ -470,43 +503,11 @@ on_alarm_timer (gpointer gself) now = indicator_datetime_service_get_localtime (self); for (l=self->priv->upcoming_appointments; l!=NULL; l=l->next) { - gchar * title; - const gchar * body; - const gchar * icon_name; 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; - icon_name = ALARM_ICON_NAME; - g_debug ("creating a snap decision with title '%s', body '%s', icon '%s'", - title, body, icon_name); - nn = notify_notification_new (title, body, 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); + if (appointment_has_alarm_url (appt)) + if (datetimes_have_the_same_minute (now, appt->begin)) + show_snap_decision_for_alarm (appt); } g_date_time_unref (now); -- cgit v1.2.3 From 8441fc4f840d668e2b7fe1582f90eef66e272652 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 14 Oct 2013 23:54:40 -0500 Subject: tweak snap decision comments --- src/service.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 37f5756..270f214 100644 --- a/src/service.c +++ b/src/service.c @@ -493,13 +493,11 @@ static void update_appointment_lists (IndicatorDatetimeService * self); static gboolean on_alarm_timer (gpointer gself) { + IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (gself); 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 */ + /* If there are any alarms at the current time, show a snap decision */ now = indicator_datetime_service_get_localtime (self); for (l=self->priv->upcoming_appointments; l!=NULL; l=l->next) { @@ -512,7 +510,8 @@ on_alarm_timer (gpointer gself) g_date_time_unref (now); /* rebuild the alarm list asynchronously. - when it's done, set_upcoming_appointments() will update the alarm timer */ + set_upcoming_appointments() will update the alarm timer when this + async call is done, so no need to restart the timer here... */ update_appointment_lists (self); return G_SOURCE_REMOVE; -- cgit v1.2.3 From 8dadf00b78312867f33a2f6dcd39118a1beb150c Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 16 Oct 2013 14:52:54 -0500 Subject: for testing purposes, fire off a snap decision as soon as the datetime indicator is started. this way one can test on phablet by running as user phablet --- src/service.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 270f214..fd3d937 100644 --- a/src/service.c +++ b/src/service.c @@ -432,24 +432,13 @@ dispatch_alarm_url (const struct IndicatorDatetimeAppt * appt) url_dispatch_send (appt->url, NULL, NULL); } -#if 0 static void -on_notification_closed (NotifyNotification * nn, gpointer gself) -{ - //IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (gself); - - g_message ("hello world"); - - /* cleanup */ - g_signal_handlers_disconnect_by_data (nn, gself); - g_object_unref (nn); -} -#endif - -static void -on_alarm_popup_ok_clicked (NotifyNotification * nn G_GNUC_UNUSED, char * action G_GNUC_UNUSED, gpointer gurl) +action_ok (NotifyNotification *notification G_GNUC_UNUSED, + char *action, + gpointer gurl) { const char * url = gurl; + g_debug ("'%s' clicked for snap decision %s", action, url); url_dispatch_send (url, NULL, NULL); } @@ -465,17 +454,18 @@ show_snap_decision_for_alarm (const struct IndicatorDatetimeAppt * appt) title = g_date_time_format (appt->begin, get_terse_time_format_string (appt->begin)); body = appt->summary; - icon_name = "alarm-symbolic"; + icon_name = "alarm-clock"; g_debug ("creating a snap decision with title '%s', body '%s', icon '%s'", title, body, icon_name); + nn = notify_notification_new (title, body, 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); + notify_notification_add_action (nn, "action_accept", _("OK"), + action_ok, g_strdup(appt->url), g_free); + error = NULL; notify_notification_show (nn, &error); if (error != NULL) @@ -1981,14 +1971,11 @@ on_name_lost (GDBusConnection * connection G_GNUC_UNUSED, { IndicatorDatetimeService * self = INDICATOR_DATETIME_SERVICE (gself); - if (connection == NULL) - g_error ("Unable to get bus connection to own name '%s'", name); - g_debug ("%s %s name lost %s", G_STRLOC, G_STRFUNC, name); unexport (self); - g_signal_emit (self, signals[SIGNAL_NAME_LOST], 0, NULL); + //g_signal_emit (self, signals[SIGNAL_NAME_LOST], 0, NULL); } -- cgit v1.2.3 From 42b338cdced3f34d719ffda6108818df2e85a84b Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 16 Oct 2013 16:48:28 -0500 Subject: use a two-button snap decision because one-button snap decisions don't show up. --- src/service.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index fd3d937..09ee4d4 100644 --- a/src/service.c +++ b/src/service.c @@ -401,8 +401,10 @@ appointment_has_alarm_url (const struct IndicatorDatetimeAppt * appt) } static gboolean -datetimes_have_the_same_minute (GDateTime * a, GDateTime * b) +datetimes_have_the_same_minute (GDateTime * a G_GNUC_UNUSED, GDateTime * b G_GNUC_UNUSED) { +return TRUE; +#if 0 int ay, am, ad; int by, bm, bd; @@ -414,6 +416,7 @@ datetimes_have_the_same_minute (GDateTime * a, GDateTime * b) (ad == bd) && (g_date_time_get_hour (a) == g_date_time_get_hour (b)) && (g_date_time_get_minute (a) == g_date_time_get_minute (b)); +#endif } static void @@ -433,13 +436,18 @@ dispatch_alarm_url (const struct IndicatorDatetimeAppt * appt) } static void -action_ok (NotifyNotification *notification G_GNUC_UNUSED, - char *action, - gpointer gurl) +on_snap_decided (NotifyNotification * notification G_GNUC_UNUSED, + char * action, + gpointer gurl) { - const char * url = gurl; - g_debug ("'%s' clicked for snap decision %s", action, url); - url_dispatch_send (url, NULL, NULL); + g_debug ("%s: %s", G_STRFUNC, action); + + if (!g_strcmp0 (action, "ok")) + { + const gchar * url = gurl; + g_debug ("dispatching url '%s'", url); + url_dispatch_send (url, NULL, NULL); + } } static void @@ -461,10 +469,10 @@ show_snap_decision_for_alarm (const struct IndicatorDatetimeAppt * appt) nn = notify_notification_new (title, body, 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, "action_accept", _("OK"), - action_ok, g_strdup(appt->url), g_free); + notify_notification_add_action (nn, "ok", _("OK"), + on_snap_decided, g_strdup(appt->url), g_free); + notify_notification_add_action (nn, "cancel", _("Cancel"), + on_snap_decided, NULL, NULL); error = NULL; notify_notification_show (nn, &error); @@ -493,6 +501,8 @@ on_alarm_timer (gpointer gself) { const struct IndicatorDatetimeAppt * appt = l->data; +g_message ("[%s][%s]", g_date_time_format (appt->begin, "%F %T"), appt->url); + if (appointment_has_alarm_url (appt)) if (datetimes_have_the_same_minute (now, appt->begin)) show_snap_decision_for_alarm (appt); @@ -1975,7 +1985,7 @@ on_name_lost (GDBusConnection * connection G_GNUC_UNUSED, unexport (self); - //g_signal_emit (self, signals[SIGNAL_NAME_LOST], 0, NULL); + g_signal_emit (self, signals[SIGNAL_NAME_LOST], 0, NULL); } -- cgit v1.2.3 From 831b21bca8afb458cc33e878d8246a00f68e6dbd Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 16 Oct 2013 21:40:13 -0500 Subject: change ok/cancel buttons to the slightly-more-informative show/dismiss --- src/service.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index e83410e..9c30310 100644 --- a/src/service.c +++ b/src/service.c @@ -451,7 +451,7 @@ on_snap_decided (NotifyNotification * notification G_GNUC_UNUSED, { g_debug ("%s: %s", G_STRFUNC, action); - if (!g_strcmp0 (action, "ok")) + if (!g_strcmp0 (action, "show")) { const gchar * url = gurl; g_debug ("dispatching url '%s'", url); @@ -478,9 +478,9 @@ show_snap_decision_for_alarm (const struct IndicatorDatetimeAppt * appt) nn = notify_notification_new (title, body, icon_name); notify_notification_set_hint (nn, "x-canonical-snap-decisions", g_variant_new_boolean(TRUE)); - notify_notification_add_action (nn, "ok", _("OK"), + notify_notification_add_action (nn, "show", _("Show"), on_snap_decided, g_strdup(appt->url), g_free); - notify_notification_add_action (nn, "cancel", _("Cancel"), + notify_notification_add_action (nn, "dismiss", _("Dismiss"), on_snap_decided, NULL, NULL); error = NULL; -- cgit v1.2.3 From 05c1039f4b9f0014371bb767089755317ea2d322 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 16 Oct 2013 21:41:28 -0500 Subject: in the alarm snap decision, add x-canonical-private-button-tint hint to highlight the 'Show' button --- src/service.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/service.c') diff --git a/src/service.c b/src/service.c index 9c30310..e42b689 100644 --- a/src/service.c +++ b/src/service.c @@ -476,8 +476,12 @@ show_snap_decision_for_alarm (const struct IndicatorDatetimeAppt * appt) title, body, icon_name); nn = notify_notification_new (title, body, icon_name); - notify_notification_set_hint (nn, "x-canonical-snap-decisions", - g_variant_new_boolean(TRUE)); + 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(appt->url), g_free); notify_notification_add_action (nn, "dismiss", _("Dismiss"), -- cgit v1.2.3