1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 #ifndef _CONFIGURATION_ACCESS_HXX_
30 #define _CONFIGURATION_ACCESS_HXX_
31 #include <vector>
32 #include "pppoptimizertoken.hxx"
33 #include <com/sun/star/awt/Size.hpp>
34 #include <com/sun/star/uno/Any.h>
35 #include <com/sun/star/uno/Reference.h>
36 #include <com/sun/star/uno/XInterface.hpp>
37 #include <com/sun/star/beans/XPropertySet.hpp>
38 #include <com/sun/star/beans/XPropertyAccess.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 #ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT
41 #include <com/sun/star/uno/XComponentContext.hpp>
42 #endif
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/container/XNameReplace.hpp>
45 #include <map>
46 
47 struct OptimizerSettings
48 {
49 	rtl::OUString	maName;
50 	sal_Bool		mbJPEGCompression;
51 	sal_Int32		mnJPEGQuality;
52 	sal_Bool		mbRemoveCropArea;
53 	sal_Int32		mnImageResolution;
54 	sal_Bool		mbEmbedLinkedGraphics;
55 	sal_Bool		mbOLEOptimization;
56 	sal_Int16		mnOLEOptimizationType;
57 	sal_Bool		mbDeleteUnusedMasterPages;
58 	sal_Bool		mbDeleteHiddenSlides;
59 	sal_Bool		mbDeleteNotesPages;
60 	rtl::OUString	maCustomShowName;
61 	sal_Bool		mbSaveAs;
62 	rtl::OUString	maSaveAsURL;
63 	rtl::OUString	maFilterName;
64 	sal_Bool		mbOpenNewDocument;
65 	sal_Int64		mnEstimatedFileSize;
66 
67 	OptimizerSettings() :
68 		mbJPEGCompression( sal_False ),
69 		mnJPEGQuality( 90 ),
70 		mbRemoveCropArea( sal_False ),
71 		mnImageResolution( 0 ),
72 		mbEmbedLinkedGraphics( sal_False ),
73 		mbOLEOptimization( sal_False ),
74 		mnOLEOptimizationType( 0 ),
75 		mbDeleteUnusedMasterPages( sal_False ),
76 		mbDeleteHiddenSlides( sal_False ),
77 		mbDeleteNotesPages( sal_False ),
78 		mbSaveAs( sal_True ),
79 		mbOpenNewDocument( sal_True ),
80 		mnEstimatedFileSize( 0 ){};
81 		~OptimizerSettings(){};
82 
83 		void LoadSettingsFromConfiguration( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& rSettings );
84 		void SaveSettingsToConfiguration( const com::sun::star::uno::Reference< com::sun::star::container::XNameReplace >& rSettings );
85 
86 		sal_Bool operator==( const OptimizerSettings& rOptimizerSettings ) const;
87 
88 };
89 class ConfigurationAccess
90 {
91 	public :
92 
93 		ConfigurationAccess( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rXFactory,
94 								OptimizerSettings* pDefaultSettings = NULL );
95 		~ConfigurationAccess();
96 		void SaveConfiguration();
97 
98 		rtl::OUString getPath( const PPPOptimizerTokenEnum );
99 		rtl::OUString getString( const PPPOptimizerTokenEnum ) const;
100 
101 		// access to current OptimizerSettings (stored in the first entry of maSettings)
102 		com::sun::star::uno::Any GetConfigProperty( const PPPOptimizerTokenEnum ) const;
103 		void SetConfigProperty( const PPPOptimizerTokenEnum, const com::sun::star::uno::Any& aValue );
104 
105 		sal_Bool GetConfigProperty( const PPPOptimizerTokenEnum, const sal_Bool bDefault ) const;
106 		sal_Int16 GetConfigProperty( const PPPOptimizerTokenEnum, const sal_Int16 nDefault ) const;
107 		sal_Int32 GetConfigProperty( const PPPOptimizerTokenEnum, const sal_Int32 nDefault ) const;
108 
109 		com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > GetConfigurationSequence();
110 
111 		// getting access to the OptimizerSettings list
112 		std::vector< OptimizerSettings >& GetOptimizerSettings() { return maSettings; };
113 		std::vector< OptimizerSettings >::iterator GetOptimizerSettingsByName( const rtl::OUString& rName );
114 
115 	private :
116 
117 		struct Compare
118 		{
119 			bool operator()( const PPPOptimizerTokenEnum s1, const PPPOptimizerTokenEnum s2 ) const
120 			{
121 				return s1 < s2;
122 			}
123 		};
124 		std::map < PPPOptimizerTokenEnum, rtl::OUString, Compare > maStrings;
125 
126 		std::vector< OptimizerSettings > maSettings;
127 		std::vector< OptimizerSettings > maInitialSettings;
128 
129 		com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > mxMSF;
130 
131 		void LoadStrings();
132 		void LoadConfiguration();
133 		com::sun::star::uno::Reference< com::sun::star::uno::XInterface > OpenConfiguration( bool bReadOnly );
134 		com::sun::star::uno::Reference< com::sun::star::uno::XInterface > GetConfigurationNode(
135 			const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& xRoot, const rtl::OUString& sPathToNode );
136 };
137 
138 #endif	// _CONFIGURATION_ACCESS_HXX_
139 
140