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 #ifndef _UTL_CONFIGITEM_HXX_ 25 #define _UTL_CONFIGITEM_HXX_ 26 27 #include <sal/types.h> 28 #include <rtl/ustring.hxx> 29 #include <com/sun/star/uno/Sequence.h> 30 #include <com/sun/star/uno/Reference.h> 31 #include "unotools/unotoolsdllapi.h" 32 #include "unotools/options.hxx" 33 34 //----------------------------------------------------------------------------- 35 namespace com{ namespace sun{ namespace star{ 36 namespace uno{ 37 class Any; 38 } 39 namespace beans{ 40 struct PropertyValue; 41 } 42 namespace container{ 43 class XHierarchicalNameAccess; 44 } 45 namespace util{ 46 class XChangesListener; 47 } 48 }}} 49 //----------------------------------------------------------------------------- 50 namespace utl 51 { 52 #define CONFIG_MODE_IMMEDIATE_UPDATE 0x00 53 #define CONFIG_MODE_DELAYED_UPDATE 0x01 54 #define CONFIG_MODE_ALL_LOCALES 0x02 55 #define CONFIG_MODE_RELEASE_TREE 0x04 56 #define CONFIG_MODE_IGNORE_ERRORS 0x08 // prevent assertions, if creation fails 57 #define CONFIG_MODE_PROPAGATE_ERRORS 0x10 // throw exceptions, if creation fails 58 59 enum ConfigNameFormat 60 { 61 CONFIG_NAME_PLAINTEXT_NAME, // unescaped local node name, for user display etc. 62 CONFIG_NAME_LOCAL_NAME, // local node name, for use in XNameAccess etc. ("Item", "Q & A") 63 CONFIG_NAME_LOCAL_PATH, // one-level relative path, for use when building pathes etc. ("Item", "Typ['Q & A']") 64 CONFIG_NAME_FULL_PATH, // full absolute path. ("/org.openoffice.Sample/Group/Item", "/org.openoffice.Sample/Set/Typ['Q & A']") 65 66 CONFIG_NAME_DEFAULT = CONFIG_NAME_LOCAL_PATH // default format 67 }; 68 69 class ConfigChangeListener_Impl; 70 class ConfigManager; 71 struct ConfigItem_Impl; 72 73 class UNOTOOLS_DLLPUBLIC ConfigItem : public ConfigurationBroadcaster 74 { 75 friend class ConfigChangeListener_Impl; 76 friend class ConfigManager; 77 78 const rtl::OUString sSubTree; 79 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess> 80 m_xHierarchyAccess; 81 com::sun::star::uno::Reference< com::sun::star::util::XChangesListener > 82 xChangeLstnr; 83 ConfigItem_Impl* pImpl; 84 85 ConfigItem();// 86 void RemoveChangesListener(); 87 void CallNotify( 88 const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames); 89 90 //*********************************************************************************************************************** 91 // In special mode ALL_LOCALES we must support reading/writing of localized cfg entries as Sequence< PropertyValue >. 92 // These methods are helper to convert given lists of names and Any-values. 93 // format: PropertyValue.Name = <locale as ISO string> 94 // PropertyValue.Value = <value; type depends from cfg entry!> 95 // e.g. 96 // LOCALIZED NODE 97 // "UIName" 98 // LOCALE VALUE 99 // "de" "Mein Name" 100 // "en-US" "my name" 101 void impl_packLocalizedProperties ( const com::sun::star::uno::Sequence< rtl::OUString >& lInNames , 102 const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& lInValues , 103 com::sun::star::uno::Sequence< com::sun::star::uno::Any >& lOutValues ); 104 void impl_unpackLocalizedProperties ( const com::sun::star::uno::Sequence< rtl::OUString >& lInNames , 105 const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& lInValues , 106 com::sun::star::uno::Sequence< rtl::OUString >& lOutNames , 107 com::sun::star::uno::Sequence< com::sun::star::uno::Any >& lOutValues ); 108 109 com::sun::star::uno::Reference< com::sun::star::container::XHierarchicalNameAccess> 110 GetTree(); 111 112 protected: 113 ConfigItem(const rtl::OUString rSubTree, 114 sal_Int16 nMode = CONFIG_MODE_DELAYED_UPDATE); 115 ConfigItem(utl::ConfigManager& rManager, const rtl::OUString rSubTree); 116 117 void SetModified (); // mark item as modified 118 void ClearModified(); // reset state after commit! 119 120 com::sun::star::uno::Sequence< com::sun::star::uno::Any> 121 GetProperties(const com::sun::star::uno::Sequence< rtl::OUString >& rNames); 122 123 com::sun::star::uno::Sequence< sal_Bool > 124 GetReadOnlyStates(const com::sun::star::uno::Sequence< rtl::OUString >& rNames); 125 126 sal_Bool PutProperties( 127 const com::sun::star::uno::Sequence< rtl::OUString >& rNames, 128 const com::sun::star::uno::Sequence< com::sun::star::uno::Any>& rValues); 129 130 /** enables notifications about changes on selected sub nodes/values 131 132 Before calling this method a second time for a possibly changed node/value set, 133 you must disable the current notifications by calling DisableNotification. 134 135 @see Notify 136 @see DisableNotification 137 */ 138 sal_Bool EnableNotification(const com::sun::star::uno::Sequence< rtl::OUString >& rNames, 139 sal_Bool bEnableInternalNotification = sal_False); 140 /** disables notifications about changes on sub nodes/values, which previosly had 141 been enabled with EnableNotification 142 @see Notify 143 @see EnableNotification 144 */ 145 void DisableNotification(); IsInternalNotification() const146 sal_Bool IsInternalNotification()const {return IsInValueChange();} 147 148 //returns all members of a node in a specific format 149 com::sun::star::uno::Sequence< rtl::OUString > 150 GetNodeNames(const rtl::OUString& rNode); 151 //returns all members of a node in a specific format 152 com::sun::star::uno::Sequence< rtl::OUString > 153 GetNodeNames(const rtl::OUString& rNode, ConfigNameFormat eFormat); 154 // remove all members of a set 155 sal_Bool ClearNodeSet(const rtl::OUString& rNode); 156 // remove selected members of a set 157 sal_Bool ClearNodeElements(const rtl::OUString& rNode, 158 com::sun::star::uno::Sequence< rtl::OUString >& rElements); 159 // change or add members to a set 160 sal_Bool SetSetProperties(const rtl::OUString& rNode, com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues); 161 // remove, change or add members of a set 162 sal_Bool ReplaceSetProperties(const rtl::OUString& rNode, com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > rValues); 163 // add a new node without setting any properties 164 sal_Bool AddNode(const rtl::OUString& rNode, const rtl::OUString& rNewNode); 165 166 /** get a name for a new element of a set node 167 @param _rSetNode 168 relative path to the set node 169 @param _rBaseName 170 <ul><li><b>in</b>: the base to use when calculating a new name</li> 171 <li><b>out</b>: an unused element name</li> 172 </ul> 173 @return <TRUE/> if a free name could be generated 174 */ 175 sal_Bool getUniqueSetElementName( const rtl::OUString& _rSetNode, rtl::OUString& _rBaseName); 176 177 public: 178 virtual ~ConfigItem(); 179 180 /** is called from the ConfigManager before application ends of from the 181 PropertyChangeListener if the sub tree broadcasts changes. */ 182 virtual void Notify( const com::sun::star::uno::Sequence<rtl::OUString>& aPropertyNames)=0; 183 184 /** is called from the ConfigManager if it is destroyed before the ConfigItem. */ 185 void ReleaseConfigMgr(); 186 187 /** enable locking of the XHierarchicalNameAccess if CONFIG_MODE_RELEASE_TREE is set to 188 prevent multiple calls ConfigManager::AcquireTree() from a single Commit() operation*/ 189 void LockTree(); 190 void UnlockTree(); 191 GetSubTreeName() const192 const rtl::OUString& GetSubTreeName() const {return sSubTree;} 193 194 sal_Bool IsModified() const; 195 196 /** writes the changed values into the sub tree. Always called in the Dtor of the derived class. */ 197 virtual void Commit()=0; 198 199 sal_Bool IsInValueChange() const; 200 201 sal_Int16 GetMode() const; 202 203 /** checks if the configuration manager used by this item is valid. 204 */ 205 sal_Bool IsValidConfigMgr() const; 206 }; 207 }//namespace utl 208 #endif //_UTL_CONFIGITEM_HXX_ 209