aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
authorArturo Espinosa <unammx@src.gnome.org>1998-04-25 10:23:26 +0800
committerArturo Espinosa <unammx@src.gnome.org>1998-04-25 10:23:26 +0800
commit07f873d107539a4357c69e1f3ce8cef17cc6277f (patch)
treed45a8c78f766cbf861b8bf7b34d80dc76b75da7c /calendar
parentce6e9cd00e965c92debe331b7c762b18674bbc85 (diff)
downloadgsoc2013-evolution-07f873d107539a4357c69e1f3ce8cef17cc6277f.tar
gsoc2013-evolution-07f873d107539a4357c69e1f3ce8cef17cc6277f.tar.gz
gsoc2013-evolution-07f873d107539a4357c69e1f3ce8cef17cc6277f.tar.bz2
gsoc2013-evolution-07f873d107539a4357c69e1f3ce8cef17cc6277f.tar.lz
gsoc2013-evolution-07f873d107539a4357c69e1f3ce8cef17cc6277f.tar.xz
gsoc2013-evolution-07f873d107539a4357c69e1f3ce8cef17cc6277f.tar.zst
gsoc2013-evolution-07f873d107539a4357c69e1f3ce8cef17cc6277f.zip
Fixed alarm saving code. Fixed alarm loading code. New -partial-
Fixed alarm saving code. Fixed alarm loading code. New -partial- implementation of the mail alarm. It is not working, I do not know what is closing stdin to sendmail svn path=/trunk/; revision=194
Diffstat (limited to 'calendar')
-rw-r--r--calendar/ChangeLog5
-rw-r--r--calendar/cal-util/calobj.c64
-rw-r--r--calendar/cal-util/calobj.h4
-rw-r--r--calendar/calendar.c2
-rw-r--r--calendar/calobj.c64
-rw-r--r--calendar/calobj.h4
-rw-r--r--calendar/eventedit.c4
-rw-r--r--calendar/gnome-cal.c35
-rw-r--r--calendar/gui/calendar.c2
-rw-r--r--calendar/gui/eventedit.c4
-rw-r--r--calendar/gui/gnome-cal.c35
-rw-r--r--calendar/gui/main.c45
-rw-r--r--calendar/main.c45
-rw-r--r--calendar/pcs/calobj.c64
-rw-r--r--calendar/pcs/calobj.h4
-rw-r--r--calendar/timeutil.c103
-rw-r--r--calendar/timeutil.h2
17 files changed, 394 insertions, 92 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index 6e5078a039..b3cb57885b 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,8 @@
+1998-04-24 Miguel de Icaza <miguel@nuclecu.unam.mx>
+
+ * calobj.c (ical_object_create_from_vobject): Fixed alarm loading;
+ Load snooze time and snooze count
+
1998-04-23 Federico Mena Quintero <federico@nuclecu.unam.mx>
* calendar.c (calendar_save): Actually save the to-do entries.
diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c
index f3098047bd..b6f5fc7f20 100644
--- a/calendar/cal-util/calobj.c
+++ b/calendar/cal-util/calobj.c
@@ -412,17 +412,25 @@ load_recurrence (iCalObject *o, char *str)
return 1;
}
+#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop)
+#define str_val(obj) the_str = fakeCString (vObjectUStringZValue (obj))
+#define has(obj,prop) (vo = isAPropertyOf (obj, prop))
+
/*
* FIXME: This is loosing precission. Enhanec the thresholds
*/
#define HOURS(n) (n*(60*60))
static void
-setup_alarm_at (time_t base, CalendarAlarm *alarm, char *iso_time)
+setup_alarm_at (iCalObject *ico, CalendarAlarm *alarm, char *iso_time, VObject *vo)
{
time_t alarm_time = time_from_isodate (iso_time);
+ time_t base = ico->dtstart;
int d = difftime (base, alarm_time);
-
+ VObject *a;
+ char *the_str;
+
+ alarm->enabled = 1;
if (d > HOURS (2)){
if (d > HOURS (48)){
alarm->count = d / HOURS (24);
@@ -435,11 +443,17 @@ setup_alarm_at (time_t base, CalendarAlarm *alarm, char *iso_time)
alarm->count = d / 60;
alarm->units = ALARM_MINUTES;
}
-}
-#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop)
-#define str_val(obj) the_str = fakeCString (vObjectUStringZValue (obj))
-#define has(obj,prop) (vo = isAPropertyOf (obj, prop))
+ if ((a = is_a_prop_of (vo, VCSnoozeTimeProp))){
+ alarm->snooze_secs = isodiff_to_secs (str_val (a));
+ free (the_str);
+ }
+
+ if ((a = is_a_prop_of (vo, VCRepeatCountProp))){
+ alarm->snooze_repeat = atoi (str_val (a));
+ free (the_str);
+ }
+}
/* FIXME: we need to load the recurrence properties */
iCalObject *
@@ -597,9 +611,8 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->dalarm.type = ALARM_DISPLAY;
ical->dalarm.enabled = 0;
if (has (o, VCDAlarmProp)){
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->dalarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->dalarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->dalarm, str_val (a), vo);
free (the_str);
}
}
@@ -608,9 +621,8 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->aalarm.type = ALARM_AUDIO;
ical->aalarm.enabled = 0;
if (has (o, VCAAlarmProp)){
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->aalarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->aalarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->aalarm, str_val (a), vo);
free (the_str);
}
}
@@ -620,12 +632,11 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->palarm.enabled = 0;
if (has (o, VCPAlarmProp)){
ical->palarm.type = ALARM_PROGRAM;
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->palarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->palarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->palarm, str_val (a), vo);
free (the_str);
- if ((a = is_a_prop_of (o, VCProcedureNameProp))){
+ if ((a = is_a_prop_of (vo, VCProcedureNameProp))){
ical->palarm.data = g_strdup (str_val (a));
free (the_str);
}
@@ -637,12 +648,11 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->malarm.enabled = 0;
if (has (o, VCMAlarmProp)){
ical->malarm.type = ALARM_MAIL;
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->malarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->malarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->malarm, str_val (a), vo);
free (the_str);
- if ((a = is_a_prop_of (o, VCEmailAddressProp))){
+ if ((a = is_a_prop_of (vo, VCEmailAddressProp))){
ical->malarm.data = g_strdup (str_val (a));
free (the_str);
}
@@ -754,9 +764,19 @@ save_alarm (VObject *o, CalendarAlarm *alarm, iCalObject *ical)
alarm_time = mktime (tm);
alarm_object = addProp (o, alarm_names [alarm->type]);
addPropValue (alarm_object, VCRunTimeProp, isodate_from_time_t (alarm_time));
- addPropValue (alarm_object, VCRepeatCountProp, "1");
- addPropValue (alarm_object, VCDisplayStringProp, "GNOME appointment alarm");
+ if (alarm->snooze_secs)
+ addPropValue (alarm_object, VCSnoozeTimeProp, isodiff_from_secs (alarm->snooze_secs));
+ else
+ addPropValue (alarm_object, VCSnoozeTimeProp, "");
+
+ if (alarm->snooze_repeat){
+ char buf [20];
+
+ sprintf (buf, "%d", alarm->snooze_repeat);
+ addPropValue (alarm_object, VCRepeatCountProp, buf);
+ } else
+ addPropValue (alarm_object, VCRepeatCountProp, "");
return alarm_object;
}
diff --git a/calendar/cal-util/calobj.h b/calendar/cal-util/calobj.h
index 60483c68ad..12b7578f10 100644
--- a/calendar/cal-util/calobj.h
+++ b/calendar/cal-util/calobj.h
@@ -36,6 +36,9 @@ typedef struct {
/* Does not get saved, internally used */
time_t offset;
time_t trigger;
+
+ int snooze_secs;
+ int snooze_repeat;
/* Widgets */
void *w_count; /* A GtkEntry */
@@ -109,6 +112,7 @@ typedef struct {
time_t _enddate; /* As found on the vCalendar file */
int __count;
} Recurrence;
+
#define IS_INFINITE(r) (r->duration == 0)
/* Flags to indicate what has changed in an object */
diff --git a/calendar/calendar.c b/calendar/calendar.c
index dc480e3dfd..2a5b532a04 100644
--- a/calendar/calendar.c
+++ b/calendar/calendar.c
@@ -97,6 +97,8 @@ calendar_add_object (Calendar *cal, iCalObject *obj)
case ICAL_EVENT:
cal->events = g_list_prepend (cal->events, obj);
ical_object_try_alarms (obj);
+ obj->malarm.trigger = 0;
+ calendar_notify (0, obj);
break;
case ICAL_TODO:
diff --git a/calendar/calobj.c b/calendar/calobj.c
index f3098047bd..b6f5fc7f20 100644
--- a/calendar/calobj.c
+++ b/calendar/calobj.c
@@ -412,17 +412,25 @@ load_recurrence (iCalObject *o, char *str)
return 1;
}
+#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop)
+#define str_val(obj) the_str = fakeCString (vObjectUStringZValue (obj))
+#define has(obj,prop) (vo = isAPropertyOf (obj, prop))
+
/*
* FIXME: This is loosing precission. Enhanec the thresholds
*/
#define HOURS(n) (n*(60*60))
static void
-setup_alarm_at (time_t base, CalendarAlarm *alarm, char *iso_time)
+setup_alarm_at (iCalObject *ico, CalendarAlarm *alarm, char *iso_time, VObject *vo)
{
time_t alarm_time = time_from_isodate (iso_time);
+ time_t base = ico->dtstart;
int d = difftime (base, alarm_time);
-
+ VObject *a;
+ char *the_str;
+
+ alarm->enabled = 1;
if (d > HOURS (2)){
if (d > HOURS (48)){
alarm->count = d / HOURS (24);
@@ -435,11 +443,17 @@ setup_alarm_at (time_t base, CalendarAlarm *alarm, char *iso_time)
alarm->count = d / 60;
alarm->units = ALARM_MINUTES;
}
-}
-#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop)
-#define str_val(obj) the_str = fakeCString (vObjectUStringZValue (obj))
-#define has(obj,prop) (vo = isAPropertyOf (obj, prop))
+ if ((a = is_a_prop_of (vo, VCSnoozeTimeProp))){
+ alarm->snooze_secs = isodiff_to_secs (str_val (a));
+ free (the_str);
+ }
+
+ if ((a = is_a_prop_of (vo, VCRepeatCountProp))){
+ alarm->snooze_repeat = atoi (str_val (a));
+ free (the_str);
+ }
+}
/* FIXME: we need to load the recurrence properties */
iCalObject *
@@ -597,9 +611,8 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->dalarm.type = ALARM_DISPLAY;
ical->dalarm.enabled = 0;
if (has (o, VCDAlarmProp)){
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->dalarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->dalarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->dalarm, str_val (a), vo);
free (the_str);
}
}
@@ -608,9 +621,8 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->aalarm.type = ALARM_AUDIO;
ical->aalarm.enabled = 0;
if (has (o, VCAAlarmProp)){
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->aalarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->aalarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->aalarm, str_val (a), vo);
free (the_str);
}
}
@@ -620,12 +632,11 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->palarm.enabled = 0;
if (has (o, VCPAlarmProp)){
ical->palarm.type = ALARM_PROGRAM;
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->palarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->palarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->palarm, str_val (a), vo);
free (the_str);
- if ((a = is_a_prop_of (o, VCProcedureNameProp))){
+ if ((a = is_a_prop_of (vo, VCProcedureNameProp))){
ical->palarm.data = g_strdup (str_val (a));
free (the_str);
}
@@ -637,12 +648,11 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->malarm.enabled = 0;
if (has (o, VCMAlarmProp)){
ical->malarm.type = ALARM_MAIL;
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->malarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->malarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->malarm, str_val (a), vo);
free (the_str);
- if ((a = is_a_prop_of (o, VCEmailAddressProp))){
+ if ((a = is_a_prop_of (vo, VCEmailAddressProp))){
ical->malarm.data = g_strdup (str_val (a));
free (the_str);
}
@@ -754,9 +764,19 @@ save_alarm (VObject *o, CalendarAlarm *alarm, iCalObject *ical)
alarm_time = mktime (tm);
alarm_object = addProp (o, alarm_names [alarm->type]);
addPropValue (alarm_object, VCRunTimeProp, isodate_from_time_t (alarm_time));
- addPropValue (alarm_object, VCRepeatCountProp, "1");
- addPropValue (alarm_object, VCDisplayStringProp, "GNOME appointment alarm");
+ if (alarm->snooze_secs)
+ addPropValue (alarm_object, VCSnoozeTimeProp, isodiff_from_secs (alarm->snooze_secs));
+ else
+ addPropValue (alarm_object, VCSnoozeTimeProp, "");
+
+ if (alarm->snooze_repeat){
+ char buf [20];
+
+ sprintf (buf, "%d", alarm->snooze_repeat);
+ addPropValue (alarm_object, VCRepeatCountProp, buf);
+ } else
+ addPropValue (alarm_object, VCRepeatCountProp, "");
return alarm_object;
}
diff --git a/calendar/calobj.h b/calendar/calobj.h
index 60483c68ad..12b7578f10 100644
--- a/calendar/calobj.h
+++ b/calendar/calobj.h
@@ -36,6 +36,9 @@ typedef struct {
/* Does not get saved, internally used */
time_t offset;
time_t trigger;
+
+ int snooze_secs;
+ int snooze_repeat;
/* Widgets */
void *w_count; /* A GtkEntry */
@@ -109,6 +112,7 @@ typedef struct {
time_t _enddate; /* As found on the vCalendar file */
int __count;
} Recurrence;
+
#define IS_INFINITE(r) (r->duration == 0)
/* Flags to indicate what has changed in an object */
diff --git a/calendar/eventedit.c b/calendar/eventedit.c
index 0158d29673..e6e2ea6b55 100644
--- a/calendar/eventedit.c
+++ b/calendar/eventedit.c
@@ -326,8 +326,6 @@ ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType t
GTK_SIGNAL_FUNC (alarm_toggle), alarm);
gtk_table_attach (table, alarm->w_enabled, 0, 1, y, y+1, FS, FS, 0, 0);
- gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (alarm->w_enabled), alarm->enabled);
-
alarm->w_count = make_spin_button (alarm->count, 0, 10000);
gtk_table_attach (table, alarm->w_count, 1, 2, y, y+1, FS, FS, 0, 0);
@@ -358,7 +356,7 @@ ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType t
default:
break;
}
-
+ gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (alarm->w_enabled), alarm->enabled);
ee_alarm_setting (alarm, alarm->enabled);
}
diff --git a/calendar/gnome-cal.c b/calendar/gnome-cal.c
index 755785836a..534db8bb4c 100644
--- a/calendar/gnome-cal.c
+++ b/calendar/gnome-cal.c
@@ -9,6 +9,7 @@
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
+#include <fcntl.h>
#include "calendar.h"
#include "gnome-cal.h"
#include "gncal-day-panel.h"
@@ -257,9 +258,9 @@ execute (char *command, int close_standard)
*/
execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0);
- exit (127);
+ _exit (127);
} else {
- exit (127);
+ _exit (127);
}
}
wait (&status);
@@ -285,13 +286,31 @@ calendar_notify (time_t time, void *data)
if (ico->malarm.enabled && ico->malarm.trigger == time){
char *command;
time_t app = ico->malarm.trigger + ico->malarm.offset;
+ pid_t pid;
+ int p [2];
- command = g_copy_strings ("mail -s '",
- _("Reminder of your appointment at "),
- ctime (&app), "' '",
- ico->malarm.data, "' ",
- NULL);
- execute (command, 1);
+ pipe (p);
+ pid = fork ();
+ if (pid == 0){
+ const int top = max_open_files ();
+ int dev_null, i;
+
+ for (i = 0; i < top; i++)
+ if (i != p [1])
+ close (i);
+ dev_null = open ("/dev/null", O_RDWR);
+ dup2 (p [1], 0);
+ dup2 (dev_null, 1);
+ dup2 (dev_null, 2);
+ execl ("/usr/lib/sendmail", "/usr/lib/sendmail",
+ ico->malarm.data, NULL);
+ _exit (127);
+ }
+ close (p [1]);
+ command = g_copy_strings ("To: ", ico->malarm.data, "\n",
+ "Subject: ", _("Reminder of your appointment at "),
+ ctime (&app), "\n\n", NULL);
+ write (p [0], command, strlen (command));
g_free (command);
return;
diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c
index dc480e3dfd..2a5b532a04 100644
--- a/calendar/gui/calendar.c
+++ b/calendar/gui/calendar.c
@@ -97,6 +97,8 @@ calendar_add_object (Calendar *cal, iCalObject *obj)
case ICAL_EVENT:
cal->events = g_list_prepend (cal->events, obj);
ical_object_try_alarms (obj);
+ obj->malarm.trigger = 0;
+ calendar_notify (0, obj);
break;
case ICAL_TODO:
diff --git a/calendar/gui/eventedit.c b/calendar/gui/eventedit.c
index 0158d29673..e6e2ea6b55 100644
--- a/calendar/gui/eventedit.c
+++ b/calendar/gui/eventedit.c
@@ -326,8 +326,6 @@ ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType t
GTK_SIGNAL_FUNC (alarm_toggle), alarm);
gtk_table_attach (table, alarm->w_enabled, 0, 1, y, y+1, FS, FS, 0, 0);
- gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (alarm->w_enabled), alarm->enabled);
-
alarm->w_count = make_spin_button (alarm->count, 0, 10000);
gtk_table_attach (table, alarm->w_count, 1, 2, y, y+1, FS, FS, 0, 0);
@@ -358,7 +356,7 @@ ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType t
default:
break;
}
-
+ gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (alarm->w_enabled), alarm->enabled);
ee_alarm_setting (alarm, alarm->enabled);
}
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index 755785836a..534db8bb4c 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -9,6 +9,7 @@
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>
+#include <fcntl.h>
#include "calendar.h"
#include "gnome-cal.h"
#include "gncal-day-panel.h"
@@ -257,9 +258,9 @@ execute (char *command, int close_standard)
*/
execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0);
- exit (127);
+ _exit (127);
} else {
- exit (127);
+ _exit (127);
}
}
wait (&status);
@@ -285,13 +286,31 @@ calendar_notify (time_t time, void *data)
if (ico->malarm.enabled && ico->malarm.trigger == time){
char *command;
time_t app = ico->malarm.trigger + ico->malarm.offset;
+ pid_t pid;
+ int p [2];
- command = g_copy_strings ("mail -s '",
- _("Reminder of your appointment at "),
- ctime (&app), "' '",
- ico->malarm.data, "' ",
- NULL);
- execute (command, 1);
+ pipe (p);
+ pid = fork ();
+ if (pid == 0){
+ const int top = max_open_files ();
+ int dev_null, i;
+
+ for (i = 0; i < top; i++)
+ if (i != p [1])
+ close (i);
+ dev_null = open ("/dev/null", O_RDWR);
+ dup2 (p [1], 0);
+ dup2 (dev_null, 1);
+ dup2 (dev_null, 2);
+ execl ("/usr/lib/sendmail", "/usr/lib/sendmail",
+ ico->malarm.data, NULL);
+ _exit (127);
+ }
+ close (p [1]);
+ command = g_copy_strings ("To: ", ico->malarm.data, "\n",
+ "Subject: ", _("Reminder of your appointment at "),
+ ctime (&app), "\n\n", NULL);
+ write (p [0], command, strlen (command));
g_free (command);
return;
diff --git a/calendar/gui/main.c b/calendar/gui/main.c
index f7d7838fe4..1d19da236c 100644
--- a/calendar/gui/main.c
+++ b/calendar/gui/main.c
@@ -51,6 +51,9 @@ static char *load_file;
/* If set, show events for the specified date and quit */
static int show_events;
+/* Session management */
+static GnomeClient *sm_client;
+
static void
init_username (void)
{
@@ -121,7 +124,7 @@ about_calendar_cmd (GtkWidget *widget, void *data)
};
about = gnome_about_new (_("Gnome Calendar"), VERSION,
- "(C) 1998 the Free Software Fundation",
+ "(C) 1998 the Free Software Foundation",
authors,
_("The GNOME personal calendar and schedule manager."),
NULL);
@@ -171,7 +174,7 @@ day_range_changed (void)
}
static void
-quit_cmd (GtkWidget *widget, GnomeCalendar *gcal)
+quit_cmd (void)
{
while (all_calendars){
GnomeCalendar *cal = GNOME_CALENDAR (all_calendars->data);
@@ -500,6 +503,42 @@ static struct argp parser =
argp_options, parse_an_arg, NULL, NULL, NULL, NULL, NULL
};
+static void
+session_die (void)
+{
+ quit_cmd ();
+}
+
+static int
+session_save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style, gint shutdown,
+ GnomeInteractStyle interact_style, gint fast, gpointer client_data)
+{
+ printf ("Got a message to save the state\n");
+}
+
+/* Setup the Session Manager shutdown routine */
+static GnomeClient *
+new_client (void)
+{
+ GnomeClient *client;
+ char buf [4096];
+
+ client = gnome_client_new_default ();
+ if (client)
+ return NULL;
+
+ getcwd ((void *)&buf, sizeof (buf));
+
+ gtk_object_ref(GTK_OBJECT(client));
+ gtk_object_sink(GTK_OBJECT(client));
+
+ gtk_signal_connect (GTK_OBJECT (client), "save_yourself",
+ GTK_SIGNAL_FUNC (session_save_state), NULL);
+ gtk_signal_connect (GTK_OBJECT (client), "die",
+ GTK_SIGNAL_FUNC (session_die), NULL);
+ return client;
+}
+
int
main(int argc, char *argv[])
{
@@ -510,6 +549,8 @@ main(int argc, char *argv[])
gnome_init ("calendar", &parser, argc, argv, 0, NULL);
+ sm_client = new_client ();
+
process_dates ();
alarm_init ();
init_calendar ();
diff --git a/calendar/main.c b/calendar/main.c
index f7d7838fe4..1d19da236c 100644
--- a/calendar/main.c
+++ b/calendar/main.c
@@ -51,6 +51,9 @@ static char *load_file;
/* If set, show events for the specified date and quit */
static int show_events;
+/* Session management */
+static GnomeClient *sm_client;
+
static void
init_username (void)
{
@@ -121,7 +124,7 @@ about_calendar_cmd (GtkWidget *widget, void *data)
};
about = gnome_about_new (_("Gnome Calendar"), VERSION,
- "(C) 1998 the Free Software Fundation",
+ "(C) 1998 the Free Software Foundation",
authors,
_("The GNOME personal calendar and schedule manager."),
NULL);
@@ -171,7 +174,7 @@ day_range_changed (void)
}
static void
-quit_cmd (GtkWidget *widget, GnomeCalendar *gcal)
+quit_cmd (void)
{
while (all_calendars){
GnomeCalendar *cal = GNOME_CALENDAR (all_calendars->data);
@@ -500,6 +503,42 @@ static struct argp parser =
argp_options, parse_an_arg, NULL, NULL, NULL, NULL, NULL
};
+static void
+session_die (void)
+{
+ quit_cmd ();
+}
+
+static int
+session_save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style, gint shutdown,
+ GnomeInteractStyle interact_style, gint fast, gpointer client_data)
+{
+ printf ("Got a message to save the state\n");
+}
+
+/* Setup the Session Manager shutdown routine */
+static GnomeClient *
+new_client (void)
+{
+ GnomeClient *client;
+ char buf [4096];
+
+ client = gnome_client_new_default ();
+ if (client)
+ return NULL;
+
+ getcwd ((void *)&buf, sizeof (buf));
+
+ gtk_object_ref(GTK_OBJECT(client));
+ gtk_object_sink(GTK_OBJECT(client));
+
+ gtk_signal_connect (GTK_OBJECT (client), "save_yourself",
+ GTK_SIGNAL_FUNC (session_save_state), NULL);
+ gtk_signal_connect (GTK_OBJECT (client), "die",
+ GTK_SIGNAL_FUNC (session_die), NULL);
+ return client;
+}
+
int
main(int argc, char *argv[])
{
@@ -510,6 +549,8 @@ main(int argc, char *argv[])
gnome_init ("calendar", &parser, argc, argv, 0, NULL);
+ sm_client = new_client ();
+
process_dates ();
alarm_init ();
init_calendar ();
diff --git a/calendar/pcs/calobj.c b/calendar/pcs/calobj.c
index f3098047bd..b6f5fc7f20 100644
--- a/calendar/pcs/calobj.c
+++ b/calendar/pcs/calobj.c
@@ -412,17 +412,25 @@ load_recurrence (iCalObject *o, char *str)
return 1;
}
+#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop)
+#define str_val(obj) the_str = fakeCString (vObjectUStringZValue (obj))
+#define has(obj,prop) (vo = isAPropertyOf (obj, prop))
+
/*
* FIXME: This is loosing precission. Enhanec the thresholds
*/
#define HOURS(n) (n*(60*60))
static void
-setup_alarm_at (time_t base, CalendarAlarm *alarm, char *iso_time)
+setup_alarm_at (iCalObject *ico, CalendarAlarm *alarm, char *iso_time, VObject *vo)
{
time_t alarm_time = time_from_isodate (iso_time);
+ time_t base = ico->dtstart;
int d = difftime (base, alarm_time);
-
+ VObject *a;
+ char *the_str;
+
+ alarm->enabled = 1;
if (d > HOURS (2)){
if (d > HOURS (48)){
alarm->count = d / HOURS (24);
@@ -435,11 +443,17 @@ setup_alarm_at (time_t base, CalendarAlarm *alarm, char *iso_time)
alarm->count = d / 60;
alarm->units = ALARM_MINUTES;
}
-}
-#define is_a_prop_of(obj,prop) isAPropertyOf (obj,prop)
-#define str_val(obj) the_str = fakeCString (vObjectUStringZValue (obj))
-#define has(obj,prop) (vo = isAPropertyOf (obj, prop))
+ if ((a = is_a_prop_of (vo, VCSnoozeTimeProp))){
+ alarm->snooze_secs = isodiff_to_secs (str_val (a));
+ free (the_str);
+ }
+
+ if ((a = is_a_prop_of (vo, VCRepeatCountProp))){
+ alarm->snooze_repeat = atoi (str_val (a));
+ free (the_str);
+ }
+}
/* FIXME: we need to load the recurrence properties */
iCalObject *
@@ -597,9 +611,8 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->dalarm.type = ALARM_DISPLAY;
ical->dalarm.enabled = 0;
if (has (o, VCDAlarmProp)){
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->dalarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->dalarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->dalarm, str_val (a), vo);
free (the_str);
}
}
@@ -608,9 +621,8 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->aalarm.type = ALARM_AUDIO;
ical->aalarm.enabled = 0;
if (has (o, VCAAlarmProp)){
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->aalarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->aalarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->aalarm, str_val (a), vo);
free (the_str);
}
}
@@ -620,12 +632,11 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->palarm.enabled = 0;
if (has (o, VCPAlarmProp)){
ical->palarm.type = ALARM_PROGRAM;
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->palarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->palarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->palarm, str_val (a), vo);
free (the_str);
- if ((a = is_a_prop_of (o, VCProcedureNameProp))){
+ if ((a = is_a_prop_of (vo, VCProcedureNameProp))){
ical->palarm.data = g_strdup (str_val (a));
free (the_str);
}
@@ -637,12 +648,11 @@ ical_object_create_from_vobject (VObject *o, const char *object_name)
ical->malarm.enabled = 0;
if (has (o, VCMAlarmProp)){
ical->malarm.type = ALARM_MAIL;
- if ((a = is_a_prop_of (o, VCRunTimeProp))){
- ical->malarm.enabled = 1;
- setup_alarm_at (ical->dtstart, &ical->malarm, str_val (a));
+ if ((a = is_a_prop_of (vo, VCRunTimeProp))){
+ setup_alarm_at (ical, &ical->malarm, str_val (a), vo);
free (the_str);
- if ((a = is_a_prop_of (o, VCEmailAddressProp))){
+ if ((a = is_a_prop_of (vo, VCEmailAddressProp))){
ical->malarm.data = g_strdup (str_val (a));
free (the_str);
}
@@ -754,9 +764,19 @@ save_alarm (VObject *o, CalendarAlarm *alarm, iCalObject *ical)
alarm_time = mktime (tm);
alarm_object = addProp (o, alarm_names [alarm->type]);
addPropValue (alarm_object, VCRunTimeProp, isodate_from_time_t (alarm_time));
- addPropValue (alarm_object, VCRepeatCountProp, "1");
- addPropValue (alarm_object, VCDisplayStringProp, "GNOME appointment alarm");
+ if (alarm->snooze_secs)
+ addPropValue (alarm_object, VCSnoozeTimeProp, isodiff_from_secs (alarm->snooze_secs));
+ else
+ addPropValue (alarm_object, VCSnoozeTimeProp, "");
+
+ if (alarm->snooze_repeat){
+ char buf [20];
+
+ sprintf (buf, "%d", alarm->snooze_repeat);
+ addPropValue (alarm_object, VCRepeatCountProp, buf);
+ } else
+ addPropValue (alarm_object, VCRepeatCountProp, "");
return alarm_object;
}
diff --git a/calendar/pcs/calobj.h b/calendar/pcs/calobj.h
index 60483c68ad..12b7578f10 100644
--- a/calendar/pcs/calobj.h
+++ b/calendar/pcs/calobj.h
@@ -36,6 +36,9 @@ typedef struct {
/* Does not get saved, internally used */
time_t offset;
time_t trigger;
+
+ int snooze_secs;
+ int snooze_repeat;
/* Widgets */
void *w_count; /* A GtkEntry */
@@ -109,6 +112,7 @@ typedef struct {
time_t _enddate; /* As found on the vCalendar file */
int __count;
} Recurrence;
+
#define IS_INFINITE(r) (r->duration == 0)
/* Flags to indicate what has changed in an object */
diff --git a/calendar/timeutil.c b/calendar/timeutil.c
index 61df809a93..0813410a3a 100644
--- a/calendar/timeutil.c
+++ b/calendar/timeutil.c
@@ -218,3 +218,106 @@ time_week_begin (time_t t)
return mktime (&tm);
}
+static char *
+pcat (char *dest, int num, char key)
+{
+ int c;
+
+ c = sprintf (dest, "%d%c", num, key);
+ return dest + c;
+}
+
+/* Converts secs into the ISO difftime representation */
+char *
+isodiff_from_secs (int secs)
+{
+ static char buffer [60], *p;
+ int years, months, weeks, days, hours, minutes;
+
+ years = months = weeks = days = hours = minutes = 0;
+
+ years = secs / (365 * 86400);
+ secs %= (365 * 86400);
+ months = secs / (30 * 86400);
+ secs %= (30 * 86400);
+ weeks = secs / (7 * 86400);
+ secs %= (7 * 86400);
+ days = secs / 86400;
+ secs %= 86400;
+ hours = secs / 3600;
+ secs %= 3600;
+ minutes = secs / 60;
+ secs %= 60;
+
+ strcpy (buffer, "P");
+ p = buffer + 1;
+ if (years)
+ p = pcat (p, years, 'Y');
+ if (months)
+ p = pcat (p, months, 'M');
+ if (weeks)
+ p = pcat (p, weeks, 'W');
+ if (days)
+ p = pcat (p, days, 'D');
+ if (hours || minutes || secs){
+ *p++ = 'T';
+ if (hours)
+ p = pcat (p, hours, 'H');
+ if (minutes)
+ p = pcat (p, minutes, 'M');
+ if (secs)
+ p = pcat (p, secs, 'S');
+ }
+
+ return buffer;
+}
+
+int
+isodiff_to_secs (char *str)
+{
+ int value, time;
+ int years, months, weeks, days, hours, minutes, seconds;
+
+ value = years = months = weeks = days = hours = minutes = time = seconds = 0;
+ if (*str != 'P')
+ return 0;
+
+ str++;
+ while (*str){
+ switch (*str){
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ value = value * 10 + (*str - '0');
+ break;
+ case 'Y':
+ years = value; value = 0;
+ break;
+ case 'M':
+ if (time)
+ minutes = value;
+ else
+ months = value;
+ value = 0;
+ break;
+ case 'W':
+ weeks = value; value = 0;
+ break;
+ case 'D':
+ days = value; value = 0;
+ break;
+ case 'T':
+ value = 0; time = 1;
+ break;
+ case 'H':
+ hours = value; value = 0;
+ break;
+ case 'S':
+ seconds = value; value = 0;
+ break;
+ }
+ str++;
+ }
+ return seconds + (minutes * 60) + (hours * 3600) +
+ (days * 86400) + (weeks * 7 * 86400) +
+ (months * 30 * 86400) + (years * 365 * 86400);
+}
diff --git a/calendar/timeutil.h b/calendar/timeutil.h
index 9c9d2d8a80..73b7e607dc 100644
--- a/calendar/timeutil.h
+++ b/calendar/timeutil.h
@@ -17,6 +17,8 @@ time_t time_from_isodate (char *str);
time_t time_from_start_duration (time_t start, char *duration);
char *isodate_from_time_t (time_t t);
int get_time_t_hour (time_t t);
+int isodiff_to_secs (char *str);
+char *isodiff_from_secs (int secs);
time_t time_add_minutes (time_t time, int minutes);
time_t time_add_day (time_t time, int days);