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
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* itip-model.c
*
* Copyright (C) 2001 Ximian, Inc.
*
* 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.
*
* Author: JP Rosevear
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib.h>
#include <liboaf/liboaf.h>
#include <bonobo/bonobo-control.h>
#include <bonobo/bonobo-widget.h>
#include <bonobo/bonobo-exception.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <libgnomevfs/gnome-vfs.h>
#include <gal/e-table/e-table-without.h>
#include <gal/e-table/e-cell-text.h>
#include <gal/e-table/e-cell-popup.h>
#include <gal/e-table/e-cell-combo.h>
#include <gal/util/e-unicode-i18n.h>
#include <e-book.h>
#include <e-card-types.h>
#include <e-card-cursor.h>
#include <e-card.h>
#include <e-card-simple.h>
#include <e-destination.h>
#include <cal-util/cal-component.h>
#include <cal-util/cal-util.h>
#include <cal-util/timeutil.h>
#include "Evolution-Addressbook-SelectNames.h"
#include "calendar-config.h"
#include "itip-utils.h"
#include "e-meeting-attendee.h"
#include "e-meeting-model.h"
#define SELECT_NAMES_OAFID "OAFIID:GNOME_Evolution_Addressbook_SelectNames"
enum columns {
ITIP_ADDRESS_COL,
ITIP_MEMBER_COL,
ITIP_TYPE_COL,
ITIP_ROLE_COL,
ITIP_RSVP_COL,
ITIP_DELTO_COL,
ITIP_DELFROM_COL,
ITIP_STATUS_COL,
ITIP_CN_COL,
ITIP_LANGUAGE_COL,
ITIP_COLUMN_COUNT
};
struct _EMeetingModelPrivate
{
GPtrArray *attendees;
ETableWithout *without;
CalClient *client;
icaltimezone *zone;
EBook *ebook;
gboolean book_loaded;
gboolean book_load_wait;
GList *refresh_callbacks;
GList *refresh_data;
gint refresh_count;
gboolean refreshing;
/* For invite others dialogs */
GNOME_Evolution_Addressbook_SelectNames corba_select_names;
};
#define BUF_SIZE 1024
static char *sections[] = {N_("Chair Persons"),
N_("Required Participants"),
N_("Optional Participants"),
N_("Non-Participants"),
NULL};
static icalparameter_role roles[] = {ICAL_ROLE_CHAIR,
ICAL_ROLE_REQPARTICIPANT,
ICAL_ROLE_OPTPARTICIPANT,
ICAL_ROLE_NONPARTICIPANT,
ICAL_ROLE_NONE};
typedef struct _EMeetingModelAttendeeRefreshData EMeetingModelAttendeeRefreshData;
struct _EMeetingModelAttendeeRefreshData {
char buffer[BUF_SIZE];
GString *string;
EMeetingAttendee *ia;
};
typedef struct _EMeetingModelRefreshData EMeetingModelRefreshData;
struct _EMeetingModelRefreshData {
EMeetingModel *im;
EMeetingModelAttendeeRefreshData attendee_data;
};
static void class_init (EMeetingModelClass *klass);
static void init (EMeetingModel *model);
static void destroy (GtkObject *obj);
static void attendee_changed_cb (EMeetingAttendee *ia, gpointer data);
static void select_names_ok_cb (BonoboListener *listener,
char *event_name,
CORBA_any *arg,
CORBA_Environment *ev,
gpointer data);
static void table_destroy_cb (ETableScrolled *etable, gpointer data);
static ETableModelClass *parent_class = NULL;
GtkType
e_meeting_model_get_type (void)
{
static GtkType type = 0;
if (type == 0)
{
static const GtkTypeInfo info =
{
"EMeetingModel",
sizeof (EMeetingModel),
sizeof (EMeetingModelClass),
(GtkClassInitFunc) class_init,
(GtkObjectInitFunc) init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
type = gtk_type_unique (e_table_model_get_type (), &info);
}
return type;
}
static void
book_open_cb (EBook *book, EBookStatus status, gpointer data)
{
EMeetingModel *im = E_MEETING_MODEL (data);
EMeetingModelPrivate *priv;
priv = im->priv;
if (status == E_BOOK_STATUS_SUCCESS)
priv->book_loaded = TRUE;
else
g_warning ("Book not loaded");
if (priv->book_load_wait) {
priv->book_load_wait = FALSE;
gtk_main_quit ();
}
}
static void
start_addressbook_server (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
gchar *uri, *path;
priv = im->priv;
priv->ebook = e_book_new ();
path = g_concat_dir_and_file (g_get_home_dir (),
"evolution/local/Contacts/addressbook.db");
uri = g_strdup_printf ("file://%s", path);
g_free (path);
e_book_load_uri (priv->ebook, uri, book_open_cb, im);
g_free (uri);
}
static EMeetingAttendee *
find_match (EMeetingModel *im, const char *address, int *pos)
{
EMeetingModelPrivate *priv;
EMeetingAttendee *ia;
const gchar *ia_address;
int i;
priv = im->priv;
if (address == NULL)
return NULL;
/* Make sure we can add the new delegatee person */
for (i = 0; i < priv->attendees->len; i++) {
ia = g_ptr_array_index (priv->attendees, i);
ia_address = e_meeting_attendee_get_address (ia);
if (ia_address != NULL && !g_strcasecmp (itip_strip_mailto (ia_address), itip_strip_mailto (address))) {
if (pos != NULL)
*pos = i;
return ia;
}
}
return NULL;
}
static icalparameter_cutype
text_to_type (const char *type)
{
if (!g_strcasecmp (type, _("Individual")))
return ICAL_CUTYPE_INDIVIDUAL;
else if (!g_strcasecmp (type, _("Group")))
return ICAL_CUTYPE_GROUP;
else if (!g_strcasecmp (type, _("Resource")))
return ICAL_CUTYPE_RESOURCE;
else if (!g_strcasecmp (type, _("Room")))
return ICAL_CUTYPE_ROOM;
else
return ICAL_CUTYPE_NONE;
}
static char *
type_to_text (icalparameter_cutype type)
{
switch (type) {
case ICAL_CUTYPE_INDIVIDUAL:
return _("Individual");
case ICAL_CUTYPE_GROUP:
return _("Group");
case ICAL_CUTYPE_RESOURCE:
return _("Resource");
case ICAL_CUTYPE_ROOM:
return _("Room");
default:
return _("Unknown");
}
return NULL;
}
static icalparameter_role
text_to_role (const char *role)
{
if (!g_strcasecmp (role, _("Chair")))
return ICAL_ROLE_CHAIR;
else if (!g_strcasecmp (role, _("Required Participant")))
return ICAL_ROLE_REQPARTICIPANT;
else if (!g_strcasecmp (role, _("Optional Participant")))
return ICAL_ROLE_OPTPARTICIPANT;
else if (!g_strcasecmp (role, _("Non-Participant")))
return ICAL_ROLE_NONPARTICIPANT;
else
return ICAL_ROLE_NONE;
}
static char *
role_to_text (icalparameter_role role)
{
switch (role) {
case ICAL_ROLE_CHAIR:
return _("Chair");
case ICAL_ROLE_REQPARTICIPANT:
return _("Required Participant");
case ICAL_ROLE_OPTPARTICIPANT:
return _("Optional Participant");
case ICAL_ROLE_NONPARTICIPANT:
return _("Non-Participant");
default:
return _("Unknown");
}
return NULL;
}
static gboolean
text_to_boolean (const char *role)
{
if (!g_strcasecmp (role, _("Yes")))
return TRUE;
else
return FALSE;
}
static char *
boolean_to_text (gboolean b)
{
if (b)
return _("Yes");
else
return _("No");
}
static icalparameter_partstat
text_to_partstat (const char *partstat)
{
if (!g_strcasecmp (partstat, _("Needs Action")))
return ICAL_PARTSTAT_NEEDSACTION;
else if (!g_strcasecmp (partstat, _("Accepted")))
return ICAL_PARTSTAT_ACCEPTED;
else if (!g_strcasecmp (partstat, _("Declined")))
return ICAL_PARTSTAT_DECLINED;
else if (!g_strcasecmp (partstat, _("Tentative")))
return ICAL_PARTSTAT_TENTATIVE;
else if (!g_strcasecmp (partstat, _("Delegated")))
return ICAL_PARTSTAT_DELEGATED;
else if (!g_strcasecmp (partstat, _("Completed")))
return ICAL_PARTSTAT_COMPLETED;
else if (!g_strcasecmp (partstat, _("In Process")))
return ICAL_PARTSTAT_INPROCESS;
else
return ICAL_PARTSTAT_NONE;
}
static char *
partstat_to_text (icalparameter_partstat partstat)
{
switch (partstat) {
case ICAL_PARTSTAT_NEEDSACTION:
return _("Needs Action");
case ICAL_PARTSTAT_ACCEPTED:
return _("Accepted");
case ICAL_PARTSTAT_DECLINED:
return _("Declined");
case ICAL_PARTSTAT_TENTATIVE:
return _("Tentative");
case ICAL_PARTSTAT_DELEGATED:
return _("Delegated");
case ICAL_PARTSTAT_COMPLETED:
return _("Completed");
case ICAL_PARTSTAT_INPROCESS:
return _("In Process");
case ICAL_PARTSTAT_NONE:
default:
return _("Unknown");
}
return NULL;
}
static int
column_count (ETableModel *etm)
{
return ITIP_COLUMN_COUNT;
}
static int
row_count (ETableModel *etm)
{
EMeetingModel *im;
EMeetingModelPrivate *priv;
im = E_MEETING_MODEL (etm);
priv = im->priv;
return (priv->attendees->len);
}
static void
append_row (ETableModel *etm, ETableModel *source, int row)
{
EMeetingModel *im;
EMeetingModelPrivate *priv;
EMeetingAttendee *ia;
char *address;
im = E_MEETING_MODEL (etm);
priv = im->priv;
address = (char *) e_table_model_value_at (source, ITIP_ADDRESS_COL, row);
if (find_match (im, address, NULL) != NULL) {
return;
}
ia = E_MEETING_ATTENDEE (e_meeting_attendee_new ());
e_meeting_attendee_set_address (ia, g_strdup_printf ("MAILTO:%s", address));
e_meeting_attendee_set_member (ia, g_strdup (e_table_model_value_at (source, ITIP_MEMBER_COL, row)));
e_meeting_attendee_set_cutype (ia, text_to_type (e_table_model_value_at (source, ITIP_TYPE_COL, row)));
e_meeting_attendee_set_role (ia, text_to_role (e_table_model_value_at (source, ITIP_ROLE_COL, row)));
e_meeting_attendee_set_rsvp (ia, text_to_boolean (e_table_model_value_at (source, ITIP_RSVP_COL, row)));
e_meeting_attendee_set_delto (ia, g_strdup (e_table_model_value_at (source, ITIP_DELTO_COL, row)));
e_meeting_attendee_set_delfrom (ia, g_strdup (e_table_model_value_at (source, ITIP_DELFROM_COL, row)));
e_meeting_attendee_set_status (ia, text_to_partstat (e_table_model_value_at (source, ITIP_STATUS_COL, row)));
e_meeting_attendee_set_cn (ia, g_strdup (e_table_model_value_at (source, ITIP_CN_COL, row)));
e_meeting_attendee_set_language (ia, g_strdup (e_table_model_value_at (source, ITIP_LANGUAGE_COL, row)));
e_meeting_model_add_attendee (E_MEETING_MODEL (etm), ia);
}
static void *
value_at (ETableModel *etm, int col, int row)
{
EMeetingModel *im;
EMeetingModelPrivate *priv;
EMeetingAttendee *ia;
im = E_MEETING_MODEL (etm);
priv = im->priv;
ia = g_ptr_array_index (priv->attendees, row);
switch (col) {
case ITIP_ADDRESS_COL:
return (void *)itip_strip_mailto (e_meeting_attendee_get_address (ia));
case ITIP_MEMBER_COL:
return (void *)e_meeting_attendee_get_member (ia);
case ITIP_TYPE_COL:
return type_to_text (e_meeting_attendee_get_cutype (ia));
case ITIP_ROLE_COL:
return role_to_text (e_meeting_attendee_get_role (ia));
case ITIP_RSVP_COL:
return boolean_to_text (e_meeting_attendee_get_rsvp (ia));
case ITIP_DELTO_COL:
return (void *)itip_strip_mailto (e_meeting_attendee_get_delto (ia));
case ITIP_DELFROM_COL:
return (void *)itip_strip_mailto (e_meeting_attendee_get_delfrom (ia));
case ITIP_STATUS_COL:
return partstat_to_text (e_meeting_attendee_get_status (ia));
case ITIP_CN_COL:
return (void *)e_meeting_attendee_get_cn (ia);
case ITIP_LANGUAGE_COL:
return (void *)e_meeting_attendee_get_language (ia);
}
return NULL;
}
static void
set_value_at (ETableModel *etm, int col, int row, const void *val)
{
EMeetingModel *im;
EMeetingModelPrivate *priv;
EMeetingAttendee *ia;
im = E_MEETING_MODEL (etm);
priv = im->priv;
ia = g_ptr_array_index (priv->attendees, row);
switch (col) {
case ITIP_ADDRESS_COL:
e_meeting_attendee_set_address (ia, g_strdup_printf ("MAILTO:%s", (char *) val));
break;
case ITIP_MEMBER_COL:
e_meeting_attendee_set_member (ia, g_strdup (val));
break;
case ITIP_TYPE_COL:
e_meeting_attendee_set_cutype (ia, text_to_type (val));
break;
case ITIP_ROLE_COL:
e_meeting_attendee_set_role (ia, text_to_role (val));
break;
case ITIP_RSVP_COL:
e_meeting_attendee_set_rsvp (ia, text_to_boolean (val));
break;
case ITIP_DELTO_COL:
e_meeting_attendee_set_delto (ia, g_strdup (val));
break;
case ITIP_DELFROM_COL:
e_meeting_attendee_set_delfrom (ia, g_strdup (val));
break;
case ITIP_STATUS_COL:
e_meeting_attendee_set_status (ia, text_to_partstat (val));
break;
case ITIP_CN_COL:
e_meeting_attendee_set_cn (ia, g_strdup (val));
break;
case ITIP_LANGUAGE_COL:
e_meeting_attendee_set_language (ia, g_strdup (val));
break;
}
}
static gboolean
is_cell_editable (ETableModel *etm, int col, int row)
{
switch (col) {
case ITIP_DELTO_COL:
case ITIP_DELFROM_COL:
return FALSE;
default:
}
return TRUE;
}
static void *
duplicate_value (ETableModel *etm, int col, const void *val)
{
return g_strdup (val);
}
static void
free_value (ETableModel *etm, int col, void *val)
{
g_free (val);
}
static void *
init_value (ETableModel *etm, int col)
{
switch (col) {
case ITIP_ADDRESS_COL:
return g_strdup ("");
case ITIP_MEMBER_COL:
return g_strdup ("");
case ITIP_TYPE_COL:
return g_strdup (_("Individual"));
case ITIP_ROLE_COL:
return g_strdup (_("Required Participant"));
case ITIP_RSVP_COL:
return g_strdup (_("Yes"));
case ITIP_DELTO_COL:
return g_strdup ("");
case ITIP_DELFROM_COL:
return g_strdup ("");
case ITIP_STATUS_COL:
return g_strdup (_("Needs Action"));
case ITIP_CN_COL:
return g_strdup ("");
case ITIP_LANGUAGE_COL:
return g_strdup ("en");
}
return g_strdup ("");
}
static gboolean
value_is_empty (ETableModel *etm, int col, const void *val)
{
switch (col) {
case ITIP_ADDRESS_COL:
case ITIP_MEMBER_COL:
case ITIP_DELTO_COL:
case ITIP_DELFROM_COL:
case ITIP_CN_COL:
if (val && !g_strcasecmp (val, ""))
return TRUE;
else
return FALSE;
default:
}
return TRUE;
}
static char *
value_to_string (ETableModel *etm, int col, const void *val)
{
return g_strdup (val);
}
static void *
get_key (ETableModel *source, int row, gpointer data)
{
EMeetingModel *im;
EMeetingModelPrivate *priv;
char *str;
im = E_MEETING_MODEL (source);
priv = im->priv;
str = value_at (source, ITIP_DELTO_COL, row);
if (str && *str)
return g_strdup ("delegator");
return g_strdup ("none");
}
static void *
duplicate_key (const void *key, gpointer data)
{
return g_strdup (key);
}
static void
free_gotten_key (void *key, gpointer data)
{
g_free (key);
}
static void
free_duplicated_key (void *key, gpointer data)
{
g_free (key);
}
static void
class_init (EMeetingModelClass *klass)
{
GtkObjectClass *object_class;
ETableModelClass *etm_class;
object_class = GTK_OBJECT_CLASS (klass);
etm_class = E_TABLE_MODEL_CLASS (klass);
parent_class = gtk_type_class (E_TABLE_MODEL_TYPE);
object_class->destroy = destroy;
etm_class->column_count = column_count;
etm_class->row_count = row_count;
etm_class->value_at = value_at;
etm_class->set_value_at = set_value_at;
etm_class->is_cell_editable = is_cell_editable;
etm_class->append_row = append_row;
etm_class->duplicate_value = duplicate_value;
etm_class->free_value = free_value;
etm_class->initialize_value = init_value;
etm_class->value_is_empty = value_is_empty;
etm_class->value_to_string = value_to_string;
}
static void
init (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
priv = g_new0 (EMeetingModelPrivate, 1);
im->priv = priv;
priv->attendees = g_ptr_array_new ();
priv->without = E_TABLE_WITHOUT (e_table_without_new (E_TABLE_MODEL (im),
g_str_hash,
g_str_equal,
get_key,
duplicate_key,
free_gotten_key,
free_duplicated_key,
NULL));
e_table_without_hide (priv->without, g_strdup ("delegator"));
priv->client = NULL;
priv->zone = icaltimezone_get_builtin_timezone (calendar_config_get_timezone ());
priv->ebook = NULL;
priv->book_loaded = FALSE;
priv->book_load_wait = FALSE;
priv->refreshing = FALSE;
start_addressbook_server (im);
}
static void
destroy (GtkObject *obj)
{
EMeetingModel *model = E_MEETING_MODEL (obj);
EMeetingModelPrivate *priv;
gint i;
priv = model->priv;
for (i = 0; i < priv->attendees->len; i++)
gtk_object_unref (GTK_OBJECT (g_ptr_array_index(priv->attendees, i)));
g_ptr_array_free (priv->attendees, FALSE);
if (priv->client != NULL)
gtk_object_unref (GTK_OBJECT (priv->client));
if (priv->ebook != NULL)
gtk_object_unref (GTK_OBJECT (priv->ebook));
if (priv->corba_select_names != CORBA_OBJECT_NIL) {
CORBA_Environment ev;
CORBA_exception_init (&ev);
bonobo_object_release_unref (priv->corba_select_names, &ev);
CORBA_exception_free (&ev);
}
g_free (priv);
}
GtkObject *
e_meeting_model_new (void)
{
return gtk_type_new (E_TYPE_MEETING_MODEL);
}
CalClient *
e_meeting_model_get_cal_client (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
priv = im->priv;
return priv->client;
}
void
e_meeting_model_set_cal_client (EMeetingModel *im, CalClient *client)
{
EMeetingModelPrivate *priv;
priv = im->priv;
if (priv->client != NULL)
gtk_object_unref (GTK_OBJECT (priv->client));
if (client != NULL)
gtk_object_ref (GTK_OBJECT (client));
priv->client = client;
}
icaltimezone *
e_meeting_model_get_zone (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
g_return_val_if_fail (im != NULL, NULL);
g_return_val_if_fail (E_IS_MEETING_MODEL (im), NULL);
priv = im->priv;
return priv->zone;
}
void
e_meeting_model_set_zone (EMeetingModel *im, icaltimezone *zone)
{
EMeetingModelPrivate *priv;
g_return_if_fail (im != NULL);
g_return_if_fail (E_IS_MEETING_MODEL (im));
priv = im->priv;
priv->zone = zone;
}
static ETableScrolled *
build_etable (ETableModel *model, const gchar *spec_file, const gchar *state_file)
{
GtkWidget *etable;
ETable *real_table;
ETableExtras *extras;
GList *strings;
ECell *popup_cell, *cell;
extras = e_table_extras_new ();
/* For type */
cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT);
popup_cell = e_cell_combo_new ();
e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell);
gtk_object_unref (GTK_OBJECT (cell));
strings = NULL;
strings = g_list_append (strings, (char*) U_("Individual"));
strings = g_list_append (strings, (char*) U_("Group"));
strings = g_list_append (strings, (char*) U_("Resource"));
strings = g_list_append (strings, (char*) U_("Room"));
strings = g_list_append (strings, (char*) U_("Unknown"));
e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), strings);
e_table_extras_add_cell (extras, "typeedit", popup_cell);
/* For role */
cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT);
popup_cell = e_cell_combo_new ();
e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell);
gtk_object_unref (GTK_OBJECT (cell));
strings = NULL;
strings = g_list_append (strings, (char*) U_("Chair"));
strings = g_list_append (strings, (char*) U_("Required Participant"));
strings = g_list_append (strings, (char*) U_("Optional Participant"));
strings = g_list_append (strings, (char*) U_("Non-Participant"));
strings = g_list_append (strings, (char*) U_("Unknown"));
e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), strings);
e_table_extras_add_cell (extras, "roleedit", popup_cell);
/* For rsvp */
cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT);
popup_cell = e_cell_combo_new ();
e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell);
gtk_object_unref (GTK_OBJECT (cell));
strings = NULL;
strings = g_list_append (strings, (char*) U_("Yes"));
strings = g_list_append (strings, (char*) U_("No"));
e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), strings);
e_table_extras_add_cell (extras, "rsvpedit", popup_cell);
/* For status */
cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT);
popup_cell = e_cell_combo_new ();
e_cell_popup_set_child (E_CELL_POPUP (popup_cell), cell);
gtk_object_unref (GTK_OBJECT (cell));
strings = NULL;
strings = g_list_append (strings, (char*) U_("Needs Action"));
strings = g_list_append (strings, (char*) U_("Accepted"));
strings = g_list_append (strings, (char*) U_("Declined"));
strings = g_list_append (strings, (char*) U_("Tentative"));
strings = g_list_append (strings, (char*) U_("Delegated"));
e_cell_combo_set_popdown_strings (E_CELL_COMBO (popup_cell), strings);
e_table_extras_add_cell (extras, "statusedit", popup_cell);
etable = e_table_scrolled_new_from_spec_file (model, extras, spec_file, NULL);
real_table = e_table_scrolled_get_table (E_TABLE_SCROLLED (etable));
gtk_object_set (GTK_OBJECT (real_table), "uniform_row_height", TRUE, NULL);
e_table_load_state (real_table, state_file);
#if 0
gtk_signal_connect (GTK_OBJECT (real_table),
"right_click", GTK_SIGNAL_FUNC (right_click_cb), mpage);
#endif
gtk_signal_connect (GTK_OBJECT (etable), "destroy",
GTK_SIGNAL_FUNC (table_destroy_cb), g_strdup (state_file));
gtk_object_unref (GTK_OBJECT (extras));
return E_TABLE_SCROLLED (etable);
}
void
e_meeting_model_add_attendee (EMeetingModel *im, EMeetingAttendee *ia)
{
EMeetingModelPrivate *priv;
priv = im->priv;
e_table_model_pre_change (E_TABLE_MODEL (im));
gtk_object_ref (GTK_OBJECT (ia));
g_ptr_array_add (priv->attendees, ia);
gtk_signal_connect (GTK_OBJECT (ia), "changed",
GTK_SIGNAL_FUNC (attendee_changed_cb), im);
e_table_model_row_inserted (E_TABLE_MODEL (im), row_count (E_TABLE_MODEL (im)) - 1);
}
EMeetingAttendee *
e_meeting_model_add_attendee_with_defaults (EMeetingModel *im)
{
EMeetingAttendee *ia;
char *str;
ia = E_MEETING_ATTENDEE (e_meeting_attendee_new ());
e_meeting_attendee_set_address (ia, init_value (E_TABLE_MODEL (im), ITIP_ADDRESS_COL));
e_meeting_attendee_set_member (ia, init_value (E_TABLE_MODEL (im), ITIP_MEMBER_COL));
str = init_value (E_TABLE_MODEL (im), ITIP_TYPE_COL);
e_meeting_attendee_set_cutype (ia, text_to_type (str));
g_free (str);
str = init_value (E_TABLE_MODEL (im), ITIP_ROLE_COL);
e_meeting_attendee_set_role (ia, text_to_role (str));
g_free (str);
str = init_value (E_TABLE_MODEL (im), ITIP_RSVP_COL);
e_meeting_attendee_set_role (ia, text_to_boolean (str));
g_free (str);
e_meeting_attendee_set_delto (ia, init_value (E_TABLE_MODEL (im), ITIP_DELTO_COL));
e_meeting_attendee_set_delfrom (ia, init_value (E_TABLE_MODEL (im), ITIP_DELFROM_COL));
str = init_value (E_TABLE_MODEL (im), ITIP_STATUS_COL);
e_meeting_attendee_set_status (ia, text_to_partstat (str));
g_free (str);
e_meeting_attendee_set_cn (ia, init_value (E_TABLE_MODEL (im), ITIP_CN_COL));
e_meeting_attendee_set_language (ia, init_value (E_TABLE_MODEL (im), ITIP_LANGUAGE_COL));
e_meeting_model_add_attendee (im, ia);
return ia;
}
void
e_meeting_model_remove_attendee (EMeetingModel *im, EMeetingAttendee *ia)
{
EMeetingModelPrivate *priv;
gint i, row = -1;
priv = im->priv;
for (i = 0; i < priv->attendees->len; i++) {
if (ia == g_ptr_array_index (priv->attendees, i)) {
row = i;
break;
}
}
if (row != -1) {
e_table_model_pre_change (E_TABLE_MODEL (im));
g_ptr_array_remove_index (priv->attendees, row);
gtk_object_unref (GTK_OBJECT (ia));
e_table_model_row_deleted (E_TABLE_MODEL (im), row);
}
}
void
e_meeting_model_remove_all_attendees (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
gint i, len;
priv = im->priv;
e_table_model_pre_change (E_TABLE_MODEL (im));
len = priv->attendees->len;
for (i = 0; i < len; i++) {
EMeetingAttendee *ia = g_ptr_array_index (priv->attendees, i);
gtk_object_unref (GTK_OBJECT (ia));
}
g_ptr_array_set_size (priv->attendees, 0);
e_table_model_rows_deleted (E_TABLE_MODEL (im), 0, len);
}
EMeetingAttendee *
e_meeting_model_find_attendee (EMeetingModel *im, const gchar *address, gint *row)
{
EMeetingModelPrivate *priv;
EMeetingAttendee *ia;
int i;
priv = im->priv;
if (address == NULL)
return NULL;
for (i = 0; i < priv->attendees->len; i++) {
const gchar *ia_address;
ia = g_ptr_array_index (priv->attendees, i);
ia_address = e_meeting_attendee_get_address (ia);
if (ia_address && !g_strcasecmp (itip_strip_mailto (ia_address), itip_strip_mailto (address))) {
if (row != NULL)
*row = i;
return ia;
}
}
return NULL;
}
EMeetingAttendee *
e_meeting_model_find_attendee_at_row (EMeetingModel *im, gint row)
{
EMeetingModelPrivate *priv;
g_return_val_if_fail (im != NULL, NULL);
g_return_val_if_fail (E_IS_MEETING_MODEL (im), NULL);
g_return_val_if_fail (row >= 0, NULL);
priv = im->priv;
g_return_val_if_fail (row < priv->attendees->len, NULL);
return g_ptr_array_index (priv->attendees, row);
}
gint
e_meeting_model_count_actual_attendees (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
priv = im->priv;
return e_table_model_row_count (E_TABLE_MODEL (priv->without));
}
const GPtrArray *
e_meeting_model_get_attendees (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
priv = im->priv;
return priv->attendees;
}
static icaltimezone *
find_zone (icalproperty *ip, icalcomponent *tz_top_level)
{
icalparameter *param;
icalcomponent *sub_comp;
const char *tzid;
icalcompiter iter;
if (tz_top_level == NULL)
return NULL;
param = icalproperty_get_first_parameter (ip, ICAL_TZID_PARAMETER);
tzid = icalparameter_get_tzid (param);
iter = icalcomponent_begin_component (tz_top_level, ICAL_VTIMEZONE_COMPONENT);
while ((sub_comp = icalcompiter_deref (&iter)) != NULL) {
icalcomponent *clone;
const char *tz_tzid;
tz_tzid = icalproperty_get_tzid (sub_comp);
if (!strcmp (tzid, tz_tzid)) {
icaltimezone *zone;
zone = icaltimezone_new ();
clone = icalcomponent_new_clone (sub_comp);
icaltimezone_set_component (zone, clone);
return zone;
}
icalcompiter_next (&iter);
}
return NULL;
}
static struct icaltimetype
convert_time (struct icaltimetype itt, icaltimezone *from, icaltimezone *to)
{
if (from == NULL)
from = icaltimezone_get_utc_timezone ();
icaltimezone_convert_time (&itt, from, to);
return itt;
}
static void
process_free_busy_comp (EMeetingAttendee *ia,
icalcomponent *fb_comp,
icaltimezone *zone,
icalcomponent *tz_top_level)
{
icalproperty *ip;
ip = icalcomponent_get_first_property (fb_comp, ICAL_DTSTART_PROPERTY);
if (ip != NULL) {
struct icaltimetype dtstart;
icaltimezone *ds_zone = NULL;
dtstart = icalproperty_get_dtstart (ip);
if (!dtstart.is_utc) {
ds_zone = find_zone (ip, tz_top_level);
if (ds_zone != NULL)
dtstart = convert_time (dtstart, ds_zone, zone);
}
e_meeting_attendee_set_start_busy_range (ia,
dtstart.year,
dtstart.month,
dtstart.day,
dtstart.hour,
dtstart.minute);
}
ip = icalcomponent_get_first_property (fb_comp, ICAL_DTEND_PROPERTY);
if (ip != NULL) {
struct icaltimetype dtend;
icaltimezone *de_zone = NULL;
dtend = icalproperty_get_dtend (ip);
if (!dtend.is_utc) {
de_zone = find_zone (ip, tz_top_level);
if (de_zone != NULL)
dtend = convert_time (dtend, de_zone, zone);
}
e_meeting_attendee_set_end_busy_range (ia,
dtend.year,
dtend.month,
dtend.day,
dtend.hour,
dtend.minute);
}
ip = icalcomponent_get_first_property (fb_comp, ICAL_FREEBUSY_PROPERTY);
while (ip != NULL) {
icalparameter *param;
struct icalperiodtype fb;
EMeetingFreeBusyType busy_type = E_MEETING_FREE_BUSY_LAST;
icalparameter_fbtype fbtype = ICAL_FBTYPE_BUSY;
fb = icalproperty_get_freebusy (ip);
param = icalproperty_get_first_parameter (ip, ICAL_FBTYPE_PARAMETER);
if (param != NULL)
fbtype = icalparameter_get_fbtype (param);
switch (fbtype) {
case ICAL_FBTYPE_BUSY:
busy_type = E_MEETING_FREE_BUSY_BUSY;
break;
case ICAL_FBTYPE_BUSYUNAVAILABLE:
busy_type = E_MEETING_FREE_BUSY_OUT_OF_OFFICE;
break;
case ICAL_FBTYPE_BUSYTENTATIVE:
busy_type = E_MEETING_FREE_BUSY_TENTATIVE;
break;
default:
}
if (busy_type != E_MEETING_FREE_BUSY_LAST) {
fb.start = convert_time (fb.start, NULL, zone);
fb.end = convert_time (fb.end, NULL, zone);
e_meeting_attendee_add_busy_period (ia,
fb.start.year,
fb.start.month,
fb.start.day,
fb.start.hour,
fb.start.minute,
fb.end.year,
fb.end.month,
fb.end.day,
fb.end.hour,
fb.end.minute,
busy_type);
}
ip = icalcomponent_get_next_property (fb_comp, ICAL_FREEBUSY_PROPERTY);
}
}
static void
process_callbacks (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
GList *l, *m;
priv = im->priv;
for (l = priv->refresh_callbacks, m = priv->refresh_data; l != NULL; l = l->next, m = m->next) {
EMeetingModelRefreshCallback cb = l->data;
cb (m->data);
}
g_list_free (priv->refresh_callbacks);
g_list_free (priv->refresh_data);
priv->refresh_callbacks = NULL;
priv->refresh_data = NULL;
priv->refreshing = FALSE;
}
static void
process_free_busy (EMeetingModel *im, EMeetingAttendee *ia, char *text)
{
EMeetingModelPrivate *priv;
icalcomponent *main_comp;
icalcomponent_kind kind = ICAL_NO_COMPONENT;
priv = im->priv;
main_comp = icalparser_parse_string (text);
if (main_comp == NULL)
return;
kind = icalcomponent_isa (main_comp);
if (kind == ICAL_VCALENDAR_COMPONENT) {
icalcompiter iter;
icalcomponent *tz_top_level, *sub_comp;
tz_top_level = cal_util_new_top_level ();
iter = icalcomponent_begin_component (main_comp, ICAL_VTIMEZONE_COMPONENT);
while ((sub_comp = icalcompiter_deref (&iter)) != NULL) {
icalcomponent *clone;
clone = icalcomponent_new_clone (sub_comp);
icalcomponent_add_component (tz_top_level, clone);
icalcompiter_next (&iter);
}
iter = icalcomponent_begin_component (main_comp, ICAL_VFREEBUSY_COMPONENT);
while ((sub_comp = icalcompiter_deref (&iter)) != NULL) {
process_free_busy_comp (ia, sub_comp, priv->zone, tz_top_level);
icalcompiter_next (&iter);
}
icalcomponent_free (tz_top_level);
} else if (kind == ICAL_VFREEBUSY_COMPONENT) {
process_free_busy_comp (ia, main_comp, priv->zone, NULL);
} else {
return;
}
icalcomponent_free (main_comp);
}
static void
async_close (GnomeVFSAsyncHandle *handle,
GnomeVFSResult result,
gpointer data)
{
EMeetingModelRefreshData *r_data = data;
EMeetingModelPrivate *priv;
process_free_busy (r_data->im, r_data->attendee_data.ia, r_data->attendee_data.string->str);
priv = r_data->im->priv;
priv->refresh_count--;
if (priv->refresh_count == 0)
process_callbacks (r_data->im);
}
static void
async_read (GnomeVFSAsyncHandle *handle,
GnomeVFSResult result,
gpointer buffer,
GnomeVFSFileSize requested,
GnomeVFSFileSize read,
gpointer data)
{
EMeetingModelRefreshData *r_data = data;
GnomeVFSFileSize buf_size = BUF_SIZE - 1;
if (result != GNOME_VFS_OK) {
gnome_vfs_async_close (handle, async_close, r_data);
return;
}
((char *)buffer)[read] = '\0';
r_data->attendee_data.string = g_string_append (r_data->attendee_data.string, buffer);
if (read < requested) {
gnome_vfs_async_close (handle, async_close, r_data);
return;
}
gnome_vfs_async_read (handle, r_data->attendee_data.buffer, buf_size, async_read, r_data);
}
static void
async_open (GnomeVFSAsyncHandle *handle,
GnomeVFSResult result,
gpointer data)
{
EMeetingModelRefreshData *r_data = data;
GnomeVFSFileSize buf_size = BUF_SIZE - 1;
gnome_vfs_async_read (handle, r_data->attendee_data.buffer, buf_size, async_read, r_data);
}
static void
cursor_cb (EBook *book, EBookStatus status, ECardCursor *cursor, gpointer data)
{
EMeetingModel *im = E_MEETING_MODEL (data);
EMeetingModelPrivate *priv;
int length, i, j;
if (status != E_BOOK_STATUS_SUCCESS)
return;
priv = im->priv;
length = e_card_cursor_get_length (cursor);
priv->refresh_count = 0;
for (i = 0; i < length; i ++) {
GnomeVFSAsyncHandle *handle;
ECard *card = e_card_cursor_get_nth (cursor, i);
EMeetingModelRefreshData *r_data = g_new0 (EMeetingModelRefreshData, 1);
EMeetingAttendee *ia = NULL;
if (card->fburl == NULL)
continue;
for (j = 0; j < priv->attendees->len; j++) {
ia = g_ptr_array_index (priv->attendees, j);
if (e_card_email_match_string (card, itip_strip_mailto (e_meeting_attendee_get_address (ia))))
break;
}
if (ia == NULL)
continue;
r_data->im = im;
r_data->attendee_data.string = g_string_new (NULL);
r_data->attendee_data.ia = ia;
priv->refresh_count++;
/* Read in free/busy data from the url */
gnome_vfs_async_open (&handle, card->fburl, GNOME_VFS_OPEN_READ, async_open, r_data);
}
}
void
e_meeting_model_refresh_busy_periods (EMeetingModel *im, EMeetingModelRefreshCallback call_back, gpointer data)
{
EMeetingModelPrivate *priv;
GPtrArray *not_found;
GString *string;
int i;
priv = im->priv;
priv->refresh_callbacks = g_list_append (priv->refresh_callbacks, call_back);
priv->refresh_data = g_list_append (priv->refresh_data, data);
if (priv->refreshing)
return;
priv->refreshing = TRUE;
/* To track what we don't find on the server */
not_found = g_ptr_array_new ();
g_ptr_array_set_size (not_found, priv->attendees->len);
for (i = 0; i < priv->attendees->len; i++)
g_ptr_array_index (not_found, i) = g_ptr_array_index (priv->attendees, i);
/* Check the server for free busy data */
if (priv->client) {
GList *fb_data, *users = NULL, *l;
time_t start, end, now = time (NULL);
start = now - 60 * 60 * 24;
end = time_add_week (now, 6);
for (i = 0; i < priv->attendees->len; i++) {
EMeetingAttendee *ia = g_ptr_array_index (priv->attendees, i);
const char *user;
user = itip_strip_mailto (e_meeting_attendee_get_address (ia));
users = g_list_append (users, g_strdup (user));
}
fb_data = cal_client_get_free_busy (priv->client, users, start, end);
g_list_foreach (users, (GFunc)g_free, NULL);
g_list_free (users);
for (l = fb_data; l != NULL; l = l->next) {
CalComponent *comp = l->data;
EMeetingAttendee *ia = NULL;
CalComponentOrganizer org;
/* Process the data for any attendees found */
cal_component_get_organizer (comp, &org);
for (i = 0; i < priv->attendees->len; i++) {
ia = g_ptr_array_index (priv->attendees, i);
if (org.value && !strcmp (org.value, e_meeting_attendee_get_address (ia))) {
g_ptr_array_remove_fast (not_found, ia);
break;
}
ia = NULL;
}
if (ia != NULL) {
char *comp_str;
comp_str = cal_component_get_as_string (comp);
process_free_busy (im, ia, comp_str);
g_free (comp_str);
}
}
}
/* Look for fburl's of attendee with no free busy info on server */
if (!priv->book_loaded) {
priv->book_load_wait = TRUE;
gtk_main ();
}
string = g_string_new ("(or ");
for (i = 0; i < not_found->len; i++) {
EMeetingAttendee *ia = g_ptr_array_index (not_found, i);
char *query;
if (!e_meeting_attendee_is_set_address (ia))
continue;
e_meeting_attendee_clear_busy_periods (ia);
query = g_strdup_printf ("(contains \"email\" \"%s\")", itip_strip_mailto (e_meeting_attendee_get_address (ia)));
g_string_append (string, query);
g_free (query);
}
g_string_append_c (string, ')');
if (not_found->len > 0)
e_book_get_cursor (priv->ebook, string->str, cursor_cb, im);
else
process_callbacks (im);
g_ptr_array_free (not_found, FALSE);
g_string_free (string, TRUE);
}
ETableScrolled *
e_meeting_model_etable_from_model (EMeetingModel *im, const gchar *spec_file, const gchar *state_file)
{
EMeetingModelPrivate *priv;
g_return_val_if_fail (im != NULL, NULL);
g_return_val_if_fail (E_IS_MEETING_MODEL (im), NULL);
priv = im->priv;
return build_etable (E_TABLE_MODEL (priv->without), spec_file, state_file);
}
int
e_meeting_model_etable_model_to_view_row (EMeetingModel *im, int model_row)
{
EMeetingModelPrivate *priv;
g_return_val_if_fail (im != NULL, -1);
g_return_val_if_fail (E_IS_MEETING_MODEL (im), -1);
priv = im->priv;
return e_table_subset_model_to_view_row (priv->without, model_row);
}
int
e_meeting_model_etable_view_to_model_row (EMeetingModel *im, int view_row)
{
EMeetingModelPrivate *priv;
g_return_val_if_fail (im != NULL, -1);
g_return_val_if_fail (E_IS_MEETING_MODEL (im), -1);
priv = im->priv;
return e_table_subset_view_to_model_row (priv->without, view_row);
}
static void
add_section (GNOME_Evolution_Addressbook_SelectNames corba_select_names, const char *name)
{
CORBA_Environment ev;
CORBA_exception_init (&ev);
GNOME_Evolution_Addressbook_SelectNames_addSection (corba_select_names,
name,
gettext (name),
&ev);
CORBA_exception_free (&ev);
}
static gboolean
get_select_name_dialog (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
CORBA_Environment ev;
int i;
priv = im->priv;
if (priv->corba_select_names != CORBA_OBJECT_NIL) {
Bonobo_Control corba_control;
GtkWidget *control_widget;
int i;
CORBA_exception_init (&ev);
for (i = 0; sections[i] != NULL; i++) {
corba_control = GNOME_Evolution_Addressbook_SelectNames_getEntryBySection
(priv->corba_select_names, sections[i], &ev);
if (BONOBO_EX (&ev)) {
CORBA_exception_free (&ev);
return FALSE;
}
control_widget = bonobo_widget_new_control_from_objref (corba_control, CORBA_OBJECT_NIL);
bonobo_widget_set_property (BONOBO_WIDGET (control_widget), "text", "", NULL);
}
CORBA_exception_free (&ev);
return TRUE;
}
CORBA_exception_init (&ev);
priv->corba_select_names = oaf_activate_from_id (SELECT_NAMES_OAFID, 0, NULL, &ev);
for (i = 0; sections[i] != NULL; i++)
add_section (priv->corba_select_names, sections[i]);
bonobo_event_source_client_add_listener (priv->corba_select_names,
select_names_ok_cb,
"GNOME/Evolution:ok:dialog",
NULL, im);
if (BONOBO_EX (&ev)) {
CORBA_exception_free (&ev);
return FALSE;
}
CORBA_exception_free (&ev);
return TRUE;
}
void
e_meeting_model_invite_others_dialog (EMeetingModel *im)
{
EMeetingModelPrivate *priv;
CORBA_Environment ev;
priv = im->priv;
if (!get_select_name_dialog (im))
return;
CORBA_exception_init (&ev);
GNOME_Evolution_Addressbook_SelectNames_activateDialog (
priv->corba_select_names, _("Required Participants"), &ev);
CORBA_exception_free (&ev);
}
static void
process_section (EMeetingModel *im, EDestination **destv, icalparameter_role role)
{
int i;
for (i = 0; destv[i] != NULL; i++) {
EMeetingAttendee *ia;
const char *name, *address;
name = e_destination_get_name (destv[i]);
address = e_destination_get_email (destv[i]);
if (address == NULL || *address == '\0')
continue;
if (e_meeting_model_find_attendee (im, address, NULL) == NULL) {
ia = e_meeting_model_add_attendee_with_defaults (im);
e_meeting_attendee_set_address (ia, g_strdup_printf ("MAILTO:%s", address));
e_meeting_attendee_set_role (ia, role);
e_meeting_attendee_set_cn (ia, g_strdup (name));
}
}
}
static void
select_names_ok_cb (BonoboListener *listener,
char *event_name,
CORBA_any *arg,
CORBA_Environment *ev,
gpointer data)
{
EMeetingModel *im = data;
EMeetingModelPrivate *priv;
Bonobo_Control corba_control;
GtkWidget *control_widget;
EDestination **destv;
char *string = NULL;
int i;
priv = im->priv;
for (i = 0; sections[i] != NULL; i++) {
corba_control = GNOME_Evolution_Addressbook_SelectNames_getEntryBySection
(priv->corba_select_names, sections[i], ev);
control_widget = bonobo_widget_new_control_from_objref
(corba_control, CORBA_OBJECT_NIL);
bonobo_widget_get_property (BONOBO_WIDGET (control_widget), "destinations", &string, NULL);
destv = e_destination_importv (string);
if (destv != NULL) {
process_section (im, destv, roles[i]);
e_destination_freev (destv);
}
}
}
static void
attendee_changed_cb (EMeetingAttendee *ia, gpointer data)
{
EMeetingModel *im = E_MEETING_MODEL (data);
EMeetingModelPrivate *priv;
gint row = -1, i;
priv = im->priv;
for (i = 0; i < priv->attendees->len; i++) {
if (ia == g_ptr_array_index (priv->attendees, i)) {
row = 1;
break;
}
}
if (row == -1)
return;
/* FIXME: Ideally I think you are supposed to call pre_change() before
the data structures are changed. */
e_table_model_pre_change (E_TABLE_MODEL (im));
e_table_model_row_changed (E_TABLE_MODEL (im), row);
}
static void
table_destroy_cb (ETableScrolled *etable, gpointer data)
{
ETable *real_table;
char *filename = data;
real_table = e_table_scrolled_get_table (etable);
e_table_save_state (real_table, filename);
g_free (data);
}
|