LCOV - code coverage report
Current view: top level - svtools/source/filter - SvFilterOptionsDialog.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 96 1.0 %
Date: 2014-04-11 Functions: 2 17 11.8 %
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             : 
      21             : #include <vcl/FilterConfigItem.hxx>
      22             : #include <vcl/graphicfilter.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <osl/file.hxx>
      25             : #include <osl/module.hxx>
      26             : #include <rtl/ref.hxx>
      27             : #include <svl/solar.hrc>
      28             : #include <vcl/fltcall.hxx>
      29             : #include <vcl/settings.hxx>
      30             : #include "exportdialog.hxx"
      31             : #include <uno/mapping.hxx>
      32             : #include <tools/fldunit.hxx>
      33             : #include <com/sun/star/frame/XModel.hpp>
      34             : #include <com/sun/star/beans/XPropertyAccess.hpp>
      35             : #include <com/sun/star/document/XExporter.hpp>
      36             : #include <com/sun/star/document/XViewDataSupplier.hpp>
      37             : #include <com/sun/star/container/XIndexAccess.hpp>
      38             : #include <com/sun/star/lang/XInitialization.hpp>
      39             : #include <com/sun/star/lang/XServiceInfo.hpp>
      40             : #include <com/sun/star/uno/Sequence.h>
      41             : #include <com/sun/star/uno/Any.h>
      42             : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      43             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      44             : #include <com/sun/star/uno/XComponentContext.hpp>
      45             : #include <unotools/syslocale.hxx>
      46             : #include <comphelper/processfactory.hxx>
      47             : #include <cppuhelper/implbase5.hxx>
      48             : #include <cppuhelper/supportsservice.hxx>
      49             : 
      50             : using namespace ::com::sun::star;
      51             : 
      52             : namespace {
      53             : 
      54             : class SvFilterOptionsDialog : public cppu::WeakImplHelper5
      55             : <
      56             :     document::XExporter,
      57             :     ui::dialogs::XExecutableDialog,
      58             :     beans::XPropertyAccess,
      59             :     lang::XInitialization,
      60             :     lang::XServiceInfo
      61             : >
      62             : {
      63             :     const uno::Reference< uno::XComponentContext >
      64             :         mxContext;
      65             :     uno::Sequence< beans::PropertyValue >
      66             :         maMediaDescriptor;
      67             :     uno::Sequence< beans::PropertyValue >
      68             :         maFilterDataSequence;
      69             :     uno::Reference< lang::XComponent >
      70             :         mxSourceDocument;
      71             : 
      72             :     OUString        maDialogTitle;
      73             :     FieldUnit       meFieldUnit;
      74             :     sal_Bool        mbExportSelection;
      75             : 
      76             : public:
      77             : 
      78             :     SvFilterOptionsDialog( const uno::Reference< uno::XComponentContext >& _rxORB );
      79             :     virtual ~SvFilterOptionsDialog();
      80             : 
      81             :     // XInterface
      82             :     virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
      83             :     virtual void SAL_CALL release() throw() SAL_OVERRIDE;
      84             : 
      85             :     // XInitialization
      86             :     virtual void SAL_CALL initialize( const uno::Sequence< uno::Any > & aArguments )
      87             :         throw ( uno::Exception, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      88             : 
      89             :     // XServiceInfo
      90             :     virtual OUString SAL_CALL getImplementationName()
      91             :         throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      92             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
      93             :         throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      94             :     virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
      95             :         throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
      96             : 
      97             :     // XPropertyAccess
      98             :     virtual uno::Sequence< beans::PropertyValue > SAL_CALL getPropertyValues()
      99             :         throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     100             :     virtual void SAL_CALL setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps )
     101             :         throw ( beans::UnknownPropertyException, beans::PropertyVetoException,
     102             :                 lang::IllegalArgumentException, lang::WrappedTargetException,
     103             :                 uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     104             : 
     105             :     // XExecuteDialog
     106             :     virtual sal_Int16 SAL_CALL execute()
     107             :         throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     108             :     virtual void SAL_CALL setTitle( const OUString& aTitle )
     109             :         throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     110             : 
     111             :     // XExporter
     112             :     virtual void SAL_CALL setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
     113             :         throw ( lang::IllegalArgumentException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     114             : 
     115             : };
     116             : 
     117           0 : SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference< uno::XComponentContext >& rxContext ) :
     118             :     mxContext           ( rxContext ),
     119             :     meFieldUnit         ( FUNIT_CM ),
     120           0 :     mbExportSelection   ( sal_False )
     121             : {
     122           0 : }
     123             : 
     124             : 
     125             : 
     126           0 : SvFilterOptionsDialog::~SvFilterOptionsDialog()
     127             : {
     128           0 : }
     129             : 
     130             : 
     131             : 
     132           0 : void SAL_CALL SvFilterOptionsDialog::acquire() throw()
     133             : {
     134           0 :     OWeakObject::acquire();
     135           0 : }
     136             : 
     137             : 
     138             : 
     139           0 : void SAL_CALL SvFilterOptionsDialog::release() throw()
     140             : {
     141           0 :     OWeakObject::release();
     142           0 : }
     143             : 
     144             : // XInitialization
     145           0 : void SAL_CALL SvFilterOptionsDialog::initialize( const uno::Sequence< uno::Any > & )
     146             :     throw ( uno::Exception, uno::RuntimeException, std::exception )
     147             : {
     148           0 : }
     149             : 
     150             : // XServiceInfo
     151           0 : OUString SAL_CALL SvFilterOptionsDialog::getImplementationName()
     152             :     throw( uno::RuntimeException, std::exception )
     153             : {
     154           0 :     return OUString( "com.sun.star.svtools.SvFilterOptionsDialog" );
     155             : }
     156           0 : sal_Bool SAL_CALL SvFilterOptionsDialog::supportsService( const OUString& rServiceName )
     157             :     throw( uno::RuntimeException, std::exception )
     158             : {
     159           0 :     return cppu::supportsService(this, rServiceName);
     160             : }
     161           0 : uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNames()
     162             :     throw ( uno::RuntimeException, std::exception )
     163             : {
     164           0 :     uno::Sequence< OUString > aRet(1);
     165           0 :     OUString* pArray = aRet.getArray();
     166           0 :     pArray[0] = OUString("com.sun.star.ui.dialog.FilterOptionsDialog");
     167           0 :     return aRet;
     168             : }
     169             : 
     170             : // XPropertyAccess
     171           0 : uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues()
     172             :         throw ( uno::RuntimeException, std::exception )
     173             : {
     174             :     sal_Int32 i, nCount;
     175           0 :     for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
     176             :     {
     177           0 :         if ( maMediaDescriptor[ i ].Name == "FilterData" )
     178           0 :             break;
     179             :     }
     180           0 :     if ( i == nCount )
     181           0 :         maMediaDescriptor.realloc( ++nCount );
     182             : 
     183             :     // the "FilterData" Property is an Any that will contain our PropertySequence of Values
     184           0 :     maMediaDescriptor[ i ].Name = "FilterData";
     185           0 :     maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
     186           0 :     return maMediaDescriptor;
     187             : }
     188             : 
     189           0 : void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps )
     190             :         throw ( beans::UnknownPropertyException, beans::PropertyVetoException,
     191             :                 lang::IllegalArgumentException, lang::WrappedTargetException,
     192             :                 uno::RuntimeException, std::exception )
     193             : {
     194           0 :     maMediaDescriptor = aProps;
     195             : 
     196             :     sal_Int32 i, nCount;
     197           0 :     for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
     198             :     {
     199           0 :         if ( maMediaDescriptor[ i ].Name == "FilterData" )
     200             :         {
     201           0 :             maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
     202             :         }
     203           0 :         else if ( maMediaDescriptor[ i ].Name == "SelectionOnly" )
     204             :         {
     205           0 :             maMediaDescriptor[ i ].Value >>= mbExportSelection;
     206             :         }
     207             :     }
     208           0 : }
     209             : 
     210             : // XExecutableDialog
     211           0 : void SvFilterOptionsDialog::setTitle( const OUString& aTitle )
     212             :     throw ( uno::RuntimeException, std::exception )
     213             : {
     214           0 :     maDialogTitle = aTitle;
     215           0 : }
     216             : 
     217           0 : sal_Int16 SvFilterOptionsDialog::execute()
     218             :     throw ( uno::RuntimeException, std::exception )
     219             : {
     220           0 :     sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
     221             : 
     222           0 :     OUString aFilterNameStr( "FilterName" );
     223           0 :     OUString aInternalFilterName;
     224           0 :     sal_Int32 j, nCount = maMediaDescriptor.getLength();
     225           0 :     for ( j = 0; j < nCount; j++ )
     226             :     {
     227           0 :         if ( maMediaDescriptor[ j ].Name.equals( aFilterNameStr ) )
     228             :         {
     229           0 :             OUString aStr;
     230           0 :             maMediaDescriptor[ j ].Value >>= aStr;
     231           0 :             aInternalFilterName = aStr;
     232           0 :             aInternalFilterName = aInternalFilterName.replaceAll( "draw_", "" );
     233           0 :             aInternalFilterName = aInternalFilterName.replaceAll( "impress_", "" );
     234           0 :             break;
     235             :        }
     236             :     }
     237           0 :     if ( !aInternalFilterName.isEmpty() )
     238             :     {
     239           0 :         GraphicFilter aGraphicFilter( true );
     240             : 
     241           0 :         sal_uInt16 nFormat, nFilterCount = aGraphicFilter.GetExportFormatCount();
     242           0 :         for ( nFormat = 0; nFormat < nFilterCount; nFormat++ )
     243             :         {
     244           0 :             if ( aGraphicFilter.GetExportInternalFilterName( nFormat ) == aInternalFilterName )
     245           0 :                 break;
     246             :         }
     247           0 :         if ( nFormat < nFilterCount )
     248             :         {
     249           0 :             FltCallDialogParameter aFltCallDlgPara( Application::GetDefDialogParent(), NULL, meFieldUnit );
     250           0 :             aFltCallDlgPara.aFilterData = maFilterDataSequence;
     251             : 
     252             :             ResMgr*     pResMgr;
     253             : 
     254           0 :             pResMgr = ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() );
     255           0 :             aFltCallDlgPara.pResMgr = pResMgr;
     256             : 
     257           0 :             aFltCallDlgPara.aFilterExt = aGraphicFilter.GetExportFormatShortName( nFormat );
     258           0 :             sal_Bool bIsPixelFormat( aGraphicFilter.IsExportPixelFormat( nFormat ) );
     259           0 :             if ( ExportDialog( aFltCallDlgPara, mxContext, mxSourceDocument, mbExportSelection, bIsPixelFormat ).Execute() == RET_OK )
     260           0 :                 nRet = ui::dialogs::ExecutableDialogResults::OK;
     261             : 
     262           0 :             delete pResMgr;
     263             : 
     264             :             // taking the out parameter from the dialog
     265           0 :             maFilterDataSequence = aFltCallDlgPara.aFilterData;
     266           0 :         }
     267             :     }
     268           0 :     return nRet;
     269             : }
     270             : 
     271             : // XEmporter
     272           0 : void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
     273             :         throw ( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
     274             : {
     275           0 :     mxSourceDocument = xDoc;
     276             : 
     277             :     // try to set the corresponding metric unit
     278           0 :     OUString aConfigPath;
     279             :     uno::Reference< lang::XServiceInfo > xServiceInfo
     280           0 :             ( xDoc, uno::UNO_QUERY );
     281           0 :     if ( xServiceInfo.is() )
     282             :     {
     283           0 :         if ( xServiceInfo->supportsService("com.sun.star.presentation.PresentationDocument") )
     284           0 :             aConfigPath = "Office.Impress/Layout/Other/MeasureUnit";
     285           0 :         else if ( xServiceInfo->supportsService("com.sun.star.drawing.DrawingDocument") )
     286           0 :             aConfigPath = "Office.Draw/Layout/Other/MeasureUnit";
     287           0 :         if ( !aConfigPath.isEmpty() )
     288             :         {
     289           0 :             FilterConfigItem aConfigItem( aConfigPath );
     290           0 :             OUString aPropertyName;
     291           0 :             SvtSysLocale aSysLocale;
     292           0 :             if ( aSysLocale.GetLocaleDataPtr()->getMeasurementSystemEnum() == MEASURE_METRIC )
     293           0 :                 aPropertyName = "Metric";
     294             :             else
     295           0 :                 aPropertyName = "NonMetric";
     296           0 :             meFieldUnit = (FieldUnit)aConfigItem.ReadInt32( aPropertyName, FUNIT_CM );
     297             :         }
     298           0 :     }
     299           0 : }
     300             : 
     301             : }
     302             : 
     303             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     304           0 : com_sun_star_svtools_SvFilterOptionsDialog_get_implementation(
     305             :     css::uno::XComponentContext * context,
     306             :     css::uno::Sequence<css::uno::Any> const &)
     307             : {
     308           0 :     return cppu::acquire(new SvFilterOptionsDialog(context));
     309         513 : }
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10