Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <svtools/imagemgr.hxx>
21 : #include <tools/urlobj.hxx>
22 : #include <tools/debug.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <vcl/wrkwin.hxx>
25 : #include <vcl/image.hxx>
26 : #include <vcl/settings.hxx>
27 : #include <sot/storage.hxx>
28 : #include <comphelper/classids.hxx>
29 : #include <unotools/ucbhelper.hxx>
30 : #include <comphelper/processfactory.hxx>
31 : #include <com/sun/star/beans/PropertyValue.hpp>
32 : #include <com/sun/star/container/XNameContainer.hpp>
33 : #include <com/sun/star/document/XTypeDetection.hpp>
34 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
36 : #include <ucbhelper/content.hxx>
37 : #include <tools/rcid.h>
38 : #include <unotools/configmgr.hxx>
39 : #include <svtools/svtools.hrc>
40 : #include <svtools/imagemgr.hrc>
41 : #include <svtools/svtresid.hxx>
42 : #include <osl/mutex.hxx>
43 : #include <vcl/lazydelete.hxx>
44 :
45 : // globals *******************************************************************
46 :
47 : #define NO_INDEX (-1)
48 : #define CONTENT_HELPER ::utl::UCBContentHelper
49 :
50 : struct SvtExtensionResIdMapping_Impl
51 : {
52 : const char* _pExt;
53 : bool _bExt;
54 : sal_uInt16 _nStrId;
55 : sal_uInt16 _nImgId;
56 : };
57 :
58 : static SvtExtensionResIdMapping_Impl const ExtensionMap_Impl[] =
59 : {
60 : { "awk", true, STR_DESCRIPTION_SOURCEFILE, 0 },
61 : { "bas", true, STR_DESCRIPTION_SOURCEFILE, 0 },
62 : { "bat", true, STR_DESCRIPTION_BATCHFILE, 0 },
63 : { "bmk", false, STR_DESCRIPTION_BOOKMARKFILE, 0 },
64 : { "bmp", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_BITMAP },
65 : { "c", true, STR_DESCRIPTION_SOURCEFILE, 0 },
66 : { "cfg", false, STR_DESCRIPTION_CFGFILE, 0 },
67 : { "cmd", true, STR_DESCRIPTION_BATCHFILE, 0 },
68 : { "cob", true, STR_DESCRIPTION_SOURCEFILE, 0 },
69 : { "com", true, STR_DESCRIPTION_APPLICATION, 0 },
70 : { "cxx", true, STR_DESCRIPTION_SOURCEFILE, 0 },
71 : { "dbf", true, STR_DESCRIPTION_DATABASE_TABLE, IMG_TABLE },
72 : { "def", true, STR_DESCRIPTION_SOURCEFILE, 0 },
73 : { "dll", true, STR_DESCRIPTION_SYSFILE, 0 },
74 : { "doc", false, STR_DESCRIPTION_WORD_DOC, IMG_WRITER },
75 : { "dot", false, STR_DESCRIPTION_WORD_DOC, IMG_WRITERTEMPLATE },
76 : { "docx", false, STR_DESCRIPTION_WORD_DOC, IMG_WRITER },
77 : { "dxf", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_DXF },
78 : { "exe", true, STR_DESCRIPTION_APPLICATION, 0 },
79 : { "gif", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_GIF },
80 : { "h", true, STR_DESCRIPTION_SOURCEFILE, 0 },
81 : { "hlp", false, STR_DESCRIPTION_HELP_DOC, 0 },
82 : { "hrc", true, STR_DESCRIPTION_SOURCEFILE, 0 },
83 : { "htm", false, STR_DESCRIPTION_HTMLFILE, IMG_HTML },
84 : { "html", false, STR_DESCRIPTION_HTMLFILE, IMG_HTML },
85 : { "asp", false, STR_DESCRIPTION_HTMLFILE, IMG_HTML },
86 : { "hxx", true, STR_DESCRIPTION_SOURCEFILE, 0 },
87 : { "ini", false, STR_DESCRIPTION_CFGFILE, 0 },
88 : { "java", true, STR_DESCRIPTION_SOURCEFILE, 0 },
89 : { "jpeg", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_JPG },
90 : { "jpg", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_JPG },
91 : { "lha", true, STR_DESCRIPTION_ARCHIVFILE, 0 },
92 : #ifdef WNT
93 : { "lnk", false, 0, 0 },
94 : #endif
95 : { "log", true, STR_DESCRIPTION_LOGFILE, 0 },
96 : { "lst", true, STR_DESCRIPTION_LOGFILE, 0 },
97 : { "met", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_MET },
98 : { "mml", false, STR_DESCRIPTION_MATHML_DOC, IMG_MATH },
99 : { "mod", true, STR_DESCRIPTION_SOURCEFILE, 0 },
100 : { "odb", false, STR_DESCRIPTION_OO_DATABASE_DOC, IMG_OO_DATABASE_DOC },
101 : { "odg", false, STR_DESCRIPTION_OO_DRAW_DOC, IMG_OO_DRAW_DOC },
102 : { "odf", false, STR_DESCRIPTION_OO_MATH_DOC, IMG_OO_MATH_DOC },
103 : { "odm", false, STR_DESCRIPTION_OO_GLOBAL_DOC, IMG_OO_GLOBAL_DOC },
104 : { "odp", false, STR_DESCRIPTION_OO_IMPRESS_DOC, IMG_OO_IMPRESS_DOC },
105 : { "ods", false, STR_DESCRIPTION_OO_CALC_DOC, IMG_OO_CALC_DOC },
106 : { "odt", false, STR_DESCRIPTION_OO_WRITER_DOC, IMG_OO_WRITER_DOC },
107 : { "otg", false, STR_DESCRIPTION_OO_DRAW_TEMPLATE, IMG_OO_DRAW_TEMPLATE },
108 : { "otp", false, STR_DESCRIPTION_OO_IMPRESS_TEMPLATE, IMG_OO_IMPRESS_TEMPLATE },
109 : { "ots", false, STR_DESCRIPTION_OO_CALC_TEMPLATE, IMG_OO_CALC_TEMPLATE },
110 : { "ott", false, STR_DESCRIPTION_OO_WRITER_TEMPLATE, IMG_OO_WRITER_TEMPLATE },
111 : { "pas", true, STR_DESCRIPTION_SOURCEFILE, 0 },
112 : { "pcd", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCD },
113 : { "pct", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCT },
114 : { "pict", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCT },
115 : { "pcx", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCX },
116 : { "pl", true, STR_DESCRIPTION_SOURCEFILE, 0 },
117 : { "png", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PNG },
118 : { "rar", true, STR_DESCRIPTION_ARCHIVFILE, 0 },
119 : { "rtf", false, STR_DESCRIPTION_WORD_DOC, IMG_WRITER },
120 : { "sbl", false, 0, 0 },
121 : { "sch", false, 0, 0 },
122 : { "sda", false, STR_DESCRIPTION_SDRAW_DOC, IMG_DRAW },
123 : { "sdb", false, STR_DESCRIPTION_SDATABASE_DOC, IMG_DATABASE },
124 : { "sdc", false, STR_DESCRIPTION_SCALC_DOC, IMG_CALC },
125 : { "sdd", false, STR_DESCRIPTION_SIMPRESS_DOC, IMG_IMPRESS },
126 : { "sdp", false, STR_DESCRIPTION_SIMPRESS_DOC, 0 },
127 : { "sds", false, STR_DESCRIPTION_SCHART_DOC, 0 },
128 : { "sdw", false, STR_DESCRIPTION_SWRITER_DOC, IMG_WRITER },
129 : { "sga", false, 0, 0 },
130 : { "sgf", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SGF },
131 : { "sgl", false, STR_DESCRIPTION_GLOBALDOC, IMG_GLOBAL_DOC },
132 : { "sgv", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SGV },
133 : { "shtml", false, STR_DESCRIPTION_HTMLFILE, IMG_HTML },
134 : { "sim", false, STR_DESCRIPTION_SIMAGE_DOC, IMG_SIM },
135 : { "smf", false, STR_DESCRIPTION_SMATH_DOC, IMG_MATH },
136 : { "src", true, STR_DESCRIPTION_SOURCEFILE, 0 },
137 : { "svh", false, STR_DESCRIPTION_HELP_DOC, 0 },
138 : { "svm", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SVM },
139 : { "stc", false, STR_DESCRIPTION_CALC_TEMPLATE, IMG_CALCTEMPLATE },
140 : { "std", false, STR_DESCRIPTION_DRAW_TEMPLATE, IMG_DRAWTEMPLATE },
141 : { "sti", false, STR_DESCRIPTION_IMPRESS_TEMPLATE, IMG_IMPRESSTEMPLATE },
142 : { "stw", false, STR_DESCRIPTION_WRITER_TEMPLATE, IMG_WRITERTEMPLATE },
143 : { "sxc", false, STR_DESCRIPTION_SXCALC_DOC, IMG_CALC },
144 : { "sxd", false, STR_DESCRIPTION_SXDRAW_DOC, IMG_DRAW },
145 : { "sxg", false, STR_DESCRIPTION_SXGLOBAL_DOC, IMG_GLOBAL_DOC },
146 : { "sxi", false, STR_DESCRIPTION_SXIMPRESS_DOC, IMG_IMPRESS },
147 : { "sxm", false, STR_DESCRIPTION_SXMATH_DOC, IMG_MATH },
148 : { "sxs", false, STR_DESCRIPTION_SXCHART_DOC, 0 },
149 : { "sxw", false, STR_DESCRIPTION_SXWRITER_DOC, IMG_WRITER },
150 : { "sys", true, STR_DESCRIPTION_SYSFILE, 0 },
151 : { "tif", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_TIFF },
152 : { "tiff", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_TIFF },
153 : { "txt", false, STR_DESCRIPTION_TEXTFILE, IMG_TEXTFILE },
154 : { "url", false, STR_DESCRIPTION_LINK, 0 },
155 : { "vor", false, STR_DESCRIPTION_SOFFICE_TEMPLATE_DOC, IMG_WRITERTEMPLATE },
156 : { "vxd", true, STR_DESCRIPTION_SYSFILE, 0 },
157 : { "wmf", true, STR_DESCRIPTION_GRAPHIC_DOC, IMG_WMF },
158 : { "xls", false, STR_DESCRIPTION_EXCEL_DOC, IMG_CALC },
159 : { "xlt", false, STR_DESCRIPTION_EXCEL_TEMPLATE_DOC, IMG_CALCTEMPLATE },
160 : { "xlsx", false, STR_DESCRIPTION_EXCEL_DOC, IMG_CALC },
161 : { "uu", true, STR_DESCRIPTION_ARCHIVFILE, 0 },
162 : { "uue", true, STR_DESCRIPTION_ARCHIVFILE, 0 },
163 : { "z", true, STR_DESCRIPTION_ARCHIVFILE, 0 },
164 : { "zip", true, STR_DESCRIPTION_ARCHIVFILE, 0 },
165 : { "zoo", true, STR_DESCRIPTION_ARCHIVFILE, 0 },
166 : { "gz", true, STR_DESCRIPTION_ARCHIVFILE, 0 },
167 : { "ppt", false, STR_DESCRIPTION_POWERPOINT, IMG_IMPRESS },
168 : { "pot", false, STR_DESCRIPTION_POWERPOINT_TEMPLATE, IMG_IMPRESSTEMPLATE },
169 : { "pps", false, STR_DESCRIPTION_POWERPOINT_SHOW, IMG_IMPRESS },
170 : { "pptx", false, STR_DESCRIPTION_POWERPOINT, IMG_IMPRESS },
171 : { "oxt", false, STR_DESCRIPTION_EXTENSION, IMG_EXTENSION },
172 : { 0, false, 0, 0 }
173 : };
174 :
175 : struct SvtFactory2ExtensionMapping_Impl
176 : {
177 : const char* _pFactory;
178 : const char* _pExtension;
179 : };
180 :
181 : // mapping from "private:factory" url to extension
182 :
183 : static SvtFactory2ExtensionMapping_Impl const Fac2ExtMap_Impl[] =
184 : {
185 : { "swriter", "odt" },
186 : { "swriter/web", "html" },
187 : { "swriter/GlobalDocument", "odm" },
188 : { "scalc", "ods" },
189 : { "simpress", "odp" },
190 : { "sdraw", "odg" },
191 : { "smath", "odf" },
192 : { "sdatabase", "odb" },
193 : { NULL, NULL }
194 : };
195 :
196 :
197 :
198 12514 : static OUString GetImageExtensionByFactory_Impl( const OUString& rURL )
199 : {
200 12514 : INetURLObject aObj( rURL );
201 25028 : OUString aPath = aObj.GetURLPath( INetURLObject::NO_DECODE );
202 12514 : OUString aExtension;
203 :
204 12514 : if ( !aPath.isEmpty() )
205 : {
206 12514 : sal_uInt16 nIndex = 0;
207 56117 : while ( Fac2ExtMap_Impl[ nIndex ]._pFactory )
208 : {
209 43603 : if ( aPath.equalsAscii( Fac2ExtMap_Impl[ nIndex ]._pFactory ) )
210 : {
211 : // extension found
212 12514 : aExtension = OUString::createFromAscii(Fac2ExtMap_Impl[ nIndex ]._pExtension);
213 : // and return it
214 12514 : return aExtension;
215 : }
216 31089 : ++nIndex;
217 : }
218 : }
219 :
220 : // no extension found, so use the type detection (performance brake)
221 :
222 : try
223 : {
224 : // get the TypeDetection service to access all registered types
225 0 : ::com::sun::star::uno::Reference < ::com::sun::star::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
226 : ::com::sun::star::uno::Reference < ::com::sun::star::document::XTypeDetection > xTypeDetector(
227 0 : xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext),
228 0 : ::com::sun::star::uno::UNO_QUERY );
229 :
230 0 : OUString aInternalType = xTypeDetector->queryTypeByURL( rURL );
231 0 : ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess > xAccess( xTypeDetector, ::com::sun::star::uno::UNO_QUERY );
232 0 : ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > aTypeProps;
233 0 : if ( !aInternalType.isEmpty() && xAccess->hasByName( aInternalType ) )
234 : {
235 0 : xAccess->getByName( aInternalType ) >>= aTypeProps;
236 0 : sal_Int32 nProps = aTypeProps.getLength();
237 0 : for ( sal_Int32 i = 0; i < nProps; ++i )
238 : {
239 0 : const ::com::sun::star::beans::PropertyValue& rProp = aTypeProps[i];
240 0 : if (rProp.Name == "Extensions")
241 : {
242 0 : ::com::sun::star::uno::Sequence < OUString > aExtensions;
243 0 : if ( ( rProp.Value >>= aExtensions ) && aExtensions.getLength() > 0 )
244 : {
245 0 : const OUString* pExtensions = aExtensions.getConstArray();
246 0 : aExtension = OUString( pExtensions[0] );
247 0 : break;
248 0 : }
249 : }
250 : }
251 0 : }
252 : }
253 0 : catch( const ::com::sun::star::uno::RuntimeException& )
254 : {
255 0 : throw; // dont hide it!
256 : }
257 0 : catch( const ::com::sun::star::uno::Exception& )
258 : {
259 : // type detection failed -> no extension
260 : }
261 :
262 12514 : return aExtension;
263 : }
264 :
265 12514 : static sal_Int32 GetIndexOfExtension_Impl( const OUString& rExtension )
266 : {
267 12514 : sal_Int32 nRet = NO_INDEX;
268 12514 : if ( !rExtension.isEmpty() )
269 : {
270 12514 : sal_Int32 nIndex = 0;
271 12514 : OUString aExt = rExtension.toAsciiLowerCase();
272 517447 : while ( ExtensionMap_Impl[ nIndex ]._pExt )
273 : {
274 504933 : if ( aExt.equalsAscii( ExtensionMap_Impl[ nIndex ]._pExt ) )
275 : {
276 12514 : nRet = nIndex;
277 12514 : break;
278 : }
279 492419 : ++nIndex;
280 12514 : }
281 : }
282 :
283 12514 : return nRet;
284 : }
285 :
286 12514 : static sal_uInt16 GetImageId_Impl( const OUString& rExtension )
287 : {
288 12514 : sal_uInt16 nImage = IMG_FILE;
289 12514 : sal_Int32 nIndex = GetIndexOfExtension_Impl( rExtension );
290 12514 : if ( nIndex != NO_INDEX )
291 : {
292 12514 : nImage = ExtensionMap_Impl[ nIndex ]._nImgId;
293 12514 : if ( !nImage )
294 0 : nImage = IMG_FILE;
295 : }
296 :
297 12514 : return nImage;
298 : }
299 :
300 0 : static bool GetVolumeProperties_Impl( ::ucbhelper::Content& rContent, svtools::VolumeInfo& rVolumeInfo )
301 : {
302 0 : bool bRet = false;
303 :
304 : try
305 : {
306 0 : bRet = ( ( rContent.getPropertyValue( "IsVolume" ) >>= rVolumeInfo.m_bIsVolume ) &&
307 0 : ( rContent.getPropertyValue( "IsRemote" ) >>= rVolumeInfo.m_bIsRemote ) &&
308 0 : ( rContent.getPropertyValue( "IsRemoveable" ) >>= rVolumeInfo.m_bIsRemoveable ) &&
309 0 : ( rContent.getPropertyValue( "IsFloppy" ) >>= rVolumeInfo.m_bIsFloppy ) &&
310 0 : ( rContent.getPropertyValue( "IsCompactDisc" ) >>= rVolumeInfo.m_bIsCompactDisc ) );
311 : }
312 0 : catch( const ::com::sun::star::uno::RuntimeException& )
313 : {
314 0 : throw; // dont hide it!
315 : }
316 0 : catch( const ::com::sun::star::uno::Exception& )
317 : {
318 : // type detection failed -> no extension
319 : }
320 :
321 0 : return bRet;
322 : }
323 :
324 0 : static sal_uInt16 GetFolderImageId_Impl( const OUString& rURL )
325 : {
326 0 : sal_uInt16 nRet = IMG_FOLDER;
327 0 : ::svtools::VolumeInfo aVolumeInfo;
328 : try
329 : {
330 0 : ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
331 0 : if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
332 : {
333 0 : if ( aVolumeInfo.m_bIsRemote )
334 0 : nRet = IMG_NETWORKDEV;
335 0 : else if ( aVolumeInfo.m_bIsCompactDisc )
336 0 : nRet = IMG_CDROMDEV;
337 0 : else if ( aVolumeInfo.m_bIsRemoveable )
338 0 : nRet = IMG_REMOVABLEDEV;
339 0 : else if ( aVolumeInfo.m_bIsVolume )
340 0 : nRet = IMG_FIXEDDEV;
341 0 : }
342 : }
343 0 : catch( const ::com::sun::star::uno::RuntimeException& )
344 : {
345 0 : throw; // dont hide it!
346 : }
347 0 : catch( const ::com::sun::star::uno::Exception& )
348 : {
349 :
350 : }
351 0 : return nRet;
352 : }
353 :
354 14941 : static sal_uInt16 GetImageId_Impl( const INetURLObject& rObject, bool bDetectFolder )
355 : {
356 29882 : OUString aExt, sURL = rObject.GetMainURL( INetURLObject::NO_DECODE );
357 14941 : sal_uInt16 nImage = IMG_FILE;
358 :
359 14941 : if ( rObject.GetProtocol() == INetProtocol::PrivSoffice )
360 : {
361 14938 : OUString aURLPath = sURL.copy( URL_PREFIX_PRIV_SOFFICE_LEN );
362 17362 : OUString aType = aURLPath.getToken( 0, '/' );
363 14938 : if ( aType == "factory" )
364 : {
365 : // detect an image id for our "private:factory" urls
366 12514 : aExt = GetImageExtensionByFactory_Impl( sURL );
367 12514 : if ( !aExt.isEmpty() )
368 12514 : nImage = GetImageId_Impl( aExt );
369 12514 : return nImage;
370 : }
371 2424 : else if ( aType == "image" )
372 4848 : nImage = (sal_uInt16)aURLPath.getToken( 1, '/' ).toInt32();
373 : }
374 : else
375 : {
376 3 : aExt = rObject.getExtension();
377 3 : if ( aExt == "vor" )
378 : {
379 0 : sal_uInt16 nId = IMG_WRITERTEMPLATE;
380 : try
381 : {
382 0 : tools::SvRef<SotStorage> aStorage = new SotStorage( sURL, STREAM_STD_READ );
383 0 : if ( !aStorage->GetError() )
384 : {
385 0 : SvGlobalName aGlobalName = aStorage->GetClassName();
386 0 : if ( aGlobalName == SvGlobalName(SO3_SC_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_30) )
387 0 : nId = IMG_CALCTEMPLATE;
388 0 : else if ( aGlobalName == SvGlobalName(SO3_SDRAW_CLASSID_50) )
389 0 : nId = IMG_DRAWTEMPLATE;
390 0 : else if ( aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_50) ||
391 0 : aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_30) )
392 0 : nId = IMG_IMPRESSTEMPLATE;
393 0 : else if ( aGlobalName == SvGlobalName(SO3_SM_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_30) )
394 0 : nId = IMG_MATHTEMPLATE;
395 0 : }
396 : }
397 0 : catch (const css::ucb::ContentCreationException& e)
398 : {
399 : SAL_WARN("svtools.misc", "GetImageId_Impl: Caught exception: " << e.Message);
400 : }
401 :
402 0 : return nId;
403 : }
404 : }
405 :
406 2427 : if ( nImage == IMG_FILE && !sURL.isEmpty() )
407 : {
408 2 : if ( bDetectFolder && CONTENT_HELPER::IsFolder( sURL ) )
409 0 : nImage = GetFolderImageId_Impl( sURL );
410 2 : else if ( !aExt.isEmpty() )
411 0 : nImage = GetImageId_Impl( aExt );
412 : }
413 17368 : return nImage;
414 : }
415 :
416 0 : static sal_uInt16 GetDescriptionId_Impl( const OUString& rExtension, bool& rbShowExt )
417 : {
418 0 : sal_uInt16 nId = 0;
419 0 : sal_Int32 nIndex = GetIndexOfExtension_Impl( rExtension );
420 0 : if ( nIndex != NO_INDEX )
421 : {
422 0 : nId = ExtensionMap_Impl[ nIndex ]._nStrId;
423 0 : rbShowExt = ExtensionMap_Impl[ nIndex ]._bExt;
424 : }
425 :
426 0 : return nId;
427 : }
428 :
429 0 : static OUString GetDescriptionByFactory_Impl( const OUString& rFactory )
430 : {
431 0 : sal_uInt16 nResId = 0;
432 0 : if ( rFactory.startsWithIgnoreAsciiCase( "swriter" ) )
433 0 : nResId = STR_DESCRIPTION_FACTORY_WRITER;
434 0 : else if ( rFactory.startsWithIgnoreAsciiCase( "scalc" ) )
435 0 : nResId = STR_DESCRIPTION_FACTORY_CALC;
436 0 : else if ( rFactory.startsWithIgnoreAsciiCase( "simpress" ) )
437 0 : nResId = STR_DESCRIPTION_FACTORY_IMPRESS;
438 0 : else if ( rFactory.startsWithIgnoreAsciiCase( "sdraw" ) )
439 0 : nResId = STR_DESCRIPTION_FACTORY_DRAW;
440 0 : else if ( rFactory.startsWithIgnoreAsciiCase( "swriter/web" ) )
441 0 : nResId = STR_DESCRIPTION_FACTORY_WRITERWEB;
442 0 : else if ( rFactory.startsWithIgnoreAsciiCase( "swriter/globaldocument" ) )
443 0 : nResId = STR_DESCRIPTION_FACTORY_GLOBALDOC;
444 0 : else if ( rFactory.startsWithIgnoreAsciiCase( "smath" ) )
445 0 : nResId = STR_DESCRIPTION_FACTORY_MATH;
446 0 : else if ( rFactory.startsWithIgnoreAsciiCase( "sdatabase" ) )
447 0 : nResId = STR_DESCRIPTION_FACTORY_DATABASE;
448 :
449 0 : if ( nResId )
450 : {
451 0 : SolarMutexGuard aGuard;
452 0 : return SvtResId(nResId).toString();
453 : }
454 0 : return OUString();
455 : }
456 :
457 0 : static sal_uInt16 GetFolderDescriptionId_Impl( const OUString& rURL )
458 : {
459 0 : sal_uInt16 nRet = STR_DESCRIPTION_FOLDER;
460 0 : svtools::VolumeInfo aVolumeInfo;
461 : try
462 : {
463 0 : ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
464 0 : if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
465 : {
466 0 : if ( aVolumeInfo.m_bIsRemote )
467 0 : nRet = STR_DESCRIPTION_REMOTE_VOLUME;
468 0 : else if ( aVolumeInfo.m_bIsFloppy )
469 0 : nRet = STR_DESCRIPTION_FLOPPY_VOLUME;
470 0 : else if ( aVolumeInfo.m_bIsCompactDisc )
471 0 : nRet = STR_DESCRIPTION_CDROM_VOLUME;
472 0 : else if ( aVolumeInfo.m_bIsRemoveable || aVolumeInfo.m_bIsVolume )
473 0 : nRet = STR_DESCRIPTION_LOCALE_VOLUME;
474 0 : }
475 : }
476 0 : catch( const ::com::sun::star::uno::RuntimeException& )
477 : {
478 0 : throw; // dont hide it!
479 : }
480 0 : catch( const ::com::sun::star::uno::Exception& )
481 : {
482 :
483 : }
484 0 : return nRet;
485 : }
486 :
487 14938 : static Image GetImageFromList_Impl( sal_uInt16 nImageId, bool bBig )
488 : {
489 14938 : if ( !bBig && IMG_FOLDER == nImageId )
490 : // return our new small folder image (256 colors)
491 0 : return Image( SvtResId( IMG_SVT_FOLDER ) );
492 :
493 14938 : ImageList* pList = NULL;
494 :
495 14938 : static vcl::DeleteOnDeinit< ImageList > xSmallImageList( NULL );
496 14938 : static vcl::DeleteOnDeinit< ImageList > xBigImageList( NULL );
497 14938 : static OUString style = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
498 :
499 : // If the style has been changed, throw away our cache of the older images
500 14938 : OUString currentStyle = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
501 14938 : if ( style != currentStyle)
502 : {
503 0 : xSmallImageList.reset();
504 0 : xBigImageList.reset();
505 0 : style = currentStyle;
506 : }
507 :
508 14938 : if ( bBig )
509 : {
510 0 : if ( !xBigImageList.get() )
511 0 : xBigImageList.reset(new ImageList(SvtResId(RID_SVTOOLS_IMAGELIST_BIG)));
512 0 : pList = xBigImageList.get();
513 : }
514 : else
515 : {
516 14938 : if ( !xSmallImageList.get() )
517 43 : xSmallImageList.reset(new ImageList(SvtResId(RID_SVTOOLS_IMAGELIST_SMALL)));
518 14938 : pList = xSmallImageList.get();
519 : }
520 :
521 14938 : if ( pList->HasImageAtPos( nImageId ) )
522 14332 : return pList->GetImage( nImageId );
523 606 : return Image();
524 : }
525 :
526 0 : OUString SvFileInformationManager::GetDescription_Impl( const INetURLObject& rObject, bool bDetectFolder )
527 : {
528 0 : OUString sExtension(rObject.getExtension());
529 0 : OUString sDescription, sURL( rObject.GetMainURL( INetURLObject::NO_DECODE ) );
530 0 : sal_uInt16 nResId = 0;
531 0 : bool bShowExt = false, bOnlyFile = false;
532 0 : bool bFolder = bDetectFolder && CONTENT_HELPER::IsFolder( sURL );
533 0 : if ( !bFolder )
534 : {
535 0 : bool bDetected = false;
536 :
537 0 : if ( rObject.GetProtocol() == INetProtocol::PrivSoffice )
538 : {
539 0 : OUString aURLPath = sURL.copy( URL_PREFIX_PRIV_SOFFICE_LEN );
540 0 : OUString aType = aURLPath.getToken( 0, '/' );
541 0 : if ( aType == "factory" )
542 : {
543 0 : sDescription = GetDescriptionByFactory_Impl( aURLPath.copy( aURLPath.indexOf( '/' ) + 1 ) );
544 0 : bDetected = true;
545 0 : }
546 : }
547 :
548 0 : if (!bDetected)
549 : {
550 : // search a description by extension
551 0 : bool bExt = !sExtension.isEmpty();
552 0 : if ( bExt )
553 : {
554 0 : sExtension = sExtension.toAsciiLowerCase();
555 0 : nResId = GetDescriptionId_Impl( sExtension, bShowExt );
556 : }
557 0 : if ( !nResId )
558 : {
559 0 : nResId = STR_DESCRIPTION_FILE;
560 0 : bOnlyFile = bExt;
561 : }
562 : }
563 : }
564 : else
565 0 : nResId = GetFolderDescriptionId_Impl( sURL );
566 :
567 0 : if ( nResId > 0 )
568 : {
569 0 : if ( bOnlyFile )
570 : {
571 0 : bShowExt = false;
572 0 : sExtension = sExtension.toAsciiUpperCase();
573 0 : sDescription = sExtension;
574 0 : sDescription += "-";
575 : }
576 0 : SolarMutexGuard aGuard;
577 0 : sDescription += SvtResId(nResId).toString();
578 : }
579 :
580 : DBG_ASSERT( !sDescription.isEmpty(), "file without description" );
581 :
582 0 : if ( bShowExt )
583 : {
584 0 : sDescription += " (";
585 0 : sDescription += sExtension;
586 0 : sDescription += ")";
587 : }
588 :
589 0 : return sDescription;
590 : }
591 :
592 0 : Image SvFileInformationManager::GetImage( const INetURLObject& rObject, bool bBig )
593 : {
594 0 : sal_uInt16 nImage = GetImageId_Impl( rObject, true );
595 : DBG_ASSERT( nImage, "invalid ImageId" );
596 0 : return GetImageFromList_Impl( nImage, bBig );
597 : }
598 :
599 0 : Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject, bool bBig )
600 : {
601 0 : sal_Int16 nImage = GetImageId_Impl( rObject, false );
602 : DBG_ASSERT( nImage, "invalid ImageId" );
603 0 : return GetImageFromList_Impl( nImage, bBig );
604 : }
605 :
606 14941 : Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, bool bBig )
607 : {
608 14941 : sal_uInt16 nImage = GetImageId_Impl( rObject, true );
609 : DBG_ASSERT( nImage, "invalid ImageId" );
610 :
611 14941 : if ( nImage == IMG_FILE )
612 3 : return Image();
613 :
614 14938 : return GetImageFromList_Impl( nImage, bBig );
615 : }
616 :
617 0 : Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo, bool bBig )
618 : {
619 0 : sal_uInt16 nImage = IMG_FOLDER;
620 : DBG_ASSERT( nImage, "invalid ImageId" );
621 :
622 0 : if ( rInfo.m_bIsRemote )
623 0 : nImage = IMG_NETWORKDEV;
624 0 : else if ( rInfo.m_bIsCompactDisc )
625 0 : nImage = IMG_CDROMDEV;
626 0 : else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsFloppy )
627 0 : nImage = IMG_REMOVABLEDEV;
628 0 : else if ( rInfo.m_bIsVolume )
629 0 : nImage = IMG_FIXEDDEV;
630 :
631 0 : return GetImageFromList_Impl( nImage, bBig );
632 : }
633 :
634 0 : OUString SvFileInformationManager::GetDescription( const INetURLObject& rObject )
635 : {
636 0 : return SvFileInformationManager::GetDescription_Impl( rObject, true );
637 : }
638 :
639 0 : OUString SvFileInformationManager::GetFileDescription( const INetURLObject& rObject )
640 : {
641 0 : return SvFileInformationManager::GetDescription_Impl( rObject, false );
642 : }
643 :
644 0 : OUString SvFileInformationManager::GetFolderDescription( const svtools::VolumeInfo& rInfo )
645 : {
646 0 : sal_uInt16 nResId = STR_DESCRIPTION_FOLDER;
647 0 : if ( rInfo.m_bIsRemote )
648 0 : nResId = STR_DESCRIPTION_REMOTE_VOLUME;
649 0 : else if ( rInfo.m_bIsFloppy )
650 0 : nResId = STR_DESCRIPTION_FLOPPY_VOLUME;
651 0 : else if ( rInfo.m_bIsCompactDisc )
652 0 : nResId = STR_DESCRIPTION_CDROM_VOLUME;
653 0 : else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsVolume )
654 0 : nResId = STR_DESCRIPTION_LOCALE_VOLUME;
655 :
656 0 : return SvtResId(nResId).toString();
657 : }
658 :
659 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|