1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sot/storage.hxx>
27 #include <comphelper/classids.hxx>
28 #include <unotools/ucbhelper.hxx>
29 #include <comphelper/processfactory.hxx>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/container/XNameContainer.hpp>
32 #include <com/sun/star/document/XTypeDetection.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
35 #include <ucbhelper/content.hxx>
36 #include <tools/rcid.h>
37 #include <rtl/logfile.hxx>
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 ((sal_uInt16)0xFFFF)
48 #define CONTENT_HELPER ::utl::UCBContentHelper
50 struct SvtExtensionResIdMapping_Impl
58 static SvtExtensionResIdMapping_Impl
const ExtensionMap_Impl
[] =
60 { "awk", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
61 { "bas", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
62 { "bat", sal_True
, STR_DESCRIPTION_BATCHFILE
, 0 },
63 { "bmk", sal_False
, STR_DESCRIPTION_BOOKMARKFILE
, 0 },
64 { "bmp", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_BITMAP
},
65 { "c", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
66 { "cfg", sal_False
, STR_DESCRIPTION_CFGFILE
, 0 },
67 { "cmd", sal_True
, STR_DESCRIPTION_BATCHFILE
, 0 },
68 { "cob", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
69 { "com", sal_True
, STR_DESCRIPTION_APPLICATION
, 0 },
70 { "cxx", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
71 { "dbf", sal_True
, STR_DESCRIPTION_DATABASE_TABLE
, IMG_TABLE
},
72 { "def", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
73 { "dll", sal_True
, STR_DESCRIPTION_SYSFILE
, 0 },
74 { "doc", sal_False
, STR_DESCRIPTION_WORD_DOC
, IMG_WRITER
},
75 { "dot", sal_False
, STR_DESCRIPTION_WORD_DOC
, IMG_WRITERTEMPLATE
},
76 { "docx", sal_False
, STR_DESCRIPTION_WORD_DOC
, IMG_WRITER
},
77 { "dxf", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_DXF
},
78 { "exe", sal_True
, STR_DESCRIPTION_APPLICATION
, 0 },
79 { "gif", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_GIF
},
80 { "h", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
81 { "hlp", sal_False
, STR_DESCRIPTION_HELP_DOC
, 0 },
82 { "hrc", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
83 { "htm", sal_False
, STR_DESCRIPTION_HTMLFILE
, IMG_HTML
},
84 { "html", sal_False
, STR_DESCRIPTION_HTMLFILE
, IMG_HTML
},
85 { "asp", sal_False
, STR_DESCRIPTION_HTMLFILE
, IMG_HTML
},
86 { "hxx", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
87 { "ini", sal_False
, STR_DESCRIPTION_CFGFILE
, 0 },
88 { "java", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
89 { "jpeg", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_JPG
},
90 { "jpg", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_JPG
},
91 { "lha", sal_True
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
93 { "lnk", sal_False
, 0, 0 },
95 { "log", sal_True
, STR_DESCRIPTION_LOGFILE
, 0 },
96 { "lst", sal_True
, STR_DESCRIPTION_LOGFILE
, 0 },
97 { "met", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_MET
},
98 { "mml", sal_False
, STR_DESCRIPTION_MATHML_DOC
, IMG_MATH
},
99 { "mod", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
100 { "odb", sal_False
, STR_DESCRIPTION_OO_DATABASE_DOC
, IMG_OO_DATABASE_DOC
},
101 { "odg", sal_False
, STR_DESCRIPTION_OO_DRAW_DOC
, IMG_OO_DRAW_DOC
},
102 { "odf", sal_False
, STR_DESCRIPTION_OO_MATH_DOC
, IMG_OO_MATH_DOC
},
103 { "odm", sal_False
, STR_DESCRIPTION_OO_GLOBAL_DOC
, IMG_OO_GLOBAL_DOC
},
104 { "odp", sal_False
, STR_DESCRIPTION_OO_IMPRESS_DOC
, IMG_OO_IMPRESS_DOC
},
105 { "ods", sal_False
, STR_DESCRIPTION_OO_CALC_DOC
, IMG_OO_CALC_DOC
},
106 { "odt", sal_False
, STR_DESCRIPTION_OO_WRITER_DOC
, IMG_OO_WRITER_DOC
},
107 { "otg", sal_False
, STR_DESCRIPTION_OO_DRAW_TEMPLATE
, IMG_OO_DRAW_TEMPLATE
},
108 { "otp", sal_False
, STR_DESCRIPTION_OO_IMPRESS_TEMPLATE
, IMG_OO_IMPRESS_TEMPLATE
},
109 { "ots", sal_False
, STR_DESCRIPTION_OO_CALC_TEMPLATE
, IMG_OO_CALC_TEMPLATE
},
110 { "ott", sal_False
, STR_DESCRIPTION_OO_WRITER_TEMPLATE
, IMG_OO_WRITER_TEMPLATE
},
111 { "pas", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
112 { "pcd", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCD
},
113 { "pct", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCT
},
114 { "pict", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCT
},
115 { "pcx", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCX
},
116 { "pl", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
117 { "png", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PNG
},
118 { "rar", sal_True
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
119 { "rtf", sal_False
, STR_DESCRIPTION_WORD_DOC
, IMG_WRITER
},
120 { "sbl", sal_False
, 0, 0 },
121 { "sch", sal_False
, 0, 0 },
122 { "sda", sal_False
, STR_DESCRIPTION_SDRAW_DOC
, IMG_DRAW
},
123 { "sdb", sal_False
, STR_DESCRIPTION_SDATABASE_DOC
, IMG_DATABASE
},
124 { "sdc", sal_False
, STR_DESCRIPTION_SCALC_DOC
, IMG_CALC
},
125 { "sdd", sal_False
, STR_DESCRIPTION_SIMPRESS_DOC
, IMG_IMPRESS
},
126 { "sdp", sal_False
, STR_DESCRIPTION_SIMPRESS_DOC
, 0 },
127 { "sds", sal_False
, STR_DESCRIPTION_SCHART_DOC
, 0 },
128 { "sdw", sal_False
, STR_DESCRIPTION_SWRITER_DOC
, IMG_WRITER
},
129 { "sga", sal_False
, 0, 0 },
130 { "sgf", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SGF
},
131 { "sgl", sal_False
, STR_DESCRIPTION_GLOBALDOC
, IMG_GLOBAL_DOC
},
132 { "sgv", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SGV
},
133 { "shtml", sal_False
, STR_DESCRIPTION_HTMLFILE
, IMG_HTML
},
134 { "sim", sal_False
, STR_DESCRIPTION_SIMAGE_DOC
, IMG_SIM
},
135 { "smf", sal_False
, STR_DESCRIPTION_SMATH_DOC
, IMG_MATH
},
136 { "src", sal_True
, STR_DESCRIPTION_SOURCEFILE
, 0 },
137 { "svh", sal_False
, STR_DESCRIPTION_HELP_DOC
, 0 },
138 { "svm", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SVM
},
139 { "stc", sal_False
, STR_DESCRIPTION_CALC_TEMPLATE
, IMG_CALCTEMPLATE
},
140 { "std", sal_False
, STR_DESCRIPTION_DRAW_TEMPLATE
, IMG_DRAWTEMPLATE
},
141 { "sti", sal_False
, STR_DESCRIPTION_IMPRESS_TEMPLATE
, IMG_IMPRESSTEMPLATE
},
142 { "stw", sal_False
, STR_DESCRIPTION_WRITER_TEMPLATE
, IMG_WRITERTEMPLATE
},
143 { "sxc", sal_False
, STR_DESCRIPTION_SXCALC_DOC
, IMG_CALC
},
144 { "sxd", sal_False
, STR_DESCRIPTION_SXDRAW_DOC
, IMG_DRAW
},
145 { "sxg", sal_False
, STR_DESCRIPTION_SXGLOBAL_DOC
, IMG_GLOBAL_DOC
},
146 { "sxi", sal_False
, STR_DESCRIPTION_SXIMPRESS_DOC
, IMG_IMPRESS
},
147 { "sxm", sal_False
, STR_DESCRIPTION_SXMATH_DOC
, IMG_MATH
},
148 { "sxs", sal_False
, STR_DESCRIPTION_SXCHART_DOC
, 0 },
149 { "sxw", sal_False
, STR_DESCRIPTION_SXWRITER_DOC
, IMG_WRITER
},
150 { "sys", sal_True
, STR_DESCRIPTION_SYSFILE
, 0 },
151 { "tif", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_TIFF
},
152 { "tiff", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_TIFF
},
153 { "txt", sal_False
, STR_DESCRIPTION_TEXTFILE
, IMG_TEXTFILE
},
154 { "url", sal_False
, STR_DESCRIPTION_LINK
, 0 },
155 { "vor", sal_False
, STR_DESCRIPTION_SOFFICE_TEMPLATE_DOC
, IMG_WRITERTEMPLATE
},
156 { "vxd", sal_True
, STR_DESCRIPTION_SYSFILE
, 0 },
157 { "wmf", sal_True
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_WMF
},
158 { "xls", sal_False
, STR_DESCRIPTION_EXCEL_DOC
, IMG_CALC
},
159 { "xlt", sal_False
, STR_DESCRIPTION_EXCEL_TEMPLATE_DOC
, IMG_CALCTEMPLATE
},
160 { "xlsx", sal_False
, STR_DESCRIPTION_EXCEL_DOC
, IMG_CALC
},
161 { "uu", sal_True
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
162 { "uue", sal_True
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
163 { "z", sal_True
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
164 { "zip", sal_True
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
165 { "zoo", sal_True
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
166 { "gz", sal_True
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
167 { "ppt", sal_False
, STR_DESCRIPTION_POWERPOINT
, IMG_IMPRESS
},
168 { "pot", sal_False
, STR_DESCRIPTION_POWERPOINT_TEMPLATE
, IMG_IMPRESSTEMPLATE
},
169 { "pps", sal_False
, STR_DESCRIPTION_POWERPOINT_SHOW
, IMG_IMPRESS
},
170 { "pptx", sal_False
, STR_DESCRIPTION_POWERPOINT
, IMG_IMPRESS
},
171 { "oxt", sal_False
, STR_DESCRIPTION_EXTENSION
, IMG_EXTENSION
},
172 { 0, sal_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" },
189 { "simpress", "odp" },
192 { "sdatabase", "odb" },
196 //****************************************************************************
198 static String
GetImageExtensionByFactory_Impl( const String
& rURL
)
200 INetURLObject
aObj( rURL
);
201 String aPath
= aObj
.GetURLPath( INetURLObject::NO_DECODE
);
206 sal_uInt16 nIndex
= 0;
207 while ( Fac2ExtMap_Impl
[ nIndex
]._pFactory
)
209 if ( aPath
.EqualsAscii( Fac2ExtMap_Impl
[ nIndex
]._pFactory
) )
212 aExtension
= OUString::createFromAscii(Fac2ExtMap_Impl
[ nIndex
]._pExtension
);
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
.compareToAscii("Extensions") == COMPARE_EQUAL
)
242 ::com::sun::star::uno::Sequence
< OUString
> aExtensions
;
243 if ( ( rProp
.Value
>>= aExtensions
) && aExtensions
.getLength() > 0 )
245 const OUString
* pExtensions
= aExtensions
.getConstArray();
246 aExtension
= String( pExtensions
[0] );
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
265 static sal_uInt16
GetIndexOfExtension_Impl( const String
& rExtension
)
267 sal_uInt16 nRet
= NO_INDEX
;
268 if ( rExtension
.Len() )
270 sal_uInt16 nIndex
= 0;
271 String aExt
= rExtension
;
273 while ( ExtensionMap_Impl
[ nIndex
]._pExt
)
275 if ( aExt
.EqualsAscii( ExtensionMap_Impl
[ nIndex
]._pExt
) )
287 static sal_uInt16
GetImageId_Impl( const String
& rExtension
)
289 sal_uInt16 nImage
= IMG_FILE
;
290 if ( rExtension
.Len() != NO_INDEX
)
292 sal_uInt16 nIndex
= GetIndexOfExtension_Impl( rExtension
);
293 if ( nIndex
!= NO_INDEX
)
295 nImage
= ExtensionMap_Impl
[ nIndex
]._nImgId
;
304 static sal_Bool
GetVolumeProperties_Impl( ::ucbhelper::Content
& rContent
, svtools::VolumeInfo
& rVolumeInfo
)
306 sal_Bool bRet
= sal_False
;
310 bRet
= ( ( rContent
.getPropertyValue( "IsVolume" ) >>= rVolumeInfo
.m_bIsVolume
) &&
311 ( rContent
.getPropertyValue( "IsRemote" ) >>= rVolumeInfo
.m_bIsRemote
) &&
312 ( rContent
.getPropertyValue( "IsRemoveable" ) >>= rVolumeInfo
.m_bIsRemoveable
) &&
313 ( rContent
.getPropertyValue( "IsFloppy" ) >>= rVolumeInfo
.m_bIsFloppy
) &&
314 ( rContent
.getPropertyValue( "IsCompactDisc" ) >>= rVolumeInfo
.m_bIsCompactDisc
) );
316 catch( const ::com::sun::star::uno::RuntimeException
& )
318 throw; // dont hide it!
320 catch( const ::com::sun::star::uno::Exception
& )
322 // type detection failed -> no extension
328 static sal_uInt16
GetFolderImageId_Impl( const String
& rURL
)
330 sal_uInt16 nRet
= IMG_FOLDER
;
331 ::svtools::VolumeInfo aVolumeInfo
;
334 ::ucbhelper::Content
aCnt( rURL
, ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
335 if ( GetVolumeProperties_Impl( aCnt
, aVolumeInfo
) )
337 if ( aVolumeInfo
.m_bIsRemote
)
338 nRet
= IMG_NETWORKDEV
;
339 else if ( aVolumeInfo
.m_bIsCompactDisc
)
341 else if ( aVolumeInfo
.m_bIsRemoveable
)
342 nRet
= IMG_REMOVEABLEDEV
;
343 else if ( aVolumeInfo
.m_bIsVolume
)
347 catch( const ::com::sun::star::uno::RuntimeException
& )
349 throw; // dont hide it!
351 catch( const ::com::sun::star::uno::Exception
& )
358 static sal_uInt16
GetImageId_Impl( const INetURLObject
& rObject
, sal_Bool bDetectFolder
)
360 RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog
, "svtools", "hb93813", "SvFileInformationManager::GetImageId_Impl()" );
362 String aExt
, sURL
= rObject
.GetMainURL( INetURLObject::NO_DECODE
);
363 sal_uInt16 nImage
= IMG_FILE
;
365 if ( rObject
.GetProtocol() == INET_PROT_PRIVATE
)
367 String aURLPath
= sURL
.Copy( URL_PREFIX_PRIV_SOFFICE_LEN
);
368 String aType
= aURLPath
.GetToken( 0, INET_PATH_TOKEN
);
369 if ( aType
== String( RTL_CONSTASCII_USTRINGPARAM("factory") ) )
371 // detect an image id for our "private:factory" urls
372 aExt
= GetImageExtensionByFactory_Impl( sURL
);
373 if ( aExt
.Len() > 0 )
374 nImage
= GetImageId_Impl( aExt
);
377 else if ( aType
== String( RTL_CONSTASCII_USTRINGPARAM("image") ) )
378 nImage
= (sal_uInt16
)aURLPath
.GetToken( 1, INET_PATH_TOKEN
).ToInt32();
382 aExt
= rObject
.getExtension();
383 if ( aExt
.EqualsAscii( "vor" ) )
385 SotStorageRef aStorage
= new SotStorage( sURL
, STREAM_STD_READ
);
386 sal_uInt16 nId
= IMG_WRITERTEMPLATE
;
387 if ( !aStorage
->GetError() )
389 SvGlobalName aGlobalName
= aStorage
->GetClassName();
390 if ( aGlobalName
== SvGlobalName(SO3_SC_CLASSID_50
) || aGlobalName
== SvGlobalName(SO3_SC_CLASSID_40
) || aGlobalName
== SvGlobalName(SO3_SC_CLASSID_30
) )
391 nId
= IMG_CALCTEMPLATE
;
392 else if ( aGlobalName
== SvGlobalName(SO3_SDRAW_CLASSID_50
) )
393 nId
= IMG_DRAWTEMPLATE
;
394 else if ( aGlobalName
== SvGlobalName(SO3_SIMPRESS_CLASSID_50
) ||
395 aGlobalName
== SvGlobalName(SO3_SIMPRESS_CLASSID_40
) || aGlobalName
== SvGlobalName(SO3_SIMPRESS_CLASSID_30
) )
396 nId
= IMG_IMPRESSTEMPLATE
;
397 else if ( aGlobalName
== SvGlobalName(SO3_SM_CLASSID_50
) || aGlobalName
== SvGlobalName(SO3_SM_CLASSID_40
) || aGlobalName
== SvGlobalName(SO3_SM_CLASSID_30
) )
398 nId
= IMG_MATHTEMPLATE
;
405 if ( nImage
== IMG_FILE
&& sURL
.Len() )
407 if ( bDetectFolder
&& CONTENT_HELPER::IsFolder( sURL
) )
408 nImage
= GetFolderImageId_Impl( sURL
);
409 else if ( aExt
.Len() > 0 )
410 nImage
= GetImageId_Impl( aExt
);
415 static sal_uInt16
GetDescriptionId_Impl( const String
& rExtension
, sal_Bool
& rbShowExt
)
419 if ( rExtension
.Len() != NO_INDEX
)
421 sal_uInt16 nIndex
= GetIndexOfExtension_Impl( rExtension
);
422 if ( nIndex
!= NO_INDEX
)
424 nId
= ExtensionMap_Impl
[ nIndex
]._nStrId
;
425 rbShowExt
= ExtensionMap_Impl
[ nIndex
]._bExt
;
432 static String
GetDescriptionByFactory_Impl( const String
& rFactory
)
434 sal_uInt16 nResId
= 0;
435 if ( rFactory
.EqualsIgnoreCaseAscii( "swriter", 0, 7 ) )
436 nResId
= STR_DESCRIPTION_FACTORY_WRITER
;
437 else if ( rFactory
.EqualsIgnoreCaseAscii( "scalc", 0, 5 ) )
438 nResId
= STR_DESCRIPTION_FACTORY_CALC
;
439 else if ( rFactory
.EqualsIgnoreCaseAscii( "simpress", 0, 8 ) )
440 nResId
= STR_DESCRIPTION_FACTORY_IMPRESS
;
441 else if ( rFactory
.EqualsIgnoreCaseAscii( "sdraw", 0, 5 ) )
442 nResId
= STR_DESCRIPTION_FACTORY_DRAW
;
443 else if ( rFactory
.EqualsIgnoreCaseAscii( "swriter/web", 0, 11 ) )
444 nResId
= STR_DESCRIPTION_FACTORY_WRITERWEB
;
445 else if ( rFactory
.EqualsIgnoreCaseAscii( "swriter/globaldocument", 0, 22 ) )
446 nResId
= STR_DESCRIPTION_FACTORY_GLOBALDOC
;
447 else if ( rFactory
.EqualsIgnoreCaseAscii( "smath", 0, 5 ) )
448 nResId
= STR_DESCRIPTION_FACTORY_MATH
;
449 else if ( rFactory
.EqualsIgnoreCaseAscii( "sdatabase", 0, 9 ) )
450 nResId
= STR_DESCRIPTION_FACTORY_DATABASE
;
454 SolarMutexGuard aGuard
;
455 return SvtResId(nResId
).toString();
460 static sal_uInt16
GetFolderDescriptionId_Impl( const String
& rURL
)
462 sal_uInt16 nRet
= STR_DESCRIPTION_FOLDER
;
463 svtools::VolumeInfo aVolumeInfo
;
466 ::ucbhelper::Content
aCnt( rURL
, ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
467 if ( GetVolumeProperties_Impl( aCnt
, aVolumeInfo
) )
469 if ( aVolumeInfo
.m_bIsRemote
)
470 nRet
= STR_DESCRIPTION_REMOTE_VOLUME
;
471 else if ( aVolumeInfo
.m_bIsFloppy
)
472 nRet
= STR_DESCRIPTION_FLOPPY_VOLUME
;
473 else if ( aVolumeInfo
.m_bIsCompactDisc
)
474 nRet
= STR_DESCRIPTION_CDROM_VOLUME
;
475 else if ( aVolumeInfo
.m_bIsRemoveable
|| aVolumeInfo
.m_bIsVolume
)
476 nRet
= STR_DESCRIPTION_LOCALE_VOLUME
;
479 catch( const ::com::sun::star::uno::RuntimeException
& )
481 throw; // dont hide it!
483 catch( const ::com::sun::star::uno::Exception
& )
490 static Image
GetImageFromList_Impl( sal_uInt16 nImageId
, sal_Bool bBig
)
492 if ( !bBig
&& IMG_FOLDER
== nImageId
)
493 // return our new small folder image (256 colors)
494 return Image( SvtResId( IMG_SVT_FOLDER
) );
496 ImageList
* pList
= NULL
;
498 static vcl::DeleteOnDeinit
< ImageList
> xSmallImageList( NULL
);
499 static vcl::DeleteOnDeinit
< ImageList
> xBigImageList( NULL
);
500 static sal_uLong nStyle
= Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
502 // If the style has been changed, throw away our cache of the older images
503 if ( nStyle
!= Application::GetSettings().GetStyleSettings().GetSymbolsStyle() )
505 xSmallImageList
.reset();
506 xBigImageList
.reset();
507 nStyle
= Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
512 if ( !xBigImageList
.get() )
513 xBigImageList
.reset(new ImageList(SvtResId(RID_SVTOOLS_IMAGELIST_BIG
)));
514 pList
= xBigImageList
.get();
518 if ( !xSmallImageList
.get() )
519 xSmallImageList
.reset(new ImageList(SvtResId(RID_SVTOOLS_IMAGELIST_SMALL
)));
520 pList
= xSmallImageList
.get();
523 if ( pList
->HasImageAtPos( nImageId
) )
524 return pList
->GetImage( nImageId
);
528 String
SvFileInformationManager::GetDescription_Impl( const INetURLObject
& rObject
, sal_Bool bDetectFolder
)
530 RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog
, "svtools", "hb93813", "SvFileInformationManager::GetDescription_Impl()" );
532 OUString
sExtension(rObject
.getExtension());
533 String sDescription
, sURL( rObject
.GetMainURL( INetURLObject::NO_DECODE
) );
534 sal_uInt16 nResId
= 0;
535 sal_Bool bShowExt
= sal_False
, bDetected
= sal_False
, bOnlyFile
= sal_False
;
536 sal_Bool bFolder
= bDetectFolder
? CONTENT_HELPER::IsFolder( sURL
) : sal_False
;
541 if ( rObject
.GetProtocol() == INET_PROT_PRIVATE
)
543 String aURLPath
= sURL
.Copy( URL_PREFIX_PRIV_SOFFICE_LEN
);
544 String aType
= aURLPath
.GetToken( 0, INET_PATH_TOKEN
);
545 if ( aType
== String( RTL_CONSTASCII_USTRINGPARAM("factory") ) )
547 sDescription
= GetDescriptionByFactory_Impl( aURLPath
.Copy( aURLPath
.Search( INET_PATH_TOKEN
) + 1 ) );
548 bDetected
= sal_True
;
554 // search a description by extension
555 bool bExt
= !sExtension
.isEmpty();
558 sExtension
= sExtension
.toAsciiLowerCase();
559 nResId
= GetDescriptionId_Impl( sExtension
, bShowExt
);
563 nResId
= STR_DESCRIPTION_FILE
;
570 nResId
= GetFolderDescriptionId_Impl( sURL
);
576 bShowExt
= sal_False
;
577 sExtension
= sExtension
.toAsciiUpperCase();
578 sDescription
= sExtension
;
581 SolarMutexGuard aGuard
;
582 sDescription
+= SvtResId(nResId
).toString();
585 DBG_ASSERT( sDescription
.Len() > 0, "file without description" );
589 sDescription
+= String( RTL_CONSTASCII_USTRINGPARAM(" (") );
590 sDescription
+= sExtension
;
597 Image
SvFileInformationManager::GetImage( const INetURLObject
& rObject
, sal_Bool bBig
)
599 sal_uInt16 nImage
= GetImageId_Impl( rObject
, sal_True
);
600 DBG_ASSERT( nImage
, "invalid ImageId" );
601 return GetImageFromList_Impl( nImage
, bBig
);
604 Image
SvFileInformationManager::GetFileImage( const INetURLObject
& rObject
, sal_Bool bBig
)
606 sal_Int16 nImage
= GetImageId_Impl( rObject
, sal_False
);
607 DBG_ASSERT( nImage
, "invalid ImageId" );
608 return GetImageFromList_Impl( nImage
, bBig
);
611 Image
SvFileInformationManager::GetImageNoDefault( const INetURLObject
& rObject
, sal_Bool bBig
)
613 sal_uInt16 nImage
= GetImageId_Impl( rObject
, sal_True
);
614 DBG_ASSERT( nImage
, "invalid ImageId" );
616 if ( nImage
== IMG_FILE
)
619 return GetImageFromList_Impl( nImage
, bBig
);
622 Image
SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo
& rInfo
, sal_Bool bBig
)
624 sal_uInt16 nImage
= IMG_FOLDER
;
625 DBG_ASSERT( nImage
, "invalid ImageId" );
627 if ( rInfo
.m_bIsRemote
)
628 nImage
= IMG_NETWORKDEV
;
629 else if ( rInfo
.m_bIsCompactDisc
)
630 nImage
= IMG_CDROMDEV
;
631 else if ( rInfo
.m_bIsRemoveable
|| rInfo
.m_bIsFloppy
)
632 nImage
= IMG_REMOVEABLEDEV
;
633 else if ( rInfo
.m_bIsVolume
)
634 nImage
= IMG_FIXEDDEV
;
636 return GetImageFromList_Impl( nImage
, bBig
);
639 String
SvFileInformationManager::GetDescription( const INetURLObject
& rObject
)
641 return SvFileInformationManager::GetDescription_Impl( rObject
, sal_True
);
644 String
SvFileInformationManager::GetFileDescription( const INetURLObject
& rObject
)
646 return SvFileInformationManager::GetDescription_Impl( rObject
, sal_False
);
649 String
SvFileInformationManager::GetFolderDescription( const svtools::VolumeInfo
& rInfo
)
651 sal_uInt16 nResId
= STR_DESCRIPTION_FOLDER
;
652 if ( rInfo
.m_bIsRemote
)
653 nResId
= STR_DESCRIPTION_REMOTE_VOLUME
;
654 else if ( rInfo
.m_bIsFloppy
)
655 nResId
= STR_DESCRIPTION_FLOPPY_VOLUME
;
656 else if ( rInfo
.m_bIsCompactDisc
)
657 nResId
= STR_DESCRIPTION_CDROM_VOLUME
;
658 else if ( rInfo
.m_bIsRemoveable
|| rInfo
.m_bIsVolume
)
659 nResId
= STR_DESCRIPTION_LOCALE_VOLUME
;
661 return SvtResId(nResId
).toString();
664 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */