LCOV - code coverage report
Current view: top level - svtools/source/misc - imagemgr.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 261 0.0 %
Date: 2014-04-14 Functions: 0 18 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <svtools/imagemgr.hxx>
      21             : #include <tools/urlobj.hxx>
      22             : #include <tools/debug.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <vcl/wrkwin.hxx>
      25             : #include "vcl/image.hxx"
      26             : #include "vcl/settings.hxx"
      27             : #include <sot/storage.hxx>
      28             : #include <comphelper/classids.hxx>
      29             : #include <unotools/ucbhelper.hxx>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <com/sun/star/beans/PropertyValue.hpp>
      32             : #include <com/sun/star/container/XNameContainer.hpp>
      33             : #include <com/sun/star/document/XTypeDetection.hpp>
      34             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35             : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
      36             : #include <ucbhelper/content.hxx>
      37             : #include <tools/rcid.h>
      38             : #include <unotools/configmgr.hxx>
      39             : #include <svtools/svtools.hrc>
      40             : #include <svtools/imagemgr.hrc>
      41             : #include <svtools/svtresid.hxx>
      42             : #include <osl/mutex.hxx>
      43             : #include <vcl/lazydelete.hxx>
      44             : 
      45             : // globals *******************************************************************
      46             : 
      47             : #define NO_INDEX        (-1)
      48             : #define CONTENT_HELPER  ::utl::UCBContentHelper
      49             : 
      50             : struct SvtExtensionResIdMapping_Impl
      51             : {
      52             :     const char*   _pExt;
      53             :     bool    _bExt;
      54             :     sal_uInt16  _nStrId;
      55             :     sal_uInt16  _nImgId;
      56             : };
      57             : 
      58             : static SvtExtensionResIdMapping_Impl const ExtensionMap_Impl[] =
      59             : {
      60             :     { "awk",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      61             :     { "bas",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      62             :     { "bat",   true,  STR_DESCRIPTION_BATCHFILE,             0 },
      63             :     { "bmk",   false, STR_DESCRIPTION_BOOKMARKFILE,          0 },
      64             :     { "bmp",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_BITMAP },
      65             :     { "c",     true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      66             :     { "cfg",   false, STR_DESCRIPTION_CFGFILE,               0 },
      67             :     { "cmd",   true,  STR_DESCRIPTION_BATCHFILE,             0 },
      68             :     { "cob",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      69             :     { "com",   true,  STR_DESCRIPTION_APPLICATION,           0 },
      70             :     { "cxx",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      71             :     { "dbf",   true,  STR_DESCRIPTION_DATABASE_TABLE,        IMG_TABLE },
      72             :     { "def",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      73             :     { "dll",   true,  STR_DESCRIPTION_SYSFILE,               0 },
      74             :     { "doc",   false, STR_DESCRIPTION_WORD_DOC,              IMG_WRITER },
      75             :     { "dot",   false, STR_DESCRIPTION_WORD_DOC,              IMG_WRITERTEMPLATE },
      76             :     { "docx",  false, STR_DESCRIPTION_WORD_DOC,              IMG_WRITER },
      77             :     { "dxf",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_DXF },
      78             :     { "exe",   true,  STR_DESCRIPTION_APPLICATION,           0 },
      79             :     { "gif",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_GIF },
      80             :     { "h",     true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      81             :     { "hlp",   false, STR_DESCRIPTION_HELP_DOC,              0 },
      82             :     { "hrc",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      83             :     { "htm",   false, STR_DESCRIPTION_HTMLFILE,              IMG_HTML },
      84             :     { "html",  false, STR_DESCRIPTION_HTMLFILE,              IMG_HTML },
      85             :     { "asp",   false, STR_DESCRIPTION_HTMLFILE,              IMG_HTML },
      86             :     { "hxx",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      87             :     { "ini",   false, STR_DESCRIPTION_CFGFILE,               0 },
      88             :     { "java",  true,  STR_DESCRIPTION_SOURCEFILE,            0 },
      89             :     { "jpeg",  true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_JPG },
      90             :     { "jpg",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_JPG },
      91             :     { "lha",   true,  STR_DESCRIPTION_ARCHIVFILE,            0 },
      92             : #ifdef WNT
      93             :     { "lnk",   false, 0,                                     0 },
      94             : #endif
      95             :     { "log",   true,  STR_DESCRIPTION_LOGFILE,               0 },
      96             :     { "lst",   true,  STR_DESCRIPTION_LOGFILE,               0 },
      97             :     { "met",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_MET },
      98             :     { "mml",   false, STR_DESCRIPTION_MATHML_DOC,            IMG_MATH },
      99             :     { "mod",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
     100             :     { "odb",   false, STR_DESCRIPTION_OO_DATABASE_DOC,       IMG_OO_DATABASE_DOC },
     101             :     { "odg",   false, STR_DESCRIPTION_OO_DRAW_DOC,           IMG_OO_DRAW_DOC },
     102             :     { "odf",   false, STR_DESCRIPTION_OO_MATH_DOC,           IMG_OO_MATH_DOC },
     103             :     { "odm",   false, STR_DESCRIPTION_OO_GLOBAL_DOC,         IMG_OO_GLOBAL_DOC },
     104             :     { "odp",   false, STR_DESCRIPTION_OO_IMPRESS_DOC,        IMG_OO_IMPRESS_DOC },
     105             :     { "ods",   false, STR_DESCRIPTION_OO_CALC_DOC,           IMG_OO_CALC_DOC },
     106             :     { "odt",   false, STR_DESCRIPTION_OO_WRITER_DOC,         IMG_OO_WRITER_DOC },
     107             :     { "otg",   false, STR_DESCRIPTION_OO_DRAW_TEMPLATE,      IMG_OO_DRAW_TEMPLATE },
     108             :     { "otp",   false, STR_DESCRIPTION_OO_IMPRESS_TEMPLATE,   IMG_OO_IMPRESS_TEMPLATE },
     109             :     { "ots",   false, STR_DESCRIPTION_OO_CALC_TEMPLATE,      IMG_OO_CALC_TEMPLATE },
     110             :     { "ott",   false, STR_DESCRIPTION_OO_WRITER_TEMPLATE,    IMG_OO_WRITER_TEMPLATE },
     111             :     { "pas",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
     112             :     { "pcd",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_PCD },
     113             :     { "pct",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_PCT },
     114             :     { "pict",   true,  STR_DESCRIPTION_GRAPHIC_DOC,          IMG_PCT },
     115             :     { "pcx",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_PCX },
     116             :     { "pl",    true,  STR_DESCRIPTION_SOURCEFILE,            0 },
     117             :     { "png",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_PNG },
     118             :     { "rar",   true,  STR_DESCRIPTION_ARCHIVFILE,            0 },
     119             :     { "rtf",   false, STR_DESCRIPTION_WORD_DOC,              IMG_WRITER },
     120             :     { "sbl",   false, 0,                                     0 },
     121             :     { "sch",   false, 0,                                     0 },
     122             :     { "sda",   false, STR_DESCRIPTION_SDRAW_DOC,             IMG_DRAW },
     123             :     { "sdb",   false, STR_DESCRIPTION_SDATABASE_DOC,         IMG_DATABASE },
     124             :     { "sdc",   false, STR_DESCRIPTION_SCALC_DOC,             IMG_CALC },
     125             :     { "sdd",   false, STR_DESCRIPTION_SIMPRESS_DOC,          IMG_IMPRESS },
     126             :     { "sdp",   false, STR_DESCRIPTION_SIMPRESS_DOC,          0 },
     127             :     { "sds",   false, STR_DESCRIPTION_SCHART_DOC,            0 },
     128             :     { "sdw",   false, STR_DESCRIPTION_SWRITER_DOC,           IMG_WRITER },
     129             :     { "sga",   false, 0,                                     0 },
     130             :     { "sgf",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_SGF },
     131             :     { "sgl",   false, STR_DESCRIPTION_GLOBALDOC,             IMG_GLOBAL_DOC },
     132             :     { "sgv",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_SGV },
     133             :     { "shtml", false, STR_DESCRIPTION_HTMLFILE,              IMG_HTML },
     134             :     { "sim",   false, STR_DESCRIPTION_SIMAGE_DOC,            IMG_SIM },
     135             :     { "smf",   false, STR_DESCRIPTION_SMATH_DOC,             IMG_MATH },
     136             :     { "src",   true,  STR_DESCRIPTION_SOURCEFILE,            0 },
     137             :     { "svh",   false, STR_DESCRIPTION_HELP_DOC,              0 },
     138             :     { "svm",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_SVM },
     139             :     { "stc",   false, STR_DESCRIPTION_CALC_TEMPLATE,         IMG_CALCTEMPLATE },
     140             :     { "std",   false, STR_DESCRIPTION_DRAW_TEMPLATE,         IMG_DRAWTEMPLATE },
     141             :     { "sti",   false, STR_DESCRIPTION_IMPRESS_TEMPLATE,      IMG_IMPRESSTEMPLATE },
     142             :     { "stw",   false, STR_DESCRIPTION_WRITER_TEMPLATE,       IMG_WRITERTEMPLATE },
     143             :     { "sxc",   false, STR_DESCRIPTION_SXCALC_DOC,            IMG_CALC },
     144             :     { "sxd",   false, STR_DESCRIPTION_SXDRAW_DOC,            IMG_DRAW },
     145             :     { "sxg",   false, STR_DESCRIPTION_SXGLOBAL_DOC,          IMG_GLOBAL_DOC },
     146             :     { "sxi",   false, STR_DESCRIPTION_SXIMPRESS_DOC,         IMG_IMPRESS },
     147             :     { "sxm",   false, STR_DESCRIPTION_SXMATH_DOC,            IMG_MATH },
     148             :     { "sxs",   false, STR_DESCRIPTION_SXCHART_DOC,           0 },
     149             :     { "sxw",   false, STR_DESCRIPTION_SXWRITER_DOC,          IMG_WRITER },
     150             :     { "sys",   true,  STR_DESCRIPTION_SYSFILE,               0 },
     151             :     { "tif",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_TIFF },
     152             :     { "tiff",  true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_TIFF },
     153             :     { "txt",   false, STR_DESCRIPTION_TEXTFILE,              IMG_TEXTFILE },
     154             :     { "url",   false, STR_DESCRIPTION_LINK,                  0 },
     155             :     { "vor",   false, STR_DESCRIPTION_SOFFICE_TEMPLATE_DOC,  IMG_WRITERTEMPLATE },
     156             :     { "vxd",   true,  STR_DESCRIPTION_SYSFILE,               0 },
     157             :     { "wmf",   true,  STR_DESCRIPTION_GRAPHIC_DOC,           IMG_WMF },
     158             :     { "xls",   false, STR_DESCRIPTION_EXCEL_DOC,             IMG_CALC },
     159             :     { "xlt",   false, STR_DESCRIPTION_EXCEL_TEMPLATE_DOC,    IMG_CALCTEMPLATE },
     160             :     { "xlsx",  false, STR_DESCRIPTION_EXCEL_DOC,             IMG_CALC },
     161             :     { "uu",    true,  STR_DESCRIPTION_ARCHIVFILE,            0 },
     162             :     { "uue",   true,  STR_DESCRIPTION_ARCHIVFILE,            0 },
     163             :     { "z",     true,  STR_DESCRIPTION_ARCHIVFILE,            0 },
     164             :     { "zip",   true,  STR_DESCRIPTION_ARCHIVFILE,            0 },
     165             :     { "zoo",   true,  STR_DESCRIPTION_ARCHIVFILE,            0 },
     166             :     { "gz",    true,  STR_DESCRIPTION_ARCHIVFILE,            0 },
     167             :     { "ppt",   false, STR_DESCRIPTION_POWERPOINT,            IMG_IMPRESS },
     168             :     { "pot",   false, STR_DESCRIPTION_POWERPOINT_TEMPLATE,   IMG_IMPRESSTEMPLATE },
     169             :     { "pps",   false, STR_DESCRIPTION_POWERPOINT_SHOW,       IMG_IMPRESS },
     170             :     { "pptx",  false, STR_DESCRIPTION_POWERPOINT,            IMG_IMPRESS },
     171             :     { "oxt",   false, STR_DESCRIPTION_EXTENSION,             IMG_EXTENSION },
     172             :     { 0, false, 0, 0 }
     173             : };
     174             : 
     175             : struct SvtFactory2ExtensionMapping_Impl
     176             : {
     177             :     const char*   _pFactory;
     178             :     const char*   _pExtension;
     179             : };
     180             : 
     181             : // mapping from "private:factory" url to extension
     182             : 
     183             : static SvtFactory2ExtensionMapping_Impl const Fac2ExtMap_Impl[] =
     184             : {
     185             :     { "swriter",                "odt" },
     186             :     { "swriter/web",            "html" },
     187             :     { "swriter/GlobalDocument", "odm" },
     188             :     { "scalc",                  "ods" },
     189             :     { "simpress",               "odp" },
     190             :     { "sdraw",                  "odg" },
     191             :     { "smath",                  "odf" },
     192             :     { "sdatabase",              "odb" },
     193             :     { NULL, NULL }
     194             : };
     195             : 
     196             : 
     197             : 
     198           0 : static OUString GetImageExtensionByFactory_Impl( const OUString& rURL )
     199             : {
     200           0 :     INetURLObject aObj( rURL );
     201           0 :     OUString aPath = aObj.GetURLPath( INetURLObject::NO_DECODE );
     202           0 :     OUString aExtension;
     203             : 
     204           0 :     if ( !aPath.isEmpty() )
     205             :     {
     206           0 :         sal_uInt16 nIndex = 0;
     207           0 :         while ( Fac2ExtMap_Impl[ nIndex ]._pFactory )
     208             :         {
     209           0 :             if ( aPath.equalsAscii( Fac2ExtMap_Impl[ nIndex ]._pFactory ) )
     210             :             {
     211             :                 // extension found
     212           0 :                 aExtension = OUString::createFromAscii(Fac2ExtMap_Impl[ nIndex ]._pExtension);
     213             :                 // and return it
     214           0 :                 return aExtension;
     215             :             }
     216           0 :             ++nIndex;
     217             :         }
     218             :     }
     219             : 
     220             :     // no extension found, so use the type detection (performance brake)
     221             : 
     222             :     try
     223             :     {
     224             :         // get the TypeDetection service to access all registered types
     225           0 :         ::com::sun::star::uno::Reference < ::com::sun::star::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     226             :         ::com::sun::star::uno::Reference < ::com::sun::star::document::XTypeDetection > xTypeDetector(
     227           0 :             xContext->getServiceManager()->createInstanceWithContext("com.sun.star.document.TypeDetection", xContext),
     228           0 :             ::com::sun::star::uno::UNO_QUERY );
     229             : 
     230           0 :         OUString aInternalType = xTypeDetector->queryTypeByURL( rURL );
     231           0 :         ::com::sun::star::uno::Reference < ::com::sun::star::container::XNameAccess > xAccess( xTypeDetector, ::com::sun::star::uno::UNO_QUERY );
     232           0 :         ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > aTypeProps;
     233           0 :         if ( !aInternalType.isEmpty() && xAccess->hasByName( aInternalType ) )
     234             :         {
     235           0 :             xAccess->getByName( aInternalType ) >>= aTypeProps;
     236           0 :             sal_Int32 nProps = aTypeProps.getLength();
     237           0 :             for ( sal_Int32 i = 0; i < nProps; ++i )
     238             :             {
     239           0 :                 const ::com::sun::star::beans::PropertyValue& rProp = aTypeProps[i];
     240           0 :                 if (rProp.Name == "Extensions")
     241             :                 {
     242           0 :                     ::com::sun::star::uno::Sequence < OUString > aExtensions;
     243           0 :                     if ( ( rProp.Value >>= aExtensions ) && aExtensions.getLength() > 0 )
     244             :                     {
     245           0 :                         const OUString* pExtensions = aExtensions.getConstArray();
     246           0 :                         aExtension = OUString( pExtensions[0] );
     247           0 :                         break;
     248           0 :                     }
     249             :                 }
     250             :             }
     251           0 :         }
     252             :     }
     253           0 :     catch( const ::com::sun::star::uno::RuntimeException& )
     254             :     {
     255           0 :         throw; // dont hide it!
     256             :     }
     257           0 :     catch( const ::com::sun::star::uno::Exception& )
     258             :     {
     259             :         // type detection failed -> no extension
     260             :     }
     261             : 
     262           0 :     return aExtension;
     263             : }
     264             : 
     265           0 : static sal_Int32 GetIndexOfExtension_Impl( const OUString& rExtension )
     266             : {
     267           0 :     sal_Int32 nRet = NO_INDEX;
     268           0 :     if ( !rExtension.isEmpty() )
     269             :     {
     270           0 :         sal_Int32 nIndex = 0;
     271           0 :         OUString aExt = rExtension.toAsciiLowerCase();
     272           0 :         while ( ExtensionMap_Impl[ nIndex ]._pExt )
     273             :         {
     274           0 :             if ( aExt.equalsAscii( ExtensionMap_Impl[ nIndex ]._pExt ) )
     275             :             {
     276           0 :                 nRet = nIndex;
     277           0 :                 break;
     278             :             }
     279           0 :             ++nIndex;
     280           0 :         }
     281             :     }
     282             : 
     283           0 :     return nRet;
     284             : }
     285             : 
     286           0 : static sal_uInt16 GetImageId_Impl( const OUString& rExtension )
     287             : {
     288           0 :     sal_uInt16 nImage = IMG_FILE;
     289           0 :     sal_Int32  nIndex = GetIndexOfExtension_Impl( rExtension );
     290           0 :     if ( nIndex != NO_INDEX )
     291             :     {
     292           0 :         nImage = ExtensionMap_Impl[ nIndex ]._nImgId;
     293           0 :         if ( !nImage )
     294           0 :             nImage = IMG_FILE;
     295             :     }
     296             : 
     297           0 :     return nImage;
     298             : }
     299             : 
     300           0 : static bool GetVolumeProperties_Impl( ::ucbhelper::Content& rContent, svtools::VolumeInfo& rVolumeInfo )
     301             : {
     302           0 :     bool bRet = false;
     303             : 
     304             :     try
     305             :     {
     306           0 :         bRet = ( ( rContent.getPropertyValue( "IsVolume" ) >>= rVolumeInfo.m_bIsVolume ) &&
     307           0 :                  ( rContent.getPropertyValue( "IsRemote" ) >>= rVolumeInfo.m_bIsRemote ) &&
     308           0 :                  ( rContent.getPropertyValue( "IsRemoveable" ) >>= rVolumeInfo.m_bIsRemoveable ) &&
     309           0 :                  ( rContent.getPropertyValue( "IsFloppy" ) >>= rVolumeInfo.m_bIsFloppy ) &&
     310           0 :                  ( rContent.getPropertyValue( "IsCompactDisc" ) >>= rVolumeInfo.m_bIsCompactDisc ) );
     311             :     }
     312           0 :     catch( const ::com::sun::star::uno::RuntimeException& )
     313             :     {
     314           0 :         throw; // dont hide it!
     315             :     }
     316           0 :     catch( const ::com::sun::star::uno::Exception& )
     317             :     {
     318             :         // type detection failed -> no extension
     319             :     }
     320             : 
     321           0 :     return bRet;
     322             : }
     323             : 
     324           0 : static sal_uInt16 GetFolderImageId_Impl( const OUString& rURL )
     325             : {
     326           0 :     sal_uInt16 nRet = IMG_FOLDER;
     327           0 :     ::svtools::VolumeInfo aVolumeInfo;
     328             :     try
     329             :     {
     330           0 :         ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     331           0 :         if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
     332             :         {
     333           0 :             if ( aVolumeInfo.m_bIsRemote )
     334           0 :                 nRet = IMG_NETWORKDEV;
     335           0 :             else if ( aVolumeInfo.m_bIsCompactDisc )
     336           0 :                 nRet = IMG_CDROMDEV;
     337           0 :             else if ( aVolumeInfo.m_bIsRemoveable )
     338           0 :                 nRet = IMG_REMOVABLEDEV;
     339           0 :             else if ( aVolumeInfo.m_bIsVolume )
     340           0 :                 nRet = IMG_FIXEDDEV;
     341           0 :         }
     342             :     }
     343           0 :     catch( const ::com::sun::star::uno::RuntimeException& )
     344             :     {
     345           0 :         throw; // dont hide it!
     346             :     }
     347           0 :     catch( const ::com::sun::star::uno::Exception& )
     348             :     {
     349             : 
     350             :     }
     351           0 :     return nRet;
     352             : }
     353             : 
     354           0 : static sal_uInt16 GetImageId_Impl( const INetURLObject& rObject, bool bDetectFolder )
     355             : {
     356           0 :     OUString aExt, sURL = rObject.GetMainURL( INetURLObject::NO_DECODE );
     357           0 :     sal_uInt16 nImage = IMG_FILE;
     358             : 
     359           0 :     if ( rObject.GetProtocol() == INET_PROT_PRIVATE )
     360             :     {
     361           0 :         OUString aURLPath = sURL.copy( URL_PREFIX_PRIV_SOFFICE_LEN );
     362           0 :         OUString aType = aURLPath.getToken( 0, '/' );
     363           0 :         if ( aType == "factory" )
     364             :         {
     365             :             // detect an image id for our "private:factory" urls
     366           0 :             aExt = GetImageExtensionByFactory_Impl( sURL );
     367           0 :             if ( !aExt.isEmpty() )
     368           0 :                 nImage = GetImageId_Impl( aExt );
     369           0 :             return nImage;
     370             :         }
     371           0 :         else if ( aType == "image" )
     372           0 :             nImage = (sal_uInt16)aURLPath.getToken( 1, '/' ).toInt32();
     373             :     }
     374             :     else
     375             :     {
     376           0 :         aExt = rObject.getExtension();
     377           0 :         if ( aExt == "vor" )
     378             :         {
     379           0 :             SotStorageRef aStorage = new SotStorage( sURL, STREAM_STD_READ );
     380           0 :             sal_uInt16 nId = IMG_WRITERTEMPLATE;
     381           0 :             if ( !aStorage->GetError() )
     382             :             {
     383           0 :                 SvGlobalName aGlobalName = aStorage->GetClassName();
     384           0 :                 if ( aGlobalName == SvGlobalName(SO3_SC_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SC_CLASSID_30) )
     385           0 :                     nId = IMG_CALCTEMPLATE;
     386           0 :                 else if ( aGlobalName == SvGlobalName(SO3_SDRAW_CLASSID_50) )
     387           0 :                     nId = IMG_DRAWTEMPLATE;
     388           0 :                 else if ( aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_50) ||
     389           0 :                         aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SIMPRESS_CLASSID_30) )
     390           0 :                     nId = IMG_IMPRESSTEMPLATE;
     391           0 :                 else if ( aGlobalName == SvGlobalName(SO3_SM_CLASSID_50) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_40) || aGlobalName == SvGlobalName(SO3_SM_CLASSID_30) )
     392           0 :                     nId = IMG_MATHTEMPLATE;
     393             :             }
     394             : 
     395           0 :             return nId;
     396             :         }
     397             :     }
     398             : 
     399           0 :     if ( nImage == IMG_FILE && !sURL.isEmpty() )
     400             :     {
     401           0 :         if ( bDetectFolder && CONTENT_HELPER::IsFolder( sURL ) )
     402           0 :             nImage = GetFolderImageId_Impl( sURL );
     403           0 :         else if ( !aExt.isEmpty() )
     404           0 :             nImage = GetImageId_Impl( aExt );
     405             :     }
     406           0 :     return nImage;
     407             : }
     408             : 
     409           0 : static sal_uInt16 GetDescriptionId_Impl( const OUString& rExtension, bool& rbShowExt )
     410             : {
     411           0 :     sal_uInt16 nId = 0;
     412           0 :     sal_Int32  nIndex = GetIndexOfExtension_Impl( rExtension );
     413           0 :     if ( nIndex != NO_INDEX )
     414             :     {
     415           0 :         nId = ExtensionMap_Impl[ nIndex ]._nStrId;
     416           0 :         rbShowExt = ExtensionMap_Impl[ nIndex ]._bExt;
     417             :     }
     418             : 
     419           0 :     return nId;
     420             : }
     421             : 
     422           0 : static OUString GetDescriptionByFactory_Impl( const OUString& rFactory )
     423             : {
     424           0 :     sal_uInt16 nResId = 0;
     425           0 :     if ( rFactory.startsWithIgnoreAsciiCase( "swriter" ) )
     426           0 :         nResId = STR_DESCRIPTION_FACTORY_WRITER;
     427           0 :     else if ( rFactory.startsWithIgnoreAsciiCase( "scalc" ) )
     428           0 :         nResId = STR_DESCRIPTION_FACTORY_CALC;
     429           0 :     else if ( rFactory.startsWithIgnoreAsciiCase( "simpress" ) )
     430           0 :         nResId = STR_DESCRIPTION_FACTORY_IMPRESS;
     431           0 :     else if ( rFactory.startsWithIgnoreAsciiCase( "sdraw" ) )
     432           0 :         nResId = STR_DESCRIPTION_FACTORY_DRAW;
     433           0 :     else if ( rFactory.startsWithIgnoreAsciiCase( "swriter/web" ) )
     434           0 :         nResId = STR_DESCRIPTION_FACTORY_WRITERWEB;
     435           0 :     else if ( rFactory.startsWithIgnoreAsciiCase( "swriter/globaldocument" ) )
     436           0 :         nResId = STR_DESCRIPTION_FACTORY_GLOBALDOC;
     437           0 :     else if ( rFactory.startsWithIgnoreAsciiCase( "smath" ) )
     438           0 :         nResId = STR_DESCRIPTION_FACTORY_MATH;
     439           0 :     else if ( rFactory.startsWithIgnoreAsciiCase( "sdatabase" ) )
     440           0 :         nResId = STR_DESCRIPTION_FACTORY_DATABASE;
     441             : 
     442           0 :     if ( nResId )
     443             :     {
     444           0 :         SolarMutexGuard aGuard;
     445           0 :         return SvtResId(nResId).toString();
     446             :     }
     447           0 :     return OUString();
     448             : }
     449             : 
     450           0 : static sal_uInt16 GetFolderDescriptionId_Impl( const OUString& rURL )
     451             : {
     452           0 :     sal_uInt16 nRet = STR_DESCRIPTION_FOLDER;
     453           0 :     svtools::VolumeInfo aVolumeInfo;
     454             :     try
     455             :     {
     456           0 :         ::ucbhelper::Content aCnt( rURL, ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
     457           0 :         if ( GetVolumeProperties_Impl( aCnt, aVolumeInfo ) )
     458             :         {
     459           0 :             if ( aVolumeInfo.m_bIsRemote )
     460           0 :                 nRet = STR_DESCRIPTION_REMOTE_VOLUME;
     461           0 :             else if ( aVolumeInfo.m_bIsFloppy )
     462           0 :                 nRet = STR_DESCRIPTION_FLOPPY_VOLUME;
     463           0 :             else if ( aVolumeInfo.m_bIsCompactDisc )
     464           0 :                 nRet = STR_DESCRIPTION_CDROM_VOLUME;
     465           0 :             else if ( aVolumeInfo.m_bIsRemoveable || aVolumeInfo.m_bIsVolume )
     466           0 :                 nRet = STR_DESCRIPTION_LOCALE_VOLUME;
     467           0 :         }
     468             :     }
     469           0 :     catch( const ::com::sun::star::uno::RuntimeException& )
     470             :     {
     471           0 :         throw; // dont hide it!
     472             :     }
     473           0 :     catch( const ::com::sun::star::uno::Exception& )
     474             :     {
     475             : 
     476             :     }
     477           0 :     return nRet;
     478             : }
     479             : 
     480           0 : static Image GetImageFromList_Impl( sal_uInt16 nImageId, bool bBig )
     481             : {
     482           0 :     if ( !bBig && IMG_FOLDER == nImageId )
     483             :         // return our new small folder image (256 colors)
     484           0 :         return Image( SvtResId( IMG_SVT_FOLDER ) );
     485             : 
     486           0 :     ImageList* pList = NULL;
     487             : 
     488           0 :     static vcl::DeleteOnDeinit< ImageList > xSmallImageList( NULL );
     489           0 :     static vcl::DeleteOnDeinit< ImageList > xBigImageList( NULL );
     490           0 :     static OUString style = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
     491             : 
     492             :     // If the style has been changed, throw away our cache of the older images
     493           0 :     OUString currentStyle = Application::GetSettings().GetStyleSettings().DetermineIconTheme();
     494           0 :     if ( style != currentStyle)
     495             :     {
     496           0 :         xSmallImageList.reset();
     497           0 :         xBigImageList.reset();
     498           0 :         style = currentStyle;
     499             :     }
     500             : 
     501           0 :     if ( bBig )
     502             :     {
     503           0 :         if ( !xBigImageList.get() )
     504           0 :             xBigImageList.reset(new ImageList(SvtResId(RID_SVTOOLS_IMAGELIST_BIG)));
     505           0 :         pList = xBigImageList.get();
     506             :     }
     507             :     else
     508             :     {
     509           0 :         if ( !xSmallImageList.get() )
     510           0 :             xSmallImageList.reset(new ImageList(SvtResId(RID_SVTOOLS_IMAGELIST_SMALL)));
     511           0 :         pList = xSmallImageList.get();
     512             :     }
     513             : 
     514           0 :     if ( pList->HasImageAtPos( nImageId ) )
     515           0 :         return pList->GetImage( nImageId );
     516           0 :     return Image();
     517             : }
     518             : 
     519           0 : OUString SvFileInformationManager::GetDescription_Impl( const INetURLObject& rObject, bool bDetectFolder )
     520             : {
     521           0 :     OUString sExtension(rObject.getExtension());
     522           0 :     OUString sDescription, sURL( rObject.GetMainURL( INetURLObject::NO_DECODE ) );
     523           0 :     sal_uInt16 nResId = 0;
     524           0 :     bool bShowExt = false, bDetected = false, bOnlyFile = false;
     525           0 :     bool bFolder = bDetectFolder && CONTENT_HELPER::IsFolder( sURL );
     526           0 :     if ( !bFolder )
     527             :     {
     528           0 :         if ( !bDetected )
     529             :         {
     530           0 :             if ( rObject.GetProtocol() == INET_PROT_PRIVATE )
     531             :             {
     532           0 :                 OUString aURLPath = sURL.copy( URL_PREFIX_PRIV_SOFFICE_LEN );
     533           0 :                 OUString aType = aURLPath.getToken( 0, '/' );
     534           0 :                 if ( aType == "factory" )
     535             :                 {
     536           0 :                     sDescription = GetDescriptionByFactory_Impl( aURLPath.copy( aURLPath.indexOf( '/' ) + 1 ) );
     537           0 :                     bDetected = true;
     538           0 :                 }
     539             :             }
     540             : 
     541           0 :             if ( !bDetected )
     542             :             {
     543             :                 // search a description by extension
     544           0 :                 bool bExt = !sExtension.isEmpty();
     545           0 :                 if ( bExt )
     546             :                 {
     547           0 :                     sExtension = sExtension.toAsciiLowerCase();
     548           0 :                     nResId = GetDescriptionId_Impl( sExtension, bShowExt );
     549             :                 }
     550           0 :                 if ( !nResId )
     551             :                 {
     552           0 :                     nResId = STR_DESCRIPTION_FILE;
     553           0 :                     bOnlyFile = bExt;
     554             :                 }
     555             :             }
     556             :         }
     557             :     }
     558             :     else
     559           0 :         nResId = GetFolderDescriptionId_Impl( sURL );
     560             : 
     561           0 :     if ( nResId > 0 )
     562             :     {
     563           0 :         if ( bOnlyFile )
     564             :         {
     565           0 :             bShowExt = false;
     566           0 :             sExtension = sExtension.toAsciiUpperCase();
     567           0 :             sDescription = sExtension;
     568           0 :             sDescription += "-";
     569             :         }
     570           0 :         SolarMutexGuard aGuard;
     571           0 :         sDescription += SvtResId(nResId).toString();
     572             :     }
     573             : 
     574             :     DBG_ASSERT( !sDescription.isEmpty(), "file without description" );
     575             : 
     576           0 :     if ( bShowExt )
     577             :     {
     578           0 :         sDescription += " (";
     579           0 :         sDescription += sExtension;
     580           0 :         sDescription += ")";
     581             :     }
     582             : 
     583           0 :     return sDescription;
     584             : }
     585             : 
     586           0 : Image SvFileInformationManager::GetImage( const INetURLObject& rObject, bool bBig )
     587             : {
     588           0 :     sal_uInt16 nImage = GetImageId_Impl( rObject, true );
     589             :     DBG_ASSERT( nImage, "invalid ImageId" );
     590           0 :     return GetImageFromList_Impl( nImage, bBig );
     591             : }
     592             : 
     593           0 : Image SvFileInformationManager::GetFileImage( const INetURLObject& rObject, bool bBig )
     594             : {
     595           0 :     sal_Int16 nImage = GetImageId_Impl( rObject, false );
     596             :     DBG_ASSERT( nImage, "invalid ImageId" );
     597           0 :     return GetImageFromList_Impl( nImage, bBig );
     598             : }
     599             : 
     600           0 : Image SvFileInformationManager::GetImageNoDefault( const INetURLObject& rObject, bool bBig )
     601             : {
     602           0 :     sal_uInt16 nImage = GetImageId_Impl( rObject, true );
     603             :     DBG_ASSERT( nImage, "invalid ImageId" );
     604             : 
     605           0 :     if ( nImage == IMG_FILE )
     606           0 :         return Image();
     607             : 
     608           0 :     return GetImageFromList_Impl( nImage, bBig );
     609             : }
     610             : 
     611           0 : Image SvFileInformationManager::GetFolderImage( const svtools::VolumeInfo& rInfo, bool bBig )
     612             : {
     613           0 :     sal_uInt16 nImage = IMG_FOLDER;
     614             :     DBG_ASSERT( nImage, "invalid ImageId" );
     615             : 
     616           0 :     if ( rInfo.m_bIsRemote )
     617           0 :         nImage = IMG_NETWORKDEV;
     618           0 :     else if ( rInfo.m_bIsCompactDisc )
     619           0 :         nImage = IMG_CDROMDEV;
     620           0 :     else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsFloppy )
     621           0 :         nImage = IMG_REMOVABLEDEV;
     622           0 :     else if ( rInfo.m_bIsVolume )
     623           0 :         nImage = IMG_FIXEDDEV;
     624             : 
     625           0 :     return GetImageFromList_Impl( nImage, bBig );
     626             : }
     627             : 
     628           0 : OUString SvFileInformationManager::GetDescription( const INetURLObject& rObject )
     629             : {
     630           0 :     return SvFileInformationManager::GetDescription_Impl( rObject, true );
     631             : }
     632             : 
     633           0 : OUString SvFileInformationManager::GetFileDescription( const INetURLObject& rObject )
     634             : {
     635           0 :     return SvFileInformationManager::GetDescription_Impl( rObject, false );
     636             : }
     637             : 
     638           0 : OUString SvFileInformationManager::GetFolderDescription( const svtools::VolumeInfo& rInfo )
     639             : {
     640           0 :     sal_uInt16 nResId = STR_DESCRIPTION_FOLDER;
     641           0 :     if ( rInfo.m_bIsRemote )
     642           0 :         nResId = STR_DESCRIPTION_REMOTE_VOLUME;
     643           0 :     else if ( rInfo.m_bIsFloppy )
     644           0 :         nResId = STR_DESCRIPTION_FLOPPY_VOLUME;
     645           0 :     else if ( rInfo.m_bIsCompactDisc )
     646           0 :         nResId = STR_DESCRIPTION_CDROM_VOLUME;
     647           0 :     else if ( rInfo.m_bIsRemoveable || rInfo.m_bIsVolume )
     648           0 :         nResId = STR_DESCRIPTION_LOCALE_VOLUME;
     649             : 
     650           0 :     return SvtResId(nResId).toString();
     651             : }
     652             : 
     653             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10