From a6c4b535334a6da5c8d1622b11a0893d0c55abee Mon Sep 17 00:00:00 2001 From: Russell Steinthal Date: Wed, 3 Nov 1999 02:36:31 +0000 Subject: Add default alarm support, Beep on display alarms option Since there are now some calls from prop.c into previously static functions in eventedit.c, the code in those files should probably be reorganized. Perhaps a new alarm-utils.c file? In any case, this commits working code to the repository before we reorganize. svn path=/trunk/; revision=1366 --- calendar/gui/eventedit.c | 40 ++++++++++++----- calendar/gui/gnome-cal.c | 2 + calendar/gui/main.c | 64 ++++++++++++++++++++++++++ calendar/gui/main.h | 8 ++++ calendar/gui/prop.c | 115 +++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 216 insertions(+), 13 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/eventedit.c b/calendar/gui/eventedit.c index 926bb6f09c..2b93426b00 100644 --- a/calendar/gui/eventedit.c +++ b/calendar/gui/eventedit.c @@ -319,20 +319,30 @@ alarm_toggle (GtkToggleButton *toggle, CalendarAlarm *alarm) #define FXS (GTK_FILL | GTK_EXPAND | GTK_SHRINK) #define FS (GTK_FILL | GTK_SHRINK) -static void -ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType type, int y) +void +ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType type, int y, gboolean control_sens, GtkSignalFunc dirty_func) { GtkWidget *entry; alarm->w_enabled = gtk_check_button_new_with_label (str); - gtk_signal_connect (GTK_OBJECT (alarm->w_enabled), "toggled", - GTK_SIGNAL_FUNC (alarm_toggle), alarm); + gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (alarm->w_enabled), + alarm->enabled); + if (control_sens) + gtk_signal_connect (GTK_OBJECT (alarm->w_enabled), "toggled", + GTK_SIGNAL_FUNC (alarm_toggle), alarm); + if (dirty_func) + gtk_signal_connect (GTK_OBJECT (alarm->w_enabled), "toggled", + GTK_SIGNAL_FUNC (dirty_func), NULL); gtk_table_attach (table, alarm->w_enabled, 0, 1, y, y+1, FS, FS, 0, 0); alarm->w_count = make_spin_button (alarm->count, 0, 10000); + if (dirty_func) + gtk_signal_connect (GTK_OBJECT (alarm->w_count), "changed", + GTK_SIGNAL_FUNC (dirty_func), NULL); gtk_table_attach (table, alarm->w_count, 1, 2, y, y+1, FS, FS, 0, 0); alarm->w_timesel = timesel_new (); + /* is there a "changed" signal which we can connect to? */ gtk_option_menu_set_history (GTK_OPTION_MENU (alarm->w_timesel), alarm->units); gtk_table_attach (table, alarm->w_timesel, 2, 3, y, y+1, FS, FS, 0, 0); @@ -344,6 +354,11 @@ ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType t alarm->w_entry = gtk_entry_new (); gtk_table_attach (table, alarm->w_entry, 4, 5, y, y+1, FXS, FS, 0, 0); gtk_entry_set_text (GTK_ENTRY (alarm->w_entry), alarm->data ? alarm->data : ""); + if (dirty_func) + gtk_signal_connect (GTK_OBJECT (alarm->w_entry), + "changed", + GTK_SIGNAL_FUNC (dirty_func), + NULL); break; case ALARM_PROGRAM: @@ -354,12 +369,17 @@ ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType t entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (alarm->w_entry)); gtk_entry_set_text (GTK_ENTRY (entry), alarm->data ? alarm->data : ""); gtk_table_attach (table, alarm->w_entry, 4, 5, y, y+1, FXS, FS, 0, 0); + if (dirty_func) + gtk_signal_connect (GTK_OBJECT (entry), + "changed", + GTK_SIGNAL_FUNC (dirty_func), + NULL); break; default: break; } - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (alarm->w_enabled), alarm->enabled); + ee_alarm_setting (alarm, alarm->enabled); } @@ -379,10 +399,10 @@ ee_alarm_widgets (EventEditor *ee) mailto = gtk_label_new (_("Mail to:")); mailte = gtk_entry_new (); - ee_create_ae (GTK_TABLE (table), _("Display"), &ee->ical->dalarm, ALARM_DISPLAY, 1); - ee_create_ae (GTK_TABLE (table), _("Audio"), &ee->ical->aalarm, ALARM_AUDIO, 2); - ee_create_ae (GTK_TABLE (table), _("Program"), &ee->ical->palarm, ALARM_PROGRAM, 3); - ee_create_ae (GTK_TABLE (table), _("Mail"), &ee->ical->malarm, ALARM_MAIL, 4); + ee_create_ae (GTK_TABLE (table), _("Display"), &ee->ical->dalarm, ALARM_DISPLAY, 1, TRUE, NULL); + ee_create_ae (GTK_TABLE (table), _("Audio"), &ee->ical->aalarm, ALARM_AUDIO, 2, TRUE, NULL); + ee_create_ae (GTK_TABLE (table), _("Program"), &ee->ical->palarm, ALARM_PROGRAM, 3, TRUE, NULL); + ee_create_ae (GTK_TABLE (table), _("Mail"), &ee->ical->malarm, ALARM_MAIL, 4, TRUE, NULL); return l; } @@ -423,7 +443,7 @@ ee_classification_widgets (EventEditor *ee) * Retrieves the information from the CalendarAlarm widgets and stores them * on the CalendarAlarm generic values */ -static void +void ee_store_alarm (CalendarAlarm *alarm, enum AlarmType type) { GtkWidget *item; diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index 1342e6454b..0487f07310 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -443,6 +443,8 @@ calendar_notify (time_t time, CalendarAlarm *which, void *data) GtkWidget *w; char *msg; + if (beep_on_display) + gdk_beep (); msg = g_strconcat (_("Reminder of your appointment at "), ctime (&app), "`", ico->summary, "'", NULL); diff --git a/calendar/gui/main.c b/calendar/gui/main.c index 0f0cc91477..391e5535ff 100644 --- a/calendar/gui/main.c +++ b/calendar/gui/main.c @@ -83,6 +83,17 @@ static int show_events; /* If set, show todo items quit */ static int show_todo; +/* If set, beep on display alarms */ +gboolean beep_on_display = 0; + +/* Default values for alarms */ +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 } +}; + static void init_username (void) { @@ -101,6 +112,52 @@ range_check_hour (int hour) return hour; } +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 (); + } +} + + /* * Initializes the calendar internal variables, loads defaults */ @@ -153,11 +210,18 @@ init_calendar (void) todo_show_priority = gnome_config_get_bool("/calendar/Todo/show_priority"); + /* read alarm settings */ + beep_on_display = gnome_config_get_bool ("/calendar/alarms/beep_on_display=FALSE"); + init_default_alarms (); + + /* Done */ gnome_config_pop_prefix (); } + + static void save_calendar_cmd (GtkWidget *widget, void *data); static void diff --git a/calendar/gui/main.h b/calendar/gui/main.h index 584ce2e83c..6419153be8 100644 --- a/calendar/gui/main.h +++ b/calendar/gui/main.h @@ -44,6 +44,9 @@ extern gboolean todo_style_changed; extern gint todo_current_sort_column; extern gint todo_current_sort_type; +/* default alarm stuff */ +extern CalendarAlarm alarm_defaults[4]; +extern gboolean beep_on_display; /* Creates and runs the preferences dialog box */ void properties (GtkWidget *toplevel); @@ -79,3 +82,8 @@ GnomeCalendar *new_calendar (char *full_name, char *calendar_file, char *geometry, char *page, gboolean hidden); #endif + + + + + diff --git a/calendar/gui/prop.c b/calendar/gui/prop.c index 129407293b..4f1ec889d4 100644 --- a/calendar/gui/prop.c +++ b/calendar/gui/prop.c @@ -21,7 +21,8 @@ enum { PROP_TIME_DISPLAY, PROP_COLORS, - PROP_TODO + PROP_TODO, + PROP_ALARMS }; static GtkWidget *prop_win; /* The preferences dialog */ @@ -47,6 +48,13 @@ static GtkWidget *due_date_show_button; static GtkWidget *due_date_overdue_highlight; static GtkWidget *priority_show_button; +/* Widgets for the alarm page */ +static GtkWidget *enable_display_beep; + +/* prototypes */ +static void prop_apply_alarms (void); +static void create_alarm_page (void); + /* Callback used when the property box is closed -- just sets the prop_win variable to null. */ static int prop_cancel (void) @@ -146,7 +154,11 @@ prop_apply (GtkWidget *w, int page) break; case PROP_TODO: - prop_apply_todo(); + prop_apply_todo (); + break; + + case PROP_ALARMS: + prop_apply_alarms (); break; case -1: @@ -654,7 +666,8 @@ properties (GtkWidget *toplevel) create_time_display_page (); create_colors_page (); - create_todo_page(); + create_todo_page (); + create_alarm_page (); gtk_signal_connect (GTK_OBJECT (prop_win), "destroy", (GtkSignalFunc) prop_cancel, NULL); @@ -702,5 +715,101 @@ color_spec_from_prop (ColorProp propnum) return build_color_spec (color_props[propnum].r, color_props[propnum].g, color_props[propnum].b); } +static void +create_alarm_page (void) +{ + GtkWidget *main_box; + GtkWidget *default_frame; + GtkWidget *default_table; + GtkWidget *misc_frame; + GtkWidget *misc_box; + + main_box = gtk_hbox_new (FALSE, GNOME_PAD); + gtk_container_set_border_width (GTK_CONTAINER (main_box), GNOME_PAD_SMALL); + gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), + main_box, gtk_label_new (_("Alarms"))); + + /* build miscellaneous box */ + misc_frame = gtk_frame_new (_("Alarm Properties")); + gtk_container_set_border_width (GTK_CONTAINER (misc_frame), + GNOME_PAD_SMALL); + misc_box = gtk_vbox_new (FALSE, GNOME_PAD); + + gtk_container_set_border_width (GTK_CONTAINER (misc_frame), GNOME_PAD_SMALL); + gtk_container_add (GTK_CONTAINER (misc_frame), misc_box); + + gtk_box_pack_start (GTK_BOX (main_box), misc_frame, FALSE, FALSE, 0); + + enable_display_beep = gtk_check_button_new_with_label (_("Beep on display alarms")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (enable_display_beep), + beep_on_display); + gtk_box_pack_start (GTK_BOX (misc_box), enable_display_beep, FALSE, FALSE, 0); + gtk_signal_connect (GTK_OBJECT (enable_display_beep), "toggled", + (GtkSignalFunc) prop_changed, + NULL); + + /* populate default frame/box */ + default_frame = gtk_frame_new (_("Defaults")); + gtk_container_set_border_width (GTK_CONTAINER (default_frame), GNOME_PAD_SMALL); + gtk_box_pack_start (GTK_BOX (main_box), default_frame, FALSE, FALSE, 0); + default_table = gtk_table_new (1, 1, 0); + gtk_container_set_border_width (GTK_CONTAINER (default_table), 4); + gtk_table_set_row_spacings (GTK_TABLE (default_table), 4); + gtk_table_set_col_spacings (GTK_TABLE (default_table), 4); + gtk_container_add (GTK_CONTAINER (default_frame), default_table); + + ee_create_ae (GTK_TABLE (default_table), _("Display"), + &alarm_defaults [ALARM_DISPLAY], ALARM_DISPLAY, 1, + FALSE, prop_changed); + ee_create_ae (GTK_TABLE (default_table), _("Audio"), + &alarm_defaults [ALARM_AUDIO], ALARM_AUDIO, 2, + FALSE, prop_changed); + ee_create_ae (GTK_TABLE (default_table), _("Program"), + &alarm_defaults [ALARM_PROGRAM], ALARM_PROGRAM, 3, + FALSE, prop_changed); + ee_create_ae (GTK_TABLE (default_table), _("Mail"), + &alarm_defaults [ALARM_MAIL], ALARM_MAIL, 4, + FALSE, prop_changed); +} + +static void +prop_store_alarm_default_values (CalendarAlarm* alarm) +{ + ee_store_alarm (alarm, alarm->type); + switch (alarm->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; + } + + gnome_config_set_int ("enabled", alarm->enabled); + gnome_config_set_int ("count", alarm->count); + gnome_config_set_int ("units", alarm->units); + if (alarm->data) + gnome_config_set_string ("data", alarm->data); + + gnome_config_pop_prefix (); + gnome_config_sync (); +} + +static void +prop_apply_alarms () +{ + int i; + for (i=0; i < 4; i++) + prop_store_alarm_default_values (&alarm_defaults [i]); + beep_on_display = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (enable_display_beep)); + gnome_config_set_bool ("/calendar/alarms/beep_on_display", beep_on_display); + gnome_config_sync(); +} -- cgit