Bump version to 5.0-14
[LibreOffice.git] / svtools / source / misc / imagemgr.cxx
blob45eae7685161e46e9bbadc589a534bdbc63dd870
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
45 // globals *******************************************************************
47 #define NO_INDEX (-1)
48 #define CONTENT_HELPER ::utl::UCBContentHelper
50 struct SvtExtensionResIdMapping_Impl
52 const char* _pExt;
53 bool _bExt;
54 sal_uInt16 _nStrId;
55 sal_uInt16 _nImgId;
58 static SvtExtensionResIdMapping_Impl const ExtensionMap_Impl[] =
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 }
175 struct SvtFactory2ExtensionMapping_Impl
177 const char* _pFactory;
178 const char* _pExtension;
181 // mapping from "private:factory" url to extension
183 static SvtFactory2ExtensionMapping_Impl const Fac2ExtMap_Impl[] =
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 }
198 static OUString GetImageExtensionByFactory_Impl( const OUString& rURL )
200 INetURLObject aObj( rURL );
201 OUString aPath = aObj.GetURLPath( INetURLObject::NO_DECODE );
202 OUString aExtension;
204 if ( !aPath.isEmpty() )
206 sal_uInt16 nIndex = 0;
207 while ( Fac2ExtMap_Impl[ nIndex ]._pFactory )
209 if ( aPath.equalsAscii( Fac2ExtMap_Impl[ nIndex ]._pFactory ) )
211 // extension found
212 aExtension = OUString::createFromAscii(Fac2ExtMap_Impl[ nIndex ]._pExtension);
213 // and return it
214 return aExtension;
216 ++nIndex;
220 // no extension found, so use the type detection (performance brake)
224 // get the TypeDetection service to access all registered types
225 ::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 xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext),
228 ::com::sun::star::uno::UNO_QUERY );
230 OUString aInternalType = xTypeDetector->queryTypeByURL( rURL );
231 ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess > xAccess( xTypeDetector, ::com::sun::star::uno::UNO_QUERY );
232 ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > aTypeProps;
233 if ( !aInternalType.isEmpty() && xAccess->hasByName( aInternalType ) )
235 xAccess->getByName( aInternalType ) >>= aTypeProps;
236 sal_Int32 nProps = aTypeProps.getLength();
237 for ( sal_Int32 i = 0; i < nProps; ++i )
239 const ::com::sun::star::beans::PropertyValue& rProp = aTypeProps[i];
240 if (rProp.Name == "Extensions")
242 ::com::sun::star::uno::Sequence < OUString > aExtensions;
243 if ( ( rProp.Value >>= aExtensions ) && aExtensions.getLength() > 0 )
245 const OUString* pExtensions = aExtensions.getConstArray();
246 aExtension = OUString( pExtensions[0] );
247 break;
253 catch( const ::com::sun::star::uno::RuntimeException& )
255 throw; // dont hide it!
257 catch( const ::com::sun::star::uno::Exception& )
259 // type detection failed -> no extension
262 return aExtension;
265 static sal_Int32 GetIndexOfExtension_Impl( const OUString& rExtension )
267 sal_Int32 nRet = NO_INDEX;
268 if ( !rExtension.isEmpty() )
270 sal_Int32 nIndex = 0;
271 OUString aExt = rExtension.toAsciiLowerCase();
272 while ( ExtensionMap_Impl[ nIndex ]._pExt )
274 if ( aExt.equalsAscii( ExtensionMap_Impl[ nIndex ]._pExt ) )
276 nRet = nIndex;
277 break;
279 ++nIndex;
283 return nRet;
286 static sal_uInt16 GetImageId_Impl( const OUString& rExtension )
288 sal_uInt16 nImage = IMG_FILE;
289 sal_Int32 nIndex = GetIndexOfExtension_Impl( rExtension );
290 if ( nIndex != NO_INDEX )
292 nImage = ExtensionMap_Impl[ nIndex ]._nImgId;
293 if ( !nImage )
294 nImage = IMG_FILE;
297 return nImage;
300 static bool GetVolumeProperties_Impl( ::ucbhelper::Content& rContent, svtools::VolumeInfo& rVolumeInfo )
302 bool bRet = false;
306 bRet = ( ( rContent.getPropertyValue( "IsVolume" ) >>= rVolumeInfo.m_bIsVolume ) &&
307 ( rContent.getPropertyValue( "IsRemote" ) >>= rVolumeInfo.m_bIsRemote ) &&
308 ( rContent.getPropertyValue( "IsRemoveable" ) >>= rVolumeInfo.m_bIsRemoveable ) &&
309 ( rContent.getPropertyValue( "IsFloppy" ) >>= rVolumeInfo.m_bIsFloppy ) &&
310 ( rContent.getPropertyValue( "IsCompactDisc" ) >>= rVolumeInfo.m_bIsCompactDisc ) );
312 catch( const ::com::sun::star::uno::RuntimeException& )
314 throw; // dont hide it!
316 catch( const ::com::sun::star::uno::Exception& )
318 // type detection failed -> no extension
321 return bRet;
324 static sal_uInt16 GetFolderImageId_Impl( const OUString& rURL )
326 sal_uInt16 nRet = IMG_FOLDER;
327 ::svtools::VolumeInfo aVolumeInfo;
330 ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
331 if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
333 if ( aVolumeInfo.m_bIsRemote )
334 nRet = IMG_NETWORKDEV;
335 else if ( aVolumeInfo.m_bIsCompactDisc )
336 nRet = IMG_CDROMDEV;
337 else if ( aVolumeInfo.m_bIsRemoveable )
338 nRet = IMG_REMOVABLEDEV;
339 else if ( aVolumeInfo.m_bIsVolume )
340 nRet = IMG_FIXEDDEV;
343 catch( const ::com::sun::star::uno::RuntimeException& )
345 throw; // dont hide it!
347 catch( const ::com::sun::star::uno::Exception& )
351 return nRet;
354 static sal_uInt16 GetImageId_Impl( const INetURLObject& rObject, bool bDetectFolder )
356 OUString aExt, sURL = rObject.GetMainURL( INetURLObject::NO_DECODE );
357 sal_uInt16 nImage = IMG_FILE;
359 if ( rObject.GetProtocol() == INetProtocol::PrivSoffice )
361 OUString aURLPath = sURL.copy( URL_PREFIX_PRIV_SOFFICE_LEN );
362 OUString aType = aURLPath.getToken( 0, '/' );
363 if ( aType == "factory" )
365 // detect an image id for our "private:factory" urls
366 aExt = GetImageExtensionByFactory_Impl( sURL );
367 if ( !aExt.isEmpty() )
368 nImage = GetImageId_Impl( aExt );
369 return nImage;
371 else if ( aType == "image" )
372 nImage = (sal_uInt16)aURLPath.getToken( 1, '/' ).toInt32();
374 else
376 aExt = rObject.getExtension();
377 if ( aExt == "vor" )
379 sal_uInt16 nId = IMG_WRITERTEMPLATE;
382 tools::SvRef<SotStorage> aStorage = new SotStorage( sURL, STREAM_STD_READ );
383 if ( !aStorage->GetError() )
385 SvGlobalName aGlobalName = aStorage->GetClassName();
386 if ( aGlobalName == SvGlobalName(SO3_SC_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_30) )
387 nId = IMG_CALCTEMPLATE;
388 else if ( aGlobalName == SvGlobalName(SO3_SDRAW_CLASSID_50) )
389 nId = IMG_DRAWTEMPLATE;
390 else if ( aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_50) ||
391 aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_30) )
392 nId = IMG_IMPRESSTEMPLATE;
393 else if ( aGlobalName == SvGlobalName(SO3_SM_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_30) )
394 nId = IMG_MATHTEMPLATE;
397 catch (const css::ucb::ContentCreationException& e)
399 SAL_WARN("svtools.misc", "GetImageId_Impl: Caught exception: " << e.Message);
402 return nId;
406 if ( nImage == IMG_FILE && !sURL.isEmpty() )
408 if ( bDetectFolder && CONTENT_HELPER::IsFolder( sURL ) )
409 nImage = GetFolderImageId_Impl( sURL );
410 else if ( !aExt.isEmpty() )
411 nImage = GetImageId_Impl( aExt );
413 return nImage;
416 static sal_uInt16 GetDescriptionId_Impl( const OUString& rExtension, bool& rbShowExt )
418 sal_uInt16 nId = 0;
419 sal_Int32 nIndex = GetIndexOfExtension_Impl( rExtension );
420 if ( nIndex != NO_INDEX )
422 nId = ExtensionMap_Impl[ nIndex ]._nStrId;
423 rbShowExt = ExtensionMap_Impl[ nIndex ]._bExt;
426 return nId;
429 static OUString GetDescriptionByFactory_Impl( const OUString& rFactory )
431 sal_uInt16 nResId = 0;
432 if ( rFactory.startsWithIgnoreAsciiCase( "swriter" ) )
433 nResId = STR_DESCRIPTION_FACTORY_WRITER;
434 else if ( rFactory.startsWithIgnoreAsciiCase( "scalc" ) )
435 nResId = STR_DESCRIPTION_FACTORY_CALC;
436 else if ( rFactory.startsWithIgnoreAsciiCase( "simpress" ) )
437 nResId = STR_DESCRIPTION_FACTORY_IMPRESS;
438 else if ( rFactory.startsWithIgnoreAsciiCase( "sdraw" ) )
439 nResId = STR_DESCRIPTION_FACTORY_DRAW;
440 else if ( rFactory.startsWithIgnoreAsciiCase( "swriter/web" ) )
441 nResId = STR_DESCRIPTION_FACTORY_WRITERWEB;
442 else if ( rFactory.startsWithIgnoreAsciiCase( "swriter/globaldocument" ) )
443 nResId = STR_DESCRIPTION_FACTORY_GLOBALDOC;
444 else if ( rFactory.startsWithIgnoreAsciiCase( "smath" ) )
445 nResId = STR_DESCRIPTION_FACTORY_MATH;
446 else if ( rFactory.startsWithIgnoreAsciiCase( "sdatabase" ) )
447 nResId = STR_DESCRIPTION_FACTORY_DATABASE;
449 if ( nResId )
451 SolarMutexGuard aGuard;
452 return SvtResId(nResId).toString();
454 return OUString();
457 static sal_uInt16 GetFolderDescriptionId_Impl( const OUString& rURL )
459 sal_uInt16 nRet = STR_DESCRIPTION_FOLDER;
460 svtools::VolumeInfo aVolumeInfo;
463 ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
464 if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
466 if ( aVolumeInfo.m_bIsRemote )
467 nRet = STR_DESCRIPTION_REMOTE_VOLUME;
468 else if ( aVolumeInfo.m_bIsFloppy )
469 nRet = STR_DESCRIPTION_FLOPPY_VOLUME;
470 else if ( aVolumeInfo.m_bIsCompactDisc )
471 nRet = STR_DESCRIPTION_CDROM_VOLUME;
472 else if ( aVolumeInfo.m_bIsRemoveable || aVolumeInfo.m_bIsVolume )
473 nRet = STR_DESCRIPTION_LOCALE_VOLUME;
476 catch( const ::com::sun::star::uno::RuntimeException& )
478 throw; // dont hide it!
480 catch( const ::com::sun::star::uno::Exception& )
484 return nRet;
487 static Image GetImageFromList_Impl( sal_uInt16 nImageId, bool bBig )
489 if ( !bBig && IMG_FOLDER == nImageId )
490 // return our new small folder image (256 colors)
491 return Image( SvtResId( IMG_SVT_FOLDER ) );
493 ImageList* pList = NULL;
495 static vcl::DeleteOnDeinit< ImageList > xSmallImageList( NULL );
496 static vcl::DeleteOnDeinit< ImageList > xBigImageList( NULL );
497 static OUString style = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
499 // If the style has been changed, throw away our cache of the older images
500 OUString currentStyle = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
501 if ( style != currentStyle)
503 xSmallImageList.reset();
504 xBigImageList.reset();
505 style = currentStyle;
508 if ( bBig )
510 if ( !xBigImageList.get() )
511 xBigImageList.reset(new ImageList(SvtResId(RID_SVTOOLS_IMAGELIST_BIG)));
512 pList = xBigImageList.get();
514 else
516 if ( !xSmallImageList.get() )
517 xSmallImageList.reset(new ImageList(SvtResId(RID_SVTOOLS_IMAGELIST_SMALL)));
518 pList = xSmallImageList.get();
521 if ( pList->HasImageAtPos( nImageId ) )
522 return pList->GetImage( nImageId );
523 return Image();
526 OUString SvFileInformationManager::GetDescription_Impl( const INetURLObject& rObject, bool bDetectFolder )
528 OUString sExtension(rObject.getExtension());
529 OUString sDescription, sURL( rObject.GetMainURL( INetURLObject::NO_DECODE ) );
530 sal_uInt16 nResId = 0;
531 bool bShowExt = false, bOnlyFile = false;
532 bool bFolder = bDetectFolder && CONTENT_HELPER::IsFolder( sURL );
533 if ( !bFolder )
535 bool bDetected = false;
537 if ( rObject.GetProtocol() == INetProtocol::PrivSoffice )
539 OUString aURLPath = sURL.copy( URL_PREFIX_PRIV_SOFFICE_LEN );
540 OUString aType = aURLPath.getToken( 0, '/' );
541 if ( aType == "factory" )
543 sDescription = GetDescriptionByFactory_Impl( aURLPath.copy( aURLPath.indexOf( '/' ) + 1 ) );
544 bDetected = true;
548 if (!bDetected)
550 // search a description by extension
551 bool bExt = !sExtension.isEmpty();
552 if ( bExt )
554 sExtension = sExtension.toAsciiLowerCase();
555 nResId = GetDescriptionId_Impl( sExtension, bShowExt );
557 if ( !nResId )
559 nResId = STR_DESCRIPTION_FILE;
560 bOnlyFile = bExt;
564 else
565 nResId = GetFolderDescriptionId_Impl( sURL );
567 if ( nResId > 0 )
569 if ( bOnlyFile )
571 bShowExt = false;
572 sExtension = sExtension.toAsciiUpperCase();
573 sDescription = sExtension;
574 sDescription += "-";
576 SolarMutexGuard aGuard;
577 sDescription += SvtResId(nResId).toString();
580 DBG_ASSERT( !sDescription.isEmpty(), "file without description" );
582 if ( bShowExt )
584 sDescription += " (";
585 sDescription += sExtension;
586 sDescription += ")";
589 return sDescription;
592 Image SvFileInformationManager::GetImage( const INetURLObject& rObject, bool bBig )
594 sal_uInt16 nImage = GetImageId_Impl( rObject, true );
595 DBG_ASSERT( nImage, "invalid ImageId" );
596 return GetImageFromList_Impl( nImage, bBig );
599 Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject, bool bBig )
601 sal_Int16 nImage = GetImageId_Impl( rObject, false );
602 DBG_ASSERT( nImage, "invalid ImageId" );
603 return GetImageFromList_Impl( nImage, bBig );
606 Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, bool bBig )
608 sal_uInt16 nImage = GetImageId_Impl( rObject, true );
609 DBG_ASSERT( nImage, "invalid ImageId" );
611 if ( nImage == IMG_FILE )
612 return Image();
614 return GetImageFromList_Impl( nImage, bBig );
617 Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo, bool bBig )
619 sal_uInt16 nImage = IMG_FOLDER;
620 DBG_ASSERT( nImage, "invalid ImageId" );
622 if ( rInfo.m_bIsRemote )
623 nImage = IMG_NETWORKDEV;
624 else if ( rInfo.m_bIsCompactDisc )
625 nImage = IMG_CDROMDEV;
626 else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsFloppy )
627 nImage = IMG_REMOVABLEDEV;
628 else if ( rInfo.m_bIsVolume )
629 nImage = IMG_FIXEDDEV;
631 return GetImageFromList_Impl( nImage, bBig );
634 OUString SvFileInformationManager::GetDescription( const INetURLObject& rObject )
636 return SvFileInformationManager::GetDescription_Impl( rObject, true );
639 OUString SvFileInformationManager::GetFileDescription( const INetURLObject& rObject )
641 return SvFileInformationManager::GetDescription_Impl( rObject, false );
644 OUString SvFileInformationManager::GetFolderDescription( const svtools::VolumeInfo& rInfo )
646 sal_uInt16 nResId = STR_DESCRIPTION_FOLDER;
647 if ( rInfo.m_bIsRemote )
648 nResId = STR_DESCRIPTION_REMOTE_VOLUME;
649 else if ( rInfo.m_bIsFloppy )
650 nResId = STR_DESCRIPTION_FLOPPY_VOLUME;
651 else if ( rInfo.m_bIsCompactDisc )
652 nResId = STR_DESCRIPTION_CDROM_VOLUME;
653 else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsVolume )
654 nResId = STR_DESCRIPTION_LOCALE_VOLUME;
656 return SvtResId(nResId).toString();
659 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */