alarm-page.c 19.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/* Evolution calendar - Alarm page of the calendar component dialogs
 *
 * Copyright (C) 2001 Ximian, Inc.
 *
 * Authors: Federico Mena-Quintero <federico@ximian.com>
 *          Miguel de Icaza <miguel@ximian.com>
 *          Seth Alves <alves@hungry.com>
 *          JP Rosevear <jpr@ximian.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

29
#include <string.h>
30 31 32 33 34 35
#include <gtk/gtksignal.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <glade/glade.h>
#include <gal/widgets/e-unicode.h>
#include "e-util/e-dialog-widgets.h"
36
#include "e-util/e-time-utils.h"
37
#include "cal-util/cal-util.h"
38 39
#include "cal-util/timeutil.h"
#include "../calendar-config.h"
40
#include "comp-editor-util.h"
41
#include "alarm-options.h"
42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "alarm-page.h"



/* Private part of the AlarmPage structure */
struct _AlarmPagePrivate {
	/* Glade XML data */
	GladeXML *xml;

	/* Widgets from the Glade file */

	GtkWidget *main;

	GtkWidget *summary;
56
	GtkWidget *date_time;
57 58 59 60 61 62 63 64 65 66

	GtkWidget *list;
	GtkWidget *add;
	GtkWidget *delete;

	GtkWidget *action;
	GtkWidget *interval_value;
	GtkWidget *value_units;
	GtkWidget *relative;
	GtkWidget *time;
67

68 69 70 71 72
	GtkWidget *button_options;

	/* Alarm options dialog and the alarm we maintain */
	CalComponentAlarm *alarm;

73
	gboolean updating;
74 75
};

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
/* "relative" types */
enum {
	BEFORE,
	AFTER
};

/* Time units */
enum {
	MINUTES,
	HOURS,
	DAYS
};

/* Option menu maps */
static const int action_map[] = {
	CAL_ALARM_DISPLAY,
	CAL_ALARM_AUDIO,
	CAL_ALARM_PROCEDURE,
	-1
};

static const int value_map[] = {
	MINUTES,
	HOURS,
	DAYS,
	-1
};

static const int relative_map[] = {
	BEFORE,
	AFTER,
	-1
};

static const int time_map[] = {
	CAL_ALARM_TRIGGER_RELATIVE_START,
	CAL_ALARM_TRIGGER_RELATIVE_END,
	-1
};

116 117 118 119 120 121


static void alarm_page_class_init (AlarmPageClass *class);
static void alarm_page_init (AlarmPage *apage);
static void alarm_page_destroy (GtkObject *object);

122
static GtkWidget *alarm_page_get_widget (CompEditorPage *page);
123
static void alarm_page_focus_main_widget (CompEditorPage *page);
124
static void alarm_page_fill_widgets (CompEditorPage *page, CalComponent *comp);
125
static gboolean alarm_page_fill_component (CompEditorPage *page, CalComponent *comp);
126 127
static void alarm_page_set_summary (CompEditorPage *page, const char *summary);
static void alarm_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates);
128

129
static CompEditorPageClass *parent_class = NULL;
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157



/**
 * alarm_page_get_type:
 *
 * Registers the #AlarmPage class if necessary, and returns the type ID
 * associated to it.
 *
 * Return value: The type ID of the #AlarmPage class.
 **/
GtkType
alarm_page_get_type (void)
{
	static GtkType alarm_page_type;

	if (!alarm_page_type) {
		static const GtkTypeInfo alarm_page_info = {
			"AlarmPage",
			sizeof (AlarmPage),
			sizeof (AlarmPageClass),
			(GtkClassInitFunc) alarm_page_class_init,
			(GtkObjectInitFunc) alarm_page_init,
			NULL, /* reserved_1 */
			NULL, /* reserved_2 */
			(GtkClassInitFunc) NULL
		};

158 159
		alarm_page_type = gtk_type_unique (TYPE_COMP_EDITOR_PAGE,
						   &alarm_page_info);
160 161 162 163 164 165 166 167 168
	}

	return alarm_page_type;
}

/* Class initialization function for the alarm page */
static void
alarm_page_class_init (AlarmPageClass *class)
{
169
	CompEditorPageClass *editor_page_class;
170 171
	GtkObjectClass *object_class;

172
	editor_page_class = (CompEditorPageClass *) class;
173 174
	object_class = (GtkObjectClass *) class;

175
	parent_class = gtk_type_class (TYPE_COMP_EDITOR_PAGE);
176 177

	editor_page_class->get_widget = alarm_page_get_widget;
178
	editor_page_class->focus_main_widget = alarm_page_focus_main_widget;
179 180 181
	editor_page_class->fill_widgets = alarm_page_fill_widgets;
	editor_page_class->fill_component = alarm_page_fill_component;
	editor_page_class->set_summary = alarm_page_set_summary;
182
	editor_page_class->set_dates = alarm_page_set_dates;
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199

	object_class->destroy = alarm_page_destroy;
}

/* Object initialization function for the alarm page */
static void
alarm_page_init (AlarmPage *apage)
{
	AlarmPagePrivate *priv;

	priv = g_new0 (AlarmPagePrivate, 1);
	apage->priv = priv;

	priv->xml = NULL;

	priv->main = NULL;
	priv->summary = NULL;
200
	priv->date_time = NULL;
201 202 203 204 205 206 207 208
	priv->list = NULL;
	priv->add = NULL;
	priv->delete = NULL;
	priv->action = NULL;
	priv->interval_value = NULL;
	priv->value_units = NULL;
	priv->relative = NULL;
	priv->time = NULL;
209 210 211
	priv->button_options = NULL;

	priv->alarm = cal_component_alarm_new ();
212 213

	priv->updating = FALSE;
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
}

/* Destroy handler for the alarm page */
static void
alarm_page_destroy (GtkObject *object)
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;

	g_return_if_fail (object != NULL);
	g_return_if_fail (IS_ALARM_PAGE (object));

	apage = ALARM_PAGE (object);
	priv = apage->priv;

	if (priv->xml) {
		gtk_object_unref (GTK_OBJECT (priv->xml));
		priv->xml = NULL;
	}

234 235 236 237 238
	if (priv->alarm) {
		cal_component_alarm_free (priv->alarm);
		priv->alarm = NULL;
	}

239 240 241 242 243 244 245 246 247 248 249
	g_free (priv);
	apage->priv = NULL;

	if (GTK_OBJECT_CLASS (parent_class)->destroy)
		(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}



/* get_widget handler for the alarm page */
static GtkWidget *
250
alarm_page_get_widget (CompEditorPage *page)
251 252 253 254 255 256 257 258 259 260
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;

	apage = ALARM_PAGE (page);
	priv = apage->priv;

	return priv->main;
}

261 262 263 264 265 266 267 268 269 270 271 272 273
/* focus_main_widget handler for the alarm page */
static void
alarm_page_focus_main_widget (CompEditorPage *page)
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;

	apage = ALARM_PAGE (page);
	priv = apage->priv;

	gtk_widget_grab_focus (priv->action);
}

274 275 276 277 278 279 280 281 282
/* Fills the widgets with default values */
static void
clear_widgets (AlarmPage *apage)
{
	AlarmPagePrivate *priv;

	priv = apage->priv;

	/* Summary */
283
	gtk_label_set_text (GTK_LABEL (priv->summary), "");
284 285

	/* Start date */
286
	gtk_label_set_text (GTK_LABEL (priv->date_time), "");
287

288 289 290 291 292 293 294
	/* Sane defaults */
	e_dialog_option_menu_set (priv->action, CAL_ALARM_DISPLAY, action_map);
	e_dialog_spin_set (priv->interval_value, 15);
	e_dialog_option_menu_set (priv->value_units, MINUTES, value_map);
	e_dialog_option_menu_set (priv->relative, BEFORE, relative_map);
	e_dialog_option_menu_set (priv->time, CAL_ALARM_TRIGGER_RELATIVE_START, time_map);

295
	/* List data */
296
	gtk_clist_clear (GTK_CLIST (priv->list));
297 298
}

