1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sdext.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "configurationaccess.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace ::rtl; 40*cdf0e10cSrcweir using namespace ::com::sun::star; 41*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 42*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 43*cdf0e10cSrcweir using namespace ::com::sun::star::container; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir static const OUString& GetConfigurationProviderServiceName (void) 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir static const OUString sConfigurationProviderServiceName ( 48*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( 49*cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationProvider")); 50*cdf0e10cSrcweir return sConfigurationProviderServiceName; 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir static const OUString& GetPathToConfigurationRoot (void) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir static const OUString sPathToConfigurationRoot ( 55*cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.extension.SunPresentationMinimizer")); 56*cdf0e10cSrcweir return sPathToConfigurationRoot; 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir void OptimizerSettings::LoadSettingsFromConfiguration( const Reference< XNameAccess >& rSettings ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir if ( rSettings.is() ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir const Sequence< OUString > aElements( rSettings->getElementNames() ); 64*cdf0e10cSrcweir for ( int i = 0; i < aElements.getLength(); i++ ) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir try 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir const OUString aPropertyName( aElements[ i ] ); 69*cdf0e10cSrcweir Any aValue( rSettings->getByName( aPropertyName ) ); 70*cdf0e10cSrcweir switch( TKGet( aPropertyName ) ) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir case TK_Name : aValue >>= maName; break; 73*cdf0e10cSrcweir case TK_JPEGCompression : aValue >>= mbJPEGCompression; break; 74*cdf0e10cSrcweir case TK_JPEGQuality : aValue >>= mnJPEGQuality; break; 75*cdf0e10cSrcweir case TK_RemoveCropArea : aValue >>= mbRemoveCropArea; break; 76*cdf0e10cSrcweir case TK_ImageResolution : aValue >>= mnImageResolution; break; 77*cdf0e10cSrcweir case TK_EmbedLinkedGraphics : aValue >>= mbEmbedLinkedGraphics; break; 78*cdf0e10cSrcweir case TK_OLEOptimization : aValue >>= mbOLEOptimization; break; 79*cdf0e10cSrcweir case TK_OLEOptimizationType : aValue >>= mnOLEOptimizationType; break; 80*cdf0e10cSrcweir case TK_DeleteUnusedMasterPages : aValue >>= mbDeleteUnusedMasterPages; break; 81*cdf0e10cSrcweir case TK_DeleteHiddenSlides : aValue >>= mbDeleteHiddenSlides; break; 82*cdf0e10cSrcweir case TK_DeleteNotesPages : aValue >>= mbDeleteNotesPages ;break; 83*cdf0e10cSrcweir case TK_SaveAs : aValue >>= mbSaveAs; break; 84*cdf0e10cSrcweir // case TK_SaveAsURL : aValue >>= maSaveAsURL; break; // URL is not saved to configuration 85*cdf0e10cSrcweir // case TK_FilterName : aValue >>= maFilterName; break; // URL is not saved to configuration 86*cdf0e10cSrcweir case TK_OpenNewDocument : aValue >>= mbOpenNewDocument; break; 87*cdf0e10cSrcweir default: break; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir catch( Exception& ) 91*cdf0e10cSrcweir { 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir } 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir void OptimizerSettings::SaveSettingsToConfiguration( const Reference< XNameReplace >& rSettings ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir if ( rSettings.is() ) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir OUString pNames[] = { 102*cdf0e10cSrcweir TKGet( TK_Name ), 103*cdf0e10cSrcweir TKGet( TK_JPEGCompression ), 104*cdf0e10cSrcweir TKGet( TK_JPEGQuality ), 105*cdf0e10cSrcweir TKGet( TK_RemoveCropArea ), 106*cdf0e10cSrcweir TKGet( TK_ImageResolution ), 107*cdf0e10cSrcweir TKGet( TK_EmbedLinkedGraphics ), 108*cdf0e10cSrcweir TKGet( TK_OLEOptimization ), 109*cdf0e10cSrcweir TKGet( TK_OLEOptimizationType ), 110*cdf0e10cSrcweir TKGet( TK_DeleteUnusedMasterPages ), 111*cdf0e10cSrcweir TKGet( TK_DeleteHiddenSlides ), 112*cdf0e10cSrcweir TKGet( TK_DeleteNotesPages ), 113*cdf0e10cSrcweir TKGet( TK_SaveAs ), 114*cdf0e10cSrcweir // TKGet( TK_SaveAsURL ), 115*cdf0e10cSrcweir // TKGet( TK_FilterName ), 116*cdf0e10cSrcweir TKGet( TK_OpenNewDocument ) }; 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir Any pValues[] = { 119*cdf0e10cSrcweir Any( maName ), 120*cdf0e10cSrcweir Any( mbJPEGCompression ), 121*cdf0e10cSrcweir Any( mnJPEGQuality ), 122*cdf0e10cSrcweir Any( mbRemoveCropArea ), 123*cdf0e10cSrcweir Any( mnImageResolution ), 124*cdf0e10cSrcweir Any( mbEmbedLinkedGraphics ), 125*cdf0e10cSrcweir Any( mbOLEOptimization ), 126*cdf0e10cSrcweir Any( mnOLEOptimizationType ), 127*cdf0e10cSrcweir Any( mbDeleteUnusedMasterPages ), 128*cdf0e10cSrcweir Any( mbDeleteHiddenSlides ), 129*cdf0e10cSrcweir Any( mbDeleteNotesPages ), 130*cdf0e10cSrcweir Any( mbSaveAs ), 131*cdf0e10cSrcweir // Any( maSaveAsURL ), 132*cdf0e10cSrcweir // Any( maFilterName ), 133*cdf0e10cSrcweir Any( mbOpenNewDocument ) }; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir sal_Int32 i, nCount = sizeof( pNames ) / sizeof( OUString ); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir for ( i = 0; i < nCount; i++ ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir try 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir rSettings->replaceByName( pNames[ i ], pValues[ i ] ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir catch( Exception& /* rException */ ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir sal_Bool OptimizerSettings::operator==( const OptimizerSettings& rOptimizerSettings ) const 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir return ( rOptimizerSettings.mbJPEGCompression == mbJPEGCompression ) 153*cdf0e10cSrcweir && ( rOptimizerSettings.mnJPEGQuality == mnJPEGQuality ) 154*cdf0e10cSrcweir && ( rOptimizerSettings.mbRemoveCropArea == mbRemoveCropArea ) 155*cdf0e10cSrcweir && ( rOptimizerSettings.mnImageResolution == mnImageResolution ) 156*cdf0e10cSrcweir && ( rOptimizerSettings.mbEmbedLinkedGraphics == mbEmbedLinkedGraphics ) 157*cdf0e10cSrcweir && ( rOptimizerSettings.mbOLEOptimization == mbOLEOptimization ) 158*cdf0e10cSrcweir && ( rOptimizerSettings.mnOLEOptimizationType == mnOLEOptimizationType ) 159*cdf0e10cSrcweir && ( rOptimizerSettings.mbDeleteUnusedMasterPages == mbDeleteUnusedMasterPages ) 160*cdf0e10cSrcweir && ( rOptimizerSettings.mbDeleteHiddenSlides == mbDeleteHiddenSlides ) 161*cdf0e10cSrcweir && ( rOptimizerSettings.mbDeleteNotesPages == mbDeleteNotesPages ); 162*cdf0e10cSrcweir // && ( rOptimizerSettings.mbOpenNewDocument == mbOpenNewDocument ); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir ConfigurationAccess::ConfigurationAccess( const Reference< uno::XComponentContext >& rxMSF, OptimizerSettings* pDefaultSettings ) : 167*cdf0e10cSrcweir mxMSF( rxMSF ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir LoadStrings(); 170*cdf0e10cSrcweir maSettings.push_back( pDefaultSettings ? 171*cdf0e10cSrcweir *pDefaultSettings : OptimizerSettings() ); 172*cdf0e10cSrcweir maSettings.back().maName = TKGet( TK_LastUsedSettings ); 173*cdf0e10cSrcweir LoadConfiguration(); 174*cdf0e10cSrcweir maInitialSettings = maSettings; 175*cdf0e10cSrcweir }; 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir ConfigurationAccess::~ConfigurationAccess() 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir rtl::OUString ConfigurationAccess::getPath( const PPPOptimizerTokenEnum eToken ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir rtl::OUString aPath; 184*cdf0e10cSrcweir try 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir static const OUString sProtocol( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.expand:" ) ); 187*cdf0e10cSrcweir static const OUString stheMacroExpander( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander" ) ); 188*cdf0e10cSrcweir Reference< container::XNameAccess > xSet( OpenConfiguration( true ), UNO_QUERY_THROW ); 189*cdf0e10cSrcweir if ( xSet->hasByName( TKGet( eToken ) ) ) 190*cdf0e10cSrcweir xSet->getByName( TKGet( eToken ) ) >>= aPath; 191*cdf0e10cSrcweir if ( aPath.match( sProtocol, 0 ) ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir rtl::OUString aTmp( aPath.copy( 20 ) ); 194*cdf0e10cSrcweir Reference< util::XMacroExpander > xExpander; 195*cdf0e10cSrcweir if ( mxMSF->getValueByName( stheMacroExpander ) >>= xExpander ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir aPath = xExpander->expandMacros( aTmp ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir catch ( Exception& ) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir return aPath; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir rtl::OUString ConfigurationAccess::getString( const PPPOptimizerTokenEnum eToken ) const 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir std::map< PPPOptimizerTokenEnum, rtl::OUString, Compare >::const_iterator aIter( maStrings.find( eToken ) ); 210*cdf0e10cSrcweir return aIter != maStrings.end() ? ((*aIter).second) : rtl::OUString(); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir void ConfigurationAccess::LoadStrings() 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir try 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir do 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir Reference< XInterface > xRoot( OpenConfiguration( true ) ); 220*cdf0e10cSrcweir if ( !xRoot.is() ) 221*cdf0e10cSrcweir break; 222*cdf0e10cSrcweir Reference< container::XNameAccess > xSet( GetConfigurationNode( xRoot, TKGet( TK_Strings ) ), UNO_QUERY ); 223*cdf0e10cSrcweir if ( xSet.is() ) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir const Sequence< OUString > aElements( xSet->getElementNames() ); 226*cdf0e10cSrcweir for ( int i = 0; i < aElements.getLength(); i++ ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir try 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir OUString aString, aPropertyName( aElements[ i ] ); 231*cdf0e10cSrcweir if ( xSet->getByName( aPropertyName ) >>= aString ) 232*cdf0e10cSrcweir maStrings[ TKGet( aPropertyName ) ] = aString; 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir catch( Exception& ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir while( false ); 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir catch( Exception& ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir void ConfigurationAccess::LoadConfiguration() 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir try 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir do 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir Reference< XInterface > xRoot( OpenConfiguration( true ) ); 254*cdf0e10cSrcweir if ( !xRoot.is() ) 255*cdf0e10cSrcweir break; 256*cdf0e10cSrcweir Reference< container::XNameAccess > xSet( GetConfigurationNode( xRoot, TKGet( TK_LastUsedSettings ) ), UNO_QUERY ); 257*cdf0e10cSrcweir if ( xSet.is() ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir OptimizerSettings& rCurrent( maSettings.front() ); 260*cdf0e10cSrcweir rCurrent.LoadSettingsFromConfiguration( xSet ); 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir xSet = Reference< container::XNameAccess >( GetConfigurationNode( xRoot, TKGet( TK_Settings_Templates ) ), UNO_QUERY ); 263*cdf0e10cSrcweir if ( xSet.is() ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir const Sequence< OUString > aElements( xSet->getElementNames() ); 266*cdf0e10cSrcweir for ( int i = 0; i < aElements.getLength(); i++ ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir try 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir OUString aPath( TKGet( TK_Settings_Templates_ ).concat( aElements[ i ] ) ); 271*cdf0e10cSrcweir Reference< container::XNameAccess > xTemplates( GetConfigurationNode( xRoot, aPath ), UNO_QUERY ); 272*cdf0e10cSrcweir if ( xTemplates.is() ) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir maSettings.push_back( OptimizerSettings() ); 275*cdf0e10cSrcweir maSettings.back().LoadSettingsFromConfiguration( xTemplates ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir catch( Exception& /* rException */ ) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir while( false ); 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir catch( Exception& ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir void ConfigurationAccess::SaveConfiguration() 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir try 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir do 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir int i; 298*cdf0e10cSrcweir unsigned int k; 299*cdf0e10cSrcweir Reference<util::XChangesBatch> xRoot( OpenConfiguration( false ), UNO_QUERY_THROW ); 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir // storing the last used settings 302*cdf0e10cSrcweir Reference< container::XNameReplace > xSet( GetConfigurationNode( xRoot, TKGet( TK_LastUsedSettings ) ), UNO_QUERY_THROW ); 303*cdf0e10cSrcweir OptimizerSettings& rCurrent( maSettings.front() ); 304*cdf0e10cSrcweir rCurrent.SaveSettingsToConfiguration( xSet ); 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir // updating template elements 307*cdf0e10cSrcweir xSet = Reference< container::XNameReplace >( GetConfigurationNode( xRoot, TKGet( TK_Settings_Templates ) ), UNO_QUERY_THROW ); 308*cdf0e10cSrcweir Reference< container::XNameContainer > xNameContainer( xSet, UNO_QUERY_THROW ); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir const Sequence< OUString > aElements( xSet->getElementNames() ); 311*cdf0e10cSrcweir for( i = 0; i < aElements.getLength(); i++ ) 312*cdf0e10cSrcweir xNameContainer->removeByName( aElements[ i ] ); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir for( k = 1; k < maSettings.size(); k++ ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir OptimizerSettings& rSettings( maSettings[ k ] ); 317*cdf0e10cSrcweir OUString aElementName( TKGet( TK_Template ).concat( OUString::valueOf( static_cast< sal_Int32 >( k ) ) ) ); 318*cdf0e10cSrcweir Reference< lang::XSingleServiceFactory > xChildFactory ( xSet, UNO_QUERY_THROW ); 319*cdf0e10cSrcweir Reference< container::XNameReplace > xChild( xChildFactory->createInstance(), UNO_QUERY_THROW ); 320*cdf0e10cSrcweir xNameContainer->insertByName( aElementName, Any( xChild ) ); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir OUString aPath( TKGet( TK_Settings_Templates_ ).concat( aElementName ) ); 323*cdf0e10cSrcweir Reference< container::XNameReplace > xTemplates( GetConfigurationNode( xRoot, aPath ), UNO_QUERY ); 324*cdf0e10cSrcweir rSettings.SaveSettingsToConfiguration( xTemplates ); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir xRoot->commitChanges(); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir while( false ); 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir catch( Exception& /* rException */ ) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir Reference< XInterface > ConfigurationAccess::OpenConfiguration( bool bReadOnly ) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir Reference< XInterface > xRoot; 339*cdf0e10cSrcweir try 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > xProvider( mxMSF->getServiceManager()->createInstanceWithContext( GetConfigurationProviderServiceName(), mxMSF ), UNO_QUERY ); 342*cdf0e10cSrcweir if ( xProvider.is() ) 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir Sequence< Any > aCreationArguments( 2 ); 345*cdf0e10cSrcweir aCreationArguments[0] = makeAny( PropertyValue( 346*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ), 0, 347*cdf0e10cSrcweir makeAny( GetPathToConfigurationRoot() ), 348*cdf0e10cSrcweir PropertyState_DIRECT_VALUE ) ); 349*cdf0e10cSrcweir aCreationArguments[1] = makeAny(beans::PropertyValue( 350*cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "lazywrite" ) ), 0, makeAny( true ), 351*cdf0e10cSrcweir PropertyState_DIRECT_VALUE ) ); 352*cdf0e10cSrcweir OUString sAccessService; 353*cdf0e10cSrcweir if ( bReadOnly ) 354*cdf0e10cSrcweir sAccessService = OUString( RTL_CONSTASCII_USTRINGPARAM( 355*cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationAccess" ) ); 356*cdf0e10cSrcweir else 357*cdf0e10cSrcweir sAccessService = OUString( RTL_CONSTASCII_USTRINGPARAM( 358*cdf0e10cSrcweir "com.sun.star.configuration.ConfigurationUpdateAccess" ) ); 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir xRoot = xProvider->createInstanceWithArguments( 361*cdf0e10cSrcweir sAccessService, aCreationArguments ); 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir catch ( Exception& /* rException */ ) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir return xRoot; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir Reference< XInterface > ConfigurationAccess::GetConfigurationNode( 371*cdf0e10cSrcweir const Reference< XInterface >& xRoot, 372*cdf0e10cSrcweir const OUString& sPathToNode ) 373*cdf0e10cSrcweir { 374*cdf0e10cSrcweir Reference< XInterface > xNode; 375*cdf0e10cSrcweir try 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir if ( !sPathToNode.getLength() ) 378*cdf0e10cSrcweir xNode = xRoot; 379*cdf0e10cSrcweir else 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir Reference< XHierarchicalNameAccess > xHierarchy( xRoot, UNO_QUERY ); 382*cdf0e10cSrcweir if ( xHierarchy.is() ) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir xHierarchy->getByHierarchicalName( sPathToNode ) >>= xNode; 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir catch ( Exception& rException ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir OSL_TRACE ("caught exception while getting configuration node %s: %s", 391*cdf0e10cSrcweir ::rtl::OUStringToOString(sPathToNode, 392*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8).getStr(), 393*cdf0e10cSrcweir ::rtl::OUStringToOString(rException.Message, 394*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8).getStr()); 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir return xNode; 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir com::sun::star::uno::Any ConfigurationAccess::GetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken ) const 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir Any aRetValue; 402*cdf0e10cSrcweir const OptimizerSettings& rSettings( maSettings.front() ); 403*cdf0e10cSrcweir try 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir switch( ePropertyToken ) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir case TK_Name : aRetValue <<= rSettings.maName; break; 408*cdf0e10cSrcweir case TK_JPEGCompression : aRetValue <<= rSettings.mbJPEGCompression; break; 409*cdf0e10cSrcweir case TK_JPEGQuality : aRetValue <<= rSettings.mnJPEGQuality; break; 410*cdf0e10cSrcweir case TK_RemoveCropArea : aRetValue <<= rSettings.mbRemoveCropArea; break; 411*cdf0e10cSrcweir case TK_ImageResolution : aRetValue <<= rSettings.mnImageResolution; break; 412*cdf0e10cSrcweir case TK_EmbedLinkedGraphics : aRetValue <<= rSettings.mbEmbedLinkedGraphics; break; 413*cdf0e10cSrcweir case TK_OLEOptimization : aRetValue <<= rSettings.mbOLEOptimization; break; 414*cdf0e10cSrcweir case TK_OLEOptimizationType : aRetValue <<= rSettings.mnOLEOptimizationType; break; 415*cdf0e10cSrcweir case TK_DeleteUnusedMasterPages : aRetValue <<= rSettings.mbDeleteUnusedMasterPages; break; 416*cdf0e10cSrcweir case TK_DeleteHiddenSlides : aRetValue <<= rSettings.mbDeleteHiddenSlides; break; 417*cdf0e10cSrcweir case TK_DeleteNotesPages : aRetValue <<= rSettings.mbDeleteNotesPages; break; 418*cdf0e10cSrcweir case TK_SaveAs : aRetValue <<= rSettings.mbSaveAs; break; 419*cdf0e10cSrcweir case TK_SaveAsURL : aRetValue <<= rSettings.maSaveAsURL; break; 420*cdf0e10cSrcweir case TK_FilterName : aRetValue <<= rSettings.maFilterName; break; 421*cdf0e10cSrcweir case TK_OpenNewDocument : aRetValue <<= rSettings.mbOpenNewDocument; break; 422*cdf0e10cSrcweir case TK_EstimatedFileSize : aRetValue <<= rSettings.mnEstimatedFileSize; break; 423*cdf0e10cSrcweir default: 424*cdf0e10cSrcweir break; 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir catch( Exception& /* rException */ ) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir return aRetValue; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir void ConfigurationAccess::SetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken, const com::sun::star::uno::Any& rValue ) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir OptimizerSettings& rSettings( maSettings.front() ); 436*cdf0e10cSrcweir try 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir switch( ePropertyToken ) 439*cdf0e10cSrcweir { 440*cdf0e10cSrcweir case TK_Name : rValue >>= rSettings.maName; break; 441*cdf0e10cSrcweir case TK_JPEGCompression : rValue >>= rSettings.mbJPEGCompression; break; 442*cdf0e10cSrcweir case TK_JPEGQuality : rValue >>= rSettings.mnJPEGQuality; break; 443*cdf0e10cSrcweir case TK_RemoveCropArea : rValue >>= rSettings.mbRemoveCropArea; break; 444*cdf0e10cSrcweir case TK_ImageResolution : rValue >>= rSettings.mnImageResolution; break; 445*cdf0e10cSrcweir case TK_EmbedLinkedGraphics : rValue >>= rSettings.mbEmbedLinkedGraphics; break; 446*cdf0e10cSrcweir case TK_OLEOptimization : rValue >>= rSettings.mbOLEOptimization; break; 447*cdf0e10cSrcweir case TK_OLEOptimizationType : rValue >>= rSettings.mnOLEOptimizationType; break; 448*cdf0e10cSrcweir case TK_DeleteUnusedMasterPages : rValue >>= rSettings.mbDeleteUnusedMasterPages; break; 449*cdf0e10cSrcweir case TK_DeleteHiddenSlides : rValue >>= rSettings.mbDeleteHiddenSlides; break; 450*cdf0e10cSrcweir case TK_DeleteNotesPages : rValue >>= rSettings.mbDeleteNotesPages; break; 451*cdf0e10cSrcweir case TK_CustomShowName : rValue >>= rSettings.maCustomShowName; break; 452*cdf0e10cSrcweir case TK_SaveAs : rValue >>= rSettings.mbSaveAs; break; 453*cdf0e10cSrcweir case TK_SaveAsURL : rValue >>= rSettings.maSaveAsURL; break; 454*cdf0e10cSrcweir case TK_FilterName : rValue >>= rSettings.maFilterName; break; 455*cdf0e10cSrcweir case TK_OpenNewDocument : rValue >>= rSettings.mbOpenNewDocument; break; 456*cdf0e10cSrcweir case TK_EstimatedFileSize : rValue >>= rSettings.mnEstimatedFileSize; break; 457*cdf0e10cSrcweir default: 458*cdf0e10cSrcweir break; 459*cdf0e10cSrcweir } 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir catch( Exception& /* rException */ ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir sal_Bool ConfigurationAccess::GetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken, const sal_Bool bDefault ) const 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir sal_Bool bRetValue = bDefault; 469*cdf0e10cSrcweir if ( ! ( GetConfigProperty( ePropertyToken ) >>= bRetValue ) ) 470*cdf0e10cSrcweir bRetValue = bDefault; 471*cdf0e10cSrcweir return bRetValue; 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir sal_Int16 ConfigurationAccess::GetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken, const sal_Int16 nDefault ) const 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir sal_Int16 nRetValue = nDefault; 477*cdf0e10cSrcweir if ( ! ( GetConfigProperty( ePropertyToken ) >>= nRetValue ) ) 478*cdf0e10cSrcweir nRetValue = nDefault; 479*cdf0e10cSrcweir return nRetValue; 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir sal_Int32 ConfigurationAccess::GetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken, const sal_Int32 nDefault ) const 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir sal_Int32 nRetValue = nDefault; 485*cdf0e10cSrcweir if ( ! ( GetConfigProperty( ePropertyToken ) >>= nRetValue ) ) 486*cdf0e10cSrcweir nRetValue = nDefault; 487*cdf0e10cSrcweir return nRetValue; 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir Sequence< PropertyValue > ConfigurationAccess::GetConfigurationSequence() 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir Sequence< PropertyValue > aRet( 15 ); 493*cdf0e10cSrcweir OptimizerSettings& rSettings( maSettings.front() ); 494*cdf0e10cSrcweir aRet[ 0 ].Name = TKGet( TK_JPEGCompression ); 495*cdf0e10cSrcweir aRet[ 0 ].Value= Any( rSettings.mbJPEGCompression ); 496*cdf0e10cSrcweir aRet[ 1 ].Name = TKGet( TK_JPEGQuality ); 497*cdf0e10cSrcweir aRet[ 1 ].Value= Any( rSettings.mnJPEGQuality ); 498*cdf0e10cSrcweir aRet[ 2 ].Name = TKGet( TK_RemoveCropArea ); 499*cdf0e10cSrcweir aRet[ 2 ].Value= Any( rSettings.mbRemoveCropArea ); 500*cdf0e10cSrcweir aRet[ 3 ].Name = TKGet( TK_ImageResolution ); 501*cdf0e10cSrcweir aRet[ 3 ].Value= Any( rSettings.mnImageResolution ); 502*cdf0e10cSrcweir aRet[ 4 ].Name = TKGet( TK_EmbedLinkedGraphics ); 503*cdf0e10cSrcweir aRet[ 4 ].Value= Any( rSettings.mbEmbedLinkedGraphics ); 504*cdf0e10cSrcweir aRet[ 5 ].Name = TKGet( TK_OLEOptimization ); 505*cdf0e10cSrcweir aRet[ 5 ].Value= Any( rSettings.mbOLEOptimization ); 506*cdf0e10cSrcweir aRet[ 6 ].Name = TKGet( TK_OLEOptimizationType ); 507*cdf0e10cSrcweir aRet[ 6 ].Value= Any( rSettings.mnOLEOptimizationType ); 508*cdf0e10cSrcweir aRet[ 7 ].Name = TKGet( TK_DeleteUnusedMasterPages ); 509*cdf0e10cSrcweir aRet[ 7 ].Value= Any( rSettings.mbDeleteUnusedMasterPages ); 510*cdf0e10cSrcweir aRet[ 8 ].Name = TKGet( TK_DeleteHiddenSlides ); 511*cdf0e10cSrcweir aRet[ 8 ].Value= Any( rSettings.mbDeleteHiddenSlides ); 512*cdf0e10cSrcweir aRet[ 9 ].Name = TKGet( TK_DeleteNotesPages ); 513*cdf0e10cSrcweir aRet[ 9 ].Value= Any( rSettings.mbDeleteNotesPages ); 514*cdf0e10cSrcweir aRet[ 10].Name = TKGet( TK_CustomShowName ); 515*cdf0e10cSrcweir aRet[ 10].Value= Any( rSettings.maCustomShowName ); 516*cdf0e10cSrcweir aRet[ 11].Name = TKGet( TK_SaveAsURL ); 517*cdf0e10cSrcweir aRet[ 11].Value= Any( rSettings.maSaveAsURL ); 518*cdf0e10cSrcweir aRet[ 12].Name = TKGet( TK_FilterName ); 519*cdf0e10cSrcweir aRet[ 12].Value= Any( rSettings.maFilterName ); 520*cdf0e10cSrcweir aRet[ 13].Name = TKGet( TK_OpenNewDocument ); 521*cdf0e10cSrcweir aRet[ 13].Value= Any( rSettings.mbOpenNewDocument ); 522*cdf0e10cSrcweir aRet[ 14].Name = TKGet( TK_EstimatedFileSize ); 523*cdf0e10cSrcweir aRet[ 14].Value= Any( rSettings.mnEstimatedFileSize ); 524*cdf0e10cSrcweir return aRet; 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir std::vector< OptimizerSettings >::iterator ConfigurationAccess::GetOptimizerSettingsByName( const rtl::OUString& rName ) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir std::vector< OptimizerSettings >::iterator aIter( maSettings.begin() + 1 ); 530*cdf0e10cSrcweir while ( aIter != maSettings.end() ) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir if ( aIter->maName == rName ) 533*cdf0e10cSrcweir break; 534*cdf0e10cSrcweir aIter++; 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir return aIter; 537*cdf0e10cSrcweir } 538