1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svtools.hxx" 30 31 // includes -------------------------------------------------------------- 32 33 #include <svtools/imagemgr.hxx> 34 #include <tools/urlobj.hxx> 35 #include <tools/debug.hxx> 36 #include <vcl/svapp.hxx> 37 #include <vcl/wrkwin.hxx> 38 #include "vcl/image.hxx" 39 #include <sot/storage.hxx> 40 #include <sot/clsids.hxx> 41 #include <unotools/ucbhelper.hxx> 42 #include <comphelper/processfactory.hxx> 43 #include <com/sun/star/beans/PropertyValue.hpp> 44 #include <com/sun/star/container/XNameContainer.hpp> 45 #include <com/sun/star/document/XTypeDetection.hpp> 46 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 47 #include <com/sun/star/ucb/XCommandEnvironment.hpp> 48 #include <ucbhelper/content.hxx> 49 #include <tools/rcid.h> 50 #include <rtl/logfile.hxx> 51 #include <unotools/configmgr.hxx> 52 #include <svtools/svtools.hrc> 53 #include <svtools/imagemgr.hrc> 54 #include <svtools/svtdata.hxx> 55 #include <vos/mutex.hxx> 56 57 // globals ******************************************************************* 58 59 #define NO_INDEX ((sal_uInt16)0xFFFF) 60 #define CONTENT_HELPER ::utl::UCBContentHelper 61 #define ASCII_STRING(s) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) ) 62 63 struct SvtExtensionResIdMapping_Impl 64 { 65 const char* _pExt; 66 sal_Bool _bExt; 67 sal_uInt16 _nStrId; 68 sal_uInt16 _nImgId; 69 }; 70 71 static SvtExtensionResIdMapping_Impl __READONLY_DATA ExtensionMap_Impl[] = 72 { 73 { "awk", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 74 { "bas", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 75 { "bat", sal_True, STR_DESCRIPTION_BATCHFILE, 0 }, 76 { "bmk", sal_False, STR_DESCRIPTION_BOOKMARKFILE, 0 }, 77 { "bmp", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_BITMAP }, 78 { "c", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 79 { "cfg", sal_False, STR_DESCRIPTION_CFGFILE, 0 }, 80 { "cmd", sal_True, STR_DESCRIPTION_BATCHFILE, 0 }, 81 { "cob", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 82 { "com", sal_True, STR_DESCRIPTION_APPLICATION, 0 }, 83 { "cxx", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 84 { "dbf", sal_True, STR_DESCRIPTION_DATABASE_TABLE, IMG_TABLE }, 85 { "def", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 86 { "dll", sal_True, STR_DESCRIPTION_SYSFILE, 0 }, 87 { "doc", sal_False, STR_DESCRIPTION_WORD_DOC, IMG_WRITER }, 88 { "dot", sal_False, STR_DESCRIPTION_WORD_DOC, IMG_WRITERTEMPLATE }, 89 { "docx", sal_False, STR_DESCRIPTION_WORD_DOC, IMG_WRITER }, 90 { "dxf", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_DXF }, 91 { "exe", sal_True, STR_DESCRIPTION_APPLICATION, 0 }, 92 { "gif", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_GIF }, 93 { "h", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 94 { "hlp", sal_False, STR_DESCRIPTION_HELP_DOC, 0 }, 95 { "hrc", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 96 { "htm", sal_False, STR_DESCRIPTION_HTMLFILE, IMG_HTML }, 97 { "html", sal_False, STR_DESCRIPTION_HTMLFILE, IMG_HTML }, 98 { "asp", sal_False, STR_DESCRIPTION_HTMLFILE, IMG_HTML }, 99 { "hxx", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 100 { "ini", sal_False, STR_DESCRIPTION_CFGFILE, 0 }, 101 { "java", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 102 { "jpeg", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_JPG }, 103 { "jpg", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_JPG }, 104 { "lha", sal_True, STR_DESCRIPTION_ARCHIVFILE, 0 }, 105 #ifdef WNT 106 { "lnk", sal_False, 0, 0 }, 107 #endif 108 { "log", sal_True, STR_DESCRIPTION_LOGFILE, 0 }, 109 { "lst", sal_True, STR_DESCRIPTION_LOGFILE, 0 }, 110 { "met", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_MET }, 111 { "mml", sal_False, STR_DESCRIPTION_MATHML_DOC, IMG_MATH }, 112 { "mod", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 113 { "odb", sal_False, STR_DESCRIPTION_OO_DATABASE_DOC, IMG_OO_DATABASE_DOC }, 114 { "odg", sal_False, STR_DESCRIPTION_OO_DRAW_DOC, IMG_OO_DRAW_DOC }, 115 { "odf", sal_False, STR_DESCRIPTION_OO_MATH_DOC, IMG_OO_MATH_DOC }, 116 { "odm", sal_False, STR_DESCRIPTION_OO_GLOBAL_DOC, IMG_OO_GLOBAL_DOC }, 117 { "odp", sal_False, STR_DESCRIPTION_OO_IMPRESS_DOC, IMG_OO_IMPRESS_DOC }, 118 { "ods", sal_False, STR_DESCRIPTION_OO_CALC_DOC, IMG_OO_CALC_DOC }, 119 { "odt", sal_False, STR_DESCRIPTION_OO_WRITER_DOC, IMG_OO_WRITER_DOC }, 120 { "otg", sal_False, STR_DESCRIPTION_OO_DRAW_TEMPLATE, IMG_OO_DRAW_TEMPLATE }, 121 { "otp", sal_False, STR_DESCRIPTION_OO_IMPRESS_TEMPLATE, IMG_OO_IMPRESS_TEMPLATE }, 122 { "ots", sal_False, STR_DESCRIPTION_OO_CALC_TEMPLATE, IMG_OO_CALC_TEMPLATE }, 123 { "ott", sal_False, STR_DESCRIPTION_OO_WRITER_TEMPLATE, IMG_OO_WRITER_TEMPLATE }, 124 { "pas", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 125 { "pcd", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCD }, 126 { "pct", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCT }, 127 { "pcx", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCX }, 128 { "pl", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 129 { "png", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_PNG }, 130 { "rar", sal_True, STR_DESCRIPTION_ARCHIVFILE, 0 }, 131 { "rtf", sal_False, STR_DESCRIPTION_WORD_DOC, IMG_WRITER }, 132 { "sbl", sal_False, 0, 0 }, 133 { "sch", sal_False, 0, 0 }, 134 { "sda", sal_False, STR_DESCRIPTION_SDRAW_DOC, IMG_DRAW }, 135 { "sdb", sal_False, STR_DESCRIPTION_SDATABASE_DOC, IMG_DATABASE }, 136 { "sdc", sal_False, STR_DESCRIPTION_SCALC_DOC, IMG_CALC }, 137 { "sdd", sal_False, STR_DESCRIPTION_SIMPRESS_DOC, IMG_IMPRESS }, 138 { "sdp", sal_False, STR_DESCRIPTION_SIMPRESS_DOC, 0 }, 139 { "sds", sal_False, STR_DESCRIPTION_SCHART_DOC, 0 }, 140 { "sdw", sal_False, STR_DESCRIPTION_SWRITER_DOC, IMG_WRITER }, 141 { "sga", sal_False, 0, 0 }, 142 { "sgf", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SGF }, 143 { "sgl", sal_False, STR_DESCRIPTION_GLOBALDOC, IMG_GLOBAL_DOC }, 144 { "sgv", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SGV }, 145 { "shtml", sal_False, STR_DESCRIPTION_HTMLFILE, IMG_HTML }, 146 { "sim", sal_False, STR_DESCRIPTION_SIMAGE_DOC, IMG_SIM }, 147 { "smf", sal_False, STR_DESCRIPTION_SMATH_DOC, IMG_MATH }, 148 { "src", sal_True, STR_DESCRIPTION_SOURCEFILE, 0 }, 149 { "svh", sal_False, STR_DESCRIPTION_HELP_DOC, 0 }, 150 { "svm", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_SVM }, 151 { "stc", sal_False, STR_DESCRIPTION_CALC_TEMPLATE, IMG_CALCTEMPLATE }, 152 { "std", sal_False, STR_DESCRIPTION_DRAW_TEMPLATE, IMG_DRAWTEMPLATE }, 153 { "sti", sal_False, STR_DESCRIPTION_IMPRESS_TEMPLATE, IMG_IMPRESSTEMPLATE }, 154 { "stw", sal_False, STR_DESCRIPTION_WRITER_TEMPLATE, IMG_WRITERTEMPLATE }, 155 { "sxc", sal_False, STR_DESCRIPTION_SXCALC_DOC, IMG_CALC }, 156 { "sxd", sal_False, STR_DESCRIPTION_SXDRAW_DOC, IMG_DRAW }, 157 { "sxg", sal_False, STR_DESCRIPTION_SXGLOBAL_DOC, IMG_GLOBAL_DOC }, 158 { "sxi", sal_False, STR_DESCRIPTION_SXIMPRESS_DOC, IMG_IMPRESS }, 159 { "sxm", sal_False, STR_DESCRIPTION_SXMATH_DOC, IMG_MATH }, 160 { "sxs", sal_False, STR_DESCRIPTION_SXCHART_DOC, 0 }, 161 { "sxw", sal_False, STR_DESCRIPTION_SXWRITER_DOC, IMG_WRITER }, 162 { "sys", sal_True, STR_DESCRIPTION_SYSFILE, 0 }, 163 { "tif", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_TIFF }, 164 { "tiff", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_TIFF }, 165 { "txt", sal_False, STR_DESCRIPTION_TEXTFILE, IMG_TEXTFILE }, 166 { "url", sal_False, STR_DESCRIPTION_LINK, 0 }, 167 { "vor", sal_False, STR_DESCRIPTION_SOFFICE_TEMPLATE_DOC, IMG_WRITERTEMPLATE }, 168 { "vxd", sal_True, STR_DESCRIPTION_SYSFILE, 0 }, 169 { "wmf", sal_True, STR_DESCRIPTION_GRAPHIC_DOC, IMG_WMF }, 170 { "xls", sal_False, STR_DESCRIPTION_EXCEL_DOC, IMG_CALC }, 171 { "xlt", sal_False, STR_DESCRIPTION_EXCEL_TEMPLATE_DOC, IMG_CALCTEMPLATE }, 172 { "xlsx", sal_False, STR_DESCRIPTION_EXCEL_DOC, IMG_CALC }, 173 { "uu", sal_True, STR_DESCRIPTION_ARCHIVFILE, 0 }, 174 { "uue", sal_True, STR_DESCRIPTION_ARCHIVFILE, 0 }, 175 { "z", sal_True, STR_DESCRIPTION_ARCHIVFILE, 0 }, 176 { "zip", sal_True, STR_DESCRIPTION_ARCHIVFILE, 0 }, 177 { "zoo", sal_True, STR_DESCRIPTION_ARCHIVFILE, 0 }, 178 { "gz", sal_True, STR_DESCRIPTION_ARCHIVFILE, 0 }, 179 { "ppt", sal_False, STR_DESCRIPTION_POWERPOINT, IMG_IMPRESS }, 180 { "pot", sal_False, STR_DESCRIPTION_POWERPOINT_TEMPLATE, IMG_IMPRESSTEMPLATE }, 181 { "pps", sal_False, STR_DESCRIPTION_POWERPOINT_SHOW, IMG_IMPRESS }, 182 { "pptx", sal_False, STR_DESCRIPTION_POWERPOINT, IMG_IMPRESS }, 183 { "oxt", sal_False, STR_DESCRIPTION_EXTENSION, IMG_EXTENSION }, 184 { 0, sal_False, 0, 0 } 185 }; 186 187 #ifdef OS2 188 SvtExtensionResIdMapping_Impl Mappings[] = 189 { 190 {"StarWriter 4.0", sal_False,STR_DESCRIPTION_SWRITER_DOC, IMG_WRITER}, 191 {"StarWriter 3.0", sal_False,STR_DESCRIPTION_SWRITER_DOC, IMG_WRITER}, 192 {"StarCalc 4.0", sal_False,STR_DESCRIPTION_SCALC_DOC, IMG_CALC}, 193 {"StarCalc 3.0", sal_False,STR_DESCRIPTION_SCALC_DOC, IMG_CALC}, 194 {"StarImpress 4.0", sal_False,STR_DESCRIPTION_SIMPRESS_DOC,IMG_IMPRESS}, 195 {"StarDraw 4.0", sal_False,STR_DESCRIPTION_SDRAW_DOC, IMG_DRAW}, 196 {"StarDraw 3.0", sal_False,STR_DESCRIPTION_SDRAW_DOC, IMG_DRAW}, 197 {"StarChart 3.0", sal_False,STR_DESCRIPTION_SCHART_DOC, IMG_CHART}, 198 {"StarChart 4.0", sal_False,STR_DESCRIPTION_SCHART_DOC, IMG_CHART}, 199 {"Bitmap", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_BITMAP}, 200 {"AutoCAD", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_SIM}, 201 {"Gif-File", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_GIF}, 202 {"JPEG-File", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_JPG}, 203 {"Metafile ", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_SIM}, 204 {"Photo-CD ", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCD}, 205 {"Mac Pict", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCT}, 206 {"PCX-File ", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_PCX}, 207 {"PNG-File", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_SIM}, 208 {"SV-Metafile", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_SIM}, 209 {"TIFF-File", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_TIFF}, 210 {"MS-Metafile", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_WMF}, 211 {"XBM-File", sal_False,STR_DESCRIPTION_GRAPHIC_DOC, IMG_BITMAP}, 212 {"UniformResourceLocator", sal_False,STR_DESCRIPTION_LINK, IMG_URL}, 213 {NULL, 0} 214 }; 215 #endif 216 217 struct SvtFactory2ExtensionMapping_Impl 218 { 219 const char* _pFactory; 220 const char* _pExtension; 221 }; 222 223 // mapping from "private:factory" url to extension 224 225 static SvtFactory2ExtensionMapping_Impl __READONLY_DATA Fac2ExtMap_Impl[] = 226 { 227 { "swriter", "odt" }, 228 { "swriter/web", "html" }, 229 { "swriter/GlobalDocument", "odm" }, 230 { "scalc", "ods" }, 231 { "simpress", "odp" }, 232 { "sdraw", "odg" }, 233 { "smath", "odf" }, 234 { "sdatabase", "odb" }, 235 { NULL, NULL } 236 }; 237 238 //**************************************************************************** 239 240 static String GetImageExtensionByFactory_Impl( const String& rURL ) 241 { 242 INetURLObject aObj( rURL ); 243 String aPath = aObj.GetURLPath( INetURLObject::NO_DECODE ); 244 String aExtension; 245 246 if ( aPath.Len() ) 247 { 248 sal_uInt16 nIndex = 0; 249 while ( Fac2ExtMap_Impl[ nIndex ]._pFactory ) 250 { 251 if ( aPath.EqualsAscii( Fac2ExtMap_Impl[ nIndex ]._pFactory ) ) 252 { 253 // extension found 254 aExtension = String::CreateFromAscii( Fac2ExtMap_Impl[ nIndex ]._pExtension ); 255 // and return it 256 return aExtension; 257 } 258 ++nIndex; 259 } 260 } 261 262 // no extension found, so use the type detection (performance brake) 263 264 try 265 { 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 ); 270 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 ) ) 275 { 276 xAccess->getByName( aInternalType ) >>= aTypeProps; 277 sal_Int32 nProps = aTypeProps.getLength(); 278 for ( sal_Int32 i = 0; i < nProps; ++i ) 279 { 280 const ::com::sun::star::beans::PropertyValue& rProp = aTypeProps[i]; 281 if ( rProp.Name.compareToAscii("Extensions") == COMPARE_EQUAL ) 282 { 283 ::com::sun::star::uno::Sequence < ::rtl::OUString > aExtensions; 284 if ( ( rProp.Value >>= aExtensions ) && aExtensions.getLength() > 0 ) 285 { 286 const ::rtl::OUString* pExtensions = aExtensions.getConstArray(); 287 aExtension = String( pExtensions[0] ); 288 break; 289 } 290 } 291 } 292 } 293 } 294 catch( const ::com::sun::star::uno::RuntimeException& ) 295 { 296 throw; // dont hide it! 297 } 298 catch( const ::com::sun::star::uno::Exception& ) 299 { 300 // type detection failed -> no extension 301 } 302 303 return aExtension; 304 } 305 306 static sal_uInt16 GetIndexOfExtension_Impl( const String& rExtension ) 307 { 308 sal_uInt16 nRet = NO_INDEX; 309 if ( rExtension.Len() ) 310 { 311 sal_uInt16 nIndex = 0; 312 String aExt = rExtension; 313 aExt.ToLowerAscii(); 314 while ( ExtensionMap_Impl[ nIndex ]._pExt ) 315 { 316 if ( aExt.EqualsAscii( ExtensionMap_Impl[ nIndex ]._pExt ) ) 317 { 318 nRet = nIndex; 319 break; 320 } 321 ++nIndex; 322 } 323 } 324 325 return nRet; 326 } 327 328 static sal_uInt16 GetImageId_Impl( const String& rExtension ) 329 { 330 sal_uInt16 nImage = IMG_FILE; 331 if ( rExtension.Len() != NO_INDEX ) 332 { 333 sal_uInt16 nIndex = GetIndexOfExtension_Impl( rExtension ); 334 if ( nIndex != NO_INDEX ) 335 { 336 nImage = ExtensionMap_Impl[ nIndex ]._nImgId; 337 if ( !nImage ) 338 nImage = IMG_FILE; 339 } 340 } 341 342 return nImage; 343 } 344 345 static sal_Bool GetVolumeProperties_Impl( ::ucbhelper::Content& rContent, svtools::VolumeInfo& rVolumeInfo ) 346 { 347 sal_Bool bRet = sal_False; 348 349 try 350 { 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 ) ); 356 } 357 catch( const ::com::sun::star::uno::RuntimeException& ) 358 { 359 throw; // dont hide it! 360 } 361 catch( const ::com::sun::star::uno::Exception& ) 362 { 363 // type detection failed -> no extension 364 } 365 366 return bRet; 367 } 368 369 static sal_uInt16 GetFolderImageId_Impl( const String& rURL ) 370 { 371 sal_uInt16 nRet = IMG_FOLDER; 372 ::svtools::VolumeInfo aVolumeInfo; 373 try 374 { 375 ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 376 if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) ) 377 { 378 if ( aVolumeInfo.m_bIsRemote ) 379 nRet = IMG_NETWORKDEV; 380 else if ( aVolumeInfo.m_bIsCompactDisc ) 381 nRet = IMG_CDROMDEV; 382 else if ( aVolumeInfo.m_bIsRemoveable ) 383 nRet = IMG_REMOVEABLEDEV; 384 else if ( aVolumeInfo.m_bIsVolume ) 385 nRet = IMG_FIXEDDEV; 386 } 387 } 388 catch( const ::com::sun::star::uno::RuntimeException& ) 389 { 390 throw; // dont hide it! 391 } 392 catch( const ::com::sun::star::uno::Exception& ) 393 { 394 // ... 395 } 396 return nRet; 397 } 398 399 static sal_uInt16 GetImageId_Impl( const INetURLObject& rObject, sal_Bool bDetectFolder ) 400 { 401 RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog, "svtools", "hb93813", "SvFileInformationManager::GetImageId_Impl()" ); 402 403 String aExt, sURL = rObject.GetMainURL( INetURLObject::NO_DECODE ); 404 sal_uInt16 nImage = IMG_FILE; 405 406 if ( rObject.GetProtocol() == INET_PROT_PRIVATE ) 407 { 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") ) ) 411 { 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 ); 416 return nImage; 417 } 418 else if ( aType == String( RTL_CONSTASCII_STRINGPARAM("image") ) ) 419 nImage = (sal_uInt16)aURLPath.GetToken( 1, INET_PATH_TOKEN ).ToInt32(); 420 } 421 else 422 { 423 aExt = rObject.getExtension(); 424 if ( aExt.EqualsAscii( "vor" ) ) 425 { 426 SotStorageRef aStorage = new SotStorage( sURL, STREAM_STD_READ ); 427 sal_uInt16 nId = IMG_WRITERTEMPLATE; 428 if ( !aStorage->GetError() ) 429 { 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; 440 } 441 442 return nId; 443 } 444 } 445 446 if ( nImage == IMG_FILE && sURL.Len() ) 447 { 448 if ( bDetectFolder && CONTENT_HELPER::IsFolder( sURL ) ) 449 nImage = GetFolderImageId_Impl( sURL ); 450 else if ( aExt.Len() > 0 ) 451 nImage = GetImageId_Impl( aExt ); 452 } 453 return nImage; 454 } 455 456 static sal_uInt16 GetDescriptionId_Impl( const String& rExtension, sal_Bool& rbShowExt ) 457 { 458 sal_uInt16 nId = 0; 459 460 if ( rExtension.Len() != NO_INDEX ) 461 { 462 sal_uInt16 nIndex = GetIndexOfExtension_Impl( rExtension ); 463 if ( nIndex != NO_INDEX ) 464 { 465 nId = ExtensionMap_Impl[ nIndex ]._nStrId; 466 rbShowExt = ExtensionMap_Impl[ nIndex ]._bExt; 467 } 468 } 469 470 return nId; 471 } 472 473 static String GetDescriptionByFactory_Impl( const String& rFactory ) 474 { 475 sal_uInt16 nResId = 0; 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; 492 493 String aRet; 494 if ( nResId ) 495 { 496 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 497 aRet = String( SvtResId( nResId ) ); 498 } 499 return aRet; 500 } 501 502 static sal_uInt16 GetFolderDescriptionId_Impl( const String& rURL ) 503 { 504 sal_uInt16 nRet = STR_DESCRIPTION_FOLDER; 505 svtools::VolumeInfo aVolumeInfo; 506 try 507 { 508 ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment > () ); 509 if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) ) 510 { 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; 519 } 520 } 521 catch( const ::com::sun::star::uno::RuntimeException& ) 522 { 523 throw; // dont hide it! 524 } 525 catch( const ::com::sun::star::uno::Exception& ) 526 { 527 // ... 528 } 529 return nRet; 530 } 531 532 /* 533 static ResMgr* GetIsoResMgr_Impl() 534 { 535 static ResMgr* pIsoResMgr = NULL; 536 537 if ( !pIsoResMgr ) 538 { 539 ByteString aResMgrName( "iso" ); 540 pIsoResMgr = ResMgr::CreateResMgr( 541 aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); 542 if ( !pIsoResMgr ) 543 { 544 // no "iso" resource -> search for "ooo" resource 545 aResMgrName = ByteString( "ooo" ); 546 pIsoResMgr = ResMgr::CreateResMgr( 547 aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() ); 548 } 549 } 550 551 return pIsoResMgr; 552 } 553 554 static ImageList* CreateImageList_Impl( sal_uInt16 nResId ) 555 { 556 ImageList* pList = NULL; 557 ResMgr* pResMgr = GetIsoResMgr_Impl(); 558 DBG_ASSERT( pResMgr, "SvFileInformationManager::CreateImageList_Impl(): no resmgr" ); 559 ResId aResId( nResId, *pResMgr ); 560 aResId.SetRT( RSC_IMAGELIST ); 561 if ( pResMgr->IsAvailable( aResId ) ) 562 pList = new ImageList( aResId ); 563 else 564 pList = new ImageList(); 565 return pList; 566 } 567 568 static Image GetOfficeImageFromList_Impl( sal_uInt16 nImageId, sal_Bool bBig, sal_Bool bHighContrast ) 569 { 570 ImageList* pList = NULL; 571 572 static ImageList* _pSmallOfficeImgList = NULL; 573 static ImageList* _pBigOfficeImgList = NULL; 574 static ImageList* _pSmallHCOfficeImgList = NULL; 575 static ImageList* _pBigHCOfficeImgList = NULL; 576 static sal_uLong nStyle = Application::GetSettings().GetStyleSettings().GetSymbolsStyle(); 577 578 // If the style has been changed, throw away our cache of the older images 579 if ( nStyle != Application::GetSettings().GetStyleSettings().GetSymbolsStyle() ) 580 { 581 delete _pSmallOfficeImgList, _pSmallOfficeImgList = NULL; 582 delete _pBigOfficeImgList, _pBigOfficeImgList = NULL; 583 delete _pSmallHCOfficeImgList, _pSmallHCOfficeImgList = NULL; 584 delete _pBigHCOfficeImgList, _pBigHCOfficeImgList = NULL; 585 nStyle = Application::GetSettings().GetStyleSettings().GetSymbolsStyle(); 586 } 587 588 // #i21242# MT: For B&W we need the HC Image and must transform. 589 // bHiContrast is sal_True for all dark backgrounds, but we need HC Images for HC White also, 590 // so we can't rely on bHighContrast. 591 sal_Bool bBlackAndWhite = Application::GetSettings().GetStyleSettings().IsHighContrastBlackAndWhite(); 592 if ( bBlackAndWhite ) 593 bHighContrast = sal_True; 594 595 596 if ( bBig ) 597 { 598 if ( bHighContrast ) 599 { 600 if ( !_pBigHCOfficeImgList ) 601 _pBigHCOfficeImgList = CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_BIG_HIGHCONTRAST ); 602 pList = _pBigHCOfficeImgList; 603 } 604 else 605 { 606 if ( !_pBigOfficeImgList ) 607 _pBigOfficeImgList = CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_BIG ); 608 pList = _pBigOfficeImgList; 609 } 610 } 611 else 612 { 613 if ( bHighContrast ) 614 { 615 if ( !_pSmallHCOfficeImgList ) 616 _pSmallHCOfficeImgList = CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_SMALL_HIGHCONTRAST ); 617 pList = _pSmallHCOfficeImgList; 618 } 619 else 620 { 621 if ( !_pSmallOfficeImgList ) 622 _pSmallOfficeImgList = CreateImageList_Impl( RID_SVTOOLS_IMAGELIST_SMALL ); 623 pList = _pSmallOfficeImgList; 624 } 625 } 626 627 Image aImage = pList->GetImage( nImageId ); 628 629 if ( bBlackAndWhite ) 630 { 631 // First invert the Image, because it's designed for black background, structures are bright 632 aImage.Invert(); 633 // Now make monochrome... 634 ImageColorTransform eTrans = IMAGECOLORTRANSFORM_MONOCHROME_WHITE; 635 if ( Application::GetSettings().GetStyleSettings().GetFaceColor().GetColor() == COL_WHITE ) 636 eTrans = IMAGECOLORTRANSFORM_MONOCHROME_BLACK; 637 aImage = aImage.GetColorTransformedImage( eTrans ); 638 } 639 640 return aImage; 641 } 642 */ 643 644 static Image GetImageFromList_Impl( sal_uInt16 nImageId, sal_Bool bBig, sal_Bool bHighContrast ) 645 { 646 if ( !bBig && IMG_FOLDER == nImageId && !bHighContrast ) 647 // return our new small folder image (256 colors) 648 return Image( SvtResId( IMG_SVT_FOLDER ) ); 649 650 ImageList* pList = NULL; 651 652 static ImageList* _pSmallImageList = NULL; 653 static ImageList* _pBigImageList = NULL; 654 static ImageList* _pSmallHCImageList = NULL; 655 static ImageList* _pBigHCImageList = NULL; 656 static sal_uLong nStyle = Application::GetSettings().GetStyleSettings().GetSymbolsStyle(); 657 658 // If the style has been changed, throw away our cache of the older images 659 if ( nStyle != Application::GetSettings().GetStyleSettings().GetSymbolsStyle() ) 660 { 661 delete _pSmallImageList, _pSmallImageList = NULL; 662 delete _pBigImageList, _pBigImageList = NULL; 663 delete _pSmallHCImageList, _pSmallHCImageList = NULL; 664 delete _pBigHCImageList, _pBigHCImageList = NULL; 665 nStyle = Application::GetSettings().GetStyleSettings().GetSymbolsStyle(); 666 } 667 668 if ( bBig ) 669 { 670 if ( bHighContrast ) 671 { 672 if ( !_pBigHCImageList ) 673 _pBigHCImageList = new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_BIG_HIGHCONTRAST ) ); 674 pList = _pBigHCImageList; 675 } 676 else 677 { 678 if ( !_pBigImageList ) 679 _pBigImageList = new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_BIG ) ); 680 pList = _pBigImageList; 681 } 682 } 683 else 684 { 685 if ( bHighContrast ) 686 { 687 if ( !_pSmallHCImageList ) 688 _pSmallHCImageList = new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_SMALL_HIGHCONTRAST ) ); 689 pList = _pSmallHCImageList; 690 } 691 else 692 { 693 if ( !_pSmallImageList ) 694 _pSmallImageList = new ImageList( SvtResId( RID_SVTOOLS_IMAGELIST_SMALL ) ); 695 pList = _pSmallImageList; 696 } 697 } 698 699 if ( pList->HasImageAtPos( nImageId ) ) 700 return pList->GetImage( nImageId ); 701 else 702 return Image(); 703 //return GetOfficeImageFromList_Impl( nImageId, bBig, bHighContrast ); 704 } 705 706 //**************************************************************************** 707 708 void ReplaceStarOfficeVar( String& _rDescription ) 709 { 710 static String sVariable( RTL_CONSTASCII_STRINGPARAM( "%STAROFFICE" ) ); 711 static String sProductName; 712 if ( sProductName.Len() == 0 ) 713 { 714 ::rtl::OUString sTemp; 715 ::utl::ConfigManager::GetDirectConfigProperty( ::utl::ConfigManager::PRODUCTNAME ) >>= sTemp; 716 if ( sTemp.equalsAscii( "StarSuite" ) == sal_False ) 717 sProductName = String::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "StarOffice" ) ); 718 else 719 sProductName = String( sTemp ); 720 } 721 _rDescription.SearchAndReplace( sVariable, sProductName ); 722 } 723 724 String SvFileInformationManager::GetDescription_Impl( const INetURLObject& rObject, sal_Bool bDetectFolder ) 725 { 726 RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog, "svtools", "hb93813", "SvFileInformationManager::GetDescription_Impl()" ); 727 728 String sDescription; 729 String sExtension( rObject.getExtension() ), sURL( rObject.GetMainURL( INetURLObject::NO_DECODE ) ); 730 sal_uInt16 nResId = 0; 731 sal_Bool bShowExt = sal_False, bDetected = sal_False, bOnlyFile = sal_False; 732 sal_Bool bFolder = bDetectFolder ? CONTENT_HELPER::IsFolder( sURL ) : sal_False; 733 if ( !bFolder ) 734 { 735 if ( !bDetected ) 736 { 737 if ( rObject.GetProtocol() == INET_PROT_PRIVATE ) 738 { 739 String aURLPath = sURL.Copy( URL_PREFIX_PRIV_SOFFICE_LEN ); 740 String aType = aURLPath.GetToken( 0, INET_PATH_TOKEN ); 741 if ( aType == String( RTL_CONSTASCII_STRINGPARAM("factory") ) ) 742 { 743 sDescription = GetDescriptionByFactory_Impl( aURLPath.Copy( aURLPath.Search( INET_PATH_TOKEN ) + 1 ) ); 744 bDetected = sal_True; 745 } 746 } 747 748 if ( !bDetected ) 749 { 750 // search a description by extension 751 sal_Bool bExt = ( sExtension.Len() > 0 ); 752 if ( bExt ) 753 { 754 sExtension.ToLowerAscii(); 755 nResId = GetDescriptionId_Impl( sExtension, bShowExt ); 756 } 757 if ( !nResId ) 758 { 759 nResId = STR_DESCRIPTION_FILE; 760 bOnlyFile = bExt; 761 } 762 } 763 } 764 } 765 else 766 nResId = GetFolderDescriptionId_Impl( sURL ); 767 768 if ( nResId > 0 ) 769 { 770 if ( bOnlyFile ) 771 { 772 bShowExt = sal_False; 773 sExtension.ToUpperAscii(); 774 sDescription = sExtension; 775 sDescription += '-'; 776 } 777 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 778 sDescription += String( SvtResId( nResId ) ); 779 } 780 781 DBG_ASSERT( sDescription.Len() > 0, "file without description" ); 782 783 if ( bShowExt ) 784 { 785 sDescription += String( RTL_CONSTASCII_STRINGPARAM(" (") ); 786 sDescription += sExtension; 787 sDescription += ')'; 788 } 789 790 ReplaceStarOfficeVar( sDescription ); 791 return sDescription; 792 } 793 794 Image SvFileInformationManager::GetImage( const INetURLObject& rObject, sal_Bool bBig ) 795 { 796 return GetImage( rObject, bBig, sal_False ); 797 } 798 799 Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject, sal_Bool bBig ) 800 { 801 return GetFileImage( rObject, bBig, sal_False ); 802 } 803 804 Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, sal_Bool bBig ) 805 { 806 return GetImageNoDefault( rObject, bBig, sal_False ); 807 } 808 809 Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo, sal_Bool bBig ) 810 { 811 return GetFolderImage( rInfo, bBig, sal_False ); 812 } 813 814 Image SvFileInformationManager::GetImage( const INetURLObject& rObject, sal_Bool bBig, sal_Bool bHighContrast ) 815 { 816 sal_uInt16 nImage = GetImageId_Impl( rObject, sal_True ); 817 DBG_ASSERT( nImage, "invalid ImageId" ); 818 return GetImageFromList_Impl( nImage, bBig, bHighContrast ); 819 } 820 821 Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject, sal_Bool bBig, sal_Bool bHighContrast ) 822 { 823 sal_uInt16 nImage = GetImageId_Impl( rObject, sal_False ); 824 DBG_ASSERT( nImage, "invalid ImageId" ); 825 return GetImageFromList_Impl( nImage, bBig, bHighContrast ); 826 } 827 828 Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, sal_Bool bBig, sal_Bool bHighContrast ) 829 { 830 sal_uInt16 nImage = GetImageId_Impl( rObject, sal_True ); 831 DBG_ASSERT( nImage, "invalid ImageId" ); 832 833 if ( nImage == IMG_FILE ) 834 return Image(); 835 836 return GetImageFromList_Impl( nImage, bBig, bHighContrast ); 837 } 838 839 Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo, sal_Bool bBig, sal_Bool bHighContrast ) 840 { 841 sal_uInt16 nImage = IMG_FOLDER; 842 DBG_ASSERT( nImage, "invalid ImageId" ); 843 844 if ( rInfo.m_bIsRemote ) 845 nImage = IMG_NETWORKDEV; 846 else if ( rInfo.m_bIsCompactDisc ) 847 nImage = IMG_CDROMDEV; 848 else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsFloppy ) 849 nImage = IMG_REMOVEABLEDEV; 850 else if ( rInfo.m_bIsVolume ) 851 nImage = IMG_FIXEDDEV; 852 853 return GetImageFromList_Impl( nImage, bBig, bHighContrast ); 854 } 855 856 String SvFileInformationManager::GetDescription( const INetURLObject& rObject ) 857 { 858 return SvFileInformationManager::GetDescription_Impl( rObject, sal_True ); 859 } 860 861 String SvFileInformationManager::GetFileDescription( const INetURLObject& rObject ) 862 { 863 return SvFileInformationManager::GetDescription_Impl( rObject, sal_False ); 864 } 865 866 String SvFileInformationManager::GetFolderDescription( const svtools::VolumeInfo& rInfo ) 867 { 868 sal_uInt16 nResId = STR_DESCRIPTION_FOLDER; 869 if ( rInfo.m_bIsRemote ) 870 nResId = STR_DESCRIPTION_REMOTE_VOLUME; 871 else if ( rInfo.m_bIsFloppy ) 872 nResId = STR_DESCRIPTION_FLOPPY_VOLUME; 873 else if ( rInfo.m_bIsCompactDisc ) 874 nResId = STR_DESCRIPTION_CDROM_VOLUME; 875 else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsVolume ) 876 nResId = STR_DESCRIPTION_LOCALE_VOLUME; 877 878 String sDescription = String( SvtResId( nResId ) ); 879 return sDescription; 880 } 881 882