configurationaccess.cxx (880c69c6) | configurationaccess.cxx (597a4c59) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 17 unchanged lines hidden (view full) --- 26 27#include "configurationaccess.hxx" 28#include <com/sun/star/frame/XComponentLoader.hpp> 29#include <com/sun/star/container/XHierarchicalNameAccess.hpp> 30#include <com/sun/star/util/XChangesBatch.hpp> 31#include <com/sun/star/container/XNameContainer.hpp> 32#include <com/sun/star/util/XMacroExpander.hpp> 33#include <com/sun/star/lang/XSingleServiceFactory.hpp> | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 17 unchanged lines hidden (view full) --- 26 27#include "configurationaccess.hxx" 28#include <com/sun/star/frame/XComponentLoader.hpp> 29#include <com/sun/star/container/XHierarchicalNameAccess.hpp> 30#include <com/sun/star/util/XChangesBatch.hpp> 31#include <com/sun/star/container/XNameContainer.hpp> 32#include <com/sun/star/util/XMacroExpander.hpp> 33#include <com/sun/star/lang/XSingleServiceFactory.hpp> |
34#include <com/sun/star/resource/XResourceBundleLoader.hpp> |
|
34 | 35 |
35using namespace ::rtl; | 36#include <rtl/ustrbuf.hxx> 37 38#include "minimizer.hrc" 39 |
36using namespace ::com::sun::star; 37using namespace ::com::sun::star::uno; 38using namespace ::com::sun::star::beans; 39using namespace ::com::sun::star::container; 40 | 40using namespace ::com::sun::star; 41using namespace ::com::sun::star::uno; 42using namespace ::com::sun::star::beans; 43using namespace ::com::sun::star::container; 44 |
45using rtl::OUString; 46using rtl::OUStringBuffer; 47 48 49#include <rtl/instance.hxx> 50 51typedef std::map < sal_Int32, rtl::OUString > StringResourceMap; 52 53struct StaticResourceMap 54 : public rtl::StaticWithInit< StringResourceMap, StaticResourceMap > 55{ 56 StringResourceMap & 57 operator()() const; 58}; 59 60StringResourceMap & 61StaticResourceMap::operator()() const 62{ 63 static StringResourceMap aMap; 64 return aMap; 65} 66 |
|
41static const OUString& GetConfigurationProviderServiceName (void) 42{ 43 static const OUString sConfigurationProviderServiceName ( 44 RTL_CONSTASCII_USTRINGPARAM( 45 "com.sun.star.configuration.ConfigurationProvider")); 46 return sConfigurationProviderServiceName; 47} 48static const OUString& GetPathToConfigurationRoot (void) 49{ 50 static const OUString sPathToConfigurationRoot ( | 67static const OUString& GetConfigurationProviderServiceName (void) 68{ 69 static const OUString sConfigurationProviderServiceName ( 70 RTL_CONSTASCII_USTRINGPARAM( 71 "com.sun.star.configuration.ConfigurationProvider")); 72 return sConfigurationProviderServiceName; 73} 74static const OUString& GetPathToConfigurationRoot (void) 75{ 76 static const OUString sPathToConfigurationRoot ( |
51 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.extension.SunPresentationMinimizer")); | 77 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Impress/PresentationMinimizer")); |
52 return sPathToConfigurationRoot; 53} 54 | 78 return sPathToConfigurationRoot; 79} 80 |
81static OUString lcl_loadString( 82 const Reference< resource::XResourceBundle > xResourceBundle, 83 sal_Int32 nResourceId ) 84{ 85 OUString sString; 86 OUStringBuffer sKey; 87 sKey.appendAscii( RTL_CONSTASCII_STRINGPARAM( "string:" ) ); 88 sKey.append( nResourceId ); 89 90 try 91 { 92 OSL_VERIFY( xResourceBundle->getByName( sKey.makeStringAndClear() ) >>= sString ); 93 } 94 catch( const uno::Exception& ) 95 { 96 OSL_ENSURE( false, "OptimizerSettings: missing resource!" ); 97 } 98 99 return sString; 100} 101 |
|
55void OptimizerSettings::LoadSettingsFromConfiguration( const Reference< XNameAccess >& rSettings ) 56{ 57 if ( rSettings.is() ) 58 { 59 const Sequence< OUString > aElements( rSettings->getElementNames() ); 60 for ( int i = 0; i < aElements.getLength(); i++ ) 61 { 62 try --- 91 unchanged lines hidden (view full) --- 154 && ( rOptimizerSettings.mnOLEOptimizationType == mnOLEOptimizationType ) 155 && ( rOptimizerSettings.mbDeleteUnusedMasterPages == mbDeleteUnusedMasterPages ) 156 && ( rOptimizerSettings.mbDeleteHiddenSlides == mbDeleteHiddenSlides ) 157 && ( rOptimizerSettings.mbDeleteNotesPages == mbDeleteNotesPages ); 158// && ( rOptimizerSettings.mbOpenNewDocument == mbOpenNewDocument ); 159} 160 161 | 102void OptimizerSettings::LoadSettingsFromConfiguration( const Reference< XNameAccess >& rSettings ) 103{ 104 if ( rSettings.is() ) 105 { 106 const Sequence< OUString > aElements( rSettings->getElementNames() ); 107 for ( int i = 0; i < aElements.getLength(); i++ ) 108 { 109 try --- 91 unchanged lines hidden (view full) --- 201 && ( rOptimizerSettings.mnOLEOptimizationType == mnOLEOptimizationType ) 202 && ( rOptimizerSettings.mbDeleteUnusedMasterPages == mbDeleteUnusedMasterPages ) 203 && ( rOptimizerSettings.mbDeleteHiddenSlides == mbDeleteHiddenSlides ) 204 && ( rOptimizerSettings.mbDeleteNotesPages == mbDeleteNotesPages ); 205// && ( rOptimizerSettings.mbOpenNewDocument == mbOpenNewDocument ); 206} 207 208 |
162ConfigurationAccess::ConfigurationAccess( const Reference< uno::XComponentContext >& rxMSF, OptimizerSettings* pDefaultSettings ) : 163 mxMSF( rxMSF ) | 209ConfigurationAccess::ConfigurationAccess( const Reference< uno::XComponentContext >& rxContext, OptimizerSettings* pDefaultSettings ) : 210 m_xContext( rxContext ) |
164{ 165 LoadStrings(); 166 maSettings.push_back( pDefaultSettings ? 167 *pDefaultSettings : OptimizerSettings() ); 168 maSettings.back().maName = TKGet( TK_LastUsedSettings ); 169 LoadConfiguration(); 170 maInitialSettings = maSettings; 171}; 172 173ConfigurationAccess::~ConfigurationAccess() 174{ 175} 176 | 211{ 212 LoadStrings(); 213 maSettings.push_back( pDefaultSettings ? 214 *pDefaultSettings : OptimizerSettings() ); 215 maSettings.back().maName = TKGet( TK_LastUsedSettings ); 216 LoadConfiguration(); 217 maInitialSettings = maSettings; 218}; 219 220ConfigurationAccess::~ConfigurationAccess() 221{ 222} 223 |
177rtl::OUString ConfigurationAccess::getPath( const PPPOptimizerTokenEnum eToken ) | 224rtl::OUString ConfigurationAccess::getString( sal_Int32 nResId ) |
178{ | 225{ |
179 rtl::OUString aPath; 180 try 181 { 182 static const OUString sProtocol( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.expand:" ) ); 183 static const OUString stheMacroExpander( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander" ) ); 184 Reference< container::XNameAccess > xSet( OpenConfiguration( true ), UNO_QUERY_THROW ); 185 if ( xSet->hasByName( TKGet( eToken ) ) ) 186 xSet->getByName( TKGet( eToken ) ) >>= aPath; 187 if ( aPath.match( sProtocol, 0 ) ) 188 { 189 rtl::OUString aTmp( aPath.copy( 20 ) ); 190 Reference< util::XMacroExpander > xExpander; 191 if ( mxMSF->getValueByName( stheMacroExpander ) >>= xExpander ) 192 { 193 aPath = xExpander->expandMacros( aTmp ); 194 } 195 } 196 } 197 catch ( Exception& ) 198 { 199 } 200 return aPath; | 226 const StringResourceMap &aStrings = StaticResourceMap::get(); 227 StringResourceMap::const_iterator aIter( aStrings.find( nResId ) ); 228 return aIter != aStrings.end() ? ((*aIter).second) : rtl::OUString(); |
201} 202 | 229} 230 |
203rtl::OUString ConfigurationAccess::getString( const PPPOptimizerTokenEnum eToken ) const 204{ 205 std::map< PPPOptimizerTokenEnum, rtl::OUString, Compare >::const_iterator aIter( maStrings.find( eToken ) ); 206 return aIter != maStrings.end() ? ((*aIter).second) : rtl::OUString(); 207} 208 | |
209void ConfigurationAccess::LoadStrings() 210{ | 231void ConfigurationAccess::LoadStrings() 232{ |
233 static bool bLoaded = false; 234 if ( bLoaded ) 235 return; 236 else 237 bLoaded = true; |
|
211 try 212 { | 238 try 239 { |
213 do 214 { 215 Reference< XInterface > xRoot( OpenConfiguration( true ) ); 216 if ( !xRoot.is() ) 217 break; 218 Reference< container::XNameAccess > xSet( GetConfigurationNode( xRoot, TKGet( TK_Strings ) ), UNO_QUERY ); 219 if ( xSet.is() ) 220 { 221 const Sequence< OUString > aElements( xSet->getElementNames() ); 222 for ( int i = 0; i < aElements.getLength(); i++ ) 223 { 224 try 225 { 226 OUString aString, aPropertyName( aElements[ i ] ); 227 if ( xSet->getByName( aPropertyName ) >>= aString ) 228 maStrings[ TKGet( aPropertyName ) ] = aString; 229 } 230 catch( Exception& ) 231 { 232 } 233 } 234 } 235 } 236 while( false ); | 240 241 Reference< resource::XResourceBundleLoader > xResourceBundleLoader( 242 m_xContext->getValueByName( 243 OUString( RTL_CONSTASCII_USTRINGPARAM( 244 "/singletons/com.sun.star.resource.OfficeResourceLoader" ) ) ), 245 UNO_QUERY_THROW ); 246 247 Reference< resource::XResourceBundle > xResourceBundle( 248 xResourceBundleLoader->loadBundle_Default( 249 OUString( RTL_CONSTASCII_USTRINGPARAM( "minimizer" ) ) ), 250 UNO_SET_THROW ); 251 252 StringResourceMap &aStrings = StaticResourceMap::get(); 253 aStrings[ STR_PRESENTATION_MINIMIZER ] = lcl_loadString( xResourceBundle, STR_PRESENTATION_MINIMIZER ); 254 aStrings[ STR_STEPS ] = lcl_loadString( xResourceBundle, STR_STEPS ); 255 aStrings[ STR_HELP ] = lcl_loadString( xResourceBundle, STR_HELP ); 256 aStrings[ STR_BACK ] = lcl_loadString( xResourceBundle, STR_BACK ); 257 aStrings[ STR_NEXT ] = lcl_loadString( xResourceBundle, STR_NEXT ); 258 aStrings[ STR_FINISH ] = lcl_loadString( xResourceBundle, STR_FINISH ); 259 aStrings[ STR_CANCEL ] = lcl_loadString( xResourceBundle, STR_CANCEL ); 260 aStrings[ STR_INTRODUCTION ] = lcl_loadString( xResourceBundle, STR_INTRODUCTION ); 261 aStrings[ STR_INTRODUCTION_T ] = lcl_loadString( xResourceBundle, STR_INTRODUCTION_T ); 262 aStrings[ STR_CHOSE_SETTINGS ] = lcl_loadString( xResourceBundle, STR_CHOSE_SETTINGS ); 263 aStrings[ STR_REMOVE ] = lcl_loadString( xResourceBundle, STR_REMOVE ); 264 aStrings[ STR_GRAPHIC_OPTIMIZATION ] = lcl_loadString( xResourceBundle, STR_GRAPHIC_OPTIMIZATION ); 265 aStrings[ STR_IMAGE_OPTIMIZATION ] = lcl_loadString( xResourceBundle, STR_IMAGE_OPTIMIZATION ); 266 aStrings[ STR_LOSSLESS_COMPRESSION ] = lcl_loadString( xResourceBundle, STR_LOSSLESS_COMPRESSION ); 267 aStrings[ STR_JPEG_COMPRESSION ] = lcl_loadString( xResourceBundle, STR_JPEG_COMPRESSION ); 268 aStrings[ STR_QUALITY ] = lcl_loadString( xResourceBundle, STR_QUALITY ); 269 aStrings[ STR_REMOVE_CROP_AREA ] = lcl_loadString( xResourceBundle, STR_REMOVE_CROP_AREA ); 270 aStrings[ STR_IMAGE_RESOLUTION ] = lcl_loadString( xResourceBundle, STR_IMAGE_RESOLUTION ); 271 aStrings[ STR_IMAGE_RESOLUTION_0 ] = lcl_loadString( xResourceBundle, STR_IMAGE_RESOLUTION_0 ); 272 aStrings[ STR_IMAGE_RESOLUTION_1 ] = lcl_loadString( xResourceBundle, STR_IMAGE_RESOLUTION_1 ); 273 aStrings[ STR_IMAGE_RESOLUTION_2 ] = lcl_loadString( xResourceBundle, STR_IMAGE_RESOLUTION_2 ); 274 aStrings[ STR_IMAGE_RESOLUTION_3 ] = lcl_loadString( xResourceBundle, STR_IMAGE_RESOLUTION_3 ); 275 aStrings[ STR_EMBED_LINKED_GRAPHICS ] = lcl_loadString( xResourceBundle, STR_EMBED_LINKED_GRAPHICS ); 276 aStrings[ STR_OLE_OBJECTS ] = lcl_loadString( xResourceBundle, STR_OLE_OBJECTS ); 277 aStrings[ STR_OLE_OPTIMIZATION ] = lcl_loadString( xResourceBundle, STR_OLE_OPTIMIZATION ); 278 aStrings[ STR_OLE_REPLACE ] = lcl_loadString( xResourceBundle, STR_OLE_REPLACE ); 279 aStrings[ STR_ALL_OLE_OBJECTS ] = lcl_loadString( xResourceBundle, STR_ALL_OLE_OBJECTS ); 280 aStrings[ STR_ALIEN_OLE_OBJECTS_ONLY ] = lcl_loadString( xResourceBundle, STR_ALIEN_OLE_OBJECTS_ONLY ); 281 aStrings[ STR_OLE_OBJECTS_DESC ] = lcl_loadString( xResourceBundle, STR_OLE_OBJECTS_DESC ); 282 aStrings[ STR_NO_OLE_OBJECTS_DESC ] = lcl_loadString( xResourceBundle, STR_NO_OLE_OBJECTS_DESC ); 283 aStrings[ STR_SLIDES ] = lcl_loadString( xResourceBundle, STR_SLIDES ); 284 aStrings[ STR_CHOOSE_SLIDES ] = lcl_loadString( xResourceBundle, STR_CHOOSE_SLIDES ); 285 aStrings[ STR_MASTER_PAGES ] = lcl_loadString( xResourceBundle, STR_MASTER_PAGES ); 286 aStrings[ STR_DELETE_MASTER_PAGES ] = lcl_loadString( xResourceBundle, STR_DELETE_MASTER_PAGES ); 287 aStrings[ STR_DELETE_NOTES_PAGES ] = lcl_loadString( xResourceBundle, STR_DELETE_NOTES_PAGES ); 288 aStrings[ STR_DELETE_HIDDEN_SLIDES ] = lcl_loadString( xResourceBundle, STR_DELETE_HIDDEN_SLIDES ); 289 aStrings[ STR_CUSTOM_SHOW ] = lcl_loadString( xResourceBundle, STR_CUSTOM_SHOW ); 290 aStrings[ STR_SUMMARY ] = lcl_loadString( xResourceBundle, STR_SUMMARY ); 291 aStrings[ STR_SUMMARY_TITLE ] = lcl_loadString( xResourceBundle, STR_SUMMARY_TITLE ); 292 aStrings[ STR_PROGRESS ] = lcl_loadString( xResourceBundle, STR_PROGRESS ); 293 aStrings[ STR_OBJECTS_OPTIMIZED ] = lcl_loadString( xResourceBundle, STR_OBJECTS_OPTIMIZED ); 294 aStrings[ STR_APPLY_TO_CURRENT ] = lcl_loadString( xResourceBundle, STR_APPLY_TO_CURRENT ); 295 aStrings[ STR_AUTOMATICALLY_OPEN ] = lcl_loadString( xResourceBundle, STR_AUTOMATICALLY_OPEN ); 296 aStrings[ STR_SAVE_SETTINGS ] = lcl_loadString( xResourceBundle, STR_SAVE_SETTINGS ); 297 aStrings[ STR_SAVE_AS ] = lcl_loadString( xResourceBundle, STR_SAVE_AS ); 298 aStrings[ STR_DELETE_SLIDES ] = lcl_loadString( xResourceBundle, STR_DELETE_SLIDES ); 299 aStrings[ STR_OPTIMIZE_IMAGES ] = lcl_loadString( xResourceBundle, STR_OPTIMIZE_IMAGES ); 300 aStrings[ STR_CREATE_REPLACEMENT ] = lcl_loadString( xResourceBundle, STR_CREATE_REPLACEMENT ); 301 aStrings[ STR_CURRENT_FILESIZE ] = lcl_loadString( xResourceBundle, STR_CURRENT_FILESIZE ); 302 aStrings[ STR_ESTIMATED_FILESIZE ] = lcl_loadString( xResourceBundle, STR_ESTIMATED_FILESIZE ); 303 aStrings[ STR_MB ] = lcl_loadString( xResourceBundle, STR_MB ); 304 aStrings[ STR_MY_SETTINGS ] = lcl_loadString( xResourceBundle, STR_MY_SETTINGS ); 305 aStrings[ STR_DEFAULT_SESSION ] = lcl_loadString( xResourceBundle, STR_DEFAULT_SESSION ); 306 aStrings[ STR_MODIFY_WARNING ] = lcl_loadString( xResourceBundle, STR_MODIFY_WARNING ); 307 aStrings[ STR_YES ] = lcl_loadString( xResourceBundle, STR_YES ); 308 aStrings[ STR_OK ] = lcl_loadString( xResourceBundle, STR_OK ); 309 aStrings[ STR_INFO_1 ] = lcl_loadString( xResourceBundle, STR_INFO_1 ); 310 aStrings[ STR_INFO_2 ] = lcl_loadString( xResourceBundle, STR_INFO_2 ); 311 aStrings[ STR_INFO_3 ] = lcl_loadString( xResourceBundle, STR_INFO_3 ); 312 aStrings[ STR_INFO_4 ] = lcl_loadString( xResourceBundle, STR_INFO_4 ); 313 aStrings[ STR_DUPLICATING_PRESENTATION ] = lcl_loadString( xResourceBundle, STR_DUPLICATING_PRESENTATION ); 314 aStrings[ STR_DELETING_SLIDES ] = lcl_loadString( xResourceBundle, STR_DELETING_SLIDES ); 315 aStrings[ STR_OPTIMIZING_GRAPHICS ] = lcl_loadString( xResourceBundle, STR_OPTIMIZING_GRAPHICS ); 316 aStrings[ STR_CREATING_OLE_REPLACEMENTS] = lcl_loadString( xResourceBundle, STR_CREATING_OLE_REPLACEMENTS ); 317 aStrings[ STR_FILESIZESEPARATOR ] = lcl_loadString( xResourceBundle, STR_FILESIZESEPARATOR ); 318 aStrings[ STR_INFO_DIALOG ] = lcl_loadString( xResourceBundle, STR_INFO_DIALOG ); |
237 } 238 catch( Exception& ) 239 { 240 } 241} 242 243void ConfigurationAccess::LoadConfiguration() 244{ --- 84 unchanged lines hidden (view full) --- 329 } 330} 331 332Reference< XInterface > ConfigurationAccess::OpenConfiguration( bool bReadOnly ) 333{ 334 Reference< XInterface > xRoot; 335 try 336 { | 319 } 320 catch( Exception& ) 321 { 322 } 323} 324 325void ConfigurationAccess::LoadConfiguration() 326{ --- 84 unchanged lines hidden (view full) --- 411 } 412} 413 414Reference< XInterface > ConfigurationAccess::OpenConfiguration( bool bReadOnly ) 415{ 416 Reference< XInterface > xRoot; 417 try 418 { |
337 Reference< lang::XMultiServiceFactory > xProvider( mxMSF->getServiceManager()->createInstanceWithContext( GetConfigurationProviderServiceName(), mxMSF ), UNO_QUERY ); | 419 Reference< lang::XMultiServiceFactory > xProvider( m_xContext->getServiceManager()->createInstanceWithContext( GetConfigurationProviderServiceName(), m_xContext ), UNO_QUERY ); |
338 if ( xProvider.is() ) 339 { 340 Sequence< Any > aCreationArguments( 2 ); 341 aCreationArguments[0] = makeAny( PropertyValue( 342 OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ), 0, 343 makeAny( GetPathToConfigurationRoot() ), 344 PropertyState_DIRECT_VALUE ) ); 345 aCreationArguments[1] = makeAny(beans::PropertyValue( --- 188 unchanged lines hidden --- | 420 if ( xProvider.is() ) 421 { 422 Sequence< Any > aCreationArguments( 2 ); 423 aCreationArguments[0] = makeAny( PropertyValue( 424 OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) ), 0, 425 makeAny( GetPathToConfigurationRoot() ), 426 PropertyState_DIRECT_VALUE ) ); 427 aCreationArguments[1] = makeAny(beans::PropertyValue( --- 188 unchanged lines hidden --- |