tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sd / source / ui / unoidl / sddetect.cxx
blobba1994708b1ecaa444571a8ba3af42cd10633b7f
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/beans/PropertyValue.hpp>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <com/sun/star/io/XInputStream.hpp>
25 #include <com/sun/star/ucb/ContentCreationException.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <vcl/graphicfilter.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <sfx2/docfilt.hxx>
30 #include <sfx2/fcontnr.hxx>
31 #include <vcl/FilterConfigItem.hxx>
32 #include <sot/storage.hxx>
33 #include <unotools/mediadescriptor.hxx>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::io;
38 using namespace ::com::sun::star::task;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::lang;
41 using utl::MediaDescriptor;
43 SdFilterDetect::SdFilterDetect()
47 SdFilterDetect::~SdFilterDetect()
51 OUString SAL_CALL SdFilterDetect::detect( Sequence< beans::PropertyValue >& lDescriptor )
53 MediaDescriptor aMediaDesc( lDescriptor );
54 OUString aTypeName = aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME, OUString() );
55 uno::Reference< io::XInputStream > xInStream ( aMediaDesc[MediaDescriptor::PROP_INPUTSTREAM], uno::UNO_QUERY );
56 if ( !xInStream.is() )
57 return OUString();
59 SfxMedium aMedium;
60 aMedium.UseInteractionHandler( false );
61 aMedium.setStreamToLoadFrom( xInStream, true );
63 SvStream *pInStrm = aMedium.GetInStream();
64 if ( !pInStrm || pInStrm->GetError() )
65 return OUString();
67 if ( aTypeName.startsWith( "impress_MS_PowerPoint_97" ) )
69 // Do not attempt to create an SotStorage on a
70 // 0-length stream as that would create the compound
71 // document header on the stream and effectively write to
72 // disk!
73 pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
74 if ( pInStrm->remainingSize() == 0 )
75 return OUString();
77 try
79 rtl::Reference<SotStorage> aStorage = new SotStorage(pInStrm, false);
80 if ( !aStorage->GetError() && aStorage->IsStream( u"PowerPoint Document"_ustr ) )
81 return aTypeName;
83 catch (const css::ucb::ContentCreationException&)
87 else
89 pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
91 const OUString aFileName( aMediaDesc.getUnpackedValueOrDefault( MediaDescriptor::PROP_URL, OUString() ) );
92 GraphicDescriptor aDesc( *pInStrm, &aFileName );
93 if( !aDesc.Detect() )
95 INetURLObject aCheckURL( aFileName );
96 if( aCheckURL.getExtension().equalsIgnoreAsciiCase("cgm") )
98 sal_uInt8 n8;
99 pInStrm->Seek( STREAM_SEEK_TO_BEGIN );
100 pInStrm->ReadUChar( n8 );
101 if ( ( n8 & 0xf0 ) == 0 )
102 // we are supporting binary cgm format only, so
103 // this is a small test to exclude cgm text
104 return u"impress_CGM_Computer_Graphics_Metafile"_ustr;
107 else
109 OUString aShortName( GraphicDescriptor::GetImportFormatShortName( aDesc.GetFileFormat() ) );
110 GraphicFilter &rGrfFilter = GraphicFilter::GetGraphicFilter();
111 const OUString aName( rGrfFilter.GetImportFormatTypeName( rGrfFilter.GetImportFormatNumberForShortName( aShortName ) ) );
113 if ( aShortName.equalsIgnoreAsciiCase( "PCD" ) ) // there is a multiple pcd selection possible
115 sal_Int32 nBase = 2; // default Base0
116 if ( aTypeName == "pcd_Photo_CD_Base4" )
117 nBase = 1;
118 else if ( aTypeName == "pcd_Photo_CD_Base16" )
119 nBase = 0;
120 FilterConfigItem aFilterConfigItem( u"Office.Common/Filter/Graphic/Import/PCD" );
121 aFilterConfigItem.WriteInt32( u"Resolution"_ustr , nBase );
124 SfxFilterMatcher aMatch(u"sdraw"_ustr);
125 std::shared_ptr<const SfxFilter> pFilter = aMatch.GetFilter4FilterName( aName );
126 if ( pFilter )
127 return pFilter->GetRealTypeName();
131 return OUString();
134 // XServiceInfo
135 OUString SAL_CALL SdFilterDetect::getImplementationName()
137 return u"com.sun.star.comp.draw.FormatDetector"_ustr;
140 // XServiceInfo
141 sal_Bool SAL_CALL SdFilterDetect::supportsService( const OUString& sServiceName )
143 return cppu::supportsService(this, sServiceName);
146 // XServiceInfo
147 Sequence< OUString > SAL_CALL SdFilterDetect::getSupportedServiceNames()
149 return { u"com.sun.star.frame.ExtendedTypeDetection"_ustr };
153 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
154 com_sun_star_comp_draw_FormatDetector_get_implementation(css::uno::XComponentContext*,
155 css::uno::Sequence<css::uno::Any> const &)
157 return cppu::acquire(new SdFilterDetect());
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */