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

Generated by: LCOV version 1.10