299
/* Builds a string for the duration of the alarm.  If the duration is zero, returns NULL. */
300 301 302 303 304
static char *
get_alarm_duration_string (struct icaldurationtype *duration)
{
	GString *string = g_string_new (NULL);
	char *ret;
305
	gboolean have_something;
306

307 308 309
	have_something = FALSE;

	if (duration->days > 1) {
310
		g_string_sprintf (string, _("%d days"), duration->days);
311 312
		have_something = TRUE;
	} else if (duration->days == 1) {
313
		g_string_append (string, _("1 day"));
314 315
		have_something = TRUE;
	}
316

317
	if (duration->weeks > 1) {
318
		g_string_sprintf (string, _("%d weeks"), duration->weeks);
319 320
		have_something = TRUE;
	} else if (duration->weeks == 1) {
321
		g_string_append (string, _("1 week"));
322 323
		have_something = TRUE;
	}
324

325
	if (duration->hours > 1) {
326
		g_string_sprintf (string, _("%d hours"), duration->hours);
327 328
		have_something = TRUE;
	} else if (duration->hours == 1) {
329
		g_string_append (string, _("1 hour"));
330 331
		have_something = TRUE;
	}
332

333
	if (duration->minutes > 1) {
334
		g_string_sprintf (string, _("%d minutes"), duration->minutes);
335 336
		have_something = TRUE;
	} else if (duration->minutes == 1) {
337
		g_string_append (string, _("1 minute"));
338 339
		have_something = TRUE;
	}
340

341
	if (duration->seconds > 1) {
342
		g_string_sprintf (string, _("%d seconds"), duration->seconds);
343 344
		have_something = TRUE;
	} else if (duration->seconds == 1) {
345
		g_string_append (string, _("1 second"));
346 347
		have_something = TRUE;
	}
348

349 350 351 352 353 354 355 356
	if (have_something) {
		ret = string->str;
		g_string_free (string, FALSE);
		return ret;
	} else {
		g_string_free (string, TRUE);
		return NULL;
	}
357 358 359 360 361 362 363 364
}

static char *
get_alarm_string (CalComponentAlarm *alarm)
{
	CalAlarmAction action;
	CalAlarmTrigger trigger;
	char string[256];
365
	char *base, *str = NULL, *dur;
366 367 368 369 370 371 372 373 374 375 376 377

	string [0] = '\0';

	cal_component_alarm_get_action (alarm, &action);
	cal_component_alarm_get_trigger (alarm, &trigger);

	switch (action) {
	case CAL_ALARM_AUDIO:
		base = _("Play a sound");
		break;

	case CAL_ALARM_DISPLAY:
378
		base = _("Display a message");
379 380 381 382 383 384 385 386 387 388 389 390
		break;

	case CAL_ALARM_EMAIL:
		base = _("Send an email");
		break;

	case CAL_ALARM_PROCEDURE:
		base = _("Run a program");
		break;

	case CAL_ALARM_NONE:
	case CAL_ALARM_UNKNOWN:
391
	default:
392
		base = _("Unknown action to be performed");
393 394 395 396 397 398 399 400 401
		break;
	}

	/* FIXME: This does not look like it will localize correctly. */

	switch (trigger.type) {
	case CAL_ALARM_TRIGGER_RELATIVE_START:
		dur = get_alarm_duration_string (&trigger.u.rel_duration);

402 403 404 405 406 407 408 409 410 411 412
		if (dur) {
			if (trigger.u.rel_duration.is_neg)
				str = g_strdup_printf (_("%s %s before the start of the appointment"),
						       base, dur);
			else
				str = g_strdup_printf (_("%s %s after the start of the appointment"),
						       base, dur);

			g_free (dur);
		} else
			str = g_strdup_printf (_("%s at the start of the appointment"), base);
413 414 415 416 417 418

		break;

	case CAL_ALARM_TRIGGER_RELATIVE_END:
		dur = get_alarm_duration_string (&trigger.u.rel_duration);

419 420 421 422 423 424 425 426 427 428 429
		if (dur) {
			if (trigger.u.rel_duration.is_neg)
				str = g_strdup_printf (_("%s %s before the end of the appointment"),
						       base, dur);
			else
				str = g_strdup_printf (_("%s %s after the end of the appointment"),
						       base, dur);

			g_free (dur);
		} else
			str = g_strdup_printf (_("%s at the end of the appointment"), base);
430 431

		break;
432 433

	case CAL_ALARM_TRIGGER_ABSOLUTE: {
434 435 436
		struct icaltimetype itt;
		icaltimezone *utc_zone, *current_zone;
		char *location;
437
		struct tm tm;
438
		char buf[256];
439 440
		char *date;

441
		/* Absolute triggers come in UTC, so convert them to the local timezone */
442

443 444 445 446 447 448 449 450 451 452 453 454
		itt = trigger.u.abs_time;

		utc_zone = icaltimezone_get_utc_timezone ();
		location = calendar_config_get_timezone ();
		current_zone = icaltimezone_get_builtin_timezone (location);

		tm = icaltimetype_to_tm_with_zone (&itt, utc_zone, current_zone);

		e_time_format_date_and_time (&tm, calendar_config_get_24_hour_format (),
					     FALSE, FALSE, buf, sizeof (buf));

		date = g_strdup_printf (_("%s at %s"), base, buf);
455 456 457

		break; }

458
	case CAL_ALARM_TRIGGER_NONE:
459
	default:
460
		str = g_strdup_printf (_("%s for an unknown trigger type"), base);
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
		break;
	}

	return str;
}

/* Appends an alarm to the list */
static void
append_reminder (AlarmPage *apage, CalComponentAlarm *alarm)
{
	AlarmPagePrivate *priv;
	GtkCList *clist;
	char *c[1];
	int i;

	priv = apage->priv;

	clist = GTK_CLIST (priv->list);

	c[0] = get_alarm_string (alarm);
	i = gtk_clist_append (clist, c);

483
	gtk_clist_set_row_data_full (clist, i, alarm, (GtkDestroyNotify) cal_component_alarm_free);
484 485 486 487 488 489 490 491
	gtk_clist_select_row (clist, i, 0);
	g_free (c[0]);

	gtk_widget_set_sensitive (priv->delete, TRUE);
}

/* fill_widgets handler for the alarm page */
static void
492
alarm_page_fill_widgets (CompEditorPage *page, CalComponent *comp)
493 494 495 496 497 498
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;
	CalComponentText text;
	GList *alarms, *l;
	GtkCList *clist;
499
	CompEditorPageDates dates;
500

501 502 503
	apage = ALARM_PAGE (page);
	priv = apage->priv;

504 505 506 507
	/* Don't send off changes during this time */
	priv->updating = TRUE;

	/* Clean the page */
508 509 510 511
	clear_widgets (apage);

	/* Summary */
	cal_component_get_summary (comp, &text);
512 513 514 515 516
	alarm_page_set_summary (page, text.value);

	/* Dates */
	comp_editor_dates (&dates, comp);
	alarm_page_set_dates (page, &dates);
517
	comp_editor_free_dates (&dates);
518 519 520

	/* List */
	if (!cal_component_has_alarms (comp))
521
		goto out;
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539

	alarms = cal_component_get_alarm_uids (comp);

	clist = GTK_CLIST (priv->list);
	for (l = alarms; l != NULL; l = l->next) {
		CalComponentAlarm *ca, *ca_copy;
		const char *auid;

		auid = l->data;
		ca = cal_component_get_alarm (comp, auid);
		g_assert (ca != NULL);

		ca_copy = cal_component_alarm_clone (ca);
		cal_component_alarm_free (ca);

		append_reminder (apage, ca_copy);
	}
	cal_obj_uid_list_free (alarms);
540

541 542
 out:

543
	priv->updating = FALSE;
544 545 546
}

/* fill_component handler for the alarm page */
547
static gboolean
548
alarm_page_fill_component (CompEditorPage *page, CalComponent *comp)
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;
	GList *list, *l;
	GtkCList *clist;
	int i;

	apage = ALARM_PAGE (page);
	priv = apage->priv;

	/* Remove all the alarms from the component */

	list = cal_component_get_alarm_uids (comp);
	for (l = list; l; l = l->next) {
		const char *auid;

		auid = l->data;
		cal_component_remove_alarm (comp, auid);
	}
	cal_obj_uid_list_free (list);

	/* Add the new alarms */

	clist = GTK_CLIST (priv->list);
	for (i = 0; i < clist->rows; i++) {
		CalComponentAlarm *alarm, *alarm_copy;

		alarm = gtk_clist_get_row_data (clist, i);
		g_assert (alarm != NULL);

		/* We clone the alarm to maintain the invariant that the alarm
		 * structures in the list did *not* come from the component.
		 */

		alarm_copy = cal_component_alarm_clone (alarm);
584
		cal_component_add_alarm (comp, alarm_copy);
585 586
		cal_component_alarm_free (alarm_copy);
	}
