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