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

Generated by: LCOV version 1.10