1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imagemgr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 // includes --------------------------------------------------------------
36 #include "imagemgr.hxx"
37 #include <tools/urlobj.hxx>
38 #include <tools/debug.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/wrkwin.hxx>
41 #include "vcl/image.hxx"
42 #include <sot/storage.hxx>
43 #include <sot/clsids.hxx>
44 #include <unotools/ucbhelper.hxx>
45 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
46 #include <comphelper/processfactory.hxx>
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #include <com/sun/star/container/XNameContainer.hpp>
50 #include <com/sun/star/document/XTypeDetection.hpp>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
53 #include <ucbhelper/content.hxx>
54 #include <tools/rcid.h>
55 #include <rtl/logfile.hxx>
56 #include <unotools/configmgr.hxx>
58 #include <svtools/svtools.hrc>
59 #include "imagemgr.hrc"
60 #include <svtools/svtdata.hxx>
62 // globals *******************************************************************
64 #define NO_INDEX ((USHORT)0xFFFF)
65 #define CONTENT_HELPER ::utl::UCBContentHelper
66 #define ASCII_STRING(s) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) )
68 struct SvtExtensionResIdMapping_Impl
76 static SvtExtensionResIdMapping_Impl __READONLY_DATA ExtensionMap_Impl
[] =
78 { "awk", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
79 { "bas", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
80 { "bat", TRUE
, STR_DESCRIPTION_BATCHFILE
, IMG_APP
},
81 { "bmk", FALSE
, STR_DESCRIPTION_BOOKMARKFILE
, 0 },
82 { "bmp", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_BITMAP
},
83 { "c", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
84 { "cfg", FALSE
, STR_DESCRIPTION_CFGFILE
, 0 },
85 { "cmd", TRUE
, STR_DESCRIPTION_BATCHFILE
, IMG_APP
},
86 { "cob", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
87 { "com", TRUE
, STR_DESCRIPTION_APPLICATION
, IMG_APP
},
88 { "cxx", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
89 { "dbf", TRUE
, STR_DESCRIPTION_DATABASE_TABLE
, IMG_TABLE
},
90 { "def", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
91 { "dll", TRUE
, STR_DESCRIPTION_SYSFILE
, 0 },
92 { "doc", FALSE
, STR_DESCRIPTION_WORD_DOC
, IMG_WORD
},
93 { "dxf", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_DXF
},
94 { "exe", TRUE
, STR_DESCRIPTION_APPLICATION
, IMG_APP
},
95 { "gif", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_GIF
},
96 { "h", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
97 { "hlp", FALSE
, STR_DESCRIPTION_HELP_DOC
, IMG_HELP
},
98 { "hrc", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
99 { "htm", FALSE
, STR_DESCRIPTION_HTMLFILE
, IMG_HTML
},
100 { "html", FALSE
, STR_DESCRIPTION_HTMLFILE
, IMG_HTML
},
101 { "asp", FALSE
, STR_DESCRIPTION_HTMLFILE
, IMG_HTML
},
102 { "hxx", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
103 { "ini", FALSE
, STR_DESCRIPTION_CFGFILE
, 0 },
104 { "java", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
105 { "jpeg", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_JPG
},
106 { "jpg", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_JPG
},
107 { "lha", TRUE
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
109 { "lnk", FALSE
, 0, 0 },
111 { "log", TRUE
, STR_DESCRIPTION_LOGFILE
, 0 },
112 { "lst", TRUE
, STR_DESCRIPTION_LOGFILE
, 0 },
113 { "met", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_MET
},
114 { "mml", FALSE
, STR_DESCRIPTION_MATHML_DOC
, IMG_MATH
},
115 { "mod", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
116 { "odb", FALSE
, STR_DESCRIPTION_OO_DATABASE_DOC
, IMG_OO_DATABASE_DOC
},
117 { "odg", FALSE
, STR_DESCRIPTION_OO_DRAW_DOC
, IMG_OO_DRAW_DOC
},
118 { "odf", FALSE
, STR_DESCRIPTION_OO_MATH_DOC
, IMG_OO_MATH_DOC
},
119 { "odm", FALSE
, STR_DESCRIPTION_OO_GLOBAL_DOC
, IMG_OO_GLOBAL_DOC
},
120 { "odp", FALSE
, STR_DESCRIPTION_OO_IMPRESS_DOC
, IMG_OO_IMPRESS_DOC
},
121 { "ods", FALSE
, STR_DESCRIPTION_OO_CALC_DOC
, IMG_OO_CALC_DOC
},
122 { "odt", FALSE
, STR_DESCRIPTION_OO_WRITER_DOC
, IMG_OO_WRITER_DOC
},
123 { "otg", FALSE
, STR_DESCRIPTION_OO_DRAW_TEMPLATE
, IMG_OO_DRAW_TEMPLATE
},
124 { "otp", FALSE
, STR_DESCRIPTION_OO_IMPRESS_TEMPLATE
, IMG_OO_IMPRESS_TEMPLATE
},
125 { "ots", FALSE
, STR_DESCRIPTION_OO_CALC_TEMPLATE
, IMG_OO_CALC_TEMPLATE
},
126 { "ott", FALSE
, STR_DESCRIPTION_OO_WRITER_TEMPLATE
, IMG_OO_WRITER_TEMPLATE
},
127 { "pas", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
128 { "pcd", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCD
},
129 { "pct", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCT
},
130 { "pcx", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCX
},
131 { "pl", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
132 { "png", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PNG
},
133 { "rar", TRUE
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
134 { "sbl", FALSE
, 0, IMG_MACROLIB
},
135 { "sch", FALSE
, 0, 0 },
136 { "sda", FALSE
, STR_DESCRIPTION_SDRAW_DOC
, IMG_DRAW
},
137 { "sdb", FALSE
, STR_DESCRIPTION_SDATABASE_DOC
, IMG_DATABASE
},
138 { "sdc", FALSE
, STR_DESCRIPTION_SCALC_DOC
, IMG_CALC
},
139 { "sdd", FALSE
, STR_DESCRIPTION_SIMPRESS_DOC
, IMG_IMPRESS
},
140 { "sdp", FALSE
, STR_DESCRIPTION_SIMPRESS_DOC
, IMG_IMPRESSPACKED
},
141 { "sds", FALSE
, STR_DESCRIPTION_SCHART_DOC
, IMG_CHART
},
142 { "sdw", FALSE
, STR_DESCRIPTION_SWRITER_DOC
, IMG_WRITER
},
143 { "sga", FALSE
, 0, IMG_GALLERY
},
144 { "sgf", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SGF
},
145 { "sgl", FALSE
, STR_DESCRIPTION_GLOBALDOC
, IMG_GLOBAL_DOC
},
146 { "sgv", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SGV
},
147 { "shtml", FALSE
, STR_DESCRIPTION_HTMLFILE
, IMG_HTML
},
148 { "sim", FALSE
, STR_DESCRIPTION_SIMAGE_DOC
, IMG_SIM
},
149 { "smf", FALSE
, STR_DESCRIPTION_SMATH_DOC
, IMG_MATH
},
150 { "src", TRUE
, STR_DESCRIPTION_SOURCEFILE
, IMG_TEXTFILE
},
151 { "svh", FALSE
, STR_DESCRIPTION_HELP_DOC
, IMG_SVHELP
},
152 { "svm", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SVM
},
153 { "stc", FALSE
, STR_DESCRIPTION_CALC_TEMPLATE
, IMG_CALCTEMPLATE
},
154 { "std", FALSE
, STR_DESCRIPTION_DRAW_TEMPLATE
, IMG_DRAWTEMPLATE
},
155 { "sti", FALSE
, STR_DESCRIPTION_IMPRESS_TEMPLATE
, IMG_IMPRESSTEMPLATE
},
156 { "stw", FALSE
, STR_DESCRIPTION_WRITER_TEMPLATE
, IMG_WRITERTEMPLATE
},
157 { "sxc", FALSE
, STR_DESCRIPTION_SXCALC_DOC
, IMG_CALC
},
158 { "sxd", FALSE
, STR_DESCRIPTION_SXDRAW_DOC
, IMG_DRAW
},
159 { "sxg", FALSE
, STR_DESCRIPTION_SXGLOBAL_DOC
, IMG_GLOBAL_DOC
},
160 { "sxi", FALSE
, STR_DESCRIPTION_SXIMPRESS_DOC
, IMG_IMPRESS
},
161 { "sxm", FALSE
, STR_DESCRIPTION_SXMATH_DOC
, IMG_MATH
},
162 { "sxs", FALSE
, STR_DESCRIPTION_SXCHART_DOC
, IMG_CHART
},
163 { "sxw", FALSE
, STR_DESCRIPTION_SXWRITER_DOC
, IMG_WRITER
},
164 { "sys", TRUE
, STR_DESCRIPTION_SYSFILE
, 0 },
165 { "tif", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_TIFF
},
166 { "tiff", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_TIFF
},
167 { "txt", FALSE
, STR_DESCRIPTION_TEXTFILE
, IMG_TEXTFILE
},
168 { "url", FALSE
, STR_DESCRIPTION_LINK
, IMG_HTML
},
169 { "vor", FALSE
, STR_DESCRIPTION_SOFFICE_TEMPLATE_DOC
, IMG_WRITERTEMPLATE
},
170 { "vxd", TRUE
, STR_DESCRIPTION_SYSFILE
, 0 },
171 { "wmf", TRUE
, STR_DESCRIPTION_GRAPHIC_DOC
, IMG_WMF
},
172 { "xls", FALSE
, STR_DESCRIPTION_EXCEL_DOC
, IMG_EXCEL
},
173 { "xlt", FALSE
, STR_DESCRIPTION_EXCEL_TEMPLATE_DOC
, IMG_EXCELTEMPLATE
},
174 { "uu", TRUE
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
175 { "uue", TRUE
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
176 { "z", TRUE
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
177 { "zip", TRUE
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
178 { "zoo", TRUE
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
179 { "gz", TRUE
, STR_DESCRIPTION_ARCHIVFILE
, 0 },
180 { "ppt", FALSE
, STR_DESCRIPTION_POWERPOINT
, IMG_POWERPOINT
},
181 { "pot", FALSE
, STR_DESCRIPTION_POWERPOINT_TEMPLATE
, IMG_POWERPOINTTEMPLATE
},
182 { "pps", FALSE
, STR_DESCRIPTION_POWERPOINT_SHOW
, IMG_POWERPOINT
},
183 { "oxt", FALSE
, STR_DESCRIPTION_EXTENSION
, IMG_EXTENSION
},
188 SvtExtensionResIdMapping_Impl Mappings
[] =
190 {"StarWriter 4.0", FALSE
,STR_DESCRIPTION_SWRITER_DOC
, IMG_WRITER
},
191 {"StarWriter 3.0", FALSE
,STR_DESCRIPTION_SWRITER_DOC
, IMG_WRITER
},
192 {"StarCalc 4.0", FALSE
,STR_DESCRIPTION_SCALC_DOC
, IMG_CALC
},
193 {"StarCalc 3.0", FALSE
,STR_DESCRIPTION_SCALC_DOC
, IMG_CALC
},
194 {"StarImpress 4.0", FALSE
,STR_DESCRIPTION_SIMPRESS_DOC
,IMG_IMPRESS
},
195 {"StarDraw 4.0", FALSE
,STR_DESCRIPTION_SDRAW_DOC
, IMG_DRAW
},
196 {"StarDraw 3.0", FALSE
,STR_DESCRIPTION_SDRAW_DOC
, IMG_DRAW
},
197 {"StarChart 3.0", FALSE
,STR_DESCRIPTION_SCHART_DOC
, IMG_CHART
},
198 {"StarChart 4.0", FALSE
,STR_DESCRIPTION_SCHART_DOC
, IMG_CHART
},
199 {"Bitmap", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_BITMAP
},
200 {"AutoCAD", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SIM
},
201 {"Gif-File", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_GIF
},
202 {"JPEG-File", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_JPG
},
203 {"Metafile ", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SIM
},
204 {"Photo-CD ", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCD
},
205 {"Mac Pict", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCT
},
206 {"PCX-File ", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_PCX
},
207 {"PNG-File", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SIM
},
208 {"SV-Metafile", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_SIM
},
209 {"TIFF-File", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_TIFF
},
210 {"MS-Metafile", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_WMF
},
211 {"XBM-File", FALSE
,STR_DESCRIPTION_GRAPHIC_DOC
, IMG_BITMAP
},
212 {"UniformResourceLocator", FALSE
,STR_DESCRIPTION_LINK
, IMG_URL
},
217 struct SvtFactory2ExtensionMapping_Impl
219 const char* _pFactory
;
220 const char* _pExtension
;
223 // mapping from "private:factory" url to extension
225 static SvtFactory2ExtensionMapping_Impl __READONLY_DATA Fac2ExtMap_Impl
[] =
227 { "swriter", "odt" },
228 { "swriter/web", "html" },
229 { "swriter/GlobalDocument", "odm" },
231 { "simpress", "odp" },
234 { "sdatabase", "odb" },
238 //****************************************************************************
240 static String
GetImageExtensionByFactory_Impl( const String
& rURL
)
242 INetURLObject
aObj( rURL
);
243 String aPath
= aObj
.GetURLPath( INetURLObject::NO_DECODE
);
249 while ( Fac2ExtMap_Impl
[ nIndex
]._pFactory
)
251 if ( aPath
.EqualsAscii( Fac2ExtMap_Impl
[ nIndex
]._pFactory
) )
254 aExtension
= String::CreateFromAscii( Fac2ExtMap_Impl
[ nIndex
]._pExtension
);
262 // no extension found, so use the type detection (performance brake)
266 // get the TypeDetection service to access all registered types
267 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> xFac
= ::comphelper::getProcessServiceFactory();
268 ::com::sun::star::uno::Reference
< ::com::sun::star::document::XTypeDetection
> xTypeDetector(
269 xFac
->createInstance( ASCII_STRING("com.sun.star.document.TypeDetection") ), ::com::sun::star::uno::UNO_QUERY
);
271 ::rtl::OUString aInternalType
= xTypeDetector
->queryTypeByURL( rURL
);
272 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> xAccess( xTypeDetector
, ::com::sun::star::uno::UNO_QUERY
);
273 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
> aTypeProps
;
274 if ( aInternalType
.getLength() > 0 && xAccess
->hasByName( aInternalType
) )
276 xAccess
->getByName( aInternalType
) >>= aTypeProps
;
277 sal_Int32 nProps
= aTypeProps
.getLength();
278 for ( sal_Int32 i
= 0; i
< nProps
; ++i
)
280 const ::com::sun::star::beans::PropertyValue
& rProp
= aTypeProps
[i
];
281 if ( rProp
.Name
.compareToAscii("Extensions") == COMPARE_EQUAL
)
283 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aExtensions
;
284 if ( ( rProp
.Value
>>= aExtensions
) && aExtensions
.getLength() > 0 )
286 const ::rtl::OUString
* pExtensions
= aExtensions
.getConstArray();
287 aExtension
= String( pExtensions
[0] );
294 catch( const ::com::sun::star::uno::RuntimeException
& )
296 throw; // dont hide it!
298 catch( const ::com::sun::star::uno::Exception
& )
300 // type detection failed -> no extension
306 static USHORT
GetIndexOfExtension_Impl( const String
& rExtension
)
308 USHORT nRet
= NO_INDEX
;
309 if ( rExtension
.Len() )
312 String aExt
= rExtension
;
314 while ( ExtensionMap_Impl
[ nIndex
]._pExt
)
316 if ( aExt
.EqualsAscii( ExtensionMap_Impl
[ nIndex
]._pExt
) )
328 static USHORT
GetImageId_Impl( const String
& rExtension
)
330 USHORT nImage
= IMG_FILE
;
331 if ( rExtension
.Len() != NO_INDEX
)
333 USHORT nIndex
= GetIndexOfExtension_Impl( rExtension
);
334 if ( nIndex
!= NO_INDEX
)
336 nImage
= ExtensionMap_Impl
[ nIndex
]._nImgId
;
345 static sal_Bool
GetVolumeProperties_Impl( ::ucbhelper::Content
& rContent
, svtools::VolumeInfo
& rVolumeInfo
)
347 sal_Bool bRet
= sal_False
;
351 bRet
= ( ( rContent
.getPropertyValue( ASCII_STRING("IsVolume") ) >>= rVolumeInfo
.m_bIsVolume
) &&
352 ( rContent
.getPropertyValue( ASCII_STRING("IsRemote") ) >>= rVolumeInfo
.m_bIsRemote
) &&
353 ( rContent
.getPropertyValue( ASCII_STRING("IsRemoveable") ) >>= rVolumeInfo
.m_bIsRemoveable
) &&
354 ( rContent
.getPropertyValue( ASCII_STRING("IsFloppy") ) >>= rVolumeInfo
.m_bIsFloppy
) &&
355 ( rContent
.getPropertyValue( ASCII_STRING("IsCompactDisc") ) >>= rVolumeInfo
.m_bIsCompactDisc
) );
357 catch( const ::com::sun::star::uno::RuntimeException
& )
359 throw; // dont hide it!
361 catch( const ::com::sun::star::uno::Exception
& )
363 // type detection failed -> no extension
369 static USHORT
GetFolderImageId_Impl( const String
& rURL
)
371 USHORT nRet
= IMG_FOLDER
;
372 ::svtools::VolumeInfo aVolumeInfo
;
375 ::ucbhelper::Content
aCnt( rURL
, ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XCommandEnvironment
> () );
376 if ( GetVolumeProperties_Impl( aCnt
, aVolumeInfo
) )
378 if ( aVolumeInfo
.m_bIsRemote
)
379 nRet
= IMG_NETWORKDEV
;
380 else if ( aVolumeInfo
.m_bIsCompactDisc
)
382 else if ( aVolumeInfo
.m_bIsRemoveable
)
383 nRet
= IMG_REMOVEABLEDEV
;
384 else if ( aVolumeInfo
.m_bIsVolume
)
388 catch( const ::com::sun::star::uno::RuntimeException
& )
390 throw; // dont hide it!
392 catch( const ::com::sun::star::uno::Exception
& )
399 static USHORT
GetImageId_Impl( const INetURLObject
& rObject
, sal_Bool bDetectFolder
)
401 RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog
, "svtools", "hb93813", "SvFileInformationManager::GetImageId_Impl()" );
403 String aExt
, sURL
= rObject
.GetMainURL( INetURLObject::NO_DECODE
);
404 USHORT nImage
= IMG_FILE
;
406 if ( rObject
.GetProtocol() == INET_PROT_PRIVATE
)
408 String aURLPath
= sURL
.Copy( URL_PREFIX_PRIV_SOFFICE_LEN
);
409 String aType
= aURLPath
.GetToken( 0, INET_PATH_TOKEN
);
410 if ( aType
== String( RTL_CONSTASCII_STRINGPARAM("factory") ) )
412 // detect an image id for our "private:factory" urls
413 aExt
= GetImageExtensionByFactory_Impl( sURL
);
414 if ( aExt
.Len() > 0 )
415 nImage
= GetImageId_Impl( aExt
);
418 else if ( aType
== String( RTL_CONSTASCII_STRINGPARAM("image") ) )
419 nImage
= (USHORT
)aURLPath
.GetToken( 1, INET_PATH_TOKEN
).ToInt32();
423 aExt
= rObject
.getExtension();
424 if ( aExt
.EqualsAscii( "vor" ) )
426 SotStorageRef aStorage
= new SotStorage( sURL
, STREAM_STD_READ
);
427 USHORT nId
= IMG_WRITERTEMPLATE
;
428 if ( !aStorage
->GetError() )
430 SvGlobalName aGlobalName
= aStorage
->GetClassName();
431 if ( aGlobalName
== SvGlobalName(SO3_SC_CLASSID_50
) || aGlobalName
== SvGlobalName(SO3_SC_CLASSID_40
) || aGlobalName
== SvGlobalName(SO3_SC_CLASSID_30
) )
432 nId
= IMG_CALCTEMPLATE
;
433 else if ( aGlobalName
== SvGlobalName(SO3_SDRAW_CLASSID_50
) )
434 nId
= IMG_DRAWTEMPLATE
;
435 else if ( aGlobalName
== SvGlobalName(SO3_SIMPRESS_CLASSID_50
) ||
436 aGlobalName
== SvGlobalName(SO3_SIMPRESS_CLASSID_40
) || aGlobalName
== SvGlobalName(SO3_SIMPRESS_CLASSID_30
) )
437 nId
= IMG_IMPRESSTEMPLATE
;
438 else if ( aGlobalName
== SvGlobalName(SO3_SM_CLASSID_50
) || aGlobalName
== SvGlobalName(SO3_SM_CLASSID_40
) || aGlobalName
== SvGlobalName(SO3_SM_CLASSID_30
) )
439 nId
= IMG_MATHTEMPLATE
;
446 if ( nImage
== IMG_FILE
&& sURL
.Len() )
448 if ( bDetectFolder
&& CONTENT_HELPER::IsFolder( sURL
) )
449 nImage
= GetFolderImageId_Impl( sURL
);
450 else if ( aExt
.Len() > 0 )
451 nImage
= GetImageId_Impl( aExt
);
456 static USHORT
GetDescriptionId_Impl( const String
& rExtension
, sal_Bool
& rbShowExt
)
460 if ( rExtension
.Len() != NO_INDEX
)
462 USHORT nIndex
= GetIndexOfExtension_Impl( rExtension
);
463 if ( nIndex
!= NO_INDEX
)
465 nId
= ExtensionMap_Impl
[ nIndex
]._nStrId
;
466 rbShowExt
= ExtensionMap_Impl
[ nIndex
]._bExt
;
473 static String
GetDescriptionByFactory_Impl( const String
& rFactory
)
476 if ( rFactory
.EqualsIgnoreCaseAscii( "swriter", 0, 7 ) )
477 nResId
= STR_DESCRIPTION_FACTORY_WRITER
;
478 else if ( rFactory
.EqualsIgnoreCaseAscii( "scalc", 0, 5 ) )
479 nResId
= STR_DESCRIPTION_FACTORY_CALC
;
480 else if ( rFactory
.EqualsIgnoreCaseAscii( "simpress", 0, 8 ) )
481 nResId
= STR_DESCRIPTION_FACTORY_IMPRESS
;
482 else if ( rFactory
.EqualsIgnoreCaseAscii( "sdraw", 0, 5 ) )
483 nResId
= STR_DESCRIPTION_FACTORY_DRAW
;
484 else if ( rFactory
.EqualsIgnoreCaseAscii( "swriter/web", 0, 11 ) )
485 nResId
= STR_DESCRIPTION_FACTORY_WRITERWEB
;
486 else if ( rFactory
.EqualsIgnoreCaseAscii( "swriter/globaldocument", 0, 22 ) )
487 nResId
= STR_DESCRIPTION_FACTORY_GLOBALDOC
;
488 else if ( rFactory
.EqualsIgnoreCaseAscii( "smath", 0, 5 ) )
489 nResId
= STR_DESCRIPTION_FACTORY_MATH
;
490 else if ( rFactory
.EqualsIgnoreCaseAscii( "sdatabase", 0, 9 ) )
491 nResId
= STR_DESCRIPTION_FACTORY_DATABASE
;
496 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
497 aRet
= String( SvtResId( nResId
) );
502 static USHORT
GetFolderDescriptionId_Impl( const String
& rURL
)
504 USHORT nRet
= STR_DESCRIPTION_FOLDER
;
505 svtools::VolumeInfo aVolumeInfo
;
508 ::ucbhelper::Content
aCnt( rURL
, ::com::sun::star::uno::Reference
< ::com::sun::star::ucb::XCommandEnvironment
> () );
509 if ( GetVolumeProperties_Impl( aCnt
, aVolumeInfo
) )
511 if ( aVolumeInfo
.m_bIsRemote
)
512 nRet
= STR_DESCRIPTION_REMOTE_VOLUME
;
513 else if ( aVolumeInfo
.m_bIsFloppy
)
514 nRet
= STR_DESCRIPTION_FLOPPY_VOLUME
;
515 else if ( aVolumeInfo
.m_bIsCompactDisc
)
516 nRet
= STR_DESCRIPTION_CDROM_VOLUME
;
517 else if ( aVolumeInfo
.m_bIsRemoveable
|| aVolumeInfo
.m_bIsVolume
)
518 nRet
= STR_DESCRIPTION_LOCALE_VOLUME
;
521 catch( const ::com::sun::star::uno::RuntimeException
& )
523 throw; // dont hide it!
525 catch( const ::com::sun::star::uno::Exception
& )
532 static ResMgr
* GetIsoResMgr_Impl()
534 static ResMgr
* pIsoResMgr
= NULL
;
538 ByteString
aResMgrName( "iso" );
539 pIsoResMgr
= ResMgr::CreateResMgr(
540 aResMgrName
.GetBuffer(), Application::GetSettings().GetUILocale() );
543 // no "iso" resource -> search for "ooo" resource
544 aResMgrName
= ByteString( "ooo" );
545 pIsoResMgr
= ResMgr::CreateResMgr(
546 aResMgrName
.GetBuffer(), Application::GetSettings().GetUILocale() );
553 static ImageList
* CreateImageList_Impl( USHORT nResId
)
555 ImageList
* pList
= NULL
;
556 ResMgr
* pResMgr
= GetIsoResMgr_Impl();
557 DBG_ASSERT( pResMgr
, "SvFileInformationManager::CreateImageList_Impl(): no resmgr" );
558 ResId
aResId( nResId
, *pResMgr
);
559 aResId
.SetRT( RSC_IMAGELIST
);
560 if ( pResMgr
->IsAvailable( aResId
) )
561 pList
= new ImageList( aResId
);
563 pList
= new ImageList();
567 static Image
GetOfficeImageFromList_Impl( USHORT nImageId
, BOOL bBig
, BOOL bHighContrast
)
569 ImageList
* pList
= NULL
;
571 static ImageList
* _pSmallOfficeImgList
= NULL
;
572 static ImageList
* _pBigOfficeImgList
= NULL
;
573 static ImageList
* _pSmallHCOfficeImgList
= NULL
;
574 static ImageList
* _pBigHCOfficeImgList
= NULL
;
575 static ULONG nStyle
= Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
577 // If the style has been changed, throw away our cache of the older images
578 if ( nStyle
!= Application::GetSettings().GetStyleSettings().GetSymbolsStyle() )
580 delete _pSmallOfficeImgList
, _pSmallOfficeImgList
= NULL
;
581 delete _pBigOfficeImgList
, _pBigOfficeImgList
= NULL
;
582 delete _pSmallHCOfficeImgList
, _pSmallHCOfficeImgList
= NULL
;
583 delete _pBigHCOfficeImgList
, _pBigHCOfficeImgList
= NULL
;
584 nStyle
= Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
587 // #i21242# MT: For B&W we need the HC Image and must transform.
588 // bHiContrast is TRUE for all dark backgrounds, but we need HC Images for HC White also,
589 // so we can't rely on bHighContrast.
590 BOOL bBlackAndWhite
= Application::GetSettings().GetStyleSettings().IsHighContrastBlackAndWhite();
591 if ( bBlackAndWhite
)
592 bHighContrast
= TRUE
;
599 if ( !_pBigHCOfficeImgList
)
600 _pBigHCOfficeImgList
= CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_BIG_HIGHCONTRAST
);
601 pList
= _pBigHCOfficeImgList
;
605 if ( !_pBigOfficeImgList
)
606 _pBigOfficeImgList
= CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_BIG
);
607 pList
= _pBigOfficeImgList
;
614 if ( !_pSmallHCOfficeImgList
)
615 _pSmallHCOfficeImgList
= CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_SMALL_HIGHCONTRAST
);
616 pList
= _pSmallHCOfficeImgList
;
620 if ( !_pSmallOfficeImgList
)
621 _pSmallOfficeImgList
= CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_SMALL
);
622 pList
= _pSmallOfficeImgList
;
626 Image aImage
= pList
->GetImage( nImageId
);
628 if ( bBlackAndWhite
)
630 // First invert the Image, because it's designed for black background, structures are bright
632 // Now make monochrome...
633 ImageColorTransform eTrans
= IMAGECOLORTRANSFORM_MONOCHROME_WHITE
;
634 if ( Application::GetSettings().GetStyleSettings().GetFaceColor().GetColor() == COL_WHITE
)
635 eTrans
= IMAGECOLORTRANSFORM_MONOCHROME_BLACK
;
636 aImage
= aImage
.GetColorTransformedImage( eTrans
);
642 static Image
GetImageFromList_Impl( USHORT nImageId
, BOOL bBig
, BOOL bHighContrast
)
644 if ( !bBig
&& IMG_FOLDER
== nImageId
&& !bHighContrast
)
645 // return our new small folder image (256 colors)
646 return Image( SvtResId( IMG_SVT_FOLDER
) );
648 ImageList
* pList
= NULL
;
650 static ImageList
* _pSmallImageList
= NULL
;
651 static ImageList
* _pBigImageList
= NULL
;
652 static ImageList
* _pSmallHCImageList
= NULL
;
653 static ImageList
* _pBigHCImageList
= NULL
;
654 static ULONG nStyle
= Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
656 // If the style has been changed, throw away our cache of the older images
657 if ( nStyle
!= Application::GetSettings().GetStyleSettings().GetSymbolsStyle() )
659 delete _pSmallImageList
, _pSmallImageList
= NULL
;
660 delete _pBigImageList
, _pBigImageList
= NULL
;
661 delete _pSmallHCImageList
, _pSmallHCImageList
= NULL
;
662 delete _pBigHCImageList
, _pBigHCImageList
= NULL
;
663 nStyle
= Application::GetSettings().GetStyleSettings().GetSymbolsStyle();
670 if ( !_pBigHCImageList
)
671 _pBigHCImageList
= new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_BIG_HIGHCONTRAST
) );
672 pList
= _pBigHCImageList
;
676 if ( !_pBigImageList
)
677 _pBigImageList
= new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_BIG
) );
678 pList
= _pBigImageList
;
685 if ( !_pSmallHCImageList
)
686 _pSmallHCImageList
= new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_SMALL_HIGHCONTRAST
) );
687 pList
= _pSmallHCImageList
;
691 if ( !_pSmallImageList
)
692 _pSmallImageList
= new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_SMALL
) );
693 pList
= _pSmallImageList
;
697 if ( pList
->HasImageAtPos( nImageId
) )
698 return pList
->GetImage( nImageId
);
700 return GetOfficeImageFromList_Impl( nImageId
, bBig
, bHighContrast
);
703 //****************************************************************************
705 void ReplaceStarOfficeVar( String
& _rDescription
)
707 static String
sVariable( RTL_CONSTASCII_STRINGPARAM( "%STAROFFICE" ) );
708 static String sProductName
;
709 if ( sProductName
.Len() == 0 )
711 ::rtl::OUString sTemp
;
712 ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME
) >>= sTemp
;
713 if ( sTemp
.equalsAscii( "StarSuite" ) == sal_False
)
714 sProductName
= String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarOffice" ) );
716 sProductName
= String( sTemp
);
718 _rDescription
.SearchAndReplace( sVariable
, sProductName
);
721 String
SvFileInformationManager::GetDescription_Impl( const INetURLObject
& rObject
, sal_Bool bDetectFolder
)
723 RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog
, "svtools", "hb93813", "SvFileInformationManager::GetDescription_Impl()" );
726 String
sExtension( rObject
.getExtension() ), sURL( rObject
.GetMainURL( INetURLObject::NO_DECODE
) );
728 sal_Bool bShowExt
= sal_False
, bDetected
= sal_False
, bOnlyFile
= sal_False
;
729 sal_Bool bFolder
= bDetectFolder
? CONTENT_HELPER::IsFolder( sURL
) : sal_False
;
734 if ( rObject
.GetProtocol() == INET_PROT_PRIVATE
)
736 String aURLPath
= sURL
.Copy( URL_PREFIX_PRIV_SOFFICE_LEN
);
737 String aType
= aURLPath
.GetToken( 0, INET_PATH_TOKEN
);
738 if ( aType
== String( RTL_CONSTASCII_STRINGPARAM("factory") ) )
740 sDescription
= GetDescriptionByFactory_Impl( aURLPath
.Copy( aURLPath
.Search( INET_PATH_TOKEN
) + 1 ) );
741 bDetected
= sal_True
;
747 // search a description by extension
748 sal_Bool bExt
= ( sExtension
.Len() > 0 );
751 sExtension
.ToLowerAscii();
752 nResId
= GetDescriptionId_Impl( sExtension
, bShowExt
);
756 nResId
= STR_DESCRIPTION_FILE
;
763 nResId
= GetFolderDescriptionId_Impl( sURL
);
769 bShowExt
= sal_False
;
770 sExtension
.ToUpperAscii();
771 sDescription
= sExtension
;
774 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
775 sDescription
+= String( SvtResId( nResId
) );
778 DBG_ASSERT( sDescription
.Len() > 0, "file without description" );
782 sDescription
+= String( RTL_CONSTASCII_STRINGPARAM(" (") );
783 sDescription
+= sExtension
;
787 ReplaceStarOfficeVar( sDescription
);
791 Image
SvFileInformationManager::GetImage( const INetURLObject
& rObject
, sal_Bool bBig
)
793 return GetImage( rObject
, bBig
, FALSE
);
796 Image
SvFileInformationManager::GetFileImage( const INetURLObject
& rObject
, sal_Bool bBig
)
798 return GetFileImage( rObject
, bBig
, FALSE
);
801 Image
SvFileInformationManager::GetImageNoDefault( const INetURLObject
& rObject
, sal_Bool bBig
)
803 return GetImageNoDefault( rObject
, bBig
, FALSE
);
806 Image
SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo
& rInfo
, sal_Bool bBig
)
808 return GetFolderImage( rInfo
, bBig
, FALSE
);
811 Image
SvFileInformationManager::GetImage( const INetURLObject
& rObject
, sal_Bool bBig
, sal_Bool bHighContrast
)
813 USHORT nImage
= GetImageId_Impl( rObject
, sal_True
);
814 DBG_ASSERT( nImage
, "invalid ImageId" );
815 return GetImageFromList_Impl( nImage
, bBig
, bHighContrast
);
818 Image
SvFileInformationManager::GetFileImage( const INetURLObject
& rObject
, sal_Bool bBig
, sal_Bool bHighContrast
)
820 USHORT nImage
= GetImageId_Impl( rObject
, sal_False
);
821 DBG_ASSERT( nImage
, "invalid ImageId" );
822 return GetImageFromList_Impl( nImage
, bBig
, bHighContrast
);
825 Image
SvFileInformationManager::GetImageNoDefault( const INetURLObject
& rObject
, sal_Bool bBig
, sal_Bool bHighContrast
)
827 USHORT nImage
= GetImageId_Impl( rObject
, sal_True
);
828 DBG_ASSERT( nImage
, "invalid ImageId" );
830 if ( nImage
== IMG_FILE
)
833 return GetImageFromList_Impl( nImage
, bBig
, bHighContrast
);
836 Image
SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo
& rInfo
, sal_Bool bBig
, sal_Bool bHighContrast
)
838 USHORT nImage
= IMG_FOLDER
;
839 DBG_ASSERT( nImage
, "invalid ImageId" );
841 if ( rInfo
.m_bIsRemote
)
842 nImage
= IMG_NETWORKDEV
;
843 else if ( rInfo
.m_bIsCompactDisc
)
844 nImage
= IMG_CDROMDEV
;
845 else if ( rInfo
.m_bIsRemoveable
|| rInfo
.m_bIsFloppy
)
846 nImage
= IMG_REMOVEABLEDEV
;
847 else if ( rInfo
.m_bIsVolume
)
848 nImage
= IMG_FIXEDDEV
;
850 return GetImageFromList_Impl( nImage
, bBig
, bHighContrast
);
853 String
SvFileInformationManager::GetDescription( const INetURLObject
& rObject
)
855 return SvFileInformationManager::GetDescription_Impl( rObject
, sal_True
);
858 String
SvFileInformationManager::GetFileDescription( const INetURLObject
& rObject
)
860 return SvFileInformationManager::GetDescription_Impl( rObject
, sal_False
);
863 String
SvFileInformationManager::GetFolderDescription( const svtools::VolumeInfo
& rInfo
)
865 USHORT nResId
= STR_DESCRIPTION_FOLDER
;
866 if ( rInfo
.m_bIsRemote
)
867 nResId
= STR_DESCRIPTION_REMOTE_VOLUME
;
868 else if ( rInfo
.m_bIsFloppy
)
869 nResId
= STR_DESCRIPTION_FLOPPY_VOLUME
;
870 else if ( rInfo
.m_bIsCompactDisc
)
871 nResId
= STR_DESCRIPTION_CDROM_VOLUME
;
872 else if ( rInfo
.m_bIsRemoveable
|| rInfo
.m_bIsVolume
)
873 nResId
= STR_DESCRIPTION_LOCALE_VOLUME
;
875 String sDescription
= String( SvtResId( nResId
) );