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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "fileview.hxx"
#include <sal/config.h>
#include <svtools/treelistentry.hxx>
#include <svtools/fileview.hxx>
#include <svtools/svtresid.hxx>
#include <svtools/imagemgr.hxx>
#include <svtools/headbar.hxx>
#include <svtools/svtabbx.hxx>
#include <svtools/svtools.hrc>
#include <svtools/viewdataentry.hxx>
#include "fileview.hrc"
#include "contentenumeration.hxx"
#include <svtools/AccessibleBrowseBoxObjType.hxx>
#include <com/sun/star/util/DateTime.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/task/InteractionHandler.hpp>
#include <com/sun/star/ucb/XProgressHandler.hpp>
#include <com/sun/star/sdbc/XResultSet.hpp>
#include <com/sun/star/ucb/XAnyCompareFactory.hpp>
#include <com/sun/star/ucb/XContentAccess.hpp>
#include <com/sun/star/ucb/XDynamicResultSet.hpp>
#include <com/sun/star/ucb/XSortedDynamicResultSetFactory.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/ucb/CommandAbortedException.hpp>
#include <com/sun/star/ucb/ContentCreationException.hpp>
#include <vcl/waitobj.hxx>
#include <vcl/settings.hxx>
#include <com/sun/star/io/XPersist.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/ucb/XCommandInfo.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <tools/urlobj.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <unotools/localfilehelper.hxx>
#include <ucbhelper/content.hxx>
#include <ucbhelper/commandenvironment.hxx>
#include <vcl/layout.hxx>
#include <rtl/math.hxx>
#include <tools/config.hxx>
#include <osl/mutex.hxx>
#include <osl/conditn.hxx>
#include <salhelper/timer.hxx>
#include <vcl/svapp.hxx>
#include <vcl/builderfactory.hxx>
#include <unotools/ucbhelper.hxx>
#include <unotools/intlwrapper.hxx>
#include <unotools/syslocale.hxx>
#include <svl/urlfilter.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <memory>
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::task;
using namespace ::com::sun::star::ucb;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::io;
using namespace ::com::sun::star::beans;
using namespace ::comphelper;
using ::svt::SortingData_Impl;
using ::svt::FolderDescriptor;
#define ALL_FILES_FILTER "*.*"
#define COLUMN_TITLE 1
#define COLUMN_TYPE 2
#define COLUMN_SIZE 3
#define COLUMN_DATE 4
#define ROW_HEIGHT 17 // the height of a row has to be a little higher than the bitmap
#define QUICK_SEARCH_TIMEOUT 1500 // time in mSec before the quicksearch string will be reseted
enum class FileViewFlags
{
NONE = 0x00,
ONLYFOLDER = 0x01,
MULTISELECTION = 0x02,
SHOW_TYPE = 0x04,
SHOW_ONLYTITLE = 0x10,
SHOW_NONE = 0x20,
};
namespace o3tl
{
template<> struct typed_flags<FileViewFlags> : is_typed_flags<FileViewFlags, 0x1f> {};
}
namespace
{
//= ITimeoutHandler
class CallbackTimer;
class ITimeoutHandler
{
public:
virtual void onTimeout( CallbackTimer* _pInstigator ) = 0;
protected:
~ITimeoutHandler() {}
};
//= CallbackTimer
class CallbackTimer : public ::salhelper::Timer
{
protected:
ITimeoutHandler* m_pTimeoutHandler;
public:
CallbackTimer( ITimeoutHandler* _pHandler ) : m_pTimeoutHandler( _pHandler ) { }
protected:
virtual void SAL_CALL onShot() SAL_OVERRIDE;
};
void SAL_CALL CallbackTimer::onShot()
{
OSL_ENSURE( m_pTimeoutHandler, "CallbackTimer::onShot: nobody interested in?" );
ITimeoutHandler* pHandler( m_pTimeoutHandler );
if ( pHandler )
pHandler->onTimeout( this );
}
}
void FilterMatch::createWildCardFilterList(const OUString& _rFilterList,::std::vector< WildCard >& _rFilters)
{
if( _rFilterList.getLength() )
{
// filter is given
sal_Int32 nIndex = 0;
OUString sToken;
do
{
sToken = _rFilterList.getToken( 0, ';', nIndex );
if ( !sToken.isEmpty() )
{
_rFilters.push_back( WildCard( sToken.toAsciiUpperCase() ) );
}
}
while ( nIndex >= 0 );
}
else
{
// no filter is given -> match all
_rFilters.push_back( WildCard(OUString("*")) );
}
}
// class ViewTabListBox_Impl ---------------------------------------------
class ViewTabListBox_Impl : public SvHeaderTabListBox
{
private:
Reference< XCommandEnvironment > mxCmdEnv;
::osl::Mutex maMutex;
VclPtr<HeaderBar> mpHeaderBar;
SvtFileView_Impl* mpParent;
Timer maResetQuickSearch;
OUString maQuickSearchText;
OUString msAccessibleDescText;
OUString msFolder;
OUString msFile;
sal_uInt32 mnSearchIndex;
bool mbResizeDisabled : 1;
bool mbAutoResize : 1;
bool mbEnableDelete : 1;
bool mbEnableRename : 1;
bool mbShowHeader;
void DeleteEntries();
void DoQuickSearch( const sal_Unicode& rChar );
bool Kill( const OUString& rURL );
protected:
virtual bool DoubleClickHdl() SAL_OVERRIDE;
virtual OUString GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos ) const SAL_OVERRIDE;
public:
ViewTabListBox_Impl( vcl::Window* pParentWin, SvtFileView_Impl* pParent, FileViewFlags nFlags );
virtual ~ViewTabListBox_Impl();
virtual void dispose() SAL_OVERRIDE;
virtual void Resize() SAL_OVERRIDE;
virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) SAL_OVERRIDE;
void ClearAll();
HeaderBar* GetHeaderBar() const { return mpHeaderBar; }
void EnableAutoResize() { mbAutoResize = true; }
void EnableDelete( bool bEnable ) { mbEnableDelete = bEnable; }
Reference< XCommandEnvironment > GetCommandEnvironment() const { return mxCmdEnv; }
DECL_LINK_TYPED(ResetQuickSearch_Impl, Timer *, void);
virtual std::unique_ptr<PopupMenu> CreateContextMenu() SAL_OVERRIDE;
virtual void ExcecuteContextMenuAction( sal_uInt16 nSelectedPopentry ) SAL_OVERRIDE;
};
// class NameTranslationList -----------------------------------------
// provides a list of _unique_ Entries
class NameTranslationList
{ // contains a list of substitutes of strings for a given folder (as URL)
// explanation of the circumstances see in remarks for Init();
protected:
INetURLObject maTransFile; // URL of file with translation entries
/// for future purposes when dealing with a set of cached NameTranslationLists
OUString m_HashedURL;
private:
std::unordered_map<OUString, OUString, OUStringHash> m_Translation;
const OUString maTransFileName;
void Init(); // reads the translation file and fills the (internal) list
public:
NameTranslationList( const INetURLObject& rBaseURL );
// rBaseURL: path to folder for which the translation of the entries
// should be done
const OUString* Translate( const OUString& rName ) const;
// returns NULL, if rName can't be found
inline const OUString& GetTransTableFileName() const;
OUString const& GetHashedURL() { return m_HashedURL; }
// returns the name for the file, which contains the translation strings
};
inline const OUString& NameTranslationList::GetTransTableFileName() const
{
return maTransFileName;
}
void NameTranslationList::Init()
{
// Tries to read the file ".nametranslation.table" in the base folder. Complete path/name is in maTransFile.
// Further on, the found entries in the section "TRANSLATIONNAMES" are used to replace names in the
// base folder by translated ones. The translation must be given in UTF8
// See examples of such a files in the samples-folder of an Office installation
try
{
::ucbhelper::Content aTestContent( maTransFile.GetMainURL( INetURLObject::NO_DECODE ), Reference< XCommandEnvironment >(), comphelper::getProcessComponentContext() );
if( aTestContent.isDocument() )
{
// ... also tests the existence of maTransFile by throwing an Exception
OUString aFsysName( maTransFile.getFSysPath( INetURLObject::FSYS_DETECT ) );
Config aConfig( aFsysName );
aConfig.SetGroup( OString("TRANSLATIONNAMES") );
sal_uInt16 nKeyCnt = aConfig.GetKeyCount();
for( sal_uInt16 nCnt = 0 ; nCnt < nKeyCnt ; ++nCnt )
{
m_Translation.insert(std::make_pair(
OStringToOUString(aConfig.GetKeyName(nCnt), RTL_TEXTENCODING_ASCII_US),
OStringToOUString(aConfig.ReadKey(nCnt), RTL_TEXTENCODING_UTF8)
));
}
}
}
catch( Exception const & ) {}
}
NameTranslationList::NameTranslationList( const INetURLObject& rBaseURL ):
maTransFile( rBaseURL ),
m_HashedURL(rBaseURL.GetMainURL(INetURLObject::NO_DECODE)),
maTransFileName( OUString(".nametranslation.table") )
{
maTransFile.insertName( maTransFileName );
Init();
}
const OUString* NameTranslationList::Translate( const OUString& rName ) const
{
auto const iter(m_Translation.find(rName));
return (iter != m_Translation.end()) ? &iter->second : nullptr;
}
// class NameTranslator_Impl ------------------------------------------
// enables the user to get string substitutions (translations for the content) for a given folder
// see more explanations above in the description for NameTranslationList
class NameTranslator_Impl : public ::svt::IContentTitleTranslation
{
private:
NameTranslationList* mpActFolder;
public:
NameTranslator_Impl( const INetURLObject& rActualFolder );
virtual ~NameTranslator_Impl();
// IContentTitleTranslation
virtual bool GetTranslation( const OUString& rOriginalName, OUString& rTranslatedName ) const SAL_OVERRIDE;
void SetActualFolder( const INetURLObject& rActualFolder );
const OUString* GetTransTableFileName() const;
// returns the name for the file, which contains the translation strings
};
//= SvtFileView_Impl
class SvtFileView_Impl :public ::svt::IEnumerationResultHandler
,public ITimeoutHandler
{
protected:
VclPtr<SvtFileView> mpAntiImpl;
Link<SvTreeListBox*,void> m_aSelectHandler;
::rtl::Reference< ::svt::FileViewContentEnumerator >
m_xContentEnumerator;
Link<void*,void> m_aCurrentAsyncActionHandler;
::osl::Condition m_aAsyncActionFinished;
::rtl::Reference< ::salhelper::Timer > m_xCancelAsyncTimer;
::svt::EnumerationResult m_eAsyncActionResult;
bool m_bRunningAsyncAction;
bool m_bAsyncActionCancelled;
public:
::std::vector< SortingData_Impl* > maContent;
::osl::Mutex maMutex;
VclPtr<ViewTabListBox_Impl> mpView;
NameTranslator_Impl* mpNameTrans;
sal_uInt16 mnSortColumn;
bool mbAscending : 1;
bool mbOnlyFolder : 1;
bool mbReplaceNames : 1; // translate folder names or display doc-title instead of file name
sal_Int16 mnSuspendSelectCallback : 1;
bool mbIsFirstResort : 1;
IntlWrapper aIntlWrapper;
OUString maViewURL;
OUString maAllFilter;
OUString maCurrentFilter;
Image maFolderImage;
Link<SvtFileView*,void> maOpenDoneLink;
Reference< XCommandEnvironment > mxCmdEnv;
SvtFileView_Impl( SvtFileView* pAntiImpl, Reference < XCommandEnvironment > xEnv,
FileViewFlags nFlags,
bool bOnlyFolder );
virtual ~SvtFileView_Impl();
void Clear();
FileViewResult GetFolderContent_Impl(
const OUString& rFolder,
const FileViewAsyncAction* pAsyncDescriptor,
const ::com::sun::star::uno::Sequence< OUString >& rBlackList = ::com::sun::star::uno::Sequence< OUString >() );
FileViewResult GetFolderContent_Impl(
const FolderDescriptor& _rFolder,
const FileViewAsyncAction* pAsyncDescriptor,
const ::com::sun::star::uno::Sequence< OUString >& rBlackList = ::com::sun::star::uno::Sequence< OUString >());
void FilterFolderContent_Impl( const OUString &rFilter );
void CancelRunningAsyncAction();
void OpenFolder_Impl();
// #83004# -------
static void ReplaceTabWithString( OUString& aValue );
void CreateDisplayText_Impl();
void SortFolderContent_Impl();
void EntryRemoved( const OUString& rURL );
void EntryRenamed( OUString& rURL,
const OUString& rName );
OUString FolderInserted( const OUString& rURL,
const OUString& rTitle );
sal_uLong GetEntryPos( const OUString& rURL );
inline void EnableDelete( bool bEnable );
void Resort_Impl( sal_Int16 nColumn, bool bAscending );
bool SearchNextEntry( sal_uInt32 &nIndex,
const OUString& rTitle,
bool bWrapAround );
void SetActualFolder( const INetURLObject& rActualFolder );
void SetSelectHandler( const Link<SvTreeListBox*,void>& _rHdl );
void InitSelection();
void ResetCursor();
inline void EndEditing( bool _bCancel );
protected:
DECL_LINK_TYPED( SelectionMultiplexer, SvTreeListBox*, void );
protected:
// IEnumerationResultHandler overridables
virtual void enumerationDone( ::svt::EnumerationResult eResult ) SAL_OVERRIDE;
void implEnumerationSuccess();
// ITimeoutHandler
virtual void onTimeout( CallbackTimer* _pInstigator ) SAL_OVERRIDE;
};
inline void SvtFileView_Impl::EnableDelete( bool bEnable )
{
mpView->EnableDelete( bEnable );
if( bEnable )
mbReplaceNames = false;
}
inline void SvtFileView_Impl::EndEditing( bool _bCancel )
{
if ( mpView->IsEditingActive() )
mpView->EndEditing(_bCancel);
}
// functions -------------------------------------------------------------
OUString CreateExactSizeText( sal_Int64 nSize )
{
double fSize( ( double ) nSize );
int nDec;
long nMega = 1024 * 1024;
long nGiga = nMega * 1024;
OUString aUnitStr(' ');
if ( nSize < 10000 )
{
aUnitStr += SVT_RESSTR(STR_SVT_BYTES );
nDec = 0;
}
else if ( nSize < nMega )
{
fSize /= 1024;
aUnitStr += SVT_RESSTR(STR_SVT_KB);
nDec = 1;
}
else if ( nSize < nGiga )
{
fSize /= nMega;
aUnitStr += SVT_RESSTR(STR_SVT_MB);
nDec = 2;
}
else
{
fSize /= nGiga;
aUnitStr += SVT_RESSTR(STR_SVT_GB);
nDec = 3;
}
OUString aSizeStr( ::rtl::math::doubleToUString( fSize,
rtl_math_StringFormat_F, nDec,
SvtSysLocale().GetLocaleData().getNumDecimalSep()[0]) );
aSizeStr += aUnitStr;
return aSizeStr;
}
// class ViewTabListBox_Impl ---------------------------------------------
ViewTabListBox_Impl::ViewTabListBox_Impl( vcl::Window* pParentWin,
SvtFileView_Impl* pParent,
FileViewFlags nFlags ) :
SvHeaderTabListBox( pParentWin, WB_TABSTOP ),
mpHeaderBar ( NULL ),
mpParent ( pParent ),
msAccessibleDescText( SVT_RESSTR(STR_SVT_ACC_DESC_FILEVIEW) ),
msFolder ( SVT_RESSTR(STR_SVT_ACC_DESC_FOLDER) ),
msFile ( SVT_RESSTR(STR_SVT_ACC_DESC_FILE) ),
mnSearchIndex ( 0 ),
mbResizeDisabled ( false ),
mbAutoResize ( false ),
mbEnableDelete ( false ),
mbEnableRename ( true ),
mbShowHeader ( !(nFlags & FileViewFlags::SHOW_NONE) )
{
Size aBoxSize = pParentWin->GetSizePixel();
mpHeaderBar = VclPtr<HeaderBar>::Create( pParentWin, WB_BUTTONSTYLE | WB_BOTTOMBORDER );
mpHeaderBar->SetPosSizePixel( Point( 0, 0 ), mpHeaderBar->CalcWindowSizePixel() );
HeaderBarItemBits nBits = ( HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER | HeaderBarItemBits::CLICKABLE );
if (nFlags & FileViewFlags::SHOW_ONLYTITLE)
{
long pTabs[] = { 2, 20, 600 };
SetTabs(&pTabs[0], MAP_PIXEL);
mpHeaderBar->InsertItem(COLUMN_TITLE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_TITLE), 600, nBits | HeaderBarItemBits::UPARROW);
}
else
{
long pTabs[] = { 5, 20, 180, 320, 400, 600 };
SetTabs(&pTabs[0], MAP_PIXEL);
SetTabJustify(2, AdjustRight); // column "Size"
mpHeaderBar->InsertItem(COLUMN_TITLE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_TITLE), 180, nBits | HeaderBarItemBits::UPARROW);
if (nFlags & FileViewFlags::SHOW_TYPE)
{
mpHeaderBar->InsertItem(COLUMN_TYPE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_TYPE), 140, nBits);
}
mpHeaderBar->InsertItem(COLUMN_SIZE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_SIZE), 80, nBits);
mpHeaderBar->InsertItem(COLUMN_DATE, SVT_RESSTR(STR_SVT_FILEVIEW_COLUMN_DATE), 500, nBits);
}
Size aHeadSize = mpHeaderBar->GetSizePixel();
SetPosSizePixel( Point( 0, aHeadSize.Height() ),
Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
InitHeaderBar( mpHeaderBar );
SetHighlightRange();
SetEntryHeight( ROW_HEIGHT );
if (nFlags & FileViewFlags::MULTISELECTION)
SetSelectionMode( MULTIPLE_SELECTION );
Show();
if( mbShowHeader )
mpHeaderBar->Show();
maResetQuickSearch.SetTimeout( QUICK_SEARCH_TIMEOUT );
maResetQuickSearch.SetTimeoutHdl( LINK( this, ViewTabListBox_Impl, ResetQuickSearch_Impl ) );
Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
Reference< XInteractionHandler > xInteractionHandler(
InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
mxCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
EnableContextMenuHandling();
}
ViewTabListBox_Impl::~ViewTabListBox_Impl()
{
disposeOnce();
}
void ViewTabListBox_Impl::dispose()
{
maResetQuickSearch.Stop();
mpHeaderBar.disposeAndClear();
SvHeaderTabListBox::dispose();
}
IMPL_LINK_NOARG_TYPED(ViewTabListBox_Impl, ResetQuickSearch_Impl, Timer *, void)
{
::osl::MutexGuard aGuard( maMutex );
maQuickSearchText.clear();
mnSearchIndex = 0;
}
void ViewTabListBox_Impl::Resize()
{
SvTabListBox::Resize();
Size aBoxSize = Control::GetParent()->GetOutputSizePixel();
if ( mbResizeDisabled || !aBoxSize.Width() )
return;
Size aBarSize;
if ( mbShowHeader )
{
aBarSize = mpHeaderBar->GetSizePixel();
aBarSize.Width() = mbAutoResize ? aBoxSize.Width() : GetSizePixel().Width();
mpHeaderBar->SetSizePixel( aBarSize );
}
if ( mbAutoResize )
{
mbResizeDisabled = true;
SetPosSizePixel( Point( 0, aBarSize.Height() ),
Size( aBoxSize.Width(), aBoxSize.Height() - aBarSize.Height() ) );
mbResizeDisabled = false;
}
}
void ViewTabListBox_Impl::KeyInput( const KeyEvent& rKEvt )
{
bool bHandled = false;
const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
if ( 0 == rKeyCode.GetModifier() )
{
if ( rKeyCode.GetCode() == KEY_RETURN )
{
ResetQuickSearch_Impl( NULL );
GetDoubleClickHdl().Call( this );
bHandled = true;
}
else if ( ( rKeyCode.GetCode() == KEY_DELETE ) &&
mbEnableDelete )
{
ResetQuickSearch_Impl( NULL );
DeleteEntries();
bHandled = true;
}
else if ( ( rKEvt.GetKeyCode().GetGroup() == KEYGROUP_NUM ) ||
( rKEvt.GetKeyCode().GetGroup() == KEYGROUP_ALPHA ) )
{
DoQuickSearch( rKEvt.GetCharCode() );
bHandled = true;
}
}
if ( !bHandled )
{
ResetQuickSearch_Impl( NULL );
SvHeaderTabListBox::KeyInput( rKEvt );
}
}
std::unique_ptr<PopupMenu> ViewTabListBox_Impl::CreateContextMenu()
{
bool bEnableDelete = mbEnableDelete;
bool bEnableRename = mbEnableRename;
if ( bEnableDelete || bEnableRename )
{
sal_Int32 nSelectedEntries = GetSelectionCount();
bEnableDelete &= nSelectedEntries > 0;
bEnableRename &= nSelectedEntries == 1;
}
if ( bEnableDelete || bEnableRename )
{
SvTreeListEntry* pEntry = FirstSelected();
while ( pEntry )
{
::ucbhelper::Content aCnt;
try
{
OUString aURL( static_cast< SvtContentEntry * >(
pEntry->GetUserData() )->maURL );
aCnt = ::ucbhelper::Content( aURL, mxCmdEnv, comphelper::getProcessComponentContext() );
}
catch( Exception const & )
{
bEnableDelete = bEnableRename = false;
}
if ( bEnableDelete )
{
try
{
Reference< XCommandInfo > aCommands = aCnt.getCommands();
if ( aCommands.is() )
bEnableDelete
= aCommands->hasCommandByName(
OUString( "delete" ) );
else
bEnableDelete = false;
}
catch( Exception const & )
{
bEnableDelete = false;
}
}
if ( bEnableRename )
{
try
{
Reference< XPropertySetInfo > aProps = aCnt.getProperties();
if ( aProps.is() )
{
Property aProp
= aProps->getPropertyByName(
OUString( "Title" ) );
bEnableRename
= !( aProp.Attributes & PropertyAttribute::READONLY );
}
else
bEnableRename = false;
}
catch( Exception const & )
{
bEnableRename = false;
}
}
pEntry = ( bEnableDelete || bEnableRename )
? NextSelected( pEntry )
: 0;
}
}
if ( bEnableDelete || bEnableRename )
{
std::unique_ptr<PopupMenu> pRet(
new PopupMenu( SvtResId( RID_FILEVIEW_CONTEXTMENU ) ));
pRet->EnableItem( MID_FILEVIEW_DELETE, bEnableDelete );
pRet->EnableItem( MID_FILEVIEW_RENAME, bEnableRename );
pRet->RemoveDisabledEntries( true, true );
return pRet;
}
return NULL;
}
void ViewTabListBox_Impl::ExcecuteContextMenuAction( sal_uInt16 nSelectedPopupEntry )
{
switch ( nSelectedPopupEntry )
{
case MID_FILEVIEW_DELETE :
DeleteEntries();
break;
case MID_FILEVIEW_RENAME :
EditEntry( FirstSelected() );
break;
}
}
void ViewTabListBox_Impl::ClearAll()
{
for ( sal_uLong i = 0; i < GetEntryCount(); ++i )
delete static_cast<SvtContentEntry*>(GetEntry(i)->GetUserData());
Clear();
}
void ViewTabListBox_Impl::DeleteEntries()
{
short eResult = svtools::QUERYDELETE_YES;
SvTreeListEntry* pEntry = FirstSelected();
OUString aURL;
OString sDialogPosition;
while ( pEntry && ( eResult != svtools::QUERYDELETE_CANCEL ) )
{
SvTreeListEntry *pCurEntry = pEntry;
pEntry = NextSelected( pEntry );
if ( pCurEntry->GetUserData() )
aURL = static_cast<SvtContentEntry*>(pCurEntry->GetUserData())->maURL;
if ( aURL.isEmpty() )
continue;
bool canDelete = true;
try
{
::ucbhelper::Content aCnt( aURL, mxCmdEnv, comphelper::getProcessComponentContext() );
Reference< XCommandInfo > aCommands = aCnt.getCommands();
if ( aCommands.is() )
canDelete
= aCommands->hasCommandByName(
OUString( "delete" ) );
else
canDelete = false;
}
catch( Exception const & )
{
canDelete = false;
}
if (!canDelete)
continue; // process next entry
if ( eResult != svtools::QUERYDELETE_ALL )
{
INetURLObject aObj( aURL );
ScopedVclPtrInstance< svtools::QueryDeleteDlg_Impl > aDlg(nullptr, aObj.GetName( INetURLObject::DECODE_WITH_CHARSET ) );
if ( sDialogPosition.getLength() )
aDlg->SetWindowState( sDialogPosition );
if ( GetSelectionCount() > 1 )
aDlg->EnableAllButton();
eResult = aDlg->Execute();
sDialogPosition = aDlg->GetWindowState( );
}
if ( ( eResult == svtools::QUERYDELETE_ALL ) ||
( eResult == svtools::QUERYDELETE_YES ) )
{
if ( Kill( aURL ) )
{
delete static_cast<SvtContentEntry*>(pCurEntry->GetUserData());
GetModel()->Remove( pCurEntry );
mpParent->EntryRemoved( aURL );
}
}
}
}
bool ViewTabListBox_Impl::EditedEntry( SvTreeListEntry* pEntry,
const OUString& rNewText )
{
bool bRet = false;
OUString aURL;
SvtContentEntry* pData = static_cast<SvtContentEntry*>(pEntry->GetUserData());
if ( pData )
aURL = pData->maURL;
if ( aURL.isEmpty() )
return bRet;
try
{
OUString aPropName( "Title" );
bool canRename = true;
::ucbhelper::Content aContent( aURL, mxCmdEnv, comphelper::getProcessComponentContext() );
try
{
Reference< XPropertySetInfo > aProps = aContent.getProperties();
if ( aProps.is() )
{
Property aProp = aProps->getPropertyByName( aPropName );
canRename = !( aProp.Attributes & PropertyAttribute::READONLY );
}
else
{
canRename = false;
}
}
catch ( Exception const & )
{
canRename = false;
}
if ( canRename )
{
Any aValue;
aValue <<= rNewText;
aContent.setPropertyValue( aPropName, aValue );
mpParent->EntryRenamed( aURL, rNewText );
if (pData)
pData->maURL = aURL;
pEntry->SetUserData( pData );
bRet = true;
}
}
catch( Exception const & )
{
}
return bRet;
}
void ViewTabListBox_Impl::DoQuickSearch( const sal_Unicode& rChar )
{
::osl::MutexGuard aGuard( maMutex );
maResetQuickSearch.Stop();
OUString aLastText = maQuickSearchText;
sal_uInt32 aLastPos = mnSearchIndex;
maQuickSearchText += OUString(rChar).toAsciiLowerCase();
bool bFound = mpParent->SearchNextEntry( mnSearchIndex, maQuickSearchText, false );
if ( !bFound && ( aLastText.getLength() == 1 ) &&
( aLastText == OUString(rChar) ) )
{
mnSearchIndex = aLastPos + 1;
maQuickSearchText = aLastText;
bFound = mpParent->SearchNextEntry( mnSearchIndex, maQuickSearchText, true );
}
if ( bFound )
{
SvTreeListEntry* pEntry = GetEntry( mnSearchIndex );
if ( pEntry )
{
SelectAll( false );
Select( pEntry );
SetCurEntry( pEntry );
MakeVisible( pEntry );
}
}
maResetQuickSearch.Start();
}
bool ViewTabListBox_Impl::DoubleClickHdl()
{
SvHeaderTabListBox::DoubleClickHdl();
return false;
// this means "do no additional handling". Especially this means that the SvImpLBox does not
// recognize that the entry at the double click position change after the handler call (which is
// the case if in the handler, our content was replaced)
// If it _would_ recognize this change, it would take this as a reason to select the entry, again
// - which is not what in the case of content replace
// (I really doubt that this behaviour of the SvImpLBox does make any sense at all, but
// who knows ...)
}
OUString ViewTabListBox_Impl::GetAccessibleObjectDescription( ::svt::AccessibleBrowseBoxObjType _eType, sal_Int32 _nPos ) const
{
OUString sRet = SvHeaderTabListBox::GetAccessibleObjectDescription( _eType, _nPos );
if ( ::svt::BBTYPE_TABLECELL == _eType )
{
sal_Int32 nRow = -1;
const sal_uInt16 nColumnCount = GetColumnCount();
if (nColumnCount > 0)
nRow = _nPos / nColumnCount;
SvTreeListEntry* pEntry = GetEntry( nRow );
if ( pEntry )
{
SvtContentEntry* pData = static_cast<SvtContentEntry*>(pEntry->GetUserData());
if ( pData )
{
const OUString sVar1( "%1" );
const OUString sVar2( "%2" );
OUString aText( msAccessibleDescText );
aText = aText.replaceAll( sVar1, pData->mbIsFolder ? msFolder : msFile );
aText = aText.replaceAll( sVar2, pData->maURL );
sRet += aText;
}
}
}
return sRet;
}
bool ViewTabListBox_Impl::Kill( const OUString& rContent )
{
bool bRet = true;
try
{
::ucbhelper::Content aCnt( rContent, mxCmdEnv, comphelper::getProcessComponentContext() );
aCnt.executeCommand( OUString( "delete" ), makeAny( true ) );
}
catch( ::com::sun::star::ucb::CommandAbortedException const & )
{
DBG_WARNING( "CommandAbortedException" );
bRet = false;
}
catch( Exception const & )
{
DBG_WARNING( "Any other exception" );
bRet = false;
}
return bRet;
}
// class SvtFileView -----------------------------------------------------
SvtFileView::SvtFileView( vcl::Window* pParent, WinBits nBits,
bool bOnlyFolder, bool bMultiSelection, bool bShowType ) :
Control( pParent, nBits )
{
FileViewFlags nFlags = FileViewFlags::NONE;
if ( bOnlyFolder )
nFlags |= FileViewFlags::ONLYFOLDER;
if ( bMultiSelection )
nFlags |= FileViewFlags::MULTISELECTION;
if ( bShowType )
nFlags |= FileViewFlags::SHOW_TYPE;
Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
Reference< XInteractionHandler > xInteractionHandler(
InteractionHandler::createWithParent(xContext, 0), UNO_QUERY_THROW );
Reference < XCommandEnvironment > xCmdEnv = new ::ucbhelper::CommandEnvironment( xInteractionHandler, Reference< XProgressHandler >() );
mpImp = new SvtFileView_Impl( this, xCmdEnv, nFlags, bOnlyFolder );
mpImp->mpView->ForbidEmptyText();
SetSortColumn( true );
HeaderBar* pHeaderBar = mpImp->mpView->GetHeaderBar();
pHeaderBar->SetSelectHdl( LINK( this, SvtFileView, HeaderSelect_Impl ) );
pHeaderBar->SetEndDragHdl( LINK( this, SvtFileView, HeaderEndDrag_Impl ) );
}
SvtFileView::~SvtFileView()
{
disposeOnce();
}
void SvtFileView::dispose()
{
// use temp pointer to prevent access of deleted member (GetFocus())
SvtFileView_Impl* pTemp = mpImp;
mpImp = NULL;
delete pTemp;
Control::dispose();
}
VCL_BUILDER_DECL_FACTORY(SvtFileView)
{
WinBits nBits = WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK;
bool bDropdown = VclBuilder::extractDropdown(rMap);
if (bDropdown)
nBits |= WB_DROPDOWN;
rRet = VclPtr<SvtFileView>::Create(pParent, nBits, true, true);
}
Size SvtFileView::GetOptimalSize() const
{
return LogicToPixel(Size(208, 50), MAP_APPFONT);
}
OUString SvtFileView::GetURL( SvTreeListEntry* pEntry )
{
OUString aURL;
if ( pEntry && pEntry->GetUserData() )
aURL = static_cast<SvtContentEntry*>(pEntry->GetUserData())->maURL;
return aURL;
}
OUString SvtFileView::GetCurrentURL() const
{
OUString aURL;
SvTreeListEntry* pEntry = mpImp->mpView->FirstSelected();
if ( pEntry && pEntry->GetUserData() )
aURL = static_cast<SvtContentEntry*>(pEntry->GetUserData())->maURL;
return aURL;
}
void SvtFileView::CreatedFolder( const OUString& rUrl, const OUString& rNewFolder )
{
OUString sEntry = mpImp->FolderInserted( rUrl, rNewFolder );
SvTreeListEntry* pEntry = mpImp->mpView->InsertEntry( sEntry, mpImp->maFolderImage, mpImp->maFolderImage );
SvtContentEntry* pUserData = new SvtContentEntry( rUrl, true );
pEntry->SetUserData( pUserData );
mpImp->mpView->MakeVisible( pEntry );
}
FileViewResult SvtFileView::PreviousLevel( const FileViewAsyncAction* pAsyncDescriptor )
{
FileViewResult eResult = eFailure;
OUString sParentURL;
if ( GetParentURL( sParentURL ) )
eResult = Initialize( sParentURL, mpImp->maCurrentFilter, pAsyncDescriptor, mpBlackList );
return eResult;
}
bool SvtFileView::GetParentURL( OUString& rParentURL ) const
{
bool bRet = false;
try
{
::ucbhelper::Content aCnt( mpImp->maViewURL, mpImp->mxCmdEnv, comphelper::getProcessComponentContext() );
Reference< XContent > xContent( aCnt.get() );
Reference< com::sun::star::container::XChild > xChild( xContent, UNO_QUERY );
if ( xChild.is() )
{
Reference< XContent > xParent( xChild->getParent(), UNO_QUERY );
if ( xParent.is() )
{
rParentURL = xParent->getIdentifier()->getContentIdentifier();
bRet = !rParentURL.isEmpty() && rParentURL != mpImp->maViewURL;
}
}
}
catch( Exception const & )
{
// perhaps an unknown url protocol (e.g. "private:newdoc")
}
return bRet;
}
const OString& SvtFileView::GetHelpId( ) const
{
return mpImp->mpView->GetHelpId( );
}
void SvtFileView::SetHelpId( const OString& rHelpId )
{
mpImp->mpView->SetHelpId( rHelpId );
}
void SvtFileView::SetSizePixel( const Size& rNewSize )
{
Control::SetSizePixel( rNewSize );
mpImp->mpView->SetSizePixel( rNewSize );
}
void SvtFileView::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
{
SetPosPixel( rNewPos );
SetSizePixel( rNewSize );
}
bool SvtFileView::Initialize( const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent>& _xContent, const OUString& rFilter )
{
WaitObject aWaitCursor( this );
mpImp->Clear();
::ucbhelper::Content aContent(_xContent, mpImp->mxCmdEnv, comphelper::getProcessComponentContext() );
FileViewResult eResult = mpImp->GetFolderContent_Impl( FolderDescriptor( aContent ), NULL );
OSL_ENSURE( eResult != eStillRunning, "SvtFileView::Initialize: this was expected to be synchronous!" );
if ( eResult != eSuccess )
return false;
mpImp->FilterFolderContent_Impl( rFilter );
mpImp->SortFolderContent_Impl(); // possibly not necessary!!!!!!!!!!
mpImp->CreateDisplayText_Impl();
mpImp->OpenFolder_Impl();
mpImp->maOpenDoneLink.Call( this );
return true;
}
FileViewResult SvtFileView::Initialize(
const OUString& rURL,
const OUString& rFilter,
const FileViewAsyncAction* pAsyncDescriptor,
const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
{
WaitObject aWaitCursor( this );
mpBlackList = rBlackList;
OUString sPushURL( mpImp->maViewURL );
mpImp->maViewURL = rURL;
FileViewResult eResult = ExecuteFilter( rFilter, pAsyncDescriptor );
switch ( eResult )
{
case eFailure:
case eTimeout:
mpImp->maViewURL = sPushURL;
return eResult;
case eStillRunning:
OSL_ENSURE( pAsyncDescriptor, "SvtFileView::Initialize: we told it to read synchronously!" );
case eSuccess:
return eResult;
}
OSL_FAIL( "SvtFileView::Initialize: unreachable!" );
return eFailure;
}
FileViewResult SvtFileView::ExecuteFilter( const OUString& rFilter, const FileViewAsyncAction* pAsyncDescriptor )
{
mpImp->maCurrentFilter = rFilter.toAsciiLowerCase();
mpImp->Clear();
FileViewResult eResult = mpImp->GetFolderContent_Impl( mpImp->maViewURL, pAsyncDescriptor, mpBlackList );
OSL_ENSURE( ( eResult != eStillRunning ) || pAsyncDescriptor, "SvtFileView::ExecuteFilter: we told it to read synchronously!" );
return eResult;
}
void SvtFileView::CancelRunningAsyncAction()
{
mpImp->CancelRunningAsyncAction();
}
void SvtFileView::SetNoSelection()
{
mpImp->mpView->SelectAll( false );
}
void SvtFileView::GetFocus()
{
Control::GetFocus();
if ( mpImp && mpImp->mpView )
mpImp->mpView->GrabFocus();
}
void SvtFileView::SetSelectHdl( const Link<SvTreeListBox*,void>& rHdl )
{
mpImp->SetSelectHandler( rHdl );
}
void SvtFileView::SetDoubleClickHdl( const Link<SvTreeListBox*,bool>& rHdl )
{
mpImp->mpView->SetDoubleClickHdl( rHdl );
}
sal_uLong SvtFileView::GetSelectionCount() const
{
return mpImp->mpView->GetSelectionCount();
}
SvTreeListEntry* SvtFileView::FirstSelected() const
{
return mpImp->mpView->FirstSelected();
}
SvTreeListEntry* SvtFileView::NextSelected( SvTreeListEntry* pEntry ) const
{
return mpImp->mpView->NextSelected( pEntry );
}
void SvtFileView::EnableAutoResize()
{
mpImp->mpView->EnableAutoResize();
}
const OUString& SvtFileView::GetViewURL() const
{
return mpImp->maViewURL;
}
void SvtFileView::SetOpenDoneHdl( const Link<SvtFileView*,void>& rHdl )
{
mpImp->maOpenDoneLink = rHdl;
}
void SvtFileView::EnableDelete( bool bEnable )
{
mpImp->EnableDelete( bEnable );
}
void SvtFileView::EndInplaceEditing( bool _bCancel )
{
return mpImp->EndEditing( _bCancel );
}
IMPL_LINK_TYPED( SvtFileView, HeaderSelect_Impl, HeaderBar*, pBar, void )
{
DBG_ASSERT( pBar, "no headerbar" );
sal_uInt16 nItemID = pBar->GetCurItemId();
HeaderBarItemBits nBits;
// clear the arrow of the recently used column
if ( nItemID != mpImp->mnSortColumn )
{
if ( !nItemID )
{
// first call -> remove arrow from title column,
// because another column is the sort column
nItemID = mpImp->mnSortColumn;
mpImp->mnSortColumn = COLUMN_TITLE;
}
nBits = pBar->GetItemBits( mpImp->mnSortColumn );
nBits &= ~HeaderBarItemBits( HeaderBarItemBits::UPARROW | HeaderBarItemBits::DOWNARROW );
pBar->SetItemBits( mpImp->mnSortColumn, nBits );
}
nBits = pBar->GetItemBits( nItemID );
bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW );
if ( bUp )
{
nBits &= ~HeaderBarItemBits::UPARROW;
nBits |= HeaderBarItemBits::DOWNARROW;
}
else
{
nBits &= ~HeaderBarItemBits::DOWNARROW;
nBits |= HeaderBarItemBits::UPARROW;
}
pBar->SetItemBits( nItemID, nBits );
mpImp->Resort_Impl( nItemID, !bUp );
}
IMPL_LINK_TYPED( SvtFileView, HeaderEndDrag_Impl, HeaderBar*, pBar, void )
{
if ( !pBar->IsItemMode() )
{
Size aSize;
sal_uInt16 nTabs = pBar->GetItemCount();
long nTmpSize = 0;
for ( sal_uInt16 i = 1; i <= nTabs; ++i )
{
long nWidth = pBar->GetItemSize(i);
aSize.Width() = nWidth + nTmpSize;
nTmpSize += nWidth;
mpImp->mpView->SetTab( i, aSize.Width(), MAP_PIXEL );
}
}
}
OUString SvtFileView::GetConfigString() const
{
OUString sRet;
HeaderBar* pBar = mpImp->mpView->GetHeaderBar();
DBG_ASSERT( pBar, "invalid headerbar" );
// sort order
sRet += OUString::number( mpImp->mnSortColumn );
sRet += ";";
HeaderBarItemBits nBits = pBar->GetItemBits( mpImp->mnSortColumn );
bool bUp = ( ( nBits & HeaderBarItemBits::UPARROW ) == HeaderBarItemBits::UPARROW );
sRet += bUp ? OUString("1") : OUString("0");
sRet += ";";
sal_uInt16 nCount = pBar->GetItemCount();
for ( sal_uInt16 i = 0; i < nCount; ++i )
{
sal_uInt16 nId = pBar->GetItemId(i);
sRet += OUString::number( nId );
sRet += ";";
sRet += OUString::number( pBar->GetItemSize( nId ) );
sRet += ";";
}
sRet = comphelper::string::stripEnd(sRet, ';');
return sRet;
}
::std::vector< SvtContentEntry > SvtFileView::GetContent()
{
::std::vector< SvtContentEntry > aContent;
for( ::std::vector< SortingData_Impl* >::size_type i = 0; i < mpImp->maContent.size(); i++ )
{
SvtContentEntry aEntry( mpImp->maContent[i]->maTargetURL, mpImp->maContent[i]->mbIsFolder );
aContent.push_back( aEntry );
}
return aContent;
}
void SvtFileView::SetConfigString( const OUString& rCfgStr )
{
HeaderBar* pBar = mpImp->mpView->GetHeaderBar();
DBG_ASSERT( pBar, "invalid headerbar" );
sal_Int32 nIdx = 0;
mpImp->mnSortColumn = (sal_uInt16)rCfgStr.getToken( 0, ';', nIdx ).toInt32();
bool bUp = (bool)(sal_uInt16)rCfgStr.getToken( 0, ';', nIdx ).toInt32();
HeaderBarItemBits nBits = pBar->GetItemBits( mpImp->mnSortColumn );
if ( bUp )
{
nBits &= ~HeaderBarItemBits::UPARROW;
nBits |= HeaderBarItemBits::DOWNARROW;
}
else
{
nBits &= ~HeaderBarItemBits::DOWNARROW;
nBits |= HeaderBarItemBits::UPARROW;
}
pBar->SetItemBits( mpImp->mnSortColumn, nBits );
while ( nIdx != -1 )
{
sal_uInt16 nItemId = (sal_uInt16)rCfgStr.getToken( 0, ';', nIdx ).toInt32();
pBar->SetItemSize( nItemId, rCfgStr.getToken( 0, ';', nIdx ).toInt32() );
}
HeaderSelect_Impl( pBar );
HeaderEndDrag_Impl( pBar );
}
void SvtFileView::StateChanged( StateChangedType nStateChange )
{
if ( nStateChange == StateChangedType::Enable )
Invalidate();
Control::StateChanged( nStateChange );
}
// class NameTranslator_Impl
NameTranslator_Impl::NameTranslator_Impl( const INetURLObject& rActualFolder )
{
mpActFolder = new NameTranslationList( rActualFolder );
}
NameTranslator_Impl::~NameTranslator_Impl()
{
delete mpActFolder;
}
void NameTranslator_Impl::SetActualFolder( const INetURLObject& rActualFolder )
{
if( mpActFolder )
{
if (mpActFolder->GetHashedURL() != rActualFolder.GetMainURL(INetURLObject::NO_DECODE))
{
delete mpActFolder;
mpActFolder = new NameTranslationList( rActualFolder );
}
}
else
mpActFolder = new NameTranslationList( rActualFolder );
}
bool NameTranslator_Impl::GetTranslation( const OUString& rOrg, OUString& rTrans ) const
{
bool bRet = false;
if( mpActFolder )
{
const OUString* pTrans = mpActFolder->Translate( rOrg );
if( pTrans )
{
rTrans = *pTrans;
bRet = true;
}
}
return bRet;
}
const OUString* NameTranslator_Impl::GetTransTableFileName() const
{
return mpActFolder? &mpActFolder->GetTransTableFileName() : NULL;
}
// class SvtFileView_Impl
SvtFileView_Impl::SvtFileView_Impl( SvtFileView* pAntiImpl, Reference < XCommandEnvironment > xEnv, FileViewFlags nFlags, bool bOnlyFolder )
:mpAntiImpl ( pAntiImpl )
,m_eAsyncActionResult ( ::svt::ERROR )
,m_bRunningAsyncAction ( false )
,m_bAsyncActionCancelled ( false )
,mpNameTrans ( NULL )
,mnSortColumn ( COLUMN_TITLE )
,mbAscending ( true )
,mbOnlyFolder ( bOnlyFolder )
,mbReplaceNames ( false )
,mnSuspendSelectCallback ( 0 )
,mbIsFirstResort ( true )
,aIntlWrapper ( Application::GetSettings().GetLanguageTag() )
,maFolderImage ( SvtResId( IMG_SVT_FOLDER ) )
,mxCmdEnv ( xEnv )
{
maAllFilter = "*.*";
mpView = VclPtr<ViewTabListBox_Impl>::Create( mpAntiImpl, this, nFlags );
mpView->EnableCellFocus();
}
SvtFileView_Impl::~SvtFileView_Impl()
{
Clear();
mpView.disposeAndClear();
}
void SvtFileView_Impl::Clear()
{
::osl::MutexGuard aGuard( maMutex );
std::vector< SortingData_Impl* >::iterator aIt;
for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
delete (*aIt);
maContent.clear();
if( mpNameTrans )
DELETEZ( mpNameTrans );
}
FileViewResult SvtFileView_Impl::GetFolderContent_Impl(
const OUString& rFolder,
const FileViewAsyncAction* pAsyncDescriptor,
const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
{
::osl::ClearableMutexGuard aGuard( maMutex );
INetURLObject aFolderObj( rFolder );
DBG_ASSERT( aFolderObj.GetProtocol() != INetProtocol::NotValid, "Invalid URL!" );
// prepare name translation
SetActualFolder( aFolderObj );
FolderDescriptor aFolder( aFolderObj.GetMainURL( INetURLObject::NO_DECODE ) );
aGuard.clear();
return GetFolderContent_Impl( aFolder, pAsyncDescriptor, rBlackList );
}
FileViewResult SvtFileView_Impl::GetFolderContent_Impl(
const FolderDescriptor& _rFolder,
const FileViewAsyncAction* pAsyncDescriptor,
const ::com::sun::star::uno::Sequence< OUString >& rBlackList )
{
DBG_TESTSOLARMUTEX();
::osl::ClearableMutexGuard aGuard( maMutex );
OSL_ENSURE( !m_xContentEnumerator.is(), "SvtFileView_Impl::GetFolderContent_Impl: still running another enumeration!" );
m_xContentEnumerator.set(new ::svt::FileViewContentEnumerator(
mpView->GetCommandEnvironment(), maContent, maMutex, mbReplaceNames ? mpNameTrans : NULL));
// TODO: should we cache and re-use this thread?
if ( !pAsyncDescriptor )
{
::svt::EnumerationResult eResult = m_xContentEnumerator->enumerateFolderContentSync( _rFolder, rBlackList );
if ( ::svt::SUCCESS == eResult )
{
implEnumerationSuccess();
m_xContentEnumerator.clear();
return eSuccess;
}
m_xContentEnumerator.clear();
return eFailure;
}
m_bRunningAsyncAction = true;
m_bAsyncActionCancelled = false;
m_eAsyncActionResult = ::svt::ERROR;
m_aAsyncActionFinished.reset();
// don't (yet) set m_aCurrentAsyncActionHandler to pTimeout->aFinishHandler.
// By definition, this handler *only* get's called when the result cannot be obtained
// during the minimum wait time, so it is only set below, when needed.
m_aCurrentAsyncActionHandler = Link<void*,void>();
// minimum time to wait
std::unique_ptr< TimeValue > pTimeout( new TimeValue );
sal_Int32 nMinTimeout = pAsyncDescriptor->nMinTimeout;
OSL_ENSURE( nMinTimeout > 0, "SvtFileView_Impl::GetFolderContent_Impl: invalid minimum timeout!" );
if ( nMinTimeout <= 0 )
nMinTimeout = sal_Int32( 1000L );
pTimeout->Seconds = nMinTimeout / 1000L;
pTimeout->Nanosec = ( nMinTimeout % 1000L ) * 1000000L;
m_xContentEnumerator->enumerateFolderContent( _rFolder, this );
// wait until the enumeration is finished
// for this, release our own mutex (which is used by the enumerator thread)
aGuard.clear();
::osl::Condition::Result eResult = ::osl::Condition::result_ok;
{
// also release the SolarMutex. Not all code which is needed during the enumeration
// is Solar-Thread-Safe, in particular there is some code which needs to access
// string resources (and our resource system relies on the SolarMutex :()
SolarMutexReleaser aSolarRelease;
// now wait. Note that if we didn't get an pAsyncDescriptor, then this is an infinite wait.
eResult = m_aAsyncActionFinished.wait( pTimeout.get() );
}
::osl::MutexGuard aGuard2( maMutex );
if ( ::osl::Condition::result_timeout == eResult )
{
// maximum time to wait
OSL_ENSURE( !m_xCancelAsyncTimer.get(), "SvtFileView_Impl::GetFolderContent_Impl: there's still a previous timer!" );
m_xCancelAsyncTimer.set(new CallbackTimer(this));
sal_Int32 nMaxTimeout = pAsyncDescriptor->nMaxTimeout;
OSL_ENSURE( nMaxTimeout > nMinTimeout,
"SvtFileView_Impl::GetFolderContent_Impl: invalid maximum timeout!" );
if ( nMaxTimeout <= nMinTimeout )
nMaxTimeout = nMinTimeout + 5000;
m_xCancelAsyncTimer->setRemainingTime( salhelper::TTimeValue( nMaxTimeout - nMinTimeout ) );
// we already waited for nMinTimeout milliseconds, so take this into account
m_xCancelAsyncTimer->start();
m_aCurrentAsyncActionHandler = pAsyncDescriptor->aFinishHandler;
DBG_ASSERT( m_aCurrentAsyncActionHandler.IsSet(), "SvtFileView_Impl::GetFolderContent_Impl: nobody interested when it's finished?" );
mpView->ClearAll();
return eStillRunning;
}
m_bRunningAsyncAction = false;
switch ( m_eAsyncActionResult )
{
case ::svt::SUCCESS:
return eSuccess;
case ::svt::ERROR:
return eFailure;
case ::svt::RUNNING:
return eStillRunning;
}
SAL_WARN( "svtools.contnr", "SvtFileView_Impl::GetFolderContent_Impl: unreachable!" );
return eFailure;
}
void SvtFileView_Impl::FilterFolderContent_Impl( const OUString &rFilter )
{
bool bHideTransFile = mbReplaceNames && mpNameTrans;
OUString sHideEntry;
if( bHideTransFile )
{
const OUString* pTransTableFileName = mpNameTrans->GetTransTableFileName();
if( pTransTableFileName )
{
sHideEntry = *pTransTableFileName;
sHideEntry = sHideEntry.toAsciiUpperCase();
}
else
bHideTransFile = false;
}
if ( !bHideTransFile &&
( rFilter.isEmpty() || ( rFilter == ALL_FILES_FILTER ) ) )
// when replacing names, there is always something to filter (no view of ".nametranslation.table")
return;
::osl::MutexGuard aGuard( maMutex );
if ( maContent.empty() )
return;
// count (estimate) the number of filter tokens
sal_Int32 nTokens=0;
const sal_Unicode* pStart = rFilter.getStr();
const sal_Unicode* pEnd = pStart + rFilter.getLength();
while ( pStart != pEnd )
if ( *pStart++ == ';' )
++nTokens;
// collect the filter tokens
::std::vector< WildCard > aFilters;
FilterMatch::createWildCardFilterList(rFilter,aFilters);
// do the filtering
::std::vector< SortingData_Impl* >::iterator aContentLoop = maContent.begin();
OUString sCompareString;
do
{
if ( (*aContentLoop)->mbIsFolder )
++aContentLoop;
else
{
// normalize the content title (we always match case-insensitive)
// 91872 - 11.09.2001 - frank.schoenheit@sun.com
sCompareString = (*aContentLoop)->GetFileName(); // filter works on file name, not on title!
bool bDelete;
if( bHideTransFile && sCompareString == sHideEntry )
bDelete = true;
else
{
bDelete = ::std::none_of( aFilters.begin(), aFilters.end(),
FilterMatch( sCompareString ) );
}
if( bDelete )
{
// none of the filters did match
delete *aContentLoop;
if ( maContent.begin() == aContentLoop )
{
maContent.erase( aContentLoop );
aContentLoop = maContent.begin();
}
else
{
std::vector< SortingData_Impl* >::iterator aDelete = aContentLoop;
--aContentLoop; // move the iterator to a position which is not invalidated by the erase
maContent.erase( aDelete );
++aContentLoop; // this is now the next one ....
}
}
else
++aContentLoop;
}
}
while ( aContentLoop != maContent.end() );
}
IMPL_LINK_TYPED( SvtFileView_Impl, SelectionMultiplexer, SvTreeListBox*, _pSource, void )
{
if (!mnSuspendSelectCallback)
m_aSelectHandler.Call( _pSource );
}
void SvtFileView_Impl::SetSelectHandler( const Link<SvTreeListBox*,void>& _rHdl )
{
m_aSelectHandler = _rHdl;
Link<SvTreeListBox*,void> aMasterHandler;
if ( m_aSelectHandler.IsSet() )
aMasterHandler = LINK( this, SvtFileView_Impl, SelectionMultiplexer );
mpView->SetSelectHdl( aMasterHandler );
}
void SvtFileView_Impl::InitSelection()
{
mpView->SelectAll( false );
SvTreeListEntry* pFirst = mpView->First();
if ( pFirst )
mpView->SetCursor( pFirst, true );
}
void SvtFileView_Impl::OpenFolder_Impl()
{
::osl::MutexGuard aGuard( maMutex );
mpView->SetUpdateMode( false );
mpView->ClearAll();
std::vector< SortingData_Impl* >::iterator aIt;
for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
{
if ( mbOnlyFolder && ! (*aIt)->mbIsFolder )
continue;
// insert entry and set user data
SvTreeListEntry* pEntry = mpView->InsertEntry( (*aIt)->maDisplayText,
(*aIt)->maImage,
(*aIt)->maImage );
SvtContentEntry* pUserData = new SvtContentEntry( (*aIt)->maTargetURL,
(*aIt)->mbIsFolder );
pEntry->SetUserData( pUserData );
}
InitSelection();
++mnSuspendSelectCallback;
mpView->SetUpdateMode( true );
--mnSuspendSelectCallback;
ResetCursor();
}
void SvtFileView_Impl::ResetCursor()
{
// deselect
SvTreeListEntry* pEntry = mpView->FirstSelected();
if ( pEntry )
mpView->Select( pEntry, false );
// set cursor to the first entry
mpView->SetCursor( mpView->First(), true );
mpView->Update();
}
void SvtFileView_Impl::CancelRunningAsyncAction()
{
DBG_TESTSOLARMUTEX();
::osl::MutexGuard aGuard( maMutex );
if ( !m_xContentEnumerator.is() )
return;
m_bAsyncActionCancelled = true;
m_xContentEnumerator->cancel();
m_bRunningAsyncAction = false;
m_xContentEnumerator.clear();
if ( m_xCancelAsyncTimer.is() && m_xCancelAsyncTimer->isTicking() )
m_xCancelAsyncTimer->stop();
m_xCancelAsyncTimer.clear();
}
void SvtFileView_Impl::onTimeout( CallbackTimer* )
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( maMutex );
if ( !m_bRunningAsyncAction )
// there might have been a race condition while we waited for the mutex
return;
CancelRunningAsyncAction();
if ( m_aCurrentAsyncActionHandler.IsSet() )
{
Application::PostUserEvent( m_aCurrentAsyncActionHandler, reinterpret_cast< void* >( eTimeout ) );
m_aCurrentAsyncActionHandler = Link<void*,void>();
}
}
void SvtFileView_Impl::enumerationDone( ::svt::EnumerationResult eResult )
{
SolarMutexGuard aSolarGuard;
::osl::MutexGuard aGuard( maMutex );
m_xContentEnumerator.clear();
if ( m_xCancelAsyncTimer.is() && m_xCancelAsyncTimer->isTicking() )
m_xCancelAsyncTimer->stop();
m_xCancelAsyncTimer.clear();
if ( m_bAsyncActionCancelled )
// this is to prevent race conditions
return;
m_eAsyncActionResult = eResult;
m_bRunningAsyncAction = false;
m_aAsyncActionFinished.set();
if ( svt::SUCCESS == eResult )
implEnumerationSuccess();
if ( m_aCurrentAsyncActionHandler.IsSet() )
{
Application::PostUserEvent( m_aCurrentAsyncActionHandler, reinterpret_cast< void* >( m_eAsyncActionResult ) );
m_aCurrentAsyncActionHandler = Link<void*,void>();
}
}
void SvtFileView_Impl::implEnumerationSuccess()
{
FilterFolderContent_Impl( maCurrentFilter );
SortFolderContent_Impl();
CreateDisplayText_Impl();
OpenFolder_Impl();
maOpenDoneLink.Call( mpAntiImpl );
}
void SvtFileView_Impl::ReplaceTabWithString( OUString& aValue )
{
OUString aTab( "\t" );
OUString aTabString( "%09" );
sal_Int32 iPos;
while ( ( iPos = aValue.indexOf( aTab ) ) >= 0 )
aValue = aValue.replaceAt( iPos, 1, aTabString );
}
void SvtFileView_Impl::CreateDisplayText_Impl()
{
::osl::MutexGuard aGuard( maMutex );
OUString aValue;
OUString aTab( "\t" );
OUString aDateSep( ", " );
std::vector< SortingData_Impl* >::iterator aIt;
for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
{
// title, type, size, date
aValue = (*aIt)->GetTitle();
// #83004# --------------------
ReplaceTabWithString( aValue );
aValue += aTab;
aValue += (*aIt)->maType;
aValue += aTab;
// folders don't have a size
if ( ! (*aIt)->mbIsFolder )
aValue += CreateExactSizeText( (*aIt)->maSize );
aValue += aTab;
// set the date, but volumes have no date
if ( ! (*aIt)->mbIsFolder || ! (*aIt)->mbIsVolume )
{
SvtSysLocale aSysLocale;
const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
aValue += rLocaleData.getDate( (*aIt)->maModDate );
aValue += aDateSep;
aValue += rLocaleData.getTime( (*aIt)->maModDate, false );
}
(*aIt)->maDisplayText = aValue;
// detect image
if ( (*aIt)->mbIsFolder )
{
::svtools::VolumeInfo aVolInfo( (*aIt)->mbIsVolume, (*aIt)->mbIsRemote,
(*aIt)->mbIsRemoveable, (*aIt)->mbIsFloppy,
(*aIt)->mbIsCompactDisc );
(*aIt)->maImage = SvFileInformationManager::GetFolderImage( aVolInfo );
}
else
(*aIt)->maImage = SvFileInformationManager::GetFileImage( INetURLObject( (*aIt)->maTargetURL ) );
}
}
void SvtFileView_Impl::Resort_Impl( sal_Int16 nColumn, bool bAscending )
{
::osl::MutexGuard aGuard( maMutex );
if ( ( nColumn == mnSortColumn ) &&
( bAscending == mbAscending ) )
return;
// reset the quick search index
mpView->ResetQuickSearch_Impl( NULL );
OUString aEntryURL;
SvTreeListEntry* pEntry = mpView->GetCurEntry();
if ( pEntry && pEntry->GetUserData() )
aEntryURL = static_cast<SvtContentEntry*>(pEntry->GetUserData())->maURL;
mnSortColumn = nColumn;
mbAscending = bAscending;
SortFolderContent_Impl();
OpenFolder_Impl();
if ( !mbIsFirstResort )
{
sal_uLong nPos = GetEntryPos( aEntryURL );
if ( nPos < mpView->GetEntryCount() )
{
pEntry = mpView->GetEntry( nPos );
++mnSuspendSelectCallback; // #i15668#
mpView->SetCurEntry( pEntry );
--mnSuspendSelectCallback;
}
}
else
mbIsFirstResort = false;
}
static bool gbAscending = true;
static sal_Int16 gnColumn = COLUMN_TITLE;
static const CollatorWrapper* pCollatorWrapper = NULL;
/* this function returns true, if aOne is less then aTwo
*/
bool CompareSortingData_Impl( SortingData_Impl* const aOne, SortingData_Impl* const aTwo )
{
DBG_ASSERT( pCollatorWrapper, "*CompareSortingData_Impl(): Can't work this way!" );
sal_Int32 nComp;
bool bRet = false;
bool bEqual = false;
if ( aOne->mbIsFolder != aTwo->mbIsFolder )
{
if ( aOne->mbIsFolder )
bRet = true;
else
bRet = false;
// !!! pb: #100376# folder always on top
if ( !gbAscending )
bRet = !bRet;
}
else
{
switch ( gnColumn )
{
case COLUMN_TITLE:
// compare case insensitive first
nComp = pCollatorWrapper->compareString( aOne->GetLowerTitle(), aTwo->GetLowerTitle() );
if ( nComp == 0 )
nComp = pCollatorWrapper->compareString( aOne->GetTitle(), aTwo->GetTitle() );
if ( nComp < 0 )
bRet = true;
else if ( nComp > 0 )
bRet = false;
else
bEqual = true;
break;
case COLUMN_TYPE:
nComp = pCollatorWrapper->compareString( aOne->maType, aTwo->maType );
if ( nComp < 0 )
bRet = true;
else if ( nComp > 0 )
bRet = false;
else
bEqual = true;
break;
case COLUMN_SIZE:
if ( aOne->maSize < aTwo->maSize )
bRet = true;
else if ( aOne->maSize > aTwo->maSize )
bRet = false;
else
bEqual = true;
break;
case COLUMN_DATE:
if ( aOne->maModDate < aTwo->maModDate )
bRet = true;
else if ( aOne->maModDate > aTwo->maModDate )
bRet = false;
else
bEqual = true;
break;
default:
DBG_WARNING( "CompareSortingData_Impl: Compare unknown type!" );
bRet = false;
}
}
// when the two elements are equal, we must not return sal_True (which would
// happen if we just return ! ( a < b ) when not sorting ascending )
if ( bEqual )
return false;
return gbAscending ? bRet : !bRet;
}
void SvtFileView_Impl::SortFolderContent_Impl()
{
::osl::MutexGuard aGuard( maMutex );
sal_uInt32 nSize = maContent.size();
if ( nSize > 1 )
{
gbAscending = mbAscending;
gnColumn = mnSortColumn;
pCollatorWrapper = aIntlWrapper.getCaseCollator();
std::stable_sort( maContent.begin(), maContent.end(), CompareSortingData_Impl );
pCollatorWrapper = NULL;
}
}
void SvtFileView_Impl::EntryRemoved( const OUString& rURL )
{
::osl::MutexGuard aGuard( maMutex );
std::vector< SortingData_Impl* >::iterator aIt;
for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
{
if ( (*aIt)->maTargetURL == rURL )
{
maContent.erase( aIt );
break;
}
}
}
void SvtFileView_Impl::EntryRenamed( OUString& rURL,
const OUString& rTitle )
{
::osl::MutexGuard aGuard( maMutex );
std::vector< SortingData_Impl* >::iterator aIt;
for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
{
if ( (*aIt)->maTargetURL == rURL )
{
(*aIt)->SetNewTitle( rTitle );
OUString aDisplayText = (*aIt)->maDisplayText;
sal_Int32 nIndex = aDisplayText.indexOf( '\t' );
if ( nIndex > 0 )
(*aIt)->maDisplayText = aDisplayText.replaceAt( 0, nIndex, rTitle );
INetURLObject aURLObj( rURL );
aURLObj.SetName( rTitle, INetURLObject::ENCODE_ALL );
rURL = aURLObj.GetMainURL( INetURLObject::NO_DECODE );
(*aIt)->maTargetURL = rURL;
break;
}
}
}
OUString SvtFileView_Impl::FolderInserted( const OUString& rURL, const OUString& rTitle )
{
::osl::MutexGuard aGuard( maMutex );
SortingData_Impl* pData = new SortingData_Impl;
pData->SetNewTitle( rTitle );
pData->maSize = 0;
pData->mbIsFolder = true;
pData->maTargetURL = rURL;
::svtools::VolumeInfo aVolInfo;
pData->maType = SvFileInformationManager::GetFolderDescription( aVolInfo );
pData->maImage = SvFileInformationManager::GetFolderImage( aVolInfo );
OUString aValue;
OUString aTab( "\t" );
OUString aDateSep( ", " );
// title, type, size, date
aValue = pData->GetTitle();
ReplaceTabWithString( aValue );
aValue += aTab;
aValue += pData->maType;
aValue += aTab;
// folders don't have a size
aValue += aTab;
// set the date
SvtSysLocale aSysLocale;
const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData();
aValue += rLocaleData.getDate( pData->maModDate );
aValue += aDateSep;
aValue += rLocaleData.getTime( pData->maModDate );
pData->maDisplayText = aValue;
maContent.push_back( pData );
return aValue;
}
sal_uLong SvtFileView_Impl::GetEntryPos( const OUString& rURL )
{
::osl::MutexGuard aGuard( maMutex );
std::vector< SortingData_Impl* >::iterator aIt;
sal_uLong nPos = 0;
for ( aIt = maContent.begin(); aIt != maContent.end(); ++aIt )
{
if ( (*aIt)->maTargetURL == rURL )
return nPos;
nPos += 1;
}
return nPos;
}
bool SvtFileView_Impl::SearchNextEntry( sal_uInt32& nIndex, const OUString& rTitle, bool bWrapAround )
{
::osl::MutexGuard aGuard( maMutex );
sal_uInt32 nEnd = maContent.size();
sal_uInt32 nStart = nIndex;
while ( nIndex < nEnd )
{
SortingData_Impl* pData = maContent[ nIndex ];
if ( pData->GetLowerTitle().startsWith( rTitle ) )
return true;
nIndex += 1;
}
if ( bWrapAround )
{
nIndex = 0;
while ( nIndex < nEnd && nIndex <= nStart )
{
SortingData_Impl* pData = maContent[ nIndex ];
if ( pData->GetLowerTitle().startsWith( rTitle ) )
return true;
nIndex += 1;
}
}
return false;
}
void SvtFileView_Impl::SetActualFolder( const INetURLObject& rActualFolder )
{
if( mbReplaceNames )
{
if( mpNameTrans )
mpNameTrans->SetActualFolder( rActualFolder );
else
mpNameTrans = new NameTranslator_Impl( rActualFolder );
}
}
namespace svtools {
QueryDeleteDlg_Impl::QueryDeleteDlg_Impl(vcl::Window* pParent, const OUString& rName)
: MessageDialog(pParent, "QueryDeleteDialog", "svt/ui/querydeletedialog.ui")
{
get(m_pAllButton, "all");
// display specified texts
set_secondary_text(get_secondary_text().replaceFirst("%s", rName));
}
QueryDeleteDlg_Impl::~QueryDeleteDlg_Impl()
{
disposeOnce();
}
void QueryDeleteDlg_Impl::dispose()
{
m_pAllButton.clear();
MessageDialog::dispose();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|