Patch for review: timeout audio alarms



Gnomecal hackers:

The following patch against HEAD implements a user-configurable 
timeout for the beeping on audio alarms (a feature requested by a 
user and which I find somewhat useful).

While I've tested the patch on my machine and don't see any problems, 
I'd appreciate it if people would review the gtk_signal_* and 
gtk_timeout_* changes in gnome-cal.c, since I'm somewhat new to that 
area.  (Thanks to the hackers on #gnome for helping me through that 
section, BTW.)

Thanks.

-Russell

Index: eventedit.c
===================================================================
RCS file: /cvs/gnome/gnome-pim/gncal/eventedit.c,v
retrieving revision 1.58
diff -u -r1.58 eventedit.c
--- eventedit.c	1999/11/03 02:36:31	1.58
+++ eventedit.c	1999/11/05 08:55:05
@@ -59,7 +59,7 @@
 	object_class->destroy = event_editor_destroy;
 }
 
-static GtkWidget *
+GtkWidget *
 make_spin_button (int val, int low, int high)
 {
 	GtkAdjustment *adj;
Index: gncal-day-view.c
===================================================================
RCS file: /cvs/gnome/gnome-pim/gncal/gncal-day-view.c,v
retrieving revision 1.17
diff -u -r1.17 gncal-day-view.c
--- gncal-day-view.c	1999/05/25 19:28:25	1.17
+++ gncal-day-view.c	1999/11/05 08:55:05
@@ -13,8 +13,8 @@
 #include "main.h"
 #include "eventedit.h"
 #include "popup-menu.h"
+#include "quick-view.h"
 
-
 #define TEXT_BORDER 2
 #define MIN_INFO_WIDTH 50
 
@@ -151,7 +151,21 @@
 
 	if (event->button == 1 && event->type == GDK_2BUTTON_PRESS)
 		gnome_calendar_dayjump (dayview->calendar, dayview->lower);
-
+#if 0
+	else if (event->button == 1 && event->type == GDK_BUTTON_PRESS) {
+		time_t day_begin_time, day_end_time;
+		GList *list;
+		GtkWidget *qv;
+		char date_str [256];
+		
+		strftime (date_str, sizeof (date_str), _("%a %b %d %Y"), 
+			  localtime (&dayview->lower));
+		qv = quick_view_new (dayview->calendar, date_str, dayview->events);
+		quick_view_do_popup (QUICK_VIEW (qv), event);
+		gtk_widget_destroy (qv);
+	}
+		
+#endif
 	return TRUE;
 }
 
Index: gnome-cal.c
===================================================================
RCS file: /cvs/gnome/gnome-pim/gncal/gnome-cal.c,v
retrieving revision 1.64
diff -u -r1.64 gnome-cal.c
--- gnome-cal.c	1999/11/03 02:36:31	1.64
+++ gnome-cal.c	1999/11/05 08:55:05
@@ -387,11 +387,20 @@
 }
 
 static void
-stop_beeping (GtkObject *object, gpointer tagp)
+stop_beeping (GtkObject* object, gpointer data)
 {
-	guint tag = GPOINTER_TO_INT (tagp);
-
-	gtk_timeout_remove (tag);
+	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
@@ -402,11 +411,18 @@
 	return TRUE;
 }
 
+static gint
+timeout_beep (gpointer data)
+{
+	stop_beeping (data, NULL);
+	return FALSE;
+}
+
 void
 calendar_notify (time_t time, CalendarAlarm *which, void *data)
 {
 	iCalObject *ico = data;
-	guint tag;
+	guint beep_tag, timer_tag;
 
 	if (&ico->aalarm == which){
 		time_t app = ico->aalarm.trigger + ico->aalarm.offset;
@@ -419,8 +435,18 @@
 
 		/* Idea: we need Snooze option :-) */
 		w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, "Ok", 
NULL);
-		tag = gtk_timeout_add (1000, start_beeping, NULL);
-		gtk_signal_connect (GTK_OBJECT (w), "destroy", stop_beeping, 
GINT_TO_POINTER (tag));
+		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_signal_connect (GTK_OBJECT (w), "destroy", stop_beeping, 
+				    NULL);
 		gtk_widget_show (w);
 
 		return;
Index: main.c
===================================================================
RCS file: /cvs/gnome/gnome-pim/gncal/main.c,v
retrieving revision 1.87
diff -u -r1.87 main.c
--- main.c	1999/11/03 02:36:31	1.87
+++ main.c	1999/11/05 08:55:05
@@ -86,6 +86,11 @@
 /* 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;
+
 /* Default values for alarms */
 CalendarAlarm alarm_defaults[4] = {
 	{ ALARM_MAIL, 0, 15, ALARM_MINUTES },
@@ -212,6 +217,8 @@
 
 	/* read alarm settings */
 	beep_on_display = gnome_config_get_bool ("/calendar/alarms/beep_on_d
isplay=FALSE");
+	enable_aalarm_timeout = gnome_config_get_bool ("/calendar/alarms/ena
ble_audio_timeout=FALSE");
+	audio_alarm_timeout = gnome_config_get_int ("/calendar/alarms/audio_
alarm_timeout=60");
 	init_default_alarms ();
 	
 
Index: main.h
===================================================================
RCS file: /cvs/gnome/gnome-pim/gncal/main.h,v
retrieving revision 1.13
diff -u -r1.13 main.h
--- main.h	1999/11/03 02:36:31	1.13
+++ main.h	1999/11/05 08:55:05
@@ -44,9 +44,11 @@
 extern gint todo_current_sort_column;
 extern gint todo_current_sort_type;
 
-/* default alarm stuff */
+/* alarm stuff */
 extern CalendarAlarm alarm_defaults[4];
 extern gboolean beep_on_display;
+extern gboolean enable_aalarm_timeout;
+extern guint audio_alarm_timeout;
 
 /* Creates and runs the preferences dialog box */
 void properties (GtkWidget *toplevel);
Index: prop.c
===================================================================
RCS file: /cvs/gnome/gnome-pim/gncal/prop.c,v
retrieving revision 1.25
diff -u -r1.25 prop.c
--- prop.c	1999/11/03 02:36:31	1.25
+++ prop.c	1999/11/05 08:55:05
@@ -50,11 +50,20 @@
 
 /* Widgets for the alarm page */
 static GtkWidget *enable_display_beep;
+static GtkWidget *to_cb;
+static GtkWidget *to_spin;
 
 /* prototypes */
 static void prop_apply_alarms (void);
 static void create_alarm_page (void);
+static void to_cb_changed (GtkWidget* object, gpointer data);
 
+GtkWidget* make_spin_button (int val, int low, int high);
+void ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm,
+		   enum AlarmType type, int y, gboolean sens,
+		   GtkSignalFunc dirty_func);
+void ee_store_alarm (CalendarAlarm *alarm, enum AlarmType type);
+
 /* Callback used when the property box is closed -- just sets the 
prop_win variable to null. */
 static int
 prop_cancel (void)
@@ -723,8 +732,9 @@
 	GtkWidget *default_table;
 	GtkWidget *misc_frame;
 	GtkWidget *misc_box;
+	GtkWidget *box, *l;
 
-	main_box = gtk_hbox_new (FALSE, GNOME_PAD);
+	main_box = gtk_vbox_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")));
@@ -748,6 +758,23 @@
 			    (GtkSignalFunc) prop_changed,
 			    NULL);
 
+	/* audio timeout widgets */
+	box = gtk_hbox_new (FALSE, GNOME_PAD);
+	to_cb = gtk_check_button_new_with_label (_("Audio alarms timeout 
after"));
+	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (to_cb), 
+				      enable_aalarm_timeout);
+	gtk_signal_connect (GTK_OBJECT (to_cb), "toggled",
+			    (GtkSignalFunc) to_cb_changed, NULL);
+	gtk_box_pack_start (GTK_BOX (box), to_cb, FALSE, FALSE, 0);
+	to_spin = make_spin_button (audio_alarm_timeout, 1, 3600);
+	gtk_widget_set_sensitive (to_spin, enable_aalarm_timeout);
+	gtk_signal_connect (GTK_OBJECT (to_spin), "changed",
+			    (GtkSignalFunc) prop_changed, NULL);
+	gtk_box_pack_start (GTK_BOX (box), to_spin, FALSE, FALSE, 0);
+	l = gtk_label_new (_(" seconds"));
+	gtk_box_pack_start (GTK_BOX (box), l, FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (misc_box), box, FALSE, FALSE, 0);
+	
 	/* populate default frame/box */
 	default_frame = gtk_frame_new (_("Defaults"));
 	gtk_container_set_border_width (GTK_CONTAINER (default_frame), 
GNOME_PAD_SMALL);
@@ -811,5 +838,22 @@
 
 	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);
+	enable_aalarm_timeout = gtk_toggle_button_get_active 
(GTK_TOGGLE_BUTTON (to_cb));
+	gnome_config_set_bool ("/calendar/alarms/enable_audio_timeout", 
enable_aalarm_timeout);
+	audio_alarm_timeout = gtk_spin_button_get_value_as_int 
(GTK_SPIN_BUTTON (to_spin));
+	gnome_config_set_int ("/calendar/alarms/audio_alarm_timeout", 
audio_alarm_timeout);
+
 	gnome_config_sync();
 }
+
+static void
+to_cb_changed (GtkWidget *object, gpointer data)
+{
+	gboolean active = 
+		gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (to_cb));
+	gtk_widget_set_sensitive (to_spin, active);
+	prop_changed ();
+}
+	
+
+

-- 
Russell Steinthal		Columbia Law School, Class of 2002
<rms39@columbia.edu>		Columbia College, Class of 1999
<steintr@nj.org>		UNIX System Administrator, nj.org







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