cid#1606940 Check of thread-shared field evades lock acquisition
[LibreOffice.git] / svtools / source / misc / imagemgr.cxx
blobb64cfb8081f4608da5d0c8b7acbbe9254f64b38e
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 <comphelper/diagnose_ex.hxx>
22 #include <tools/urlobj.hxx>
23 #include <tools/debug.hxx>
24 #include <vcl/image.hxx>
25 #include <sot/storage.hxx>
26 #include <comphelper/classids.hxx>
27 #include <unotools/ucbhelper.hxx>
28 #include <comphelper/processfactory.hxx>
29 #include <com/sun/star/beans/PropertyValue.hpp>
30 #include <com/sun/star/container/XNameAccess.hpp>
31 #include <com/sun/star/document/XTypeDetection.hpp>
32 #include <com/sun/star/ucb/CommandAbortedException.hpp>
33 #include <com/sun/star/ucb/ContentCreationException.hpp>
34 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
35 #include <com/sun/star/uno/XComponentContext.hpp>
36 #include <ucbhelper/content.hxx>
37 #include <svtools/strings.hrc>
38 #include <svtools/svtresid.hxx>
39 #include <o3tl/string_view.hxx>
40 #include <bitmaps.hlst>
41 #include <strings.hxx>
43 // globals *******************************************************************
45 #define NO_INDEX (-1)
46 #define CONTENT_HELPER ::utl::UCBContentHelper
48 namespace {
50 struct SvtExtensionResIdMapping_Impl
52 const char* _pExt;
53 bool _bExt;
54 TranslateId pStrId;
55 SvImageId _nImgId;
60 SvtExtensionResIdMapping_Impl const ExtensionMap_Impl[] =
62 { "awk", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
63 { "bas", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
64 { "bat", true, STR_DESCRIPTION_BATCHFILE, SvImageId::NONE },
65 { "bmk", false, STR_DESCRIPTION_BOOKMARKFILE, SvImageId::NONE },
66 { "bmp", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::Bitmap },
67 { "c", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
68 { "cfg", false, STR_DESCRIPTION_CFGFILE, SvImageId::NONE },
69 { "cmd", true, STR_DESCRIPTION_BATCHFILE, SvImageId::NONE },
70 { "cob", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
71 { "com", true, STR_DESCRIPTION_APPLICATION, SvImageId::NONE },
72 { "cxx", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
73 { "dbf", true, STR_DESCRIPTION_DATABASE_TABLE, SvImageId::Table },
74 { "def", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
75 { "dll", true, STR_DESCRIPTION_SYSFILE, SvImageId::NONE },
76 { "doc", false, STR_DESCRIPTION_WORD_DOC, SvImageId::Writer },
77 { "dot", false, STR_DESCRIPTION_WORD_DOC, SvImageId::WriterTemplate },
78 { "docx", false, STR_DESCRIPTION_WORD_DOC, SvImageId::Writer },
79 { "dxf", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::DXF },
80 { "exe", true, STR_DESCRIPTION_APPLICATION, SvImageId::NONE },
81 { "gif", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::GIF },
82 { "h", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
83 { "hlp", false, STR_DESCRIPTION_HELP_DOC, SvImageId::NONE },
84 { "hrc", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
85 { "htm", false, STR_DESCRIPTION_HTMLFILE, SvImageId::HTML },
86 { "html", false, STR_DESCRIPTION_HTMLFILE, SvImageId::HTML },
87 { "asp", false, STR_DESCRIPTION_HTMLFILE, SvImageId::HTML },
88 { "hxx", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
89 { "ini", false, STR_DESCRIPTION_CFGFILE, SvImageId::NONE },
90 { "java", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
91 { "jpeg", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::JPG },
92 { "jpg", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::JPG },
93 { "lha", true, STR_DESCRIPTION_ARCHIVFILE, SvImageId::NONE },
94 #ifdef _WIN32
95 { "lnk", false, {}, SvImageId::NONE },
96 #endif
97 { "log", true, STR_DESCRIPTION_LOGFILE, SvImageId::NONE },
98 { "lst", true, STR_DESCRIPTION_LOGFILE, SvImageId::NONE },
99 { "met", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::MET },
100 { "mml", false, STR_DESCRIPTION_MATHML_DOC, SvImageId::Math },
101 { "mod", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
102 { "odb", false, STR_DESCRIPTION_OO_DATABASE_DOC, SvImageId::OO_DatabaseDoc },
103 { "odg", false, STR_DESCRIPTION_OO_DRAW_DOC, SvImageId::OO_DrawDoc },
104 { "fodg", false, STR_DESCRIPTION_OO_DRAW_DOC, SvImageId::OO_DrawDoc },
105 { "odf", false, STR_DESCRIPTION_OO_MATH_DOC, SvImageId::OO_MathDoc },
106 { "odm", false, STR_DESCRIPTION_OO_GLOBAL_DOC, SvImageId::OO_GlobalDoc },
107 { "odp", false, STR_DESCRIPTION_OO_IMPRESS_DOC, SvImageId::OO_ImpressDoc },
108 { "fodp", false, STR_DESCRIPTION_OO_IMPRESS_DOC, SvImageId::OO_ImpressDoc },
109 { "ods", false, STR_DESCRIPTION_OO_CALC_DOC, SvImageId::OO_CalcDoc },
110 { "fods", false, STR_DESCRIPTION_OO_CALC_DOC, SvImageId::OO_CalcDoc },
111 { "odt", false, STR_DESCRIPTION_OO_WRITER_DOC, SvImageId::OO_WriterDoc },
112 { "fodt", false, STR_DESCRIPTION_OO_WRITER_DOC, SvImageId::OO_WriterDoc },
113 { "otg", false, STR_DESCRIPTION_OO_DRAW_TEMPLATE, SvImageId::OO_DrawTemplate },
114 { "otp", false, STR_DESCRIPTION_OO_IMPRESS_TEMPLATE, SvImageId::OO_ImpressTemplate },
115 { "ots", false, STR_DESCRIPTION_OO_CALC_TEMPLATE, SvImageId::OO_CalcTemplate },
116 { "ott", false, STR_DESCRIPTION_OO_WRITER_TEMPLATE, SvImageId::OO_WriterTemplate },
117 { "pas", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
118 { "pcd", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::PCD },
119 { "pct", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::PCT },
120 { "pict", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::PCT },
121 { "pcx", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::PCX },
122 { "pl", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
123 { "png", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::PNG },
124 { "rar", true, STR_DESCRIPTION_ARCHIVFILE, SvImageId::NONE },
125 { "rtf", false, STR_DESCRIPTION_WORD_DOC, SvImageId::Writer },
126 { "sbl", false, {}, SvImageId::NONE },
127 { "sch", false, {}, SvImageId::NONE },
128 { "sda", false, { nullptr, STR_DESCRIPTION_SDRAW_DOC}, SvImageId::Draw },
129 { "sdb", false, STR_DESCRIPTION_SDATABASE_DOC, SvImageId::Database },
130 { "sdc", false, { nullptr, STR_DESCRIPTION_SCALC_DOC}, SvImageId::Calc },
131 { "sdd", false, { nullptr, STR_DESCRIPTION_SIMPRESS_DOC}, SvImageId::Impress },
132 { "sdp", false, { nullptr, STR_DESCRIPTION_SIMPRESS_DOC}, SvImageId::NONE },
133 { "sds", false, { nullptr, STR_DESCRIPTION_SCHART_DOC}, SvImageId::NONE },
134 { "sdw", false, { nullptr, STR_DESCRIPTION_SWRITER_DOC}, SvImageId::Writer },
135 { "sga", false, {}, SvImageId::NONE },
136 { "sgl", false, STR_DESCRIPTION_GLOBALDOC, SvImageId::GlobalDoc },
137 { "shtml", false, STR_DESCRIPTION_HTMLFILE, SvImageId::HTML },
138 { "sim", false, STR_DESCRIPTION_SIMAGE_DOC, SvImageId::SIM },
139 { "smf", false, { nullptr, STR_DESCRIPTION_SMATH_DOC}, SvImageId::Math },
140 { "src", true, STR_DESCRIPTION_SOURCEFILE, SvImageId::NONE },
141 { "svh", false, STR_DESCRIPTION_HELP_DOC, SvImageId::NONE },
142 { "svm", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::SVM },
143 { "stc", false, STR_DESCRIPTION_CALC_TEMPLATE, SvImageId::CalcTemplate },
144 { "std", false, STR_DESCRIPTION_DRAW_TEMPLATE, SvImageId::DrawTemplate },
145 { "sti", false, STR_DESCRIPTION_IMPRESS_TEMPLATE, SvImageId::ImpressTemplate },
146 { "stw", false, STR_DESCRIPTION_WRITER_TEMPLATE, SvImageId::WriterTemplate },
147 { "sxc", false, STR_DESCRIPTION_SXCALC_DOC, SvImageId::Calc },
148 { "sxd", false, STR_DESCRIPTION_SXDRAW_DOC, SvImageId::Draw },
149 { "sxg", false, STR_DESCRIPTION_SXGLOBAL_DOC, SvImageId::GlobalDoc },
150 { "sxi", false, STR_DESCRIPTION_SXIMPRESS_DOC, SvImageId::Impress },
151 { "sxm", false, STR_DESCRIPTION_SXMATH_DOC, SvImageId::Math },
152 { "sxs", false, STR_DESCRIPTION_SXCHART_DOC, SvImageId::NONE },
153 { "sxw", false, STR_DESCRIPTION_SXWRITER_DOC, SvImageId::Writer },
154 { "sys", true, STR_DESCRIPTION_SYSFILE, SvImageId::NONE },
155 { "tif", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::TIFF },
156 { "tiff", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::TIFF },
157 { "txt", false, STR_DESCRIPTION_TEXTFILE, SvImageId::TextFile },
158 { "url", false, STR_DESCRIPTION_LINK, SvImageId::NONE },
159 { "vor", false, STR_DESCRIPTION_SOFFICE_TEMPLATE_DOC, SvImageId::WriterTemplate },
160 { "vxd", true, STR_DESCRIPTION_SYSFILE, SvImageId::NONE },
161 { "webp", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::WEBP },
162 { "wmf", true, STR_DESCRIPTION_GRAPHIC_DOC, SvImageId::WMF },
163 { "xls", false, STR_DESCRIPTION_EXCEL_DOC, SvImageId::Calc },
164 { "xlt", false, STR_DESCRIPTION_EXCEL_TEMPLATE_DOC, SvImageId::CalcTemplate },
165 { "xlsx", false, STR_DESCRIPTION_EXCEL_DOC, SvImageId::Calc },
166 { "uu", true, STR_DESCRIPTION_ARCHIVFILE, SvImageId::NONE },
167 { "uue", true, STR_DESCRIPTION_ARCHIVFILE, SvImageId::NONE },
168 { "z", true, STR_DESCRIPTION_ARCHIVFILE, SvImageId::NONE },
169 { "zip", true, STR_DESCRIPTION_ARCHIVFILE, SvImageId::NONE },
170 { "zoo", true, STR_DESCRIPTION_ARCHIVFILE, SvImageId::NONE },
171 { "gz", true, STR_DESCRIPTION_ARCHIVFILE, SvImageId::NONE },
172 { "ppt", false, STR_DESCRIPTION_POWERPOINT, SvImageId::Impress },
173 { "pot", false, STR_DESCRIPTION_POWERPOINT_TEMPLATE, SvImageId::ImpressTemplate },
174 { "pps", false, STR_DESCRIPTION_POWERPOINT_SHOW, SvImageId::Impress },
175 { "pptx", false, STR_DESCRIPTION_POWERPOINT, SvImageId::Impress },
176 { "oxt", false, STR_DESCRIPTION_EXTENSION, SvImageId::Extension },
177 { nullptr, false, {}, SvImageId::NONE }
180 namespace {
182 struct SvtFactory2ExtensionMapping_Impl
184 const char* _pFactory;
185 const char* _pExtension;
190 // mapping from "private:factory" url to extension
192 SvtFactory2ExtensionMapping_Impl const Fac2ExtMap_Impl[] =
194 { "swriter", "odt" },
195 { "swriter/web", "html" },
196 { "swriter/GlobalDocument", "odm" },
197 { "scalc", "ods" },
198 { "simpress", "odp" },
199 { "sdraw", "odg" },
200 { "smath", "odf" },
201 { "sdatabase", "odb" },
202 { nullptr, nullptr }
206 static OUString GetImageExtensionByFactory_Impl( const OUString& rURL )
208 INetURLObject aObj( rURL );
209 OUString aPath = aObj.GetURLPath( INetURLObject::DecodeMechanism::NONE );
210 OUString aExtension;
212 if ( !aPath.isEmpty() )
214 sal_uInt16 nIndex = 0;
215 while ( Fac2ExtMap_Impl[ nIndex ]._pFactory )
217 if ( aPath.equalsAscii( Fac2ExtMap_Impl[ nIndex ]._pFactory ) )
219 // extension found
220 aExtension = OUString::createFromAscii(Fac2ExtMap_Impl[ nIndex ]._pExtension);
221 // and return it
222 return aExtension;
224 ++nIndex;
228 // no extension found, so use the type detection (performance brake)
232 // get the TypeDetection service to access all registered types
233 const css::uno::Reference < css::uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext();
234 css::uno::Reference < css::document::XTypeDetection > xTypeDetector(
235 xContext->getServiceManager()->createInstanceWithContext(u"com.sun.star.document.TypeDetection"_ustr, xContext),
236 css::uno::UNO_QUERY );
238 OUString aInternalType = xTypeDetector->queryTypeByURL( rURL );
239 css::uno::Reference < css::container::XNameAccess > xAccess( xTypeDetector, css::uno::UNO_QUERY );
240 css::uno::Sequence < css::beans::PropertyValue > aTypeProps;
241 if ( !aInternalType.isEmpty() && xAccess->hasByName( aInternalType ) )
243 xAccess->getByName( aInternalType ) >>= aTypeProps;
244 for (const css::beans::PropertyValue& rProp : aTypeProps)
246 if (rProp.Name == "Extensions")
248 css::uno::Sequence < OUString > aExtensions;
249 if ( ( rProp.Value >>= aExtensions ) && aExtensions.hasElements() )
251 const OUString* pExtensions = aExtensions.getConstArray();
252 aExtension = pExtensions[0];
253 break;
259 catch( const css::uno::RuntimeException& )
261 throw; // don't hide it!
263 catch( const css::uno::Exception& )
265 // type detection failed -> no extension
268 return aExtension;
271 static sal_Int32 GetIndexOfExtension_Impl( const OUString& rExtension )
273 sal_Int32 nRet = NO_INDEX;
274 if ( !rExtension.isEmpty() )
276 sal_Int32 nIndex = 0;
277 OUString aExt = rExtension.toAsciiLowerCase();
278 while ( ExtensionMap_Impl[ nIndex ]._pExt )
280 if ( aExt.equalsAscii( ExtensionMap_Impl[ nIndex ]._pExt ) )
282 nRet = nIndex;
283 break;
285 ++nIndex;
289 return nRet;
292 static SvImageId GetImageId_Impl( const OUString& rExtension )
294 SvImageId nImage = SvImageId::File;
295 sal_Int32 nIndex = GetIndexOfExtension_Impl( rExtension );
296 if ( nIndex != NO_INDEX )
298 nImage = ExtensionMap_Impl[ nIndex ]._nImgId;
299 if ( nImage == SvImageId::NONE )
300 nImage = SvImageId::File;
303 return nImage;
306 static bool GetVolumeProperties_Impl( ::ucbhelper::Content& rContent, svtools::VolumeInfo& rVolumeInfo )
308 bool bRet = false;
312 bRet = ( ( rContent.getPropertyValue( u"IsVolume"_ustr ) >>= rVolumeInfo.m_bIsVolume ) &&
313 ( rContent.getPropertyValue( u"IsRemote"_ustr ) >>= rVolumeInfo.m_bIsRemote ) &&
314 ( rContent.getPropertyValue( u"IsRemoveable"_ustr ) >>= rVolumeInfo.m_bIsRemoveable ) &&
315 ( rContent.getPropertyValue( u"IsFloppy"_ustr ) >>= rVolumeInfo.m_bIsFloppy ) &&
316 ( rContent.getPropertyValue( u"IsCompactDisc"_ustr ) >>= rVolumeInfo.m_bIsCompactDisc ) );
318 catch( const css::uno::RuntimeException& )
320 throw; // don't hide it!
322 catch( const css::uno::Exception& )
324 // type detection failed -> no extension
327 return bRet;
330 static SvImageId GetFolderImageId_Impl( const OUString& rURL )
332 SvImageId nRet = SvImageId::Folder;
335 ::svtools::VolumeInfo aVolumeInfo;
336 ::ucbhelper::Content aCnt( rURL, css::uno::Reference< css::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
337 if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
339 if ( aVolumeInfo.m_bIsRemote )
340 nRet = SvImageId::NetworkDevice;
341 else if ( aVolumeInfo.m_bIsCompactDisc )
342 nRet = SvImageId::CDRomDevice;
343 else if ( aVolumeInfo.m_bIsRemoveable )
344 nRet = SvImageId::RemoveableDevice;
345 else if ( aVolumeInfo.m_bIsVolume )
346 nRet = SvImageId::FixedDevice;
349 catch( const css::uno::RuntimeException& )
351 throw; // don't hide it!
353 catch( const css::uno::Exception& )
357 return nRet;
360 static bool isFolder(
361 OUString const & url, css::uno::Reference<css::ucb::XCommandEnvironment> const & env)
363 try {
364 return ucbhelper::Content(url, env, comphelper::getProcessComponentContext()).isFolder();
365 } catch (css::uno::RuntimeException &) {
366 throw;
367 } catch (css::ucb::CommandAbortedException &) {
368 assert(false); // this cannot happen
369 throw;
370 } catch (css::uno::Exception &) {
371 TOOLS_INFO_EXCEPTION("svtools.misc", "isFolder(" << url << ")");
372 return false;
376 static SvImageId GetImageId_Impl(
377 const INetURLObject& rObject, bool bDetectFolder,
378 css::uno::Reference<css::ucb::XCommandEnvironment> const & env )
380 OUString aExt, sURL = rObject.GetMainURL( INetURLObject::DecodeMechanism::NONE );
381 SvImageId nImage = SvImageId::File;
383 if ( rObject.GetProtocol() == INetProtocol::PrivSoffice )
385 std::u16string_view aURLPath = sURL.subView( strlen(URL_PREFIX_PRIV_SOFFICE) );
386 std::u16string_view aType = o3tl::getToken(aURLPath, 0, '/' );
387 if ( aType == u"factory" )
389 // detect an image id for our "private:factory" urls
390 aExt = GetImageExtensionByFactory_Impl( sURL );
391 if ( !aExt.isEmpty() )
392 nImage = GetImageId_Impl( aExt );
393 return nImage;
395 else if ( aType == u"image" )
396 nImage = static_cast<SvImageId>(o3tl::toInt32(o3tl::getToken(aURLPath, 1, '/' )));
398 else
400 aExt = rObject.getExtension();
401 if ( aExt == "vor" )
403 SvImageId nId = SvImageId::WriterTemplate;
406 rtl::Reference<SotStorage> aStorage = new SotStorage(sURL, StreamMode::STD_READ);
407 if ( !aStorage->GetError() )
409 SvGlobalName aGlobalName = aStorage->GetClassName();
410 if ( aGlobalName == SvGlobalName(SO3_SC_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_30) )
411 nId = SvImageId::CalcTemplate;
412 else if ( aGlobalName == SvGlobalName(SO3_SDRAW_CLASSID_50) )
413 nId = SvImageId::DrawTemplate;
414 else if ( aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_50) ||
415 aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_30) )
416 nId = SvImageId::ImpressTemplate;
417 else if ( aGlobalName == SvGlobalName(SO3_SM_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_30) )
418 nId = SvImageId::MathTemplate;
421 catch (const css::ucb::ContentCreationException&)
423 TOOLS_WARN_EXCEPTION("svtools.misc", "GetImageId_Impl");
426 return nId;
430 if ( nImage == SvImageId::File && !sURL.isEmpty() )
432 if ( bDetectFolder && isFolder( sURL, env ) )
433 nImage = GetFolderImageId_Impl( sURL );
434 else if ( !aExt.isEmpty() )
435 nImage = GetImageId_Impl( aExt );
437 return nImage;
440 static TranslateId GetDescriptionId_Impl( const OUString& rExtension, bool& rbShowExt )
442 TranslateId pId;
443 sal_Int32 nIndex = GetIndexOfExtension_Impl( rExtension );
444 if ( nIndex != NO_INDEX )
446 pId = ExtensionMap_Impl[ nIndex ].pStrId;
447 rbShowExt = ExtensionMap_Impl[ nIndex ]._bExt;
450 return pId;
453 static OUString GetDescriptionByFactory_Impl( const OUString& rFactory )
455 TranslateId pResId;
456 if ( rFactory.startsWithIgnoreAsciiCase( "swriter" ) )
457 pResId = STR_DESCRIPTION_FACTORY_WRITER;
458 else if ( rFactory.startsWithIgnoreAsciiCase( "scalc" ) )
459 pResId = STR_DESCRIPTION_FACTORY_CALC;
460 else if ( rFactory.startsWithIgnoreAsciiCase( "simpress" ) )
461 pResId = STR_DESCRIPTION_FACTORY_IMPRESS;
462 else if ( rFactory.startsWithIgnoreAsciiCase( "sdraw" ) )
463 pResId = STR_DESCRIPTION_FACTORY_DRAW;
464 else if ( rFactory.startsWithIgnoreAsciiCase( "swriter/web" ) )
465 pResId = STR_DESCRIPTION_FACTORY_WRITERWEB;
466 else if ( rFactory.startsWithIgnoreAsciiCase( "swriter/globaldocument" ) )
467 pResId = STR_DESCRIPTION_FACTORY_GLOBALDOC;
468 else if ( rFactory.startsWithIgnoreAsciiCase( "smath" ) )
469 pResId = STR_DESCRIPTION_FACTORY_MATH;
470 else if ( rFactory.startsWithIgnoreAsciiCase( "sdatabase" ) )
471 pResId = STR_DESCRIPTION_FACTORY_DATABASE;
473 if (pResId)
475 return SvtResId(pResId);
477 return OUString();
480 static TranslateId GetFolderDescriptionId_Impl( const OUString& rURL )
482 TranslateId pRet = STR_DESCRIPTION_FOLDER;
485 ::ucbhelper::Content aCnt( rURL, css::uno::Reference< css::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
486 svtools::VolumeInfo aVolumeInfo;
487 if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
489 if ( aVolumeInfo.m_bIsRemote )
490 pRet = STR_DESCRIPTION_REMOTE_VOLUME;
491 else if ( aVolumeInfo.m_bIsFloppy )
492 pRet = STR_DESCRIPTION_FLOPPY_VOLUME;
493 else if ( aVolumeInfo.m_bIsCompactDisc )
494 pRet = STR_DESCRIPTION_CDROM_VOLUME;
495 else if ( aVolumeInfo.m_bIsRemoveable || aVolumeInfo.m_bIsVolume )
496 pRet = STR_DESCRIPTION_LOCALE_VOLUME;
499 catch( const css::uno::RuntimeException& )
501 throw; // don't hide it!
503 catch( const css::uno::Exception& )
507 return pRet;
510 static const OUString & GetImageNameFromList_Impl( SvImageId nImageId, vcl::ImageType eImageType )
512 if (eImageType == vcl::ImageType::Size32)
514 switch (nImageId)
516 case SvImageId::HTML:
517 return BMP_HTML_32;
518 case SvImageId::OO_DatabaseDoc:
519 return BMP_OO_DATABASE_DOC_32;
520 case SvImageId::OO_DrawDoc:
521 return BMP_OO_DRAW_DOC_32;
522 case SvImageId::OO_MathDoc:
523 return BMP_OO_MATH_DOC_32;
524 case SvImageId::OO_GlobalDoc:
525 return BMP_OO_GLOBAL_DOC_32;
526 case SvImageId::OO_ImpressDoc:
527 return BMP_OO_IMPRESS_DOC_32;
528 case SvImageId::OO_CalcDoc:
529 return BMP_OO_CALC_DOC_32;
530 case SvImageId::OO_WriterDoc:
531 return BMP_OO_WRITER_DOC_32;
532 case SvImageId::OO_WriterTemplate:
533 return BMP_OO_WRITER_TEMPLATE_32;
534 default: break;
537 else if (eImageType == vcl::ImageType::Size26)
539 switch (nImageId)
541 case SvImageId::Impress:
542 return BMP_IMPRESS_LC;
543 case SvImageId::Bitmap:
544 return BMP_BITMAP_LC;
545 case SvImageId::Calc:
546 return BMP_CALC_LC;
547 case SvImageId::CalcTemplate:
548 return BMP_CALCTEMPLATE_LC;
549 case SvImageId::Database:
550 return BMP_DATABASE_LC;
551 case SvImageId::ImpressTemplate:
552 return BMP_IMPRESSTEMPLATE_LC;
553 case SvImageId::GIF:
554 return BMP_GIF_LC;
555 case SvImageId::HTML:
556 return BMP_HTML_LC;
557 case SvImageId::JPG:
558 return BMP_JPG_LC;
559 case SvImageId::Math:
560 return BMP_MATH_LC;
561 case SvImageId::MathTemplate:
562 return BMP_MATHTEMPLATE_LC;
563 case SvImageId::File:
564 return BMP_FILE_LC;
565 case SvImageId::PCD:
566 return BMP_PCD_LC;
567 case SvImageId::PCT:
568 return BMP_PCT_LC;
569 case SvImageId::PCX:
570 return BMP_PCX_LC;
571 case SvImageId::SIM:
572 return BMP_SIM_LC;
573 case SvImageId::TextFile:
574 return BMP_TEXTFILE_LC;
575 case SvImageId::TIFF:
576 return BMP_TIFF_LC;
577 case SvImageId::WEBP:
578 return BMP_WEBP_LC;
579 case SvImageId::WMF:
580 return BMP_WMF_LC;
581 case SvImageId::Writer:
582 return BMP_WRITER_LC;
583 case SvImageId::WriterTemplate:
584 return BMP_WRITERTEMPLATE_LC;
585 case SvImageId::FixedDevice:
586 return BMP_FIXEDDEV_LC;
587 case SvImageId::RemoveableDevice:
588 return BMP_REMOVABLEDEV_LC;
589 case SvImageId::CDRomDevice:
590 return BMP_CDROMDEV_LC;
591 case SvImageId::NetworkDevice:
592 return BMP_NETWORKDEV_LC;
593 case SvImageId::Table:
594 return BMP_TABLE_LC;
595 case SvImageId::Folder:
596 return BMP_FOLDER_LC;
597 case SvImageId::DXF:
598 return BMP_DXF_LC;
599 case SvImageId::MET:
600 return BMP_MET_LC;
601 case SvImageId::PNG:
602 return BMP_PNG_LC;
603 case SvImageId::SVM:
604 return BMP_SVM_LC;
605 case SvImageId::GlobalDoc:
606 return BMP_GLOBAL_DOC_LC;
607 case SvImageId::Draw:
608 return BMP_DRAW_LC;
609 case SvImageId::DrawTemplate:
610 return BMP_DRAWTEMPLATE_LC;
611 case SvImageId::OO_DatabaseDoc:
612 return BMP_OO_DATABASE_DOC_LC;
613 case SvImageId::OO_DrawDoc:
614 return BMP_OO_DRAW_DOC_LC;
615 case SvImageId::OO_MathDoc:
616 return BMP_OO_MATH_DOC_LC;
617 case SvImageId::OO_GlobalDoc:
618 return BMP_OO_GLOBAL_DOC_LC;
619 case SvImageId::OO_ImpressDoc:
620 return BMP_OO_IMPRESS_DOC_LC;
621 case SvImageId::OO_CalcDoc:
622 return BMP_OO_CALC_DOC_LC;
623 case SvImageId::OO_WriterDoc:
624 return BMP_OO_WRITER_DOC_LC;
625 case SvImageId::OO_DrawTemplate:
626 return BMP_OO_DRAW_TEMPLATE_LC;
627 case SvImageId::OO_ImpressTemplate:
628 return BMP_OO_IMPRESS_TEMPLATE_LC;
629 case SvImageId::OO_CalcTemplate:
630 return BMP_OO_CALC_TEMPLATE_LC;
631 case SvImageId::OO_WriterTemplate:
632 return BMP_OO_WRITER_TEMPLATE_LC;
633 case SvImageId::Extension:
634 return BMP_EXTENSION_LC;
635 default: break;
638 else
640 switch (nImageId)
642 case SvImageId::Impress:
643 return BMP_IMPRESS_SC;
644 case SvImageId::Bitmap:
645 return BMP_BITMAP_SC;
646 case SvImageId::Calc:
647 return BMP_CALC_SC;
648 case SvImageId::CalcTemplate:
649 return BMP_CALCTEMPLATE_SC;
650 case SvImageId::Database:
651 return BMP_DATABASE_SC;
652 case SvImageId::ImpressTemplate:
653 return BMP_IMPRESSTEMPLATE_SC;
654 case SvImageId::GIF:
655 return BMP_GIF_SC;
656 case SvImageId::HTML:
657 return BMP_HTML_SC;
658 case SvImageId::JPG:
659 return BMP_JPG_SC;
660 case SvImageId::Math:
661 return BMP_MATH_SC;
662 case SvImageId::MathTemplate:
663 return BMP_MATHTEMPLATE_SC;
664 case SvImageId::File:
665 return BMP_FILE_SC;
666 case SvImageId::PCD:
667 return BMP_PCD_SC;
668 case SvImageId::PCT:
669 return BMP_PCT_SC;
670 case SvImageId::PCX:
671 return BMP_PCX_SC;
672 case SvImageId::SIM:
673 return BMP_SIM_SC;
674 case SvImageId::TextFile:
675 return BMP_TEXTFILE_SC;
676 case SvImageId::TIFF:
677 return BMP_TIFF_SC;
678 case SvImageId::WEBP:
679 return BMP_WEBP_SC;
680 case SvImageId::WMF:
681 return BMP_WMF_SC;
682 case SvImageId::Writer:
683 return BMP_WRITER_SC;
684 case SvImageId::WriterTemplate:
685 return BMP_WRITERTEMPLATE_SC;
686 case SvImageId::FixedDevice:
687 return BMP_FIXEDDEV_SC;
688 case SvImageId::RemoveableDevice:
689 return BMP_REMOVABLEDEV_SC;
690 case SvImageId::CDRomDevice:
691 return BMP_CDROMDEV_SC;
692 case SvImageId::NetworkDevice:
693 return BMP_NETWORKDEV_SC;
694 case SvImageId::Table:
695 return BMP_TABLE_SC;
696 case SvImageId::Folder:
697 return RID_BMP_FOLDER;
698 case SvImageId::DXF:
699 return BMP_DXF_SC;
700 case SvImageId::MET:
701 return BMP_MET_SC;
702 case SvImageId::PNG:
703 return BMP_PNG_SC;
704 case SvImageId::SVM:
705 return BMP_SVM_SC;
706 case SvImageId::GlobalDoc:
707 return BMP_GLOBAL_DOC_SC;
708 case SvImageId::Draw:
709 return BMP_DRAW_SC;
710 case SvImageId::DrawTemplate:
711 return BMP_DRAWTEMPLATE_SC;
712 case SvImageId::OO_DatabaseDoc:
713 return BMP_OO_DATABASE_DOC_SC;
714 case SvImageId::OO_DrawDoc:
715 return BMP_OO_DRAW_DOC_SC;
716 case SvImageId::OO_MathDoc:
717 return BMP_OO_MATH_DOC_SC;
718 case SvImageId::OO_GlobalDoc:
719 return BMP_OO_GLOBAL_DOC_SC;
720 case SvImageId::OO_ImpressDoc:
721 return BMP_OO_IMPRESS_DOC_SC;
722 case SvImageId::OO_CalcDoc:
723 return BMP_OO_CALC_DOC_SC;
724 case SvImageId::OO_WriterDoc:
725 return BMP_OO_WRITER_DOC_SC;
726 case SvImageId::OO_DrawTemplate:
727 return BMP_OO_DRAW_TEMPLATE_SC;
728 case SvImageId::OO_ImpressTemplate:
729 return BMP_OO_IMPRESS_TEMPLATE_SC;
730 case SvImageId::OO_CalcTemplate:
731 return BMP_OO_CALC_TEMPLATE_SC;
732 case SvImageId::OO_WriterTemplate:
733 return BMP_OO_WRITER_TEMPLATE_SC;
734 case SvImageId::Extension:
735 return BMP_EXTENSION_SC;
736 default: break;
740 return EMPTY_OUSTRING;
743 static Image GetImageFromList_Impl( SvImageId nImageId, vcl::ImageType eImageType)
745 OUString sImageName(GetImageNameFromList_Impl(nImageId, eImageType));
746 if (!sImageName.isEmpty())
747 return Image(StockImage::Yes, sImageName);
748 return Image();
751 OUString SvFileInformationManager::GetDescription_Impl( const INetURLObject& rObject, bool bDetectFolder )
753 OUString sExtension(rObject.getExtension());
754 OUString sDescription, sURL( rObject.GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
755 TranslateId pResId;
756 bool bShowExt = false, bOnlyFile = false;
757 bool bFolder = bDetectFolder && CONTENT_HELPER::IsFolder( sURL );
758 if ( !bFolder )
760 bool bDetected = false;
762 if ( rObject.GetProtocol() == INetProtocol::PrivSoffice )
764 OUString aURLPath = sURL.copy( strlen(URL_PREFIX_PRIV_SOFFICE) );
765 std::u16string_view aType = o3tl::getToken(aURLPath, 0, '/' );
766 if ( aType == u"factory" )
768 sDescription = GetDescriptionByFactory_Impl( aURLPath.copy( aURLPath.indexOf( '/' ) + 1 ) );
769 bDetected = true;
773 if (!bDetected)
775 // search a description by extension
776 bool bExt = !sExtension.isEmpty();
777 if ( bExt )
779 sExtension = sExtension.toAsciiLowerCase();
780 pResId = GetDescriptionId_Impl( sExtension, bShowExt );
782 if (!pResId)
784 pResId = STR_DESCRIPTION_FILE;
785 bOnlyFile = bExt;
789 else
790 pResId = GetFolderDescriptionId_Impl( sURL );
792 if (pResId)
794 if ( bOnlyFile )
796 bShowExt = false;
797 sExtension = sExtension.toAsciiUpperCase();
798 sDescription = sExtension + "-";
800 sDescription += SvtResId(pResId);
803 DBG_ASSERT( !sDescription.isEmpty(), "file without description" );
805 if ( bShowExt )
807 sDescription += " (" + sExtension + ")";
810 return sDescription;
813 const OUString & SvFileInformationManager::GetImageId(const INetURLObject& rObject, bool bBig)
815 SvImageId nImage = GetImageId_Impl(
816 rObject, true, utl::UCBContentHelper::getDefaultCommandEnvironment() );
817 DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" );
818 return GetImageNameFromList_Impl(nImage, bBig ? vcl::ImageType::Size26 : vcl::ImageType::Size16);
821 Image SvFileInformationManager::GetImage(
822 const INetURLObject& rObject, bool bBig,
823 css::uno::Reference<css::ucb::XCommandEnvironment> const & env)
825 SvImageId nImage = GetImageId_Impl( rObject, true, env );
826 DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" );
827 return GetImageFromList_Impl(nImage, bBig ? vcl::ImageType::Size26 : vcl::ImageType::Size16);
830 const OUString & SvFileInformationManager::GetFileImageId(const INetURLObject& rObject)
832 SvImageId nImage = GetImageId_Impl(
833 rObject, false, utl::UCBContentHelper::getDefaultCommandEnvironment() );
834 DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" );
835 return GetImageNameFromList_Impl(nImage, vcl::ImageType::Size16);
838 Image SvFileInformationManager::GetImageNoDefault(const INetURLObject& rObject, vcl::ImageType eImageType)
840 SvImageId nImage = GetImageId_Impl(
841 rObject, true, utl::UCBContentHelper::getDefaultCommandEnvironment());
842 DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" );
844 if ( nImage == SvImageId::File )
845 return Image();
847 return GetImageFromList_Impl(nImage, eImageType);
850 const OUString & SvFileInformationManager::GetFolderImageId( const svtools::VolumeInfo& rInfo )
852 SvImageId nImage = SvImageId::Folder;
853 DBG_ASSERT( nImage != SvImageId::NONE, "invalid ImageId" );
855 if ( rInfo.m_bIsRemote )
856 nImage = SvImageId::NetworkDevice;
857 else if ( rInfo.m_bIsCompactDisc )
858 nImage = SvImageId::CDRomDevice;
859 else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsFloppy )
860 nImage = SvImageId::RemoveableDevice;
861 else if ( rInfo.m_bIsVolume )
862 nImage = SvImageId::FixedDevice;
864 return GetImageNameFromList_Impl(nImage, vcl::ImageType::Size16);
867 OUString SvFileInformationManager::GetDescription( const INetURLObject& rObject )
869 return SvFileInformationManager::GetDescription_Impl( rObject, true );
872 OUString SvFileInformationManager::GetFileDescription( const INetURLObject& rObject )
874 return SvFileInformationManager::GetDescription_Impl( rObject, false );
877 OUString SvFileInformationManager::GetFolderDescription( const svtools::VolumeInfo& rInfo )
879 TranslateId pResId = STR_DESCRIPTION_FOLDER;
880 if ( rInfo.m_bIsRemote )
881 pResId = STR_DESCRIPTION_REMOTE_VOLUME;
882 else if ( rInfo.m_bIsFloppy )
883 pResId = STR_DESCRIPTION_FLOPPY_VOLUME;
884 else if ( rInfo.m_bIsCompactDisc )
885 pResId = STR_DESCRIPTION_CDROM_VOLUME;
886 else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsVolume )
887 pResId = STR_DESCRIPTION_LOCALE_VOLUME;
889 return SvtResId(pResId);
892 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */