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 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985
|
/* Evolution calendar - iCalendar component object
*
* Copyright (C) 2000 Ximian, Inc.
* Copyright (C) 2000 Ximian, Inc.
*
* Author: Federico Mena-Quintero <federico@ximian.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <glib.h>
#include <glib/gi18n-lib.h>
#include "e-cal-component.h"
#include "e-cal-time-util.h"
#ifdef G_OS_WIN32
#define getgid() 0
#define getppid() 0
#endif
/* Extension property for alarm components so that we can reference them by UID */
#define EVOLUTION_ALARM_UID_PROPERTY "X-EVOLUTION-ALARM-UID"
struct attendee {
icalproperty *prop;
icalparameter *cutype_param;
icalparameter *member_param;
icalparameter *role_param;
icalparameter *partstat_param;
icalparameter *rsvp_param;
icalparameter *delto_param;
icalparameter *delfrom_param;
icalparameter *sentby_param;
icalparameter *cn_param;
icalparameter *language_param;
};
struct attachment {
icalproperty *prop;
icalattach *attach;
};
struct text {
icalproperty *prop;
icalparameter *altrep_param;
};
struct datetime {
icalproperty *prop;
icalparameter *tzid_param;
};
struct organizer {
icalproperty *prop;
icalparameter *sentby_param;
icalparameter *cn_param;
icalparameter *language_param;
};
struct period {
icalproperty *prop;
icalparameter *value_param;
};
struct recur_id {
struct datetime recur_time;
icalparameter *range_param;
};
/* Private part of the CalComponent structure */
struct _ECalComponentPrivate {
/* The icalcomponent we wrap */
icalcomponent *icalcomp;
/* Properties */
icalproperty *uid;
icalproperty *status;
GSList *attendee_list;
icalproperty *categories;
icalproperty *classification;
GSList *comment_list; /* list of struct text */
icalproperty *completed;
GSList *contact_list; /* list of struct text */
icalproperty *created;
GSList *description_list; /* list of struct text */
struct datetime dtstart;
struct datetime dtend;
icalproperty *dtstamp;
/* The DURATION property can be used instead of the VEVENT DTEND or
the VTODO DUE dates. We do not use it directly ourselves, but we
must be able to handle it from incoming data. If a DTEND or DUE
is requested, we convert the DURATION if necessary. If DTEND or
DUE is set, we remove any DURATION. */
icalproperty *duration;
struct datetime due;
GSList *exdate_list; /* list of struct datetime */
GSList *exrule_list; /* list of icalproperty objects */
struct organizer organizer;
icalproperty *geo;
icalproperty *last_modified;
icalproperty *percent;
icalproperty *priority;
struct recur_id recur_id;
GSList *rdate_list; /* list of struct period */
GSList *rrule_list; /* list of icalproperty objects */
icalproperty *sequence;
struct {
icalproperty *prop;
icalparameter *altrep_param;
} summary;
icalproperty *transparency;
icalproperty *url;
icalproperty *location;
GSList *attachment_list;
/* Subcomponents */
GHashTable *alarm_uid_hash;
/* Whether we should increment the sequence number when piping the
* object over the wire.
*/
guint need_sequence_inc : 1;
};
/* Private structure for alarms */
struct _ECalComponentAlarm {
/* Alarm icalcomponent we wrap */
icalcomponent *icalcomp;
/* Our extension UID property */
icalproperty *uid;
/* Properties */
icalproperty *action;
icalproperty *attach; /* FIXME: see scan_alarm_property() below */
struct {
icalproperty *prop;
icalparameter *altrep_param;
} description;
icalproperty *duration;
icalproperty *repeat;
icalproperty *trigger;
GSList *attendee_list;
};
static void e_cal_component_class_init (ECalComponentClass *klass);
static void e_cal_component_init (ECalComponent *comp, ECalComponentClass *klass);
static void e_cal_component_finalize (GObject *object);
static GObjectClass *parent_class;
/**
* e_cal_component_get_type:
*
* Registers the #ECalComponent class if necessary, and returns the type ID
* associated to it.
*
* Return value: The type ID of the #ECalComponent class.
**/
GType
e_cal_component_get_type (void)
{
static GType e_cal_component_type = 0;
if (!e_cal_component_type) {
static GTypeInfo info = {
sizeof (ECalComponentClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) e_cal_component_class_init,
NULL, NULL,
sizeof (ECalComponent),
0,
(GInstanceInitFunc) e_cal_component_init
};
e_cal_component_type = g_type_register_static (G_TYPE_OBJECT, "ECalComponent", &info, 0);
}
return e_cal_component_type;
}
/* Class initialization function for the calendar component object */
static void
e_cal_component_class_init (ECalComponentClass *klass)
{
GObjectClass *object_class;
object_class = (GObjectClass *) klass;
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = e_cal_component_finalize;
}
/* Object initialization function for the calendar component object */
static void
e_cal_component_init (ECalComponent *comp, ECalComponentClass *klass)
{
ECalComponentPrivate *priv;
priv = g_new0 (ECalComponentPrivate, 1);
comp->priv = priv;
priv->alarm_uid_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
/* Does a simple g_free() of the elements of a GSList and then frees the list
* itself. Returns NULL.
*/
static GSList *
free_slist (GSList *slist)
{
GSList *l;
for (l = slist; l; l = l->next)
g_free (l->data);
g_slist_free (slist);
return NULL;
}
/* Used from g_hash_table_foreach_remove() to free the alarm UIDs hash table.
* We do not need to do anything to individual elements since we were storing
* the UID pointers inside the icalproperties themselves.
*/
static gboolean
free_alarm_cb (gpointer key, gpointer value, gpointer data)
{
return TRUE;
}
/* Frees the internal icalcomponent only if it does not have a parent. If it
* does, it means we don't own it and we shouldn't free it.
*/
static void
free_icalcomponent (ECalComponent *comp, gboolean free)
{
ECalComponentPrivate *priv;
GSList *l;
priv = comp->priv;
if (!priv->icalcomp)
return;
/* Free the icalcomponent */
if (free && icalcomponent_get_parent (priv->icalcomp) == NULL) {
icalcomponent_free (priv->icalcomp);
priv->icalcomp = NULL;
}
/* Free the mappings */
priv->uid = NULL;
priv->status = NULL;
for (l = priv->attachment_list; l != NULL; l = l->next)
g_free (l->data);
g_slist_free (priv->attachment_list);
priv->attachment_list = NULL;
for (l = priv->attendee_list; l != NULL; l = l->next)
g_free (l->data);
g_slist_free (priv->attendee_list);
priv->attendee_list = NULL;
priv->categories = NULL;
priv->classification = NULL;
priv->comment_list = NULL;
priv->completed = NULL;
priv->contact_list = NULL;
priv->created = NULL;
priv->description_list = free_slist (priv->description_list);
priv->dtend.prop = NULL;
priv->dtend.tzid_param = NULL;
priv->dtstamp = NULL;
priv->dtstart.prop = NULL;
priv->dtstart.tzid_param = NULL;
priv->due.prop = NULL;
priv->due.tzid_param = NULL;
priv->duration = NULL;
priv->exdate_list = free_slist (priv->exdate_list);
g_slist_free (priv->exrule_list);
priv->exrule_list = NULL;
priv->geo = NULL;
priv->last_modified = NULL;
priv->percent = NULL;
priv->priority = NULL;
priv->rdate_list = free_slist (priv->rdate_list);
g_slist_free (priv->rrule_list);
priv->rrule_list = NULL;
priv->sequence = NULL;
priv->summary.prop = NULL;
priv->summary.altrep_param = NULL;
priv->transparency = NULL;
priv->url = NULL;
priv->location = NULL;
/* Free the subcomponents */
g_hash_table_foreach_remove (priv->alarm_uid_hash, free_alarm_cb, NULL);
/* Clean up */
priv->need_sequence_inc = FALSE;
}
/* Finalize handler for the calendar component object */
static void
e_cal_component_finalize (GObject *object)
{
ECalComponent *comp;
ECalComponentPrivate *priv;
g_return_if_fail (object != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (object));
comp = E_CAL_COMPONENT (object);
priv = comp->priv;
free_icalcomponent (comp, TRUE);
g_hash_table_destroy (priv->alarm_uid_hash);
priv->alarm_uid_hash = NULL;
g_free (priv);
comp->priv = NULL;
if (G_OBJECT_CLASS (parent_class)->finalize)
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
/**
* e_cal_component_gen_uid:
*
* Generates a unique identifier suitable for calendar components.
*
* Return value: A unique identifier string. Every time this function is called
* a different string is returned.
**/
char *
e_cal_component_gen_uid (void)
{
char *iso, *ret;
static char *hostname;
time_t t = time (NULL);
static int serial;
if (!hostname) {
#ifndef G_OS_WIN32
static char buffer [512];
if ((gethostname (buffer, sizeof (buffer) - 1) == 0) &&
(buffer [0] != 0))
hostname = buffer;
else
hostname = "localhost";
#else
hostname = g_get_host_name ();
#endif
}
iso = isodate_from_time_t (t);
ret = g_strdup_printf ("%s-%d-%d-%d-%d@%s",
iso,
getpid (),
getgid (),
getppid (),
serial++,
hostname);
g_free (iso);
return ret;
}
/**
* e_cal_component_new:
*
* Creates a new empty calendar component object. Once created, you should set it from an
* existing #icalcomponent structure by using e_cal_component_set_icalcomponent() or with a
* new empty component type by using e_cal_component_set_new_vtype().
*
* Return value: A newly-created calendar component object.
**/
ECalComponent *
e_cal_component_new (void)
{
return E_CAL_COMPONENT (g_object_new (E_TYPE_CAL_COMPONENT, NULL));
}
/**
* e_cal_component_new_from_string:
* @calobj: A string representation of an iCalendar component.
*
* Creates a new calendar component object from the given iCalendar string.
*
* Return value: A calendar component representing the given iCalendar string on
* success, NULL if there was an error.
**/
ECalComponent *
e_cal_component_new_from_string (const char *calobj)
{
ECalComponent *comp;
icalcomponent *icalcomp;
g_return_val_if_fail (calobj != NULL, NULL);
icalcomp = icalparser_parse_string (calobj);
if (!icalcomp)
return NULL;
comp = e_cal_component_new ();
if (!e_cal_component_set_icalcomponent (comp, icalcomp)) {
icalcomponent_free (icalcomp);
g_object_unref (comp);
return NULL;
}
return comp;
}
/**
* e_cal_component_clone:
* @comp: A calendar component object.
*
* Creates a new calendar component object by copying the information from
* another one.
*
* Return value: A newly-created calendar component with the same values as the
* original one.
**/
ECalComponent *
e_cal_component_clone (ECalComponent *comp)
{
ECalComponentPrivate *priv;
ECalComponent *new_comp;
icalcomponent *new_icalcomp;
g_return_val_if_fail (comp != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
priv = comp->priv;
g_return_val_if_fail (priv->need_sequence_inc == FALSE, NULL);
new_comp = e_cal_component_new ();
if (priv->icalcomp) {
new_icalcomp = icalcomponent_new_clone (priv->icalcomp);
e_cal_component_set_icalcomponent (new_comp, new_icalcomp);
}
return new_comp;
}
/* Scans an attachment property */
static void
scan_attachment (GSList **attachment_list, icalproperty *prop)
{
struct attachment *attachment;
attachment = g_new (struct attachment, 1);
attachment->prop = prop;
attachment->attach = icalproperty_get_attach (prop);
*attachment_list = g_slist_append (*attachment_list, attachment);
}
/* Scans an attendee property */
static void
scan_attendee (GSList **attendee_list, icalproperty *prop)
{
struct attendee *attendee;
attendee = g_new (struct attendee, 1);
attendee->prop = prop;
attendee->cutype_param = icalproperty_get_first_parameter (prop, ICAL_CUTYPE_PARAMETER);
attendee->member_param = icalproperty_get_first_parameter (prop, ICAL_MEMBER_PARAMETER);
attendee->role_param = icalproperty_get_first_parameter (prop, ICAL_ROLE_PARAMETER);
attendee->partstat_param = icalproperty_get_first_parameter (prop, ICAL_PARTSTAT_PARAMETER);
attendee->rsvp_param = icalproperty_get_first_parameter (prop, ICAL_RSVP_PARAMETER);
attendee->delto_param = icalproperty_get_first_parameter (prop, ICAL_DELEGATEDTO_PARAMETER);
attendee->delfrom_param = icalproperty_get_first_parameter (prop, ICAL_DELEGATEDFROM_PARAMETER);
attendee->sentby_param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER);
attendee->cn_param = icalproperty_get_first_parameter (prop, ICAL_CN_PARAMETER);
attendee->language_param = icalproperty_get_first_parameter (prop, ICAL_LANGUAGE_PARAMETER);
*attendee_list = g_slist_append (*attendee_list, attendee);
}
/* Scans a date/time and timezone pair property */
static void
scan_datetime (ECalComponent *comp, struct datetime *datetime, icalproperty *prop)
{
ECalComponentPrivate *priv;
priv = comp->priv;
datetime->prop = prop;
datetime->tzid_param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
}
/* Scans an exception date property */
static void
scan_exdate (ECalComponent *comp, icalproperty *prop)
{
ECalComponentPrivate *priv;
struct datetime *dt;
priv = comp->priv;
dt = g_new (struct datetime, 1);
dt->prop = prop;
dt->tzid_param = icalproperty_get_first_parameter (prop, ICAL_TZID_PARAMETER);
priv->exdate_list = g_slist_append (priv->exdate_list, dt);
}
/* Scans and attendee property */
static void
scan_organizer (ECalComponent *comp, struct organizer *organizer, icalproperty *prop)
{
organizer->prop = prop;
organizer->sentby_param = icalproperty_get_first_parameter (prop, ICAL_SENTBY_PARAMETER);
organizer->cn_param = icalproperty_get_first_parameter (prop, ICAL_CN_PARAMETER);
organizer->language_param = icalproperty_get_first_parameter (prop, ICAL_LANGUAGE_PARAMETER);
}
/* Scans an icalperiodtype property */
static void
scan_period (ECalComponent *comp, GSList **list, icalproperty *prop)
{
struct period *period;
period = g_new (struct period, 1);
period->prop = prop;
period->value_param = icalproperty_get_first_parameter (prop, ICAL_VALUE_PARAMETER);
*list = g_slist_append (*list, period);
}
/* Scans an icalrecurtype property */
static void
scan_recur_id (ECalComponent *comp, struct recur_id *recur_id, icalproperty *prop)
{
scan_datetime (comp, &recur_id->recur_time, prop);
recur_id->range_param = icalproperty_get_first_parameter (prop, ICAL_RANGE_PARAMETER);
}
/* Scans an icalrecurtype property */
static void
scan_recur (ECalComponent *comp, GSList **list, icalproperty *prop)
{
*list = g_slist_append (*list, prop);
}
/* Scans the summary property */
static void
scan_summary (ECalComponent *comp, icalproperty *prop)
{
ECalComponentPrivate *priv;
priv = comp->priv;
priv->summary.prop = prop;
priv->summary.altrep_param = icalproperty_get_first_parameter (prop, ICAL_ALTREP_PARAMETER);
}
/* Scans a text (i.e. text + altrep) property */
static void
scan_text (ECalComponent *comp, GSList **text_list, icalproperty *prop)
{
struct text *text;
text = g_new (struct text, 1);
text->prop = prop;
text->altrep_param = icalproperty_get_first_parameter (prop, ICAL_ALTREP_PARAMETER);
*text_list = g_slist_append (*text_list, text);
}
/* Scans an icalproperty and adds its mapping to the component */
static void
scan_property (ECalComponent *comp, icalproperty *prop)
{
ECalComponentPrivate *priv;
icalproperty_kind kind;
priv = comp->priv;
kind = icalproperty_isa (prop);
switch (kind) {
case ICAL_STATUS_PROPERTY:
priv->status = prop;
break;
case ICAL_ATTACH_PROPERTY:
scan_attachment (&priv->attachment_list, prop);
break;
case ICAL_ATTENDEE_PROPERTY:
scan_attendee (&priv->attendee_list, prop);
break;
case ICAL_CATEGORIES_PROPERTY:
priv->categories = prop;
break;
case ICAL_CLASS_PROPERTY:
priv->classification = prop;
break;
case ICAL_COMMENT_PROPERTY:
scan_text (comp, &priv->comment_list, prop);
break;
case ICAL_COMPLETED_PROPERTY:
priv->completed = prop;
break;
case ICAL_CONTACT_PROPERTY:
scan_text (comp, &priv->contact_list, prop);
break;
case ICAL_CREATED_PROPERTY:
priv->created = prop;
break;
case ICAL_DESCRIPTION_PROPERTY:
scan_text (comp, &priv->description_list, prop);
break;
case ICAL_DTEND_PROPERTY:
scan_datetime (comp, &priv->dtend, prop);
break;
case ICAL_DTSTAMP_PROPERTY:
priv->dtstamp = prop;
break;
case ICAL_DTSTART_PROPERTY:
scan_datetime (comp, &priv->dtstart, prop);
break;
case ICAL_DUE_PROPERTY:
scan_datetime (comp, &priv->due, prop);
break;
case ICAL_DURATION_PROPERTY:
priv->duration = prop;
break;
case ICAL_EXDATE_PROPERTY:
scan_exdate (comp, prop);
break;
case ICAL_EXRULE_PROPERTY:
scan_recur (comp, &priv->exrule_list, prop);
break;
case ICAL_GEO_PROPERTY:
priv->geo = prop;
break;
case ICAL_LASTMODIFIED_PROPERTY:
priv->last_modified = prop;
break;
case ICAL_ORGANIZER_PROPERTY:
scan_organizer (comp, &priv->organizer, prop);
break;
case ICAL_PERCENTCOMPLETE_PROPERTY:
priv->percent = prop;
break;
case ICAL_PRIORITY_PROPERTY:
priv->priority = prop;
break;
case ICAL_RECURRENCEID_PROPERTY:
scan_recur_id (comp, &priv->recur_id, prop);
break;
case ICAL_RDATE_PROPERTY:
scan_period (comp, &priv->rdate_list, prop);
break;
case ICAL_RRULE_PROPERTY:
scan_recur (comp, &priv->rrule_list, prop);
break;
case ICAL_SEQUENCE_PROPERTY:
priv->sequence = prop;
break;
case ICAL_SUMMARY_PROPERTY:
scan_summary (comp, prop);
break;
case ICAL_TRANSP_PROPERTY:
priv->transparency = prop;
break;
case ICAL_UID_PROPERTY:
priv->uid = prop;
break;
case ICAL_URL_PROPERTY:
priv->url = prop;
break;
case ICAL_LOCATION_PROPERTY :
priv->location = prop;
break;
default:
break;
}
}
/* Gets our alarm UID string from a property that is known to contain it */
static const char *
alarm_uid_from_prop (icalproperty *prop)
{
const char *xstr;
g_assert (icalproperty_isa (prop) == ICAL_X_PROPERTY);
xstr = icalproperty_get_x (prop);
g_assert (xstr != NULL);
return xstr;
}
/* Sets our alarm UID extension property on an alarm component. Returns a
* pointer to the UID string inside the property itself.
*/
static const char *
set_alarm_uid (icalcomponent *alarm, const char *auid)
{
icalproperty *prop;
const char *inprop_auid;
/* Create the new property */
prop = icalproperty_new_x ((char *) auid);
icalproperty_set_x_name (prop, EVOLUTION_ALARM_UID_PROPERTY);
icalcomponent_add_property (alarm, prop);
inprop_auid = alarm_uid_from_prop (prop);
return inprop_auid;
}
/* Removes any alarm UID extension properties from an alarm subcomponent */
static void
remove_alarm_uid (icalcomponent *alarm)
{
icalproperty *prop;
GSList *list, *l;
list = NULL;
for (prop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
prop;
prop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY)) {
const char *xname;
xname = icalproperty_get_x_name (prop);
g_assert (xname != NULL);
if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0)
list = g_slist_prepend (list, prop);
}
for (l = list; l; l = l->next) {
prop = l->data;
icalcomponent_remove_property (alarm, prop);
icalproperty_free (prop);
}
g_slist_free (list);
}
/* Adds an alarm subcomponent to the calendar component's mapping table. The
* actual UID with which it gets added may not be the same as the specified one;
* this function will change it if the table already had an alarm subcomponent
* with the specified UID. Returns the actual UID used.
*/
static const char *
add_alarm (ECalComponent *comp, icalcomponent *alarm, const char *auid)
{
ECalComponentPrivate *priv;
icalcomponent *old_alarm;
priv = comp->priv;
/* First we see if we already have an alarm with the requested UID. In
* that case, we need to change the new UID to something else. This
* should never happen, but who knows.
*/
old_alarm = g_hash_table_lookup (priv->alarm_uid_hash, auid);
if (old_alarm != NULL) {
char *new_auid;
g_message ("add_alarm(): Got alarm with duplicated UID `%s', changing it...", auid);
remove_alarm_uid (alarm);
new_auid = e_cal_component_gen_uid ();
auid = set_alarm_uid (alarm, new_auid);
g_free (new_auid);
}
g_hash_table_insert (priv->alarm_uid_hash, (char *) auid, alarm);
return auid;
}
/* Scans an alarm subcomponent, adds an UID extension property to it (so that we
* can reference alarms by unique IDs), and adds its mapping to the component. */
static void
scan_alarm (ECalComponent *comp, icalcomponent *alarm)
{
ECalComponentPrivate *priv;
icalproperty *prop;
const char *auid;
char *new_auid;
priv = comp->priv;
for (prop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
prop;
prop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY)) {
const char *xname;
xname = icalproperty_get_x_name (prop);
g_assert (xname != NULL);
if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0) {
auid = alarm_uid_from_prop (prop);
add_alarm (comp, alarm, auid);
return;
}
}
/* The component has no alarm UID property, so we create one. */
new_auid = e_cal_component_gen_uid ();
auid = set_alarm_uid (alarm, new_auid);
g_free (new_auid);
add_alarm (comp, alarm, auid);
}
/* Scans an icalcomponent for its properties so that we can provide
* random-access to them. It also builds a hash table of the component's alarm
* subcomponents.
*/
static void
scan_icalcomponent (ECalComponent *comp)
{
ECalComponentPrivate *priv;
icalproperty *prop;
icalcompiter iter;
priv = comp->priv;
g_assert (priv->icalcomp != NULL);
/* Scan properties */
for (prop = icalcomponent_get_first_property (priv->icalcomp, ICAL_ANY_PROPERTY);
prop;
prop = icalcomponent_get_next_property (priv->icalcomp, ICAL_ANY_PROPERTY))
scan_property (comp, prop);
/* Scan subcomponents */
for (iter = icalcomponent_begin_component (priv->icalcomp, ICAL_VALARM_COMPONENT);
icalcompiter_deref (&iter) != NULL;
icalcompiter_next (&iter)) {
icalcomponent *subcomp;
subcomp = icalcompiter_deref (&iter);
scan_alarm (comp, subcomp);
}
}
/* Ensures that the mandatory calendar component properties (uid, dtstamp) do
* exist. If they don't exist, it creates them automatically.
*/
static void
ensure_mandatory_properties (ECalComponent *comp)
{
ECalComponentPrivate *priv;
priv = comp->priv;
g_assert (priv->icalcomp != NULL);
if (!priv->uid) {
char *uid;
uid = e_cal_component_gen_uid ();
priv->uid = icalproperty_new_uid (uid);
g_free (uid);
icalcomponent_add_property (priv->icalcomp, priv->uid);
}
if (!priv->dtstamp) {
struct icaltimetype t;
t = icaltime_current_time_with_zone (icaltimezone_get_utc_timezone ());
priv->dtstamp = icalproperty_new_dtstamp (t);
icalcomponent_add_property (priv->icalcomp, priv->dtstamp);
}
}
/**
* e_cal_component_set_new_vtype:
* @comp: A calendar component object.
* @type: Type of calendar component to create.
*
* Clears any existing component data from a calendar component object and
* creates a new #icalcomponent of the specified type for it. The only property
* that will be set in the new component will be its unique identifier.
**/
void
e_cal_component_set_new_vtype (ECalComponent *comp, ECalComponentVType type)
{
ECalComponentPrivate *priv;
icalcomponent *icalcomp;
icalcomponent_kind kind;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
free_icalcomponent (comp, TRUE);
if (type == E_CAL_COMPONENT_NO_TYPE)
return;
/* Figure out the kind and create the icalcomponent */
switch (type) {
case E_CAL_COMPONENT_EVENT:
kind = ICAL_VEVENT_COMPONENT;
break;
case E_CAL_COMPONENT_TODO:
kind = ICAL_VTODO_COMPONENT;
break;
case E_CAL_COMPONENT_JOURNAL:
kind = ICAL_VJOURNAL_COMPONENT;
break;
case E_CAL_COMPONENT_FREEBUSY:
kind = ICAL_VFREEBUSY_COMPONENT;
break;
case E_CAL_COMPONENT_TIMEZONE:
kind = ICAL_VTIMEZONE_COMPONENT;
break;
default:
g_assert_not_reached ();
kind = ICAL_NO_COMPONENT;
}
icalcomp = icalcomponent_new (kind);
if (!icalcomp) {
g_message ("e_cal_component_set_new_vtype(): Could not create the icalcomponent!");
return;
}
/* Scan the component to build our mapping table */
priv->icalcomp = icalcomp;
scan_icalcomponent (comp);
/* Add missing stuff */
ensure_mandatory_properties (comp);
}
/**
* e_cal_component_set_icalcomponent:
* @comp: A calendar component object.
* @icalcomp: An #icalcomponent.
*
* Sets the contents of a calendar component object from an #icalcomponent
* structure. If the @comp already had an #icalcomponent set into it, it will
* will be freed automatically if the #icalcomponent does not have a parent
* component itself.
*
* Supported component types are VEVENT, VTODO, VJOURNAL, VFREEBUSY, and VTIMEZONE.
*
* Return value: TRUE on success, FALSE if @icalcomp is an unsupported component
* type.
**/
gboolean
e_cal_component_set_icalcomponent (ECalComponent *comp, icalcomponent *icalcomp)
{
ECalComponentPrivate *priv;
icalcomponent_kind kind;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
if (priv->icalcomp == icalcomp)
return TRUE;
free_icalcomponent (comp, TRUE);
if (!icalcomp) {
priv->icalcomp = NULL;
return TRUE;
}
kind = icalcomponent_isa (icalcomp);
if (!(kind == ICAL_VEVENT_COMPONENT
|| kind == ICAL_VTODO_COMPONENT
|| kind == ICAL_VJOURNAL_COMPONENT
|| kind == ICAL_VFREEBUSY_COMPONENT
|| kind == ICAL_VTIMEZONE_COMPONENT))
return FALSE;
priv->icalcomp = icalcomp;
scan_icalcomponent (comp);
ensure_mandatory_properties (comp);
return TRUE;
}
/**
* e_cal_component_get_icalcomponent:
* @comp: A calendar component object.
*
* Queries the #icalcomponent structure that a calendar component object is
* wrapping.
*
* Return value: An #icalcomponent structure, or NULL if the @comp has no
* #icalcomponent set to it.
**/
icalcomponent *
e_cal_component_get_icalcomponent (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
priv = comp->priv;
return priv->icalcomp;
}
/**
* e_cal_component_rescan:
* @comp: A calendar component object.
*
* Rescans the #icalcomponent being wrapped by the given calendar component. This
* would replace any value that was changed in the wrapped #icalcomponent.
*/
void
e_cal_component_rescan (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
/* Clear everything out */
free_icalcomponent (comp, FALSE);
/* Rescan */
scan_icalcomponent (comp);
ensure_mandatory_properties (comp);
}
/**
* e_cal_component_strip_errors:
* @comp: A calendar component object.
*
* Strips all error messages from the calendar component. Those error messages are
* added to the iCalendar string representation whenever an invalid is used for
* one of its fields.
*/
void
e_cal_component_strip_errors (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
icalcomponent_strip_errors (priv->icalcomp);
}
/**
* e_cal_component_get_vtype:
* @comp: A calendar component object.
*
* Queries the type of a calendar component object.
*
* Return value: The type of the component, as defined by RFC 2445.
**/
ECalComponentVType
e_cal_component_get_vtype (ECalComponent *comp)
{
ECalComponentPrivate *priv;
icalcomponent_kind kind;
g_return_val_if_fail (comp != NULL, E_CAL_COMPONENT_NO_TYPE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), E_CAL_COMPONENT_NO_TYPE);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, E_CAL_COMPONENT_NO_TYPE);
kind = icalcomponent_isa (priv->icalcomp);
switch (kind) {
case ICAL_VEVENT_COMPONENT:
return E_CAL_COMPONENT_EVENT;
case ICAL_VTODO_COMPONENT:
return E_CAL_COMPONENT_TODO;
case ICAL_VJOURNAL_COMPONENT:
return E_CAL_COMPONENT_JOURNAL;
case ICAL_VFREEBUSY_COMPONENT:
return E_CAL_COMPONENT_FREEBUSY;
case ICAL_VTIMEZONE_COMPONENT:
return E_CAL_COMPONENT_TIMEZONE;
default:
/* We should have been loaded with a supported type! */
g_assert_not_reached ();
return E_CAL_COMPONENT_NO_TYPE;
}
}
/**
* e_cal_component_get_as_string:
* @comp: A calendar component.
*
* Gets the iCalendar string representation of a calendar component. You should
* call e_cal_component_commit_sequence() before this function to ensure that the
* component's sequence number is consistent with the state of the object.
*
* Return value: String representation of the calendar component according to
* RFC 2445.
**/
char *
e_cal_component_get_as_string (ECalComponent *comp)
{
ECalComponentPrivate *priv;
char *str, *buf;
g_return_val_if_fail (comp != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, NULL);
/* Ensure that the user has committed the new SEQUENCE */
g_return_val_if_fail (priv->need_sequence_inc == FALSE, NULL);
/* We dup the string; libical owns that memory */
str = icalcomponent_as_ical_string (priv->icalcomp);
if (str)
buf = g_strdup (str);
else
buf = NULL;
return buf;
}
/* Used from g_hash_table_foreach(); ensures that an alarm subcomponent
* has the mandatory properties it needs.
*/
static void
ensure_alarm_properties_cb (gpointer key, gpointer value, gpointer data)
{
ECalComponent *comp;
ECalComponentPrivate *priv;
icalcomponent *alarm;
icalproperty *prop;
enum icalproperty_action action;
const char *str;
alarm = value;
comp = E_CAL_COMPONENT (data);
priv = comp->priv;
prop = icalcomponent_get_first_property (alarm, ICAL_ACTION_PROPERTY);
if (!prop)
return;
action = icalproperty_get_action (prop);
switch (action) {
case ICAL_ACTION_DISPLAY:
/* Ensure we have a DESCRIPTION property */
prop = icalcomponent_get_first_property (alarm, ICAL_DESCRIPTION_PROPERTY);
if (prop) {
if (priv->summary.prop) {
icalproperty *xprop;
xprop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
while (xprop) {
str = icalproperty_get_x_name (xprop);
if (!strcmp (str, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
icalproperty_set_description (prop, icalproperty_get_summary(priv->summary.prop));
icalcomponent_remove_property (alarm, xprop);
icalproperty_free (xprop);
break;
}
xprop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY);
}
break;
}
}
if (!priv->summary.prop) {
str = _("Untitled appointment");
/* add the X-EVOLUTION-NEEDS-DESCRIPTION property */
prop = icalproperty_new_x ("1");
icalproperty_set_x_name (prop, "X-EVOLUTION-NEEDS-DESCRIPTION");
icalcomponent_add_property (alarm, prop);
} else
str = icalproperty_get_summary (priv->summary.prop);
prop = icalproperty_new_description (str);
icalcomponent_add_property (alarm, prop);
break;
default:
break;
/* FIXME: add other action types here */
}
}
/* Ensures that alarm subcomponents have the mandatory properties they need,
* even when clients may not have set them properly.
*/
static void
ensure_alarm_properties (ECalComponent *comp)
{
ECalComponentPrivate *priv;
priv = comp->priv;
g_hash_table_foreach (priv->alarm_uid_hash, ensure_alarm_properties_cb, comp);
}
/**
* e_cal_component_commit_sequence:
* @comp: A calendar component object.
*
* Increments the sequence number property in a calendar component object if it
* needs it. This needs to be done when any of a number of properties listed in
* RFC 2445 change values, such as the start and end dates of a component.
*
* This function must be called before calling e_cal_component_get_as_string() to
* ensure that the component is fully consistent.
**/
void
e_cal_component_commit_sequence (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
ensure_alarm_properties (comp);
if (!priv->need_sequence_inc)
return;
if (priv->sequence) {
int seq;
seq = icalproperty_get_sequence (priv->sequence);
icalproperty_set_sequence (priv->sequence, seq + 1);
} else {
/* The component had no SEQUENCE property, so assume that the
* default would have been zero. Since it needed incrementing
* anyways, we use a value of 1 here.
*/
priv->sequence = icalproperty_new_sequence (1);
icalcomponent_add_property (priv->icalcomp, priv->sequence);
}
priv->need_sequence_inc = FALSE;
}
/**
* e_cal_component_abort_sequence:
* @comp: A calendar component object.
*
* Aborts the sequence change needed in the given calendar component, which
* means it will not require a sequence commit (via #e_cal_component_commit_sequence)
* even if the changes done require a sequence increment.
*/
void
e_cal_component_abort_sequence (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
priv->need_sequence_inc = FALSE;
}
/**
* e_cal_component_get_id:
* @comp: A calendar component object.
*
* Return value: the id of the component
* */
ECalComponentId *
e_cal_component_get_id (ECalComponent *comp)
{
ECalComponentPrivate *priv;
ECalComponentId *id = NULL;
g_return_val_if_fail (comp != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, NULL);
id = g_new0 (ECalComponentId, 1);
id->uid = g_strdup (icalproperty_get_uid (priv->uid));
id->rid = g_strdup (e_cal_component_get_recurid_as_string (comp));
return id;
}
/**
* e_cal_component_get_uid:
* @comp: A calendar component object.
* @uid: Return value for the UID string.
*
* Queries the unique identifier of a calendar component object.
**/
void
e_cal_component_get_uid (ECalComponent *comp, const char **uid)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (uid != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
/* This MUST exist, since we ensured that it did */
g_assert (priv->uid != NULL);
*uid = icalproperty_get_uid (priv->uid);
}
/**
* e_cal_component_set_uid:
* @comp: A calendar component object.
* @uid: Unique identifier.
*
* Sets the unique identifier string of a calendar component object.
**/
void
e_cal_component_set_uid (ECalComponent *comp, const char *uid)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (uid != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
/* This MUST exist, since we ensured that it did */
g_assert (priv->uid != NULL);
icalproperty_set_uid (priv->uid, (char *) uid);
}
/* Gets a text list value */
static void
get_attachment_list (GSList *attachment_list, GSList **al)
{
GSList *l;
*al = NULL;
if (!attachment_list)
return;
for (l = attachment_list; l; l = l->next) {
struct attachment *attachment;
const char *data;
attachment = l->data;
g_assert (attachment->attach != NULL);
if (icalattach_get_is_url (attachment->attach)) {
/* FIXME : this ref count is screwed up
* These structures are being leaked.
*/
icalattach_ref (attachment->attach);
data = icalattach_get_url (attachment->attach);
}
else
data = NULL;
*al = g_slist_prepend (*al, (char *)data);
}
*al = g_slist_reverse (*al);
}
static void
set_attachment_list (icalcomponent *icalcomp,
GSList **attachment_list,
GSList *al)
{
GSList *l;
/* Remove old attachments */
if (*attachment_list) {
for (l = *attachment_list; l; l = l->next) {
struct attachment *attachment;
attachment = l->data;
g_assert (attachment->prop != NULL);
g_assert (attachment->attach != NULL);
icalcomponent_remove_property (icalcomp, attachment->prop);
icalproperty_free (attachment->prop);
g_free (attachment);
}
g_slist_free (*attachment_list);
*attachment_list = NULL;
}
/* Add in new attachments */
for (l = al; l; l = l->next) {
struct attachment *attachment;
attachment = g_new0 (struct attachment, 1);
attachment->attach = icalattach_new_from_url ((char *) l->data);
attachment->prop = icalproperty_new_attach (attachment->attach);
icalcomponent_add_property (icalcomp, attachment->prop);
*attachment_list = g_slist_prepend (*attachment_list, attachment);
}
*attachment_list = g_slist_reverse (*attachment_list);
}
/**
* e_cal_component_get_attachment_list:
* @comp: A calendar component object.
* @attachment_list: Return list of URLS to attachments.
*
* Queries the attachment properties of the calendar component object. When done,
* the @attachment_list should be freed by calling #g_slist_free.
**/
void
e_cal_component_get_attachment_list (ECalComponent *comp, GSList **attachment_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (attachment_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_attachment_list (priv->attachment_list, attachment_list);
}
/**
* e_cal_component_set_attachment_list:
* @comp: A calendar component object.
* @attachment_list: list of urls to attachment pointers.
*
* This currently handles only attachments that are urls
* in the file system - not inline binaries.
*
* Sets the attachments of a calendar component object
**/
void
e_cal_component_set_attachment_list (ECalComponent *comp, GSList *attachment_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_attachment_list (priv->icalcomp, &priv->attachment_list, attachment_list);
}
/**
* e_cal_component_has_attachments:
* @comp: A calendar component object.
*
* Queries the component to see if it has attachments.
*
* Return value: TRUE if there are attachments, FALSE otherwise.
*/
gboolean
e_cal_component_has_attachments (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
if (g_slist_length (priv->attachment_list) > 0)
return TRUE;
return FALSE;
}
int
e_cal_component_get_num_attachments (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, 0);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), 0);
priv = comp->priv;
return g_slist_length (priv->attachment_list) > 0;
}
/**
* e_cal_component_get_categories:
* @comp: A calendar component object.
* @categories: Return holder for the categories.
*
* Queries the categories of the given calendar component. The categories
* are returned in the @categories argument, which, on success, will contain
* a comma-separated list of all categories set in the component.
**/
void
e_cal_component_get_categories (ECalComponent *comp, const char **categories)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (categories != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (priv->categories)
*categories = icalproperty_get_categories (priv->categories);
else
*categories = NULL;
}
/**
* e_cal_component_set_categories:
* @comp: A calendar component object.
* @categories: Comma-separated list of categories.
*
* Sets the list of categories for a calendar component.
**/
void
e_cal_component_set_categories (ECalComponent *comp, const char *categories)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!categories || !(*categories)) {
if (priv->categories) {
icalcomponent_remove_property (priv->icalcomp, priv->categories);
icalproperty_free (priv->categories);
priv->url = NULL;
}
return;
}
if (priv->categories)
icalproperty_set_categories (priv->categories, (char *) categories);
else {
priv->categories = icalproperty_new_categories ((char *) categories);
icalcomponent_add_property (priv->icalcomp, priv->categories);
}
}
/**
* e_cal_component_get_categories_list:
* @comp: A calendar component object.
* @categ_list: Return value for the list of strings, where each string is a
* category. This should be freed using e_cal_component_free_categories_list().
*
* Queries the list of categories of a calendar component object. Each element
* in the returned categ_list is a string with the corresponding category.
**/
void
e_cal_component_get_categories_list (ECalComponent *comp, GSList **categ_list)
{
ECalComponentPrivate *priv;
const char *categories;
const char *p;
const char *cat_start;
char *str;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (categ_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!priv->categories) {
*categ_list = NULL;
return;
}
categories = icalproperty_get_categories (priv->categories);
g_assert (categories != NULL);
cat_start = categories;
*categ_list = NULL;
for (p = categories; *p; p++)
if (*p == ',') {
str = g_strndup (cat_start, p - cat_start);
*categ_list = g_slist_prepend (*categ_list, str);
cat_start = p + 1;
}
str = g_strndup (cat_start, p - cat_start);
*categ_list = g_slist_prepend (*categ_list, str);
*categ_list = g_slist_reverse (*categ_list);
}
/* Creates a comma-delimited string of categories */
static char *
stringify_categories (GSList *categ_list)
{
GString *s;
GSList *l;
char *str;
s = g_string_new (NULL);
for (l = categ_list; l; l = l->next) {
g_string_append (s, l->data);
if (l->next != NULL)
g_string_append (s, ",");
}
str = s->str;
g_string_free (s, FALSE);
return str;
}
/**
* e_cal_component_set_categories_list:
* @comp: A calendar component object.
* @categ_list: List of strings, one for each category.
*
* Sets the list of categories of a calendar component object.
**/
void
e_cal_component_set_categories_list (ECalComponent *comp, GSList *categ_list)
{
ECalComponentPrivate *priv;
char *categories_str;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!categ_list) {
if (priv->categories) {
icalcomponent_remove_property (priv->icalcomp, priv->categories);
icalproperty_free (priv->categories);
}
return;
}
/* Create a single string of categories */
categories_str = stringify_categories (categ_list);
/* Set the categories */
priv->categories = icalproperty_new_categories (categories_str);
g_free (categories_str);
icalcomponent_add_property (priv->icalcomp, priv->categories);
}
/**
* e_cal_component_get_classification:
* @comp: A calendar component object.
* @classif: Return value for the classification.
*
* Queries the classification of a calendar component object. If the
* classification property is not set on this component, this function returns
* #E_CAL_COMPONENT_CLASS_NONE.
**/
void
e_cal_component_get_classification (ECalComponent *comp, ECalComponentClassification *classif)
{
ECalComponentPrivate *priv;
icalproperty_class class;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (classif != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!priv->classification) {
*classif = E_CAL_COMPONENT_CLASS_NONE;
return;
}
class = icalproperty_get_class (priv->classification);
switch (class)
{
case ICAL_CLASS_PUBLIC:
*classif = E_CAL_COMPONENT_CLASS_PUBLIC;
break;
case ICAL_CLASS_PRIVATE:
*classif = E_CAL_COMPONENT_CLASS_PRIVATE;
break;
case ICAL_CLASS_CONFIDENTIAL:
*classif = E_CAL_COMPONENT_CLASS_CONFIDENTIAL;
break;
default:
*classif = E_CAL_COMPONENT_CLASS_UNKNOWN;
break;
}
}
/**
* e_cal_component_set_classification:
* @comp: A calendar component object.
* @classif: Classification to use.
*
* Sets the classification property of a calendar component object. To unset
* the property, specify E_CAL_COMPONENT_CLASS_NONE for @classif.
**/
void
e_cal_component_set_classification (ECalComponent *comp, ECalComponentClassification classif)
{
ECalComponentPrivate *priv;
icalproperty_class class;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (classif != E_CAL_COMPONENT_CLASS_UNKNOWN);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (classif == E_CAL_COMPONENT_CLASS_NONE) {
if (priv->classification) {
icalcomponent_remove_property (priv->icalcomp, priv->classification);
icalproperty_free (priv->classification);
priv->classification = NULL;
}
return;
}
switch (classif) {
case E_CAL_COMPONENT_CLASS_PUBLIC:
class = ICAL_CLASS_PUBLIC;
break;
case E_CAL_COMPONENT_CLASS_PRIVATE:
class = ICAL_CLASS_PRIVATE;
break;
case E_CAL_COMPONENT_CLASS_CONFIDENTIAL:
class = ICAL_CLASS_CONFIDENTIAL;
break;
default:
g_assert_not_reached ();
class = ICAL_CLASS_NONE;
}
if (priv->classification)
icalproperty_set_class (priv->classification, class);
else {
priv->classification = icalproperty_new_class (class);
icalcomponent_add_property (priv->icalcomp, priv->classification);
}
}
/* Gets a text list value */
static void
get_text_list (GSList *text_list,
const char *(* get_prop_func) (const icalproperty *prop),
GSList **tl)
{
GSList *l;
*tl = NULL;
if (!text_list)
return;
for (l = text_list; l; l = l->next) {
struct text *text;
ECalComponentText *t;
text = l->data;
g_assert (text->prop != NULL);
t = g_new (ECalComponentText, 1);
t->value = (* get_prop_func) (text->prop);
if (text->altrep_param)
t->altrep = icalparameter_get_altrep (text->altrep_param);
else
t->altrep = NULL;
*tl = g_slist_prepend (*tl, t);
}
*tl = g_slist_reverse (*tl);
}
/* Sets a text list value */
static void
set_text_list (ECalComponent *comp,
icalproperty *(* new_prop_func) (const char *value),
GSList **text_list,
GSList *tl)
{
ECalComponentPrivate *priv;
GSList *l;
priv = comp->priv;
/* Remove old texts */
for (l = *text_list; l; l = l->next) {
struct text *text;
text = l->data;
g_assert (text->prop != NULL);
icalcomponent_remove_property (priv->icalcomp, text->prop);
icalproperty_free (text->prop);
g_free (text);
}
g_slist_free (*text_list);
*text_list = NULL;
/* Add in new texts */
for (l = tl; l; l = l->next) {
ECalComponentText *t;
struct text *text;
t = l->data;
g_return_if_fail (t->value != NULL);
text = g_new (struct text, 1);
text->prop = (* new_prop_func) ((char *) t->value);
icalcomponent_add_property (priv->icalcomp, text->prop);
if (t->altrep) {
text->altrep_param = icalparameter_new_altrep ((char *) t->altrep);
icalproperty_add_parameter (text->prop, text->altrep_param);
} else
text->altrep_param = NULL;
*text_list = g_slist_prepend (*text_list, text);
}
*text_list = g_slist_reverse (*text_list);
}
/**
* e_cal_component_get_comment_list:
* @comp: A calendar component object.
* @text_list: Return value for the comment properties and their parameters, as
* a list of #ECalComponentText structures. This should be freed using the
* e_cal_component_free_text_list() function.
*
* Queries the comments of a calendar component object. The comment property can
* appear several times inside a calendar component, and so a list of
* #ECalComponentText is returned.
**/
void
e_cal_component_get_comment_list (ECalComponent *comp, GSList **text_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (text_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_text_list (priv->comment_list, icalproperty_get_comment, text_list);
}
/**
* e_cal_component_set_comment_list:
* @comp: A calendar component object.
* @text_list: List of #ECalComponentText structures.
*
* Sets the comments of a calendar component object. The comment property can
* appear several times inside a calendar component, and so a list of
* #ECalComponentText structures is used.
**/
void
e_cal_component_set_comment_list (ECalComponent *comp, GSList *text_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_text_list (comp, icalproperty_new_comment, &priv->comment_list, text_list);
}
/**
* e_cal_component_get_contact_list:
* @comp: A calendar component object.
* @text_list: Return value for the contact properties and their parameters, as
* a list of #ECalComponentText structures. This should be freed using the
* e_cal_component_free_text_list() function.
*
* Queries the contact of a calendar component object. The contact property can
* appear several times inside a calendar component, and so a list of
* #ECalComponentText is returned.
**/
void
e_cal_component_get_contact_list (ECalComponent *comp, GSList **text_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (text_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_text_list (priv->contact_list, icalproperty_get_contact, text_list);
}
/**
* e_cal_component_set_contact_list:
* @comp: A calendar component object.
* @text_list: List of #ECalComponentText structures.
*
* Sets the contact of a calendar component object. The contact property can
* appear several times inside a calendar component, and so a list of
* #ECalComponentText structures is used.
**/
void
e_cal_component_set_contact_list (ECalComponent *comp, GSList *text_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_text_list (comp, icalproperty_new_contact, &priv->contact_list, text_list);
}
/* Gets a struct icaltimetype value */
static void
get_icaltimetype (icalproperty *prop,
struct icaltimetype (* get_prop_func) (const icalproperty *prop),
struct icaltimetype **t)
{
if (!prop) {
*t = NULL;
return;
}
*t = g_new (struct icaltimetype, 1);
**t = (* get_prop_func) (prop);
}
/* Sets a struct icaltimetype value */
static void
set_icaltimetype (ECalComponent *comp, icalproperty **prop,
icalproperty *(* prop_new_func) (struct icaltimetype v),
void (* prop_set_func) (icalproperty *prop, struct icaltimetype v),
struct icaltimetype *t)
{
ECalComponentPrivate *priv;
priv = comp->priv;
if (!t) {
if (*prop) {
icalcomponent_remove_property (priv->icalcomp, *prop);
icalproperty_free (*prop);
*prop = NULL;
}
return;
}
if (*prop)
(* prop_set_func) (*prop, *t);
else {
*prop = (* prop_new_func) (*t);
icalcomponent_add_property (priv->icalcomp, *prop);
}
}
/**
* e_cal_component_get_completed:
* @comp: A calendar component object.
* @t: Return value for the completion date. This should be freed using the
* e_cal_component_free_icaltimetype() function.
*
* Queries the date at which a calendar compoment object was completed.
**/
void
e_cal_component_get_completed (ECalComponent *comp, struct icaltimetype **t)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (t != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_icaltimetype (priv->completed, icalproperty_get_completed, t);
}
/**
* e_cal_component_set_completed:
* @comp: A calendar component object.
* @t: Value for the completion date.
*
* Sets the date at which a calendar component object was completed.
**/
void
e_cal_component_set_completed (ECalComponent *comp, struct icaltimetype *t)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_icaltimetype (comp, &priv->completed,
icalproperty_new_completed,
icalproperty_set_completed,
t);
}
/**
* e_cal_component_get_created:
* @comp: A calendar component object.
* @t: Return value for the creation date. This should be freed using the
* e_cal_component_free_icaltimetype() function.
*
* Queries the date in which a calendar component object was created in the
* calendar store.
**/
void
e_cal_component_get_created (ECalComponent *comp, struct icaltimetype **t)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (t != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_icaltimetype (priv->created, icalproperty_get_created, t);
}
/**
* e_cal_component_set_created:
* @comp: A calendar component object.
* @t: Value for the creation date.
*
* Sets the date in which a calendar component object is created in the calendar
* store. This should only be used inside a calendar store application, i.e.
* not by calendar user agents.
**/
void
e_cal_component_set_created (ECalComponent *comp, struct icaltimetype *t)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_icaltimetype (comp, &priv->created,
icalproperty_new_created,
icalproperty_set_created,
t);
}
/**
* e_cal_component_get_description_list:
* @comp: A calendar component object.
* @text_list: Return value for the description properties and their parameters,
* as a list of #ECalComponentText structures. This should be freed using the
* e_cal_component_free_text_list() function.
*
* Queries the description of a calendar component object. Journal components
* may have more than one description, and as such this function returns a list
* of #ECalComponentText structures. All other types of components can have at
* most one description.
**/
void
e_cal_component_get_description_list (ECalComponent *comp, GSList **text_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (text_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_text_list (priv->description_list, icalproperty_get_description, text_list);
}
/**
* e_cal_component_set_description_list:
* @comp: A calendar component object.
* @text_list: List of #ECalComponentSummary structures.
*
* Sets the description of a calendar component object. Journal components may
* have more than one description, and as such this function takes in a list of
* #ECalComponentDescription structures. All other types of components can have
* at most one description.
**/
void
e_cal_component_set_description_list (ECalComponent *comp, GSList *text_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_text_list (comp, icalproperty_new_description, &priv->description_list, text_list);
}
/* Gets a date/time and timezone pair */
static void
get_datetime (struct datetime *datetime,
struct icaltimetype (* get_prop_func) (const icalproperty *prop),
ECalComponentDateTime *dt)
{
if (datetime->prop) {
dt->value = g_new (struct icaltimetype, 1);
*dt->value = (* get_prop_func) (datetime->prop);
} else
dt->value = NULL;
/* If the icaltimetype has is_utc set, we set "UTC" as the TZID.
This makes the timezone code simpler. */
if (datetime->tzid_param)
dt->tzid = g_strdup (icalparameter_get_tzid (datetime->tzid_param));
else if (dt->value && dt->value->is_utc)
dt->tzid = g_strdup ("UTC");
else
dt->tzid = NULL;
}
/* Sets a date/time and timezone pair */
static void
set_datetime (ECalComponent *comp, struct datetime *datetime,
icalproperty *(* prop_new_func) (struct icaltimetype v),
void (* prop_set_func) (icalproperty * prop, struct icaltimetype v),
ECalComponentDateTime *dt)
{
ECalComponentPrivate *priv;
priv = comp->priv;
/* If we are setting the property to NULL (i.e. removing it), then
we remove it if it exists. */
if (!dt) {
if (datetime->prop) {
icalcomponent_remove_property (priv->icalcomp, datetime->prop);
icalproperty_free (datetime->prop);
datetime->prop = NULL;
datetime->tzid_param = NULL;
}
return;
}
g_return_if_fail (dt->value != NULL);
/* If the TZID is set to "UTC", we set the is_utc flag. */
if (dt->tzid && !strcmp (dt->tzid, "UTC"))
dt->value->is_utc = 1;
else
dt->value->is_utc = 0;
if (datetime->prop) {
(* prop_set_func) (datetime->prop, *dt->value);
} else {
datetime->prop = (* prop_new_func) (*dt->value);
icalcomponent_add_property (priv->icalcomp, datetime->prop);
}
/* If the TZID is set to "UTC", we don't want to save the TZID. */
if (dt->tzid && strcmp (dt->tzid, "UTC")) {
g_assert (datetime->prop != NULL);
if (datetime->tzid_param) {
icalparameter_set_tzid (datetime->tzid_param, (char *) dt->tzid);
} else {
datetime->tzid_param = icalparameter_new_tzid ((char *) dt->tzid);
icalproperty_add_parameter (datetime->prop, datetime->tzid_param);
}
} else if (datetime->tzid_param) {
icalproperty_remove_parameter (datetime->prop, ICAL_TZID_PARAMETER);
datetime->tzid_param = NULL;
}
}
/* This tries to get the DTSTART + DURATION for a VEVENT or VTODO. In a
VEVENT this is used for the DTEND if no DTEND exists, In a VTOTO it is
used for the DUE date if DUE doesn't exist. */
static void
e_cal_component_get_start_plus_duration (ECalComponent *comp,
ECalComponentDateTime *dt)
{
ECalComponentPrivate *priv;
struct icaldurationtype duration;
priv = comp->priv;
if (!priv->duration)
return;
/* Get the DTSTART time. */
get_datetime (&priv->dtstart, icalproperty_get_dtstart, dt);
if (!dt->value)
return;
duration = icalproperty_get_duration (priv->duration);
/* The DURATION shouldn't be negative, but just return DTSTART if it
is, i.e. assume it is 0. */
if (duration.is_neg)
return;
/* If DTSTART is a DATE value, then we need to check if the DURATION
includes any hours, minutes or seconds. If it does, we need to
make the DTEND/DUE a DATE-TIME value. */
duration.days += duration.weeks * 7;
if (dt->value->is_date) {
if (duration.hours != 0 || duration.minutes != 0
|| duration.seconds != 0) {
dt->value->is_date = 0;
}
}
/* Add on the DURATION. */
icaltime_adjust (dt->value, duration.days, duration.hours,
duration.minutes, duration.seconds);
}
/**
* e_cal_component_get_dtend:
* @comp: A calendar component object.
* @dt: Return value for the date/time end. This should be freed with the
* e_cal_component_free_datetime() function.
*
* Queries the date/time end of a calendar component object.
**/
void
e_cal_component_get_dtend (ECalComponent *comp, ECalComponentDateTime *dt)
{
ECalComponentPrivate *priv;
g_return_if_fail (dt != NULL);
dt->tzid = NULL;
dt->value = NULL;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_datetime (&priv->dtend, icalproperty_get_dtend, dt);
/* If we don't have a DTEND property, then we try to get DTSTART
+ DURATION. */
if (!dt->value)
e_cal_component_get_start_plus_duration (comp, dt);
}
/**
* e_cal_component_set_dtend:
* @comp: A calendar component object.
* @dt: End date/time.
*
* Sets the date/time end property of a calendar component object.
**/
void
e_cal_component_set_dtend (ECalComponent *comp, ECalComponentDateTime *dt)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_datetime (comp, &priv->dtend,
icalproperty_new_dtend,
icalproperty_set_dtend,
dt);
/* Make sure we remove any existing DURATION property, as it can't be
used with a DTEND. If DTEND is set to NULL, i.e. removed, we also
want to remove any DURATION. */
if (priv->duration) {
icalcomponent_remove_property (priv->icalcomp, priv->duration);
icalproperty_free (priv->duration);
priv->duration = NULL;
}
priv->need_sequence_inc = TRUE;
}
/**
* e_cal_component_get_dtstamp:
* @comp: A calendar component object.
* @t: A value for the date/timestamp.
*
* Queries the date/timestamp property of a calendar component object, which is
* the last time at which the object was modified by a calendar user agent.
**/
void
e_cal_component_get_dtstamp (ECalComponent *comp, struct icaltimetype *t)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (t != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
/* This MUST exist, since we ensured that it did */
g_assert (priv->dtstamp != NULL);
*t = icalproperty_get_dtstamp (priv->dtstamp);
}
/**
* e_cal_component_set_dtstamp:
* @comp: A calendar component object.
* @t: Date/timestamp value.
*
* Sets the date/timestamp of a calendar component object. This should be
* called whenever a calendar user agent makes a change to a component's
* properties.
**/
void
e_cal_component_set_dtstamp (ECalComponent *comp, struct icaltimetype *t)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (t != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
/* This MUST exist, since we ensured that it did */
g_assert (priv->dtstamp != NULL);
icalproperty_set_dtstamp (priv->dtstamp, *t);
}
/**
* e_cal_component_get_dtstart:
* @comp: A calendar component object.
* @dt: Return value for the date/time start. This should be freed with the
* e_cal_component_free_datetime() function.
*
* Queries the date/time start of a calendar component object.
**/
void
e_cal_component_get_dtstart (ECalComponent *comp, ECalComponentDateTime *dt)
{
ECalComponentPrivate *priv;
g_return_if_fail (dt != NULL);
dt->tzid = NULL;
dt->value = NULL;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_datetime (&priv->dtstart, icalproperty_get_dtstart, dt);
}
/**
* e_cal_component_set_dtstart:
* @comp: A calendar component object.
* @dt: Start date/time.
*
* Sets the date/time start property of a calendar component object.
**/
void
e_cal_component_set_dtstart (ECalComponent *comp, ECalComponentDateTime *dt)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_datetime (comp, &priv->dtstart,
icalproperty_new_dtstart,
icalproperty_set_dtstart,
dt);
priv->need_sequence_inc = TRUE;
}
/**
* e_cal_component_get_due:
* @comp: A calendar component object.
* @dt: Return value for the due date/time. This should be freed with the
* e_cal_component_free_datetime() function.
*
* Queries the due date/time of a calendar component object.
**/
void
e_cal_component_get_due (ECalComponent *comp, ECalComponentDateTime *dt)
{
ECalComponentPrivate *priv;
g_return_if_fail (dt != NULL);
dt->tzid = NULL;
dt->value = NULL;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_datetime (&priv->due, icalproperty_get_due, dt);
/* If we don't have a DTEND property, then we try to get DTSTART
+ DURATION. */
if (!dt->value)
e_cal_component_get_start_plus_duration (comp, dt);
}
/**
* e_cal_component_set_due:
* @comp: A calendar component object.
* @dt: End date/time.
*
* Sets the due date/time property of a calendar component object.
**/
void
e_cal_component_set_due (ECalComponent *comp, ECalComponentDateTime *dt)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_datetime (comp, &priv->due,
icalproperty_new_due,
icalproperty_set_due,
dt);
/* Make sure we remove any existing DURATION property, as it can't be
used with a DTEND. If DTEND is set to NULL, i.e. removed, we also
want to remove any DURATION. */
if (priv->duration) {
icalcomponent_remove_property (priv->icalcomp, priv->duration);
icalproperty_free (priv->duration);
priv->duration = NULL;
}
priv->need_sequence_inc = TRUE;
}
/* Builds a list of ECalComponentPeriod structures based on a list of icalproperties */
static void
get_period_list (GSList *period_list,
struct icaldatetimeperiodtype (* get_prop_func) (const icalproperty *prop),
GSList **list)
{
GSList *l;
*list = NULL;
if (!period_list)
return;
for (l = period_list; l; l = l->next) {
struct period *period;
ECalComponentPeriod *p;
struct icaldatetimeperiodtype ip;
period = l->data;
g_assert (period->prop != NULL);
p = g_new (ECalComponentPeriod, 1);
/* Get value parameter */
if (period->value_param) {
icalparameter_value value_type;
value_type = icalparameter_get_value (period->value_param);
if (value_type == ICAL_VALUE_DATE || value_type == ICAL_VALUE_DATETIME)
p->type = E_CAL_COMPONENT_PERIOD_DATETIME;
else if (value_type == ICAL_VALUE_DURATION)
p->type = E_CAL_COMPONENT_PERIOD_DURATION;
else {
g_message ("get_period_list(): Unknown value for period %d; "
"using DATETIME", value_type);
p->type = E_CAL_COMPONENT_PERIOD_DATETIME;
}
} else
p->type = E_CAL_COMPONENT_PERIOD_DATETIME;
/* Get start and end/duration */
ip = (* get_prop_func) (period->prop);
p->start = ip.period.start;
if (p->type == E_CAL_COMPONENT_PERIOD_DATETIME)
p->u.end = ip.period.end;
else if (p->type == E_CAL_COMPONENT_PERIOD_DURATION)
p->u.duration = ip.period.duration;
else
g_assert_not_reached ();
/* Put in list */
*list = g_slist_prepend (*list, p);
}
*list = g_slist_reverse (*list);
}
/* Sets a period list value */
static void
set_period_list (ECalComponent *comp,
icalproperty *(* new_prop_func) (struct icaldatetimeperiodtype period),
GSList **period_list,
GSList *pl)
{
ECalComponentPrivate *priv;
GSList *l;
priv = comp->priv;
/* Remove old periods */
for (l = *period_list; l; l = l->next) {
struct period *period;
period = l->data;
g_assert (period->prop != NULL);
icalcomponent_remove_property (priv->icalcomp, period->prop);
icalproperty_free (period->prop);
g_free (period);
}
g_slist_free (*period_list);
*period_list = NULL;
/* Add in new periods */
for (l = pl; l; l = l->next) {
ECalComponentPeriod *p;
struct period *period;
struct icaldatetimeperiodtype ip;
icalparameter_value value_type;
g_assert (l->data != NULL);
p = l->data;
/* Create libical value */
ip.period.start = p->start;
if (p->type == E_CAL_COMPONENT_PERIOD_DATETIME) {
value_type = ICAL_VALUE_DATETIME;
ip.period.end = p->u.end;
} else if (p->type == E_CAL_COMPONENT_PERIOD_DURATION) {
value_type = ICAL_VALUE_DURATION;
ip.period.duration = p->u.duration;
} else {
g_assert_not_reached ();
return;
}
/* Create property */
period = g_new (struct period, 1);
period->prop = (* new_prop_func) (ip);
period->value_param = icalparameter_new_value (value_type);
icalproperty_add_parameter (period->prop, period->value_param);
/* Add to list */
*period_list = g_slist_prepend (*period_list, period);
}
*period_list = g_slist_reverse (*period_list);
}
/**
* e_cal_component_get_exdate_list:
* @comp: A calendar component object.
* @exdate_list: Return value for the list of exception dates, as a list of
* #ECalComponentDateTime structures. This should be freed using the
* e_cal_component_free_exdate_list() function.
*
* Queries the list of exception date properties in a calendar component object.
**/
void
e_cal_component_get_exdate_list (ECalComponent *comp, GSList **exdate_list)
{
ECalComponentPrivate *priv;
GSList *l;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (exdate_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
*exdate_list = NULL;
for (l = priv->exdate_list; l; l = l->next) {
struct datetime *dt;
ECalComponentDateTime *cdt;
dt = l->data;
cdt = g_new (ECalComponentDateTime, 1);
cdt->value = g_new (struct icaltimetype, 1);
*cdt->value = icalproperty_get_exdate (dt->prop);
if (dt->tzid_param)
cdt->tzid = g_strdup (icalparameter_get_tzid (dt->tzid_param));
else
cdt->tzid = NULL;
*exdate_list = g_slist_prepend (*exdate_list, cdt);
}
*exdate_list = g_slist_reverse (*exdate_list);
}
/**
* e_cal_component_set_exdate_list:
* @comp: A calendar component object.
* @exdate_list: List of #ECalComponentDateTime structures.
*
* Sets the list of exception dates in a calendar component object.
**/
void
e_cal_component_set_exdate_list (ECalComponent *comp, GSList *exdate_list)
{
ECalComponentPrivate *priv;
GSList *l;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
/* Remove old exception dates */
for (l = priv->exdate_list; l; l = l->next) {
struct datetime *dt;
dt = l->data;
/* Removing the DATE or DATE-TIME property will also remove
any TZID parameter. */
icalcomponent_remove_property (priv->icalcomp, dt->prop);
icalproperty_free (dt->prop);
g_free (dt);
}
g_slist_free (priv->exdate_list);
priv->exdate_list = NULL;
/* Add in new exception dates */
for (l = exdate_list; l; l = l->next) {
ECalComponentDateTime *cdt;
struct datetime *dt;
g_assert (l->data != NULL);
cdt = l->data;
g_assert (cdt->value != NULL);
dt = g_new (struct datetime, 1);
dt->prop = icalproperty_new_exdate (*cdt->value);
if (cdt->tzid) {
dt->tzid_param = icalparameter_new_tzid ((char *) cdt->tzid);
icalproperty_add_parameter (dt->prop, dt->tzid_param);
} else
dt->tzid_param = NULL;
icalcomponent_add_property (priv->icalcomp, dt->prop);
priv->exdate_list = g_slist_prepend (priv->exdate_list, dt);
}
priv->exdate_list = g_slist_reverse (priv->exdate_list);
priv->need_sequence_inc = TRUE;
}
/**
* e_cal_component_has_exdates:
* @comp: A calendar component object.
*
* Queries whether a calendar component object has any exception dates defined
* for it.
*
* Return value: TRUE if the component has exception dates, FALSE otherwise.
**/
gboolean
e_cal_component_has_exdates (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
return (priv->exdate_list != NULL);
}
/* Gets a list of recurrence rules */
static void
get_recur_list (GSList *recur_list,
struct icalrecurrencetype (* get_prop_func) (const icalproperty *prop),
GSList **list)
{
GSList *l;
*list = NULL;
for (l = recur_list; l; l = l->next) {
icalproperty *prop;
struct icalrecurrencetype *r;
prop = l->data;
r = g_new (struct icalrecurrencetype, 1);
*r = (* get_prop_func) (prop);
*list = g_slist_prepend (*list, r);
}
*list = g_slist_reverse (*list);
}
/* Sets a list of recurrence rules */
static void
set_recur_list (ECalComponent *comp,
icalproperty *(* new_prop_func) (struct icalrecurrencetype recur),
GSList **recur_list,
GSList *rl)
{
ECalComponentPrivate *priv;
GSList *l;
priv = comp->priv;
/* Remove old recurrences */
for (l = *recur_list; l; l = l->next) {
icalproperty *prop;
prop = l->data;
icalcomponent_remove_property (priv->icalcomp, prop);
icalproperty_free (prop);
}
g_slist_free (*recur_list);
*recur_list = NULL;
/* Add in new recurrences */
for (l = rl; l; l = l->next) {
icalproperty *prop;
struct icalrecurrencetype *recur;
g_assert (l->data != NULL);
recur = l->data;
prop = (* new_prop_func) (*recur);
icalcomponent_add_property (priv->icalcomp, prop);
*recur_list = g_slist_prepend (*recur_list, prop);
}
*recur_list = g_slist_reverse (*recur_list);
}
/**
* e_cal_component_get_exrule_list:
* @comp: A calendar component object.
* @recur_list: List of exception rules as struct #icalrecurrencetype
* structures. This should be freed using the e_cal_component_free_recur_list()
* function.
*
* Queries the list of exception rule properties of a calendar component
* object.
**/
void
e_cal_component_get_exrule_list (ECalComponent *comp, GSList **recur_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (recur_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_recur_list (priv->exrule_list, icalproperty_get_exrule, recur_list);
}
/**
* e_cal_component_get_exrule_property_list:
* @comp: A calendar component object.
* @recur_list: Returns a list of exception rule properties.
*
* Queries the list of exception rule properties of a calendar component object.
**/
void
e_cal_component_get_exrule_property_list (ECalComponent *comp, GSList **recur_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (recur_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
*recur_list = priv->exrule_list;
}
/**
* e_cal_component_set_exrule_list:
* @comp: A calendar component object.
* @recur_list: List of struct #icalrecurrencetype structures.
*
* Sets the list of exception rules in a calendar component object.
**/
void
e_cal_component_set_exrule_list (ECalComponent *comp, GSList *recur_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_recur_list (comp, icalproperty_new_exrule, &priv->exrule_list, recur_list);
priv->need_sequence_inc = TRUE;
}
/**
* e_cal_component_has_exrules:
* @comp: A calendar component object.
*
* Queries whether a calendar component object has any exception rules defined
* for it.
*
* Return value: TRUE if the component has exception rules, FALSE otherwise.
**/
gboolean
e_cal_component_has_exrules (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
return (priv->exrule_list != NULL);
}
/**
* e_cal_component_has_exceptions:
* @comp: A calendar component object
*
* Queries whether a calendar component object has any exception dates
* or exception rules.
*
* Return value: TRUE if the component has exceptions, FALSE otherwise.
**/
gboolean
e_cal_component_has_exceptions (ECalComponent *comp)
{
return e_cal_component_has_exdates (comp) || e_cal_component_has_exrules (comp);
}
/**
* e_cal_component_get_geo:
* @comp: A calendar component object.
* @geo: Return value for the geographic position property. This should be
* freed using the e_cal_component_free_geo() function.
*
* Gets the geographic position property of a calendar component object.
**/
void
e_cal_component_get_geo (ECalComponent *comp, struct icalgeotype **geo)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (geo != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (priv->geo) {
*geo = g_new (struct icalgeotype, 1);
**geo = icalproperty_get_geo (priv->geo);
} else
*geo = NULL;
}
/**
* e_cal_component_set_geo:
* @comp: A calendar component object.
* @geo: Value for the geographic position property.
*
* Sets the geographic position property on a calendar component object.
**/
void
e_cal_component_set_geo (ECalComponent *comp, struct icalgeotype *geo)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!geo) {
if (priv->geo) {
icalcomponent_remove_property (priv->icalcomp, priv->geo);
icalproperty_free (priv->geo);
priv->geo = NULL;
}
return;
}
if (priv->geo)
icalproperty_set_geo (priv->geo, *geo);
else {
priv->geo = icalproperty_new_geo (*geo);
icalcomponent_add_property (priv->icalcomp, priv->geo);
}
}
/**
* e_cal_component_get_last_modified:
* @comp: A calendar component object.
* @t: Return value for the last modified time value.
*
* Queries the time at which a calendar component object was last modified in
* the calendar store.
**/
void
e_cal_component_get_last_modified (ECalComponent *comp, struct icaltimetype **t)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (t != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_icaltimetype (priv->last_modified, icalproperty_get_lastmodified, t);
}
/**
* e_cal_component_set_last_modified:
* @comp: A calendar component object.
* @t: Value for the last time modified.
*
* Sets the time at which a calendar component object was last stored in the
* calendar store. This should not be called by plain calendar user agents.
**/
void
e_cal_component_set_last_modified (ECalComponent *comp, struct icaltimetype *t)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_icaltimetype (comp, &priv->last_modified,
icalproperty_new_lastmodified,
icalproperty_set_lastmodified,
t);
}
/**
* e_cal_component_get_organizer:
* @comp: A calendar component object
* @organizer: A value for the organizer
*
* Queries the organizer property of a calendar component object
**/
void
e_cal_component_get_organizer (ECalComponent *comp, ECalComponentOrganizer *organizer)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (organizer != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (priv->organizer.prop)
organizer->value = icalproperty_get_organizer (priv->organizer.prop);
else
organizer->value = NULL;
if (priv->organizer.sentby_param)
organizer->sentby = icalparameter_get_sentby (priv->organizer.sentby_param);
else
organizer->sentby = NULL;
if (priv->organizer.cn_param)
organizer->cn = icalparameter_get_sentby (priv->organizer.cn_param);
else
organizer->cn = NULL;
if (priv->organizer.language_param)
organizer->language = icalparameter_get_sentby (priv->organizer.language_param);
else
organizer->language = NULL;
}
/**
* e_cal_component_set_organizer:
* @comp: A calendar component object.
* @organizer: Value for the organizer property
*
* Sets the organizer of a calendar component object
**/
void
e_cal_component_set_organizer (ECalComponent *comp, ECalComponentOrganizer *organizer)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!organizer) {
if (priv->organizer.prop) {
icalcomponent_remove_property (priv->icalcomp, priv->organizer.prop);
icalproperty_free (priv->organizer.prop);
priv->organizer.prop = NULL;
priv->organizer.sentby_param = NULL;
priv->organizer.cn_param = NULL;
priv->organizer.language_param = NULL;
}
return;
}
g_return_if_fail (organizer->value != NULL);
if (priv->organizer.prop)
icalproperty_set_organizer (priv->organizer.prop, (char *) organizer->value);
else {
priv->organizer.prop = icalproperty_new_organizer ((char *) organizer->value);
icalcomponent_add_property (priv->icalcomp, priv->organizer.prop);
}
if (organizer->sentby) {
g_assert (priv->organizer.prop != NULL);
if (priv->organizer.sentby_param)
icalparameter_set_sentby (priv->organizer.sentby_param,
(char *) organizer->sentby);
else {
priv->organizer.sentby_param = icalparameter_new_sentby (
(char *) organizer->sentby);
icalproperty_add_parameter (priv->organizer.prop,
priv->organizer.sentby_param);
}
} else if (priv->organizer.sentby_param) {
icalproperty_remove_parameter (priv->organizer.prop, ICAL_SENTBY_PARAMETER);
priv->organizer.sentby_param = NULL;
}
if (organizer->cn) {
g_assert (priv->organizer.prop != NULL);
if (priv->organizer.cn_param)
icalparameter_set_cn (priv->organizer.cn_param,
(char *) organizer->cn);
else {
priv->organizer.cn_param = icalparameter_new_cn (
(char *) organizer->cn);
icalproperty_add_parameter (priv->organizer.prop,
priv->organizer.cn_param);
}
} else if (priv->organizer.cn_param) {
icalproperty_remove_parameter (priv->organizer.prop, ICAL_CN_PARAMETER);
priv->organizer.cn_param = NULL;
}
if (organizer->language) {
g_assert (priv->organizer.prop != NULL);
if (priv->organizer.language_param)
icalparameter_set_language (priv->organizer.language_param,
(char *) organizer->language);
else {
priv->organizer.language_param = icalparameter_new_language (
(char *) organizer->language);
icalproperty_add_parameter (priv->organizer.prop,
priv->organizer.language_param);
}
} else if (priv->organizer.language_param) {
icalproperty_remove_parameter (priv->organizer.prop, ICAL_LANGUAGE_PARAMETER);
priv->organizer.language_param = NULL;
}
}
/**
* e_cal_component_has_organizer:
* @comp: A calendar component object.
*
* Check whether a calendar component object has an organizer or not.
*
* Return value: TRUE if there is an organizer, FALSE otherwise.
**/
gboolean
e_cal_component_has_organizer (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
return priv->organizer.prop != NULL;
}
/**
* e_cal_component_get_percent:
* @comp: A calendar component object.
* @percent: Return value for the percent-complete property. This should be
* freed using the e_cal_component_free_percent() function.
*
* Queries the percent-complete property of a calendar component object.
**/
void
e_cal_component_get_percent (ECalComponent *comp, int **percent)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (percent != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (priv->percent) {
*percent = g_new (int, 1);
**percent = icalproperty_get_percentcomplete (priv->percent);
} else
*percent = NULL;
}
/**
* e_cal_component_set_percent:
* @comp: A calendar component object.
* @percent: Value for the percent-complete property.
*
* Sets the percent-complete property of a calendar component object.
**/
void
e_cal_component_set_percent (ECalComponent *comp, int *percent)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!percent) {
if (priv->percent) {
icalcomponent_remove_property (priv->icalcomp, priv->percent);
icalproperty_free (priv->percent);
priv->percent = NULL;
}
return;
}
g_return_if_fail (*percent >= 0 && *percent <= 100);
if (priv->percent)
icalproperty_set_percentcomplete (priv->percent, *percent);
else {
priv->percent = icalproperty_new_percentcomplete (*percent);
icalcomponent_add_property (priv->icalcomp, priv->percent);
}
}
/**
* e_cal_component_get_priority:
* @comp: A calendar component object.
* @priority: Return value for the priority property. This should be freed using
* the e_cal_component_free_priority() function.
*
* Queries the priority property of a calendar component object.
**/
void
e_cal_component_get_priority (ECalComponent *comp, int **priority)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (priority != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (priv->priority) {
*priority = g_new (int, 1);
**priority = icalproperty_get_priority (priv->priority);
} else
*priority = NULL;
}
/**
* e_cal_component_set_priority:
* @comp: A calendar component object.
* @priority: Value for the priority property.
*
* Sets the priority property of a calendar component object.
**/
void
e_cal_component_set_priority (ECalComponent *comp, int *priority)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!priority) {
if (priv->priority) {
icalcomponent_remove_property (priv->icalcomp, priv->priority);
icalproperty_free (priv->priority);
priv->priority = NULL;
}
return;
}
g_return_if_fail (*priority >= 0 && *priority <= 9);
if (priv->priority)
icalproperty_set_priority (priv->priority, *priority);
else {
priv->priority = icalproperty_new_priority (*priority);
icalcomponent_add_property (priv->icalcomp, priv->priority);
}
}
/**
* e_cal_component_get_recurid:
* @comp: A calendar component object.
* @recur_id: Return value for the recurrence id property
*
* Queries the recurrence id property of a calendar component object.
**/
void
e_cal_component_get_recurid (ECalComponent *comp, ECalComponentRange *recur_id)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (recur_id != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_datetime (&priv->recur_id.recur_time,
icalproperty_get_recurrenceid,
&recur_id->datetime);
}
/**
* e_cal_component_get_recurid_as_string:
* @comp: A calendar component object.
*
* Gets the recurrence ID property as a string.
*
* Return value: the recurrence ID as a string.
*/
const char *
e_cal_component_get_recurid_as_string (ECalComponent *comp)
{
ECalComponentRange range;
struct icaltimetype tt;
if (!e_cal_component_is_instance (comp))
return NULL;
e_cal_component_get_recurid (comp, &range);
if (!range.datetime.value)
return "0";
tt = *range.datetime.value;
e_cal_component_free_range (&range);
return icaltime_is_valid_time (tt) && !icaltime_is_null_time (tt) ?
icaltime_as_ical_string (tt) : "0";
}
/**
* e_cal_component_set_recurid:
* @comp: A calendar component object.
* @recur_id: Value for the recurrence id property.
*
* Sets the recurrence id property of a calendar component object.
**/
void
e_cal_component_set_recurid (ECalComponent *comp, ECalComponentRange *recur_id)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_datetime (comp, &priv->recur_id.recur_time,
icalproperty_new_recurrenceid,
icalproperty_set_recurrenceid,
recur_id ? &recur_id->datetime : NULL);
}
/**
* e_cal_component_get_rdate_list:
* @comp: A calendar component object.
* @period_list: Return value for the list of recurrence dates, as a list of
* #ECalComponentPeriod structures. This should be freed using the
* e_cal_component_free_period_list() function.
*
* Queries the list of recurrence date properties in a calendar component
* object.
**/
void
e_cal_component_get_rdate_list (ECalComponent *comp, GSList **period_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (period_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_period_list (priv->rdate_list, icalproperty_get_rdate, period_list);
}
/**
* e_cal_component_set_rdate_list:
* @comp: A calendar component object.
* @period_list: List of #ECalComponentPeriod structures.
*
* Sets the list of recurrence dates in a calendar component object.
**/
void
e_cal_component_set_rdate_list (ECalComponent *comp, GSList *period_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_period_list (comp, icalproperty_new_rdate, &priv->rdate_list, period_list);
priv->need_sequence_inc = TRUE;
}
/**
* e_cal_component_has_rdates:
* @comp: A calendar component object.
*
* Queries whether a calendar component object has any recurrence dates defined
* for it.
*
* Return value: TRUE if the component has recurrence dates, FALSE otherwise.
**/
gboolean
e_cal_component_has_rdates (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
return (priv->rdate_list != NULL);
}
/**
* e_cal_component_get_rrule_list:
* @comp: A calendar component object.
* @recur_list: List of recurrence rules as struct #icalrecurrencetype
* structures. This should be freed using the e_cal_component_free_recur_list()
* function.
*
* Queries the list of recurrence rule properties of a calendar component
* object.
**/
void
e_cal_component_get_rrule_list (ECalComponent *comp, GSList **recur_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (recur_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_recur_list (priv->rrule_list, icalproperty_get_rrule, recur_list);
}
/**
* e_cal_component_get_rrule_property_list:
* @comp: A calendar component object.
* @recur_list: Returns a list of recurrence rule properties.
*
* Queries a list of recurrence rule properties of a calendar component object.
**/
void
e_cal_component_get_rrule_property_list (ECalComponent *comp, GSList **recur_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (recur_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
*recur_list = priv->rrule_list;
}
/**
* e_cal_component_set_rrule_list:
* @comp: A calendar component object.
* @recur_list: List of struct #icalrecurrencetype structures.
*
* Sets the list of recurrence rules in a calendar component object.
**/
void
e_cal_component_set_rrule_list (ECalComponent *comp, GSList *recur_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_recur_list (comp, icalproperty_new_rrule, &priv->rrule_list, recur_list);
priv->need_sequence_inc = TRUE;
}
/**
* e_cal_component_has_rrules:
* @comp: A calendar component object.
*
* Queries whether a calendar component object has any recurrence rules defined
* for it.
*
* Return value: TRUE if the component has recurrence rules, FALSE otherwise.
**/
gboolean
e_cal_component_has_rrules (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
return (priv->rrule_list != NULL);
}
/**
* e_cal_component_has_recurrences:
* @comp: A calendar component object
*
* Queries whether a calendar component object has any recurrence dates or
* recurrence rules.
*
* Return value: TRUE if the component has recurrences, FALSE otherwise.
**/
gboolean
e_cal_component_has_recurrences (ECalComponent *comp)
{
return e_cal_component_has_rdates (comp) || e_cal_component_has_rrules (comp);
}
/* Counts the elements in the by_xxx fields of an icalrecurrencetype */
static int
count_by_xxx (short *field, int max_elements)
{
int i;
for (i = 0; i < max_elements; i++)
if (field[i] == ICAL_RECURRENCE_ARRAY_MAX)
break;
return i;
}
/**
* e_cal_component_has_simple_recurrence:
* @comp: A calendar component object.
*
* Checks whether the given calendar component object has simple recurrence
* rules or more complicated ones.
*
+ Return value: TRUE if it has a simple recurrence rule, FALSE otherwise.
*/
gboolean
e_cal_component_has_simple_recurrence (ECalComponent *comp)
{
GSList *rrule_list;
struct icalrecurrencetype *r;
int n_by_second, n_by_minute, n_by_hour;
int n_by_day, n_by_month_day, n_by_year_day;
int n_by_week_no, n_by_month, n_by_set_pos;
int len, i;
gboolean simple = FALSE;
if (!e_cal_component_has_recurrences (comp))
return TRUE;
e_cal_component_get_rrule_list (comp, &rrule_list);
len = g_slist_length (rrule_list);
if (len > 1
|| e_cal_component_has_rdates (comp)
|| e_cal_component_has_exrules (comp))
goto cleanup;
/* Down to one rule, so test that one */
r = rrule_list->data;
/* Any funky frequency? */
if (r->freq == ICAL_SECONDLY_RECURRENCE
|| r->freq == ICAL_MINUTELY_RECURRENCE
|| r->freq == ICAL_HOURLY_RECURRENCE)
goto cleanup;
/* Any funky BY_* */
#define N_HAS_BY(field) (count_by_xxx (field, sizeof (field) / sizeof (field[0])))
n_by_second = N_HAS_BY (r->by_second);
n_by_minute = N_HAS_BY (r->by_minute);
n_by_hour = N_HAS_BY (r->by_hour);
n_by_day = N_HAS_BY (r->by_day);
n_by_month_day = N_HAS_BY (r->by_month_day);
n_by_year_day = N_HAS_BY (r->by_year_day);
n_by_week_no = N_HAS_BY (r->by_week_no);
n_by_month = N_HAS_BY (r->by_month);
n_by_set_pos = N_HAS_BY (r->by_set_pos);
if (n_by_second != 0
|| n_by_minute != 0
|| n_by_hour != 0)
goto cleanup;
switch (r->freq) {
case ICAL_DAILY_RECURRENCE:
if (n_by_day != 0
|| n_by_month_day != 0
|| n_by_year_day != 0
|| n_by_week_no != 0
|| n_by_month != 0
|| n_by_set_pos != 0)
goto cleanup;
simple = TRUE;
break;
case ICAL_WEEKLY_RECURRENCE:
if (n_by_month_day != 0
|| n_by_year_day != 0
|| n_by_week_no != 0
|| n_by_month != 0
|| n_by_set_pos != 0)
goto cleanup;
for (i = 0; i < 8 && r->by_day[i] != ICAL_RECURRENCE_ARRAY_MAX; i++) {
int pos;
pos = icalrecurrencetype_day_position (r->by_day[i]);
if (pos != 0)
goto cleanup;
}
simple = TRUE;
break;
case ICAL_MONTHLY_RECURRENCE:
if (n_by_year_day != 0
|| n_by_week_no != 0
|| n_by_month != 0
|| n_by_set_pos > 1)
goto cleanup;
if (n_by_month_day == 1) {
int nth;
if (n_by_set_pos != 0)
goto cleanup;
nth = r->by_month_day[0];
if (nth < 1 && nth != -1)
goto cleanup;
simple = TRUE;
} else if (n_by_day == 1) {
enum icalrecurrencetype_weekday weekday;
int pos;
/* Outlook 2000 uses BYDAY=TU;BYSETPOS=2, and will not
accept BYDAY=2TU. So we now use the same as Outlook
by default. */
weekday = icalrecurrencetype_day_day_of_week (r->by_day[0]);
pos = icalrecurrencetype_day_position (r->by_day[0]);
if (pos == 0) {
if (n_by_set_pos != 1)
goto cleanup;
pos = r->by_set_pos[0];
} else if (pos < 0) {
goto cleanup;
}
switch (weekday) {
case ICAL_MONDAY_WEEKDAY:
case ICAL_TUESDAY_WEEKDAY:
case ICAL_WEDNESDAY_WEEKDAY:
case ICAL_THURSDAY_WEEKDAY:
case ICAL_FRIDAY_WEEKDAY:
case ICAL_SATURDAY_WEEKDAY:
case ICAL_SUNDAY_WEEKDAY:
break;
default:
goto cleanup;
}
} else {
goto cleanup;
}
simple = TRUE;
break;
case ICAL_YEARLY_RECURRENCE:
if (n_by_day != 0
|| n_by_month_day != 0
|| n_by_year_day != 0
|| n_by_week_no != 0
|| n_by_month != 0
|| n_by_set_pos != 0)
goto cleanup;
simple = TRUE;
break;
default:
goto cleanup;
}
cleanup:
e_cal_component_free_recur_list (rrule_list);
return simple;
}
/**
* e_cal_component_is_instance:
* @comp: A calendar component object.
*
* Checks whether a calendar component object is an instance of a recurring
* event.
*
* Return value: TRUE if it is an instance, FALSE if not.
*/
gboolean
e_cal_component_is_instance (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
return !(priv->recur_id.recur_time.prop == NULL);
}
/**
* e_cal_component_get_sequence:
* @comp: A calendar component object.
* @sequence: Return value for the sequence number. This should be freed using
* e_cal_component_free_sequence().
*
* Queries the sequence number of a calendar component object.
**/
void
e_cal_component_get_sequence (ECalComponent *comp, int **sequence)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (sequence != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!priv->sequence) {
*sequence = NULL;
return;
}
*sequence = g_new (int, 1);
**sequence = icalproperty_get_sequence (priv->sequence);
}
/**
* e_cal_component_set_sequence:
* @comp: A calendar component object.
* @sequence: Sequence number value.
*
* Sets the sequence number of a calendar component object. Normally this
* function should not be called, since the sequence number is incremented
* automatically at the proper times.
**/
void
e_cal_component_set_sequence (ECalComponent *comp, int *sequence)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
priv->need_sequence_inc = FALSE;
if (!sequence) {
if (priv->sequence) {
icalcomponent_remove_property (priv->icalcomp, priv->sequence);
icalproperty_free (priv->sequence);
priv->sequence = NULL;
}
return;
}
if (priv->sequence)
icalproperty_set_sequence (priv->sequence, *sequence);
else {
priv->sequence = icalproperty_new_sequence (*sequence);
icalcomponent_add_property (priv->icalcomp, priv->sequence);
}
}
/**
* e_cal_component_get_status:
* @comp: A calendar component object.
* @status: Return value for the status value. It is set to #ICAL_STATUS_NONE
* if the component has no status property.
*
* Queries the status property of a calendar component object.
**/
void
e_cal_component_get_status (ECalComponent *comp, icalproperty_status *status)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (status != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!priv->status) {
*status = ICAL_STATUS_NONE;
return;
}
*status = icalproperty_get_status (priv->status);
}
/**
* e_cal_component_set_status:
* @comp: A calendar component object.
* @status: Status value. You should use #ICAL_STATUS_NONE if you want to unset
* this property.
*
* Sets the status property of a calendar component object.
**/
void
e_cal_component_set_status (ECalComponent *comp, icalproperty_status status)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
priv->need_sequence_inc = TRUE;
if (status == ICAL_STATUS_NONE) {
if (priv->status) {
icalcomponent_remove_property (priv->icalcomp, priv->status);
icalproperty_free (priv->status);
priv->status = NULL;
}
return;
}
if (priv->status) {
icalproperty_set_status (priv->status, status);
} else {
priv->status = icalproperty_new_status (status);
icalcomponent_add_property (priv->icalcomp, priv->status);
}
}
/**
* e_cal_component_get_summary:
* @comp: A calendar component object.
* @summary: Return value for the summary property and its parameters.
*
* Queries the summary of a calendar component object.
**/
void
e_cal_component_get_summary (ECalComponent *comp, ECalComponentText *summary)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (summary != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (priv->summary.prop)
summary->value = icalproperty_get_summary (priv->summary.prop);
else
summary->value = NULL;
if (priv->summary.altrep_param)
summary->altrep = icalparameter_get_altrep (priv->summary.altrep_param);
else
summary->altrep = NULL;
}
typedef struct {
const char *old_summary;
const char *new_summary;
} SetAlarmDescriptionData;
static void
set_alarm_description_cb (gpointer key, gpointer value, gpointer user_data)
{
icalcomponent *alarm;
icalproperty *icalprop, *desc_prop;
SetAlarmDescriptionData *sadd;
gboolean changed = FALSE;
const char *old_summary = NULL;
alarm = value;
sadd = user_data;
/* set the new description on the alarm */
desc_prop = icalcomponent_get_first_property (alarm, ICAL_DESCRIPTION_PROPERTY);
if (desc_prop)
old_summary = icalproperty_get_description (desc_prop);
else
desc_prop = icalproperty_new_description (sadd->new_summary);
/* remove the X-EVOLUTION-NEEDS_DESCRIPTION property */
icalprop = icalcomponent_get_first_property (alarm, ICAL_X_PROPERTY);
while (icalprop) {
const char *x_name;
x_name = icalproperty_get_x_name (icalprop);
if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
icalcomponent_remove_property (alarm, icalprop);
icalproperty_free (icalprop);
icalproperty_set_description (desc_prop, sadd->new_summary);
changed = TRUE;
break;
}
icalprop = icalcomponent_get_next_property (alarm, ICAL_X_PROPERTY);
}
if (!changed) {
if (!strcmp (old_summary ? old_summary : "", sadd->old_summary ? sadd->old_summary : "")) {
icalproperty_set_description (desc_prop, sadd->new_summary);
}
}
}
/**
* e_cal_component_set_summary:
* @comp: A calendar component object.
* @summary: Summary property and its parameters.
*
* Sets the summary of a calendar component object.
**/
void
e_cal_component_set_summary (ECalComponent *comp, ECalComponentText *summary)
{
ECalComponentPrivate *priv;
SetAlarmDescriptionData sadd;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!summary) {
if (priv->summary.prop) {
icalcomponent_remove_property (priv->icalcomp, priv->summary.prop);
icalproperty_free (priv->summary.prop);
priv->summary.prop = NULL;
priv->summary.altrep_param = NULL;
}
return;
}
g_return_if_fail (summary->value != NULL);
if (priv->summary.prop) {
sadd.old_summary = icalproperty_get_summary (priv->summary.prop);
icalproperty_set_summary (priv->summary.prop, (char *) summary->value);
} else {
sadd.old_summary = NULL;
priv->summary.prop = icalproperty_new_summary ((char *) summary->value);
icalcomponent_add_property (priv->icalcomp, priv->summary.prop);
}
if (summary->altrep) {
g_assert (priv->summary.prop != NULL);
if (priv->summary.altrep_param)
icalparameter_set_altrep (priv->summary.altrep_param,
(char *) summary->altrep);
else {
priv->summary.altrep_param = icalparameter_new_altrep (
(char *) summary->altrep);
icalproperty_add_parameter (priv->summary.prop,
priv->summary.altrep_param);
}
} else if (priv->summary.altrep_param) {
icalproperty_remove_parameter (priv->summary.prop, ICAL_ALTREP_PARAMETER);
priv->summary.altrep_param = NULL;
}
/* look for alarms that need a description */
sadd.new_summary = summary->value;
g_hash_table_foreach (priv->alarm_uid_hash, set_alarm_description_cb, &sadd);
}
/**
* e_cal_component_get_transparency:
* @comp: A calendar component object.
* @transp: Return value for the time transparency.
*
* Queries the time transparency of a calendar component object.
**/
void
e_cal_component_get_transparency (ECalComponent *comp, ECalComponentTransparency *transp)
{
ECalComponentPrivate *priv;
icalproperty_transp ical_transp;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (transp != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!priv->transparency) {
*transp = E_CAL_COMPONENT_TRANSP_NONE;
return;
}
ical_transp = icalproperty_get_transp (priv->transparency);
switch (ical_transp)
{
case ICAL_TRANSP_TRANSPARENT:
case ICAL_TRANSP_TRANSPARENTNOCONFLICT:
*transp = E_CAL_COMPONENT_TRANSP_TRANSPARENT;
break;
case ICAL_TRANSP_OPAQUE:
case ICAL_TRANSP_OPAQUENOCONFLICT:
*transp = E_CAL_COMPONENT_TRANSP_OPAQUE;
break;
default:
*transp = E_CAL_COMPONENT_TRANSP_UNKNOWN;
break;
}
}
/**
* e_cal_component_set_transparency:
* @comp: A calendar component object.
* @transp: Time transparency value.
*
* Sets the time transparency of a calendar component object.
**/
void
e_cal_component_set_transparency (ECalComponent *comp, ECalComponentTransparency transp)
{
ECalComponentPrivate *priv;
icalproperty_transp ical_transp;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (transp != E_CAL_COMPONENT_TRANSP_UNKNOWN);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (transp == E_CAL_COMPONENT_TRANSP_NONE) {
if (priv->transparency) {
icalcomponent_remove_property (priv->icalcomp, priv->transparency);
icalproperty_free (priv->transparency);
priv->transparency = NULL;
}
return;
}
switch (transp) {
case E_CAL_COMPONENT_TRANSP_TRANSPARENT:
ical_transp = ICAL_TRANSP_TRANSPARENT;
break;
case E_CAL_COMPONENT_TRANSP_OPAQUE:
ical_transp = ICAL_TRANSP_OPAQUE;
break;
default:
g_assert_not_reached ();
ical_transp = ICAL_TRANSP_NONE;
}
if (priv->transparency)
icalproperty_set_transp (priv->transparency, ical_transp);
else {
priv->transparency = icalproperty_new_transp (ical_transp);
icalcomponent_add_property (priv->icalcomp, priv->transparency);
}
}
/**
* e_cal_component_get_url:
* @comp: A calendar component object.
* @url: Return value for the URL.
*
* Queries the uniform resource locator property of a calendar component object.
**/
void
e_cal_component_get_url (ECalComponent *comp, const char **url)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (url != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (priv->url)
*url = icalproperty_get_url (priv->url);
else
*url = NULL;
}
/**
* e_cal_component_set_url:
* @comp: A calendar component object.
* @url: URL value.
*
* Sets the uniform resource locator property of a calendar component object.
**/
void
e_cal_component_set_url (ECalComponent *comp, const char *url)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!url || !(*url)) {
if (priv->url) {
icalcomponent_remove_property (priv->icalcomp, priv->url);
icalproperty_free (priv->url);
priv->url = NULL;
}
return;
}
if (priv->url)
icalproperty_set_url (priv->url, (char *) url);
else {
priv->url = icalproperty_new_url ((char *) url);
icalcomponent_add_property (priv->icalcomp, priv->url);
}
}
/* Gets a text list value */
static void
get_attendee_list (GSList *attendee_list, GSList **al)
{
GSList *l;
*al = NULL;
if (!attendee_list)
return;
for (l = attendee_list; l; l = l->next) {
struct attendee *attendee;
ECalComponentAttendee *a;
attendee = l->data;
g_assert (attendee->prop != NULL);
a = g_new0 (ECalComponentAttendee, 1);
a->value = icalproperty_get_attendee (attendee->prop);
if (attendee->member_param)
a->member = icalparameter_get_member (attendee->member_param);
if (attendee->cutype_param)
a->cutype = icalparameter_get_cutype (attendee->cutype_param);
else
a->cutype = ICAL_CUTYPE_UNKNOWN;
if (attendee->role_param)
a->role = icalparameter_get_role (attendee->role_param);
else
a->role = ICAL_ROLE_REQPARTICIPANT;
if (attendee->partstat_param)
a->status = icalparameter_get_partstat (attendee->partstat_param);
else
a->status = ICAL_PARTSTAT_NEEDSACTION;
if (attendee->rsvp_param && icalparameter_get_rsvp (attendee->rsvp_param) == ICAL_RSVP_TRUE)
a->rsvp = TRUE;
else
a->rsvp = FALSE;
if (attendee->delfrom_param)
a->delfrom = icalparameter_get_delegatedfrom (attendee->delfrom_param);
if (attendee->delto_param)
a->delto = icalparameter_get_delegatedto (attendee->delto_param);
if (attendee->sentby_param)
a->sentby = icalparameter_get_sentby (attendee->sentby_param);
if (attendee->cn_param)
a->cn = icalparameter_get_cn (attendee->cn_param);
if (attendee->language_param)
a->language = icalparameter_get_language (attendee->language_param);
*al = g_slist_prepend (*al, a);
}
*al = g_slist_reverse (*al);
}
/* Sets a text list value */
static void
set_attendee_list (icalcomponent *icalcomp,
GSList **attendee_list,
GSList *al)
{
GSList *l;
/* Remove old attendees */
for (l = *attendee_list; l; l = l->next) {
struct attendee *attendee;
attendee = l->data;
g_assert (attendee->prop != NULL);
icalcomponent_remove_property (icalcomp, attendee->prop);
icalproperty_free (attendee->prop);
g_free (attendee);
}
g_slist_free (*attendee_list);
*attendee_list = NULL;
/* Add in new attendees */
for (l = al; l; l = l->next) {
ECalComponentAttendee *a;
struct attendee *attendee;
a = l->data;
g_return_if_fail (a->value != NULL);
attendee = g_new0 (struct attendee, 1);
attendee->prop = icalproperty_new_attendee (a->value);
icalcomponent_add_property (icalcomp, attendee->prop);
if (a->member) {
attendee->member_param = icalparameter_new_member (a->member);
icalproperty_add_parameter (attendee->prop, attendee->member_param);
}
attendee->cutype_param = icalparameter_new_cutype (a->cutype);
icalproperty_add_parameter (attendee->prop, attendee->cutype_param);
attendee->role_param = icalparameter_new_role (a->role);
icalproperty_add_parameter (attendee->prop, attendee->role_param);
attendee->partstat_param = icalparameter_new_partstat (a->status);
icalproperty_add_parameter (attendee->prop, attendee->partstat_param);
if (a->rsvp)
attendee->rsvp_param = icalparameter_new_rsvp (ICAL_RSVP_TRUE);
else
attendee->rsvp_param = icalparameter_new_rsvp (ICAL_RSVP_FALSE);
icalproperty_add_parameter (attendee->prop, attendee->rsvp_param);
if (a->delfrom) {
attendee->delfrom_param = icalparameter_new_delegatedfrom (a->delfrom);
icalproperty_add_parameter (attendee->prop, attendee->delfrom_param);
}
if (a->delto) {
attendee->delto_param = icalparameter_new_delegatedto (a->delto);
icalproperty_add_parameter (attendee->prop, attendee->delto_param);
}
if (a->sentby) {
attendee->sentby_param = icalparameter_new_sentby (a->sentby);
icalproperty_add_parameter (attendee->prop, attendee->sentby_param);
}
if (a->cn) {
attendee->cn_param = icalparameter_new_cn (a->cn);
icalproperty_add_parameter (attendee->prop, attendee->cn_param);
}
if (a->language) {
attendee->language_param = icalparameter_new_language (a->language);
icalproperty_add_parameter (attendee->prop, attendee->language_param);
}
*attendee_list = g_slist_prepend (*attendee_list, attendee);
}
*attendee_list = g_slist_reverse (*attendee_list);
}
/**
* e_cal_component_get_attendee_list:
* @comp: A calendar component object.
* @attendee_list: Return value for the attendee property.
* This should be freed using the e_cal_component_free_attendee_list ()
* function.
*
* Queries the attendee properties of the calendar component object
**/
void
e_cal_component_get_attendee_list (ECalComponent *comp, GSList **attendee_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (attendee_list != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
get_attendee_list (priv->attendee_list, attendee_list);
}
/**
* e_cal_component_set_attendee_list:
* @comp: A calendar component object.
* @attendee_list: Values for attendee properties
*
* Sets the attendees of a calendar component object
**/
void
e_cal_component_set_attendee_list (ECalComponent *comp, GSList *attendee_list)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
set_attendee_list (priv->icalcomp, &priv->attendee_list, attendee_list);
}
/**
* e_cal_component_has_attendees:
* @comp: A calendar component object.
*
* Queries a calendar component object for the existence of attendees.
*
* Return value: TRUE if there are attendees, FALSE if not.
*/
gboolean
e_cal_component_has_attendees (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
if (g_slist_length (priv->attendee_list) > 0)
return TRUE;
return FALSE;
}
/**
* e_cal_component_get_location:
* @comp: A calendar component object
* @location: Return value for the location.
*
* Queries the location property of a calendar component object.
**/
void
e_cal_component_get_location (ECalComponent *comp, const char **location)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (location != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (priv->location)
*location = icalproperty_get_location (priv->location);
else
*location = NULL;
}
/**
* e_cal_component_set_location:
* @comp: A calendar component object.
* @location: Location value.
*
* Sets the location property of a calendar component object.
**/
void
e_cal_component_set_location (ECalComponent *comp, const char *location)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
if (!location || !(*location)) {
if (priv->location) {
icalcomponent_remove_property (priv->icalcomp, priv->location);
icalproperty_free (priv->location);
priv->location = NULL;
}
return;
}
if (priv->location)
icalproperty_set_location (priv->location, (char *) location);
else {
priv->location = icalproperty_new_location ((char *) location);
icalcomponent_add_property (priv->icalcomp, priv->location);
}
}
/**
* e_cal_component_free_categories_list:
* @categ_list: List of category strings.
*
* Frees a list of category strings.
**/
void
e_cal_component_free_categories_list (GSList *categ_list)
{
GSList *l;
for (l = categ_list; l; l = l->next)
g_free (l->data);
g_slist_free (categ_list);
}
/**
* e_cal_component_free_datetime:
* @dt: A date/time structure.
*
* Frees a date/time structure.
**/
void
e_cal_component_free_datetime (ECalComponentDateTime *dt)
{
g_return_if_fail (dt != NULL);
g_free (dt->value);
g_free ((char*)dt->tzid);
}
/**
* e_cal_component_free_range:
* @range: A #ECalComponentRange.
*
* Frees an #ECalComponentRange structure.
*/
void
e_cal_component_free_range (ECalComponentRange *range)
{
g_return_if_fail (range != NULL);
e_cal_component_free_datetime (&range->datetime);
}
/**
* e_cal_component_free_exdate_list:
* @exdate_list: List of #ECalComponentDateTime structures.
*
* Frees a list of #ECalComponentDateTime structures as returned by the
* e_cal_component_get_exdate_list() function.
**/
void
e_cal_component_free_exdate_list (GSList *exdate_list)
{
GSList *l;
for (l = exdate_list; l; l = l->next) {
ECalComponentDateTime *cdt;
g_assert (l->data != NULL);
cdt = l->data;
g_assert (cdt->value != NULL);
g_free (cdt->value);
g_free ((char*)cdt->tzid);
g_free (cdt);
}
g_slist_free (exdate_list);
}
/**
* e_cal_component_free_geo:
* @geo: An #icalgeotype structure.
*
* Frees a struct #icalgeotype structure as returned by the calendar component
* functions.
**/
void
e_cal_component_free_geo (struct icalgeotype *geo)
{
g_return_if_fail (geo != NULL);
g_free (geo);
}
/**
* e_cal_component_free_icaltimetype:
* @t: An #icaltimetype structure.
*
* Frees a struct #icaltimetype value as returned by the calendar component
* functions.
**/
void
e_cal_component_free_icaltimetype (struct icaltimetype *t)
{
g_return_if_fail (t != NULL);
g_free (t);
}
/**
* e_cal_component_free_percent:
* @percent: Percent value.
*
* Frees a percent value as returned by the e_cal_component_get_percent()
* function.
**/
void
e_cal_component_free_percent (int *percent)
{
g_return_if_fail (percent != NULL);
g_free (percent);
}
/**
* e_cal_component_free_priority:
* @priority: Priority value.
*
* Frees a priority value as returned by the e_cal_component_get_priority()
* function.
**/
void
e_cal_component_free_priority (int *priority)
{
g_return_if_fail (priority != NULL);
g_free (priority);
}
/**
* e_cal_component_free_period_list:
* @period_list: List of #ECalComponentPeriod structures.
*
* Frees a list of #ECalComponentPeriod structures.
**/
void
e_cal_component_free_period_list (GSList *period_list)
{
GSList *l;
for (l = period_list; l; l = l->next) {
ECalComponentPeriod *period;
g_assert (l->data != NULL);
period = l->data;
g_free (period);
}
g_slist_free (period_list);
}
/**
* e_cal_component_free_recur_list:
* @recur_list: List of struct #icalrecurrencetype structures.
*
* Frees a list of struct #icalrecurrencetype structures.
**/
void
e_cal_component_free_recur_list (GSList *recur_list)
{
GSList *l;
for (l = recur_list; l; l = l->next) {
struct icalrecurrencetype *r;
g_assert (l->data != NULL);
r = l->data;
g_free (r);
}
g_slist_free (recur_list);
}
/**
* e_cal_component_free_sequence:
* @sequence: Sequence number value.
*
* Frees a sequence number value.
**/
void
e_cal_component_free_sequence (int *sequence)
{
g_return_if_fail (sequence != NULL);
g_free (sequence);
}
/**
* e_cal_component_free_id:
* @id Component Id.
*
* Frees the id.
**/
void
e_cal_component_free_id (ECalComponentId *id)
{
g_return_if_fail (id != NULL);
if (id->uid) {
g_free (id->uid);
id->uid = NULL;
}
if (id->rid) {
g_free (id->rid);
id->rid = NULL;
}
g_free (id);
}
/**
* e_cal_component_free_text_list:
* @text_list: List of #ECalComponentText structures.
*
* Frees a list of #ECalComponentText structures. This function should only be
* used to free lists of text values as returned by the other getter functions
* of #ECalComponent.
**/
void
e_cal_component_free_text_list (GSList *text_list)
{
GSList *l;
for (l = text_list; l; l = l->next) {
ECalComponentText *text;
g_assert (l->data != NULL);
text = l->data;
g_return_if_fail (text != NULL);
g_free (text);
}
g_slist_free (text_list);
}
/**
* e_cal_component_free_attendee_list:
* @attendee_list: List of attendees.
*
* Frees a list of #ECalComponentAttendee structures.
*
**/
void
e_cal_component_free_attendee_list (GSList *attendee_list)
{
GSList *l;
for (l = attendee_list; l; l = l->next) {
ECalComponentAttendee *attendee;
g_assert (l->data != NULL);
attendee = l->data;
g_return_if_fail (attendee != NULL);
g_free (attendee);
}
g_slist_free (attendee_list);
}
/**
* e_cal_component_has_alarms:
* @comp: A calendar component object.
*
* Checks whether the component has any alarms.
*
* Return value: TRUE if the component has any alarms.
**/
gboolean
e_cal_component_has_alarms (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_val_if_fail (comp != NULL, FALSE);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), FALSE);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, FALSE);
return g_hash_table_size (priv->alarm_uid_hash) != 0;
}
/**
* e_cal_component_add_alarm:
* @comp: A calendar component.
* @alarm: An alarm.
*
* Adds an alarm subcomponent to a calendar component. You should have created
* the @alarm by using e_cal_component_alarm_new(); it is invalid to use a
* #ECalComponentAlarm structure that came from e_cal_component_get_alarm(). After
* adding the alarm, the @alarm structure is no longer valid because the
* internal structures may change and you should get rid of it by using
* e_cal_component_alarm_free().
**/
void
e_cal_component_add_alarm (ECalComponent *comp, ECalComponentAlarm *alarm)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (alarm != NULL);
priv = comp->priv;
add_alarm (comp, alarm->icalcomp, icalproperty_get_x (alarm->uid));
icalcomponent_add_component (priv->icalcomp, alarm->icalcomp);
}
/**
* e_cal_component_remove_alarm:
* @comp: A calendar component.
* @auid: UID of the alarm to remove.
*
* Removes an alarm subcomponent from a calendar component. If the alarm that
* corresponds to the specified @auid had been fetched with
* e_cal_component_get_alarm(), then those alarm structures will be invalid; you
* should get rid of them with e_cal_component_alarm_free() before using this
* function.
**/
void
e_cal_component_remove_alarm (ECalComponent *comp, const char *auid)
{
ECalComponentPrivate *priv;
icalcomponent *alarm;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
g_return_if_fail (auid != NULL);
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
alarm = g_hash_table_lookup (priv->alarm_uid_hash, auid);
if (!alarm)
return;
g_hash_table_remove (priv->alarm_uid_hash, auid);
icalcomponent_remove_component (priv->icalcomp, alarm);
icalcomponent_free (alarm);
}
static gboolean
for_each_remove_all_alarms (gpointer key, gpointer value, gpointer data)
{
ECalComponent *comp = E_CAL_COMPONENT (data);
ECalComponentPrivate *priv;
icalcomponent *alarm = value;
priv = comp->priv;
icalcomponent_remove_component (priv->icalcomp, alarm);
icalcomponent_free (alarm);
return TRUE;
}
/**
* e_cal_component_remove_all_alarms:
* @comp: A calendar component
*
* Remove all alarms from the calendar component
**/
void
e_cal_component_remove_all_alarms (ECalComponent *comp)
{
ECalComponentPrivate *priv;
g_return_if_fail (comp != NULL);
g_return_if_fail (E_IS_CAL_COMPONENT (comp));
priv = comp->priv;
g_return_if_fail (priv->icalcomp != NULL);
g_hash_table_foreach_remove (priv->alarm_uid_hash, for_each_remove_all_alarms, comp);
}
/* Scans an icalproperty from a calendar component and adds its mapping to our
* own alarm structure.
*/
static void
scan_alarm_property (ECalComponentAlarm *alarm, icalproperty *prop)
{
icalproperty_kind kind;
const char *xname;
kind = icalproperty_isa (prop);
switch (kind) {
case ICAL_ACTION_PROPERTY:
alarm->action = prop;
break;
case ICAL_ATTACH_PROPERTY:
/* FIXME: mail alarms may have any number of these, not just one */
alarm->attach = prop;
break;
case ICAL_DESCRIPTION_PROPERTY:
alarm->description.prop = prop;
alarm->description.altrep_param = icalproperty_get_first_parameter (
prop, ICAL_ALTREP_PARAMETER);
break;
case ICAL_DURATION_PROPERTY:
alarm->duration = prop;
break;
case ICAL_REPEAT_PROPERTY:
alarm->repeat = prop;
break;
case ICAL_TRIGGER_PROPERTY:
alarm->trigger = prop;
break;
case ICAL_ATTENDEE_PROPERTY:
scan_attendee (&alarm->attendee_list, prop);
break;
case ICAL_X_PROPERTY:
xname = icalproperty_get_x_name (prop);
g_assert (xname != NULL);
if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0)
alarm->uid = prop;
break;
default:
break;
}
}
/* Creates a ECalComponentAlarm from a libical alarm subcomponent */
static ECalComponentAlarm *
make_alarm (icalcomponent *subcomp)
{
ECalComponentAlarm *alarm;
icalproperty *prop;
alarm = g_new (ECalComponentAlarm, 1);
alarm->icalcomp = subcomp;
alarm->uid = NULL;
alarm->action = NULL;
alarm->attach = NULL;
alarm->description.prop = NULL;
alarm->description.altrep_param = NULL;
alarm->duration = NULL;
alarm->repeat = NULL;
alarm->trigger = NULL;
alarm->attendee_list = NULL;
for (prop = icalcomponent_get_first_property (subcomp, ICAL_ANY_PROPERTY);
prop;
prop = icalcomponent_get_next_property (subcomp, ICAL_ANY_PROPERTY))
scan_alarm_property (alarm, prop);
g_assert (alarm->uid != NULL);
return alarm;
}
/**
* e_cal_component_get_alarm_uids:
* @comp: A calendar component.
*
* Builds a list of the unique identifiers of the alarm subcomponents inside a
* calendar component.
*
* Return value: List of unique identifiers for alarms. This should be freed
* using cal_obj_uid_list_free().
**/
GList *
e_cal_component_get_alarm_uids (ECalComponent *comp)
{
ECalComponentPrivate *priv;
icalcompiter iter;
GList *l;
g_return_val_if_fail (comp != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, NULL);
l = NULL;
for (iter = icalcomponent_begin_component (priv->icalcomp, ICAL_VALARM_COMPONENT);
icalcompiter_deref (&iter) != NULL;
icalcompiter_next (&iter)) {
icalcomponent *subcomp;
icalproperty *prop;
subcomp = icalcompiter_deref (&iter);
for (prop = icalcomponent_get_first_property (subcomp, ICAL_X_PROPERTY);
prop;
prop = icalcomponent_get_next_property (subcomp, ICAL_X_PROPERTY)) {
const char *xname;
xname = icalproperty_get_x_name (prop);
g_assert (xname != NULL);
if (strcmp (xname, EVOLUTION_ALARM_UID_PROPERTY) == 0) {
const char *auid;
auid = alarm_uid_from_prop (prop);
l = g_list_append (l, g_strdup (auid));
}
}
}
return l;
}
/**
* e_cal_component_get_alarm:
* @comp: A calendar component.
* @auid: Unique identifier for the sought alarm subcomponent.
*
* Queries a particular alarm subcomponent of a calendar component.
*
* Return value: The alarm subcomponent that corresponds to the specified @auid,
* or #NULL if no alarm exists with that UID. This should be freed using
* e_cal_component_alarm_free().
**/
ECalComponentAlarm *
e_cal_component_get_alarm (ECalComponent *comp, const char *auid)
{
ECalComponentPrivate *priv;
icalcomponent *alarm;
g_return_val_if_fail (comp != NULL, NULL);
g_return_val_if_fail (E_IS_CAL_COMPONENT (comp), NULL);
priv = comp->priv;
g_return_val_if_fail (priv->icalcomp != NULL, NULL);
g_return_val_if_fail (auid != NULL, NULL);
alarm = g_hash_table_lookup (priv->alarm_uid_hash, auid);
if (alarm)
return make_alarm (alarm);
else
return NULL;
}
/**
* e_cal_component_alarms_free:
* @alarms: Component alarms structure.
*
* Frees a #ECalComponentAlarms structure.
**/
void
e_cal_component_alarms_free (ECalComponentAlarms *alarms)
{
GSList *l;
g_return_if_fail (alarms != NULL);
g_assert (alarms->comp != NULL);
g_object_unref (G_OBJECT (alarms->comp));
for (l = alarms->alarms; l; l = l->next) {
ECalComponentAlarmInstance *instance;
instance = l->data;
g_assert (instance != NULL);
g_free (instance);
}
g_slist_free (alarms->alarms);
g_free (alarms);
}
/**
* e_cal_component_alarm_new:
*
* Create a new alarm object.
*
* Return value: a new alarm component
**/
ECalComponentAlarm *
e_cal_component_alarm_new (void)
{
ECalComponentAlarm *alarm;
char *new_auid ;
alarm = g_new (ECalComponentAlarm, 1);
alarm->icalcomp = icalcomponent_new (ICAL_VALARM_COMPONENT);
new_auid = e_cal_component_gen_uid ();
alarm->uid = icalproperty_new_x (new_auid);
icalproperty_set_x_name (alarm->uid, EVOLUTION_ALARM_UID_PROPERTY);
icalcomponent_add_property (alarm->icalcomp, alarm->uid);
g_free (new_auid);
alarm->action = NULL;
alarm->attach = NULL;
alarm->description.prop = NULL;
alarm->description.altrep_param = NULL;
alarm->duration = NULL;
alarm->repeat = NULL;
alarm->trigger = NULL;
alarm->attendee_list = NULL;
return alarm;
}
/**
* e_cal_component_alarm_clone:
* @alarm: An alarm subcomponent.
*
* Creates a new alarm subcomponent by copying the information from another one.
*
* Return value: A newly-created alarm subcomponent with the same values as the
* original one. Should be freed with e_cal_component_alarm_free().
**/
ECalComponentAlarm *
e_cal_component_alarm_clone (ECalComponentAlarm *alarm)
{
icalcomponent *icalcomp;
g_return_val_if_fail (alarm != NULL, NULL);
icalcomp = icalcomponent_new_clone (alarm->icalcomp);
return make_alarm (icalcomp);
}
/**
* e_cal_component_alarm_free:
* @alarm: A calendar alarm.
*
* Frees an alarm structure.
**/
void
e_cal_component_alarm_free (ECalComponentAlarm *alarm)
{
GSList *l;
g_return_if_fail (alarm != NULL);
g_assert (alarm->icalcomp != NULL);
if (icalcomponent_get_parent (alarm->icalcomp) == NULL)
icalcomponent_free (alarm->icalcomp);
alarm->icalcomp = NULL;
alarm->uid = NULL;
alarm->action = NULL;
alarm->attach = NULL;
alarm->description.prop = NULL;
alarm->description.altrep_param = NULL;
alarm->duration = NULL;
alarm->repeat = NULL;
alarm->trigger = NULL;
for (l = alarm->attendee_list; l != NULL; l = l->next)
g_free (l->data);
g_slist_free (alarm->attendee_list);
alarm->attendee_list = NULL;
g_free (alarm);
}
/**
* e_cal_component_alarm_get_uid:
* @alarm: An alarm subcomponent.
*
* Queries the unique identifier of an alarm subcomponent.
*
* Return value: UID of the alarm.
**/
const char *
e_cal_component_alarm_get_uid (ECalComponentAlarm *alarm)
{
g_return_val_if_fail (alarm != NULL, NULL);
return alarm_uid_from_prop (alarm->uid);
}
/**
* e_cal_component_alarm_get_action:
* @alarm: An alarm.
* @action: Return value for the alarm's action type.
*
* Queries the action type of an alarm.
**/
void
e_cal_component_alarm_get_action (ECalComponentAlarm *alarm, ECalComponentAlarmAction *action)
{
enum icalproperty_action ipa;
g_return_if_fail (alarm != NULL);
g_return_if_fail (action != NULL);
g_assert (alarm->icalcomp != NULL);
if (!alarm->action) {
*action = E_CAL_COMPONENT_ALARM_NONE;
return;
}
ipa = icalproperty_get_action (alarm->action);
switch (ipa) {
case ICAL_ACTION_AUDIO:
*action = E_CAL_COMPONENT_ALARM_AUDIO;
break;
case ICAL_ACTION_DISPLAY:
*action = E_CAL_COMPONENT_ALARM_DISPLAY;
break;
case ICAL_ACTION_EMAIL:
*action = E_CAL_COMPONENT_ALARM_EMAIL;
break;
case ICAL_ACTION_PROCEDURE:
*action = E_CAL_COMPONENT_ALARM_PROCEDURE;
break;
case ICAL_ACTION_NONE:
*action = E_CAL_COMPONENT_ALARM_NONE;
break;
default:
*action = E_CAL_COMPONENT_ALARM_UNKNOWN;
}
}
/**
* e_cal_component_alarm_set_action:
* @alarm: An alarm.
* @action: Action type.
*
* Sets the action type for an alarm.
**/
void
e_cal_component_alarm_set_action (ECalComponentAlarm *alarm, ECalComponentAlarmAction action)
{
enum icalproperty_action ipa;
g_return_if_fail (alarm != NULL);
g_return_if_fail (action != E_CAL_COMPONENT_ALARM_NONE);
g_return_if_fail (action != E_CAL_COMPONENT_ALARM_UNKNOWN);
g_assert (alarm->icalcomp != NULL);
switch (action) {
case E_CAL_COMPONENT_ALARM_AUDIO:
ipa = ICAL_ACTION_AUDIO;
break;
case E_CAL_COMPONENT_ALARM_DISPLAY:
ipa = ICAL_ACTION_DISPLAY;
break;
case E_CAL_COMPONENT_ALARM_EMAIL:
ipa = ICAL_ACTION_EMAIL;
break;
case E_CAL_COMPONENT_ALARM_PROCEDURE:
ipa = ICAL_ACTION_PROCEDURE;
break;
default:
g_assert_not_reached ();
ipa = ICAL_ACTION_NONE;
}
if (alarm->action)
icalproperty_set_action (alarm->action, ipa);
else {
alarm->action = icalproperty_new_action (ipa);
icalcomponent_add_property (alarm->icalcomp, alarm->action);
}
}
/**
* e_cal_component_alarm_get_attach:
* @alarm: An alarm.
* @attach: Return value for the attachment; should be freed using icalattach_unref().
*
* Queries the attachment property of an alarm.
**/
void
e_cal_component_alarm_get_attach (ECalComponentAlarm *alarm, icalattach **attach)
{
g_return_if_fail (alarm != NULL);
g_return_if_fail (attach != NULL);
g_assert (alarm->icalcomp != NULL);
if (alarm->attach) {
*attach = icalproperty_get_attach (alarm->attach);
icalattach_ref (*attach);
} else
*attach = NULL;
}
/**
* e_cal_component_alarm_set_attach:
* @alarm: An alarm.
* @attach: Attachment property or NULL to remove an existing property.
*
* Sets the attachment property of an alarm.
**/
void
e_cal_component_alarm_set_attach (ECalComponentAlarm *alarm, icalattach *attach)
{
g_return_if_fail (alarm != NULL);
g_assert (alarm->icalcomp != NULL);
if (alarm->attach) {
icalcomponent_remove_property (alarm->icalcomp, alarm->attach);
icalproperty_free (alarm->attach);
alarm->attach = NULL;
}
if (attach) {
alarm->attach = icalproperty_new_attach (attach);
icalcomponent_add_property (alarm->icalcomp, alarm->attach);
}
}
/**
* e_cal_component_alarm_get_description:
* @alarm: An alarm.
* @description: Return value for the description property and its parameters.
*
* Queries the description property of an alarm.
**/
void
e_cal_component_alarm_get_description (ECalComponentAlarm *alarm, ECalComponentText *description)
{
g_return_if_fail (alarm != NULL);
g_return_if_fail (description != NULL);
g_assert (alarm->icalcomp != NULL);
if (alarm->description.prop)
description->value = icalproperty_get_description (alarm->description.prop);
else
description->value = NULL;
if (alarm->description.altrep_param)
description->altrep = icalparameter_get_altrep (alarm->description.altrep_param);
else
description->altrep = NULL;
}
/**
* e_cal_component_alarm_set_description:
* @alarm: An alarm.
* @description: Description property and its parameters, or NULL for no description.
*
* Sets the description property of an alarm.
**/
void
e_cal_component_alarm_set_description (ECalComponentAlarm *alarm, ECalComponentText *description)
{
g_return_if_fail (alarm != NULL);
g_assert (alarm->icalcomp != NULL);
if (alarm->description.prop) {
icalcomponent_remove_property (alarm->icalcomp, alarm->description.prop);
icalproperty_free (alarm->description.prop);
alarm->description.prop = NULL;
alarm->description.altrep_param = NULL;
}
if (!description)
return;
g_return_if_fail (description->value != NULL);
alarm->description.prop = icalproperty_new_description (description->value);
icalcomponent_add_property (alarm->icalcomp, alarm->description.prop);
if (description->altrep) {
alarm->description.altrep_param = icalparameter_new_altrep (
(char *) description->altrep);
icalproperty_add_parameter (alarm->description.prop,
alarm->description.altrep_param);
}
}
/**
* e_cal_component_alarm_get_repeat:
* @alarm: An alarm.
* @repeat: Return value for the repeat/duration properties.
*
* Queries the repeat/duration properties of an alarm.
**/
void
e_cal_component_alarm_get_repeat (ECalComponentAlarm *alarm, ECalComponentAlarmRepeat *repeat)
{
g_return_if_fail (alarm != NULL);
g_return_if_fail (repeat != NULL);
g_assert (alarm->icalcomp != NULL);
if (!(alarm->repeat && alarm->duration)) {
repeat->repetitions = 0;
memset (&repeat->duration, 0, sizeof (repeat->duration));
return;
}
repeat->repetitions = icalproperty_get_repeat (alarm->repeat);
repeat->duration = icalproperty_get_duration (alarm->duration);
}
/**
* e_cal_component_alarm_set_repeat:
* @alarm: An alarm.
* @repeat: Repeat/duration values. To remove any repetitions from the alarm,
* set the @repeat.repetitions to 0.
*
* Sets the repeat/duration values for an alarm.
**/
void
e_cal_component_alarm_set_repeat (ECalComponentAlarm *alarm, ECalComponentAlarmRepeat repeat)
{
g_return_if_fail (alarm != NULL);
g_return_if_fail (repeat.repetitions >= 0);
g_assert (alarm->icalcomp != NULL);
/* Delete old properties */
if (alarm->repeat) {
icalcomponent_remove_property (alarm->icalcomp, alarm->repeat);
icalproperty_free (alarm->repeat);
alarm->repeat = NULL;
}
if (alarm->duration) {
icalcomponent_remove_property (alarm->icalcomp, alarm->duration);
icalproperty_free (alarm->duration);
alarm->duration = NULL;
}
/* Set the new properties */
if (repeat.repetitions == 0)
return; /* For zero extra repetitions the properties should not exist */
alarm->repeat = icalproperty_new_repeat (repeat.repetitions);
icalcomponent_add_property (alarm->icalcomp, alarm->repeat);
alarm->duration = icalproperty_new_duration (repeat.duration);
icalcomponent_add_property (alarm->icalcomp, alarm->duration);
}
/**
* e_cal_component_alarm_get_trigger:
* @alarm: An alarm.
* @trigger: Return value for the trigger time.
*
* Queries the trigger time for an alarm.
**/
void
e_cal_component_alarm_get_trigger (ECalComponentAlarm *alarm, ECalComponentAlarmTrigger *trigger)
{
icalparameter *param;
struct icaltriggertype t;
gboolean relative;
g_return_if_fail (alarm != NULL);
g_return_if_fail (trigger != NULL);
g_assert (alarm->icalcomp != NULL);
if (!alarm->trigger) {
trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_NONE;
return;
}
/* Get trigger type */
param = icalproperty_get_first_parameter (alarm->trigger, ICAL_VALUE_PARAMETER);
if (param) {
icalparameter_value value;
value = icalparameter_get_value (param);
switch (value) {
case ICAL_VALUE_DURATION:
relative = TRUE;
break;
case ICAL_VALUE_DATETIME:
relative = FALSE;
break;
default:
g_message ("e_cal_component_alarm_get_trigger(): Unknown value for trigger "
"value %d; using RELATIVE", value);
relative = TRUE;
break;
}
} else
relative = TRUE;
/* Get trigger value and the RELATED parameter */
t = icalproperty_get_trigger (alarm->trigger);
if (relative) {
trigger->u.rel_duration = t.duration;
param = icalproperty_get_first_parameter (alarm->trigger, ICAL_RELATED_PARAMETER);
if (param) {
icalparameter_related rel;
rel = icalparameter_get_related (param);
switch (rel) {
case ICAL_RELATED_START:
trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START;
break;
case ICAL_RELATED_END:
trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_END;
break;
default:
g_assert_not_reached ();
}
} else
trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START;
} else {
trigger->u.abs_time = t.time;
trigger->type = E_CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE;
}
}
/**
* e_cal_component_alarm_set_trigger:
* @alarm: An alarm.
* @trigger: Trigger time structure.
*
* Sets the trigger time of an alarm.
**/
void
e_cal_component_alarm_set_trigger (ECalComponentAlarm *alarm, ECalComponentAlarmTrigger trigger)
{
struct icaltriggertype t;
icalparameter *param;
icalparameter_value value_type;
icalparameter_related related;
g_return_if_fail (alarm != NULL);
g_return_if_fail (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_NONE);
g_assert (alarm->icalcomp != NULL);
/* Delete old trigger */
if (alarm->trigger) {
icalcomponent_remove_property (alarm->icalcomp, alarm->trigger);
icalproperty_free (alarm->trigger);
alarm->trigger = NULL;
}
/* Set the value */
related = ICAL_RELATED_START; /* Keep GCC happy */
t.time = icaltime_null_time ();
t.duration = icaldurationtype_null_duration ();
switch (trigger.type) {
case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START:
t.duration = trigger.u.rel_duration;
value_type = ICAL_VALUE_DURATION;
related = ICAL_RELATED_START;
break;
case E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_END:
t.duration = trigger.u.rel_duration;
value_type = ICAL_VALUE_DURATION;
related = ICAL_RELATED_END;
break;
case E_CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE:
t.time = trigger.u.abs_time;
value_type = ICAL_VALUE_DATETIME;
break;
default:
g_assert_not_reached ();
return;
}
alarm->trigger = icalproperty_new_trigger (t);
icalcomponent_add_property (alarm->icalcomp, alarm->trigger);
/* Value parameters */
param = icalproperty_get_first_parameter (alarm->trigger, ICAL_VALUE_PARAMETER);
if (param)
icalparameter_set_value (param, value_type);
else {
param = icalparameter_new_value (value_type);
icalproperty_add_parameter (alarm->trigger, param);
}
/* Related parameter */
if (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_ABSOLUTE) {
param = icalproperty_get_first_parameter (alarm->trigger, ICAL_RELATED_PARAMETER);
if (param)
icalparameter_set_related (param, related);
else {
param = icalparameter_new_related (related);
icalproperty_add_parameter (alarm->trigger, param);
}
}
}
/**
* e_cal_component_alarm_set_attendee_list:
* @alarm: An alarm.
* @attendee_list: Return value for the list of attendees.
*
* Gets the list of attendees associated with an alarm.
*/
void
e_cal_component_alarm_get_attendee_list (ECalComponentAlarm *alarm, GSList **attendee_list)
{
g_return_if_fail (alarm != NULL);
get_attendee_list (alarm->attendee_list, attendee_list);
}
/**
* e_cal_component_alarm_set_attendee_list:
* @alarm: An alarm.
* @attendee_list: List of attendees.
*
* Sets the list of attendees for an alarm.
*/
void
e_cal_component_alarm_set_attendee_list (ECalComponentAlarm *alarm, GSList *attendee_list)
{
g_return_if_fail (alarm != NULL);
set_attendee_list (alarm->icalcomp, &alarm->attendee_list, attendee_list);
}
/**
* e_cal_component_alarm_has_attendees:
* @alarm: An alarm.
*
* Queries an alarm to see if it has attendees associated with it.
*
* Return value: TRUE if there are attendees in the alarm, FALSE if not.
*/
gboolean
e_cal_component_alarm_has_attendees (ECalComponentAlarm *alarm)
{
g_return_val_if_fail (alarm != NULL, FALSE);
if (g_slist_length (alarm->attendee_list) > 0)
return TRUE;
return FALSE;
}
/**
* e_cal_component_alarm_get_icalcomponent
* @alarm: An alarm.
*
* Get the icalcomponent associated with the given #ECalComponentAlarm.
*
* Returns: the icalcomponent.
*/
icalcomponent *
e_cal_component_alarm_get_icalcomponent (ECalComponentAlarm *alarm)
{
g_return_val_if_fail (alarm != NULL, NULL);
return alarm->icalcomp;
}
/* Returns TRUE if both strings match, i.e. they are both NULL or the
strings are equal. */
static gboolean
e_cal_component_strings_match (const gchar *string1,
const gchar *string2)
{
if (string1 == NULL || string2 == NULL)
return (string1 == string2) ? TRUE : FALSE;
if (!strcmp (string1, string2))
return TRUE;
return FALSE;
}
/**
* e_cal_component_event_dates_match:
* @comp1: A calendar component object.
* @comp2: A calendar component object.
*
* Checks if the DTSTART and DTEND properties of the 2 components match.
* Note that the events may have different recurrence properties which are not
* taken into account here.
*
* Returns: TRUE if the DTSTART and DTEND properties of the 2 components match.
**/
gboolean
e_cal_component_event_dates_match (ECalComponent *comp1,
ECalComponent *comp2)
{
ECalComponentDateTime comp1_dtstart, comp1_dtend;
ECalComponentDateTime comp2_dtstart, comp2_dtend;
gboolean retval = TRUE;
e_cal_component_get_dtstart (comp1, &comp1_dtstart);
e_cal_component_get_dtend (comp1, &comp1_dtend);
e_cal_component_get_dtstart (comp2, &comp2_dtstart);
e_cal_component_get_dtend (comp2, &comp2_dtend);
/* If either value is NULL they must both be NULL to match. */
if (comp1_dtstart.value == NULL || comp2_dtstart.value == NULL) {
if (comp1_dtstart.value != comp2_dtstart.value) {
retval = FALSE;
goto out;
}
} else {
if (icaltime_compare (*comp1_dtstart.value,
*comp2_dtstart.value)) {
retval = FALSE;
goto out;
}
}
if (comp1_dtend.value == NULL || comp2_dtend.value == NULL) {
if (comp1_dtend.value != comp2_dtend.value) {
retval = FALSE;
goto out;
}
} else {
if (icaltime_compare (*comp1_dtend.value,
*comp2_dtend.value)) {
retval = FALSE;
goto out;
}
}
/* Now check the timezones. */
if (!e_cal_component_strings_match (comp1_dtstart.tzid,
comp2_dtstart.tzid)) {
retval = FALSE;
goto out;
}
if (!e_cal_component_strings_match (comp1_dtend.tzid,
comp2_dtend.tzid)) {
retval = FALSE;
}
out:
e_cal_component_free_datetime (&comp1_dtstart);
e_cal_component_free_datetime (&comp1_dtend);
e_cal_component_free_datetime (&comp2_dtstart);
e_cal_component_free_datetime (&comp2_dtend);
return retval;
}
|