[evolution/kill-bonobo] Bug #579646 - Remember alarm's last notified per calendar



commit fe2f720c14d3f39ca6694f1b56b7f4e8121e732b
Author: Milan Crha <mcrha redhat com>
Date:   Mon Jul 27 17:06:20 2009 +0200

    Bug #579646 - Remember alarm's last notified per calendar

 calendar/gui/alarm-notify/alarm-queue.c |   24 ++++++-------------
 calendar/gui/alarm-notify/config-data.c |   37 +++++++++++++++++++++++++++++-
 calendar/gui/alarm-notify/config-data.h |    5 ++-
 3 files changed, 46 insertions(+), 20 deletions(-)
---
diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c
index e7fbdc7..b500d8c 100644
--- a/calendar/gui/alarm-notify/alarm-queue.c
+++ b/calendar/gui/alarm-notify/alarm-queue.c
@@ -61,12 +61,6 @@ static AlarmNotificationsDialog *alarm_notifications_dialog = NULL;
 /* Whether the queueing system has been initialized */
 static gboolean alarm_queue_inited = FALSE;
 
-/* When the alarm queue system is inited, this gets set to the last time an
- * alarm notification was issued.  This lets us present any notifications that
- * should have happened while the alarm daemon was not running.
- */
-static time_t saved_notification_time;
-
 /* Clients we are monitoring for alarms */
 static GHashTable *client_alarms_hash = NULL;
 
@@ -395,9 +389,8 @@ alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data)
 	cqa = data;
 	comp = cqa->alarms->comp;
 
-	config_data_set_last_notification_time (trigger);
+	config_data_set_last_notification_time (cqa->parent_client->client, trigger);
 	d(printf("%s:%d (alarm_trigger_cb) - Setting Last notification time to %s\n",__FILE__, __LINE__, ctime (&trigger)));
-	saved_notification_time = trigger;
 
 	qa = lookup_queued_alarm (cqa, alarm_id);
 	if (!qa)
@@ -577,11 +570,11 @@ load_alarms_for_today (ClientAlarms *ca)
 	day_start = time_day_begin_with_zone (now, zone);
 
 	/* Make sure we don't miss some events from the last notification.
-	 * We add 1 to the saved_notification_time to make the time ranges
+	 * We add 1 to the saved notification time to make the time ranges
 	 * half-open; we do not want to display the "last" displayed alarm
 	 * twice, once when it occurs and once when the alarm daemon restarts.
 	 */
-	from = MAX (config_data_get_last_notification_time () + 1, day_start);
+	from = MAX (config_data_get_last_notification_time (ca->client) + 1, day_start);
 
 	day_end = time_day_end_with_zone (now, zone);
 	d(printf("%s:%d (load_alarms_for_today) - From %s to %s\n",__FILE__, __LINE__, ctime (&from), ctime(&day_end)));
@@ -713,7 +706,7 @@ query_objects_changed_async (struct _query_msg *msg)
 	ca = msg->data;
 	objects = msg->objects;
 
-	from = config_data_get_last_notification_time ();
+	from = config_data_get_last_notification_time (client);
 	if (from == -1)
 		from = time (NULL);
 	else
@@ -1847,11 +1840,10 @@ alarm_queue_init (gpointer data)
 	client_alarms_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
 	queue_midnight_refresh ();
 
-	saved_notification_time = config_data_get_last_notification_time ();
-	if (saved_notification_time == -1) {
-		saved_notification_time = time (NULL);
-		d(printf("%s:%d (alarm_queue_init) - Setting last notification time to %s\n",__FILE__, __LINE__, ctime(&saved_notification_time)));
-		config_data_set_last_notification_time (saved_notification_time);
+	if (config_data_get_last_notification_time (NULL) == -1) {
+		time_t tmval = time (NULL);
+		d(printf("%s:%d (alarm_queue_init) - Setting last notification time to %s\n",__FILE__, __LINE__, ctime(&tmval)));
+		config_data_set_last_notification_time (NULL, tmval);
 	}
 
 	/* install timeout handler (every 30 mins) for not missing the midnight refresh */
diff --git a/calendar/gui/alarm-notify/config-data.c b/calendar/gui/alarm-notify/config-data.c
index 8f3b0ae..c66819f 100644
--- a/calendar/gui/alarm-notify/config-data.c
+++ b/calendar/gui/alarm-notify/config-data.c
@@ -256,13 +256,30 @@ config_data_get_notify_with_tray (void)
  * triggered while it was not running.
  **/
 void
-config_data_set_last_notification_time (time_t t)
+config_data_set_last_notification_time (ECal *cal, time_t t)
 {
 	GConfClient *client;
 	time_t current_t, now = time (NULL);
 
 	g_return_if_fail (t != -1);
 
+	if (cal) {
+		ESource *source = e_cal_get_source (cal);
+		if (source) {
+			GTimeVal tmval = {0};
+			char *as_text;
+
+			tmval.tv_sec = (glong) t;
+			as_text = g_time_val_to_iso8601 (&tmval);
+
+			if (as_text) {
+				e_source_set_property (source, "last-notified", as_text);
+				g_free (as_text);
+				return;
+			}
+		}
+	}
+
 	if (!(client = config_data_get_conf_client ()))
 		return;
 
@@ -281,11 +298,27 @@ config_data_set_last_notification_time (time_t t)
  * Return value: The last saved value, or -1 if no value had been saved before.
  **/
 time_t
-config_data_get_last_notification_time (void)
+config_data_get_last_notification_time (ECal *cal)
 {
 	GConfValue *value;
 	GConfClient *client;
 
+	if (cal) {
+		ESource *source = e_cal_get_source (cal);
+		if (source) {
+			const gchar *last_notified = e_source_get_property (source, "last-notified");
+			GTimeVal tmval = {0};
+
+			if (last_notified && *last_notified && g_time_val_from_iso8601 (last_notified, &tmval)) {
+				time_t now = time (NULL), val = (time_t) tmval.tv_sec;
+
+				if (val > now)
+					val = now;
+				return val;
+			}
+		}
+	}
+
 	if (!(client = config_data_get_conf_client ()))
 		return -1;
 
diff --git a/calendar/gui/alarm-notify/config-data.h b/calendar/gui/alarm-notify/config-data.h
index 19086be..08f3915 100644
--- a/calendar/gui/alarm-notify/config-data.h
+++ b/calendar/gui/alarm-notify/config-data.h
@@ -28,6 +28,7 @@
 
 #include <glib.h>
 #include <libical/ical.h>
+#include <libecal/e-cal.h>
 #include <gconf/gconf-client.h>
 #include <libedataserver/e-source-list.h>
 
@@ -36,8 +37,8 @@ GConfClient  *config_data_get_conf_client (void);
 icaltimezone *config_data_get_timezone (void);
 gboolean      config_data_get_24_hour_format (void);
 gboolean      config_data_get_notify_with_tray (void);
-void          config_data_set_last_notification_time (time_t t);
-time_t        config_data_get_last_notification_time (void);
+void          config_data_set_last_notification_time (ECal *cal, time_t t);
+time_t        config_data_get_last_notification_time (ECal *cal);
 void          config_data_save_blessed_program (const gchar *program);
 gboolean      config_data_is_blessed_program (const gchar *program);
 ESourceList  *config_data_get_calendars (const gchar *);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]