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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org 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 version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <sfx2/filedlghelper.hxx>
#include <sal/types.h>
#include <com/sun/star/lang/XInitialization.hpp>
#include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
#include <com/sun/star/ui/dialogs/FilePreviewImageFormats.hpp>
#include <com/sun/star/ui/dialogs/ControlActions.hpp>
#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
#include <com/sun/star/ui/dialogs/XControlInformation.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
#include <com/sun/star/ui/dialogs/XFilePickerNotifier.hpp>
#include <com/sun/star/ui/dialogs/XFilePreview.hpp>
#include <com/sun/star/ui/dialogs/XFilterManager.hpp>
#include <com/sun/star/ui/dialogs/XFilterGroupManager.hpp>
#include <com/sun/star/ui/dialogs/XFolderPicker.hpp>
#include <com/sun/star/ui/dialogs/XFilePicker2.hpp>
#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/container/XEnumeration.hpp>
#include <com/sun/star/container/XContainerQuery.hpp>
#include <com/sun/star/task/XInteractionRequest.hpp>
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
#include <comphelper/processfactory.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <comphelper/stillreadwriteinteraction.hxx>
#include <comphelper/string.hxx>
#include <comphelper/types.hxx>
#include <tools/urlobj.hxx>
#include <vcl/help.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <unotools/ucbhelper.hxx>
#include <unotools/localfilehelper.hxx>
#include <osl/mutex.hxx>
#include <osl/security.hxx>
#include <osl/thread.hxx>
#include <vcl/cvtgrf.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/mnemonic.hxx>
#include <unotools/pathoptions.hxx>
#include <unotools/securityoptions.hxx>
#include <svl/itemset.hxx>
#include <svl/eitem.hxx>
#include <svl/intitem.hxx>
#include <svl/stritem.hxx>
#include <svtools/filter.hxx>
#include <unotools/viewoptions.hxx>
#include <unotools/moduleoptions.hxx>
#include <svtools/helpid.hrc>
#include <comphelper/docpasswordrequest.hxx>
#include <comphelper/docpasswordhelper.hxx>
#include <ucbhelper/content.hxx>
#include <ucbhelper/commandenvironment.hxx>
#include <comphelper/storagehelper.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <sfx2/app.hxx>
#include <sfx2/frame.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/docfac.hxx>
#include "openflag.hxx"
#include <sfx2/passwd.hxx>
#include "sfx2/sfxresid.hxx"
#include <sfx2/sfxsids.hrc>
#include "filedlghelper.hrc"
#include "filtergrouping.hxx"
#include <sfx2/request.hxx>
#include "filedlgimpl.hxx"
#include <helpid.hrc>
#include <sfxlocal.hrc>
#include <rtl/strbuf.hxx>
#ifdef UNX
#include <sys/stat.h>
#endif
//-----------------------------------------------------------------------------
using namespace ::com::sun::star;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::ui::dialogs;
using namespace ::com::sun::star::ui::dialogs::TemplateDescription;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
using namespace ::rtl;
using namespace ::cppu;
//-----------------------------------------------------------------------------
#define IODLG_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Save"))
#define IMPGRF_CONFIGNAME String(DEFINE_CONST_UNICODE("FilePicker_Graph"))
#define USERITEM_NAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "UserItem" ))
//-----------------------------------------------------------------------------
namespace sfx2
{
const OUString* GetLastFilterConfigId( FileDialogHelper::Context _eContext )
{
static const OUString aSD_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SdExportLastFilter" ) );
static const OUString aSI_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SiExportLastFilter" ) );
static const OUString aSW_EXPORT_IDENTIFIER( RTL_CONSTASCII_USTRINGPARAM( "SwExportLastFilter" ) );
const OUString* pRet = NULL;
switch( _eContext )
{
case FileDialogHelper::SD_EXPORT: pRet = &aSD_EXPORT_IDENTIFIER; break;
case FileDialogHelper::SI_EXPORT: pRet = &aSI_EXPORT_IDENTIFIER; break;
case FileDialogHelper::SW_EXPORT: pRet = &aSW_EXPORT_IDENTIFIER; break;
default: break;
}
return pRet;
}
String EncodeSpaces_Impl( const String& rSource );
String DecodeSpaces_Impl( const String& rSource );
// ------------------------------------------------------------------------
// ----------- FileDialogHelper_Impl ---------------------------
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// XFilePickerListener Methods
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper_Impl::fileSelectionChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
{
SolarMutexGuard aGuard;
mpAntiImpl->FileSelectionChanged( aEvent );
}
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper_Impl::directoryChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
{
SolarMutexGuard aGuard;
mpAntiImpl->DirectoryChanged( aEvent );
}
// ------------------------------------------------------------------------
OUString SAL_CALL FileDialogHelper_Impl::helpRequested( const FilePickerEvent& aEvent ) throw ( RuntimeException )
{
SolarMutexGuard aGuard;
return mpAntiImpl->HelpRequested( aEvent );
}
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper_Impl::controlStateChanged( const FilePickerEvent& aEvent ) throw ( RuntimeException )
{
SolarMutexGuard aGuard;
mpAntiImpl->ControlStateChanged( aEvent );
}
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper_Impl::dialogSizeChanged() throw ( RuntimeException )
{
SolarMutexGuard aGuard;
mpAntiImpl->DialogSizeChanged();
}
// ------------------------------------------------------------------------
// XDialogClosedListener Methods
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper_Impl::dialogClosed( const DialogClosedEvent& _rEvent ) throw ( RuntimeException )
{
SolarMutexGuard aGuard;
mpAntiImpl->DialogClosed( _rEvent );
postExecute( _rEvent.DialogResult );
}
// ------------------------------------------------------------------------
// handle XFilePickerListener events
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::handleFileSelectionChanged( const FilePickerEvent& )
{
if ( mbHasVersions )
updateVersions();
if ( mbShowPreview )
maPreViewTimer.Start();
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::handleDirectoryChanged( const FilePickerEvent& )
{
if ( mbShowPreview )
TimeOutHdl_Impl( NULL );
}
// ------------------------------------------------------------------------
OUString FileDialogHelper_Impl::handleHelpRequested( const FilePickerEvent& aEvent )
{
//!!! todo: cache the help strings (here or TRA)
rtl::OString sHelpId;
// mapping from element id -> help id
switch ( aEvent.ElementId )
{
case ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION :
sHelpId = HID_FILESAVE_AUTOEXTENSION;
break;
case ExtendedFilePickerElementIds::CHECKBOX_PASSWORD :
sHelpId = HID_FILESAVE_SAVEWITHPASSWORD;
break;
case ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS :
sHelpId = HID_FILESAVE_CUSTOMIZEFILTER;
break;
case ExtendedFilePickerElementIds::CHECKBOX_READONLY :
sHelpId = HID_FILEOPEN_READONLY;
break;
case ExtendedFilePickerElementIds::CHECKBOX_LINK :
sHelpId = HID_FILEDLG_LINK_CB;
break;
case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW :
sHelpId = HID_FILEDLG_PREVIEW_CB;
break;
case ExtendedFilePickerElementIds::PUSHBUTTON_PLAY :
sHelpId = HID_FILESAVE_DOPLAY;
break;
case ExtendedFilePickerElementIds::LISTBOX_VERSION_LABEL :
case ExtendedFilePickerElementIds::LISTBOX_VERSION :
sHelpId = HID_FILEOPEN_VERSION;
break;
case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE_LABEL :
case ExtendedFilePickerElementIds::LISTBOX_TEMPLATE :
sHelpId = HID_FILESAVE_TEMPLATE;
break;
case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE_LABEL :
case ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE :
sHelpId = HID_FILEOPEN_IMAGE_TEMPLATE;
break;
case ExtendedFilePickerElementIds::CHECKBOX_SELECTION :
sHelpId = HID_FILESAVE_SELECTION;
break;
default:
DBG_ERRORFILE( "invalid element id" );
}
OUString aHelpText;
Help* pHelp = Application::GetHelp();
if ( pHelp )
aHelpText = String( pHelp->GetHelpText( rtl::OStringToOUString(sHelpId, RTL_TEXTENCODING_UTF8), NULL ) );
return aHelpText;
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::handleControlStateChanged( const FilePickerEvent& aEvent )
{
switch ( aEvent.ElementId )
{
case CommonFilePickerElementIds::LISTBOX_FILTER:
updateFilterOptionsBox();
enablePasswordBox( sal_False );
updateSelectionBox();
// only use it for export and with our own dialog
if ( mbExport && !mbSystemPicker )
updateExportButton();
break;
case ExtendedFilePickerElementIds::CHECKBOX_PREVIEW:
updatePreviewState();
break;
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::handleDialogSizeChanged()
{
if ( mbShowPreview )
TimeOutHdl_Impl( NULL );
}
// ------------------------------------------------------------------------
// XEventListener Methods
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper_Impl::disposing( const EventObject& ) throw ( RuntimeException )
{
SolarMutexGuard aGuard;
dispose();
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::dispose()
{
if ( mxFileDlg.is() )
{
// remove the event listener
uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
if ( xNotifier.is() )
xNotifier->removeFilePickerListener( this );
::comphelper::disposeComponent( mxFileDlg );
mxFileDlg.clear();
}
}
// ------------------------------------------------------------------------
String FileDialogHelper_Impl::getCurrentFilterUIName() const
{
String aFilterName;
uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
if( xFltMgr.is() )
{
aFilterName = xFltMgr->getCurrentFilter();
if ( aFilterName.Len() && isShowFilterExtensionEnabled() )
aFilterName = getFilterName( aFilterName );
}
return aFilterName;
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::LoadLastUsedFilter( const OUString& _rContextIdentifier )
{
SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
if( aDlgOpt.Exists() )
{
OUString aLastFilter;
if( aDlgOpt.GetUserItem( _rContextIdentifier ) >>= aLastFilter )
setFilter( aLastFilter );
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::SaveLastUsedFilter( const OUString& _rContextIdentifier )
{
SvtViewOptions( E_DIALOG, IODLG_CONFIGNAME ).SetUserItem( _rContextIdentifier,
makeAny( getFilterWithExtension( getFilter() ) ) );
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::SaveLastUsedFilter( void )
{
const OUString* pConfigId = GetLastFilterConfigId( meContext );
if( pConfigId )
SaveLastUsedFilter( *pConfigId );
}
// ------------------------------------------------------------------------
const SfxFilter* FileDialogHelper_Impl::getCurentSfxFilter()
{
String aFilterName = getCurrentFilterUIName();
const SfxFilter* pFilter = NULL;
if ( mpMatcher && aFilterName.Len() )
pFilter = mpMatcher->GetFilter4UIName( aFilterName, m_nMustFlags, m_nDontFlags );
return pFilter;
}
// ------------------------------------------------------------------------
sal_Bool FileDialogHelper_Impl::updateExtendedControl( sal_Int16 _nExtendedControlId, sal_Bool _bEnable )
{
sal_Bool bIsEnabled = sal_False;
uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
if ( xCtrlAccess.is() )
{
try
{
xCtrlAccess->enableControl( _nExtendedControlId, _bEnable );
bIsEnabled = _bEnable;
}
catch( const IllegalArgumentException& )
{
OSL_FAIL( "FileDialogHelper_Impl::updateExtendedControl: caught an exception!" );
}
}
return bIsEnabled;
}
// ------------------------------------------------------------------------
sal_Bool FileDialogHelper_Impl::CheckFilterOptionsCapability( const SfxFilter* _pFilter )
{
sal_Bool bResult = sal_False;
if( mxFilterCFG.is() && _pFilter )
{
try {
Sequence < PropertyValue > aProps;
Any aAny = mxFilterCFG->getByName( _pFilter->GetName() );
if ( aAny >>= aProps )
{
::rtl::OUString aServiceName;
sal_Int32 nPropertyCount = aProps.getLength();
for( sal_Int32 nProperty=0; nProperty < nPropertyCount; ++nProperty )
{
if( aProps[nProperty].Name.equals( DEFINE_CONST_OUSTRING( "UIComponent") ) )
{
aProps[nProperty].Value >>= aServiceName;
if( aServiceName.getLength() )
bResult = sal_True;
}
}
}
}
catch( const Exception& )
{
}
}
return bResult;
}
// ------------------------------------------------------------------------
sal_Bool FileDialogHelper_Impl::isInOpenMode() const
{
sal_Bool bRet = sal_False;
switch ( m_nDialogType )
{
case FILEOPEN_SIMPLE:
case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
case FILEOPEN_PLAY:
case FILEOPEN_READONLY_VERSION:
case FILEOPEN_LINK_PREVIEW:
bRet = sal_True;
}
return bRet;
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::updateFilterOptionsBox()
{
if ( !m_bHaveFilterOptions )
return;
updateExtendedControl(
ExtendedFilePickerElementIds::CHECKBOX_FILTEROPTIONS,
CheckFilterOptionsCapability( getCurentSfxFilter() )
);
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::updateExportButton()
{
uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
if ( xCtrlAccess.is() )
{
OUString sEllipses( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
OUString sOldLabel( xCtrlAccess->getLabel( CommonFilePickerElementIds::PUSHBUTTON_OK ) );
// initialize button label; we need the label with the mnemonic char
if ( !maButtonLabel.getLength() || maButtonLabel.indexOf( MNEMONIC_CHAR ) == -1 )
{
// cut the ellipses, if necessary
sal_Int32 nIndex = sOldLabel.indexOf( sEllipses );
if ( -1 == nIndex )
nIndex = sOldLabel.getLength();
maButtonLabel = sOldLabel.copy( 0, nIndex );
}
OUString sLabel = maButtonLabel;
// filter with options -> append ellipses on export button label
if ( CheckFilterOptionsCapability( getCurentSfxFilter() ) )
sLabel += OUString( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
if ( sOldLabel != sLabel )
{
try
{
xCtrlAccess->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK, sLabel );
}
catch( const IllegalArgumentException& )
{
DBG_ERRORFILE( "FileDialogHelper_Impl::updateExportButton: caught an exception!" );
}
}
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::updateSelectionBox()
{
if ( !mbHasSelectionBox )
return;
// Does the selection box exist?
sal_Bool bSelectionBoxFound = sal_False;
uno::Reference< XControlInformation > xCtrlInfo( mxFileDlg, UNO_QUERY );
if ( xCtrlInfo.is() )
{
Sequence< ::rtl::OUString > aCtrlList = xCtrlInfo->getSupportedControls();
sal_uInt32 nCount = aCtrlList.getLength();
for ( sal_uInt32 nCtrl = 0; nCtrl < nCount; ++nCtrl )
if ( aCtrlList[ nCtrl ].equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("SelectionBox")) )
{
bSelectionBoxFound = sal_False;
break;
}
}
if ( bSelectionBoxFound )
{
const SfxFilter* pFilter = getCurentSfxFilter();
mbSelectionFltrEnabled = updateExtendedControl(
ExtendedFilePickerElementIds::CHECKBOX_SELECTION,
( mbSelectionEnabled && pFilter && ( pFilter->GetFilterFlags() & SFX_FILTER_SUPPORTSSELECTION ) != 0 ) );
uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, makeAny( (sal_Bool)mbSelection ) );
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::enablePasswordBox( sal_Bool bInit )
{
if ( ! mbHasPassword )
return;
sal_Bool bWasEnabled = mbIsPwdEnabled;
const SfxFilter* pCurrentFilter = getCurentSfxFilter();
mbIsPwdEnabled = updateExtendedControl(
ExtendedFilePickerElementIds::CHECKBOX_PASSWORD,
pCurrentFilter && ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_ENCRYPTION )
);
if( bInit )
{
// in case of inintialization previous state is not interesting
if( mbIsPwdEnabled )
{
uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
if( mbPwdCheckBoxState )
xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
}
}
else if( !bWasEnabled && mbIsPwdEnabled )
{
uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
if( mbPwdCheckBoxState )
xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_True ) );
}
else if( bWasEnabled && !mbIsPwdEnabled )
{
// remember user settings until checkbox is enabled
uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
sal_Bool bPassWord = sal_False;
mbPwdCheckBoxState = ( aValue >>= bPassWord ) && bPassWord;
xCtrlAccess->setValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0, makeAny( sal_False ) );
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::updatePreviewState( sal_Bool _bUpdatePreviewWindow )
{
if ( mbHasPreview )
{
uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
// check, wether or not we have to display a preview
if ( xCtrlAccess.is() )
{
try
{
Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
sal_Bool bShowPreview = sal_False;
if ( aValue >>= bShowPreview )
{
mbShowPreview = bShowPreview;
// setShowState has currently no effect for the
// OpenOffice FilePicker (see svtools/source/filepicker/iodlg.cxx)
uno::Reference< XFilePreview > xFilePreview( mxFileDlg, UNO_QUERY );
if ( xFilePreview.is() )
xFilePreview->setShowState( mbShowPreview );
if ( _bUpdatePreviewWindow )
TimeOutHdl_Impl( NULL );
}
}
catch( const Exception& )
{
DBG_ERRORFILE( "FileDialogHelper_Impl::updatePreviewState: caught an exception!" );
}
}
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::updateVersions()
{
Sequence < OUString > aEntries;
Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
if ( aPathSeq.getLength() == 1 )
{
INetURLObject aObj( aPathSeq[0] );
if ( ( aObj.GetProtocol() == INET_PROT_FILE ) &&
( utl::UCBContentHelper::IsDocument( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) ) )
{
try
{
uno::Reference< embed::XStorage > xStorage = ::comphelper::OStorageHelper::GetStorageFromURL(
aObj.GetMainURL( INetURLObject::NO_DECODE ),
embed::ElementModes::READ );
DBG_ASSERT( xStorage.is(), "The method must return the storage or throw an exception!" );
if ( !xStorage.is() )
throw uno::RuntimeException();
uno::Sequence < util::RevisionTag > xVersions = SfxMedium::GetVersionList( xStorage );
aEntries.realloc( xVersions.getLength() + 1 );
aEntries[0] = OUString( String ( SfxResId( STR_SFX_FILEDLG_ACTUALVERSION ) ) );
for ( sal_Int32 i=0; i<xVersions.getLength(); i++ )
aEntries[ i + 1 ] = xVersions[i].Identifier;
}
catch( const uno::Exception& )
{
}
}
}
uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
Any aValue;
try
{
xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
ControlActions::DELETE_ITEMS, aValue );
}
catch( const IllegalArgumentException& ){}
sal_Int32 nCount = aEntries.getLength();
if ( nCount )
{
try
{
aValue <<= aEntries;
xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
ControlActions::ADD_ITEMS, aValue );
Any aPos;
aPos <<= (sal_Int32) 0;
xDlg->setValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
ControlActions::SET_SELECT_ITEM, aPos );
}
catch( const IllegalArgumentException& ){}
}
}
// -----------------------------------------------------------------------
IMPL_LINK( FileDialogHelper_Impl, TimeOutHdl_Impl, Timer*, EMPTYARG )
{
if ( !mbHasPreview )
return 0;
maGraphic.Clear();
Any aAny;
uno::Reference < XFilePreview > xFilePicker( mxFileDlg, UNO_QUERY );
if ( ! xFilePicker.is() )
return 0;
Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
if ( mbShowPreview && ( aPathSeq.getLength() == 1 ) )
{
OUString aURL = aPathSeq[0];
if ( ERRCODE_NONE == getGraphic( aURL, maGraphic ) )
{
// changed the code slightly;
// before: the bitmap was scaled and
// surrounded a white frame
// now: the bitmap will only be scaled
// and the filepicker implementation
// is responsible for placing it at its
// proper position and painting a frame
Bitmap aBmp = maGraphic.GetBitmap();
// scale the bitmap to the correct size
sal_Int32 nOutWidth = xFilePicker->getAvailableWidth();
sal_Int32 nOutHeight = xFilePicker->getAvailableHeight();
sal_Int32 nBmpWidth = aBmp.GetSizePixel().Width();
sal_Int32 nBmpHeight = aBmp.GetSizePixel().Height();
double nXRatio = (double) nOutWidth / nBmpWidth;
double nYRatio = (double) nOutHeight / nBmpHeight;
if ( nXRatio < nYRatio )
aBmp.Scale( nXRatio, nXRatio );
else
aBmp.Scale( nYRatio, nYRatio );
// Convert to true color, to allow CopyPixel
aBmp.Convert( BMP_CONVERSION_24BIT );
// and copy it into the Any
SvMemoryStream aData;
aData << aBmp;
const Sequence < sal_Int8 > aBuffer(
static_cast< const sal_Int8* >(aData.GetData()),
aData.GetEndOfData() );
aAny <<= aBuffer;
}
}
try
{
SolarMutexReleaser aReleaseForCallback;
// clear the preview window
xFilePicker->setImage( FilePreviewImageFormats::BITMAP, aAny );
}
catch( const IllegalArgumentException& )
{
}
return 0;
}
// ------------------------------------------------------------------------
ErrCode FileDialogHelper_Impl::getGraphic( const OUString& rURL,
Graphic& rGraphic ) const
{
if ( utl::UCBContentHelper::IsFolder( rURL ) )
return ERRCODE_IO_NOTAFILE;
if ( !mpGraphicFilter )
return ERRCODE_IO_NOTSUPPORTED;
// select graphic filter from dialog filter selection
OUString aCurFilter( getFilter() );
sal_uInt16 nFilter = aCurFilter.getLength() && mpGraphicFilter->GetImportFormatCount()
? mpGraphicFilter->GetImportFormatNumber( aCurFilter )
: GRFILTER_FORMAT_DONTKNOW;
INetURLObject aURLObj( rURL );
if ( aURLObj.HasError() || INET_PROT_NOT_VALID == aURLObj.GetProtocol() )
{
aURLObj.SetSmartProtocol( INET_PROT_FILE );
aURLObj.SetSmartURL( rURL );
}
ErrCode nRet = ERRCODE_NONE;
sal_uInt32 nFilterImportFlags = GRFILTER_I_FLAGS_SET_LOGSIZE_FOR_JPEG;
// non-local?
if ( INET_PROT_FILE != aURLObj.GetProtocol() )
{
SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( rURL, STREAM_READ );
if( pStream )
nRet = mpGraphicFilter->ImportGraphic( rGraphic, rURL, *pStream, nFilter, NULL, nFilterImportFlags );
else
nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
delete pStream;
}
else
{
nRet = mpGraphicFilter->ImportGraphic( rGraphic, aURLObj, nFilter, NULL, nFilterImportFlags );
}
return nRet;
}
// ------------------------------------------------------------------------
ErrCode FileDialogHelper_Impl::getGraphic( Graphic& rGraphic ) const
{
ErrCode nRet = ERRCODE_NONE;
if ( ! maGraphic )
{
OUString aPath;;
Sequence < OUString > aPathSeq = mxFileDlg->getFiles();
if ( aPathSeq.getLength() == 1 )
{
aPath = aPathSeq[0];
}
if ( aPath.getLength() )
nRet = getGraphic( aPath, rGraphic );
else
nRet = ERRCODE_IO_GENERAL;
}
else
rGraphic = maGraphic;
return nRet;
}
// ------------------------------------------------------------------------
static bool lcl_isSystemFilePicker( const uno::Reference< XFilePicker >& _rxFP )
{
try
{
uno::Reference< XServiceInfo > xSI( _rxFP, UNO_QUERY );
if ( !xSI.is() )
return true;
return xSI->supportsService( DEFINE_CONST_OUSTRING( "com.sun.star.ui.dialogs.SystemFilePicker" ) );
}
catch( const Exception& )
{
}
return false;
}
enum open_or_save_t {OPEN, SAVE, UNDEFINED};
static open_or_save_t lcl_OpenOrSave(sal_Int16 const nDialogType)
{
switch (nDialogType)
{
case FILEOPEN_SIMPLE:
case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
case FILEOPEN_PLAY:
case FILEOPEN_READONLY_VERSION:
case FILEOPEN_LINK_PREVIEW:
return OPEN;
case FILESAVE_SIMPLE:
case FILESAVE_AUTOEXTENSION_PASSWORD:
case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
case FILESAVE_AUTOEXTENSION_SELECTION:
case FILESAVE_AUTOEXTENSION_TEMPLATE:
case FILESAVE_AUTOEXTENSION:
return SAVE;
default:
assert(false); // invalid dialog type
}
return UNDEFINED;
}
// ------------------------------------------------------------------------
// ----------- FileDialogHelper_Impl ---------------------------
// ------------------------------------------------------------------------
FileDialogHelper_Impl::FileDialogHelper_Impl(
FileDialogHelper* _pAntiImpl,
sal_Int16 nDialogType,
sal_Int64 nFlags,
sal_Int16 nDialog,
Window* _pPreferredParentWindow,
const String& sStandardDir,
const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList
)
:m_nDialogType ( nDialogType )
,meContext ( FileDialogHelper::UNKNOWN_CONTEXT )
{
const char* pServiceName=0;
if ( nDialog == SFX2_IMPL_DIALOG_SYSTEM )
pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
else if ( nDialog == SFX2_IMPL_DIALOG_OOO )
pServiceName = FILE_OPEN_SERVICE_NAME_OOO;
else
pServiceName = FILE_OPEN_SERVICE_NAME;
OUString aService = ::rtl::OUString::createFromAscii( pServiceName );
uno::Reference< XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
// create the file open dialog
// the flags can be SFXWB_INSERT or SFXWB_MULTISELECTION
mpPreferredParentWindow = _pPreferredParentWindow;
mpAntiImpl = _pAntiImpl;
mnError = ERRCODE_NONE;
mbHasAutoExt = sal_False;
mbHasPassword = sal_False;
m_bHaveFilterOptions = sal_False;
mbIsPwdEnabled = sal_True;
mbHasVersions = sal_False;
mbHasPreview = sal_False;
mbShowPreview = sal_False;
mbAddGraphicFilter = SFXWB_GRAPHIC == (nFlags & SFXWB_GRAPHIC);
mbDeleteMatcher = sal_False;
mbInsert = SFXWB_INSERT == ( nFlags & SFXWB_INSERT );
mbExport = SFXWB_EXPORT == ( nFlags & SFXWB_EXPORT );
mbIsSaveDlg = sal_False;
mbPwdCheckBoxState = sal_False;
mbSelection = sal_False;
mbSelectionEnabled = sal_True;
mbHasSelectionBox = sal_False;
mbSelectionFltrEnabled = sal_False;
// default settings
m_nDontFlags = SFX_FILTER_INTERNAL | SFX_FILTER_NOTINFILEDLG | SFX_FILTER_NOTINSTALLED;
if (OPEN == lcl_OpenOrSave(m_nDialogType))
m_nMustFlags = SFX_FILTER_IMPORT;
else
m_nMustFlags = SFX_FILTER_EXPORT;
mpMatcher = NULL;
mpGraphicFilter = NULL;
mnPostUserEventId = 0;
// create the picker component
mxFileDlg = mxFileDlg.query( xFactory->createInstance( aService ) );
mbSystemPicker = lcl_isSystemFilePicker( mxFileDlg );
uno::Reference< XFilePickerNotifier > xNotifier( mxFileDlg, UNO_QUERY );
uno::Reference< XInitialization > xInit( mxFileDlg, UNO_QUERY );
if ( ! mxFileDlg.is() || ! xNotifier.is() )
{
mnError = ERRCODE_ABORT;
return;
}
if ( xInit.is() )
{
sal_Int16 nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
switch ( m_nDialogType )
{
case FILEOPEN_SIMPLE:
nTemplateDescription = TemplateDescription::FILEOPEN_SIMPLE;
break;
case FILESAVE_SIMPLE:
nTemplateDescription = TemplateDescription::FILESAVE_SIMPLE;
mbIsSaveDlg = sal_True;
break;
case FILESAVE_AUTOEXTENSION_PASSWORD:
nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD;
mbHasPassword = sal_True;
mbHasAutoExt = sal_True;
mbIsSaveDlg = sal_True;
break;
case FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS:
nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD_FILTEROPTIONS;
mbHasPassword = sal_True;
m_bHaveFilterOptions = sal_True;
if( xFactory.is() )
{
mxFilterCFG = uno::Reference< XNameAccess >(
xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
UNO_QUERY );
}
mbHasAutoExt = sal_True;
mbIsSaveDlg = sal_True;
break;
case FILESAVE_AUTOEXTENSION_SELECTION:
nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_SELECTION;
mbHasAutoExt = sal_True;
mbIsSaveDlg = sal_True;
mbHasSelectionBox = sal_True;
if ( mbExport && !mxFilterCFG.is() && xFactory.is() )
{
mxFilterCFG = uno::Reference< XNameAccess >(
xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.document.FilterFactory" ) ),
UNO_QUERY );
}
break;
case FILESAVE_AUTOEXTENSION_TEMPLATE:
nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION_TEMPLATE;
mbHasAutoExt = sal_True;
mbIsSaveDlg = sal_True;
break;
case FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE:
nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE;
mbHasPreview = sal_True;
// aPreviewTimer
maPreViewTimer.SetTimeout( 500 );
maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
break;
case FILEOPEN_PLAY:
nTemplateDescription = TemplateDescription::FILEOPEN_PLAY;
break;
case FILEOPEN_READONLY_VERSION:
nTemplateDescription = TemplateDescription::FILEOPEN_READONLY_VERSION;
mbHasVersions = sal_True;
break;
case FILEOPEN_LINK_PREVIEW:
nTemplateDescription = TemplateDescription::FILEOPEN_LINK_PREVIEW;
mbHasPreview = sal_True;
// aPreviewTimer
maPreViewTimer.SetTimeout( 500 );
maPreViewTimer.SetTimeoutHdl( LINK( this, FileDialogHelper_Impl, TimeOutHdl_Impl ) );
break;
case FILESAVE_AUTOEXTENSION:
nTemplateDescription = TemplateDescription::FILESAVE_AUTOEXTENSION;
mbHasAutoExt = sal_True;
mbIsSaveDlg = sal_True;
break;
default:
DBG_ERRORFILE( "FileDialogHelper::ctor with unknown type" );
break;
}
Sequence < Any > aInitArguments( !mpPreferredParentWindow ? 3 : 4 );
// This is a hack. We currently know that the internal file picker implementation
// supports the extended arguments as specified below.
// TODO:
// a) adjust the service description so that it includes the TemplateDescription and ParentWindow args
// b) adjust the implementation of the system file picker to that it recognizes it
if ( mbSystemPicker )
{
aInitArguments[0] <<= nTemplateDescription;
}
else
{
aInitArguments[0] <<= NamedValue(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TemplateDescription" ) ),
makeAny( nTemplateDescription )
);
::rtl::OUString sStandardDirTemp = ::rtl::OUString( sStandardDir );
aInitArguments[1] <<= NamedValue(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "StandardDir" ) ),
makeAny( sStandardDirTemp )
);
aInitArguments[2] <<= NamedValue(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BlackList" ) ),
makeAny( rBlackList )
);
if ( mpPreferredParentWindow )
aInitArguments[3] <<= NamedValue(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParentWindow" ) ),
makeAny( VCLUnoHelper::GetInterface( mpPreferredParentWindow ) )
);
}
try
{
xInit->initialize( aInitArguments );
}
catch( const Exception& )
{
OSL_FAIL( "FileDialogHelper_Impl::FileDialogHelper_Impl: could not initialize the picker!" );
}
}
// set multiselection mode
if ( nFlags & SFXWB_MULTISELECTION )
mxFileDlg->setMultiSelectionMode( sal_True );
if (mbAddGraphicFilter) // generate graphic filter only on demand
{
addGraphicFilter();
}
// Export dialog
if ( mbExport )
{
mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_EXPORT ) ) ) );
try {
com::sun::star::uno::Reference < XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY_THROW );
xCtrlAccess->enableControl( ExtendedFilePickerElementIds::LISTBOX_FILTER_SELECTOR, sal_True );
}
catch( const Exception & ) { }
}
// the "insert file" dialog needs another title
if ( mbInsert )
{
mxFileDlg->setTitle( OUString( String( SfxResId( STR_SFX_EXPLORERFILE_INSERT ) ) ) );
uno::Reference < XFilePickerControlAccess > xExtDlg( mxFileDlg, UNO_QUERY );
if ( xExtDlg.is() )
{
try
{
xExtDlg->setLabel( CommonFilePickerElementIds::PUSHBUTTON_OK,
OUString( String( SfxResId( STR_SFX_EXPLORERFILE_BUTTONINSERT ) ) ) );
}
catch( const IllegalArgumentException& ){}
}
}
// add the event listener
xNotifier->addFilePickerListener( this );
}
// ------------------------------------------------------------------------
FileDialogHelper_Impl::~FileDialogHelper_Impl()
{
// Remove user event if we haven't received it yet
if ( mnPostUserEventId )
Application::RemoveUserEvent( mnPostUserEventId );
mnPostUserEventId = 0;
delete mpGraphicFilter;
if ( mbDeleteMatcher )
delete mpMatcher;
maPreViewTimer.SetTimeoutHdl( Link() );
::comphelper::disposeComponent( mxFileDlg );
}
#define nMagic -1
class PickerThread_Impl : public ::osl::Thread
{
uno::Reference < XFilePicker > mxPicker;
::osl::Mutex maMutex;
virtual void SAL_CALL run();
sal_Int16 mnRet;
public:
PickerThread_Impl( const uno::Reference < XFilePicker >& rPicker )
: mxPicker( rPicker ), mnRet(nMagic) {}
sal_Int16 GetReturnValue()
{ ::osl::MutexGuard aGuard( maMutex ); return mnRet; }
void SetReturnValue( sal_Int16 aRetValue )
{ ::osl::MutexGuard aGuard( maMutex ); mnRet = aRetValue; }
};
void SAL_CALL PickerThread_Impl::run()
{
try
{
sal_Int16 n = mxPicker->execute();
SetReturnValue( n );
}
catch( const RuntimeException& )
{
SetReturnValue( ExecutableDialogResults::CANCEL );
DBG_ERRORFILE( "RuntimeException caught" );
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::setControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId )
{
DBG_ASSERT( _pControlId && _pHelpId, "FileDialogHelper_Impl::setControlHelpIds: invalid array pointers!" );
if ( !_pControlId || !_pHelpId )
return;
// forward these ids to the file picker
try
{
const ::rtl::OUString sHelpIdPrefix( RTL_CONSTASCII_USTRINGPARAM( INET_HID_SCHEME ) );
// the ids for the single controls
uno::Reference< XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
if ( xControlAccess.is() )
{
while ( *_pControlId )
{
DBG_ASSERT( INetURLObject( rtl::OStringToOUString( *_pHelpId, RTL_TEXTENCODING_UTF8 ) ).GetProtocol() == INET_PROT_NOT_VALID, "Wrong HelpId!" );
::rtl::OUString sId( sHelpIdPrefix );
sId += ::rtl::OUString( *_pHelpId, strlen( *_pHelpId ), RTL_TEXTENCODING_UTF8 );
xControlAccess->setValue( *_pControlId, ControlActions::SET_HELP_URL, makeAny( sId ) );
++_pControlId; ++_pHelpId;
}
}
}
catch( const Exception& )
{
OSL_FAIL( "FileDialogHelper_Impl::setControlHelpIds: caught an exception while setting the help ids!" );
}
}
// ------------------------------------------------------------------------
IMPL_LINK( FileDialogHelper_Impl, InitControls, void*, NOTINTERESTEDIN )
{
(void)NOTINTERESTEDIN;
mnPostUserEventId = 0;
enablePasswordBox( sal_True );
updateFilterOptionsBox( );
updateSelectionBox( );
return 0L;
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::preExecute()
{
loadConfig( );
setDefaultValues( );
updatePreviewState( sal_False );
implInitializeFileName( );
#if !(defined(MACOSX) && defined(QUARTZ)) && !defined(WNT)
// allow for dialog implementations which need to be executed before they return valid values for
// current filter and such
// On Vista (at least SP1) it's the same as on MacOSX, the modal dialog won't let message pass
// through before it returns from execution
mnPostUserEventId = Application::PostUserEvent( LINK( this, FileDialogHelper_Impl, InitControls ) );
#else
// However, the Mac OS X implementation's pickers run modally in execute and so the event doesn't
// get through in time... so we call the methods directly
enablePasswordBox( sal_True );
updateFilterOptionsBox( );
updateSelectionBox( );
#endif
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::postExecute( sal_Int16 _nResult )
{
if ( ExecutableDialogResults::CANCEL != _nResult )
saveConfig();
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::implInitializeFileName( )
{
if ( maFileName.getLength() )
{
INetURLObject aObj( maPath );
aObj.Append( maFileName );
// in case we're operating as save dialog, and "auto extension" is checked,
// cut the extension from the name
if ( mbIsSaveDlg && mbHasAutoExt )
{
try
{
sal_Bool bAutoExtChecked = sal_False;
uno::Reference < XFilePickerControlAccess > xControlAccess( mxFileDlg, UNO_QUERY );
if ( xControlAccess.is()
&& ( xControlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 )
>>= bAutoExtChecked
)
)
{
if ( bAutoExtChecked )
{ // cut the extension
aObj.removeExtension( );
mxFileDlg->setDefaultName( aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) );
}
}
}
catch( const Exception& )
{
OSL_FAIL( "FileDialogHelper_Impl::implInitializeFileName: could not ask for the auto-extension current-value!" );
}
}
}
}
// ------------------------------------------------------------------------
sal_Int16 FileDialogHelper_Impl::implDoExecute()
{
preExecute();
sal_Int16 nRet = ExecutableDialogResults::CANCEL;
//On MacOSX the native file picker has to run in the primordial thread because of drawing issues
//On Linux the native gtk file picker, when backed by gnome-vfs2, needs to be run in the same
//primordial thread as the ucb gnome-vfs2 provider was initialized in.
{
try
{
#ifdef WNT
if ( mbSystemPicker )
{
SolarMutexReleaser aSolarMutex;
nRet = mxFileDlg->execute();
}
else
#endif
nRet = mxFileDlg->execute();
}
catch( const Exception& )
{
DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
}
}
postExecute( nRet );
return nRet;
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::implStartExecute()
{
DBG_ASSERT( mxFileDlg.is(), "invalid file dialog" );
preExecute();
if ( mbSystemPicker )
{
}
else
{
try
{
uno::Reference< XAsynchronousExecutableDialog > xAsyncDlg( mxFileDlg, UNO_QUERY );
if ( xAsyncDlg.is() )
xAsyncDlg->startExecuteModal( this );
}
catch( const Exception& )
{
DBG_ERRORFILE( "FileDialogHelper_Impl::implDoExecute: caught an exception!" );
}
}
}
// ------------------------------------------------------------------------
void lcl_saveLastURLs(SvStringsDtor*& rpURLList ,
::comphelper::SequenceAsVector< ::rtl::OUString >& lLastURLs )
{
lLastURLs.clear();
sal_uInt16 c = rpURLList->Count();
sal_uInt16 i = 0;
for (i=0; i<c; ++i)
lLastURLs.push_back(*(rpURLList->GetObject(i)));
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::implGetAndCacheFiles(const uno::Reference< XInterface >& xPicker ,
SvStringsDtor*& rpURLList,
const SfxFilter* pFilter )
{
rpURLList = NULL;
rtl::OUString sExtension;
if (pFilter)
{
sExtension = pFilter->GetDefaultExtension ();
sExtension = comphelper::string::remove(sExtension, '*');
sExtension = comphelper::string::remove(sExtension, '.');
}
// a) the new way (optional!)
uno::Reference< XFilePicker2 > xPickNew(xPicker, UNO_QUERY);
if (xPickNew.is())
{
rpURLList = new SvStringsDtor;
Sequence< OUString > lFiles = xPickNew->getSelectedFiles();
::sal_Int32 nFiles = lFiles.getLength();
for (::sal_Int32 i = 0; i < nFiles; i++)
{
String* pURL = new String(lFiles[i]);
rpURLList->Insert( pURL, rpURLList->Count() );
}
}
// b) the olde way ... non optional.
else
{
uno::Reference< XFilePicker > xPickOld(xPicker, UNO_QUERY_THROW);
Sequence< OUString > lFiles = xPickOld->getFiles();
::sal_Int32 nFiles = lFiles.getLength();
if ( nFiles == 1 )
{
rpURLList = new SvStringsDtor;
String* pURL = new String(lFiles[0]);
rpURLList->Insert( pURL, 0 );
}
else
if ( nFiles > 1 )
{
rpURLList = new SvStringsDtor;
INetURLObject aPath( lFiles[0] );
aPath.setFinalSlash();
for (::sal_Int32 i = 1; i < nFiles; i++)
{
if (i == 1)
aPath.Append( lFiles[i] );
else
aPath.setName( lFiles[i] );
String* pURL = new String(aPath.GetMainURL( INetURLObject::NO_DECODE ) );
rpURLList->Insert( pURL, rpURLList->Count() );
}
}
}
lcl_saveLastURLs(rpURLList, mlLastURLs);
}
// ------------------------------------------------------------------------
ErrCode FileDialogHelper_Impl::execute( SvStringsDtor*& rpURLList,
SfxItemSet *& rpSet,
String& rFilter )
{
// rFilter is a pure output parameter, it shouldn't be used for anything else
// changing this would surely break code
// rpSet is in/out parameter, usually just a media-descriptor that can be changed by dialog
uno::Reference< XFilePickerControlAccess > xCtrlAccess( mxFileDlg, UNO_QUERY );
// retrieves parameters from rpSet
// for now only Password is used
if ( rpSet )
{
// check password checkbox if the document had password before
if( mbHasPassword )
{
SFX_ITEMSET_ARG( rpSet, pPassItem, SfxBoolItem, SID_PASSWORDINTERACTION, sal_False );
mbPwdCheckBoxState = ( pPassItem != NULL && pPassItem->GetValue() );
// in case the document has password to modify, the dialog should be shown
SFX_ITEMSET_ARG( rpSet, pPassToModifyItem, SfxUnoAnyItem, SID_MODIFYPASSWORDINFO, sal_False );
mbPwdCheckBoxState |= ( pPassToModifyItem && pPassToModifyItem->GetValue().hasValue() );
}
SFX_ITEMSET_ARG( rpSet, pSelectItem, SfxBoolItem, SID_SELECTION, sal_False );
if ( pSelectItem )
mbSelection = pSelectItem->GetValue();
else
mbSelectionEnabled = sal_False;
// the password will be set in case user decide so
rpSet->ClearItem( SID_PASSWORDINTERACTION );
rpSet->ClearItem( SID_PASSWORD );
rpSet->ClearItem( SID_ENCRYPTIONDATA );
rpSet->ClearItem( SID_RECOMMENDREADONLY );
rpSet->ClearItem( SID_MODIFYPASSWORDINFO );
}
if ( mbHasPassword && !mbPwdCheckBoxState )
{
SvtSecurityOptions aSecOpt;
mbPwdCheckBoxState = (
aSecOpt.IsOptionSet( SvtSecurityOptions::E_DOCWARN_RECOMMENDPASSWORD ) );
}
rpURLList = NULL;
if ( ! mxFileDlg.is() )
return ERRCODE_ABORT;
if ( ExecutableDialogResults::CANCEL != implDoExecute() )
{
// create an itemset if there is no
if( !rpSet )
rpSet = new SfxAllItemSet( SFX_APP()->GetPool() );
// the item should remain only if it was set by the dialog
rpSet->ClearItem( SID_SELECTION );
if( mbExport && mbHasSelectionBox )
{
try
{
Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
sal_Bool bSelection = sal_False;
if ( aValue >>= bSelection )
rpSet->Put( SfxBoolItem( SID_SELECTION, bSelection ) );
}
catch( const IllegalArgumentException& )
{
OSL_FAIL( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
}
}
// set the read-only flag. When inserting a file, this flag is always set
if ( mbInsert )
rpSet->Put( SfxBoolItem( SID_DOC_READONLY, sal_True ) );
else
{
if ( ( FILEOPEN_READONLY_VERSION == m_nDialogType ) && xCtrlAccess.is() )
{
try
{
Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 );
sal_Bool bReadOnly = sal_False;
if ( ( aValue >>= bReadOnly ) && bReadOnly )
rpSet->Put( SfxBoolItem( SID_DOC_READONLY, bReadOnly ) );
}
catch( const IllegalArgumentException& )
{
OSL_FAIL( "FileDialogHelper_Impl::execute: caught an IllegalArgumentException!" );
}
}
}
if ( mbHasVersions && xCtrlAccess.is() )
{
try
{
Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION,
ControlActions::GET_SELECTED_ITEM_INDEX );
sal_Int32 nVersion = 0;
if ( ( aValue >>= nVersion ) && nVersion > 0 )
// open a special version; 0 == current version
rpSet->Put( SfxInt16Item( SID_VERSION, (short)nVersion ) );
}
catch( const IllegalArgumentException& ){}
}
// set the filter
getRealFilter( rFilter );
const SfxFilter* pCurrentFilter = getCurentSfxFilter();
// fill the rpURLList
implGetAndCacheFiles( mxFileDlg, rpURLList, pCurrentFilter );
if ( rpURLList == NULL || rpURLList->GetObject(0) == NULL )
return ERRCODE_ABORT;
// check, wether or not we have to display a password box
if ( pCurrentFilter && mbHasPassword && mbIsPwdEnabled && xCtrlAccess.is() )
{
try
{
Any aValue = xCtrlAccess->getValue( ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, 0 );
sal_Bool bPassWord = sal_False;
if ( ( aValue >>= bPassWord ) && bPassWord )
{
// ask for a password
rtl::OUString aDocName(*(rpURLList->GetObject(0)));
ErrCode errCode = RequestPassword(pCurrentFilter, aDocName, rpSet);
if (errCode != ERRCODE_NONE)
return errCode;
}
}
catch( const IllegalArgumentException& ){}
}
SaveLastUsedFilter();
return ERRCODE_NONE;
}
else
return ERRCODE_ABORT;
}
// ------------------------------------------------------------------------
ErrCode FileDialogHelper_Impl::execute()
{
if ( ! mxFileDlg.is() )
return ERRCODE_ABORT;
sal_Int16 nRet = implDoExecute();
maPath = mxFileDlg->getDisplayDirectory();
if ( ExecutableDialogResults::CANCEL == nRet )
return ERRCODE_ABORT;
else
{
return ERRCODE_NONE;
}
}
// ------------------------------------------------------------------------
OUString FileDialogHelper_Impl::getPath() const
{
OUString aPath;
if ( mxFileDlg.is() )
aPath = mxFileDlg->getDisplayDirectory();
if ( !aPath.getLength() )
aPath = maPath;
return aPath;
}
// ------------------------------------------------------------------------
OUString FileDialogHelper_Impl::getFilter() const
{
String aFilter = getCurrentFilterUIName();
if( !aFilter.Len() )
aFilter = maCurFilter;
return aFilter;
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::getRealFilter( String& _rFilter ) const
{
_rFilter = getCurrentFilterUIName();
if ( !_rFilter.Len() )
_rFilter = maCurFilter;
if ( _rFilter.Len() && mpMatcher )
{
const SfxFilter* pFilter =
mpMatcher->GetFilter4UIName( _rFilter, m_nMustFlags, m_nDontFlags );
_rFilter = pFilter ? pFilter->GetFilterName() : _rFilter.Erase();
}
}
void FileDialogHelper_Impl::verifyPath()
{
#ifdef UNX
static char const s_FileScheme[] = "file://";
if (0 != rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength(
maPath.getStr(), maPath.getLength(),
s_FileScheme, RTL_CONSTASCII_LENGTH(s_FileScheme)))
{
return;
}
const OString sFullPath = OUStringToOString(
maPath.copy(RTL_CONSTASCII_LENGTH(s_FileScheme)) + maFileName,
osl_getThreadTextEncoding() );
struct stat aFileStat;
stat( sFullPath.getStr(), &aFileStat );
// lp#905355, fdo#43895
// Check that the file has read only permission and is in /tmp -- this is
// the case if we have opened the file from the web with firefox only.
if ( maPath.reverseCompareToAsciiL("file:///tmp",11) == 0 &&
( aFileStat.st_mode & (S_IRWXO + S_IRWXG + S_IRWXU) ) == S_IRUSR )
{
maPath = SvtPathOptions().GetWorkPath();
mxFileDlg->setDisplayDirectory( maPath );
}
#endif
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::displayFolder( const ::rtl::OUString& _rPath )
{
if ( ! _rPath.getLength() )
// nothing to do
return;
maPath = _rPath;
if ( mxFileDlg.is() )
{
try
{
mxFileDlg->setDisplayDirectory( maPath );
verifyPath();
}
catch( const IllegalArgumentException& )
{
OSL_FAIL( "FileDialogHelper_Impl::displayFolder: caught an exception!" );
}
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::setFileName( const ::rtl::OUString& _rFile )
{
maFileName = _rFile;
if ( mxFileDlg.is() )
{
try
{
mxFileDlg->setDefaultName( maFileName );
verifyPath();
}
catch( const IllegalArgumentException& )
{
OSL_FAIL( "FileDialogHelper_Impl::setFileName: caught an exception!" );
}
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::setFilter( const OUString& rFilter )
{
DBG_ASSERT( rFilter.indexOf(':') == -1, "Old filter name used!");
maCurFilter = rFilter;
if ( rFilter.getLength() && mpMatcher )
{
const SfxFilter* pFilter = mpMatcher->GetFilter4FilterName(
rFilter, m_nMustFlags, m_nDontFlags );
if ( pFilter )
maCurFilter = pFilter->GetUIName();
}
uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
if ( maCurFilter.getLength() && xFltMgr.is() )
{
try
{
xFltMgr->setCurrentFilter( maCurFilter );
}
catch( const IllegalArgumentException& ){}
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::createMatcher( const String& rFactory )
{
mpMatcher = new SfxFilterMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
mbDeleteMatcher = sal_True;
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::addFilters( const String& rFactory,
SfxFilterFlags nMust,
SfxFilterFlags nDont )
{
uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
if ( ! xFltMgr.is() )
return;
// we still need a matcher to convert UI names to filter names
if ( !rFactory.Len() )
{
SfxApplication *pSfxApp = SFX_APP();
mpMatcher = &pSfxApp->GetFilterMatcher();
mbDeleteMatcher = sal_False;
}
else
{
mpMatcher = new SfxFilterMatcher( rFactory );
mbDeleteMatcher = sal_True;
}
uno::Reference< XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
uno::Reference< XContainerQuery > xFilterCont(
xSMGR->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.FilterFactory"))),
UNO_QUERY);
if ( ! xFilterCont.is() )
return;
m_nMustFlags |= nMust;
m_nDontFlags |= nDont;
// create the list of filters
::rtl::OUStringBuffer sQuery(256);
sQuery.appendAscii(RTL_CONSTASCII_STRINGPARAM("getSortedFilterList()"));
sQuery.appendAscii(RTL_CONSTASCII_STRINGPARAM(":module="));
sQuery.append(rFactory); // use long name here !
sQuery.appendAscii(RTL_CONSTASCII_STRINGPARAM(":iflags="));
sQuery.append(::rtl::OUString::valueOf((sal_Int32)m_nMustFlags));
sQuery.appendAscii(RTL_CONSTASCII_STRINGPARAM(":eflags="));
sQuery.append(::rtl::OUString::valueOf((sal_Int32)m_nDontFlags));
uno::Reference< XEnumeration > xResult;
try
{
xResult = xFilterCont->createSubSetEnumerationByQuery(sQuery.makeStringAndClear());
}
catch( const uno::Exception& )
{
DBG_ERRORFILE( "Could not get filters from the configuration!" );
}
TSortedFilterList aIter (xResult);
// no matcher any longer used ...
mbDeleteMatcher = sal_False;
// append the filters
::rtl::OUString sFirstFilter;
if (OPEN == lcl_OpenOrSave(m_nDialogType))
::sfx2::appendFiltersForOpen( aIter, xFltMgr, sFirstFilter, *this );
else if ( mbExport )
::sfx2::appendExportFilters( aIter, xFltMgr, sFirstFilter, *this );
else
::sfx2::appendFiltersForSave( aIter, xFltMgr, sFirstFilter, *this, rFactory );
// set our initial selected filter (if we do not already have one)
if ( !maSelectFilter.getLength() )
maSelectFilter = sFirstFilter;
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::addFilter( const OUString& rFilterName,
const OUString& rExtension )
{
uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
if ( ! xFltMgr.is() )
return;
try
{
xFltMgr->appendFilter( rFilterName, rExtension );
if ( !maSelectFilter.getLength() )
maSelectFilter = rFilterName;
}
catch( const IllegalArgumentException& )
{
#ifdef DBG_UTIL
rtl::OStringBuffer aMsg(RTL_CONSTASCII_STRINGPARAM("Could not append Filter"));
aMsg.append(rtl::OUStringToOString(rFilterName, RTL_TEXTENCODING_UTF8));
DBG_ERRORFILE( aMsg.getStr() );
#endif
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::addGraphicFilter()
{
uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
if ( ! xFltMgr.is() )
return;
// create the list of filters
mpGraphicFilter = new GraphicFilter;
sal_uInt16 i, j, nCount = mpGraphicFilter->GetImportFormatCount();
// compute the extension string for all known import filters
String aExtensions;
for ( i = 0; i < nCount; i++ )
{
j = 0;
String sWildcard;
while( sal_True )
{
sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
if ( !sWildcard.Len() )
break;
if ( aExtensions.Search( sWildcard ) == STRING_NOTFOUND )
{
if ( aExtensions.Len() )
aExtensions += sal_Unicode(';');
aExtensions += sWildcard;
}
}
}
#if defined(WNT)
if ( aExtensions.Len() > 240 )
aExtensions = DEFINE_CONST_UNICODE( FILEDIALOG_FILTER_ALL );
#endif
sal_Bool bIsInOpenMode = isInOpenMode();
try
{
OUString aAllFilterName = String( SfxResId( STR_SFX_IMPORT_ALL ) );
aAllFilterName = ::sfx2::addExtension( aAllFilterName, aExtensions, bIsInOpenMode, *this );
xFltMgr->appendFilter( aAllFilterName, aExtensions );
maSelectFilter = aAllFilterName;
}
catch( const IllegalArgumentException& )
{
DBG_ERRORFILE( "Could not append Filter" );
}
// Now add the filter
for ( i = 0; i < nCount; i++ )
{
String aName = mpGraphicFilter->GetImportFormatName( i );
String aExt;
j = 0;
String sWildcard;
while( sal_True )
{
sWildcard = mpGraphicFilter->GetImportWildcard( i, j++ );
if ( !sWildcard.Len() )
break;
if ( aExt.Search( sWildcard ) == STRING_NOTFOUND )
{
if ( aExt.Len() )
aExt += sal_Unicode(';');
aExt += sWildcard;
}
}
aName = ::sfx2::addExtension( aName, aExt, bIsInOpenMode, *this );
try
{
xFltMgr->appendFilter( aName, aExt );
}
catch( const IllegalArgumentException& )
{
DBG_ERRORFILE( "Could not append Filter" );
}
}
}
// ------------------------------------------------------------------------
#define GRF_CONFIG_STR " "
#define STD_CONFIG_STR "1 "
void FileDialogHelper_Impl::saveConfig()
{
uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
Any aValue;
if ( ! xDlg.is() )
return;
if ( mbHasPreview )
{
SvtViewOptions aDlgOpt( E_DIALOG, IMPGRF_CONFIGNAME );
String aUserData = DEFINE_CONST_UNICODE( GRF_CONFIG_STR );
try
{
sal_Bool bValue = sal_False;
aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 );
bValue = sal_False;
aValue >>= bValue;
aUserData.SetToken( 1, ' ', String::CreateFromInt32( (sal_Int32) bValue ) );
INetURLObject aObj( getPath() );
if ( aObj.GetProtocol() == INET_PROT_FILE )
aUserData.SetToken( 2, ' ', aObj.GetMainURL( INetURLObject::NO_DECODE ) );
String aFilter = getFilter();
aFilter = EncodeSpaces_Impl( aFilter );
aUserData.SetToken( 3, ' ', aFilter );
aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
}
catch( const IllegalArgumentException& ){}
}
else
{
sal_Bool bWriteConfig = sal_False;
SvtViewOptions aDlgOpt( E_DIALOG, IODLG_CONFIGNAME );
String aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
if ( aDlgOpt.Exists() )
{
Any aUserItem = aDlgOpt.GetUserItem( USERITEM_NAME );
OUString aTemp;
if ( aUserItem >>= aTemp )
aUserData = String( aTemp );
}
if ( mbHasAutoExt )
{
try
{
aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0 );
sal_Bool bAutoExt = sal_True;
aValue >>= bAutoExt;
aUserData.SetToken( 0, ' ', String::CreateFromInt32( (sal_Int32) bAutoExt ) );
bWriteConfig = sal_True;
}
catch( const IllegalArgumentException& ){}
}
if ( ! mbIsSaveDlg )
{
OUString aPath = getPath();
if ( aPath.getLength() &&
utl::LocalFileHelper::IsLocalFile( aPath ) )
{
aUserData.SetToken( 1, ' ', aPath );
bWriteConfig = sal_True;
}
}
if( mbHasSelectionBox && mbSelectionFltrEnabled )
{
try
{
aValue = xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0 );
sal_Bool bSelection = sal_True;
aValue >>= bSelection;
if ( aUserData.GetTokenCount(' ') < 3 )
aUserData.Append(' ');
aUserData.SetToken( 2, ' ', String::CreateFromInt32( (sal_Int32) bSelection ) );
bWriteConfig = sal_True;
}
catch( const IllegalArgumentException& ){}
}
if ( bWriteConfig )
aDlgOpt.SetUserItem( USERITEM_NAME, makeAny( OUString( aUserData ) ) );
}
SfxApplication *pSfxApp = SFX_APP();
pSfxApp->SetLastDir_Impl( getPath() );
}
// ------------------------------------------------------------------------
namespace
{
static ::rtl::OUString getInitPath( const String& _rFallback, const xub_StrLen _nFallbackToken )
{
SfxApplication *pSfxApp = SFX_APP();
String sPath = pSfxApp->GetLastDir_Impl();
if ( !sPath.Len() )
sPath = _rFallback.GetToken( _nFallbackToken, ' ' );
// check if the path points to a valid (accessible) directory
sal_Bool bValid = sal_False;
if ( sPath.Len() )
{
String sPathCheck( sPath );
if ( sPathCheck.GetBuffer()[ sPathCheck.Len() - 1 ] != '/' )
sPathCheck += '/';
sPathCheck += '.';
try
{
::ucbhelper::Content aContent( sPathCheck, uno::Reference< ucb::XCommandEnvironment >() );
bValid = aContent.isFolder();
}
catch( const Exception& ) {}
}
if ( !bValid )
sPath.Erase();
return sPath;
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::loadConfig()
{
uno::Reference < XFilePickerControlAccess > xDlg( mxFileDlg, UNO_QUERY );
Any aValue;
if ( ! xDlg.is() )
return;
if ( mbHasPreview )
{
SvtViewOptions aViewOpt( E_DIALOG, IMPGRF_CONFIGNAME );
String aUserData;
if ( aViewOpt.Exists() )
{
Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
OUString aTemp;
if ( aUserItem >>= aTemp )
aUserData = String( aTemp );
}
if ( aUserData.Len() > 0 )
{
try
{
// respect the last "show preview" state
sal_Bool bShowPreview = (sal_Bool) aUserData.GetToken( 1, ' ' ).ToInt32();
if ( !xDlg->getValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0 ).hasValue() )
{
aValue <<= bShowPreview;
xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, aValue );
}
if ( !maPath.getLength() )
displayFolder( getInitPath( aUserData, 2 ) );
if ( ! maCurFilter.getLength() )
{
String aFilter = aUserData.GetToken( 3, ' ' );
aFilter = DecodeSpaces_Impl( aFilter );
setFilter( aFilter );
}
// set the member so we know that we have to show the preview
mbShowPreview = bShowPreview;
}
catch( const IllegalArgumentException& ){}
}
if ( !maPath.getLength() )
displayFolder( SvtPathOptions().GetGraphicPath() );
}
else
{
SvtViewOptions aViewOpt( E_DIALOG, IODLG_CONFIGNAME );
String aUserData;
if ( aViewOpt.Exists() )
{
Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
OUString aTemp;
if ( aUserItem >>= aTemp )
aUserData = String( aTemp );
}
if ( ! aUserData.Len() )
aUserData = DEFINE_CONST_UNICODE( STD_CONFIG_STR );
if ( ! maPath.getLength() )
displayFolder( getInitPath( aUserData, 1 ) );
if ( mbHasAutoExt )
{
sal_Int32 nFlag = aUserData.GetToken( 0, ' ' ).ToInt32();
aValue <<= (sal_Bool) nFlag;
try
{
xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue );
}
catch( const IllegalArgumentException& ){}
}
if( mbHasSelectionBox )
{
sal_Int32 nFlag = aUserData.GetToken( 2, ' ' ).ToInt32();
aValue <<= (sal_Bool) nFlag;
try
{
xDlg->setValue( ExtendedFilePickerElementIds::CHECKBOX_SELECTION, 0, aValue );
}
catch( const IllegalArgumentException& ){}
}
if ( !maPath.getLength() )
displayFolder( SvtPathOptions().GetWorkPath() );
}
}
// ------------------------------------------------------------------------
void FileDialogHelper_Impl::setDefaultValues()
{
// when no filter is set, we set the curentFilter to <all>
if ( !maCurFilter.getLength() && maSelectFilter.getLength() )
{
uno::Reference< XFilterManager > xFltMgr( mxFileDlg, UNO_QUERY );
try
{
xFltMgr->setCurrentFilter( maSelectFilter );
}
catch( const IllegalArgumentException& )
{}
}
// when no path is set, we use the standard 'work' folder
if ( ! maPath.getLength() )
{
OUString aWorkFolder = SvtPathOptions().GetWorkPath();
try
{
mxFileDlg->setDisplayDirectory( aWorkFolder );
}
catch( const Exception& )
{
OSL_FAIL( "FileDialogHelper_Impl::setDefaultValues: caught an exception while setting the display directory!" );
}
}
}
sal_Bool FileDialogHelper_Impl::isShowFilterExtensionEnabled() const
{
return !maFilters.empty();
}
void FileDialogHelper_Impl::addFilterPair( const OUString& rFilter,
const OUString& rFilterWithExtension )
{
maFilters.push_back( FilterPair( rFilter, rFilterWithExtension ) );
}
OUString FileDialogHelper_Impl::getFilterName( const OUString& rFilterWithExtension ) const
{
OUString sRet;
for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
{
if ( (*pIter).Second == rFilterWithExtension )
{
sRet = (*pIter).First;
break;
}
}
return sRet;
}
OUString FileDialogHelper_Impl::getFilterWithExtension( const OUString& rFilter ) const
{
OUString sRet;
for( ::std::vector< FilterPair >::const_iterator pIter = maFilters.begin(); pIter != maFilters.end(); ++pIter )
{
if ( (*pIter).First == rFilter )
{
sRet = (*pIter).Second;
break;
}
}
return sRet;
}
void FileDialogHelper_Impl::SetContext( FileDialogHelper::Context _eNewContext )
{
meContext = _eNewContext;
const OUString* pConfigId = GetLastFilterConfigId( _eNewContext );
if( pConfigId )
LoadLastUsedFilter( *pConfigId );
}
// ------------------------------------------------------------------------
// ----------- FileDialogHelper ---------------------------
// ------------------------------------------------------------------------
FileDialogHelper::FileDialogHelper(
sal_Int16 nDialogType,
sal_Int64 nFlags,
const String& rFact,
SfxFilterFlags nMust,
SfxFilterFlags nDont )
{
mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags );
mxImp = mpImp;
// create the list of filters
mpImp->addFilters(
SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
}
// ------------------------------------------------------------------------
FileDialogHelper::FileDialogHelper(
sal_Int16 nDialogType,
sal_Int64 nFlags,
const String& rFact,
sal_Int16 nDialog,
SfxFilterFlags nMust,
SfxFilterFlags nDont,
const String& rStandardDir,
const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList)
{
mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, nDialog, NULL, rStandardDir, rBlackList );
mxImp = mpImp;
// create the list of filters
mpImp->addFilters(
SfxObjectShell::GetServiceNameFromFactory(rFact), nMust, nDont );
}
// ------------------------------------------------------------------------
FileDialogHelper::FileDialogHelper(
sal_Int16 nDialogType,
sal_Int64 nFlags,
Window* _pPreferredParent )
{
mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent );
mxImp = mpImp;
}
// ------------------------------------------------------------------------
FileDialogHelper::FileDialogHelper(
sal_Int16 nDialogType,
sal_Int64 nFlags,
const ::rtl::OUString& aFilterUIName,
const ::rtl::OUString& aExtName,
const ::rtl::OUString& rStandardDir,
const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList,
Window* _pPreferredParent )
{
mpImp = new FileDialogHelper_Impl( this, nDialogType, nFlags, SFX2_IMPL_DIALOG_CONFIG, _pPreferredParent,rStandardDir, rBlackList );
mxImp = mpImp;
// the wildcard here is expected in form "*.extension"
::rtl::OUString aWildcard;
if ( aExtName.indexOf( (sal_Unicode)'*' ) != 0 )
{
if ( aExtName.getLength() && aExtName.indexOf( (sal_Unicode)'.' ) != 0 )
aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
else
aWildcard = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*" ) );
}
aWildcard += aExtName;
::rtl::OUString const aUIString = ::sfx2::addExtension( aFilterUIName,
aWildcard, (OPEN == lcl_OpenOrSave(mpImp->m_nDialogType)), *mpImp);
AddFilter( aUIString, aWildcard );
}
// ------------------------------------------------------------------------
FileDialogHelper::~FileDialogHelper()
{
mpImp->dispose();
mxImp.clear();
}
// ------------------------------------------------------------------------
void FileDialogHelper::CreateMatcher( const String& rFactory )
{
mpImp->createMatcher( SfxObjectShell::GetServiceNameFromFactory(rFactory) );
}
// ------------------------------------------------------------------------
void FileDialogHelper::SetControlHelpIds( const sal_Int16* _pControlId, const char** _pHelpId )
{
mpImp->setControlHelpIds( _pControlId, _pHelpId );
}
void FileDialogHelper::SetContext( Context _eNewContext )
{
mpImp->SetContext( _eNewContext );
}
// ------------------------------------------------------------------------
IMPL_LINK( FileDialogHelper, ExecuteSystemFilePicker, void*, EMPTYARG )
{
m_nError = mpImp->execute();
if ( m_aDialogClosedLink.IsSet() )
m_aDialogClosedLink.Call( this );
return 0L;
}
// ------------------------------------------------------------------------
// rDirPath has to be a directory
ErrCode FileDialogHelper::Execute( SvStringsDtor*& rpURLList,
SfxItemSet *& rpSet,
String& rFilter,
const String& rDirPath )
{
SetDisplayFolder( rDirPath );
return mpImp->execute( rpURLList, rpSet, rFilter );
}
// ------------------------------------------------------------------------
ErrCode FileDialogHelper::Execute()
{
return mpImp->execute();
}
// ------------------------------------------------------------------------
ErrCode FileDialogHelper::Execute( SfxItemSet *& rpSet,
String& rFilter )
{
ErrCode nRet;
SvStringsDtor* pURLList;
nRet = mpImp->execute( pURLList, rpSet, rFilter );
delete pURLList;
return nRet;
}
void FileDialogHelper::StartExecuteModal( const Link& rEndDialogHdl )
{
m_aDialogClosedLink = rEndDialogHdl;
m_nError = ERRCODE_NONE;
if ( mpImp->isSystemFilePicker() )
Application::PostUserEvent( LINK( this, FileDialogHelper, ExecuteSystemFilePicker ) );
else
mpImp->implStartExecute();
}
// ------------------------------------------------------------------------
short FileDialogHelper::GetDialogType() const
{
return mpImp ? mpImp->m_nDialogType : 0;
}
// ------------------------------------------------------------------------
sal_Bool FileDialogHelper::IsPasswordEnabled() const
{
return mpImp ? mpImp->isPasswordEnabled() : sal_False;
}
// ------------------------------------------------------------------------
String FileDialogHelper::GetRealFilter() const
{
String sFilter;
if ( mpImp )
mpImp->getRealFilter( sFilter );
return sFilter;
}
// ------------------------------------------------------------------------
void FileDialogHelper::SetTitle( const String& rNewTitle )
{
if ( mpImp->mxFileDlg.is() )
mpImp->mxFileDlg->setTitle( rNewTitle );
}
// ------------------------------------------------------------------------
String FileDialogHelper::GetPath() const
{
OUString aPath;
if ( mpImp->mlLastURLs.size() > 0)
return mpImp->mlLastURLs[0];
if ( mpImp->mxFileDlg.is() )
{
Sequence < OUString > aPathSeq = mpImp->mxFileDlg->getFiles();
if ( aPathSeq.getLength() == 1 )
{
aPath = aPathSeq[0];
}
}
return aPath;
}
// ------------------------------------------------------------------------
Sequence < OUString > FileDialogHelper::GetMPath() const
{
if ( mpImp->mlLastURLs.size() > 0)
return mpImp->mlLastURLs.getAsConstList();
if ( mpImp->mxFileDlg.is() )
return mpImp->mxFileDlg->getFiles();
else
{
Sequence < OUString > aEmpty;
return aEmpty;
}
}
// ------------------------------------------------------------------------
Sequence< ::rtl::OUString > FileDialogHelper::GetSelectedFiles() const
{
// a) the new way (optional!)
uno::Sequence< ::rtl::OUString > aResultSeq;
uno::Reference< XFilePicker2 > xPickNew(mpImp->mxFileDlg, UNO_QUERY);
if (xPickNew.is())
{
aResultSeq = xPickNew->getSelectedFiles();
}
// b) the olde way ... non optional.
else
{
uno::Reference< XFilePicker > xPickOld(mpImp->mxFileDlg, UNO_QUERY_THROW);
Sequence< OUString > lFiles = xPickOld->getFiles();
::sal_Int32 nFiles = lFiles.getLength();
if ( nFiles > 1 )
{
aResultSeq = Sequence< ::rtl::OUString >( nFiles-1 );
INetURLObject aPath( lFiles[0] );
aPath.setFinalSlash();
for (::sal_Int32 i = 1; i < nFiles; i++)
{
if (i == 1)
aPath.Append( lFiles[i] );
else
aPath.setName( lFiles[i] );
aResultSeq[i-1] = ::rtl::OUString(aPath.GetMainURL( INetURLObject::NO_DECODE ));
}
}
else
aResultSeq = lFiles;
}
return aResultSeq;
}
// ------------------------------------------------------------------------
String FileDialogHelper::GetDisplayDirectory() const
{
return mpImp->getPath();
}
// ------------------------------------------------------------------------
String FileDialogHelper::GetCurrentFilter() const
{
return mpImp->getFilter();
}
// ------------------------------------------------------------------------
ErrCode FileDialogHelper::GetGraphic( Graphic& rGraphic ) const
{
return mpImp->getGraphic( rGraphic );
}
// ------------------------------------------------------------------------
static int impl_isFolder( const OUString& rPath )
{
uno::Reference< task::XInteractionHandler > xHandler;
try
{
uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
xHandler.set( xFactory->createInstance( DEFINE_CONST_OUSTRING( "com.sun.star.task.InteractionHandler" ) ),
uno::UNO_QUERY_THROW );
}
catch ( const Exception & )
{
}
::rtl::Reference< ::comphelper::StillReadWriteInteraction > aHandler = new ::comphelper::StillReadWriteInteraction( xHandler );
try
{
::ucbhelper::Content aContent(
rPath, new ::ucbhelper::CommandEnvironment( static_cast< task::XInteractionHandler* > ( aHandler.get() ), uno::Reference< ucb::XProgressHandler >() ) );
if ( aContent.isFolder() )
return 1;
return 0;
}
catch ( const Exception & )
{
}
return -1;
}
void FileDialogHelper::SetDisplayDirectory( const String& _rPath )
{
if ( !_rPath.Len() )
return;
// if the given path isn't a folder, we cut off the last part
// and take it as filename and the rest of the path should be
// the folder
INetURLObject aObj( _rPath );
::rtl::OUString sFileName = aObj.GetName( INetURLObject::DECODE_WITH_CHARSET );
aObj.removeSegment();
::rtl::OUString sPath = aObj.GetMainURL( INetURLObject::NO_DECODE );
int nIsFolder = impl_isFolder( _rPath );
if ( nIsFolder == 0 ||
( nIsFolder == -1 && impl_isFolder( sPath ) == 1 ) )
{
mpImp->setFileName( sFileName );
mpImp->displayFolder( sPath );
}
else
{
INetURLObject aObjPathName( _rPath );
::rtl::OUString sFolder( aObjPathName.GetMainURL( INetURLObject::NO_DECODE ) );
if ( sFolder.getLength() == 0 )
{
// _rPath is not a valid path -> fallback to home directory
osl::Security aSecurity;
aSecurity.getHomeDir( sFolder );
}
mpImp->displayFolder( sFolder );
}
}
// ------------------------------------------------------------------------
void FileDialogHelper::SetDisplayFolder( const String& _rURL )
{
mpImp->displayFolder( _rURL );
}
// ------------------------------------------------------------------------
void FileDialogHelper::SetFileName( const String& _rFileName )
{
mpImp->setFileName( _rFileName );
}
// ------------------------------------------------------------------------
void FileDialogHelper::AddFilter( const String& rFilterName,
const String& rExtension )
{
mpImp->addFilter( rFilterName, rExtension );
}
// ------------------------------------------------------------------------
void FileDialogHelper::SetCurrentFilter( const String& rFilter )
{
String sFilter( rFilter );
if ( mpImp->isShowFilterExtensionEnabled() )
sFilter = mpImp->getFilterWithExtension( rFilter );
mpImp->setFilter( sFilter );
}
// ------------------------------------------------------------------------
uno::Reference < XFilePicker > FileDialogHelper::GetFilePicker() const
{
return mpImp->mxFileDlg;
}
// ------------------------------------------------------------------------
// XFilePickerListener Methods
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper::FileSelectionChanged( const FilePickerEvent& aEvent )
{
mpImp->handleFileSelectionChanged( aEvent );
}
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper::DirectoryChanged( const FilePickerEvent& aEvent )
{
mpImp->handleDirectoryChanged( aEvent );
}
// ------------------------------------------------------------------------
OUString SAL_CALL FileDialogHelper::HelpRequested( const FilePickerEvent& aEvent )
{
return mpImp->handleHelpRequested( aEvent );
}
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper::ControlStateChanged( const FilePickerEvent& aEvent )
{
mpImp->handleControlStateChanged( aEvent );
}
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper::DialogSizeChanged()
{
mpImp->handleDialogSizeChanged();
}
// ------------------------------------------------------------------------
void SAL_CALL FileDialogHelper::DialogClosed( const DialogClosedEvent& _rEvent )
{
m_nError = ( RET_OK == _rEvent.DialogResult ) ? ERRCODE_NONE : ERRCODE_ABORT;
if ( m_aDialogClosedLink.IsSet() )
m_aDialogClosedLink.Call( this );
}
// ------------------------------------------------------------------------
ErrCode FileOpenDialog_Impl( sal_Int16 nDialogType,
sal_Int64 nFlags,
const String& rFact,
SvStringsDtor *& rpURLList,
String& rFilter,
SfxItemSet *& rpSet,
const String* pPath,
sal_Int16 nDialog,
const String& rStandardDir,
const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rBlackList )
{
ErrCode nRet;
FileDialogHelper aDialog( nDialogType, nFlags,
rFact, nDialog, 0, 0, rStandardDir, rBlackList );
String aPath;
if ( pPath )
aPath = *pPath;
nRet = aDialog.Execute( rpURLList, rpSet, rFilter, aPath );
DBG_ASSERT( rFilter.SearchAscii(": ") == STRING_NOTFOUND, "Old filter name used!");
return nRet;
}
ErrCode RequestPassword(const SfxFilter* pCurrentFilter, rtl::OUString& aURL, SfxItemSet* pSet)
{
uno::Reference < ::com::sun::star::task::XInteractionHandler > xInteractionHandler( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.uui.UUIInteractionHandler"))), UNO_QUERY );
if( xInteractionHandler.is() )
{
// TODO: need a save way to distinguish MS filters from other filters
// for now MS-filters are the only alien filters that support encryption
sal_Bool bMSType = !pCurrentFilter->IsOwnFormat();
::comphelper::DocPasswordRequestType eType = bMSType ?
::comphelper::DocPasswordRequestType_MS :
::comphelper::DocPasswordRequestType_STANDARD;
::rtl::Reference< ::comphelper::DocPasswordRequest > pPasswordRequest( new ::comphelper::DocPasswordRequest( eType, ::com::sun::star::task::PasswordRequestMode_PASSWORD_CREATE, aURL, ( pCurrentFilter->GetFilterFlags() & SFX_FILTER_PASSWORDTOMODIFY ) != 0 ) );
uno::Reference< com::sun::star::task::XInteractionRequest > rRequest( pPasswordRequest.get() );
xInteractionHandler->handle( rRequest );
if ( pPasswordRequest->isPassword() )
{
if ( pPasswordRequest->getPassword().getLength() )
{
// TODO/LATER: The filters should show the password dialog themself in future
if ( bMSType )
{
// all the current MS-filters use MSCodec_Std97 implementation
uno::Sequence< sal_Int8 > aUniqueID = ::comphelper::DocPasswordHelper::GenerateRandomByteSequence( 16 );
uno::Sequence< sal_Int8 > aEncryptionKey = ::comphelper::DocPasswordHelper::GenerateStd97Key( pPasswordRequest->getPassword(), aUniqueID );
if ( aEncryptionKey.getLength() )
{
::comphelper::SequenceAsHashMap aHashData;
aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97EncryptionKey" ) ) ] <<= aEncryptionKey;
aHashData[ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "STD97UniqueID" ) ) ] <<= aUniqueID;
pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( aHashData.getAsConstNamedValueList() ) ) );
}
else
return ERRCODE_IO_NOTSUPPORTED;
}
else
{
pSet->Put( SfxUnoAnyItem( SID_ENCRYPTIONDATA, uno::makeAny( ::comphelper::OStorageHelper::CreatePackageEncryptionData( pPasswordRequest->getPassword() ) ) ) );
}
}
if ( pPasswordRequest->getRecommendReadOnly() )
pSet->Put( SfxBoolItem( SID_RECOMMENDREADONLY, sal_True ) );
if ( bMSType )
{
// the empty password has 0 as Hash
sal_Int32 nHash = SfxMedium::CreatePasswordToModifyHash( pPasswordRequest->getPasswordToModify(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ).equals( pCurrentFilter->GetServiceName() ) );
if ( nHash )
pSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( nHash ) ) );
}
else
{
uno::Sequence< beans::PropertyValue > aModifyPasswordInfo = ::comphelper::DocPasswordHelper::GenerateNewModifyPasswordInfo( pPasswordRequest->getPasswordToModify() );
if ( aModifyPasswordInfo.getLength() )
pSet->Put( SfxUnoAnyItem( SID_MODIFYPASSWORDINFO, uno::makeAny( aModifyPasswordInfo ) ) );
}
}
else
return ERRCODE_ABORT;
}
return ERRCODE_NONE;
}
// ------------------------------------------------------------------------
String EncodeSpaces_Impl( const String& rSource )
{
String sRet( rSource );
sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( " " ), DEFINE_CONST_UNICODE( "%20" ) );
return sRet;
}
// ------------------------------------------------------------------------
String DecodeSpaces_Impl( const String& rSource )
{
String sRet( rSource );
sRet.SearchAndReplaceAll( DEFINE_CONST_UNICODE( "%20" ), DEFINE_CONST_UNICODE( " " ) );
return sRet;
}
// ------------------------------------------------------------------------
} // end of namespace sfx2
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|