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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
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
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
|
/* Evolution calendar - Alarm options dialog
*
* Copyright (C) 2001 Ximian, Inc.
*
* Authors: Federico Mena-Quintero <federico@ximian.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* 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
#include <string.h>
#include <glib.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkhbox.h>
#include <liboaf/liboaf.h>
#include <bonobo/bonobo-control.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-widget.h>
#include <glade/glade.h>
#include <ebook/e-destination.h>
#include "Evolution-Addressbook-SelectNames.h"
#include "e-util/e-dialog-widgets.h"
#include "alarm-options.h"
typedef struct {
/* Whether the dialog was accepted or canceled */
gboolean canceled;
/* Glade XML data */
GladeXML *xml;
/* Toplevel */
GtkWidget *toplevel;
/* Buttons */
GtkWidget *button_ok;
GtkWidget *button_cancel;
/* Alarm repeat widgets */
gboolean repeat;
GtkWidget *repeat_toggle;
GtkWidget *repeat_group;
GtkWidget *repeat_quantity;
GtkWidget *repeat_value;
GtkWidget *repeat_unit;
/* Display alarm widgets */
GtkWidget *dalarm_group;
GtkWidget *dalarm_description;
/* Audio alarm widgets */
GtkWidget *aalarm_group;
GtkWidget *aalarm_attach;
/* Mail alarm widgets */
const char *email;
GtkWidget *malarm_group;
GtkWidget *malarm_address_group;
GtkWidget *malarm_addresses;
GtkWidget *malarm_addressbook;
GtkWidget *malarm_description;
GNOME_Evolution_Addressbook_SelectNames corba_select_names;
/* Procedure alarm widgets */
GtkWidget *palarm_group;
GtkWidget *palarm_program;
GtkWidget *palarm_args;
} Dialog;
#define SELECT_NAMES_OAFID "OAFIID:GNOME_Evolution_Addressbook_SelectNames"
static const char *section_name = "Send To";
/* Gets the widgets from the XML file and returns if they are all available. */
static gboolean
get_widgets (Dialog *dialog)
{
#define GW(name) glade_xml_get_widget (dialog->xml, name)
dialog->toplevel = GW ("alarm-options-toplevel");
dialog->button_ok = GW ("button-ok");
dialog->button_cancel = GW ("button-cancel");
dialog->repeat_toggle = GW ("repeat-toggle");
dialog->repeat_group = GW ("repeat-group");
dialog->repeat_quantity = GW ("repeat-quantity");
dialog->repeat_value = GW ("repeat-value");
dialog->repeat_unit = GW ("repeat-unit");
dialog->dalarm_group = GW ("dalarm-group");
dialog->dalarm_description = GW ("dalarm-description");
dialog->aalarm_group = GW ("aalarm-group");
dialog->aalarm_attach = GW ("aalarm-attach");
dialog->malarm_group = GW ("malarm-group");
dialog->malarm_address_group = GW ("malarm-address-group");
dialog->malarm_addressbook = GW ("malarm-addressbook");
dialog->malarm_description = GW ("malarm-description");
dialog->palarm_group = GW ("palarm-group");
dialog->palarm_program = GW ("palarm-program");
dialog->palarm_args = GW ("palarm-args");
return (dialog->toplevel
&& dialog->button_ok
&& dialog->button_cancel
&& dialog->repeat_toggle
&& dialog->repeat_group
&& dialog->repeat_quantity
&& dialog->repeat_value
&& dialog->repeat_unit
&& dialog->dalarm_group
&& dialog->dalarm_description
&& dialog->aalarm_group
&& dialog->aalarm_attach
&& dialog->malarm_group
&& dialog->malarm_address_group
&& dialog->malarm_addressbook
&& dialog->malarm_description
&& dialog->palarm_group
&& dialog->palarm_program
&& dialog->palarm_args);
}
static void
addressbook_clicked_cb (GtkWidget *widget, gpointer data)
{
Dialog *dialog = data;
CORBA_Environment ev;
CORBA_exception_init (&ev);
GNOME_Evolution_Addressbook_SelectNames_activateDialog (dialog->corba_select_names,
section_name, &ev);
CORBA_exception_free (&ev);
}
static gboolean
setup_select_names (Dialog *dialog)
{
Bonobo_Control corba_control;
CORBA_Environment ev;
CORBA_exception_init (&ev);
dialog->corba_select_names = oaf_activate_from_id (SELECT_NAMES_OAFID, 0, NULL, &ev);
if (BONOBO_EX (&ev))
return FALSE;
GNOME_Evolution_Addressbook_SelectNames_addSection (dialog->corba_select_names,
section_name, section_name, &ev);
if (BONOBO_EX (&ev))
return FALSE;
corba_control = GNOME_Evolution_Addressbook_SelectNames_getEntryBySection (dialog->corba_select_names,
section_name, &ev);
if (BONOBO_EX (&ev))
return FALSE;
CORBA_exception_free (&ev);
dialog->malarm_addresses = bonobo_widget_new_control_from_objref (corba_control, CORBA_OBJECT_NIL);
gtk_widget_show (dialog->malarm_addresses);
gtk_box_pack_end_defaults (GTK_BOX (dialog->malarm_address_group), dialog->malarm_addresses);
gtk_signal_connect (GTK_OBJECT (dialog->malarm_addressbook), "clicked",
GTK_SIGNAL_FUNC (addressbook_clicked_cb), dialog);
return TRUE;
}
/* Closes the dialog by terminating its main loop */
static void
close_dialog (Dialog *dialog, gboolean canceled)
{
dialog->canceled = canceled;
gtk_main_quit ();
}
/* Callback used when the toplevel window is deleted */
static guint
toplevel_delete_event_cb (GtkWidget *widget, GdkEventAny *event, gpointer data)
{
Dialog *dialog;
dialog = data;
close_dialog (dialog, TRUE);
return TRUE;
}
/* Callback used when the OK button is clicked */
static void
button_ok_clicked_cb (GtkWidget *button, gpointer data)
{
Dialog *dialog;
dialog = data;
close_dialog (dialog, FALSE);
}
/* Callback used when the Cancel button is clicked */
static void
button_cancel_clicked_cb (GtkWidget *button, gpointer data)
{
Dialog *dialog;
dialog = data;
close_dialog (dialog, TRUE);
}
/* Callback used when the repeat toggle button is toggled. We sensitize the
* repeat group options as appropriate.
*/
static void
repeat_toggle_toggled_cb (GtkToggleButton *toggle, gpointer data)
{
Dialog *dialog;
gboolean active;
dialog = data;
active = gtk_toggle_button_get_active (toggle);
gtk_widget_set_sensitive (dialog->repeat_group, active);
}
/* Hooks the widget signals */
static void
init_widgets (Dialog *dialog)
{
/* Toplevel, buttons */
dialog->canceled = TRUE;
gtk_signal_connect (GTK_OBJECT (dialog->toplevel), "delete_event",
GTK_SIGNAL_FUNC (toplevel_delete_event_cb), dialog);
gtk_signal_connect (GTK_OBJECT (dialog->button_ok), "clicked",
GTK_SIGNAL_FUNC (button_ok_clicked_cb), dialog);
gtk_signal_connect (GTK_OBJECT (dialog->button_cancel), "clicked",
GTK_SIGNAL_FUNC (button_cancel_clicked_cb), dialog);
/* Alarm repeat */
gtk_signal_connect (GTK_OBJECT (dialog->repeat_toggle), "toggled",
GTK_SIGNAL_FUNC (repeat_toggle_toggled_cb), dialog);
}
/* Fills the audio alarm widgets with the values from the alarm component */
static void
alarm_to_aalarm_widgets (Dialog *dialog, CalComponentAlarm *alarm)
{
icalattach *attach;
const char *url;
cal_component_alarm_get_attach (alarm, &attach);
if (!attach) {
e_dialog_editable_set (dialog->aalarm_attach, NULL);
return;
}
/* FIXME: this does not support inline data */
url = NULL;
if (icalattach_get_is_url (attach))
url = icalattach_get_url (attach);
else
g_message ("alarm_to_aalarm_widgets(): FIXME: we don't support inline data yet");
e_dialog_editable_set (dialog->aalarm_attach, url);
icalattach_unref (attach);
}
/* Fills the display alarm widgets with the values from the alarm component */
static void
alarm_to_dalarm_widgets (Dialog *dialog, CalComponentAlarm *alarm)
{
CalComponentText description;
cal_component_alarm_get_description (alarm, &description);
e_dialog_editable_set (dialog->dalarm_description, description.value);
}
/* Fills the mail alarm widgets with the values from the alarm component */
static void
alarm_to_malarm_widgets (Dialog *dialog, CalComponentAlarm *alarm)
{
CalComponentText description;
GSList *attendee_list, *l;
EDestination **destv;
int len, i;
/* Recipients */
cal_component_alarm_get_attendee_list (alarm, &attendee_list);
len = g_slist_length (attendee_list);
if (len <= 0) {
destv = g_new0 (EDestination *, 2);
destv[0] = e_destination_new ();
e_destination_set_email (destv[0], dialog->email);
destv[1] = NULL;
len = 1;
} else {
destv = g_new0 (EDestination *, len + 1);
for (l = attendee_list, i = 0; l != NULL; l = l->next, i++) {
CalComponentAttendee *a = l->data;
EDestination *dest;
dest = e_destination_new ();
if (a->cn != NULL && *a->cn)
e_destination_set_name (dest, a->cn);
if (a->value != NULL && *a->value)
e_destination_set_email (dest, a->value);
destv[i] = dest;
}
destv[i] = NULL;
}
bonobo_widget_set_property (BONOBO_WIDGET (dialog->malarm_addresses),
"destinations", e_destination_exportv (destv), NULL);
for (i = 0; i < len; i++)
gtk_object_unref (GTK_OBJECT (destv[i]));
g_free (destv);
cal_component_free_attendee_list (attendee_list);
/* Description */
cal_component_alarm_get_description (alarm, &description);
e_dialog_editable_set (dialog->malarm_description, description.value);
}
/* Fills the procedure alarm widgets with the values from the alarm component */
static void
alarm_to_palarm_widgets (Dialog *dialog, CalComponentAlarm *alarm)
{
icalattach *attach;
CalComponentText description;
cal_component_alarm_get_attach (alarm, &attach);
cal_component_alarm_get_description (alarm, &description);
if (attach) {
const char *url;
if (icalattach_get_is_url (attach)) {
url = icalattach_get_url (attach);
e_dialog_editable_set (dialog->palarm_program, url);
} else
g_message ("alarm_to_palarm_widgets(): Don't know what to do with non-URL "
"attachments");
icalattach_unref (attach);
}
e_dialog_editable_set (dialog->palarm_args, description.value);
}
enum duration_units {
DUR_MINUTES,
DUR_HOURS,
DUR_DAYS
};
static const int duration_units_map[] = {
DUR_MINUTES,
DUR_HOURS,
DUR_DAYS,
-1
};
/* Sigh. Takes an overcomplicated duration value and reduces it to its lowest
* common denominator.
*/
static void
normalize_duration (struct icaldurationtype dur, int *value, enum duration_units *units)
{
if (dur.seconds != 0 || dur.minutes != 0) {
*value = ((((dur.weeks * 7 + dur.days) * 24 + dur.hours) * 60) + dur.minutes
+ dur.seconds / 60 + ((dur.seconds % 60) >= 30 ? 1 : 0));
*units = DUR_MINUTES;
} else if (dur.hours) {
*value = ((dur.weeks * 7) + dur.days) * 24 + dur.hours;
*units = DUR_HOURS;
} else if (dur.days != 0 || dur.weeks != 0) {
*value = dur.weeks * 7 + dur.days;
*units = DUR_DAYS;
} else {
*value = 0;
*units = DUR_MINUTES;
}
}
/* Fills the repeat widgets with the values from the alarm component */
static void
alarm_to_repeat_widgets (Dialog *dialog, CalComponentAlarm *alarm)
{
CalAlarmRepeat repeat;
int value;
enum duration_units units;
cal_component_alarm_get_repeat (alarm, &repeat);
/* Sensitivity */
if (dialog->repeat || repeat.repetitions == 0) {
gtk_widget_set_sensitive (dialog->repeat_toggle, dialog->repeat);
gtk_widget_set_sensitive (dialog->repeat_group, FALSE);
e_dialog_toggle_set (dialog->repeat_toggle, FALSE);
return;
}
gtk_widget_set_sensitive (dialog->repeat_group, TRUE);
e_dialog_toggle_set (dialog->repeat_toggle, TRUE);
/* Repetitions */
e_dialog_spin_set (dialog->repeat_quantity, repeat.repetitions);
/* Duration */
normalize_duration (repeat.duration, &value, &units);
e_dialog_spin_set (dialog->repeat_value, value);
e_dialog_option_menu_set (dialog->repeat_unit, units, duration_units_map);
}
/* Fills the widgets with the values from the alarm component */
static void
alarm_to_dialog (Dialog *dialog, CalComponentAlarm *alarm)
{
CalAlarmAction action;
alarm_to_repeat_widgets (dialog, alarm);
cal_component_alarm_get_action (alarm, &action);
switch (action) {
case CAL_ALARM_NONE:
g_assert_not_reached ();
return;
case CAL_ALARM_AUDIO:
gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Audio Alarm Options"));
gtk_widget_show (dialog->aalarm_group);
gtk_widget_hide (dialog->dalarm_group);
gtk_widget_hide (dialog->malarm_group);
gtk_widget_hide (dialog->palarm_group);
alarm_to_aalarm_widgets (dialog, alarm);
break;
case CAL_ALARM_DISPLAY:
gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Message Alarm Options"));
gtk_widget_hide (dialog->aalarm_group);
gtk_widget_show (dialog->dalarm_group);
gtk_widget_hide (dialog->malarm_group);
gtk_widget_hide (dialog->palarm_group);
alarm_to_dalarm_widgets (dialog, alarm);
break;
case CAL_ALARM_EMAIL:
gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Email Alarm Options"));
gtk_widget_hide (dialog->aalarm_group);
gtk_widget_hide (dialog->dalarm_group);
gtk_widget_show (dialog->malarm_group);
gtk_widget_hide (dialog->palarm_group);
alarm_to_malarm_widgets (dialog, alarm);
break;
case CAL_ALARM_PROCEDURE:
gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Program Alarm Options"));
gtk_widget_hide (dialog->aalarm_group);
gtk_widget_hide (dialog->dalarm_group);
gtk_widget_hide (dialog->malarm_group);
gtk_widget_show (dialog->palarm_group);
alarm_to_palarm_widgets (dialog, alarm);
break;
case CAL_ALARM_UNKNOWN:
gtk_window_set_title (GTK_WINDOW (dialog->toplevel), _("Unknown Alarm Options"));
break;
default:
g_assert_not_reached ();
return;
}
}
/* Fills the alarm data with the values from the repeat/duration widgets */
static void
repeat_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm)
{
CalAlarmRepeat repeat;
if (!e_dialog_toggle_get (dialog->repeat_toggle)) {
repeat.repetitions = 0;
cal_component_alarm_set_repeat (alarm, repeat);
return;
}
repeat.repetitions = e_dialog_spin_get_int (dialog->repeat_quantity);
memset (&repeat.duration, 0, sizeof (repeat.duration));
switch (e_dialog_option_menu_get (dialog->repeat_unit, duration_units_map)) {
case DUR_MINUTES:
repeat.duration.minutes = e_dialog_spin_get_int (dialog->repeat_value);
break;
case DUR_HOURS:
repeat.duration.hours = e_dialog_spin_get_int (dialog->repeat_value);
break;
case DUR_DAYS:
repeat.duration.days = e_dialog_spin_get_int (dialog->repeat_value);
break;
default:
g_assert_not_reached ();
}
cal_component_alarm_set_repeat (alarm, repeat);
}
/* Fills the audio alarm data with the values from the widgets */
static void
aalarm_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm)
{
char *url;
icalattach *attach;
url = e_dialog_editable_get (dialog->aalarm_attach);
attach = icalattach_new_from_url (url ? url : "");
g_free (url);
cal_component_alarm_set_attach (alarm, attach);
icalattach_unref (attach);
}
/* Fills the display alarm data with the values from the widgets */
static void
dalarm_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm)
{
char *str;
CalComponentText description;
icalcomponent *icalcomp;
icalproperty *icalprop;
str = e_dialog_editable_get (dialog->dalarm_description);
description.value = str;
description.altrep = NULL;
cal_component_alarm_set_description (alarm, &description);
g_free (str);
/* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that
* we don't re-set the alarm's description */
icalcomp = cal_component_alarm_get_icalcomponent (alarm);
icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);
while (icalprop) {
const char *x_name;
x_name = icalproperty_get_x_name (icalprop);
if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
icalcomponent_remove_property (icalcomp, icalprop);
break;
}
icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
}
}
/* Fills the mail alarm data with the values from the widgets */
static void
malarm_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm)
{
char *str;
CalComponentText description;
GSList *attendee_list = NULL;
EDestination **destv;
icalcomponent *icalcomp;
icalproperty *icalprop;
int i;
/* Attendees */
bonobo_widget_get_property (BONOBO_WIDGET (dialog->malarm_addresses), "destinations",
&str, NULL);
destv = e_destination_importv (str);
g_free (str);
for (i = 0; destv[i] != NULL; i++) {
EDestination *dest;
CalComponentAttendee *a;
dest = destv[i];
a = g_new0 (CalComponentAttendee, 1);
a->value = e_destination_get_email (dest);
a->cn = e_destination_get_name (dest);
attendee_list = g_slist_append (attendee_list, a);
}
cal_component_alarm_set_attendee_list (alarm, attendee_list);
cal_component_free_attendee_list (attendee_list);
e_destination_freev (destv);
/* Description */
str = e_dialog_editable_get (dialog->malarm_description);
description.value = str;
description.altrep = NULL;
cal_component_alarm_set_description (alarm, &description);
g_free (str);
/* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that
* we don't re-set the alarm's description */
icalcomp = cal_component_alarm_get_icalcomponent (alarm);
icalprop = icalcomponent_get_first_property(icalcomp, ICAL_X_PROPERTY);
while (icalprop) {
const char *x_name;
x_name = icalproperty_get_x_name (icalprop);
if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
icalcomponent_remove_property (icalcomp, icalprop);
break;
}
icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
}
}
/* Fills the procedure alarm data with the values from the widgets */
static void
palarm_widgets_to_alarm (Dialog *dialog, CalComponentAlarm *alarm)
{
char *program;
icalattach *attach;
char *str;
CalComponentText description;
icalcomponent *icalcomp;
icalproperty *icalprop;
program = e_dialog_editable_get (dialog->palarm_program);
attach = icalattach_new_from_url (program ? program : "");
g_free (program);
cal_component_alarm_set_attach (alarm, attach);
icalattach_unref (attach);
str = e_dialog_editable_get (dialog->palarm_args);
description.value = str;
description.altrep = NULL;
cal_component_alarm_set_description (alarm, &description);
g_free (str);
/* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that
* we don't re-set the alarm's description */
icalcomp = cal_component_alarm_get_icalcomponent (alarm);
icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);
while (icalprop) {
const char *x_name;
x_name = icalproperty_get_x_name (icalprop);
if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
icalcomponent_remove_property (icalcomp, icalprop);
break;
}
icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
}
}
/* Fills the alarm data with the values from the widgets */
static void
dialog_to_alarm (Dialog *dialog, CalComponentAlarm *alarm)
{
CalAlarmAction action;
repeat_widgets_to_alarm (dialog, alarm);
cal_component_alarm_get_action (alarm, &action);
switch (action) {
case CAL_ALARM_NONE:
g_assert_not_reached ();
break;
case CAL_ALARM_AUDIO:
aalarm_widgets_to_alarm (dialog, alarm);
break;
case CAL_ALARM_DISPLAY:
dalarm_widgets_to_alarm (dialog, alarm);
break;
case CAL_ALARM_EMAIL:
malarm_widgets_to_alarm (dialog, alarm);
break;
case CAL_ALARM_PROCEDURE:
palarm_widgets_to_alarm (dialog, alarm);
break;
case CAL_ALARM_UNKNOWN:
break;
default:
g_assert_not_reached ();
}
}
/**
* alarm_options_dialog_run:
* @alarm: Alarm that is to be edited.
*
* Runs an alarm options dialog modally.
*
* Return value: TRUE if the dialog could be created, FALSE otherwise.
**/
gboolean
alarm_options_dialog_run (CalComponentAlarm *alarm, const char *email, gboolean repeat)
{
Dialog dialog;
g_return_val_if_fail (alarm != NULL, FALSE);
dialog.repeat = repeat;
dialog.email = email;
dialog.xml = glade_xml_new (EVOLUTION_GLADEDIR "/alarm-options.glade", NULL);
if (!dialog.xml) {
g_message ("alarm_options_dialog_new(): Could not load the Glade XML file!");
return FALSE;
}
if (!get_widgets (&dialog)) {
gtk_object_unref (GTK_OBJECT (dialog.xml));
return FALSE;
}
if (!setup_select_names (&dialog)) {
gtk_object_unref (GTK_OBJECT (dialog.xml));
return FALSE;
}
init_widgets (&dialog);
alarm_to_dialog (&dialog, alarm);
gtk_widget_show (dialog.toplevel);
gtk_main ();
if (!dialog.canceled)
dialog_to_alarm (&dialog, alarm);
gtk_widget_destroy (dialog.toplevel);
gtk_object_unref (GTK_OBJECT (dialog.xml));
return TRUE;
}
|