aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@ximian.com>2001-10-10 08:40:30 +0800
committerFederico Mena Quintero <federico@src.gnome.org>2001-10-10 08:40:30 +0800
commit423268bfa266e80902f28a84da8de637afd841a1 (patch)
treebaff5e5f54e32e19ae933849e243be85077f4c11 /calendar
parent45a3bf8c4557eea71a77afd8a6efcc01416ecdef (diff)
downloadgsoc2013-evolution-423268bfa266e80902f28a84da8de637afd841a1.tar
gsoc2013-evolution-423268bfa266e80902f28a84da8de637afd841a1.tar.gz
gsoc2013-evolution-423268bfa266e80902f28a84da8de637afd841a1.tar.bz2
gsoc2013-evolution-423268bfa266e80902f28a84da8de637afd841a1.tar.lz
gsoc2013-evolution-423268bfa266e80902f28a84da8de637afd841a1.tar.xz
gsoc2013-evolution-423268bfa266e80902f28a84da8de637afd841a1.tar.zst
gsoc2013-evolution-423268bfa266e80902f28a84da8de637afd841a1.zip
Fixes bug #884.
2001-10-09 Federico Mena Quintero <federico@ximian.com> Fixes bug #884. * gui/alarm-notify/save.[ch]: New files with functions to save/load the last notification time. * gui/alarm-notify/alarm-queue.c (alarm_trigger_cb): Save the last notification time. (alarm_queue_init): Load the last notification time when the daemon is inited. (alarm_queue_add_client): Load the alarms that we missed while the alarm daemon was not running. (cal_opened_cb): Likewise. * gui/alarm-notify/Makefile.am (evolution_alarm_notify_SOURCES): Added save.[ch] to the list of sources. svn path=/trunk/; revision=13538
Diffstat (limited to 'calendar')
-rw-r--r--calendar/ChangeLog18
-rw-r--r--calendar/gui/alarm-notify/Makefile.am6
-rw-r--r--calendar/gui/alarm-notify/alarm-queue.c65
-rw-r--r--calendar/gui/alarm-notify/alarm-queue.h3
-rw-r--r--calendar/gui/alarm-notify/save.c129
-rw-r--r--calendar/gui/alarm-notify/save.h31
6 files changed, 235 insertions, 17 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index e0f8951ede..9220f6aae7 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,21 @@
+2001-10-09 Federico Mena Quintero <federico@ximian.com>
+
+ Fixes bug #884.
+
+ * gui/alarm-notify/save.[ch]: New files with functions to
+ save/load the last notification time.
+
+ * gui/alarm-notify/alarm-queue.c (alarm_trigger_cb): Save the last
+ notification time.
+ (alarm_queue_init): Load the last notification time when the
+ daemon is inited.
+ (alarm_queue_add_client): Load the alarms that we missed while the
+ alarm daemon was not running.
+ (cal_opened_cb): Likewise.
+
+ * gui/alarm-notify/Makefile.am (evolution_alarm_notify_SOURCES):
+ Added save.[ch] to the list of sources.
+
2001-10-09 JP Rosevear <jpr@ximian.com>
* gui/itip-utils.c (get_address): util function to get address
diff --git a/calendar/gui/alarm-notify/Makefile.am b/calendar/gui/alarm-notify/Makefile.am
index eef2e6abcc..4c323c3b55 100644
--- a/calendar/gui/alarm-notify/Makefile.am
+++ b/calendar/gui/alarm-notify/Makefile.am
@@ -29,6 +29,7 @@ INCLUDES = \
-I$(top_srcdir)/widgets \
-I$(includedir) \
$(BONOBO_VFS_GNOME_CFLAGS) \
+ $(BONOBO_CONF_CFLAGS) \
$(EXTRA_GNOME_CFLAGS) \
-DEVOLUTION_DATADIR=\""$(datadir)"\" \
-DEVOLUTION_GLADEDIR=\""$(gladedir)"\" \
@@ -47,7 +48,9 @@ evolution_alarm_notify_SOURCES = \
alarm-notify-dialog.h \
alarm-queue.c \
alarm-queue.h \
- notify-main.c
+ notify-main.c \
+ save.c \
+ save.h
evolution_alarm_notify_LDADD = \
libalarm.a \
@@ -55,6 +58,7 @@ evolution_alarm_notify_LDADD = \
$(top_builddir)/calendar/cal-util/libcal-util.la \
$(top_builddir)/libical/src/libical/libical.la \
$(top_builddir)/libwombat/libwombat.la \
+ $(BONOBO_CONF_LIBS) \
$(BONOBO_VFS_GNOME_LIBS) \
$(EXTRA_GNOME_LIBS) \
$(INTLLIBS)
diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c
index c73f1a760b..342a07e420 100644
--- a/calendar/gui/alarm-notify/alarm-queue.c
+++ b/calendar/gui/alarm-notify/alarm-queue.c
@@ -1,7 +1,6 @@
/* Evolution calendar - Alarm queueing engine
*
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
+ * Copyright (C) 2001 Ximian, Inc.
*
* Authors: Federico Mena-Quintero <federico@ximian.com>
*
@@ -39,12 +38,19 @@
#include "alarm.h"
#include "alarm-notify-dialog.h"
#include "alarm-queue.h"
+#include "save.h"
/* Whether the queueing system has been initialized */
static gboolean alarm_queue_inited;
+/* 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;
@@ -104,7 +110,7 @@ static void procedure_notification (time_t trigger, CompQueuedAlarms *cqa, gpoin
/* Alarm queue engine */
-static void load_alarms (ClientAlarms *ca);
+static void load_alarms_for_today (ClientAlarms *ca);
static void midnight_refresh_cb (gpointer alarm_id, time_t trigger, gpointer data);
/* Queues an alarm trigger for midnight so that we can load the next day's worth
@@ -133,7 +139,7 @@ add_client_alarms_cb (gpointer key, gpointer value, gpointer data)
ClientAlarms *ca;
ca = value;
- load_alarms (ca);
+ load_alarms_for_today (ca);
}
/* Loads the alarms for the new day every midnight */
@@ -231,6 +237,8 @@ alarm_trigger_cb (gpointer alarm_id, time_t trigger, gpointer data)
cqa = data;
comp = cqa->alarms->comp;
+ save_notification_time (trigger);
+
qa = lookup_queued_alarm (cqa, alarm_id);
/* Decide what to do based on the alarm action. We use the trigger that
@@ -330,18 +338,14 @@ add_component_alarms (ClientAlarms *ca, CalComponentAlarms *alarms)
g_hash_table_insert (ca->uid_alarms_hash, (char *) uid, cqa);
}
-/* Loads today's remaining alarms for a client */
+/* Loads the alarms of a client for a given range of time */
static void
-load_alarms (ClientAlarms *ca)
+load_alarms (ClientAlarms *ca, time_t start, time_t end)
{
- time_t now, day_end;
GSList *comp_alarms;
GSList *l;
- now = time (NULL);
- day_end = time_day_end (now);
-
- comp_alarms = cal_client_get_alarms_in_range (ca->client, now, day_end);
+ comp_alarms = cal_client_get_alarms_in_range (ca->client, start, end);
/* All of the last day's alarms should have already triggered and should
* have been removed, so we should have no pending components.
@@ -358,6 +362,30 @@ load_alarms (ClientAlarms *ca)
g_slist_free (comp_alarms);
}
+/* Loads today's remaining alarms for a client */
+static void
+load_alarms_for_today (ClientAlarms *ca)
+{
+ time_t now, day_end;
+
+ now = time (NULL);
+ day_end = time_day_end (now);
+}
+
+/* Adds any alarms that should have occurred while the alarm daemon was not
+ * running.
+ */
+static void
+load_missed_alarms (ClientAlarms *ca)
+{
+ time_t now;
+
+ now = time (NULL);
+
+ g_assert (saved_notification_time != -1);
+ load_alarms (ca, saved_notification_time, now);
+}
+
/* Called when a calendar client finished loading; we load its alarms */
static void
cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data)
@@ -369,7 +397,8 @@ cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data)
if (status != CAL_CLIENT_OPEN_SUCCESS)
return;
- load_alarms (ca);
+ load_alarms_for_today (ca);
+ load_missed_alarms (ca);
}
/* Looks up a component's queued alarm structure in a client alarms structure */
@@ -783,6 +812,12 @@ alarm_queue_init (void)
client_alarms_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
queue_midnight_refresh ();
+ saved_notification_time = get_saved_notification_time ();
+ if (saved_notification_time == -1) {
+ saved_notification_time = time (NULL);
+ save_notification_time (saved_notification_time);
+ }
+
alarm_queue_inited = TRUE;
}
@@ -859,8 +894,10 @@ alarm_queue_add_client (CalClient *client)
gtk_signal_connect (GTK_OBJECT (client), "obj_removed",
GTK_SIGNAL_FUNC (obj_removed_cb), ca);
- if (cal_client_get_load_state (client) == CAL_CLIENT_LOAD_LOADED)
- load_alarms (ca);
+ if (cal_client_get_load_state (client) == CAL_CLIENT_LOAD_LOADED) {
+ load_alarms_for_today (ca);
+ load_missed_alarms (ca);
+ }
}
/* Called from g_hash_table_foreach(); adds a component UID to a list */
diff --git a/calendar/gui/alarm-notify/alarm-queue.h b/calendar/gui/alarm-notify/alarm-queue.h
index cd2e9444b1..3588e68708 100644
--- a/calendar/gui/alarm-notify/alarm-queue.h
+++ b/calendar/gui/alarm-notify/alarm-queue.h
@@ -1,7 +1,6 @@
/* Evolution calendar - Alarm queueing engine
*
- * Copyright (C) 2000 Ximian, Inc.
- * Copyright (C) 2000 Ximian, Inc.
+ * Copyright (C) 2001 Ximian, Inc.
*
* Authors: Federico Mena-Quintero <federico@ximian.com>
*
diff --git a/calendar/gui/alarm-notify/save.c b/calendar/gui/alarm-notify/save.c
new file mode 100644
index 0000000000..3fb8dde818
--- /dev/null
+++ b/calendar/gui/alarm-notify/save.c
@@ -0,0 +1,129 @@
+/* Evolution calendar - Functions to save alarm notification times
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Authors: Federico Mena-Quintero <federico@ximian.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <bonobo/bonobo-exception.h>
+#include <bonobo/bonobo-moniker-util.h>
+#include <bonobo-conf/bonobo-config-database.h>
+#include "save.h"
+
+
+
+/* Tries to get the config database object; returns CORBA_OBJECT_NIL on failure. */
+static Bonobo_ConfigDatabase
+get_config_db (void)
+{
+ CORBA_Environment ev;
+ Bonobo_ConfigDatabase db;
+
+ CORBA_exception_init (&ev);
+
+ db = bonobo_get_object ("wombat:", "Bonobo/ConfigDatabase", &ev);
+ if (BONOBO_EX (&ev) || db == CORBA_OBJECT_NIL) {
+ g_message ("get_config_db(): Could not get the config database object");
+ db = CORBA_OBJECT_NIL;
+ }
+
+ CORBA_exception_free (&ev);
+ return db;
+}
+
+/* Syncs a database and unrefs it */
+static void
+discard_config_db (Bonobo_ConfigDatabase db)
+{
+ CORBA_Environment ev;
+
+ CORBA_exception_init (&ev);
+
+ Bonobo_ConfigDatabase_sync (db, &ev);
+ if (BONOBO_EX (&ev))
+ g_message ("discard_config_db(): Got an exception during the sync command");
+
+ CORBA_exception_free (&ev);
+
+ CORBA_exception_init (&ev);
+
+ bonobo_object_release_unref (db, &ev);
+ if (BONOBO_EX (&ev))
+ g_message ("discard_config_db(): Could not release/unref the database");
+
+ CORBA_exception_free (&ev);
+}
+
+/**
+ * save_notification_time:
+ * @t: A time value.
+ *
+ * Saves the last notification time so that it can be fetched the next time the
+ * alarm daemon is run. This way the daemon can show alarms that should have
+ * triggered while it was not running.
+ **/
+void
+save_notification_time (time_t t)
+{
+ Bonobo_ConfigDatabase db;
+ CORBA_Environment ev;
+
+ g_return_if_fail (t != -1);
+
+ db = get_config_db ();
+ if (db == CORBA_OBJECT_NIL)
+ return;
+
+ CORBA_exception_init (&ev);
+
+ bonobo_config_set_long (db, "/Calendar/AlarmNotify/LastNotificationTime", (long) t, &ev);
+ if (BONOBO_EX (&ev))
+ g_message ("save_notification_time(): Could not save the value");
+
+ CORBA_exception_free (&ev);
+
+ discard_config_db (db);
+}
+
+/**
+ * get_saved_notification_time:
+ *
+ * Queries the last saved value for alarm notification times.
+ *
+ * Return value: The last saved value, or -1 if no value had been saved before.
+ **/
+time_t
+get_saved_notification_time (void)
+{
+ Bonobo_ConfigDatabase db;
+ long t;
+
+ db = get_config_db ();
+ if (db == CORBA_OBJECT_NIL)
+ return -1;
+
+ t = bonobo_config_get_long_with_default (db, "/Calendar/AlarmNotify/LastNotificationTime",
+ -1, NULL);
+
+ discard_config_db (db);
+
+ return (time_t) t;
+}
diff --git a/calendar/gui/alarm-notify/save.h b/calendar/gui/alarm-notify/save.h
new file mode 100644
index 0000000000..550fc972ea
--- /dev/null
+++ b/calendar/gui/alarm-notify/save.h
@@ -0,0 +1,31 @@
+/* Evolution calendar - Functions to save alarm notification times
+ *
+ * Copyright (C) 2001 Ximian, Inc.
+ *
+ * Authors: Federico Mena-Quintero <federico@ximian.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SAVE_H
+#define SAVE_H
+
+#include <time.h>
+
+void save_notification_time (time_t t);
+
+time_t get_saved_notification_time (void);
+
+#endif