diff options
author | Federico Mena Quintero <federico@helixcode.com> | 2001-01-03 00:35:57 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2001-01-03 00:35:57 +0800 |
commit | b3e4ed6da61c048e670a0623f18645f5519c3cd0 (patch) | |
tree | c268921b31edfe03e295dced8325c33c43e86892 /calendar | |
parent | 45f3b8b6e04845a465d6b4d06a2af876e90296ce (diff) | |
download | gsoc2013-evolution-b3e4ed6da61c048e670a0623f18645f5519c3cd0.tar.gz gsoc2013-evolution-b3e4ed6da61c048e670a0623f18645f5519c3cd0.tar.zst gsoc2013-evolution-b3e4ed6da61c048e670a0623f18645f5519c3cd0.zip |
Unconditionally remove the client from the alarm notification system.
2001-01-01 Federico Mena Quintero <federico@helixcode.com>
* gui/gnome-cal.c (gnome_calendar_destroy): Unconditionally remove
the client from the alarm notification system.
Removed all the obsolete alarm code.
* gui/event-editor.c: Removed some crufty externs left over from
Gnomecal.
* gui/calendar-commands.c: #include "goto.h"
Removed crufty variables left over from Gnomecal.
(new_calendar): Do not take a full_name parameter.
(init_username): Removed function.
(init_calendar): Wheeeeeeee! Removed crufty function.
(quit_cmd): Removed function.
* gui/print.c (WEEK_STARTS_ON_MONDAY): Made it unconditionally
FALSE because we do not use the configuration setting anyways.
Sigh, all the printing code needs to be revamped.
svn path=/trunk/; revision=7209
Diffstat (limited to 'calendar')
-rw-r--r-- | calendar/ChangeLog | 20 | ||||
-rw-r--r-- | calendar/gui/alarm-notify.c | 406 | ||||
-rw-r--r-- | calendar/gui/alarm-notify/alarm-queue.c | 406 | ||||
-rw-r--r-- | calendar/gui/calendar-commands.c | 215 | ||||
-rw-r--r-- | calendar/gui/calendar-commands.h | 78 | ||||
-rw-r--r-- | calendar/gui/calendar-model.c | 3 | ||||
-rw-r--r-- | calendar/gui/control-factory.c | 2 | ||||
-rw-r--r-- | calendar/gui/event-editor.c | 4 | ||||
-rw-r--r-- | calendar/gui/gnome-cal.c | 478 | ||||
-rw-r--r-- | calendar/gui/main.c | 2 | ||||
-rw-r--r-- | calendar/gui/print.c | 11 |
11 files changed, 852 insertions, 773 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index 9aa2728798..b372baa31e 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,3 +1,23 @@ +2001-01-01 Federico Mena Quintero <federico@helixcode.com> + + * gui/gnome-cal.c (gnome_calendar_destroy): Unconditionally remove + the client from the alarm notification system. + Removed all the obsolete alarm code. + + * gui/event-editor.c: Removed some crufty externs left over from + Gnomecal. + + * gui/calendar-commands.c: #include "goto.h" + Removed crufty variables left over from Gnomecal. + (new_calendar): Do not take a full_name parameter. + (init_username): Removed function. + (init_calendar): Wheeeeeeee! Removed crufty function. + (quit_cmd): Removed function. + + * gui/print.c (WEEK_STARTS_ON_MONDAY): Made it unconditionally + FALSE because we do not use the configuration setting anyways. + Sigh, all the printing code needs to be revamped. + 2000-12-26 Iain Holmes <iain@helixcode.com> * gui/calendar-summary.c (create_summary_view): Create a shared diff --git a/calendar/gui/alarm-notify.c b/calendar/gui/alarm-notify.c index 6f0e8e6759..805b29f81d 100644 --- a/calendar/gui/alarm-notify.c +++ b/calendar/gui/alarm-notify.c @@ -509,3 +509,409 @@ alarm_notify_remove_client (CalClient *client) g_hash_table_remove (client_alarms_hash, client); } + + + +#if 0 + +/* Sends a mail notification of an alarm trigger */ +static void +mail_notification (char *mail_address, char *text, time_t app_time) +{ + pid_t pid; + int p [2]; + char *command; + + pipe (p); + pid = fork (); + if (pid == 0){ + int dev_null; + + dev_null = open ("/dev/null", O_RDWR); + dup2 (p [0], 0); + dup2 (dev_null, 1); + dup2 (dev_null, 2); + execl ("/usr/lib/sendmail", "/usr/lib/sendmail", + mail_address, NULL); + _exit (127); + } + command = g_strconcat ("To: ", mail_address, "\n", + "Subject: ", _("Reminder of your appointment at "), + ctime (&app_time), "\n\n", text, "\n", NULL); + write (p [1], command, strlen (command)); + close (p [1]); + close (p [0]); + g_free (command); +} + +static int +max_open_files (void) +{ + static int files; + + if (files) + return files; + + files = sysconf (_SC_OPEN_MAX); + if (files != -1) + return files; +#ifdef OPEN_MAX + return files = OPEN_MAX; +#else + return files = 256; +#endif +} + +/* Executes a program as a notification of an alarm trigger */ +static void +program_notification (char *command, int close_standard) +{ + struct sigaction ignore, save_intr, save_quit; + int status = 0, i; + pid_t pid; + + ignore.sa_handler = SIG_IGN; + sigemptyset (&ignore.sa_mask); + ignore.sa_flags = 0; + + sigaction (SIGINT, &ignore, &save_intr); + sigaction (SIGQUIT, &ignore, &save_quit); + + if ((pid = fork ()) < 0){ + fprintf (stderr, "\n\nfork () = -1\n"); + return; + } + if (pid == 0){ + pid = fork (); + if (pid == 0){ + const int top = max_open_files (); + sigaction (SIGINT, &save_intr, NULL); + sigaction (SIGQUIT, &save_quit, NULL); + + for (i = (close_standard ? 0 : 3); i < top; i++) + close (i); + + /* FIXME: As an excercise to the reader, copy the + * code from mc to setup shell properly instead of + * /bin/sh. Yes, this comment is larger than a cut and paste. + */ + execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0); + + _exit (127); + } else { + _exit (127); + } + } + wait (&status); + sigaction (SIGINT, &save_intr, NULL); + sigaction (SIGQUIT, &save_quit, NULL); +} + +/* Queues a snooze alarm */ +static void +snooze (GnomeCalendar *gcal, CalComponent *comp, time_t occur, int snooze_mins, gboolean audio) +{ + time_t now, trigger; + struct tm tm; + CalAlarmInstance ai; + + now = time (NULL); + tm = *localtime (&now); + tm.tm_min += snooze_mins; + + trigger = mktime (&tm); + if (trigger == -1) { + g_message ("snooze(): produced invalid time_t; not queueing alarm!"); + return; + } + +#if 0 + cal_component_get_uid (comp, &ai.uid); + ai.type = audio ? ALARM_AUDIO : ALARM_DISPLAY; +#endif + ai.trigger = trigger; + ai.occur = occur; + + setup_alarm (gcal, &ai); +} + +struct alarm_notify_closure { + GnomeCalendar *gcal; + CalComponent *comp; + time_t occur; +}; + +/* Callback used for the result of the alarm notification dialog */ +static void +display_notification_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) +{ + struct alarm_notify_closure *c; + + c = data; + + switch (result) { + case ALARM_NOTIFY_CLOSE: + break; + + case ALARM_NOTIFY_SNOOZE: + snooze (c->gcal, c->comp, c->occur, snooze_mins, FALSE); + break; + + case ALARM_NOTIFY_EDIT: + gnome_calendar_edit_object (c->gcal, c->comp); + break; + + default: + g_assert_not_reached (); + } + + gtk_object_unref (GTK_OBJECT (c->comp)); + g_free (c); +} + +/* Present a display notification of an alarm trigger */ +static void +display_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal) +{ + gboolean result; + struct alarm_notify_closure *c; + + gtk_object_ref (GTK_OBJECT (comp)); + + c = g_new (struct alarm_notify_closure, 1); + c->gcal = gcal; + c->comp = comp; + c->occur = occur; + + result = alarm_notify_dialog (trigger, occur, comp, display_notification_cb, c); + if (!result) { + g_message ("display_notification(): could not display the alarm notification dialog"); + g_free (c); + gtk_object_unref (GTK_OBJECT (comp)); + } +} + +/* Present an audible notification of an alarm trigger */ +static void +audio_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal) +{ + g_message ("AUDIO NOTIFICATION!"); + /* FIXME */ +} + +/* Callback function used when an alarm is triggered */ +static void +trigger_alarm_cb (gpointer alarm_id, time_t trigger, gpointer data) +{ + struct trigger_alarm_closure *c; + GnomeCalendarPrivate *priv; + CalComponent *comp; + CalClientGetStatus status; + const char *uid; + ObjectAlarms *oa; + GList *l; + + c = data; + priv = c->gcal->priv; + + /* Fetch the object */ + + status = cal_client_get_object (priv->client, c->uid, &comp); + + switch (status) { + case CAL_CLIENT_GET_SUCCESS: + /* Go on */ + break; + case CAL_CLIENT_GET_SYNTAX_ERROR: + case CAL_CLIENT_GET_NOT_FOUND: + g_message ("trigger_alarm_cb(): syntax error in fetched object"); + return; + } + + g_assert (comp != NULL); + + /* Present notification */ + + switch (c->type) { + case CAL_COMPONENT_ALARM_EMAIL: +#if 0 + g_assert (ico->malarm.enabled); + mail_notification (ico->malarm.data, ico->summary, c->occur); +#endif + break; + + case CAL_COMPONENT_ALARM_PROCEDURE: +#if 0 + g_assert (ico->palarm.enabled); + program_notification (ico->palarm.data, FALSE); +#endif + break; + + case CAL_COMPONENT_ALARM_DISPLAY: +#if 0 + g_assert (ico->dalarm.enabled); +#endif + display_notification (trigger, c->occur, comp, c->gcal); + break; + + case CAL_COMPONENT_ALARM_AUDIO: +#if 0 + g_assert (ico->aalarm.enabled); +#endif + audio_notification (trigger, c->occur, comp, c->gcal); + break; + + default: + break; + } + + /* Remove the alarm from the hash table */ + cal_component_get_uid (comp, &uid); + oa = g_hash_table_lookup (priv->alarms, uid); + g_assert (oa != NULL); + + l = g_list_find (oa->alarm_ids, alarm_id); + g_assert (l != NULL); + + oa->alarm_ids = g_list_remove_link (oa->alarm_ids, l); + g_list_free_1 (l); + + if (!oa->alarm_ids) { + g_hash_table_remove (priv->alarms, uid); + g_free (oa->uid); + g_free (oa); + } + + gtk_object_unref (GTK_OBJECT (comp)); +} + +#endif + +#if 0 + +static void +stop_beeping (GtkObject* object, gpointer data) +{ + guint timer_tag, beep_tag; + timer_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "timer_tag")); + beep_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "beep_tag")); + + if (beep_tag > 0) { + gtk_timeout_remove (beep_tag); + gtk_object_set_data (object, "beep_tag", GINT_TO_POINTER (0)); + } + if (timer_tag > 0) { + gtk_timeout_remove (timer_tag); + gtk_object_set_data (object, "timer_tag", GINT_TO_POINTER (0)); + } +} + +static gint +start_beeping (gpointer data) +{ + gdk_beep (); + + return TRUE; +} + +static gint +timeout_beep (gpointer data) +{ + stop_beeping (data, NULL); + return FALSE; +} + +void +calendar_notify (time_t activation_time, CalendarAlarm *which, void *data) +{ + iCalObject *ico = data; + guint beep_tag, timer_tag; + int ret; + gchar* snooze_button = (enable_snooze ? _("Snooze") : NULL); + time_t now, diff; + + if (&ico->aalarm == which){ + time_t app = ico->aalarm.trigger + ico->aalarm.offset; + GtkWidget *w; + char *msg; + + msg = g_strconcat (_("Reminder of your appointment at "), + ctime (&app), "`", + ico->summary, "'", NULL); + + /* Idea: we need Snooze option :-) */ + w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, _("Ok"), snooze_button, NULL); + beep_tag = gtk_timeout_add (1000, start_beeping, NULL); + if (enable_aalarm_timeout) + timer_tag = gtk_timeout_add (audio_alarm_timeout*1000, + timeout_beep, w); + else + timer_tag = 0; + gtk_object_set_data (GTK_OBJECT (w), "timer_tag", + GINT_TO_POINTER (timer_tag)); + gtk_object_set_data (GTK_OBJECT (w), "beep_tag", + GINT_TO_POINTER (beep_tag)); + gtk_widget_ref (w); + gtk_window_set_modal (GTK_WINDOW (w), FALSE); + ret = gnome_dialog_run (GNOME_DIALOG (w)); + switch (ret) { + case 1: + stop_beeping (GTK_OBJECT (w), NULL); + now = time (NULL); + diff = now - which->trigger; + which->trigger = which->trigger + diff + snooze_secs; + which->offset = which->offset - diff - snooze_secs; + alarm_add (which, &calendar_notify, data); + break; + default: + stop_beeping (GTK_OBJECT (w), NULL); + break; + } + + gtk_widget_unref (w); + return; + } + + if (&ico->palarm == which){ + execute (ico->palarm.data, 0); + return; + } + + if (&ico->malarm == which){ + time_t app = ico->malarm.trigger + ico->malarm.offset; + + mail_notify (ico->malarm.data, ico->summary, app); + return; + } + + if (&ico->dalarm == which){ + time_t app = ico->dalarm.trigger + ico->dalarm.offset; + GtkWidget *w; + char *msg; + + if (beep_on_display) + gdk_beep (); + msg = g_strconcat (_("Reminder of your appointment at "), + ctime (&app), "`", + ico->summary, "'", NULL); + w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, + _("Ok"), snooze_button, NULL); + gtk_window_set_modal (GTK_WINDOW (w), FALSE); + ret = gnome_dialog_run (GNOME_DIALOG (w)); + switch (ret) { + case 1: + now = time (NULL); + diff = now - which->trigger; + which->trigger = which->trigger + diff + snooze_secs; + which->offset = which->offset - diff - snooze_secs; + alarm_add (which, &calendar_notify, data); + break; + default: + break; + } + + return; + } +} + +#endif diff --git a/calendar/gui/alarm-notify/alarm-queue.c b/calendar/gui/alarm-notify/alarm-queue.c index 6f0e8e6759..805b29f81d 100644 --- a/calendar/gui/alarm-notify/alarm-queue.c +++ b/calendar/gui/alarm-notify/alarm-queue.c @@ -509,3 +509,409 @@ alarm_notify_remove_client (CalClient *client) g_hash_table_remove (client_alarms_hash, client); } + + + +#if 0 + +/* Sends a mail notification of an alarm trigger */ +static void +mail_notification (char *mail_address, char *text, time_t app_time) +{ + pid_t pid; + int p [2]; + char *command; + + pipe (p); + pid = fork (); + if (pid == 0){ + int dev_null; + + dev_null = open ("/dev/null", O_RDWR); + dup2 (p [0], 0); + dup2 (dev_null, 1); + dup2 (dev_null, 2); + execl ("/usr/lib/sendmail", "/usr/lib/sendmail", + mail_address, NULL); + _exit (127); + } + command = g_strconcat ("To: ", mail_address, "\n", + "Subject: ", _("Reminder of your appointment at "), + ctime (&app_time), "\n\n", text, "\n", NULL); + write (p [1], command, strlen (command)); + close (p [1]); + close (p [0]); + g_free (command); +} + +static int +max_open_files (void) +{ + static int files; + + if (files) + return files; + + files = sysconf (_SC_OPEN_MAX); + if (files != -1) + return files; +#ifdef OPEN_MAX + return files = OPEN_MAX; +#else + return files = 256; +#endif +} + +/* Executes a program as a notification of an alarm trigger */ +static void +program_notification (char *command, int close_standard) +{ + struct sigaction ignore, save_intr, save_quit; + int status = 0, i; + pid_t pid; + + ignore.sa_handler = SIG_IGN; + sigemptyset (&ignore.sa_mask); + ignore.sa_flags = 0; + + sigaction (SIGINT, &ignore, &save_intr); + sigaction (SIGQUIT, &ignore, &save_quit); + + if ((pid = fork ()) < 0){ + fprintf (stderr, "\n\nfork () = -1\n"); + return; + } + if (pid == 0){ + pid = fork (); + if (pid == 0){ + const int top = max_open_files (); + sigaction (SIGINT, &save_intr, NULL); + sigaction (SIGQUIT, &save_quit, NULL); + + for (i = (close_standard ? 0 : 3); i < top; i++) + close (i); + + /* FIXME: As an excercise to the reader, copy the + * code from mc to setup shell properly instead of + * /bin/sh. Yes, this comment is larger than a cut and paste. + */ + execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0); + + _exit (127); + } else { + _exit (127); + } + } + wait (&status); + sigaction (SIGINT, &save_intr, NULL); + sigaction (SIGQUIT, &save_quit, NULL); +} + +/* Queues a snooze alarm */ +static void +snooze (GnomeCalendar *gcal, CalComponent *comp, time_t occur, int snooze_mins, gboolean audio) +{ + time_t now, trigger; + struct tm tm; + CalAlarmInstance ai; + + now = time (NULL); + tm = *localtime (&now); + tm.tm_min += snooze_mins; + + trigger = mktime (&tm); + if (trigger == -1) { + g_message ("snooze(): produced invalid time_t; not queueing alarm!"); + return; + } + +#if 0 + cal_component_get_uid (comp, &ai.uid); + ai.type = audio ? ALARM_AUDIO : ALARM_DISPLAY; +#endif + ai.trigger = trigger; + ai.occur = occur; + + setup_alarm (gcal, &ai); +} + +struct alarm_notify_closure { + GnomeCalendar *gcal; + CalComponent *comp; + time_t occur; +}; + +/* Callback used for the result of the alarm notification dialog */ +static void +display_notification_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) +{ + struct alarm_notify_closure *c; + + c = data; + + switch (result) { + case ALARM_NOTIFY_CLOSE: + break; + + case ALARM_NOTIFY_SNOOZE: + snooze (c->gcal, c->comp, c->occur, snooze_mins, FALSE); + break; + + case ALARM_NOTIFY_EDIT: + gnome_calendar_edit_object (c->gcal, c->comp); + break; + + default: + g_assert_not_reached (); + } + + gtk_object_unref (GTK_OBJECT (c->comp)); + g_free (c); +} + +/* Present a display notification of an alarm trigger */ +static void +display_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal) +{ + gboolean result; + struct alarm_notify_closure *c; + + gtk_object_ref (GTK_OBJECT (comp)); + + c = g_new (struct alarm_notify_closure, 1); + c->gcal = gcal; + c->comp = comp; + c->occur = occur; + + result = alarm_notify_dialog (trigger, occur, comp, display_notification_cb, c); + if (!result) { + g_message ("display_notification(): could not display the alarm notification dialog"); + g_free (c); + gtk_object_unref (GTK_OBJECT (comp)); + } +} + +/* Present an audible notification of an alarm trigger */ +static void +audio_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal) +{ + g_message ("AUDIO NOTIFICATION!"); + /* FIXME */ +} + +/* Callback function used when an alarm is triggered */ +static void +trigger_alarm_cb (gpointer alarm_id, time_t trigger, gpointer data) +{ + struct trigger_alarm_closure *c; + GnomeCalendarPrivate *priv; + CalComponent *comp; + CalClientGetStatus status; + const char *uid; + ObjectAlarms *oa; + GList *l; + + c = data; + priv = c->gcal->priv; + + /* Fetch the object */ + + status = cal_client_get_object (priv->client, c->uid, &comp); + + switch (status) { + case CAL_CLIENT_GET_SUCCESS: + /* Go on */ + break; + case CAL_CLIENT_GET_SYNTAX_ERROR: + case CAL_CLIENT_GET_NOT_FOUND: + g_message ("trigger_alarm_cb(): syntax error in fetched object"); + return; + } + + g_assert (comp != NULL); + + /* Present notification */ + + switch (c->type) { + case CAL_COMPONENT_ALARM_EMAIL: +#if 0 + g_assert (ico->malarm.enabled); + mail_notification (ico->malarm.data, ico->summary, c->occur); +#endif + break; + + case CAL_COMPONENT_ALARM_PROCEDURE: +#if 0 + g_assert (ico->palarm.enabled); + program_notification (ico->palarm.data, FALSE); +#endif + break; + + case CAL_COMPONENT_ALARM_DISPLAY: +#if 0 + g_assert (ico->dalarm.enabled); +#endif + display_notification (trigger, c->occur, comp, c->gcal); + break; + + case CAL_COMPONENT_ALARM_AUDIO: +#if 0 + g_assert (ico->aalarm.enabled); +#endif + audio_notification (trigger, c->occur, comp, c->gcal); + break; + + default: + break; + } + + /* Remove the alarm from the hash table */ + cal_component_get_uid (comp, &uid); + oa = g_hash_table_lookup (priv->alarms, uid); + g_assert (oa != NULL); + + l = g_list_find (oa->alarm_ids, alarm_id); + g_assert (l != NULL); + + oa->alarm_ids = g_list_remove_link (oa->alarm_ids, l); + g_list_free_1 (l); + + if (!oa->alarm_ids) { + g_hash_table_remove (priv->alarms, uid); + g_free (oa->uid); + g_free (oa); + } + + gtk_object_unref (GTK_OBJECT (comp)); +} + +#endif + +#if 0 + +static void +stop_beeping (GtkObject* object, gpointer data) +{ + guint timer_tag, beep_tag; + timer_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "timer_tag")); + beep_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "beep_tag")); + + if (beep_tag > 0) { + gtk_timeout_remove (beep_tag); + gtk_object_set_data (object, "beep_tag", GINT_TO_POINTER (0)); + } + if (timer_tag > 0) { + gtk_timeout_remove (timer_tag); + gtk_object_set_data (object, "timer_tag", GINT_TO_POINTER (0)); + } +} + +static gint +start_beeping (gpointer data) +{ + gdk_beep (); + + return TRUE; +} + +static gint +timeout_beep (gpointer data) +{ + stop_beeping (data, NULL); + return FALSE; +} + +void +calendar_notify (time_t activation_time, CalendarAlarm *which, void *data) +{ + iCalObject *ico = data; + guint beep_tag, timer_tag; + int ret; + gchar* snooze_button = (enable_snooze ? _("Snooze") : NULL); + time_t now, diff; + + if (&ico->aalarm == which){ + time_t app = ico->aalarm.trigger + ico->aalarm.offset; + GtkWidget *w; + char *msg; + + msg = g_strconcat (_("Reminder of your appointment at "), + ctime (&app), "`", + ico->summary, "'", NULL); + + /* Idea: we need Snooze option :-) */ + w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, _("Ok"), snooze_button, NULL); + beep_tag = gtk_timeout_add (1000, start_beeping, NULL); + if (enable_aalarm_timeout) + timer_tag = gtk_timeout_add (audio_alarm_timeout*1000, + timeout_beep, w); + else + timer_tag = 0; + gtk_object_set_data (GTK_OBJECT (w), "timer_tag", + GINT_TO_POINTER (timer_tag)); + gtk_object_set_data (GTK_OBJECT (w), "beep_tag", + GINT_TO_POINTER (beep_tag)); + gtk_widget_ref (w); + gtk_window_set_modal (GTK_WINDOW (w), FALSE); + ret = gnome_dialog_run (GNOME_DIALOG (w)); + switch (ret) { + case 1: + stop_beeping (GTK_OBJECT (w), NULL); + now = time (NULL); + diff = now - which->trigger; + which->trigger = which->trigger + diff + snooze_secs; + which->offset = which->offset - diff - snooze_secs; + alarm_add (which, &calendar_notify, data); + break; + default: + stop_beeping (GTK_OBJECT (w), NULL); + break; + } + + gtk_widget_unref (w); + return; + } + + if (&ico->palarm == which){ + execute (ico->palarm.data, 0); + return; + } + + if (&ico->malarm == which){ + time_t app = ico->malarm.trigger + ico->malarm.offset; + + mail_notify (ico->malarm.data, ico->summary, app); + return; + } + + if (&ico->dalarm == which){ + time_t app = ico->dalarm.trigger + ico->dalarm.offset; + GtkWidget *w; + char *msg; + + if (beep_on_display) + gdk_beep (); + msg = g_strconcat (_("Reminder of your appointment at "), + ctime (&app), "`", + ico->summary, "'", NULL); + w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, + _("Ok"), snooze_button, NULL); + gtk_window_set_modal (GTK_WINDOW (w), FALSE); + ret = gnome_dialog_run (GNOME_DIALOG (w)); + switch (ret) { + case 1: + now = time (NULL); + diff = now - which->trigger; + which->trigger = which->trigger + diff + snooze_secs; + which->offset = which->offset - diff - snooze_secs; + alarm_add (which, &calendar_notify, data); + break; + default: + break; + } + + return; + } +} + +#endif diff --git a/calendar/gui/calendar-commands.c b/calendar/gui/calendar-commands.c index 94fc3aa57d..7b6c909f76 100644 --- a/calendar/gui/calendar-commands.c +++ b/calendar/gui/calendar-commands.c @@ -20,8 +20,9 @@ #include <libgnorba/gnorba.h> #include <bonobo.h> #include <cal-util/timeutil.h> -#include "gnome-cal.h" #include "calendar-commands.h" +#include "gnome-cal.h" +#include "goto.h" #include "print.h" #include "dialogs/cal-prefs-dialog.h" @@ -34,65 +35,9 @@ #endif -/* The username, used to set the `owner' field of the event */ -char *user_name; - -/* The full user name from the Gecos field */ -char *full_name; - -/* a gnome-config string prefix that can be used to access the calendar config info */ -char *calendar_settings; - -/* Day begin, day end parameters */ -int day_begin, day_end; - -/* Whether weeks starts on Sunday or Monday */ -int week_starts_on_monday; - -/* If AM/PM indicators should be used. This may not be supported by the new - views. */ -int am_pm_flag = 0; - -/* The array of color properties -- keep in sync with the enumeration defined in main.h. The color - * values specified here are the defaults for the program. - */ -struct color_prop color_props[] = { - { 0x3e72, 0x35ec, 0x8ba2, N_("Outline:"), "/calendar/Colors/outline" }, - { 0xffff, 0xffff, 0xffff, N_("Headings:"), "/calendar/Colors/headings" }, - { 0xf26c, 0xecec, 0xbbe7, N_("Empty days:"), "/calendar/Colors/empty_bg" }, - { 0xfc1e, 0xf87f, 0x5f80, N_("Appointments:"), "/calendar/Colors/mark_bg" }, - { 0xd364, 0xc6b7, 0x7969, N_("Highlighted day:"), "/calendar/Colors/prelight_bg" }, - { 0x01f0, 0x01f0, 0x01f0, N_("Day numbers:"), "/calendar/Colors/day_fg" }, - { 0x0000, 0x0000, 0xffff, N_("Current day's number:"), "/calendar/Colors/current_fg" }, - { 0xbbbb, 0xbbbb, 0x0000, N_("To-Do item that is not yet due:"), "/calendar/Colors/todo_not_yet" }, - { 0xdddd, 0xbbbb, 0x0000, N_("To-Do item that is due today:"), "/calendar/Colors/todo_today" }, - { 0xbbbb, 0xdddd, 0x0000, N_("To-Do item that is overdue:"), "/calendar/Colors/todo_overdue" } -}; - /* A list of all of the calendars started */ static GList *all_calendars = NULL; -/* If set, beep on display alarms */ -gboolean beep_on_display = 0; - -/* If true, timeout the beeper on audio alarms */ - -gboolean enable_aalarm_timeout = 0; -guint audio_alarm_timeout = 0; -const guint MAX_AALARM_TIMEOUT = 3600; -const guint MAX_SNOOZE_SECS = 3600; -gboolean enable_snooze = 0; -guint snooze_secs = 60; - -#if 0 -CalendarAlarm alarm_defaults[4] = { - { ALARM_MAIL, 0, 15, ALARM_MINUTES }, - { ALARM_PROGRAM, 0, 15, ALARM_MINUTES }, - { ALARM_DISPLAY, 0, 15, ALARM_MINUTES }, - { ALARM_AUDIO, 0, 15, ALARM_MINUTES } -}; -#endif - /* We have one global preferences dialog. */ static CalPrefsDialog *preferences_dialog = NULL; @@ -103,72 +48,6 @@ static void set_pixmap (BonoboUIComponent *uic, char **xpm_data); - -static void -init_username (void) -{ - user_name = g_strdup(g_get_user_name()); - full_name = g_strdup(g_get_real_name()); -} - -static int -range_check_hour (int hour) -{ - if (hour < 0) - hour = 0; - else if (hour >= 24) - hour = 23; - - return hour; -} - -#if 0 -static void -init_default_alarms (void) -{ - int i; - gboolean def; - - alarm_defaults [ALARM_DISPLAY].type = ALARM_DISPLAY; - alarm_defaults [ALARM_AUDIO].type = ALARM_AUDIO; - alarm_defaults [ALARM_PROGRAM].type = ALARM_PROGRAM; - alarm_defaults [ALARM_MAIL].type = ALARM_MAIL; - - for (i = 0; i < 4; i++) { - switch (alarm_defaults [i].type) { - case ALARM_DISPLAY: - gnome_config_push_prefix ("/calendar/alarms/def_disp_"); - break; - case ALARM_AUDIO: - gnome_config_push_prefix ("/calendar/alarms/def_audio_"); - break; - case ALARM_PROGRAM: - gnome_config_push_prefix ("/calendar/alarms/def_prog_"); - break; - case ALARM_MAIL: - gnome_config_push_prefix ("/calendar/alarms/def_mail_"); - break; - } - - alarm_defaults[i].enabled = gnome_config_get_int ("enabled=0"); - if (alarm_defaults[i].type != ALARM_MAIL) { - alarm_defaults[i].count = gnome_config_get_int ("count=15"); - alarm_defaults[i].units = gnome_config_get_int ("units=0"); - } else { - alarm_defaults[i].count = gnome_config_get_int ("count=1"); - alarm_defaults[i].count = gnome_config_get_int ("count=2"); - } - - alarm_defaults[i].data = gnome_config_get_string_with_default ("data=", - &def); - if (def) - alarm_defaults[i].data = NULL; - - gnome_config_pop_prefix (); - } -} -#endif - /* Callback for the new appointment command */ static void new_appointment_cb (BonoboUIComponent *uih, void *user_data, const char *path) @@ -317,34 +196,10 @@ show_month_view_clicked (BonoboUIComponent *uih, void *user_data, const char *pa static void new_calendar_cmd (BonoboUIComponent *uih, void *user_data, const char *path) { - new_calendar (full_name); + new_calendar (); } static void -close_cmd (BonoboUIComponent *uih, void *user_data, const char *path) -{ - GnomeCalendar *gcal = GNOME_CALENDAR (user_data); - all_calendars = g_list_remove (all_calendars, gcal); - - gtk_widget_destroy (GTK_WIDGET (gcal)); - - if (all_calendars == NULL) - gtk_main_quit (); -} - - -void -quit_cmd (BonoboUIComponent *uih, void *user_data, const char *path) -{ - while (all_calendars){ - GnomeCalendar *cal = GNOME_CALENDAR (all_calendars->data); - - close_cmd (uih, cal, path); - } -} - - -static void open_ok (GtkWidget *widget, GtkFileSelection *fs) { GtkWidget *error_dialog; @@ -545,7 +400,7 @@ calendar_control_deactivate (BonoboControl *control) } GnomeCalendar * -new_calendar (char *full_name) +new_calendar (void) { GtkWidget *gcal; @@ -558,67 +413,11 @@ new_calendar (char *full_name) } -void calendar_set_uri (GnomeCalendar *gcal, char *calendar_file) +void +calendar_set_uri (GnomeCalendar *gcal, char *calendar_file) { g_return_if_fail (gcal); g_return_if_fail (calendar_file); - gnome_calendar_open (gcal, - calendar_file, - CALENDAR_OPEN_OR_CREATE); -} - - - - - -/* - * Initializes the calendar internal variables, loads defaults - */ -void -init_calendar (void) -{ - int i; - char *cspec, *color; - char *str; - - init_username (); - /*user_calendar_file = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/user-cal.vcf");*/ - - gnome_config_push_prefix (calendar_settings); - - /* Read calendar settings */ - - day_begin = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day start=8")); - day_end = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day end=17")); - am_pm_flag = gnome_config_get_bool ("/calendar/Calendar/AM PM flag=0"); - week_starts_on_monday = gnome_config_get_bool ("/calendar/Calendar/Week starts on Monday=0"); - - if (day_end < day_begin) { - day_begin = 8; - day_end = 17; - } - - /* read alarm settings */ - beep_on_display = gnome_config_get_bool ("/calendar/alarms/beep_on_display=FALSE"); - enable_aalarm_timeout = gnome_config_get_bool ("/calendar/alarms/enable_audio_timeout=FALSE"); - audio_alarm_timeout = gnome_config_get_int ("/calendar/alarms/audio_alarm_timeout=60"); - if (audio_alarm_timeout < 1) - audio_alarm_timeout = 1; - if (audio_alarm_timeout > MAX_AALARM_TIMEOUT) - audio_alarm_timeout = MAX_AALARM_TIMEOUT; - enable_snooze = gnome_config_get_bool ("/calendar/alarms/enable_snooze=FALSE"); - snooze_secs = gnome_config_get_int ("/calendar/alarms/snooze_secs=300"); - if (snooze_secs < 1) - snooze_secs = 1; - if (snooze_secs > MAX_SNOOZE_SECS) - snooze_secs = MAX_SNOOZE_SECS; - -#if 0 - init_default_alarms (); -#endif - - /* Done */ - - gnome_config_pop_prefix (); + gnome_calendar_open (gcal, calendar_file, CALENDAR_OPEN_OR_CREATE); } diff --git a/calendar/gui/calendar-commands.h b/calendar/gui/calendar-commands.h index 5189e2878f..81e1b33408 100644 --- a/calendar/gui/calendar-commands.h +++ b/calendar/gui/calendar-commands.h @@ -4,91 +4,15 @@ #include <bonobo/bonobo-control.h> #include "gnome-cal.h" -/* This enum and the following array define the color preferences */ - -typedef enum { - COLOR_PROP_OUTLINE_COLOR, /* Color of calendar outline */ - COLOR_PROP_HEADING_COLOR, /* Color for headings */ - COLOR_PROP_EMPTY_DAY_BG, /* Background color for empty days */ - COLOR_PROP_MARK_DAY_BG, /* Background color for days with appointments */ - COLOR_PROP_PRELIGHT_DAY_BG, /* Background color for prelighted day */ - COLOR_PROP_DAY_FG, /* Color for day numbers */ - COLOR_PROP_CURRENT_DAY_FG, /* Color for current day's number */ - COLOR_PROP_TODO_NOT_DUE_YET, /* Color for Todo items not yet due */ - COLOR_PROP_TODO_DUE_TODAY, /* Color for Todo items due today */ - COLOR_PROP_TODO_OVERDUE, /* Color for Todo items that are overdue */ - COLOR_PROP_LAST /* Number of color properties */ -} ColorProp; - -struct color_prop { - int r; /* Values are in [0, 65535] */ - int g; - int b; - char *label; /* Label for properties dialog */ - char *key; /* Key for gnome_config */ -}; - -extern struct color_prop color_props[]; - - -#define COOKIE_USER_HOME_DIR ((char *) -1) - - -/* Calendar preferences */ - -extern int day_begin, day_end; -extern char *user_name; -extern int am_pm_flag; -extern int week_starts_on_monday; - -/* alarm stuff */ -#if 0 -extern CalendarAlarm alarm_defaults[4]; -#endif -extern gboolean beep_on_display; -extern gboolean enable_aalarm_timeout; -extern guint audio_alarm_timeout; -extern const guint MAX_AALARM_TIMEOUT; -extern gboolean enable_snooze; -extern guint snooze_secs; -extern const guint MAX_SNOOZE_SECS; - - - /* This tells all the calendars to reload the config settings. */ void update_all_config_settings (void); -/* Returns a pointer to a statically-allocated string with a representation of the specified color. - * Values must be in [0, 65535]. - */ -char *build_color_spec (int r, int g, int b); - -/* Parses a color specification of the form "#%04x%04x%04x" and returns the color components. */ -void parse_color_spec (char *spec, int *r, int *g, int *b); - -/* Calls build_color_spec() for the color in the specified property number */ -char *color_spec_from_prop (ColorProp propnum); - -GnomeCalendar *new_calendar (char *full_name); +GnomeCalendar *new_calendar (void); void calendar_set_uri (GnomeCalendar *gcal, char *calendar_file); - -/*----------------------------------------------------------------------*/ -/* FIXME -- where should this stuff go? */ -/*----------------------------------------------------------------------*/ - -void init_calendar (void); - void calendar_control_activate (BonoboControl *control, GnomeCalendar *cal); void calendar_control_deactivate (BonoboControl *control); -void quit_cmd (BonoboUIComponent *uih, void *user_data, const char *path); - -/*extern char *user_calendar_file;*/ -extern char *user_name; -extern char *full_name; -extern int debug_alarms; - #endif /* CALENDAR_COMMANDS_H */ diff --git a/calendar/gui/calendar-model.c b/calendar/gui/calendar-model.c index 67904b451a..55f265390c 100644 --- a/calendar/gui/calendar-model.c +++ b/calendar/gui/calendar-model.c @@ -25,7 +25,6 @@ #include <config.h> #include <math.h> #include <ctype.h> -#include <time.h> #include <gnome.h> #include <cal-util/timeutil.h> #include "calendar-model.h" @@ -34,9 +33,11 @@ /* We need this for strptime. */ #define _XOPEN_SOURCE 500 #define __USE_XOPEN +#include <time.h> #include <sys/time.h> #undef _XOPEN_SOURCE #undef __USE_XOPEN + /* Private part of the ECalendarModel structure */ diff --git a/calendar/gui/control-factory.c b/calendar/gui/control-factory.c index ea68675e43..ddec91be71 100644 --- a/calendar/gui/control-factory.c +++ b/calendar/gui/control-factory.c @@ -164,7 +164,7 @@ control_factory_new_control (void) BonoboControl *control; GnomeCalendar *gcal; - gcal = new_calendar (full_name); + gcal = new_calendar (); gtk_widget_show (GTK_WIDGET (gcal)); control = bonobo_control_new (GTK_WIDGET (gcal)); diff --git a/calendar/gui/event-editor.c b/calendar/gui/event-editor.c index 726f29e67d..6ddfd859ed 100644 --- a/calendar/gui/event-editor.c +++ b/calendar/gui/event-editor.c @@ -172,10 +172,6 @@ static void event_editor_destroy (GtkObject *object); static GtkObjectClass *parent_class; -extern int day_begin, day_end; -extern char *user_name; -extern int am_pm_flag; - static void append_exception (EventEditor *ee, time_t t); static void check_all_day (EventEditor *ee); diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 77dc0a71dc..808f5d9ee8 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -106,12 +106,6 @@ struct _GnomeCalendarPrivate { /* The signal handler id for our GtkCalendar "day_selected" handler. */ guint day_selected_id; - /* Alarm ID for the midnight refresh function */ - gpointer midnight_alarm_refresh_id; - - /* UID->ObjectAlarms hash */ - GHashTable *alarms; - /* Whether we are being destroyed and should not mess with the object * editor hash table. */ @@ -120,28 +114,6 @@ struct _GnomeCalendarPrivate { -/* A queued alarm for a component */ -typedef struct { - /* Alarm ID from alarm.h */ - gpointer alarm_id; - - /* Trigger instance this queued alarm refers to */ - CalAlarmInstance *instance; -} QueuedAlarm; - -/* An entry in the UID->alarms hash table */ -typedef struct { - /* The actual component we keep around; its UID *is* the key in the hash - * table. - */ - CalComponentAlarms *alarms; - - /* List of QueuedAlarm structures */ - GList *queued_alarms; -} ObjectAlarms; - - - static void gnome_calendar_class_init (GnomeCalendarClass *class); static void gnome_calendar_init (GnomeCalendar *gcal); static void gnome_calendar_destroy (GtkObject *object); @@ -172,9 +144,6 @@ static gboolean gnome_calendar_get_days_shown (GnomeCalendar *gcal, static GtkVBoxClass *parent_class; -#if 0 -static void setup_alarm (GnomeCalendar *cal, CalAlarmInstance *ai); -#endif @@ -322,7 +291,6 @@ gnome_calendar_init (GnomeCalendar *gcal) priv->load_state = LOAD_STATE_NOT_LOADED; priv->object_editor_hash = g_hash_table_new (g_str_hash, g_str_equal); - priv->alarms = g_hash_table_new (g_str_hash, g_str_equal); priv->current_view_type = VIEW_NOT_SET; priv->range_selected = FALSE; @@ -333,39 +301,6 @@ gnome_calendar_init (GnomeCalendar *gcal) priv->selection_end_time = time_add_day (priv->selection_start_time, 1); } -/* Used from g_hash_table_foreach(); frees an object alarms entry */ -static void -free_object_alarms (gpointer key, gpointer value, gpointer data) -{ - ObjectAlarms *oa; - GList *l; - - oa = value; - - g_assert (oa->alarms != NULL); - cal_component_alarms_free (oa->alarms); - oa->alarms = NULL; - - g_assert (oa->queued_alarms != NULL); - - for (l = oa->queued_alarms; l; l = l->next) { - QueuedAlarm *qa; - - qa = l->data; - - /* The instance structures were already freed by the call to - * cal_component_alarms_free(). - */ - - g_free (qa); - } - - g_list_free (oa->queued_alarms); - oa->queued_alarms = NULL; - - g_free (oa); -} - /* Used from g_hash_table_foreach(); frees an UID string */ static void destroy_editor_cb (gpointer key, gpointer value, gpointer data) @@ -402,17 +337,11 @@ gnome_calendar_destroy (GtkObject *object) } if (priv->client) { - if (cal_client_is_loaded (priv->client)) - alarm_notify_remove_client (priv->client); - + alarm_notify_remove_client (priv->client); gtk_object_unref (GTK_OBJECT (priv->client)); priv->client = NULL; } - g_hash_table_foreach (priv->alarms, free_object_alarms, NULL); - g_hash_table_destroy (priv->alarms); - priv->alarms = NULL; - priv->in_destroy = TRUE; g_hash_table_foreach (priv->object_editor_hash, destroy_editor_cb, NULL); g_hash_table_destroy (priv->object_editor_hash); @@ -725,281 +654,6 @@ gnome_calendar_set_pane_positions (GnomeCalendar *gcal) gtk_widget_set_usize (GTK_WIDGET (priv->date_navigator), -2, top_pane_height + 1); } -#if 0 - -/* Sends a mail notification of an alarm trigger */ -static void -mail_notification (char *mail_address, char *text, time_t app_time) -{ - pid_t pid; - int p [2]; - char *command; - - pipe (p); - pid = fork (); - if (pid == 0){ - int dev_null; - - dev_null = open ("/dev/null", O_RDWR); - dup2 (p [0], 0); - dup2 (dev_null, 1); - dup2 (dev_null, 2); - execl ("/usr/lib/sendmail", "/usr/lib/sendmail", - mail_address, NULL); - _exit (127); - } - command = g_strconcat ("To: ", mail_address, "\n", - "Subject: ", _("Reminder of your appointment at "), - ctime (&app_time), "\n\n", text, "\n", NULL); - write (p [1], command, strlen (command)); - close (p [1]); - close (p [0]); - g_free (command); -} - -static int -max_open_files (void) -{ - static int files; - - if (files) - return files; - - files = sysconf (_SC_OPEN_MAX); - if (files != -1) - return files; -#ifdef OPEN_MAX - return files = OPEN_MAX; -#else - return files = 256; -#endif -} - -/* Executes a program as a notification of an alarm trigger */ -static void -program_notification (char *command, int close_standard) -{ - struct sigaction ignore, save_intr, save_quit; - int status = 0, i; - pid_t pid; - - ignore.sa_handler = SIG_IGN; - sigemptyset (&ignore.sa_mask); - ignore.sa_flags = 0; - - sigaction (SIGINT, &ignore, &save_intr); - sigaction (SIGQUIT, &ignore, &save_quit); - - if ((pid = fork ()) < 0){ - fprintf (stderr, "\n\nfork () = -1\n"); - return; - } - if (pid == 0){ - pid = fork (); - if (pid == 0){ - const int top = max_open_files (); - sigaction (SIGINT, &save_intr, NULL); - sigaction (SIGQUIT, &save_quit, NULL); - - for (i = (close_standard ? 0 : 3); i < top; i++) - close (i); - - /* FIXME: As an excercise to the reader, copy the - * code from mc to setup shell properly instead of - * /bin/sh. Yes, this comment is larger than a cut and paste. - */ - execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0); - - _exit (127); - } else { - _exit (127); - } - } - wait (&status); - sigaction (SIGINT, &save_intr, NULL); - sigaction (SIGQUIT, &save_quit, NULL); -} - -/* Queues a snooze alarm */ -static void -snooze (GnomeCalendar *gcal, CalComponent *comp, time_t occur, int snooze_mins, gboolean audio) -{ - time_t now, trigger; - struct tm tm; - CalAlarmInstance ai; - - now = time (NULL); - tm = *localtime (&now); - tm.tm_min += snooze_mins; - - trigger = mktime (&tm); - if (trigger == -1) { - g_message ("snooze(): produced invalid time_t; not queueing alarm!"); - return; - } - -#if 0 - cal_component_get_uid (comp, &ai.uid); - ai.type = audio ? ALARM_AUDIO : ALARM_DISPLAY; -#endif - ai.trigger = trigger; - ai.occur = occur; - - setup_alarm (gcal, &ai); -} - -struct alarm_notify_closure { - GnomeCalendar *gcal; - CalComponent *comp; - time_t occur; -}; - -/* Callback used for the result of the alarm notification dialog */ -static void -display_notification_cb (AlarmNotifyResult result, int snooze_mins, gpointer data) -{ - struct alarm_notify_closure *c; - - c = data; - - switch (result) { - case ALARM_NOTIFY_CLOSE: - break; - - case ALARM_NOTIFY_SNOOZE: - snooze (c->gcal, c->comp, c->occur, snooze_mins, FALSE); - break; - - case ALARM_NOTIFY_EDIT: - gnome_calendar_edit_object (c->gcal, c->comp); - break; - - default: - g_assert_not_reached (); - } - - gtk_object_unref (GTK_OBJECT (c->comp)); - g_free (c); -} - -/* Present a display notification of an alarm trigger */ -static void -display_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal) -{ - gboolean result; - struct alarm_notify_closure *c; - - gtk_object_ref (GTK_OBJECT (comp)); - - c = g_new (struct alarm_notify_closure, 1); - c->gcal = gcal; - c->comp = comp; - c->occur = occur; - - result = alarm_notify_dialog (trigger, occur, comp, display_notification_cb, c); - if (!result) { - g_message ("display_notification(): could not display the alarm notification dialog"); - g_free (c); - gtk_object_unref (GTK_OBJECT (comp)); - } -} - -/* Present an audible notification of an alarm trigger */ -static void -audio_notification (time_t trigger, time_t occur, CalComponent *comp, GnomeCalendar *gcal) -{ - g_message ("AUDIO NOTIFICATION!"); - /* FIXME */ -} - -/* Callback function used when an alarm is triggered */ -static void -trigger_alarm_cb (gpointer alarm_id, time_t trigger, gpointer data) -{ - struct trigger_alarm_closure *c; - GnomeCalendarPrivate *priv; - CalComponent *comp; - CalClientGetStatus status; - const char *uid; - ObjectAlarms *oa; - GList *l; - - c = data; - priv = c->gcal->priv; - - /* Fetch the object */ - - status = cal_client_get_object (priv->client, c->uid, &comp); - - switch (status) { - case CAL_CLIENT_GET_SUCCESS: - /* Go on */ - break; - case CAL_CLIENT_GET_SYNTAX_ERROR: - case CAL_CLIENT_GET_NOT_FOUND: - g_message ("trigger_alarm_cb(): syntax error in fetched object"); - return; - } - - g_assert (comp != NULL); - - /* Present notification */ - - switch (c->type) { - case CAL_COMPONENT_ALARM_EMAIL: -#if 0 - g_assert (ico->malarm.enabled); - mail_notification (ico->malarm.data, ico->summary, c->occur); -#endif - break; - - case CAL_COMPONENT_ALARM_PROCEDURE: -#if 0 - g_assert (ico->palarm.enabled); - program_notification (ico->palarm.data, FALSE); -#endif - break; - - case CAL_COMPONENT_ALARM_DISPLAY: -#if 0 - g_assert (ico->dalarm.enabled); -#endif - display_notification (trigger, c->occur, comp, c->gcal); - break; - - case CAL_COMPONENT_ALARM_AUDIO: -#if 0 - g_assert (ico->aalarm.enabled); -#endif - audio_notification (trigger, c->occur, comp, c->gcal); - break; - - default: - break; - } - - /* Remove the alarm from the hash table */ - cal_component_get_uid (comp, &uid); - oa = g_hash_table_lookup (priv->alarms, uid); - g_assert (oa != NULL); - - l = g_list_find (oa->alarm_ids, alarm_id); - g_assert (l != NULL); - - oa->alarm_ids = g_list_remove_link (oa->alarm_ids, l); - g_list_free_1 (l); - - if (!oa->alarm_ids) { - g_hash_table_remove (priv->alarms, uid); - g_free (oa->uid); - g_free (oa); - } - - gtk_object_unref (GTK_OBJECT (comp)); -} - -#endif - /* Loads the initial data into the calendar; this should be called right after * the cal_loaded signal from the client is invoked. */ @@ -1290,136 +944,6 @@ gnome_calendar_open (GnomeCalendar *gcal, char *file, GnomeCalendarOpenMode gcom return TRUE; } -#if 0 - -static void -stop_beeping (GtkObject* object, gpointer data) -{ - guint timer_tag, beep_tag; - timer_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "timer_tag")); - beep_tag = GPOINTER_TO_INT (gtk_object_get_data (object, "beep_tag")); - - if (beep_tag > 0) { - gtk_timeout_remove (beep_tag); - gtk_object_set_data (object, "beep_tag", GINT_TO_POINTER (0)); - } - if (timer_tag > 0) { - gtk_timeout_remove (timer_tag); - gtk_object_set_data (object, "timer_tag", GINT_TO_POINTER (0)); - } -} - -static gint -start_beeping (gpointer data) -{ - gdk_beep (); - - return TRUE; -} - -static gint -timeout_beep (gpointer data) -{ - stop_beeping (data, NULL); - return FALSE; -} - -void -calendar_notify (time_t activation_time, CalendarAlarm *which, void *data) -{ - iCalObject *ico = data; - guint beep_tag, timer_tag; - int ret; - gchar* snooze_button = (enable_snooze ? _("Snooze") : NULL); - time_t now, diff; - - if (&ico->aalarm == which){ - time_t app = ico->aalarm.trigger + ico->aalarm.offset; - GtkWidget *w; - char *msg; - - msg = g_strconcat (_("Reminder of your appointment at "), - ctime (&app), "`", - ico->summary, "'", NULL); - - /* Idea: we need Snooze option :-) */ - w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, _("Ok"), snooze_button, NULL); - beep_tag = gtk_timeout_add (1000, start_beeping, NULL); - if (enable_aalarm_timeout) - timer_tag = gtk_timeout_add (audio_alarm_timeout*1000, - timeout_beep, w); - else - timer_tag = 0; - gtk_object_set_data (GTK_OBJECT (w), "timer_tag", - GINT_TO_POINTER (timer_tag)); - gtk_object_set_data (GTK_OBJECT (w), "beep_tag", - GINT_TO_POINTER (beep_tag)); - gtk_widget_ref (w); - gtk_window_set_modal (GTK_WINDOW (w), FALSE); - ret = gnome_dialog_run (GNOME_DIALOG (w)); - switch (ret) { - case 1: - stop_beeping (GTK_OBJECT (w), NULL); - now = time (NULL); - diff = now - which->trigger; - which->trigger = which->trigger + diff + snooze_secs; - which->offset = which->offset - diff - snooze_secs; - alarm_add (which, &calendar_notify, data); - break; - default: - stop_beeping (GTK_OBJECT (w), NULL); - break; - } - - gtk_widget_unref (w); - return; - } - - if (&ico->palarm == which){ - execute (ico->palarm.data, 0); - return; - } - - if (&ico->malarm == which){ - time_t app = ico->malarm.trigger + ico->malarm.offset; - - mail_notify (ico->malarm.data, ico->summary, app); - return; - } - - if (&ico->dalarm == which){ - time_t app = ico->dalarm.trigger + ico->dalarm.offset; - GtkWidget *w; - char *msg; - - if (beep_on_display) - gdk_beep (); - msg = g_strconcat (_("Reminder of your appointment at "), - ctime (&app), "`", - ico->summary, "'", NULL); - w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, - _("Ok"), snooze_button, NULL); - gtk_window_set_modal (GTK_WINDOW (w), FALSE); - ret = gnome_dialog_run (GNOME_DIALOG (w)); - switch (ret) { - case 1: - now = time (NULL); - diff = now - which->trigger; - which->trigger = which->trigger + diff + snooze_secs; - which->offset = which->offset - diff - snooze_secs; - alarm_add (which, &calendar_notify, data); - break; - default: - break; - } - - return; - } -} - -#endif - - /* Tells the calendar to reload all config settings. If initializing is TRUE it sets the pane positions as well. (We don't want to reset the pane positions after the user clicks 'Apply' in the diff --git a/calendar/gui/main.c b/calendar/gui/main.c index 183d7bfd90..53f833f70f 100644 --- a/calendar/gui/main.c +++ b/calendar/gui/main.c @@ -67,8 +67,6 @@ main (int argc, char **argv) alarm_notify_init (); e_cursors_init (); - init_calendar (); - #if 0 //g_log_set_always_fatal ((GLogLevelFlags) 0xFFFF); g_log_set_always_fatal (G_LOG_LEVEL_ERROR | diff --git a/calendar/gui/print.c b/calendar/gui/print.c index 90d6161886..e0de3894c7 100644 --- a/calendar/gui/print.c +++ b/calendar/gui/print.c @@ -66,6 +66,11 @@ static const int sept_1752[42] = { #define SEPT_1752_START 2 /* Start day within month */ #define SEPT_1752_END 20 /* End day within month */ +/* FIXME: This needs to be able to render using all the options from the new + * calendar configuration stuff. + */ +#define WEEK_STARTS_ON_MONDAY FALSE + struct pdinfo { GList *slots; @@ -363,7 +368,7 @@ print_month_small (GnomePrintContext *pc, GnomeCalendar *gcal, tm = *localtime (&month); /* get month days */ - build_month(tm.tm_mon, tm.tm_year+1900, week_starts_on_monday, days, 0, 0); + build_month(tm.tm_mon, tm.tm_year+1900, WEEK_STARTS_ON_MONDAY, days, 0, 0); /* build day-busy bits */ now = time_month_begin(month); @@ -384,7 +389,7 @@ print_month_small (GnomePrintContext *pc, GnomeCalendar *gcal, gnome_print_setrgbcolor (pc, 0,0,0); for (x=0;x<7;x++) { - print_text(pc, font_bold, daynames[(week_starts_on_monday?x+1:x)%7], ALIGN_CENTRE, + print_text(pc, font_bold, daynames[(WEEK_STARTS_ON_MONDAY?x+1:x)%7], ALIGN_CENTRE, left+x*xpad, left+(x+1)*xpad, bottom+7*ypad, bottom+7*ypad-gnome_font_get_size(font_bold)); } @@ -882,7 +887,7 @@ print_month_summary (GnomePrintContext *pc, GnomeCalendar *gcal, time_t whence, tm = *localtime (&now); /* get month days */ - build_month(tm.tm_mon, tm.tm_year+1900, week_starts_on_monday, days, 0, 0); + build_month(tm.tm_mon, tm.tm_year+1900, WEEK_STARTS_ON_MONDAY, days, 0, 0); /* a little margin */ top -= 4; |