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
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
|
/*
* Evolution calendar - Data model for ETable
*
* 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:
* Rodrigo Moya <rodrigo@ximian.com>
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <glib/gi18n.h>
#include <libedataserver/e-flag.h>
#include <libedataserver/e-time-utils.h>
#include <libecal/e-cal-client-view.h>
#include <libecal/e-cal-time-util.h>
#include "comp-util.h"
#include "e-cal-model.h"
#include "itip-utils.h"
#include "misc.h"
#include "e-util/e-util.h"
#include "e-util/e-account-utils.h"
#include "e-util/e-extensible.h"
#include "e-util/e-util-enumtypes.h"
typedef struct {
ECalClient *client;
ECalClientView *view;
gboolean do_query;
GCancellable *cancellable;
} ECalModelClient;
struct _ECalModelPrivate {
/* The list of clients we are managing. Each element is of type ECalModelClient */
GList *clients;
/* The default client in the list */
ECalClient *default_client;
/* Array for storing the objects. Each element is of type ECalModelComponent */
GPtrArray *objects;
icalcomponent_kind kind;
ECalModelFlags flags;
icaltimezone *zone;
/* The time range to display */
time_t start;
time_t end;
/* The search regular expression */
gchar *search_sexp;
/* The full regular expression, including time range */
gchar *full_sexp;
/* The default category */
gchar *default_category;
/* Addresses for determining icons */
EAccountList *accounts;
/* Whether we display dates in 24-hour format. */
gboolean use_24_hour_format;
/* Whether to compress weekends into one cell. */
gboolean compress_weekend;
/* First day of the week: 0 (Monday) to 6 (Sunday) */
gint week_start_day;
/* Work day timespan */
gint work_day_start_hour;
gint work_day_start_minute;
gint work_day_end_hour;
gint work_day_end_minute;
/* callback, to retrieve start time for newly added rows by click-to-add */
ECalModelDefaultTimeFunc get_default_time;
gpointer get_default_time_user_data;
/* Default reminder for events */
gboolean use_default_reminder;
gint default_reminder_interval;
EDurationType default_reminder_units;
/* Ask user to confirm before deleting components. */
gboolean confirm_delete;
gboolean in_added;
gboolean in_modified;
gboolean in_removed;
GSList *notify_added;
GSList *notify_modified;
GSList *notify_removed;
GMutex *notify_lock;
GCancellable *loading_clients;
};
static gint ecm_column_count (ETableModel *etm);
static gint ecm_row_count (ETableModel *etm);
static gpointer ecm_value_at (ETableModel *etm, gint col, gint row);
static void ecm_set_value_at (ETableModel *etm, gint col, gint row, gconstpointer value);
static gboolean ecm_is_cell_editable (ETableModel *etm, gint col, gint row);
static void ecm_append_row (ETableModel *etm, ETableModel *source, gint row);
static gpointer ecm_duplicate_value (ETableModel *etm, gint col, gconstpointer value);
static void ecm_free_value (ETableModel *etm, gint col, gpointer value);
static gpointer ecm_initialize_value (ETableModel *etm, gint col);
static gboolean ecm_value_is_empty (ETableModel *etm, gint col, gconstpointer value);
static gchar *ecm_value_to_string (ETableModel *etm, gint col, gconstpointer value);
static const gchar *ecm_get_color_for_component (ECalModel *model, ECalModelComponent *comp_data);
static ECalModelClient *add_new_client (ECalModel *model, ECalClient *client, gboolean do_query);
static ECalModelClient *find_client_data (ECalModel *model, ECalClient *client);
static void remove_client_objects (ECalModel *model, ECalModelClient *client_data);
static void remove_client (ECalModel *model, ECalModelClient *client_data);
enum {
PROP_0,
PROP_COMPRESS_WEEKEND,
PROP_CONFIRM_DELETE,
PROP_DEFAULT_CLIENT,
PROP_DEFAULT_REMINDER_INTERVAL,
PROP_DEFAULT_REMINDER_UNITS,
PROP_TIMEZONE,
PROP_USE_24_HOUR_FORMAT,
PROP_USE_DEFAULT_REMINDER,
PROP_WEEK_START_DAY,
PROP_WORK_DAY_END_HOUR,
PROP_WORK_DAY_END_MINUTE,
PROP_WORK_DAY_START_HOUR,
PROP_WORK_DAY_START_MINUTE
};
enum {
TIME_RANGE_CHANGED,
ROW_APPENDED,
COMPS_DELETED,
CAL_VIEW_PROGRESS,
CAL_VIEW_COMPLETE,
STATUS_MESSAGE,
TIMEZONE_CHANGED,
LAST_SIGNAL
};
static gpointer parent_class;
static guint signals[LAST_SIGNAL];
G_DEFINE_TYPE_WITH_CODE (
ECalModel, e_cal_model, E_TYPE_TABLE_MODEL,
G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE, NULL))
static void
cal_model_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_COMPRESS_WEEKEND:
e_cal_model_set_compress_weekend (
E_CAL_MODEL (object),
g_value_get_boolean (value));
return;
case PROP_CONFIRM_DELETE:
e_cal_model_set_confirm_delete (
E_CAL_MODEL (object),
g_value_get_boolean (value));
return;
case PROP_DEFAULT_CLIENT:
e_cal_model_set_default_client (
E_CAL_MODEL (object),
g_value_get_object (value));
return;
case PROP_DEFAULT_REMINDER_INTERVAL:
e_cal_model_set_default_reminder_interval (
E_CAL_MODEL (object),
g_value_get_int (value));
return;
case PROP_DEFAULT_REMINDER_UNITS:
e_cal_model_set_default_reminder_units (
E_CAL_MODEL (object),
g_value_get_enum (value));
return;
case PROP_TIMEZONE:
e_cal_model_set_timezone (
E_CAL_MODEL (object),
g_value_get_pointer (value));
return;
case PROP_USE_24_HOUR_FORMAT:
e_cal_model_set_use_24_hour_format (
E_CAL_MODEL (object),
g_value_get_boolean (value));
return;
case PROP_USE_DEFAULT_REMINDER:
e_cal_model_set_use_default_reminder (
E_CAL_MODEL (object),
g_value_get_boolean (value));
return;
case PROP_WEEK_START_DAY:
e_cal_model_set_week_start_day (
E_CAL_MODEL (object),
g_value_get_int (value));
return;
case PROP_WORK_DAY_END_HOUR:
e_cal_model_set_work_day_end_hour (
E_CAL_MODEL (object),
g_value_get_int (value));
return;
case PROP_WORK_DAY_END_MINUTE:
e_cal_model_set_work_day_end_minute (
E_CAL_MODEL (object),
g_value_get_int (value));
return;
case PROP_WORK_DAY_START_HOUR:
e_cal_model_set_work_day_start_hour (
E_CAL_MODEL (object),
g_value_get_int (value));
return;
case PROP_WORK_DAY_START_MINUTE:
e_cal_model_set_work_day_start_minute (
E_CAL_MODEL (object),
g_value_get_int (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
cal_model_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_COMPRESS_WEEKEND:
g_value_set_boolean (
value,
e_cal_model_get_compress_weekend (
E_CAL_MODEL (object)));
return;
case PROP_CONFIRM_DELETE:
g_value_set_boolean (
value,
e_cal_model_get_confirm_delete (
E_CAL_MODEL (object)));
return;
case PROP_DEFAULT_CLIENT:
g_value_set_object (
value,
e_cal_model_get_default_client (
E_CAL_MODEL (object)));
return;
case PROP_DEFAULT_REMINDER_INTERVAL:
g_value_set_int (
value,
e_cal_model_get_default_reminder_interval (
E_CAL_MODEL (object)));
return;
case PROP_DEFAULT_REMINDER_UNITS:
g_value_set_enum (
value,
e_cal_model_get_default_reminder_units (
E_CAL_MODEL (object)));
return;
case PROP_TIMEZONE:
g_value_set_pointer (
value,
e_cal_model_get_timezone (
E_CAL_MODEL (object)));
return;
case PROP_USE_24_HOUR_FORMAT:
g_value_set_boolean (
value,
e_cal_model_get_use_24_hour_format (
E_CAL_MODEL (object)));
return;
case PROP_USE_DEFAULT_REMINDER:
g_value_set_boolean (
value,
e_cal_model_get_use_default_reminder (
E_CAL_MODEL (object)));
return;
case PROP_WEEK_START_DAY:
g_value_set_int (
value,
e_cal_model_get_week_start_day (
E_CAL_MODEL (object)));
return;
case PROP_WORK_DAY_END_HOUR:
g_value_set_int (
value,
e_cal_model_get_work_day_end_hour (
E_CAL_MODEL (object)));
return;
case PROP_WORK_DAY_END_MINUTE:
g_value_set_int (
value,
e_cal_model_get_work_day_end_minute (
E_CAL_MODEL (object)));
return;
case PROP_WORK_DAY_START_HOUR:
g_value_set_int (
value,
e_cal_model_get_work_day_start_hour (
E_CAL_MODEL (object)));
return;
case PROP_WORK_DAY_START_MINUTE:
g_value_set_int (
value,
e_cal_model_get_work_day_start_minute (
E_CAL_MODEL (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
cal_model_constructed (GObject *object)
{
e_extensible_load_extensions (E_EXTENSIBLE (object));
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (parent_class)->constructed (object);
}
static void
cal_model_dispose (GObject *object)
{
ECalModelPrivate *priv;
priv = E_CAL_MODEL (object)->priv;
if (priv->loading_clients) {
g_cancellable_cancel (priv->loading_clients);
g_object_unref (priv->loading_clients);
priv->loading_clients = NULL;
}
if (priv->clients) {
while (priv->clients != NULL) {
ECalModelClient *client_data = (ECalModelClient *) priv->clients->data;
g_signal_handlers_disconnect_matched (client_data->client, G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL, object);
if (client_data->view)
g_signal_handlers_disconnect_matched (client_data->view, G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL, object);
priv->clients = g_list_remove (priv->clients, client_data);
g_object_unref (client_data->client);
if (client_data->cancellable) {
g_cancellable_cancel (client_data->cancellable);
g_object_unref (client_data->cancellable);
}
if (client_data->view)
g_object_unref (client_data->view);
g_free (client_data);
}
priv->clients = NULL;
priv->default_client = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (parent_class)->dispose (object);
}
static void
cal_model_finalize (GObject *object)
{
ECalModelPrivate *priv;
gint ii;
priv = E_CAL_MODEL (object)->priv;
g_free (priv->search_sexp);
g_free (priv->full_sexp);
g_free (priv->default_category);
for (ii = 0; ii < priv->objects->len; ii++) {
ECalModelComponent *comp_data;
comp_data = g_ptr_array_index (priv->objects, ii);
if (comp_data == NULL) {
g_warning ("comp_data is null\n");
continue;
}
g_object_unref (comp_data);
}
g_ptr_array_free (priv->objects, FALSE);
g_mutex_free (priv->notify_lock);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
e_cal_model_class_init (ECalModelClass *class)
{
GObjectClass *object_class;
ETableModelClass *etm_class;
parent_class = g_type_class_peek_parent (class);
g_type_class_add_private (class, sizeof (ECalModelPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = cal_model_set_property;
object_class->get_property = cal_model_get_property;
object_class->constructed = cal_model_constructed;
object_class->dispose = cal_model_dispose;
object_class->finalize = cal_model_finalize;
etm_class = E_TABLE_MODEL_CLASS (class);
etm_class->column_count = ecm_column_count;
etm_class->row_count = ecm_row_count;
etm_class->value_at = ecm_value_at;
etm_class->set_value_at = ecm_set_value_at;
etm_class->is_cell_editable = ecm_is_cell_editable;
etm_class->append_row = ecm_append_row;
etm_class->duplicate_value = ecm_duplicate_value;
etm_class->free_value = ecm_free_value;
etm_class->initialize_value = ecm_initialize_value;
etm_class->value_is_empty = ecm_value_is_empty;
etm_class->value_to_string = ecm_value_to_string;
class->get_color_for_component = ecm_get_color_for_component;
class->fill_component_from_model = NULL;
g_object_class_install_property (
object_class,
PROP_COMPRESS_WEEKEND,
g_param_spec_boolean (
"compress-weekend",
"Compress Weekend",
NULL,
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_CONFIRM_DELETE,
g_param_spec_boolean (
"confirm-delete",
"Confirm Delete",
NULL,
TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_DEFAULT_CLIENT,
g_param_spec_object (
"default-client",
"Default ECalClient",
NULL,
E_TYPE_CAL_CLIENT,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_DEFAULT_REMINDER_INTERVAL,
g_param_spec_int (
"default-reminder-interval",
"Default Reminder Interval",
NULL,
G_MININT,
G_MAXINT,
0,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_DEFAULT_REMINDER_UNITS,
g_param_spec_enum (
"default-reminder-units",
"Default Reminder Units",
NULL,
E_TYPE_DURATION_TYPE,
E_DURATION_MINUTES,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_TIMEZONE,
g_param_spec_pointer (
"timezone",
"Time Zone",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_USE_24_HOUR_FORMAT,
g_param_spec_boolean (
"use-24-hour-format",
"Use 24-Hour Format",
NULL,
TRUE,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_USE_DEFAULT_REMINDER,
g_param_spec_boolean (
"use-default-reminder",
"Use Default Reminder",
NULL,
FALSE,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_WEEK_START_DAY,
g_param_spec_int (
"week-start-day",
"Week Start Day",
NULL,
0, /* Monday */
6, /* Sunday */
0,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_WORK_DAY_END_HOUR,
g_param_spec_int (
"work-day-end-hour",
"Work Day End Hour",
NULL,
0,
23,
0,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_WORK_DAY_END_MINUTE,
g_param_spec_int (
"work-day-end-minute",
"Work Day End Minute",
NULL,
0,
59,
0,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_WORK_DAY_START_HOUR,
g_param_spec_int (
"work-day-start-hour",
"Work Day Start Hour",
NULL,
0,
23,
0,
G_PARAM_READWRITE));
g_object_class_install_property (
object_class,
PROP_WORK_DAY_START_MINUTE,
g_param_spec_int (
"work-day-start-minute",
"Work Day Start Minute",
NULL,
0,
59,
0,
G_PARAM_READWRITE));
signals[TIME_RANGE_CHANGED] =
g_signal_new ("time_range_changed",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ECalModelClass, time_range_changed),
NULL, NULL,
e_marshal_VOID__LONG_LONG,
G_TYPE_NONE, 2, G_TYPE_LONG, G_TYPE_LONG);
signals[ROW_APPENDED] =
g_signal_new ("row_appended",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ECalModelClass, row_appended),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
signals[COMPS_DELETED] =
g_signal_new ("comps_deleted",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ECalModelClass, comps_deleted),
NULL, NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
signals[CAL_VIEW_PROGRESS] =
g_signal_new ("cal_view_progress",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ECalModelClass, cal_view_progress),
NULL, NULL,
e_marshal_VOID__STRING_INT_INT,
G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT);
signals[CAL_VIEW_COMPLETE] =
g_signal_new ("cal_view_complete",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ECalModelClass, cal_view_complete),
NULL, NULL,
e_marshal_VOID__BOXED_INT,
G_TYPE_NONE, 2, G_TYPE_ERROR, G_TYPE_INT);
signals[STATUS_MESSAGE] = g_signal_new (
"status-message",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (ECalModelClass, status_message),
NULL, NULL,
e_marshal_VOID__STRING_DOUBLE,
G_TYPE_NONE, 2,
G_TYPE_STRING, G_TYPE_DOUBLE);
signals[TIMEZONE_CHANGED] = g_signal_new (
"timezone-changed",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ECalModelClass, timezone_changed),
NULL, NULL,
e_marshal_VOID__POINTER_POINTER,
G_TYPE_NONE, 2,
G_TYPE_POINTER,
G_TYPE_POINTER);
}
static void
e_cal_model_init (ECalModel *model)
{
model->priv = G_TYPE_INSTANCE_GET_PRIVATE (
model, E_TYPE_CAL_MODEL, ECalModelPrivate);
/* match none by default */
model->priv->start = -1;
model->priv->end = -1;
model->priv->search_sexp = NULL;
model->priv->full_sexp = g_strdup ("#f");
model->priv->objects = g_ptr_array_new ();
model->priv->kind = ICAL_NO_COMPONENT;
model->priv->flags = 0;
model->priv->accounts = e_get_account_list ();
model->priv->use_24_hour_format = TRUE;
model->priv->in_added = FALSE;
model->priv->in_modified = FALSE;
model->priv->in_removed = FALSE;
model->priv->notify_added = NULL;
model->priv->notify_modified = NULL;
model->priv->notify_removed = NULL;
model->priv->notify_lock = g_mutex_new ();
model->priv->loading_clients = g_cancellable_new ();
}
/* ETableModel methods */
static gint
ecm_column_count (ETableModel *etm)
{
return E_CAL_MODEL_FIELD_LAST;
}
static gint
ecm_row_count (ETableModel *etm)
{
ECalModelPrivate *priv;
ECalModel *model = (ECalModel *) etm;
g_return_val_if_fail (E_IS_CAL_MODEL (model), -1);
priv = model->priv;
return priv->objects->len;
}
static gpointer
get_categories (ECalModelComponent *comp_data)
{
icalproperty *prop;
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CATEGORIES_PROPERTY);
if (prop)
return (gpointer) icalproperty_get_categories (prop);
return (gpointer) "";
}
static gchar *
get_classification (ECalModelComponent *comp_data)
{
icalproperty *prop;
icalproperty_class class;
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CLASS_PROPERTY);
if (!prop)
return _("Public");
class = icalproperty_get_class (prop);
switch (class)
{
case ICAL_CLASS_PUBLIC:
return _("Public");
case ICAL_CLASS_PRIVATE:
return _("Private");
case ICAL_CLASS_CONFIDENTIAL:
return _("Confidential");
default:
return _("Unknown");
}
}
static const gchar *
get_color (ECalModel *model, ECalModelComponent *comp_data)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
return e_cal_model_get_color_for_component (model, comp_data);
}
static gpointer
get_description (ECalModelComponent *comp_data)
{
icalproperty *prop;
static GString *str = NULL;
if (str) {
g_string_free (str, TRUE);
str = NULL;
}
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DESCRIPTION_PROPERTY);
if (prop) {
str = g_string_new (NULL);
do {
str = g_string_append (str, icalproperty_get_description (prop));
} while ((prop = icalcomponent_get_next_property (comp_data->icalcomp, ICAL_DESCRIPTION_PROPERTY)));
return str->str;
}
return (gpointer) "";
}
static ECellDateEditValue*
get_dtstart (ECalModel *model, ECalModelComponent *comp_data)
{
ECalModelPrivate *priv;
struct icaltimetype tt_start;
priv = model->priv;
if (!comp_data->dtstart) {
icalproperty *prop;
icaltimezone *zone;
gboolean got_zone = FALSE;
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY);
if (!prop)
return NULL;
tt_start = icalproperty_get_dtstart (prop);
if (icaltime_get_tzid (tt_start)
&& e_cal_client_get_timezone_sync (comp_data->client, icaltime_get_tzid (tt_start), &zone, NULL, NULL))
got_zone = TRUE;
if (e_cal_model_get_flags (model) & E_CAL_MODEL_FLAGS_EXPAND_RECURRENCES) {
if (got_zone) {
tt_start = icaltime_from_timet_with_zone (comp_data->instance_start, tt_start.is_date, zone);
if (priv->zone)
icaltimezone_convert_time (&tt_start, zone, priv->zone);
} else
if (priv->zone)
tt_start = icaltime_from_timet_with_zone (comp_data->instance_start, tt_start.is_date, priv->zone);
}
if (!icaltime_is_valid_time (tt_start) || icaltime_is_null_time (tt_start))
return NULL;
comp_data->dtstart = g_new0 (ECellDateEditValue, 1);
comp_data->dtstart->tt = tt_start;
if (got_zone)
comp_data->dtstart->zone = zone;
else
comp_data->dtstart->zone = NULL;
}
return comp_data->dtstart;
}
static ECellDateEditValue*
get_datetime_from_utc (ECalModel *model, ECalModelComponent *comp_data, icalproperty_kind propkind, struct icaltimetype (*get_value)(const icalproperty* prop), ECellDateEditValue **buffer)
{
ECalModelPrivate *priv;
struct icaltimetype tt_value;
icalproperty *prop;
ECellDateEditValue *res;
g_return_val_if_fail (buffer!= NULL, NULL);
if (*buffer)
return *buffer;
priv = model->priv;
prop = icalcomponent_get_first_property (comp_data->icalcomp, propkind);
if (!prop)
return NULL;
tt_value = get_value (prop);
/* these are always in UTC, thus convert to default zone, if any and done */
if (priv->zone)
icaltimezone_convert_time (&tt_value, icaltimezone_get_utc_timezone (), priv->zone);
if (!icaltime_is_valid_time (tt_value) || icaltime_is_null_time (tt_value))
return NULL;
res = g_new0 (ECellDateEditValue, 1);
res->tt = tt_value;
res->zone = NULL;
*buffer = res;
return res;
}
static gpointer
get_summary (ECalModelComponent *comp_data)
{
icalproperty *prop;
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_SUMMARY_PROPERTY);
if (prop)
return (gpointer) icalproperty_get_summary (prop);
return (gpointer) "";
}
static gchar *
get_uid (ECalModelComponent *comp_data)
{
return (gchar *) icalcomponent_get_uid (comp_data->icalcomp);
}
static gpointer
ecm_value_at (ETableModel *etm, gint col, gint row)
{
ECalModelPrivate *priv;
ECalModelComponent *comp_data;
ECalModel *model = (ECalModel *) etm;
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
priv = model->priv;
g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_FIELD_LAST, NULL);
g_return_val_if_fail (row >= 0 && row < priv->objects->len, NULL);
comp_data = g_ptr_array_index (priv->objects, row);
g_return_val_if_fail (comp_data != NULL, NULL);
g_return_val_if_fail (comp_data->icalcomp != NULL, NULL);
switch (col) {
case E_CAL_MODEL_FIELD_CATEGORIES :
return get_categories (comp_data);
case E_CAL_MODEL_FIELD_CLASSIFICATION :
return get_classification (comp_data);
case E_CAL_MODEL_FIELD_COLOR :
return (gpointer) get_color (model, comp_data);
case E_CAL_MODEL_FIELD_COMPONENT :
return comp_data->icalcomp;
case E_CAL_MODEL_FIELD_DESCRIPTION :
return get_description (comp_data);
case E_CAL_MODEL_FIELD_DTSTART :
return (gpointer) get_dtstart (model, comp_data);
case E_CAL_MODEL_FIELD_CREATED :
return (gpointer) get_datetime_from_utc (model, comp_data, ICAL_CREATED_PROPERTY, icalproperty_get_created, &comp_data->created);
case E_CAL_MODEL_FIELD_LASTMODIFIED :
return (gpointer) get_datetime_from_utc (model, comp_data, ICAL_LASTMODIFIED_PROPERTY, icalproperty_get_lastmodified, &comp_data->lastmodified);
case E_CAL_MODEL_FIELD_HAS_ALARMS :
return GINT_TO_POINTER ((icalcomponent_get_first_component (comp_data->icalcomp,
ICAL_VALARM_COMPONENT) != NULL));
case E_CAL_MODEL_FIELD_ICON :
{
ECalComponent *comp;
icalcomponent *icalcomp;
gint retval = 0;
comp = e_cal_component_new ();
icalcomp = icalcomponent_new_clone (comp_data->icalcomp);
if (e_cal_component_set_icalcomponent (comp, icalcomp)) {
if (e_cal_component_get_vtype (comp) == E_CAL_COMPONENT_JOURNAL) {
g_object_unref (comp);
return GINT_TO_POINTER (retval);
}
if (e_cal_component_has_recurrences (comp))
retval = 1;
else if (itip_organizer_is_user (comp, comp_data->client))
retval = 3;
else {
GSList *attendees = NULL, *sl;
e_cal_component_get_attendee_list (comp, &attendees);
for (sl = attendees; sl != NULL; sl = sl->next) {
ECalComponentAttendee *ca = sl->data;
const gchar *text;
text = itip_strip_mailto (ca->value);
if (itip_address_is_user (text)) {
if (ca->delto != NULL)
retval = 3;
else
retval = 2;
break;
}
}
e_cal_component_free_attendee_list (attendees);
}
} else
icalcomponent_free (icalcomp);
g_object_unref (comp);
return GINT_TO_POINTER (retval);
}
case E_CAL_MODEL_FIELD_SUMMARY :
return get_summary (comp_data);
case E_CAL_MODEL_FIELD_UID :
return get_uid (comp_data);
}
return (gpointer) "";
}
static void
set_categories (ECalModelComponent *comp_data, const gchar *value)
{
icalproperty *prop;
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CATEGORIES_PROPERTY);
if (!value || !(*value)) {
if (prop) {
icalcomponent_remove_property (comp_data->icalcomp, prop);
icalproperty_free (prop);
}
} else {
if (!prop) {
prop = icalproperty_new_categories (value);
icalcomponent_add_property (comp_data->icalcomp, prop);
} else
icalproperty_set_categories (prop, value);
}
}
static void
set_classification (ECalModelComponent *comp_data, const gchar *value)
{
icalproperty *prop;
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_CLASS_PROPERTY);
if (!value || !(*value)) {
if (prop) {
icalcomponent_remove_property (comp_data->icalcomp, prop);
icalproperty_free (prop);
}
} else {
icalproperty_class ical_class;
if (!g_ascii_strcasecmp (value, "PUBLIC"))
ical_class = ICAL_CLASS_PUBLIC;
else if (!g_ascii_strcasecmp (value, "PRIVATE"))
ical_class = ICAL_CLASS_PRIVATE;
else if (!g_ascii_strcasecmp (value, "CONFIDENTIAL"))
ical_class = ICAL_CLASS_CONFIDENTIAL;
else
ical_class = ICAL_CLASS_NONE;
if (!prop) {
prop = icalproperty_new_class (ical_class);
icalcomponent_add_property (comp_data->icalcomp, prop);
} else
icalproperty_set_class (prop, ical_class);
}
}
static void
set_description (ECalModelComponent *comp_data, const gchar *value)
{
icalproperty *prop;
/* remove old description(s) */
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DESCRIPTION_PROPERTY);
while (prop) {
icalproperty *next;
next = icalcomponent_get_next_property (comp_data->icalcomp, ICAL_DESCRIPTION_PROPERTY);
icalcomponent_remove_property (comp_data->icalcomp, prop);
icalproperty_free (prop);
prop = next;
}
/* now add the new description */
if (!value || !(*value))
return;
prop = icalproperty_new_description (value);
icalcomponent_add_property (comp_data->icalcomp, prop);
}
static void
datetime_to_zone (ECalClient *client, struct icaltimetype *tt, icaltimezone *tt_zone, const gchar *tzid)
{
icaltimezone *from, *to;
const gchar *tt_tzid = NULL;
g_return_if_fail (tt != NULL);
if (tt_zone)
tt_tzid = icaltimezone_get_tzid (tt_zone);
if (tt_tzid == NULL || tzid == NULL ||
tt_tzid == tzid || g_str_equal (tt_tzid, tzid))
return;
from = tt_zone;
to = icaltimezone_get_builtin_timezone_from_tzid (tzid);
if (!to) {
/* do not check failure here, maybe the zone is not available there */
e_cal_client_get_timezone_sync (client, tzid, &to, NULL, NULL);
}
icaltimezone_convert_time (tt, from, to);
}
/* updates time in a component, and keeps the timezone used in it, if exists */
void
e_cal_model_update_comp_time (ECalModel *model, ECalModelComponent *comp_data, gconstpointer time_value, icalproperty_kind kind, void (*set_func)(icalproperty *prop, struct icaltimetype v), icalproperty * (*new_func)(struct icaltimetype v))
{
ECellDateEditValue *dv = (ECellDateEditValue *) time_value;
icalproperty *prop;
icalparameter *param;
struct icaltimetype tt;
g_return_if_fail (model != NULL);
g_return_if_fail (comp_data != NULL);
g_return_if_fail (set_func != NULL);
g_return_if_fail (new_func != NULL);
prop = icalcomponent_get_first_property (comp_data->icalcomp, kind);
if (prop)
param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
else
param = NULL;
/* If we are setting the property to NULL (i.e. removing it), then
we remove it if it exists. */
if (!dv) {
if (prop) {
icalcomponent_remove_property (comp_data->icalcomp, prop);
icalproperty_free (prop);
}
return;
}
tt = dv->tt;
datetime_to_zone (comp_data->client, &tt, e_cal_model_get_timezone (model), param ? icalparameter_get_tzid (param) : NULL);
if (prop) {
set_func (prop, tt);
} else {
prop = new_func (tt);
icalcomponent_add_property (comp_data->icalcomp, prop);
}
if (param) {
const gchar *tzid = icalparameter_get_tzid (param);
/* If the TZID is set to "UTC", we don't want to save the TZID. */
if (tzid && strcmp (tzid, "UTC")) {
if (param) {
icalparameter_set_tzid (param, (gchar *) tzid);
} else {
param = icalparameter_new_tzid ((gchar *) tzid);
icalproperty_add_parameter (prop, param);
}
} else {
icalproperty_remove_parameter (prop, ICAL_TZID_PARAMETER);
}
}
}
static void
set_dtstart (ECalModel *model, ECalModelComponent *comp_data, gconstpointer value)
{
e_cal_model_update_comp_time (model, comp_data, value, ICAL_DTSTART_PROPERTY, icalproperty_set_dtstart, icalproperty_new_dtstart);
}
static void
set_summary (ECalModelComponent *comp_data, const gchar *value)
{
icalproperty *prop;
prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_SUMMARY_PROPERTY);
if (string_is_empty (value)) {
if (prop) {
icalcomponent_remove_property (comp_data->icalcomp, prop);
icalproperty_free (prop);
}
} else {
if (prop)
icalproperty_set_summary (prop, value);
else {
prop = icalproperty_new_summary (value);
icalcomponent_add_property (comp_data->icalcomp, prop);
}
}
}
static void
ecm_set_value_at (ETableModel *etm, gint col, gint row, gconstpointer value)
{
ECalModelPrivate *priv;
ECalModelComponent *comp_data;
ECalModel *model = (ECalModel *) etm;
GError *error = NULL;
g_return_if_fail (E_IS_CAL_MODEL (model));
priv = model->priv;
g_return_if_fail (col >= 0 && col < E_CAL_MODEL_FIELD_LAST);
g_return_if_fail (row >= 0 && row < priv->objects->len);
comp_data = g_ptr_array_index (priv->objects, row);
g_return_if_fail (comp_data != NULL);
switch (col) {
case E_CAL_MODEL_FIELD_CATEGORIES :
set_categories (comp_data, value);
break;
case E_CAL_MODEL_FIELD_CLASSIFICATION :
set_classification (comp_data, value);
break;
case E_CAL_MODEL_FIELD_DESCRIPTION :
set_description (comp_data, value);
break;
case E_CAL_MODEL_FIELD_DTSTART :
set_dtstart (model, comp_data, value);
break;
case E_CAL_MODEL_FIELD_SUMMARY :
set_summary (comp_data, value);
break;
}
/* FIXME ask about mod type */
if (!e_cal_client_modify_object_sync (comp_data->client, comp_data->icalcomp, CALOBJ_MOD_ALL, NULL, &error)) {
g_warning (G_STRLOC ": Could not modify the object! %s", error ? error->message : "Unknown error");
/* FIXME Show error dialog */
if (error)
g_error_free (error);
}
}
/**
* e_cal_model_test_row_editable
* @model: an #ECalModel
* @row: Row of our interest. -1 is editable only when default client is
* editable.
*
* Checks if component at @row is editable or not. It doesn't check bounds
* for @row.
*
* Returns: Whether @row is editable or not.
**/
gboolean
e_cal_model_test_row_editable (ECalModel *model, gint row)
{
gboolean readonly;
ECalClient *client = NULL;
if (row != -1) {
ECalModelComponent *comp_data;
comp_data = e_cal_model_get_component_at (model, row);
if (comp_data)
client = comp_data->client;
} else {
client = e_cal_model_get_default_client (model);
}
readonly = client == NULL;
if (!readonly)
readonly = e_client_is_readonly (E_CLIENT (client));
return !readonly;
}
static gboolean
ecm_is_cell_editable (ETableModel *etm, gint col, gint row)
{
ECalModelPrivate *priv;
ECalModel *model = (ECalModel *) etm;
g_return_val_if_fail (E_IS_CAL_MODEL (model), FALSE);
priv = model->priv;
g_return_val_if_fail (col >= 0 && col <= E_CAL_MODEL_FIELD_LAST, FALSE);
g_return_val_if_fail (row >= -1 || (row >= 0 && row < priv->objects->len), FALSE);
if (!e_cal_model_test_row_editable (E_CAL_MODEL (etm), row))
return FALSE;
switch (col) {
case E_CAL_MODEL_FIELD_CATEGORIES :
case E_CAL_MODEL_FIELD_CLASSIFICATION :
case E_CAL_MODEL_FIELD_DESCRIPTION :
case E_CAL_MODEL_FIELD_DTSTART :
case E_CAL_MODEL_FIELD_SUMMARY :
return TRUE;
}
return FALSE;
}
static void
ecm_append_row (ETableModel *etm, ETableModel *source, gint row)
{
ECalModelClass *model_class;
ECalModelComponent *comp_data;
ECalModel *model = (ECalModel *) etm;
gchar *uid = NULL;
GError *error = NULL;
g_return_if_fail (E_IS_CAL_MODEL (model));
g_return_if_fail (E_IS_TABLE_MODEL (source));
comp_data = g_object_new (E_TYPE_CAL_MODEL_COMPONENT, NULL);
comp_data->client = e_cal_model_get_default_client (model);
if (comp_data->client)
g_object_ref (comp_data->client);
/* guard against saving before the calendar is open */
if (!comp_data->client || !e_client_is_opened (E_CLIENT (comp_data->client))) {
g_object_unref (comp_data);
return;
}
comp_data->icalcomp = e_cal_model_create_component_with_defaults (model, FALSE);
/* set values for our fields */
set_categories (comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_CATEGORIES, row));
set_classification (comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_CLASSIFICATION, row));
set_description (comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_DESCRIPTION, row));
set_summary (comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_SUMMARY, row));
if (e_table_model_value_at (source, E_CAL_MODEL_FIELD_DTSTART, row)) {
set_dtstart (model, comp_data, e_table_model_value_at (source, E_CAL_MODEL_FIELD_DTSTART, row));
} else if (model->priv->get_default_time) {
time_t tt = model->priv->get_default_time (model, model->priv->get_default_time_user_data);
if (tt > 0) {
struct icaltimetype itt = icaltime_from_timet_with_zone (tt, FALSE, e_cal_model_get_timezone (model));
icalproperty *prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY);
if (prop) {
icalproperty_set_dtstart (prop, itt);
} else {
prop = icalproperty_new_dtstart (itt);
icalcomponent_add_property (comp_data->icalcomp, prop);
}
}
}
/* call the class' method for filling the component */
model_class = (ECalModelClass *) G_OBJECT_GET_CLASS (model);
if (model_class->fill_component_from_model != NULL) {
model_class->fill_component_from_model (model, comp_data, source, row);
}
if (!e_cal_client_create_object_sync (comp_data->client, comp_data->icalcomp, &uid, NULL, &error)) {
g_warning (G_STRLOC ": Could not create the object! %s", error ? error->message : "Unknown error");
/* FIXME: show error dialog */
if (error)
g_error_free (error);
} else {
if (uid)
icalcomponent_set_uid (comp_data->icalcomp, uid);
g_signal_emit (G_OBJECT (model), signals[ROW_APPENDED], 0);
}
g_free (uid);
g_object_unref (comp_data);
}
static gpointer
ecm_duplicate_value (ETableModel *etm, gint col, gconstpointer value)
{
g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_FIELD_LAST, NULL);
switch (col) {
case E_CAL_MODEL_FIELD_CATEGORIES :
case E_CAL_MODEL_FIELD_CLASSIFICATION :
case E_CAL_MODEL_FIELD_DESCRIPTION :
case E_CAL_MODEL_FIELD_SUMMARY :
return g_strdup (value);
case E_CAL_MODEL_FIELD_HAS_ALARMS :
case E_CAL_MODEL_FIELD_ICON :
case E_CAL_MODEL_FIELD_COLOR :
return (gpointer) value;
case E_CAL_MODEL_FIELD_COMPONENT :
return icalcomponent_new_clone ((icalcomponent *) value);
case E_CAL_MODEL_FIELD_DTSTART :
case E_CAL_MODEL_FIELD_CREATED :
case E_CAL_MODEL_FIELD_LASTMODIFIED :
if (value) {
ECellDateEditValue *dv, *orig_dv;
orig_dv = (ECellDateEditValue *) value;
dv = g_new0 (ECellDateEditValue, 1);
*dv = *orig_dv;
return dv;
}
break;
}
return NULL;
}
static void
ecm_free_value (ETableModel *etm, gint col, gpointer value)
{
g_return_if_fail (col >= 0 && col < E_CAL_MODEL_FIELD_LAST);
switch (col) {
case E_CAL_MODEL_FIELD_CATEGORIES :
case E_CAL_MODEL_FIELD_DESCRIPTION :
case E_CAL_MODEL_FIELD_SUMMARY :
if (value)
g_free (value);
break;
case E_CAL_MODEL_FIELD_CLASSIFICATION :
case E_CAL_MODEL_FIELD_HAS_ALARMS :
case E_CAL_MODEL_FIELD_ICON :
case E_CAL_MODEL_FIELD_COLOR :
break;
case E_CAL_MODEL_FIELD_DTSTART :
case E_CAL_MODEL_FIELD_CREATED :
case E_CAL_MODEL_FIELD_LASTMODIFIED :
if (value)
g_free (value);
break;
case E_CAL_MODEL_FIELD_COMPONENT :
if (value)
icalcomponent_free ((icalcomponent *) value);
break;
}
}
static gpointer
ecm_initialize_value (ETableModel *etm, gint col)
{
ECalModelPrivate *priv;
ECalModel *model = (ECalModel *) etm;
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_FIELD_LAST, NULL);
priv = model->priv;
switch (col) {
case E_CAL_MODEL_FIELD_CATEGORIES :
return g_strdup (priv->default_category?priv->default_category:"");
case E_CAL_MODEL_FIELD_CLASSIFICATION :
case E_CAL_MODEL_FIELD_DESCRIPTION :
case E_CAL_MODEL_FIELD_SUMMARY :
return g_strdup ("");
case E_CAL_MODEL_FIELD_DTSTART :
case E_CAL_MODEL_FIELD_CREATED :
case E_CAL_MODEL_FIELD_LASTMODIFIED :
case E_CAL_MODEL_FIELD_HAS_ALARMS :
case E_CAL_MODEL_FIELD_ICON :
case E_CAL_MODEL_FIELD_COLOR :
case E_CAL_MODEL_FIELD_COMPONENT :
return NULL;
}
return NULL;
}
static gboolean
ecm_value_is_empty (ETableModel *etm, gint col, gconstpointer value)
{
ECalModelPrivate *priv;
ECalModel *model = (ECalModel *) etm;
g_return_val_if_fail (E_IS_CAL_MODEL (model), TRUE);
g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_FIELD_LAST, TRUE);
priv = model->priv;
switch (col) {
case E_CAL_MODEL_FIELD_CATEGORIES :
/* This could be a hack or not. If the categories field only
* contains the default category, then it possibly means that
* the user has not entered anything at all in the click-to-add;
* the category is in the value because we put it there in
* ecm_initialize_value().
*/
if (priv->default_category && value && strcmp (priv->default_category, value) == 0)
return TRUE;
else
return string_is_empty (value);
case E_CAL_MODEL_FIELD_CLASSIFICATION :
case E_CAL_MODEL_FIELD_DESCRIPTION :
case E_CAL_MODEL_FIELD_SUMMARY :
return string_is_empty (value);
case E_CAL_MODEL_FIELD_DTSTART :
case E_CAL_MODEL_FIELD_CREATED :
case E_CAL_MODEL_FIELD_LASTMODIFIED :
return value ? FALSE : TRUE;
case E_CAL_MODEL_FIELD_HAS_ALARMS :
case E_CAL_MODEL_FIELD_ICON :
case E_CAL_MODEL_FIELD_COLOR :
case E_CAL_MODEL_FIELD_COMPONENT :
return TRUE;
}
return TRUE;
}
static gchar *
ecm_value_to_string (ETableModel *etm, gint col, gconstpointer value)
{
g_return_val_if_fail (col >= 0 && col < E_CAL_MODEL_FIELD_LAST, g_strdup (""));
switch (col) {
case E_CAL_MODEL_FIELD_CATEGORIES :
case E_CAL_MODEL_FIELD_CLASSIFICATION :
case E_CAL_MODEL_FIELD_DESCRIPTION :
case E_CAL_MODEL_FIELD_SUMMARY :
return g_strdup (value);
case E_CAL_MODEL_FIELD_DTSTART :
case E_CAL_MODEL_FIELD_CREATED :
case E_CAL_MODEL_FIELD_LASTMODIFIED :
return e_cal_model_date_value_to_string (E_CAL_MODEL (etm), value);
case E_CAL_MODEL_FIELD_ICON :
if (GPOINTER_TO_INT (value) == 0)
return g_strdup (_("Normal"));
else if (GPOINTER_TO_INT (value) == 1)
return g_strdup (_("Recurring"));
else
return g_strdup (_("Assigned"));
case E_CAL_MODEL_FIELD_HAS_ALARMS :
return g_strdup (value ? _("Yes") : _("No"));
case E_CAL_MODEL_FIELD_COLOR :
case E_CAL_MODEL_FIELD_COMPONENT :
return g_strdup ("");
}
return g_strdup ("");
}
/* ECalModel class methods */
typedef struct {
const gchar *color;
GList *uris;
} AssignedColorData;
static const gchar *
ecm_get_color_for_component (ECalModel *model, ECalModelComponent *comp_data)
{
ESource *source;
const gchar *color_spec;
gint i, first_empty = 0;
static AssignedColorData assigned_colors[] = {
{ "#BECEDD", NULL }, /* 190 206 221 Blue */
{ "#E2F0EF", NULL }, /* 226 240 239 Light Blue */
{ "#C6E2B7", NULL }, /* 198 226 183 Green */
{ "#E2F0D3", NULL }, /* 226 240 211 Light Green */
{ "#E2D4B7", NULL }, /* 226 212 183 Khaki */
{ "#EAEAC1", NULL }, /* 234 234 193 Light Khaki */
{ "#F0B8B7", NULL }, /* 240 184 183 Pink */
{ "#FED4D3", NULL }, /* 254 212 211 Light Pink */
{ "#E2C6E1", NULL }, /* 226 198 225 Purple */
{ "#F0E2EF", NULL } /* 240 226 239 Light Purple */
};
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
source = e_client_get_source (E_CLIENT (comp_data->client));
color_spec = e_source_peek_color_spec (source);
if (color_spec != NULL) {
g_free (comp_data->color);
comp_data->color = g_strdup (color_spec);
return comp_data->color;
}
for (i = 0; i < G_N_ELEMENTS (assigned_colors); i++) {
GList *l;
if (assigned_colors[i].uris == NULL) {
first_empty = i;
continue;
}
for (l = assigned_colors[i].uris; l != NULL; l = l->next) {
if (!strcmp ((const gchar *) l->data,
e_client_get_uri (E_CLIENT (comp_data->client))))
{
return assigned_colors[i].color;
}
}
}
/* return the first unused color */
assigned_colors[first_empty].uris = g_list_append (assigned_colors[first_empty].uris,
g_strdup (e_client_get_uri (E_CLIENT (comp_data->client))));
return assigned_colors[first_empty].color;
}
gboolean
e_cal_model_get_confirm_delete (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), FALSE);
return model->priv->confirm_delete;
}
void
e_cal_model_set_confirm_delete (ECalModel *model,
gboolean confirm_delete)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->confirm_delete = confirm_delete;
g_object_notify (G_OBJECT (model), "confirm-delete");
}
icalcomponent_kind
e_cal_model_get_component_kind (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), ICAL_NO_COMPONENT);
return model->priv->kind;
}
void
e_cal_model_set_component_kind (ECalModel *model, icalcomponent_kind kind)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->kind = kind;
}
ECalModelFlags
e_cal_model_get_flags (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
return model->priv->flags;
}
void
e_cal_model_set_flags (ECalModel *model, ECalModelFlags flags)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->flags = flags;
}
icaltimezone *
e_cal_model_get_timezone (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
return model->priv->zone;
}
void
e_cal_model_set_timezone (ECalModel *model,
icaltimezone *zone)
{
icaltimezone *old_zone;
g_return_if_fail (E_IS_CAL_MODEL (model));
if (model->priv->zone == zone)
return;
e_table_model_pre_change (E_TABLE_MODEL (model));
old_zone = model->priv->zone;
model->priv->zone = zone;
/* the timezone affects the times shown for date fields,
so we need to redisplay everything */
e_table_model_changed (E_TABLE_MODEL (model));
g_object_notify (G_OBJECT (model), "timezone");
g_signal_emit (G_OBJECT (model), signals[TIMEZONE_CHANGED], 0,
old_zone, zone);
}
gboolean
e_cal_model_get_compress_weekend (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), FALSE);
return model->priv->compress_weekend;
}
void
e_cal_model_set_compress_weekend (ECalModel *model,
gboolean compress_weekend)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->compress_weekend = compress_weekend;
g_object_notify (G_OBJECT (model), "compress-weekend");
}
void
e_cal_model_set_default_category (ECalModel *model,
const gchar *default_category)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
g_free (model->priv->default_category);
model->priv->default_category = g_strdup (default_category);
}
gint
e_cal_model_get_default_reminder_interval (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
return model->priv->default_reminder_interval;
}
void
e_cal_model_set_default_reminder_interval (ECalModel *model,
gint default_reminder_interval)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->default_reminder_interval = default_reminder_interval;
g_object_notify (G_OBJECT (model), "default-reminder-interval");
}
EDurationType
e_cal_model_get_default_reminder_units (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
return model->priv->default_reminder_units;
}
void
e_cal_model_set_default_reminder_units (ECalModel *model,
EDurationType default_reminder_units)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->default_reminder_units = default_reminder_units;
g_object_notify (G_OBJECT (model), "default-reminder-units");
}
gboolean
e_cal_model_get_use_24_hour_format (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), FALSE);
return model->priv->use_24_hour_format;
}
void
e_cal_model_set_use_24_hour_format (ECalModel *model,
gboolean use_24_hour_format)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
if (model->priv->use_24_hour_format == use_24_hour_format)
return;
e_table_model_pre_change (E_TABLE_MODEL (model));
model->priv->use_24_hour_format = use_24_hour_format;
/* Get the views to redraw themselves. */
e_table_model_changed (E_TABLE_MODEL (model));
g_object_notify (G_OBJECT (model), "use-24-hour-format");
}
gboolean
e_cal_model_get_use_default_reminder (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), FALSE);
return model->priv->use_default_reminder;
}
void
e_cal_model_set_use_default_reminder (ECalModel *model,
gboolean use_default_reminder)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->use_default_reminder = use_default_reminder;
g_object_notify (G_OBJECT (model), "use-default-reminder");
}
gint
e_cal_model_get_week_start_day (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
return model->priv->week_start_day;
}
void
e_cal_model_set_week_start_day (ECalModel *model,
gint week_start_day)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
g_return_if_fail (week_start_day >= 0);
g_return_if_fail (week_start_day < 7);
if (model->priv->week_start_day == week_start_day)
return;
model->priv->week_start_day = week_start_day;
g_object_notify (G_OBJECT (model), "week-start-day");
}
gint
e_cal_model_get_work_day_end_hour (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
return model->priv->work_day_end_hour;
}
void
e_cal_model_set_work_day_end_hour (ECalModel *model,
gint work_day_end_hour)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->work_day_end_hour = work_day_end_hour;
g_object_notify (G_OBJECT (model), "work-day-end-hour");
}
gint
e_cal_model_get_work_day_end_minute (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
return model->priv->work_day_end_minute;
}
void
e_cal_model_set_work_day_end_minute (ECalModel *model,
gint work_day_end_minute)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->work_day_end_minute = work_day_end_minute;
g_object_notify (G_OBJECT (model), "work-day-end-minute");
}
gint
e_cal_model_get_work_day_start_hour (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
return model->priv->work_day_start_hour;
}
void
e_cal_model_set_work_day_start_hour (ECalModel *model,
gint work_day_start_hour)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->work_day_start_hour = work_day_start_hour;
g_object_notify (G_OBJECT (model), "work-day-start-hour");
}
gint
e_cal_model_get_work_day_start_minute (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), 0);
return model->priv->work_day_start_minute;
}
void
e_cal_model_set_work_day_start_minute (ECalModel *model,
gint work_day_start_minute)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->work_day_start_minute = work_day_start_minute;
g_object_notify (G_OBJECT (model), "work-day-start-minute");
}
ECalClient *
e_cal_model_get_default_client (ECalModel *model)
{
ECalModelPrivate *priv;
ECalModelClient *client_data;
g_return_val_if_fail (model != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
priv = model->priv;
/* FIXME Should we force the client to be open? */
/* we always return a valid ECal, since we rely on it in many places */
if (priv->default_client)
return priv->default_client;
if (!priv->clients)
return NULL;
client_data = (ECalModelClient *) priv->clients->data;
return client_data ? client_data->client : NULL;
}
void
e_cal_model_set_default_client (ECalModel *model, ECalClient *client)
{
ECalModelPrivate *priv;
ECalModelClient *client_data;
g_return_if_fail (E_IS_CAL_MODEL (model));
if (client != NULL)
g_return_if_fail (E_IS_CAL_CLIENT (client));
priv = model->priv;
if (priv->default_client) {
client_data = find_client_data (model, priv->default_client);
if (!client_data) {
g_warning ("client_data is NULL\n");
} else {
if (!client_data->do_query)
remove_client (model, client_data);
}
}
if (client != NULL) {
/* Make sure its in the model */
client_data = add_new_client (model, client, FALSE);
/* Store the default client */
priv->default_client = client_data->client;
} else
priv->default_client = NULL;
g_object_notify (G_OBJECT (model), "default-client");
}
GList *
e_cal_model_get_client_list (ECalModel *model)
{
GList *list = NULL, *l;
ECalClient *default_client;
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
default_client = model->priv->default_client;
for (l = model->priv->clients; l != NULL; l = l->next) {
ECalModelClient *client_data = (ECalModelClient *) l->data;
/* Exclude the default client if we're not querying it. */
if (client_data->client == default_client && !client_data->do_query)
continue;
list = g_list_append (list, client_data->client);
}
return list;
}
/**
* e_cal_model_get_client_for_uri:
* @model: A calendar model.
* @uri: Uri for the client to get.
*/
ECalClient *
e_cal_model_get_client_for_uri (ECalModel *model, const gchar *uri)
{
GList *l;
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
g_return_val_if_fail (uri != NULL, NULL);
for (l = model->priv->clients; l != NULL; l = l->next) {
ECalModelClient *client_data = (ECalModelClient *) l->data;
if (!strcmp (uri, e_client_get_uri (E_CLIENT (client_data->client))))
return client_data->client;
}
return NULL;
}
static ECalModelClient *
find_client_data (ECalModel *model, ECalClient *client)
{
ECalModelPrivate *priv;
GList *l;
priv = model->priv;
for (l = priv->clients; l != NULL; l = l->next) {
ECalModelClient *client_data = (ECalModelClient *) l->data;
if (client_data->client == client)
return client_data;
}
return NULL;
}
static ECalModelComponent *
search_by_id_and_client (ECalModelPrivate *priv, ECalClient *client, const ECalComponentId *id)
{
gint i;
for (i = 0; i < priv->objects->len; i++) {
ECalModelComponent *comp_data = g_ptr_array_index (priv->objects, i);
if (comp_data) {
const gchar *uid;
gchar *rid = NULL;
struct icaltimetype icalrid;
gboolean has_rid = (id->rid && *id->rid);
uid = icalcomponent_get_uid (comp_data->icalcomp);
icalrid = icalcomponent_get_recurrenceid (comp_data->icalcomp);
if (!icaltime_is_null_time (icalrid))
rid = icaltime_as_ical_string_r (icalrid);
if (uid && *uid) {
if ((!client || comp_data->client == client) && !strcmp (id->uid, uid)) {
if (has_rid) {
if (!(rid && *rid && !strcmp (rid, id->rid))) {
g_free (rid);
continue;
}
}
g_free (rid);
return comp_data;
}
}
g_free (rid);
}
}
return NULL;
}
typedef struct {
ECalClient *client;
ECalClientView *view;
ECalModel *model;
icalcomponent *icalcomp;
} RecurrenceExpansionData;
static gboolean
add_instance_cb (ECalComponent *comp, time_t instance_start, time_t instance_end, gpointer user_data)
{
ECalModelComponent *comp_data;
ECalModelPrivate *priv;
RecurrenceExpansionData *rdata = user_data;
icaltimetype time;
ECalComponentDateTime datetime, to_set;
icaltimezone *zone = NULL;
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), TRUE);
priv = rdata->model->priv;
e_table_model_pre_change (E_TABLE_MODEL (rdata->model));
/* set the right instance start date to component */
e_cal_component_get_dtstart (comp, &datetime);
if (datetime.tzid)
e_cal_client_get_timezone_sync (rdata->client, datetime.tzid, &zone, NULL, NULL);
time = icaltime_from_timet_with_zone (instance_start, FALSE, zone ? zone : priv->zone);
to_set.value = &time;
to_set.tzid = datetime.tzid;
e_cal_component_set_dtstart (comp, &to_set);
e_cal_component_free_datetime (&datetime);
/* set the right instance end date to component*/
e_cal_component_get_dtend (comp, &datetime);
zone = NULL;
if (datetime.tzid)
e_cal_client_get_timezone_sync (rdata->client, datetime.tzid, &zone, NULL, NULL);
time = icaltime_from_timet_with_zone (instance_end, FALSE, zone ? zone : priv->zone);
to_set.value = &time;
to_set.tzid = datetime.tzid;
e_cal_component_set_dtend (comp, &to_set);
e_cal_component_free_datetime (&datetime);
comp_data = g_object_new (E_TYPE_CAL_MODEL_COMPONENT, NULL);
comp_data->client = g_object_ref (rdata->client);
comp_data->icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp));
comp_data->instance_start = instance_start;
comp_data->instance_end = instance_end;
g_ptr_array_add (priv->objects, comp_data);
e_table_model_row_inserted (E_TABLE_MODEL (rdata->model), priv->objects->len - 1);
return TRUE;
}
/* We do this check since the calendar items are downloaded from the server
* in the open_method, since the default timezone might not be set there. */
static void
ensure_dates_are_in_default_zone (ECalModel *model,
icalcomponent *icalcomp)
{
icaltimetype dt;
icaltimezone *zone;
zone = e_cal_model_get_timezone (model);
if (!zone)
return;
dt = icalcomponent_get_dtstart (icalcomp);
if (dt.is_utc) {
dt = icaltime_convert_to_zone (dt, zone);
icalcomponent_set_dtstart (icalcomp, dt);
}
dt = icalcomponent_get_dtend (icalcomp);
if (dt.is_utc) {
dt = icaltime_convert_to_zone (dt, zone);
icalcomponent_set_dtend (icalcomp, dt);
}
}
static gint
place_master_object_first_cb (gconstpointer p1, gconstpointer p2)
{
icalcomponent *c1 = (icalcomponent *) p1, *c2 = (icalcomponent *) p2;
const gchar *uid1, *uid2;
gint res;
g_return_val_if_fail (c1 != NULL, 0);
g_return_val_if_fail (c2 != NULL, 0);
uid1 = icalcomponent_get_uid (c1);
uid2 = icalcomponent_get_uid (c2);
res = g_strcmp0 (uid1, uid2);
if (res == 0) {
struct icaltimetype rid1, rid2;
rid1 = icalcomponent_get_recurrenceid (c1);
rid2 = icalcomponent_get_recurrenceid (c2);
if (icaltime_is_null_time (rid1)) {
if (!icaltime_is_null_time (rid2))
res = -1;
} else if (icaltime_is_null_time (rid2)) {
res = 1;
} else {
res = icaltime_compare (rid1, rid2);
}
}
return res;
}
static void client_view_objects_added_cb (ECalClientView *view, const GSList *objects, ECalModel *model);
static void
process_added (ECalClientView *view, const GSList *objects, ECalModel *model)
{
ECalModelPrivate *priv;
const GSList *l;
GSList *copy;
priv = model->priv;
/* order matters, process master object first, then detached instances */
copy = g_slist_sort (g_slist_copy ((GSList *) objects), place_master_object_first_cb);
for (l = copy; l; l = l->next) {
ECalModelComponent *comp_data;
ECalComponentId *id;
ECalComponent *comp = e_cal_component_new ();
ECalClient *client = e_cal_client_view_get_client (view);
/* This will fail for alarm or VCalendar component */
if (!e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (l->data))) {
g_object_unref (comp);
continue;
}
id = e_cal_component_get_id (comp);
/* remove the components if they are already present and re-add them */
while ((comp_data = search_by_id_and_client (priv, client,
id))) {
gint pos;
GSList *list = NULL;
pos = get_position_in_array (priv->objects, comp_data);
if (!g_ptr_array_remove (priv->objects, comp_data))
continue;
list = g_slist_append (list, comp_data);
g_signal_emit (G_OBJECT (model), signals[COMPS_DELETED], 0, list);
g_slist_free (list);
g_object_unref (comp_data);
e_table_model_pre_change (E_TABLE_MODEL (model));
e_table_model_row_deleted (E_TABLE_MODEL (model), pos);
}
e_cal_component_free_id (id);
g_object_unref (comp);
ensure_dates_are_in_default_zone (model, l->data);
if (e_cal_util_component_has_recurrences (l->data) && (priv->flags & E_CAL_MODEL_FLAGS_EXPAND_RECURRENCES)) {
ECalModelClient *client_data = find_client_data (model, client);
if (client_data) {
RecurrenceExpansionData *rdata = g_new0 (RecurrenceExpansionData, 1);
rdata->client = client;
rdata->view = view;
rdata->model = model;
rdata->icalcomp = l->data;
e_cal_client_generate_instances_for_object (rdata->client, l->data, priv->start, priv->end, client_data->cancellable,
(ECalRecurInstanceFn) add_instance_cb, rdata, g_free);
}
} else {
e_table_model_pre_change (E_TABLE_MODEL (model));
comp_data = g_object_new (E_TYPE_CAL_MODEL_COMPONENT, NULL);
comp_data->client = g_object_ref (client);
comp_data->icalcomp = icalcomponent_new_clone (l->data);
e_cal_model_set_instance_times (comp_data, priv->zone);
g_ptr_array_add (priv->objects, comp_data);
e_table_model_row_inserted (E_TABLE_MODEL (model), priv->objects->len - 1);
}
}
g_slist_free (copy);
}
static void
process_modified (ECalClientView *view, const GSList *objects, ECalModel *model)
{
ECalModelPrivate *priv;
const GSList *l;
GSList *list = NULL;
priv = model->priv;
/* re-add only the recurrence objects */
for (l = objects; l != NULL; l = g_slist_next (l)) {
if (!e_cal_util_component_is_instance (l->data) && e_cal_util_component_has_recurrences (l->data) && (priv->flags & E_CAL_MODEL_FLAGS_EXPAND_RECURRENCES))
list = g_slist_prepend (list, l->data);
else {
gint pos;
ECalModelComponent *comp_data;
ECalComponentId *id;
ECalComponent *comp = e_cal_component_new ();
ECalClient *client = e_cal_client_view_get_client (view);
if (!e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (l->data))) {
g_object_unref (comp);
continue;
}
e_table_model_pre_change (E_TABLE_MODEL (model));
id = e_cal_component_get_id (comp);
comp_data = search_by_id_and_client (priv, client, id);
e_cal_component_free_id (id);
g_object_unref (comp);
if (!comp_data) {
/* the modified component is not in the model yet, just skip it */
continue;
}
if (comp_data->icalcomp)
icalcomponent_free (comp_data->icalcomp);
if (comp_data->dtstart) {
g_free (comp_data->dtstart);
comp_data->dtstart = NULL;
}
if (comp_data->dtend) {
g_free (comp_data->dtend);
comp_data->dtend = NULL;
}
if (comp_data->due) {
g_free (comp_data->due);
comp_data->due = NULL;
}
if (comp_data->completed) {
g_free (comp_data->completed);
comp_data->completed = NULL;
}
if (comp_data->created) {
g_free (comp_data->created);
comp_data->created = NULL;
}
if (comp_data->lastmodified) {
g_free (comp_data->lastmodified);
comp_data->lastmodified = NULL;
}
if (comp_data->color) {
g_free (comp_data->color);
comp_data->color = NULL;
}
comp_data->icalcomp = icalcomponent_new_clone (l->data);
e_cal_model_set_instance_times (comp_data, priv->zone);
pos = get_position_in_array (priv->objects, comp_data);
e_table_model_row_changed (E_TABLE_MODEL (model), pos);
}
}
client_view_objects_added_cb (view, list, model);
g_slist_free (list);
}
static void
process_removed (ECalClientView *view, const GSList *ids, ECalModel *model)
{
ECalModelPrivate *priv;
const GSList *l;
priv = model->priv;
for (l = ids; l; l = l->next) {
ECalModelComponent *comp_data = NULL;
ECalComponentId *id = l->data;
gint pos;
/* make sure we remove all objects with this UID */
while ((comp_data = search_by_id_and_client (priv, e_cal_client_view_get_client (view), id))) {
GSList *l = NULL;
pos = get_position_in_array (priv->objects, comp_data);
if (!g_ptr_array_remove (priv->objects, comp_data))
continue;
l = g_slist_append (l, comp_data);
g_signal_emit (G_OBJECT (model), signals[COMPS_DELETED], 0, l);
g_slist_free (l);
g_object_unref (comp_data);
e_table_model_pre_change (E_TABLE_MODEL (model));
e_table_model_row_deleted (E_TABLE_MODEL (model), pos);
}
}
/* to notify about changes, because in call of row_deleted there are still all events */
e_table_model_changed (E_TABLE_MODEL (model));
}
static gpointer
copy_comp_id (gpointer id)
{
ECalComponentId *comp_id = (ECalComponentId *) id, *copy;
g_return_val_if_fail (comp_id != NULL, NULL);
copy = g_new0 (ECalComponentId, 1);
copy->uid = g_strdup (comp_id->uid);
copy->rid = g_strdup (comp_id->rid);
return copy;
}
static void
free_comp_id (gpointer id)
{
ECalComponentId *comp_id = (ECalComponentId *) id;
g_return_if_fail (comp_id != NULL);
g_free (comp_id->uid);
g_free (comp_id->rid);
g_free (comp_id);
}
static void
process_event (ECalClientView *view, const GSList *objects, ECalModel *model,
void (*process_fn) (ECalClientView *view, const GSList *objects, ECalModel *model),
gboolean *in, GSList **save_list, gpointer (*copy_fn) (gpointer data), void (*free_fn)(gpointer data))
{
gboolean skip = FALSE;
const GSList *l;
g_mutex_lock (model->priv->notify_lock);
if (*in) {
skip = TRUE;
for (l = objects; l; l = l->next) {
if (l->data)
*save_list = g_slist_append (*save_list, copy_fn (l->data));
}
} else {
*in = TRUE;
}
g_mutex_unlock (model->priv->notify_lock);
if (skip)
return;
/* do it */
process_fn (view, objects, model);
g_mutex_lock (model->priv->notify_lock);
while (*save_list) {
GSList *copy = *save_list;
*save_list = NULL;
g_mutex_unlock (model->priv->notify_lock);
/* do it */
process_fn (view, copy, model);
for (l = copy; l; l = l->next) {
if (l->data) {
free_fn (l->data);
}
}
g_slist_free (copy);
g_mutex_lock (model->priv->notify_lock);
}
*in = FALSE;
g_mutex_unlock (model->priv->notify_lock);
}
static void
client_view_objects_added_cb (ECalClientView *view, const GSList *objects, ECalModel *model)
{
process_event (view, objects, model,
process_added, &model->priv->in_added, &model->priv->notify_added,
(gpointer (*)(gpointer)) icalcomponent_new_clone, (void (*)(gpointer)) icalcomponent_free);
}
static void
client_view_objects_modified_cb (ECalClientView *view, const GSList *objects, ECalModel *model)
{
process_event (view, objects, model,
process_modified, &model->priv->in_modified, &model->priv->notify_modified,
(gpointer (*)(gpointer)) icalcomponent_new_clone, (void (*)(gpointer)) icalcomponent_free);
}
static void
client_view_objects_removed_cb (ECalClientView *view, const GSList *ids, ECalModel *model)
{
process_event (view, ids, model,
process_removed, &model->priv->in_removed, &model->priv->notify_removed,
copy_comp_id, free_comp_id);
}
static void
client_view_progress_cb (ECalClientView *view, gint percent, const gchar *message, gpointer user_data)
{
ECalModel *model = (ECalModel *) user_data;
ECalClient *client = e_cal_client_view_get_client (view);
g_return_if_fail (E_IS_CAL_MODEL (model));
g_signal_emit (G_OBJECT (model), signals[CAL_VIEW_PROGRESS], 0, message,
percent, e_cal_client_get_source_type (client));
}
static void
client_view_complete_cb (ECalClientView *view, const GError *error, gpointer user_data)
{
ECalModel *model = (ECalModel *) user_data;
ECalClient *client = e_cal_client_view_get_client (view);
g_return_if_fail (E_IS_CAL_MODEL (model));
g_signal_emit (G_OBJECT (model), signals[CAL_VIEW_COMPLETE], 0, error,
e_cal_client_get_source_type (client));
}
struct get_view_data
{
ECalModel *model; /* do not touch this, if cancelled */
ECalModelClient *client_data; /* do not touch this, if cancelled */
GCancellable *cancellable;
guint tries;
};
static void
free_get_view_data (struct get_view_data *gvd)
{
if (!gvd)
return;
g_object_unref (gvd->cancellable);
g_free (gvd);
}
static gboolean retry_get_view_timeout_cb (gpointer user_data);
static void
get_view_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
struct get_view_data *gvd = user_data;
GError *error = NULL;
ECalClientView *view = NULL;
g_return_if_fail (source_object != NULL);
g_return_if_fail (result != NULL);
g_return_if_fail (gvd != NULL);
g_return_if_fail (gvd->model != NULL);
g_return_if_fail (gvd->client_data != NULL);
if (!e_cal_client_get_view_finish (E_CAL_CLIENT (source_object), result, &view, &error)) {
if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_clear_error (&error);
free_get_view_data (gvd);
return;
}
if (gvd->tries < 10) {
gvd->tries++;
g_timeout_add (500, retry_get_view_timeout_cb, gvd);
return;
}
g_debug ("%s: Failed to get view: %s", G_STRFUNC, error ? error->message : "Unknown error");
g_clear_error (&error);
} else {
gvd->client_data->view = view;
g_signal_connect (gvd->client_data->view, "objects-added", G_CALLBACK (client_view_objects_added_cb), gvd->model);
g_signal_connect (gvd->client_data->view, "objects-modified", G_CALLBACK (client_view_objects_modified_cb), gvd->model);
g_signal_connect (gvd->client_data->view, "objects-removed", G_CALLBACK (client_view_objects_removed_cb), gvd->model);
g_signal_connect (gvd->client_data->view, "progress", G_CALLBACK (client_view_progress_cb), gvd->model);
g_signal_connect (gvd->client_data->view, "complete", G_CALLBACK (client_view_complete_cb), gvd->model);
e_cal_client_view_start (gvd->client_data->view, &error);
if (error) {
g_debug ("%s: Failed to start view: %s", G_STRFUNC, error->message);
g_error_free (error);
}
}
free_get_view_data (gvd);
}
static gboolean
retry_get_view_timeout_cb (gpointer user_data)
{
struct get_view_data *gvd = user_data;
if (g_cancellable_is_cancelled (gvd->cancellable)) {
free_get_view_data (gvd);
return FALSE;
}
e_cal_client_get_view (gvd->client_data->client, gvd->model->priv->full_sexp, gvd->cancellable, get_view_cb, gvd);
return FALSE;
}
static void
update_e_cal_view_for_client (ECalModel *model, ECalModelClient *client_data)
{
ECalModelPrivate *priv;
struct get_view_data *gvd;
priv = model->priv;
/* Skip if this client has not finished loading yet */
if (!e_client_is_opened (E_CLIENT (client_data->client)))
return;
/* free the previous view, if any */
if (client_data->view) {
g_signal_handlers_disconnect_matched (client_data->view, G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL, model);
g_object_unref (client_data->view);
client_data->view = NULL;
}
/* prepare the view */
g_return_if_fail (priv->full_sexp != NULL);
/* Don't create the new query if we won't use it */
if (!client_data->do_query)
return;
if (client_data->cancellable) {
g_cancellable_cancel (client_data->cancellable);
g_object_unref (client_data->cancellable);
}
client_data->cancellable = g_cancellable_new ();
gvd = g_new0 (struct get_view_data, 1);
gvd->client_data = client_data;
gvd->model = model;
gvd->tries = 0;
gvd->cancellable = g_object_ref (client_data->cancellable);
e_cal_client_get_view (client_data->client, priv->full_sexp, gvd->cancellable, get_view_cb, gvd);
}
void
e_cal_model_update_status_message (ECalModel *model, const gchar *message, gdouble percent)
{
g_return_if_fail (model != NULL);
g_signal_emit (model, signals[STATUS_MESSAGE], 0, message, percent);
}
static void
backend_died_cb (ECalClient *client, gpointer user_data)
{
ECalModel *model;
model = E_CAL_MODEL (user_data);
e_cal_model_remove_client (model, client);
}
static void
cal_model_retrieve_capabilies_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
ECalClient *client = E_CAL_CLIENT (source_object);
ECalModel *model = user_data;
ECalModelClient *client_data;
gchar *capabilities = NULL;
g_return_if_fail (client != NULL);
g_return_if_fail (model != NULL);
e_client_retrieve_capabilities_finish (E_CLIENT (client), result, &capabilities, NULL);
g_free (capabilities);
e_cal_model_update_status_message (model, NULL, -1.0);
client_data = find_client_data (model, client);
g_return_if_fail (client_data);
update_e_cal_view_for_client (model, client_data);
}
struct RetryOpenData
{
EClient *client;
ECalModel *model;
GCancellable *cancellable;
};
static void
free_retry_open_data (gpointer data)
{
struct RetryOpenData *rod = data;
if (!rod)
return;
g_object_unref (rod->client);
g_object_unref (rod->cancellable);
g_free (rod);
}
static gboolean cal_model_retry_open_timeout_cb (gpointer user_data);
static void
client_opened_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
{
ECalClient *client = E_CAL_CLIENT (source_object);
ECalModel *model = (ECalModel *) user_data;
GError *error = NULL;
e_client_open_finish (E_CLIENT (client), result, &error);
if (g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_CANCELLED) ||
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_error_free (error);
return;
}
if (error && g_error_matches (error, E_CLIENT_ERROR, E_CLIENT_ERROR_BUSY)) {
struct RetryOpenData *rod;
rod = g_new0 (struct RetryOpenData, 1);
rod->client = g_object_ref (client);
rod->model = model;
rod->cancellable = g_object_ref (model->priv->loading_clients);
/* postpone for 1/2 of a second, backend is busy now */
g_timeout_add_full (G_PRIORITY_DEFAULT, 500, cal_model_retry_open_timeout_cb, rod, free_retry_open_data);
g_error_free (error);
return;
}
if (error) {
e_cal_model_remove_client (model, client);
g_debug ("%s: Failed to open '%s': %s", G_STRFUNC, e_client_get_uri (E_CLIENT (client)), error->message);
g_error_free (error);
e_cal_model_update_status_message (model, NULL, -1.0);
return;
}
/* to have them ready for later use */
e_client_retrieve_capabilities (E_CLIENT (client), model->priv->loading_clients, cal_model_retrieve_capabilies_cb, model);
}
static gboolean
cal_model_retry_open_timeout_cb (gpointer user_data)
{
struct RetryOpenData *rod = user_data;
g_return_val_if_fail (rod != NULL, FALSE);
g_return_val_if_fail (rod->client != NULL, FALSE);
g_return_val_if_fail (rod->model != NULL, FALSE);
e_client_open (rod->client, TRUE, rod->cancellable, client_opened_cb, rod->model);
return FALSE;
}
static ECalModelClient *
add_new_client (ECalModel *model, ECalClient *client, gboolean do_query)
{
ECalModelPrivate *priv;
ECalModelClient *client_data;
priv = model->priv;
/* DEBUG the load state should always be loaded here
if (e_cal_get_load_state (client) != E_CAL_LOAD_LOADED) {
g_assert_not_reached ();
} */
/* Look to see if we already have this client */
client_data = find_client_data (model, client);
if (client_data) {
if (client_data->do_query)
return client_data;
else
client_data->do_query = do_query;
goto load;
}
client_data = g_new0 (ECalModelClient, 1);
client_data->client = g_object_ref (client);
client_data->view = NULL;
client_data->do_query = do_query;
priv->clients = g_list_append (priv->clients, client_data);
g_signal_connect (G_OBJECT (client_data->client), "backend_died",
G_CALLBACK (backend_died_cb), model);
load:
if (e_client_is_opened (E_CLIENT (client))) {
update_e_cal_view_for_client (model, client_data);
} else {
gchar *msg;
msg = g_strdup_printf (_("Opening %s"), e_client_get_uri (E_CLIENT (client)));
e_cal_model_update_status_message (model, msg, -1.0);
g_free (msg);
e_cal_client_set_default_timezone (client, e_cal_model_get_timezone (model));
e_client_open (E_CLIENT (client), TRUE, model->priv->loading_clients, client_opened_cb, model);
}
return client_data;
}
/**
* e_cal_model_add_client
*/
void
e_cal_model_add_client (ECalModel *model, ECalClient *client)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
g_return_if_fail (E_IS_CAL_CLIENT (client));
add_new_client (model, client, TRUE);
}
static void
remove_client_objects (ECalModel *model, ECalModelClient *client_data)
{
gint i;
/* remove all objects belonging to this client */
for (i = model->priv->objects->len; i > 0; i--) {
ECalModelComponent *comp_data = (ECalModelComponent *) g_ptr_array_index (model->priv->objects, i - 1);
g_return_if_fail (comp_data != NULL);
if (comp_data->client == client_data->client) {
GSList *l = NULL;
g_ptr_array_remove (model->priv->objects, comp_data);
l = g_slist_append (l, comp_data);
g_signal_emit (G_OBJECT (model), signals[COMPS_DELETED], 0, l);
g_slist_free (l);
g_object_unref (comp_data);
e_table_model_pre_change (E_TABLE_MODEL (model));
e_table_model_row_deleted (E_TABLE_MODEL (model), i - 1);
}
}
/* to notify about changes, because in call of row_deleted there are still all events */
e_table_model_changed (E_TABLE_MODEL (model));
}
static void
remove_client (ECalModel *model, ECalModelClient *client_data)
{
/* FIXME We might not want to disconnect the open signal for the default client */
g_signal_handlers_disconnect_matched (client_data->client, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model);
if (client_data->view)
g_signal_handlers_disconnect_matched (client_data->view, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, model);
remove_client_objects (model, client_data);
/* If this is the default client and we were querying (so it
* was also a source), keep it around but don't query it */
if (model->priv->default_client == client_data->client && client_data->do_query) {
client_data->do_query = FALSE;
return;
}
if (model->priv->default_client == client_data->client)
model->priv->default_client = NULL;
/* Remove the client from the list */
model->priv->clients = g_list_remove (model->priv->clients, client_data);
/* free all remaining memory */
g_object_unref (client_data->client);
if (client_data->view)
g_object_unref (client_data->view);
g_free (client_data);
}
/**
* e_cal_model_remove_client
*/
void
e_cal_model_remove_client (ECalModel *model, ECalClient *client)
{
ECalModelClient *client_data;
g_return_if_fail (E_IS_CAL_MODEL (model));
g_return_if_fail (E_IS_CAL_CLIENT (client));
client_data = find_client_data (model, client);
if (client_data)
remove_client (model, client_data);
}
/**
* e_cal_model_remove_all_clients
*/
void
e_cal_model_remove_all_clients (ECalModel *model)
{
ECalModelPrivate *priv;
g_return_if_fail (E_IS_CAL_MODEL (model));
priv = model->priv;
while (priv->clients != NULL) {
ECalModelClient *client_data = (ECalModelClient *) priv->clients->data;
remove_client (model, client_data);
}
}
static GSList *
get_objects_as_list (ECalModel *model)
{
gint i;
GSList *l = NULL;
ECalModelPrivate *priv = model->priv;
for (i = 0; i < priv->objects->len; i++) {
ECalModelComponent *comp_data;
comp_data = g_ptr_array_index (priv->objects, i);
if (comp_data == NULL) {
g_warning ("comp_data is null\n");
continue;
}
l = g_slist_prepend (l, comp_data);
}
return l;
}
struct cc_data
{
ECalModel *model;
EFlag *eflag;
};
static gboolean
cleanup_content_cb (gpointer user_data)
{
ECalModel *model;
ECalModelPrivate *priv;
GSList *slist;
gint len;
struct cc_data *data = user_data;
g_return_val_if_fail (data != NULL, FALSE);
g_return_val_if_fail (data->model != NULL, FALSE);
g_return_val_if_fail (data->eflag != NULL, FALSE);
model = data->model;
priv = model->priv;
g_return_val_if_fail (priv != NULL, FALSE);
e_table_model_pre_change (E_TABLE_MODEL (model));
len = priv->objects->len;
slist = get_objects_as_list (model);
g_ptr_array_set_size (priv->objects, 0);
g_signal_emit (G_OBJECT (model), signals[COMPS_DELETED], 0, slist);
e_table_model_rows_deleted (E_TABLE_MODEL (model), 0, len);
g_slist_foreach (slist, (GFunc) g_object_unref, NULL);
g_slist_free (slist);
e_flag_set (data->eflag);
return FALSE;
}
static void
redo_queries (ECalModel *model)
{
ECalModelPrivate *priv;
GList *l;
struct cc_data data;
priv = model->priv;
if (priv->full_sexp)
g_free (priv->full_sexp);
if (priv->start != -1 && priv->end != -1) {
gchar *iso_start, *iso_end;
iso_start = isodate_from_time_t (priv->start);
iso_end = isodate_from_time_t (priv->end);
if (priv->search_sexp) {
priv->full_sexp = g_strdup_printf ("(and (occur-in-time-range? (make-time \"%s\")"
" (make-time \"%s\"))"
" %s)",
iso_start, iso_end,
priv->search_sexp ? priv->search_sexp : "");
} else {
priv->full_sexp = g_strdup_printf ("(occur-in-time-range? (make-time \"%s\")"
" (make-time \"%s\"))",
iso_start, iso_end);
}
g_free (iso_start);
g_free (iso_end);
} else if (priv->search_sexp) {
priv->full_sexp = g_strdup (priv->search_sexp);
} else {
priv->full_sexp = g_strdup ("#f");
}
/* clean up the current contents, which should be done
always from the main thread, because of gtk calls during removal */
data.model = model;
data.eflag = e_flag_new ();
if (!g_main_context_is_owner (g_main_context_default ())) {
/* function called from other than main thread */
g_timeout_add (10, cleanup_content_cb, &data);
e_flag_wait (data.eflag);
} else {
cleanup_content_cb (&data);
}
e_flag_free (data.eflag);
/* update the view for all clients */
for (l = priv->clients; l != NULL; l = l->next) {
ECalModelClient *client_data;
client_data = (ECalModelClient *) l->data;
update_e_cal_view_for_client (model, client_data);
}
}
void
e_cal_model_get_time_range (ECalModel *model, time_t *start, time_t *end)
{
ECalModelPrivate *priv;
g_return_if_fail (model != NULL);
g_return_if_fail (E_IS_CAL_MODEL (model));
priv = model->priv;
if (start)
*start = priv->start;
if (end)
*end = priv->end;
}
void
e_cal_model_set_time_range (ECalModel *model, time_t start, time_t end)
{
ECalModelPrivate *priv;
g_return_if_fail (model != NULL);
g_return_if_fail (E_IS_CAL_MODEL (model));
g_return_if_fail (start >= 0 && end >= 0);
g_return_if_fail (start <= end);
priv = model->priv;
if (priv->start == start && priv->end == end)
return;
priv->start = start;
priv->end = end;
g_signal_emit (G_OBJECT (model), signals[TIME_RANGE_CHANGED], 0, start, end);
redo_queries (model);
}
const gchar *
e_cal_model_get_search_query (ECalModel *model)
{
ECalModelPrivate *priv;
g_return_val_if_fail (model != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
priv = model->priv;
return priv->search_sexp;
}
/**
* e_cal_model_set_query
*/
void
e_cal_model_set_search_query (ECalModel *model, const gchar *sexp)
{
ECalModelPrivate *priv;
g_return_if_fail (E_IS_CAL_MODEL (model));
priv = model->priv;
if (!strcmp (sexp ? sexp : "", priv->search_sexp ? priv->search_sexp : ""))
return;
if (priv->search_sexp)
g_free (priv->search_sexp);
priv->search_sexp = g_strdup (sexp);
redo_queries (model);
}
/**
* e_cal_model_set_query
*/
void
e_cal_model_set_search_query_with_time_range (ECalModel *model, const gchar *sexp, time_t start, time_t end)
{
ECalModelPrivate *priv;
gboolean do_query = FALSE;
g_return_if_fail (E_IS_CAL_MODEL (model));
priv = model->priv;
if (strcmp (sexp ? sexp : "", priv->search_sexp ? priv->search_sexp : "")) {
if (priv->search_sexp)
g_free (priv->search_sexp);
priv->search_sexp = g_strdup (sexp);
do_query = TRUE;
}
if (!(priv->start == start && priv->end == end)) {
priv->start = start;
priv->end = end;
do_query = TRUE;
g_signal_emit (G_OBJECT (model), signals[TIME_RANGE_CHANGED], 0, start, end);
}
if (do_query)
redo_queries (model);
}
/**
* e_cal_model_create_component_with_defaults
*/
icalcomponent *
e_cal_model_create_component_with_defaults (ECalModel *model, gboolean all_day)
{
ECalModelPrivate *priv;
ECalComponent *comp;
icalcomponent *icalcomp;
ECalClient *client;
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
priv = model->priv;
g_return_val_if_fail (priv->clients != NULL, NULL);
client = e_cal_model_get_default_client (model);
if (!client)
return icalcomponent_new (priv->kind);
switch (priv->kind) {
case ICAL_VEVENT_COMPONENT :
comp = cal_comp_event_new_with_defaults (
client, all_day,
e_cal_model_get_use_default_reminder (model),
e_cal_model_get_default_reminder_interval (model),
e_cal_model_get_default_reminder_units (model));
break;
case ICAL_VTODO_COMPONENT :
comp = cal_comp_task_new_with_defaults (client);
break;
case ICAL_VJOURNAL_COMPONENT :
comp = cal_comp_memo_new_with_defaults (client);
break;
default:
return NULL;
}
if (!comp)
return icalcomponent_new (priv->kind);
icalcomp = icalcomponent_new_clone (e_cal_component_get_icalcomponent (comp));
g_object_unref (comp);
/* make sure the component has an UID */
if (!icalcomponent_get_uid (icalcomp)) {
gchar *uid;
uid = e_cal_component_gen_uid ();
icalcomponent_set_uid (icalcomp, uid);
g_free (uid);
}
return icalcomp;
}
/**
* e_cal_model_get_color_for_component
*/
const gchar *
e_cal_model_get_color_for_component (ECalModel *model, ECalModelComponent *comp_data)
{
ECalModelClass *model_class;
const gchar *color = NULL;
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
g_return_val_if_fail (comp_data != NULL, NULL);
model_class = (ECalModelClass *) G_OBJECT_GET_CLASS (model);
if (model_class->get_color_for_component != NULL)
color = model_class->get_color_for_component (model, comp_data);
if (!color)
color = ecm_get_color_for_component (model, comp_data);
return color;
}
/**
* e_cal_model_get_rgb_color_for_component
*/
gboolean
e_cal_model_get_rgb_color_for_component (ECalModel *model, ECalModelComponent *comp_data, double *red, double *green, double *blue)
{
GdkColor gdk_color;
const gchar *color;
color = e_cal_model_get_color_for_component (model, comp_data);
if (color && gdk_color_parse (color, &gdk_color)) {
if (red)
*red = ((double) gdk_color.red)/0xffff;
if (green)
*green = ((double) gdk_color.green)/0xffff;
if (blue)
*blue = ((double) gdk_color.blue)/0xffff;
return TRUE;
}
return FALSE;
}
/**
* e_cal_model_get_component_at
*/
ECalModelComponent *
e_cal_model_get_component_at (ECalModel *model, gint row)
{
ECalModelPrivate *priv;
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
priv = model->priv;
g_return_val_if_fail (row >= 0 && row < priv->objects->len, NULL);
return g_ptr_array_index (priv->objects, row);
}
ECalModelComponent *
e_cal_model_get_component_for_uid (ECalModel *model, const ECalComponentId *id)
{
ECalModelPrivate *priv;
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
priv = model->priv;
return search_by_id_and_client (priv, NULL, id);
}
/**
* e_cal_model_date_value_to_string
*/
gchar *
e_cal_model_date_value_to_string (ECalModel *model, gconstpointer value)
{
ECalModelPrivate *priv;
ECellDateEditValue *dv = (ECellDateEditValue *) value;
struct icaltimetype tt;
struct tm tmp_tm;
gchar buffer[64];
g_return_val_if_fail (E_IS_CAL_MODEL (model), g_strdup (""));
priv = model->priv;
if (!dv)
return g_strdup ("");
/* We currently convert all the dates to the current timezone. */
tt = dv->tt;
icaltimezone_convert_time (&tt, dv->zone, priv->zone);
tmp_tm.tm_year = tt.year - 1900;
tmp_tm.tm_mon = tt.month - 1;
tmp_tm.tm_mday = tt.day;
tmp_tm.tm_hour = tt.hour;
tmp_tm.tm_min = tt.minute;
tmp_tm.tm_sec = tt.second;
tmp_tm.tm_isdst = -1;
tmp_tm.tm_wday = time_day_of_week (tt.day, tt.month - 1, tt.year);
memset (buffer, 0, sizeof (buffer));
e_time_format_date_and_time (&tmp_tm, priv->use_24_hour_format,
TRUE, FALSE,
buffer, sizeof (buffer));
return g_strdup (buffer);
}
/* FIXME is it still needed ?
static ECellDateEditValue *
copy_ecdv (ECellDateEditValue *ecdv)
{
ECellDateEditValue *new_ecdv;
new_ecdv = g_new0 (ECellDateEditValue, 1);
new_ecdv->tt = ecdv ? ecdv->tt : icaltime_null_time ();
new_ecdv->zone = ecdv ? ecdv->zone : NULL;
return new_ecdv;
} */
struct _ECalModelComponentPrivate {
gchar nouse;
};
static void e_cal_model_component_finalize (GObject *object);
static GObjectClass *component_parent_class;
/* Class initialization function for the calendar component object */
static void
e_cal_model_component_class_init (ECalModelComponentClass *class)
{
GObjectClass *object_class;
object_class = (GObjectClass *) class;
component_parent_class = g_type_class_peek_parent (class);
object_class->finalize = e_cal_model_component_finalize;
}
static void
e_cal_model_component_finalize (GObject *object)
{
ECalModelComponent *comp_data = E_CAL_MODEL_COMPONENT (object);
if (comp_data->client) {
g_object_unref (comp_data->client);
comp_data->client = NULL;
}
if (comp_data->icalcomp) {
icalcomponent_free (comp_data->icalcomp);
comp_data->icalcomp = NULL;
}
if (comp_data->dtstart) {
g_free (comp_data->dtstart);
comp_data->dtstart = NULL;
}
if (comp_data->dtend) {
g_free (comp_data->dtend);
comp_data->dtend = NULL;
}
if (comp_data->due) {
g_free (comp_data->due);
comp_data->due = NULL;
}
if (comp_data->completed) {
g_free (comp_data->completed);
comp_data->completed = NULL;
}
if (comp_data->created) {
g_free (comp_data->created);
comp_data->created = NULL;
}
if (comp_data->lastmodified) {
g_free (comp_data->lastmodified);
comp_data->lastmodified = NULL;
}
if (comp_data->color) {
g_free (comp_data->color);
comp_data->color = NULL;
}
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (component_parent_class)->finalize (object);
}
/* Object initialization function for the calendar component object */
static void
e_cal_model_component_init (ECalModelComponent *comp)
{
comp->dtstart = NULL;
comp->dtend = NULL;
comp->due = NULL;
comp->completed = NULL;
comp->created = NULL;
comp->lastmodified = NULL;
comp->color = NULL;
}
GType
e_cal_model_component_get_type (void)
{
static GType e_cal_model_component_type = 0;
if (!e_cal_model_component_type) {
static GTypeInfo info = {
sizeof (ECalModelComponentClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) e_cal_model_component_class_init,
NULL, NULL,
sizeof (ECalModelComponent),
0,
(GInstanceInitFunc) e_cal_model_component_init
};
e_cal_model_component_type = g_type_register_static (G_TYPE_OBJECT, "ECalModelComponent", &info, 0);
}
return e_cal_model_component_type;
}
/**
* e_cal_model_generate_instances_sync
*
* cb function is not called with cb_data, but with ECalModelGenerateInstancesData which contains cb_data
*/
void
e_cal_model_generate_instances_sync (ECalModel *model, time_t start, time_t end,
ECalRecurInstanceFn cb, gpointer cb_data)
{
ECalModelGenerateInstancesData mdata;
gint i, n;
n = e_table_model_row_count (E_TABLE_MODEL (model));
for (i = 0; i < n; i++) {
ECalModelComponent *comp_data = e_cal_model_get_component_at (model, i);
mdata.comp_data = comp_data;
mdata.cb_data = cb_data;
if (comp_data->instance_start < end && comp_data->instance_end > start)
e_cal_client_generate_instances_for_object_sync (comp_data->client, comp_data->icalcomp, start, end, cb, &mdata);
}
}
/**
* e_cal_model_get_object_array
*/
GPtrArray *
e_cal_model_get_object_array (ECalModel *model)
{
g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);
return model->priv->objects;
}
void
e_cal_model_set_instance_times (ECalModelComponent *comp_data, const icaltimezone *zone)
{
struct icaltimetype start_time, end_time;
icalcomponent_kind kind;
kind = icalcomponent_isa (comp_data->icalcomp);
start_time = icalcomponent_get_dtstart (comp_data->icalcomp);
end_time = icalcomponent_get_dtend (comp_data->icalcomp);
if (kind == ICAL_VEVENT_COMPONENT) {
if (start_time.is_date && icaltime_is_null_time (end_time)) {
/* If end_time is null and it's an all day event,
* just make start_time = end_time so that end_time
* will be a valid date
*/
end_time = start_time;
icaltime_adjust (&end_time, 1, 0, 0, 0);
icalcomponent_set_dtend (comp_data->icalcomp, end_time);
} else if (start_time.is_date && end_time.is_date &&
(icaltime_compare_date_only (start_time, end_time) == 0)) {
/* If both DTSTART and DTEND are DATE values, and they are the
same day, we add 1 day to DTEND. This means that most
events created with the old Evolution behavior will still
work OK. */
icaltime_adjust (&end_time, 1, 0, 0, 0);
icalcomponent_set_dtend (comp_data->icalcomp, end_time);
}
}
if (start_time.zone)
zone = start_time.zone;
else {
icalparameter *param = NULL;
icalproperty *prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY);
if (prop) {
param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
if (param) {
const gchar *tzid = NULL;
icaltimezone *st_zone = NULL;
tzid = icalparameter_get_tzid (param);
if (tzid)
e_cal_client_get_timezone_sync (comp_data->client, tzid, &st_zone, NULL, NULL);
if (st_zone)
zone = st_zone;
}
}
}
comp_data->instance_start = icaltime_as_timet_with_zone (start_time, zone);
if (end_time.zone)
zone = end_time.zone;
else {
icalparameter *param = NULL;
icalproperty *prop = icalcomponent_get_first_property (comp_data->icalcomp, ICAL_DTSTART_PROPERTY);
if (prop) {
param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
if (param) {
const gchar *tzid = NULL;
icaltimezone *end_zone = NULL;
tzid = icalparameter_get_tzid (param);
if (tzid)
e_cal_client_get_timezone_sync (comp_data->client, tzid, &end_zone, NULL, NULL);
if (end_zone)
zone = end_zone;
}
}
}
comp_data->instance_end = icaltime_as_timet_with_zone (end_time, zone);
}
/**
* e_cal_model_set_default_time_func:
* This function will be used when creating new item from the "click-to-add",
* when user didn't fill a start date there.
**/
void
e_cal_model_set_default_time_func (ECalModel *model, ECalModelDefaultTimeFunc func, gpointer user_data)
{
g_return_if_fail (E_IS_CAL_MODEL (model));
model->priv->get_default_time = func;
model->priv->get_default_time_user_data = user_data;
}
|