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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
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
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*
* Authors:
* Federico Mena-Quintero <federico@ximian.com>
* Miguel de Icaza <miguel@ximian.com>
* Seth Alves <alves@hungry.com>
* JP Rosevear <jpr@ximian.com>
* Hans Petter Jansson <hpj@ximian.com>
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <gtk/gtk.h>
#include <glib/gi18n.h>
#include <glade/glade.h>
#include <libedataserver/e-time-utils.h>
#include "e-util/e-dialog-widgets.h"
#include <libecal/e-cal-util.h>
#include <libecal/e-cal-time-util.h>
#include "e-util/e-dialog-widgets.h"
#include "e-util/e-util-private.h"
#include <libebook/e-destination.h>
#include <libedataserverui/e-name-selector.h>
#include <libical/icalattach.h>
#include "../calendar-config.h"
#include "comp-editor-util.h"
#include "alarm-dialog.h"
typedef struct {
/* Glade XML data */
GladeXML *xml;
/* The alarm */
ECalComponentAlarm *alarm;
/* The client */
ECal *ecal;
/* Toplevel */
GtkWidget *toplevel;
GtkWidget *action;
GtkWidget *interval_value;
GtkWidget *value_units;
GtkWidget *relative;
GtkWidget *time;
/* Alarm repeat widgets */
GtkWidget *repeat_toggle;
GtkWidget *repeat_group;
GtkWidget *repeat_quantity;
GtkWidget *repeat_value;
GtkWidget *repeat_unit;
GtkWidget *option_notebook;
/* Display alarm widgets */
GtkWidget *dalarm_group;
GtkWidget *dalarm_message;
GtkWidget *dalarm_description;
/* Audio alarm widgets */
GtkWidget *aalarm_group;
GtkWidget *aalarm_sound;
GtkWidget *aalarm_file_chooser;
/* Mail alarm widgets */
const char *email;
GtkWidget *malarm_group;
GtkWidget *malarm_address_group;
GtkWidget *malarm_addresses;
GtkWidget *malarm_addressbook;
GtkWidget *malarm_message;
GtkWidget *malarm_description;
/* Procedure alarm widgets */
GtkWidget *palarm_group;
GtkWidget *palarm_program;
GtkWidget *palarm_args;
/* Addressbook name selector */
ENameSelector *name_selector;
} Dialog;
static const char *section_name = "Send To";
/* "relative" types */
enum {
BEFORE,
AFTER
};
/* Time units */
enum {
MINUTES,
HOURS,
DAYS
};
/* Option menu maps */
static const int action_map[] = {
E_CAL_COMPONENT_ALARM_DISPLAY,
E_CAL_COMPONENT_ALARM_AUDIO,
E_CAL_COMPONENT_ALARM_PROCEDURE,
E_CAL_COMPONENT_ALARM_EMAIL,
-1
};
static const char *action_map_cap[] = {
CAL_STATIC_CAPABILITY_NO_DISPLAY_ALARMS,
CAL_STATIC_CAPABILITY_NO_AUDIO_ALARMS,
CAL_STATIC_CAPABILITY_NO_PROCEDURE_ALARMS,
CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS
};
static const int value_map[] = {
MINUTES,
HOURS,
DAYS,
-1
};
static const int relative_map[] = {
BEFORE,
AFTER,
-1
};
static const int time_map[] = {
E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START,
E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_END,
-1
};
enum duration_units {
DUR_MINUTES,
DUR_HOURS,
DUR_DAYS
};
static const int duration_units_map[] = {
DUR_MINUTES,
DUR_HOURS,
DUR_DAYS,
-1
};
static void populate_widgets_from_alarm (Dialog *dialog);
static void action_selection_done_cb (GtkMenuShell *menu_shell, gpointer data);
/* Fills the widgets with default values */
static void
clear_widgets (Dialog *dialog)
{
/* Sane defaults */
e_dialog_option_menu_set (dialog->action, E_CAL_COMPONENT_ALARM_DISPLAY, action_map);
e_dialog_spin_set (dialog->interval_value, 15);
e_dialog_option_menu_set (dialog->value_units, MINUTES, value_map);
e_dialog_option_menu_set (dialog->relative, BEFORE, relative_map);
e_dialog_option_menu_set (dialog->time, E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START, time_map);
gtk_widget_set_sensitive (dialog->repeat_group, FALSE);
gtk_widget_set_sensitive (dialog->dalarm_group, FALSE);
gtk_widget_set_sensitive (dialog->aalarm_group, FALSE);
gtk_widget_set_sensitive (dialog->malarm_group, FALSE);
gtk_notebook_set_current_page (GTK_NOTEBOOK (dialog->option_notebook), 0);
}
/* fill_widgets handler for the alarm page */
static void
alarm_to_dialog (Dialog *dialog)
{
GtkWidget *menu;
GList *l;
gboolean repeat;
ECalComponentAlarmAction action;
char *email;
int i;
/* Clean the page */
clear_widgets (dialog);
/* Alarm types */
menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (dialog->action));
for (i = 0, l = GTK_MENU_SHELL (menu)->children; action_map[i] != -1; i++, l = l->next) {
if (e_cal_get_static_capability (dialog->ecal, action_map_cap[i]))
gtk_widget_set_sensitive (l->data, FALSE);
else
gtk_widget_set_sensitive (l->data, TRUE);
}
/* Set a default address if possible */
if (!e_cal_get_static_capability (dialog->ecal, CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS)
&& !e_cal_component_alarm_has_attendees (dialog->alarm)
&& e_cal_get_alarm_email_address (dialog->ecal, &email, NULL)) {
ECalComponentAttendee *a;
GSList attendee_list;
a = g_new0 (ECalComponentAttendee, 1);
a->value = email;
attendee_list.data = a;
attendee_list.next = NULL;
e_cal_component_alarm_set_attendee_list (dialog->alarm, &attendee_list);
g_free (email);
g_free (a);
}
/* If we can repeat */
repeat = !e_cal_get_static_capability (dialog->ecal, CAL_STATIC_CAPABILITY_NO_ALARM_REPEAT);
gtk_widget_set_sensitive (dialog->repeat_toggle, repeat);
/* if we are editing a exiting alarm */
e_cal_component_alarm_get_action (dialog->alarm, &action);
if (action)
populate_widgets_from_alarm (dialog);
}
static void
alarm_to_repeat_widgets (Dialog *dialog, ECalComponentAlarm *alarm)
{
ECalComponentAlarmRepeat repeat;
e_cal_component_alarm_get_repeat (dialog->alarm, &repeat);
if ( repeat.repetitions ) {
e_dialog_toggle_set (dialog->repeat_toggle, TRUE);
e_dialog_spin_set (dialog->repeat_quantity, repeat.repetitions);
} else
return;
if ( repeat.duration.minutes ) {
e_dialog_option_menu_set (dialog->repeat_unit, DUR_MINUTES, duration_units_map);
e_dialog_spin_set (dialog->repeat_value, repeat.duration.minutes);
}
if ( repeat.duration.hours ) {
e_dialog_option_menu_set (dialog->repeat_unit, DUR_HOURS, duration_units_map);
e_dialog_spin_set (dialog->repeat_value, repeat.duration.hours);
}
if ( repeat.duration.days ) {
e_dialog_option_menu_set (dialog->repeat_unit, DUR_DAYS, duration_units_map);
e_dialog_spin_set (dialog->repeat_value, repeat.duration.days);
}
}
static void
repeat_widgets_to_alarm (Dialog *dialog, ECalComponentAlarm *alarm)
{
ECalComponentAlarmRepeat repeat;
if (!e_dialog_toggle_get (dialog->repeat_toggle)) {
repeat.repetitions = 0;
e_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_return_if_reached ();
}
e_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, ECalComponentAlarm *alarm)
{
char *url;
icalattach *attach;
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->aalarm_sound)))
return;
url = gtk_file_chooser_get_uri (
GTK_FILE_CHOOSER (dialog->aalarm_file_chooser));
attach = icalattach_new_from_url (url ? url : "");
g_free (url);
e_cal_component_alarm_set_attach (alarm, attach);
icalattach_unref (attach);
}
/* Fills the widgets with audio alarm data */
static void
alarm_to_aalarm_widgets (Dialog *dialog, ECalComponentAlarm *alarm)
{
const char *url;
icalattach *attach;
e_cal_component_alarm_get_attach (alarm, (&attach));
url = icalattach_get_url (attach);
icalattach_unref (attach);
if ( !(url && *url) )
return;
e_dialog_toggle_set (dialog->aalarm_sound, TRUE);
gtk_file_chooser_set_uri (
GTK_FILE_CHOOSER (dialog->aalarm_file_chooser), url);
}
/* Fills the widgets with display alarm data */
static void
alarm_to_dalarm_widgets (Dialog *dialog, ECalComponentAlarm *alarm )
{
ECalComponentText description;
GtkTextBuffer *text_buffer;
e_cal_component_alarm_get_description (alarm, &description);
if (description.value) {
e_dialog_toggle_set (dialog->dalarm_message, TRUE);
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description));
gtk_text_buffer_set_text (text_buffer, description.value, -1);
}
}
/* Fills the display alarm data with the values from the widgets */
static void
dalarm_widgets_to_alarm (Dialog *dialog, ECalComponentAlarm *alarm)
{
char *str;
ECalComponentText description;
GtkTextBuffer *text_buffer;
GtkTextIter text_iter_start, text_iter_end;
icalcomponent *icalcomp;
icalproperty *icalprop;
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->dalarm_message)))
return;
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description));
gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start);
gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end);
str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE);
description.value = str;
description.altrep = NULL;
e_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 = e_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, ECalComponentAlarm *alarm)
{
char *str;
ECalComponentText description;
GSList *attendee_list = NULL;
GtkTextBuffer *text_buffer;
GtkTextIter text_iter_start, text_iter_end;
ENameSelectorModel *name_selector_model;
EDestinationStore *destination_store;
GList *destinations;
icalcomponent *icalcomp;
icalproperty *icalprop;
GList *l;
/* Attendees */
name_selector_model = e_name_selector_peek_model (dialog->name_selector);
e_name_selector_model_peek_section (name_selector_model, section_name, NULL, &destination_store);
destinations = e_destination_store_list_destinations (destination_store);
for (l = destinations; l; l = g_list_next (l)) {
EDestination *dest;
ECalComponentAttendee *a;
dest = l->data;
a = g_new0 (ECalComponentAttendee, 1);
a->value = e_destination_get_email (dest);
a->cn = e_destination_get_name (dest);
attendee_list = g_slist_append (attendee_list, a);
}
e_cal_component_alarm_set_attendee_list (alarm, attendee_list);
e_cal_component_free_attendee_list (attendee_list);
g_list_free (destinations);
if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->malarm_message)))
return;
/* Description */
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->malarm_description));
gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start);
gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end);
str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE);
description.value = str;
description.altrep = NULL;
e_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 = e_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 widgets from mail alarm data */
static void
alarm_to_malarm_widgets (Dialog *dialog, ECalComponentAlarm *alarm )
{
ENameSelectorModel *name_selector_model;
EDestinationStore *destination_store;
ECalComponentText description;
GtkTextBuffer *text_buffer;
GSList *attendee_list, *l;
int len;
/* Attendees */
name_selector_model = e_name_selector_peek_model (dialog->name_selector);
e_name_selector_model_peek_section (name_selector_model, section_name, NULL, &destination_store);
e_cal_component_alarm_get_attendee_list (alarm, &attendee_list);
len = g_slist_length (attendee_list);
if (len > 0) {
for (l = attendee_list; l; l = g_slist_next (l)) {
ECalComponentAttendee *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) {
if (!strncasecmp (a->value, "MAILTO:", 7))
e_destination_set_email (dest, a->value + 7);
else
e_destination_set_email (dest, a->value);
}
e_destination_store_append_destination (destination_store, dest);
g_object_unref(GTK_OBJECT (dest));
}
e_cal_component_free_attendee_list (attendee_list);
}
/* Description */
e_cal_component_alarm_get_description (alarm, &description);
if (description.value) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->malarm_message), TRUE);
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->malarm_description));
gtk_text_buffer_set_text (text_buffer, description.value, -1);
}
}
/* Fills the widgets from procedure alarm data */
static void
alarm_to_palarm_widgets (Dialog *dialog, ECalComponentAlarm *alarm)
{
ECalComponentText description;
const char *url;
icalattach *attach;
e_cal_component_alarm_get_attach (alarm, (&attach));
url = icalattach_get_url (attach);
icalattach_unref (attach);
if ( !(url && *url) )
return;
e_dialog_editable_set (dialog->palarm_program, url);
e_cal_component_alarm_get_description (alarm, &description);
e_dialog_editable_set (dialog->palarm_args, description.value);
}
/* Fills the procedure alarm data with the values from the widgets */
static void
palarm_widgets_to_alarm (Dialog *dialog, ECalComponentAlarm *alarm)
{
char *program;
icalattach *attach;
char *str;
ECalComponentText description;
icalcomponent *icalcomp;
icalproperty *icalprop;
program = e_dialog_editable_get (dialog->palarm_program);
attach = icalattach_new_from_url (program ? program : "");
g_free (program);
e_cal_component_alarm_set_attach (alarm, attach);
icalattach_unref (attach);
str = e_dialog_editable_get (dialog->palarm_args);
description.value = str;
description.altrep = NULL;
e_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 = e_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);
}
}
static void
populate_widgets_from_alarm (Dialog *dialog)
{
ECalComponentAlarmTrigger *trigger;
ECalComponentAlarmAction *action;
action = g_new0 (ECalComponentAlarmAction, 1);
e_cal_component_alarm_get_action (dialog->alarm, action);
g_return_if_fail ( action != NULL );
trigger = g_new0 (ECalComponentAlarmTrigger, 1);
e_cal_component_alarm_get_trigger (dialog->alarm, trigger);
g_return_if_fail ( trigger != NULL );
if ( *action == E_CAL_COMPONENT_ALARM_NONE )
return;
gtk_window_set_title (GTK_WINDOW (dialog->toplevel),_("Edit Alarm"));
/* Alarm Types */
switch ( trigger->type ) {
case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START:
e_dialog_option_menu_set (dialog->time, E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START, time_map);
break;
case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_END:
e_dialog_option_menu_set (dialog->time, E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_END, time_map);
break;
default:
g_warning ("%s: Unexpected alarm type (%d)", G_STRLOC, trigger->type);
}
switch ( trigger->u.rel_duration.is_neg ){
case 1:
e_dialog_option_menu_set (dialog->relative, BEFORE, relative_map);
break;
case 0:
e_dialog_option_menu_set (dialog->relative, AFTER, relative_map);
break;
}
if ( trigger->u.rel_duration.days ) {
e_dialog_option_menu_set (dialog->value_units, DAYS, value_map);
e_dialog_spin_set (dialog->interval_value, trigger->u.rel_duration.days);
} else if ( trigger->u.rel_duration.hours ) {
e_dialog_option_menu_set (dialog->value_units, HOURS, value_map);
e_dialog_spin_set (dialog->interval_value, trigger->u.rel_duration.hours);
} else if ( trigger->u.rel_duration.minutes ) {
e_dialog_option_menu_set (dialog->value_units, MINUTES, value_map);
e_dialog_spin_set (dialog->interval_value, trigger->u.rel_duration.minutes);
} else {
e_dialog_option_menu_set (dialog->value_units, MINUTES, value_map);
e_dialog_spin_set (dialog->interval_value, 0);
}
/* Repeat options */
alarm_to_repeat_widgets (dialog, dialog->alarm);
/* Alarm options */
e_dialog_option_menu_set (dialog->action, *action, action_map);
action_selection_done_cb (GTK_MENU_SHELL (dialog->action), dialog);
switch (*action) {
case E_CAL_COMPONENT_ALARM_AUDIO:
alarm_to_aalarm_widgets (dialog, dialog->alarm);
break;
case E_CAL_COMPONENT_ALARM_DISPLAY:
alarm_to_dalarm_widgets (dialog, dialog->alarm);
break;
case E_CAL_COMPONENT_ALARM_EMAIL:
alarm_to_malarm_widgets (dialog, dialog->alarm);
break;
case E_CAL_COMPONENT_ALARM_PROCEDURE:
alarm_to_palarm_widgets (dialog, dialog->alarm);
break;
default:
g_warning ("%s: Unexpected alarm action (%d)", G_STRLOC, *action);
}
}
/* fill_component handler for the alarm page */
static void
dialog_to_alarm (Dialog *dialog)
{
ECalComponentAlarmTrigger trigger;
ECalComponentAlarmAction action;
/* Fill out the alarm */
memset (&trigger, 0, sizeof (ECalComponentAlarmTrigger));
trigger.type = e_dialog_option_menu_get (dialog->time, time_map);
if (e_dialog_option_menu_get (dialog->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 (dialog->value_units, value_map)) {
case MINUTES:
trigger.u.rel_duration.minutes =
e_dialog_spin_get_int (dialog->interval_value);
break;
case HOURS:
trigger.u.rel_duration.hours =
e_dialog_spin_get_int (dialog->interval_value);
break;
case DAYS:
trigger.u.rel_duration.days =
e_dialog_spin_get_int (dialog->interval_value);
break;
default:
g_return_if_reached ();
}
e_cal_component_alarm_set_trigger (dialog->alarm, trigger);
action = e_dialog_option_menu_get (dialog->action, action_map);
e_cal_component_alarm_set_action (dialog->alarm, action);
/* Repeat stuff */
repeat_widgets_to_alarm (dialog, dialog->alarm);
/* Options */
switch (action) {
case E_CAL_COMPONENT_ALARM_NONE:
g_return_if_reached ();
break;
case E_CAL_COMPONENT_ALARM_AUDIO:
aalarm_widgets_to_alarm (dialog, dialog->alarm);
break;
case E_CAL_COMPONENT_ALARM_DISPLAY:
dalarm_widgets_to_alarm (dialog, dialog->alarm);
break;
case E_CAL_COMPONENT_ALARM_EMAIL:
malarm_widgets_to_alarm (dialog, dialog->alarm);
break;
case E_CAL_COMPONENT_ALARM_PROCEDURE:
palarm_widgets_to_alarm (dialog, dialog->alarm);
break;
case E_CAL_COMPONENT_ALARM_UNKNOWN:
break;
default:
g_return_if_reached ();
}
}
/* Gets the widgets from the XML file and returns TRUE 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-dialog");
if (!dialog->toplevel)
return FALSE;
dialog->action = GW ("action");
dialog->interval_value = GW ("interval-value");
dialog->value_units = GW ("value-units");
dialog->relative = GW ("relative");
dialog->time = GW ("time");
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->option_notebook = GW ("option-notebook");
dialog->dalarm_group = GW ("dalarm-group");
dialog->dalarm_message = GW ("dalarm-message");
dialog->dalarm_description = GW ("dalarm-description");
dialog->aalarm_group = GW ("aalarm-group");
dialog->aalarm_sound = GW ("aalarm-sound");
dialog->aalarm_file_chooser = GW ("aalarm-file-chooser");
dialog->malarm_group = GW ("malarm-group");
dialog->malarm_address_group = GW ("malarm-address-group");
dialog->malarm_addressbook = GW ("malarm-addressbook");
dialog->malarm_message = GW ("malarm-message");
dialog->malarm_description = GW ("malarm-description");
dialog->palarm_group = GW ("palarm-group");
dialog->palarm_program = GW ("palarm-program");
dialog->palarm_args = GW ("palarm-args");
#undef GW
return (dialog->action
&& dialog->interval_value
&& dialog->value_units
&& dialog->relative
&& dialog->time
&& dialog->repeat_toggle
&& dialog->repeat_group
&& dialog->repeat_quantity
&& dialog->repeat_value
&& dialog->repeat_unit
&& dialog->option_notebook
&& dialog->dalarm_group
&& dialog->dalarm_message
&& dialog->dalarm_description
&& dialog->aalarm_group
&& dialog->aalarm_sound
&& dialog->aalarm_file_chooser
&& dialog->malarm_group
&& dialog->malarm_address_group
&& dialog->malarm_addressbook
&& dialog->malarm_message
&& dialog->malarm_description
&& dialog->palarm_group
&& dialog->palarm_program
&& dialog->palarm_args);
}
#if 0
/* Callback used when the alarm options button is clicked */
static void
show_options (Dialog *dialog)
{
gboolean repeat;
char *email;
e_cal_component_alarm_set_action (dialog->alarm,
e_dialog_option_menu_get (dialog->action, action_map));
repeat = !e_cal_get_static_capability (dialog->ecal, CAL_STATIC_CAPABILITY_NO_ALARM_REPEAT);
if (e_cal_get_static_capability (dialog->ecal, CAL_STATIC_CAPABILITY_NO_EMAIL_ALARMS)
|| e_cal_get_alarm_email_address (dialog->ecal, &email, NULL)) {
if (!alarm_options_dialog_run (dialog->toplevel, dialog->alarm, email, repeat))
g_message (G_STRLOC ": not create the alarm options dialog");
}
}
#endif
static void
addressbook_clicked_cb (GtkWidget *widget, gpointer data)
{
Dialog *dialog = data;
ENameSelectorDialog *name_selector_dialog;
name_selector_dialog = e_name_selector_peek_dialog (dialog->name_selector);
gtk_widget_show (GTK_WIDGET (name_selector_dialog));
}
static void
addressbook_response_cb (GtkWidget *widget, gint response, gpointer data)
{
Dialog *dialog = data;
ENameSelectorDialog *name_selector_dialog;
name_selector_dialog = e_name_selector_peek_dialog (dialog->name_selector);
gtk_widget_hide (GTK_WIDGET (name_selector_dialog));
}
static gboolean
setup_select_names (Dialog *dialog)
{
ENameSelectorModel *name_selector_model;
ENameSelectorDialog *name_selector_dialog;
dialog->name_selector = e_name_selector_new ();
name_selector_model = e_name_selector_peek_model (dialog->name_selector);
e_name_selector_model_add_section (name_selector_model, section_name, section_name, NULL);
dialog->malarm_addresses =
GTK_WIDGET (e_name_selector_peek_section_entry (dialog->name_selector, section_name));
gtk_widget_show (dialog->malarm_addresses);
gtk_box_pack_end_defaults (GTK_BOX (dialog->malarm_address_group), dialog->malarm_addresses);
g_signal_connect (G_OBJECT (dialog->malarm_addressbook), "clicked",
G_CALLBACK (addressbook_clicked_cb), dialog);
name_selector_dialog = e_name_selector_peek_dialog (dialog->name_selector);
g_signal_connect (name_selector_dialog, "response",
G_CALLBACK (addressbook_response_cb), dialog);
return 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 = data;
gboolean active;
active = gtk_toggle_button_get_active (toggle);
gtk_widget_set_sensitive (dialog->repeat_group, active);
}
static void
check_custom_sound (Dialog *dialog)
{
char *str, *dir;
gboolean sens;
str = gtk_file_chooser_get_filename (
GTK_FILE_CHOOSER (dialog->aalarm_file_chooser));
if ( str && *str ) {
dir = g_path_get_dirname (str);
if ( dir && *dir ) {
calendar_config_set_dir_path (dir);
}
}
sens = e_dialog_toggle_get (dialog->aalarm_sound) ? str && *str : TRUE;
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog->toplevel), GTK_RESPONSE_OK, sens);
g_free (str);
}
static void
aalarm_sound_toggled_cb (GtkToggleButton *toggle, gpointer data)
{
Dialog *dialog = data;
gboolean active;
active = gtk_toggle_button_get_active (toggle);
gtk_widget_set_sensitive (dialog->aalarm_group, active);
check_custom_sound (dialog);
}
static void
aalarm_attach_changed_cb (GtkWidget *widget, gpointer data)
{
Dialog *dialog = data;
check_custom_sound (dialog);
}
static void
check_custom_message (Dialog *dialog)
{
char *str;
GtkTextBuffer *text_buffer;
GtkTextIter text_iter_start, text_iter_end;
gboolean sens;
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description));
gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start);
gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end);
str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE);
sens = e_dialog_toggle_get (dialog->dalarm_message) ? str && *str : TRUE;
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog->toplevel), GTK_RESPONSE_OK, sens);
g_free (str);
}
static void
dalarm_message_toggled_cb (GtkToggleButton *toggle, gpointer data)
{
Dialog *dialog = data;
gboolean active;
active = gtk_toggle_button_get_active (toggle);
gtk_widget_set_sensitive (dialog->dalarm_group, active);
check_custom_message (dialog);
}
static void
dalarm_description_changed_cb (GtkWidget *widget, gpointer data)
{
Dialog *dialog = data;
check_custom_message (dialog);
}
static void
check_custom_program (Dialog *dialog)
{
char *str;
gboolean sens;
str = e_dialog_editable_get (dialog->palarm_program);
sens = str && *str;
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog->toplevel), GTK_RESPONSE_OK, sens);
}
static void
palarm_program_changed_cb (GtkWidget *widget, gpointer data)
{
Dialog *dialog = data;
check_custom_program (dialog);
}
static void
check_custom_email (Dialog *dialog)
{
char *str;
GtkTextBuffer *text_buffer;
GtkTextIter text_iter_start, text_iter_end;
ENameSelectorModel *name_selector_model;
EDestinationStore *destination_store;
GList *destinations;
gboolean sens;
name_selector_model = e_name_selector_peek_model (dialog->name_selector);
e_name_selector_model_peek_section (name_selector_model, section_name, NULL, &destination_store);
destinations = e_destination_store_list_destinations (destination_store);
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->malarm_description));
gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start);
gtk_text_buffer_get_end_iter (text_buffer, &text_iter_end);
str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE);
sens = (destinations != NULL) && (e_dialog_toggle_get (dialog->malarm_message) ? str && *str : TRUE);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog->toplevel), GTK_RESPONSE_OK, sens);
g_list_free (destinations);
}
static void
malarm_addresses_changed_cb (GtkWidget *editable,
gpointer data)
{
Dialog *dialog = data;
check_custom_email (dialog);
}
static void
malarm_message_toggled_cb (GtkToggleButton *toggle, gpointer data)
{
Dialog *dialog = data;
gboolean active;
active = gtk_toggle_button_get_active (toggle);
gtk_widget_set_sensitive (dialog->malarm_group, active);
check_custom_email (dialog);
}
static void
malarm_description_changed_cb (GtkWidget *widget, gpointer data)
{
Dialog *dialog = data;
check_custom_email (dialog);
}
static void
action_selection_done_cb (GtkMenuShell *menu_shell, gpointer data)
{
Dialog *dialog = data;
char *dir;
ECalComponentAlarmAction action;
int page = 0, i;
action = e_dialog_option_menu_get (dialog->action, action_map);
for (i = 0; action_map[i] != -1 ; i++) {
if (action == action_map[i]) {
page = i;
break;
}
}
gtk_notebook_set_current_page (
GTK_NOTEBOOK (dialog->option_notebook), page);
switch (action) {
case E_CAL_COMPONENT_ALARM_AUDIO:
dir = calendar_config_get_dir_path ();
if ( dir && *dir )
gtk_file_chooser_set_current_folder (
GTK_FILE_CHOOSER (dialog->aalarm_file_chooser),
dir);
g_free (dir);
check_custom_sound (dialog);
break;
case E_CAL_COMPONENT_ALARM_DISPLAY:
check_custom_message (dialog);
break;
case E_CAL_COMPONENT_ALARM_EMAIL:
check_custom_email (dialog);
break;
case E_CAL_COMPONENT_ALARM_PROCEDURE:
check_custom_program (dialog);
break;
default:
g_return_if_reached ();
return;
}
}
/* Hooks the widget signals */
static void
init_widgets (Dialog *dialog)
{
GtkWidget *menu;
GtkTextBuffer *text_buffer;
menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (dialog->action));
g_signal_connect (menu, "selection_done",
G_CALLBACK (action_selection_done_cb),
dialog);
g_signal_connect (G_OBJECT (dialog->repeat_toggle), "toggled",
G_CALLBACK (repeat_toggle_toggled_cb), dialog);
/* Handle custom sounds */
g_signal_connect (G_OBJECT (dialog->aalarm_sound), "toggled",
G_CALLBACK (aalarm_sound_toggled_cb), dialog);
g_signal_connect (G_OBJECT (dialog->aalarm_file_chooser), "selection-changed",
G_CALLBACK (aalarm_attach_changed_cb), dialog);
/* Handle custom messages */
g_signal_connect (G_OBJECT (dialog->dalarm_message), "toggled",
G_CALLBACK (dalarm_message_toggled_cb), dialog);
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description));
g_signal_connect (G_OBJECT (text_buffer), "changed",
G_CALLBACK (dalarm_description_changed_cb), dialog);
/* Handle program */
g_signal_connect (G_OBJECT (dialog->palarm_program), "changed",
G_CALLBACK (palarm_program_changed_cb), dialog);
/* Handle custom email */
g_signal_connect (G_OBJECT (dialog->malarm_message), "toggled",
G_CALLBACK (malarm_message_toggled_cb), dialog);
text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->malarm_description));
g_signal_connect (G_OBJECT (text_buffer), "changed",
G_CALLBACK (malarm_description_changed_cb), dialog);
g_signal_connect (dialog->malarm_addresses, "changed",
G_CALLBACK (malarm_addresses_changed_cb), dialog);
}
gboolean
alarm_dialog_run (GtkWidget *parent, ECal *ecal, ECalComponentAlarm *alarm)
{
Dialog dialog;
int response_id;
char *gladefile;
g_return_val_if_fail (alarm != NULL, FALSE);
dialog.alarm = alarm;
dialog.ecal = ecal;
gladefile = g_build_filename (EVOLUTION_GLADEDIR,
"alarm-dialog.glade",
NULL);
dialog.xml = glade_xml_new (gladefile, NULL, NULL);
g_free (gladefile);
if (!dialog.xml) {
g_message (G_STRLOC ": Could not load the Glade XML file!");
return FALSE;
}
if (!get_widgets (&dialog)) {
g_object_unref(dialog.xml);
return FALSE;
}
if (!setup_select_names (&dialog)) {
g_object_unref (dialog.xml);
return FALSE;
}
init_widgets (&dialog);
alarm_to_dialog (&dialog);
gtk_widget_ensure_style (dialog.toplevel);
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog.toplevel)->vbox), 0);
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog.toplevel)->action_area), 12);
gtk_window_set_icon_name (
GTK_WINDOW (dialog.toplevel), "x-office-calendar");
gtk_window_set_transient_for (GTK_WINDOW (dialog.toplevel),
GTK_WINDOW (parent));
response_id = gtk_dialog_run (GTK_DIALOG (dialog.toplevel));
if (response_id == GTK_RESPONSE_OK)
dialog_to_alarm (&dialog);
gtk_widget_destroy (dialog.toplevel);
g_object_unref (dialog.xml);
return response_id == GTK_RESPONSE_OK ? TRUE : FALSE;
}
|