587 588

	return TRUE;
589 590 591 592
}

/* set_summary handler for the alarm page */
static void
593
alarm_page_set_summary (CompEditorPage *page, const char *summary)
594 595 596
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;
597
	gchar *s;
598

599 600 601
	apage = ALARM_PAGE (page);
	priv = apage->priv;

602 603 604
	s = e_utf8_to_gtk_string (priv->summary, summary);
	gtk_label_set_text (GTK_LABEL (priv->summary), s);
	g_free (s);
605 606
}

607
/* set_dates handler for the alarm page */
608
static void
609
alarm_page_set_dates (CompEditorPage *page, CompEditorPageDates *dates)
610 611 612 613 614 615 616
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;

	apage = ALARM_PAGE (page);
	priv = apage->priv;

617
	comp_editor_date_label (dates, priv->date_time);
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
}



/* Gets the widgets from the XML file and returns if they are all available. */
static gboolean
get_widgets (AlarmPage *apage)
{
	AlarmPagePrivate *priv;

	priv = apage->priv;

#define GW(name) glade_xml_get_widget (priv->xml, name)

	priv->main = GW ("alarm-page");
633 634 635
	if (!priv->main)
		return FALSE;

636 637
	gtk_widget_ref (priv->main);
	gtk_widget_unparent (priv->main);
638

639
	priv->summary = GW ("summary");
640
	priv->date_time = GW ("date-time");
641 642 643 644 645 646 647 648 649 650 651

	priv->list = GW ("list");
	priv->add = GW ("add");
	priv->delete = GW ("delete");

	priv->action = GW ("action");
	priv->interval_value = GW ("interval-value");
	priv->value_units = GW ("value-units");
	priv->relative = GW ("relative");
	priv->time = GW ("time");

652 653
	priv->button_options = GW ("button-options");

654 655 656
#undef GW

	return (priv->summary
657
		&& priv->date_time
658 659 660 661 662 663 664
		&& priv->list
		&& priv->add
		&& priv->delete
		&& priv->action
		&& priv->interval_value
		&& priv->value_units
		&& priv->relative
665 666
		&& priv->time
		&& priv->button_options);
667 668 669 670 671 672 673
}

/* This is called when any field is changed; it notifies upstream. */
static void
field_changed_cb (GtkWidget *widget, gpointer data)
{
	AlarmPage *apage;
674
	AlarmPagePrivate *priv;
675

676
	apage = ALARM_PAGE (data);
677
	priv = apage->priv;
678

679 680
	if (!priv->updating)
		comp_editor_page_notify_changed (COMP_EDITOR_PAGE (apage));
681 682 683 684 685 686 687 688 689 690 691 692 693 694
}

/* Callback used for the "add reminder" button */
static void
add_clicked_cb (GtkButton *button, gpointer data)
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;
	CalComponentAlarm *alarm;
	CalAlarmTrigger trigger;

	apage = ALARM_PAGE (data);
	priv = apage->priv;

695
	alarm = cal_component_alarm_clone (priv->alarm);
696 697 698 699 700 701 702 703 704 705

	memset (&trigger, 0, sizeof (CalAlarmTrigger));
	trigger.type = e_dialog_option_menu_get (priv->time, time_map);
	if (e_dialog_option_menu_get (priv->relative, relative_map) == BEFORE)
		trigger.u.rel_duration.is_neg = 1;
	else
		trigger.u.rel_duration.is_neg = 0;

	switch (e_dialog_option_menu_get (priv->value_units, value_map)) {
	case MINUTES:
706
		trigger.u.rel_duration.minutes =
707
			e_dialog_spin_get_int (priv->interval_value);
708 709 710
		break;

	case HOURS:
711 712
		trigger.u.rel_duration.hours =
			e_dialog_spin_get_int (priv->interval_value);
713 714 715
		break;

	case DAYS:
716 717
		trigger.u.rel_duration.days =
			e_dialog_spin_get_int (priv->interval_value);
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
		break;

	default:
		g_assert_not_reached ();
	}
	cal_component_alarm_set_trigger (alarm, trigger);

	cal_component_alarm_set_action (alarm, e_dialog_option_menu_get (priv->action, action_map));

	append_reminder (apage, alarm);
}

/* Callback used for the "delete reminder" button */
static void
delete_clicked_cb (GtkButton *button, gpointer data)
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;
	GtkCList *clist;
	int sel;

	apage = ALARM_PAGE (data);
	priv = apage->priv;

	clist = GTK_CLIST (priv->list);
	if (!clist->selection)
		return;

	sel = GPOINTER_TO_INT (clist->selection->data);

	gtk_clist_remove (clist, sel);
	if (sel >= clist->rows)
		sel--;

	if (clist->rows > 0)
		gtk_clist_select_row (clist, sel, 0);
	else
		gtk_widget_set_sensitive (priv->delete, FALSE);
}

758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
/* Callback used when the alarm options button is clicked */
static void
button_options_clicked_cb (GtkWidget *widget, gpointer data)
{
	AlarmPage *apage;
	AlarmPagePrivate *priv;

	apage = ALARM_PAGE (data);
	priv = apage->priv;

	cal_component_alarm_set_action (priv->alarm,
					e_dialog_option_menu_get (priv->action, action_map));

	if (!alarm_options_dialog_run (priv->alarm))
		g_message ("button_options_clicked_cb(): Could not create the alarm options dialog");
}

775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795
/* Hooks the widget signals */
static void
init_widgets (AlarmPage *apage)
{
	AlarmPagePrivate *priv;

	priv = apage->priv;

	/* Reminder buttons */
	gtk_signal_connect (GTK_OBJECT (priv->add), "clicked",
			    GTK_SIGNAL_FUNC (add_clicked_cb), apage);
	gtk_signal_connect (GTK_OBJECT (priv->delete), "clicked",
			    GTK_SIGNAL_FUNC (delete_clicked_cb), apage);

	/* Connect the default signal handler to use to make sure we notify
	 * upstream of changes to the widget values.
	 */
	gtk_signal_connect (GTK_OBJECT (priv->add), "clicked",
			    GTK_SIGNAL_FUNC (field_changed_cb), apage);
	gtk_signal_connect (GTK_OBJECT (priv->delete), "clicked",
			    GTK_SIGNAL_FUNC (field_changed_cb), apage);
796 797 798 799

	/* Options button */
	gtk_signal_connect (GTK_OBJECT (priv->button_options), "clicked",
			    GTK_SIGNAL_FUNC (button_options_clicked_cb), apage);
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
}



/**
 * alarm_page_construct:
 * @apage: An alarm page.
 *
 * Constructs an alarm page by loading its Glade data.
 *
 * Return value: The same object as @apage, or NULL if the widgets could not be
 * created.
 **/
AlarmPage *
alarm_page_construct (AlarmPage *apage)
{
	AlarmPagePrivate *priv;

	priv = apage->priv;

820 821
	priv->xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-page.glade",
				   NULL);
822
	if (!priv->xml) {
823 824
		g_message ("alarm_page_construct(): "
			   "Could not load the Glade XML file!");
825 826 827 828
		return NULL;
	}

	if (!get_widgets (apage)) {
829 830
		g_message ("alarm_page_construct(): "
			   "Could not find all widgets in the XML file!");
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859
		return NULL;
	}

	init_widgets (apage);

	return apage;
}

/**
 * alarm_page_new:
 *
 * Creates a new alarm page.
 *
 * Return value: A newly-created alarm page, or NULL if the page could not be
 * created.
 **/
AlarmPage *
alarm_page_new (void)
{
	AlarmPage *apage;

	apage = gtk_type_new (TYPE_ALARM_PAGE);
	if (!alarm_page_construct (apage)) {
		gtk_object_unref (GTK_OBJECT (apage));
		return NULL;
	}

	return apage;
}