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