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