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 
25 #ifndef _CONFIGURATION_ACCESS_HXX_
26 #define _CONFIGURATION_ACCESS_HXX_
27 #include <vector>
28 #include "pppoptimizertoken.hxx"
29 #include <com/sun/star/awt/Size.hpp>
30 #include <com/sun/star/uno/Any.h>
31 #include <com/sun/star/uno/Reference.h>
32 #include <com/sun/star/uno/XInterface.hpp>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/beans/XPropertyAccess.hpp>
35 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 #endif
39 #include <com/sun/star/container/XNameAccess.hpp>
40 #include <com/sun/star/container/XNameReplace.hpp>
41 #include <map>
42 
43 
44 struct OptimizerSettings
45 {
46 	rtl::OUString	maName;
47 	sal_Bool		mbJPEGCompression;
48 	sal_Int32		mnJPEGQuality;
49 	sal_Bool		mbRemoveCropArea;
50 	sal_Int32		mnImageResolution;
51 	sal_Bool		mbEmbedLinkedGraphics;
52 	sal_Bool		mbOLEOptimization;
53 	sal_Int16		mnOLEOptimizationType;
54 	sal_Bool		mbDeleteUnusedMasterPages;
55 	sal_Bool		mbDeleteHiddenSlides;
56 	sal_Bool		mbDeleteNotesPages;
57 	rtl::OUString	maCustomShowName;
58 	sal_Bool		mbSaveAs;
59 	rtl::OUString	maSaveAsURL;
60 	rtl::OUString	maFilterName;
61 	sal_Bool		mbOpenNewDocument;
62 	sal_Int64		mnEstimatedFileSize;
63 
OptimizerSettingsOptimizerSettings64 	OptimizerSettings() :
65 		mbJPEGCompression( sal_False ),
66 		mnJPEGQuality( 90 ),
67 		mbRemoveCropArea( sal_False ),
68 		mnImageResolution( 0 ),
69 		mbEmbedLinkedGraphics( sal_False ),
70 		mbOLEOptimization( sal_False ),
71 		mnOLEOptimizationType( 0 ),
72 		mbDeleteUnusedMasterPages( sal_False ),
73 		mbDeleteHiddenSlides( sal_False ),
74 		mbDeleteNotesPages( sal_False ),
75 		mbSaveAs( sal_True ),
76 		mbOpenNewDocument( sal_True ),
77 		mnEstimatedFileSize( 0 ){};
~OptimizerSettingsOptimizerSettings78 		~OptimizerSettings(){};
79 
80 		void LoadSettingsFromConfiguration( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& rSettings );
81 		void SaveSettingsToConfiguration( const com::sun::star::uno::Reference< com::sun::star::container::XNameReplace >& rSettings );
82 
83 		sal_Bool operator==( const OptimizerSettings& rOptimizerSettings ) const;
84 
85 };
86 class ConfigurationAccess
87 {
88 	public :
89 
90 		ConfigurationAccess( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext,
91 								OptimizerSettings* pDefaultSettings = NULL );
92 		~ConfigurationAccess();
93 		void SaveConfiguration();
94 
95 		static rtl::OUString getString( sal_Int32 nResId );
96 
97 		// access to current OptimizerSettings (stored in the first entry of maSettings)
98 		com::sun::star::uno::Any GetConfigProperty( const PPPOptimizerTokenEnum ) const;
99 		void SetConfigProperty( const PPPOptimizerTokenEnum, const com::sun::star::uno::Any& aValue );
100 
101 		sal_Bool GetConfigProperty( const PPPOptimizerTokenEnum, const sal_Bool bDefault ) const;
102 		sal_Int16 GetConfigProperty( const PPPOptimizerTokenEnum, const sal_Int16 nDefault ) const;
103 		sal_Int32 GetConfigProperty( const PPPOptimizerTokenEnum, const sal_Int32 nDefault ) const;
104 
105 		com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > GetConfigurationSequence();
106 
107 		// getting access to the OptimizerSettings list
GetOptimizerSettings()108 		std::vector< OptimizerSettings >& GetOptimizerSettings() { return maSettings; };
109 		std::vector< OptimizerSettings >::iterator GetOptimizerSettingsByName( const rtl::OUString& rName );
110 
111 	private :
112 
113         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext;
114 		std::vector< OptimizerSettings > maSettings;
115 		std::vector< OptimizerSettings > maInitialSettings;
116 
117 		void LoadStrings();
118 		void LoadConfiguration();
119 		com::sun::star::uno::Reference< com::sun::star::uno::XInterface > OpenConfiguration( bool bReadOnly );
120 		com::sun::star::uno::Reference< com::sun::star::uno::XInterface > GetConfigurationNode(
121 			const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& xRoot, const rtl::OUString& sPathToNode );
122 };
123 
124 #endif	// _CONFIGURATION_ACCESS_HXX_
125 
126