bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / unoidl / sddetect.cxx
blob3a54d2c26071d3aec93e3630917e7b9ab114a42f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sddetect.hxx"
22 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <com/sun/star/io/XInputStream.hpp>
27 #include <com/sun/star/ucb/ContentCreationException.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <vcl/graphicfilter.hxx>
30 #include <rtl/ustring.h>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/docfilt.hxx>
33 #include <sfx2/fcontnr.hxx>
34 #include <vcl/FilterConfigItem.hxx>
35 #include <sot/storage.hxx>
36 #include <unotools/mediadescriptor.hxx>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::io;
41 using namespace ::com::sun::star::task;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::lang;
44 using utl::MediaDescriptor;
46 SdFilterDetect::SdFilterDetect()
50 SdFilterDetect::~SdFilterDetect()
54 OUString SAL_CALL SdFilterDetect::detect( Sequence< beans::PropertyValue >& lDescriptor )
56 MediaDescriptor aMediaDesc( lDescriptor );
57 OUString aTypeName = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME(), OUString() );
58 uno::Reference< io::XInputStream > xInStream ( aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM()], uno::UNO_QUERY );
59 if ( !xInStream.is() )
60 return OUString();
62 SfxMedium aMedium;
63 aMedium.UseInteractionHandler( false );
64 aMedium.setStreamToLoadFrom( xInStream, true );
66 SvStream *pInStrm = aMedium.GetInStream();
67 if ( !pInStrm || pInStrm->GetError() )
68 return OUString();
70 if ( aTypeName.startsWith( "impress_MS_PowerPoint_97" ) )
72 // Do not attempt to create an SotStorage on a
73 // 0-length stream as that would create the compound
74 // document header on the stream and effectively write to
75 // disk!
76 pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
77 if ( pInStrm->remainingSize() == 0 )
78 return OUString();
80 try
82 tools::SvRef<SotStorage> aStorage = new SotStorage( pInStrm, false );
83 if ( !aStorage->GetError() && aStorage->IsStream( "PowerPoint Document" ) )
84 return aTypeName;
86 catch (const css::ucb::ContentCreationException&)
90 else
92 pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
94 const OUString aFileName( aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL(), OUString() ) );
95 GraphicDescriptor aDesc( *pInStrm, &aFileName );
96 if( !aDesc.Detect() )
98 INetURLObject aCheckURL( aFileName );
99 if( aCheckURL.getExtension().equalsIgnoreAsciiCase("cgm") )
101 sal_uInt8 n8;
102 pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
103 pInStrm->ReadUChar( n8 );
104 if ( ( n8 & 0xf0 ) == 0 )
105 // we are supporting binary cgm format only, so
106 // this is a small test to exclude cgm text
107 return OUString("impress_CGM_Computer_Graphics_Metafile");
110 else
112 OUString aShortName( GraphicDescriptor::GetImportFormatShortName( aDesc.GetFileFormat() ) );
113 GraphicFilter &rGrfFilter = GraphicFilter::GetGraphicFilter();
114 const OUString aName( rGrfFilter.GetImportFormatTypeName( rGrfFilter.GetImportFormatNumberForShortName( aShortName ) ) );
116 if ( aShortName.equalsIgnoreAsciiCase( "PCD" ) ) // there is a multiple pcd selection possible
118 sal_Int32 nBase = 2; // default Base0
119 if ( aTypeName == "pcd_Photo_CD_Base4" )
120 nBase = 1;
121 else if ( aTypeName == "pcd_Photo_CD_Base16" )
122 nBase = 0;
123 FilterConfigItem aFilterConfigItem( "Office.Common/Filter/Graphic/Import/PCD" );
124 aFilterConfigItem.WriteInt32( "Resolution" , nBase );
127 SfxFilterMatcher aMatch("sdraw");
128 std::shared_ptr<const SfxFilter> pFilter = aMatch.GetFilter4FilterName( aName );
129 if ( pFilter )
130 return pFilter->GetRealTypeName();
134 return OUString();
137 // XServiceInfo
138 OUString SAL_CALL SdFilterDetect::getImplementationName()
140 return OUString( "com.sun.star.comp.draw.FormatDetector" );
143 // XServiceInfo
144 sal_Bool SAL_CALL SdFilterDetect::supportsService( const OUString& sServiceName )
146 return cppu::supportsService(this, sServiceName);
149 // XServiceInfo
150 Sequence< OUString > SAL_CALL SdFilterDetect::getSupportedServiceNames()
152 Sequence<OUString> seqServiceNames { "com.sun.star.frame.ExtendedTypeDetection" };
153 return seqServiceNames ;
157 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
158 com_sun_star_comp_draw_FormatDetector_get_implementation(css::uno::XComponentContext*,
159 css::uno::Sequence<css::uno::Any> const &)
161 return cppu::acquire(new SdFilterDetect());
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */