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 struct OptimizerSettings 44 { 45 rtl::OUString maName; 46 sal_Bool mbJPEGCompression; 47 sal_Int32 mnJPEGQuality; 48 sal_Bool mbRemoveCropArea; 49 sal_Int32 mnImageResolution; 50 sal_Bool mbEmbedLinkedGraphics; 51 sal_Bool mbOLEOptimization; 52 sal_Int16 mnOLEOptimizationType; 53 sal_Bool mbDeleteUnusedMasterPages; 54 sal_Bool mbDeleteHiddenSlides; 55 sal_Bool mbDeleteNotesPages; 56 rtl::OUString maCustomShowName; 57 sal_Bool mbSaveAs; 58 rtl::OUString maSaveAsURL; 59 rtl::OUString maFilterName; 60 sal_Bool mbOpenNewDocument; 61 sal_Int64 mnEstimatedFileSize; 62 63 OptimizerSettings() : 64 mbJPEGCompression( sal_False ), 65 mnJPEGQuality( 90 ), 66 mbRemoveCropArea( sal_False ), 67 mnImageResolution( 0 ), 68 mbEmbedLinkedGraphics( sal_False ), 69 mbOLEOptimization( sal_False ), 70 mnOLEOptimizationType( 0 ), 71 mbDeleteUnusedMasterPages( sal_False ), 72 mbDeleteHiddenSlides( sal_False ), 73 mbDeleteNotesPages( sal_False ), 74 mbSaveAs( sal_True ), 75 mbOpenNewDocument( sal_True ), 76 mnEstimatedFileSize( 0 ){}; 77 ~OptimizerSettings(){}; 78 79 void LoadSettingsFromConfiguration( const com::sun::star::uno::Reference< com::sun::star::container::XNameAccess >& rSettings ); 80 void SaveSettingsToConfiguration( const com::sun::star::uno::Reference< com::sun::star::container::XNameReplace >& rSettings ); 81 82 sal_Bool operator==( const OptimizerSettings& rOptimizerSettings ) const; 83 84 }; 85 class ConfigurationAccess 86 { 87 public : 88 89 ConfigurationAccess( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rXFactory, 90 OptimizerSettings* pDefaultSettings = NULL ); 91 ~ConfigurationAccess(); 92 void SaveConfiguration(); 93 94 rtl::OUString getPath( const PPPOptimizerTokenEnum ); 95 rtl::OUString getString( const PPPOptimizerTokenEnum ) const; 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 108 std::vector< OptimizerSettings >& GetOptimizerSettings() { return maSettings; }; 109 std::vector< OptimizerSettings >::iterator GetOptimizerSettingsByName( const rtl::OUString& rName ); 110 111 private : 112 113 struct Compare 114 { 115 bool operator()( const PPPOptimizerTokenEnum s1, const PPPOptimizerTokenEnum s2 ) const 116 { 117 return s1 < s2; 118 } 119 }; 120 std::map < PPPOptimizerTokenEnum, rtl::OUString, Compare > maStrings; 121 122 std::vector< OptimizerSettings > maSettings; 123 std::vector< OptimizerSettings > maInitialSettings; 124 125 com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > mxMSF; 126 127 void LoadStrings(); 128 void LoadConfiguration(); 129 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > OpenConfiguration( bool bReadOnly ); 130 com::sun::star::uno::Reference< com::sun::star::uno::XInterface > GetConfigurationNode( 131 const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& xRoot, const rtl::OUString& sPathToNode ); 132 }; 133 134 #endif // _CONFIGURATION_ACCESS_HXX_ 135 136