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
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
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>
35
36 #include <rtl/ustrbuf.hxx>
37
38 #include "minimizer.hrc"
39
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::container;
44
45 using rtl::OUString;
46 using rtl::OUStringBuffer;
47
48
49 #include <rtl/instance.hxx>
50
51 typedef std::map < sal_Int32, rtl::OUString > StringResourceMap;
52
53 struct StaticResourceMap
54 : public rtl::StaticWithInit< StringResourceMap, StaticResourceMap >
55 {
56 StringResourceMap &
57 operator()() const;
58 };
59
60 StringResourceMap &
operator ()() const61 StaticResourceMap::operator()() const
62 {
63 static StringResourceMap aMap;
64 return aMap;
65 }
66
GetConfigurationProviderServiceName(void)67 static const OUString& GetConfigurationProviderServiceName (void)
68 {
69 static const OUString sConfigurationProviderServiceName (
70 RTL_CONSTASCII_USTRINGPARAM(
71 "com.sun.star.configuration.ConfigurationProvider"));
72 return sConfigurationProviderServiceName;
73 }
GetPathToConfigurationRoot(void)74 static const OUString& GetPathToConfigurationRoot (void)
75 {
76 static const OUString sPathToConfigurationRoot (
77 RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.Impress/PresentationMinimizer"));
78 return sPathToConfigurationRoot;
79 }
80
lcl_loadString(const Reference<resource::XResourceBundle> xResourceBundle,sal_Int32 nResourceId)81 static 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
LoadSettingsFromConfiguration(const Reference<XNameAccess> & rSettings)102 void 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
110 {
111 const OUString aPropertyName( aElements[ i ] );
112 Any aValue( rSettings->getByName( aPropertyName ) );
113 switch( TKGet( aPropertyName ) )
114 {
115 case TK_Name : aValue >>= maName; break;
116 case TK_JPEGCompression : aValue >>= mbJPEGCompression; break;
117 case TK_JPEGQuality : aValue >>= mnJPEGQuality; break;
118 case TK_RemoveCropArea : aValue >>= mbRemoveCropArea; break;
119 case TK_ImageResolution : aValue >>= mnImageResolution; break;
120 case TK_EmbedLinkedGraphics : aValue >>= mbEmbedLinkedGraphics; break;
121 case TK_OLEOptimization : aValue >>= mbOLEOptimization; break;
122 case TK_OLEOptimizationType : aValue >>= mnOLEOptimizationType; break;
123 case TK_DeleteUnusedMasterPages : aValue >>= mbDeleteUnusedMasterPages; break;
124 case TK_DeleteHiddenSlides : aValue >>= mbDeleteHiddenSlides; break;
125 case TK_DeleteNotesPages : aValue >>= mbDeleteNotesPages ;break;
126 case TK_SaveAs : aValue >>= mbSaveAs; break;
127 // case TK_SaveAsURL : aValue >>= maSaveAsURL; break; // URL is not saved to configuration
128 // case TK_FilterName : aValue >>= maFilterName; break; // URL is not saved to configuration
129 case TK_OpenNewDocument : aValue >>= mbOpenNewDocument; break;
130 default: break;
131 }
132 }
133 catch( Exception& )
134 {
135 }
136 }
137 }
138 }
139
SaveSettingsToConfiguration(const Reference<XNameReplace> & rSettings)140 void OptimizerSettings::SaveSettingsToConfiguration( const Reference< XNameReplace >& rSettings )
141 {
142 if ( rSettings.is() )
143 {
144 OUString pNames[] = {
145 TKGet( TK_Name ),
146 TKGet( TK_JPEGCompression ),
147 TKGet( TK_JPEGQuality ),
148 TKGet( TK_RemoveCropArea ),
149 TKGet( TK_ImageResolution ),
150 TKGet( TK_EmbedLinkedGraphics ),
151 TKGet( TK_OLEOptimization ),
152 TKGet( TK_OLEOptimizationType ),
153 TKGet( TK_DeleteUnusedMasterPages ),
154 TKGet( TK_DeleteHiddenSlides ),
155 TKGet( TK_DeleteNotesPages ),
156 TKGet( TK_SaveAs ),
157 // TKGet( TK_SaveAsURL ),
158 // TKGet( TK_FilterName ),
159 TKGet( TK_OpenNewDocument ) };
160
161 Any pValues[] = {
162 Any( maName ),
163 Any( mbJPEGCompression ),
164 Any( mnJPEGQuality ),
165 Any( mbRemoveCropArea ),
166 Any( mnImageResolution ),
167 Any( mbEmbedLinkedGraphics ),
168 Any( mbOLEOptimization ),
169 Any( mnOLEOptimizationType ),
170 Any( mbDeleteUnusedMasterPages ),
171 Any( mbDeleteHiddenSlides ),
172 Any( mbDeleteNotesPages ),
173 Any( mbSaveAs ),
174 // Any( maSaveAsURL ),
175 // Any( maFilterName ),
176 Any( mbOpenNewDocument ) };
177
178 sal_Int32 i, nCount = sizeof( pNames ) / sizeof( OUString );
179
180 for ( i = 0; i < nCount; i++ )
181 {
182 try
183 {
184 rSettings->replaceByName( pNames[ i ], pValues[ i ] );
185 }
186 catch( Exception& /* rException */ )
187 {
188 }
189 }
190 }
191 }
192
operator ==(const OptimizerSettings & rOptimizerSettings) const193 sal_Bool OptimizerSettings::operator==( const OptimizerSettings& rOptimizerSettings ) const
194 {
195 return ( rOptimizerSettings.mbJPEGCompression == mbJPEGCompression )
196 && ( rOptimizerSettings.mnJPEGQuality == mnJPEGQuality )
197 && ( rOptimizerSettings.mbRemoveCropArea == mbRemoveCropArea )
198 && ( rOptimizerSettings.mnImageResolution == mnImageResolution )
199 && ( rOptimizerSettings.mbEmbedLinkedGraphics == mbEmbedLinkedGraphics )
200 && ( rOptimizerSettings.mbOLEOptimization == mbOLEOptimization )
201 && ( rOptimizerSettings.mnOLEOptimizationType == mnOLEOptimizationType )
202 && ( rOptimizerSettings.mbDeleteUnusedMasterPages == mbDeleteUnusedMasterPages )
203 && ( rOptimizerSettings.mbDeleteHiddenSlides == mbDeleteHiddenSlides )
204 && ( rOptimizerSettings.mbDeleteNotesPages == mbDeleteNotesPages );
205 // && ( rOptimizerSettings.mbOpenNewDocument == mbOpenNewDocument );
206 }
207
208
ConfigurationAccess(const Reference<uno::XComponentContext> & rxContext,OptimizerSettings * pDefaultSettings)209 ConfigurationAccess::ConfigurationAccess( const Reference< uno::XComponentContext >& rxContext, OptimizerSettings* pDefaultSettings ) :
210 m_xContext( rxContext )
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
~ConfigurationAccess()220 ConfigurationAccess::~ConfigurationAccess()
221 {
222 }
223
getString(sal_Int32 nResId)224 rtl::OUString ConfigurationAccess::getString( sal_Int32 nResId )
225 {
226 const StringResourceMap &aStrings = StaticResourceMap::get();
227 StringResourceMap::const_iterator aIter( aStrings.find( nResId ) );
228 return aIter != aStrings.end() ? ((*aIter).second) : rtl::OUString();
229 }
230
LoadStrings()231 void ConfigurationAccess::LoadStrings()
232 {
233 static bool bLoaded = false;
234 if ( bLoaded )
235 return;
236 else
237 bLoaded = true;
238 try
239 {
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 );
319 }
320 catch( Exception& )
321 {
322 }
323 }
324
LoadConfiguration()325 void ConfigurationAccess::LoadConfiguration()
326 {
327 try
328 {
329 do
330 {
331 Reference< XInterface > xRoot( OpenConfiguration( true ) );
332 if ( !xRoot.is() )
333 break;
334 Reference< container::XNameAccess > xSet( GetConfigurationNode( xRoot, TKGet( TK_LastUsedSettings ) ), UNO_QUERY );
335 if ( xSet.is() )
336 {
337 OptimizerSettings& rCurrent( maSettings.front() );
338 rCurrent.LoadSettingsFromConfiguration( xSet );
339 }
340 xSet = Reference< container::XNameAccess >( GetConfigurationNode( xRoot, TKGet( TK_Settings_Templates ) ), UNO_QUERY );
341 if ( xSet.is() )
342 {
343 const Sequence< OUString > aElements( xSet->getElementNames() );
344 for ( int i = 0; i < aElements.getLength(); i++ )
345 {
346 try
347 {
348 OUString aPath( TKGet( TK_Settings_Templates_ ).concat( aElements[ i ] ) );
349 Reference< container::XNameAccess > xTemplates( GetConfigurationNode( xRoot, aPath ), UNO_QUERY );
350 if ( xTemplates.is() )
351 {
352 maSettings.push_back( OptimizerSettings() );
353 maSettings.back().LoadSettingsFromConfiguration( xTemplates );
354 }
355 }
356 catch( Exception& /* rException */ )
357 {
358 }
359 }
360 }
361 }
362 while( false );
363 }
364 catch( Exception& )
365 {
366 }
367 }
368
SaveConfiguration()369 void ConfigurationAccess::SaveConfiguration()
370 {
371 try
372 {
373 do
374 {
375 int i;
376 unsigned int k;
377 Reference<util::XChangesBatch> xRoot( OpenConfiguration( false ), UNO_QUERY_THROW );
378
379 // storing the last used settings
380 Reference< container::XNameReplace > xSet( GetConfigurationNode( xRoot, TKGet( TK_LastUsedSettings ) ), UNO_QUERY_THROW );
381 OptimizerSettings& rCurrent( maSettings.front() );
382 rCurrent.SaveSettingsToConfiguration( xSet );
383
384 // updating template elements
385 xSet = Reference< container::XNameReplace >( GetConfigurationNode( xRoot, TKGet( TK_Settings_Templates ) ), UNO_QUERY_THROW );
386 Reference< container::XNameContainer > xNameContainer( xSet, UNO_QUERY_THROW );
387
388 const Sequence< OUString > aElements( xSet->getElementNames() );
389 for( i = 0; i < aElements.getLength(); i++ )
390 xNameContainer->removeByName( aElements[ i ] );
391
392 for( k = 1; k < maSettings.size(); k++ )
393 {
394 OptimizerSettings& rSettings( maSettings[ k ] );
395 OUString aElementName( TKGet( TK_Template ).concat( OUString::valueOf( static_cast< sal_Int32 >( k ) ) ) );
396 Reference< lang::XSingleServiceFactory > xChildFactory ( xSet, UNO_QUERY_THROW );
397 Reference< container::XNameReplace > xChild( xChildFactory->createInstance(), UNO_QUERY_THROW );
398 xNameContainer->insertByName( aElementName, Any( xChild ) );
399
400 OUString aPath( TKGet( TK_Settings_Templates_ ).concat( aElementName ) );
401 Reference< container::XNameReplace > xTemplates( GetConfigurationNode( xRoot, aPath ), UNO_QUERY );
402 rSettings.SaveSettingsToConfiguration( xTemplates );
403 }
404 xRoot->commitChanges();
405 }
406 while( false );
407 }
408 catch( Exception& /* rException */ )
409 {
410
411 }
412 }
413
OpenConfiguration(bool bReadOnly)414 Reference< XInterface > ConfigurationAccess::OpenConfiguration( bool bReadOnly )
415 {
416 Reference< XInterface > xRoot;
417 try
418 {
419 Reference< lang::XMultiServiceFactory > xProvider( m_xContext->getServiceManager()->createInstanceWithContext( GetConfigurationProviderServiceName(), m_xContext ), UNO_QUERY );
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(
428 OUString( RTL_CONSTASCII_USTRINGPARAM( "lazywrite" ) ), 0, makeAny( true ),
429 PropertyState_DIRECT_VALUE ) );
430 OUString sAccessService;
431 if ( bReadOnly )
432 sAccessService = OUString( RTL_CONSTASCII_USTRINGPARAM(
433 "com.sun.star.configuration.ConfigurationAccess" ) );
434 else
435 sAccessService = OUString( RTL_CONSTASCII_USTRINGPARAM(
436 "com.sun.star.configuration.ConfigurationUpdateAccess" ) );
437
438 xRoot = xProvider->createInstanceWithArguments(
439 sAccessService, aCreationArguments );
440 }
441 }
442 catch ( Exception& /* rException */ )
443 {
444 }
445 return xRoot;
446 }
447
GetConfigurationNode(const Reference<XInterface> & xRoot,const OUString & sPathToNode)448 Reference< XInterface > ConfigurationAccess::GetConfigurationNode(
449 const Reference< XInterface >& xRoot,
450 const OUString& sPathToNode )
451 {
452 Reference< XInterface > xNode;
453 try
454 {
455 if ( !sPathToNode.getLength() )
456 xNode = xRoot;
457 else
458 {
459 Reference< XHierarchicalNameAccess > xHierarchy( xRoot, UNO_QUERY );
460 if ( xHierarchy.is() )
461 {
462 xHierarchy->getByHierarchicalName( sPathToNode ) >>= xNode;
463 }
464 }
465 }
466 catch ( Exception& rException )
467 {
468 OSL_TRACE ("caught exception while getting configuration node %s: %s",
469 ::rtl::OUStringToOString(sPathToNode,
470 RTL_TEXTENCODING_UTF8).getStr(),
471 ::rtl::OUStringToOString(rException.Message,
472 RTL_TEXTENCODING_UTF8).getStr());
473 }
474 return xNode;
475 }
476
GetConfigProperty(const PPPOptimizerTokenEnum ePropertyToken) const477 com::sun::star::uno::Any ConfigurationAccess::GetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken ) const
478 {
479 Any aRetValue;
480 const OptimizerSettings& rSettings( maSettings.front() );
481 try
482 {
483 switch( ePropertyToken )
484 {
485 case TK_Name : aRetValue <<= rSettings.maName; break;
486 case TK_JPEGCompression : aRetValue <<= rSettings.mbJPEGCompression; break;
487 case TK_JPEGQuality : aRetValue <<= rSettings.mnJPEGQuality; break;
488 case TK_RemoveCropArea : aRetValue <<= rSettings.mbRemoveCropArea; break;
489 case TK_ImageResolution : aRetValue <<= rSettings.mnImageResolution; break;
490 case TK_EmbedLinkedGraphics : aRetValue <<= rSettings.mbEmbedLinkedGraphics; break;
491 case TK_OLEOptimization : aRetValue <<= rSettings.mbOLEOptimization; break;
492 case TK_OLEOptimizationType : aRetValue <<= rSettings.mnOLEOptimizationType; break;
493 case TK_DeleteUnusedMasterPages : aRetValue <<= rSettings.mbDeleteUnusedMasterPages; break;
494 case TK_DeleteHiddenSlides : aRetValue <<= rSettings.mbDeleteHiddenSlides; break;
495 case TK_DeleteNotesPages : aRetValue <<= rSettings.mbDeleteNotesPages; break;
496 case TK_SaveAs : aRetValue <<= rSettings.mbSaveAs; break;
497 case TK_SaveAsURL : aRetValue <<= rSettings.maSaveAsURL; break;
498 case TK_FilterName : aRetValue <<= rSettings.maFilterName; break;
499 case TK_OpenNewDocument : aRetValue <<= rSettings.mbOpenNewDocument; break;
500 case TK_EstimatedFileSize : aRetValue <<= rSettings.mnEstimatedFileSize; break;
501 default:
502 break;
503 }
504 }
505 catch( Exception& /* rException */ )
506 {
507 }
508 return aRetValue;
509 }
510
SetConfigProperty(const PPPOptimizerTokenEnum ePropertyToken,const com::sun::star::uno::Any & rValue)511 void ConfigurationAccess::SetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken, const com::sun::star::uno::Any& rValue )
512 {
513 OptimizerSettings& rSettings( maSettings.front() );
514 try
515 {
516 switch( ePropertyToken )
517 {
518 case TK_Name : rValue >>= rSettings.maName; break;
519 case TK_JPEGCompression : rValue >>= rSettings.mbJPEGCompression; break;
520 case TK_JPEGQuality : rValue >>= rSettings.mnJPEGQuality; break;
521 case TK_RemoveCropArea : rValue >>= rSettings.mbRemoveCropArea; break;
522 case TK_ImageResolution : rValue >>= rSettings.mnImageResolution; break;
523 case TK_EmbedLinkedGraphics : rValue >>= rSettings.mbEmbedLinkedGraphics; break;
524 case TK_OLEOptimization : rValue >>= rSettings.mbOLEOptimization; break;
525 case TK_OLEOptimizationType : rValue >>= rSettings.mnOLEOptimizationType; break;
526 case TK_DeleteUnusedMasterPages : rValue >>= rSettings.mbDeleteUnusedMasterPages; break;
527 case TK_DeleteHiddenSlides : rValue >>= rSettings.mbDeleteHiddenSlides; break;
528 case TK_DeleteNotesPages : rValue >>= rSettings.mbDeleteNotesPages; break;
529 case TK_CustomShowName : rValue >>= rSettings.maCustomShowName; break;
530 case TK_SaveAs : rValue >>= rSettings.mbSaveAs; break;
531 case TK_SaveAsURL : rValue >>= rSettings.maSaveAsURL; break;
532 case TK_FilterName : rValue >>= rSettings.maFilterName; break;
533 case TK_OpenNewDocument : rValue >>= rSettings.mbOpenNewDocument; break;
534 case TK_EstimatedFileSize : rValue >>= rSettings.mnEstimatedFileSize; break;
535 default:
536 break;
537 }
538 }
539 catch( Exception& /* rException */ )
540 {
541 }
542 }
543
GetConfigProperty(const PPPOptimizerTokenEnum ePropertyToken,const sal_Bool bDefault) const544 sal_Bool ConfigurationAccess::GetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken, const sal_Bool bDefault ) const
545 {
546 sal_Bool bRetValue = bDefault;
547 if ( ! ( GetConfigProperty( ePropertyToken ) >>= bRetValue ) )
548 bRetValue = bDefault;
549 return bRetValue;
550 }
551
GetConfigProperty(const PPPOptimizerTokenEnum ePropertyToken,const sal_Int16 nDefault) const552 sal_Int16 ConfigurationAccess::GetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken, const sal_Int16 nDefault ) const
553 {
554 sal_Int16 nRetValue = nDefault;
555 if ( ! ( GetConfigProperty( ePropertyToken ) >>= nRetValue ) )
556 nRetValue = nDefault;
557 return nRetValue;
558 }
559
GetConfigProperty(const PPPOptimizerTokenEnum ePropertyToken,const sal_Int32 nDefault) const560 sal_Int32 ConfigurationAccess::GetConfigProperty( const PPPOptimizerTokenEnum ePropertyToken, const sal_Int32 nDefault ) const
561 {
562 sal_Int32 nRetValue = nDefault;
563 if ( ! ( GetConfigProperty( ePropertyToken ) >>= nRetValue ) )
564 nRetValue = nDefault;
565 return nRetValue;
566 }
567
GetConfigurationSequence()568 Sequence< PropertyValue > ConfigurationAccess::GetConfigurationSequence()
569 {
570 Sequence< PropertyValue > aRet( 15 );
571 OptimizerSettings& rSettings( maSettings.front() );
572 aRet[ 0 ].Name = TKGet( TK_JPEGCompression );
573 aRet[ 0 ].Value= Any( rSettings.mbJPEGCompression );
574 aRet[ 1 ].Name = TKGet( TK_JPEGQuality );
575 aRet[ 1 ].Value= Any( rSettings.mnJPEGQuality );
576 aRet[ 2 ].Name = TKGet( TK_RemoveCropArea );
577 aRet[ 2 ].Value= Any( rSettings.mbRemoveCropArea );
578 aRet[ 3 ].Name = TKGet( TK_ImageResolution );
579 aRet[ 3 ].Value= Any( rSettings.mnImageResolution );
580 aRet[ 4 ].Name = TKGet( TK_EmbedLinkedGraphics );
581 aRet[ 4 ].Value= Any( rSettings.mbEmbedLinkedGraphics );
582 aRet[ 5 ].Name = TKGet( TK_OLEOptimization );
583 aRet[ 5 ].Value= Any( rSettings.mbOLEOptimization );
584 aRet[ 6 ].Name = TKGet( TK_OLEOptimizationType );
585 aRet[ 6 ].Value= Any( rSettings.mnOLEOptimizationType );
586 aRet[ 7 ].Name = TKGet( TK_DeleteUnusedMasterPages );
587 aRet[ 7 ].Value= Any( rSettings.mbDeleteUnusedMasterPages );
588 aRet[ 8 ].Name = TKGet( TK_DeleteHiddenSlides );
589 aRet[ 8 ].Value= Any( rSettings.mbDeleteHiddenSlides );
590 aRet[ 9 ].Name = TKGet( TK_DeleteNotesPages );
591 aRet[ 9 ].Value= Any( rSettings.mbDeleteNotesPages );
592 aRet[ 10].Name = TKGet( TK_CustomShowName );
593 aRet[ 10].Value= Any( rSettings.maCustomShowName );
594 aRet[ 11].Name = TKGet( TK_SaveAsURL );
595 aRet[ 11].Value= Any( rSettings.maSaveAsURL );
596 aRet[ 12].Name = TKGet( TK_FilterName );
597 aRet[ 12].Value= Any( rSettings.maFilterName );
598 aRet[ 13].Name = TKGet( TK_OpenNewDocument );
599 aRet[ 13].Value= Any( rSettings.mbOpenNewDocument );
600 aRet[ 14].Name = TKGet( TK_EstimatedFileSize );
601 aRet[ 14].Value= Any( rSettings.mnEstimatedFileSize );
602 return aRet;
603 }
604
GetOptimizerSettingsByName(const rtl::OUString & rName)605 std::vector< OptimizerSettings >::iterator ConfigurationAccess::GetOptimizerSettingsByName( const rtl::OUString& rName )
606 {
607 std::vector< OptimizerSettings >::iterator aIter( maSettings.begin() + 1 );
608 while ( aIter != maSettings.end() )
609 {
610 if ( aIter->maName == rName )
611 break;
612 aIter++;
613 }
614 return aIter;
615 }
616