xref: /trunk/main/vcl/source/gdi/configsettings.cxx (revision 71fb1a33)
19f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59f62ea84SAndrew Rist  * distributed with this work for additional information
69f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
99f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
109f62ea84SAndrew Rist  *
119f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129f62ea84SAndrew Rist  *
139f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149f62ea84SAndrew Rist  * software distributed under the License is distributed on an
159f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
179f62ea84SAndrew Rist  * specific language governing permissions and limitations
189f62ea84SAndrew Rist  * under the License.
199f62ea84SAndrew Rist  *
209f62ea84SAndrew Rist  *************************************************************/
219f62ea84SAndrew Rist 
229f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vcl/configsettings.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svdata.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
32cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
33cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace rtl;
36cdf0e10cSrcweir using namespace utl;
37cdf0e10cSrcweir using namespace vcl;
38cdf0e10cSrcweir using namespace com::sun::star::uno;
39cdf0e10cSrcweir using namespace com::sun::star::lang;
40cdf0e10cSrcweir using namespace com::sun::star::beans;
41cdf0e10cSrcweir using namespace com::sun::star::container;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #define SETTINGS_CONFIGNODE "VCL/Settings"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /*
46cdf0e10cSrcweir  *	SettingsConfigItem::get
47cdf0e10cSrcweir  */
48cdf0e10cSrcweir 
get()49cdf0e10cSrcweir SettingsConfigItem* SettingsConfigItem::get()
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     ImplSVData* pSVData = ImplGetSVData();
52cdf0e10cSrcweir     if( ! pSVData->mpSettingsConfigItem )
53cdf0e10cSrcweir         pSVData->mpSettingsConfigItem = new SettingsConfigItem();
54cdf0e10cSrcweir     return pSVData->mpSettingsConfigItem;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir /*
58cdf0e10cSrcweir  *  SettignsConfigItem constructor
59cdf0e10cSrcweir  */
60cdf0e10cSrcweir 
SettingsConfigItem()61cdf0e10cSrcweir SettingsConfigItem::SettingsConfigItem()
62cdf0e10cSrcweir         :
63cdf0e10cSrcweir         ConfigItem( OUString( RTL_CONSTASCII_USTRINGPARAM( SETTINGS_CONFIGNODE ) ),
64cdf0e10cSrcweir                     CONFIG_MODE_DELAYED_UPDATE ),
65cdf0e10cSrcweir 	m_aSettings( 0 )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     getValues();
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir /*
71cdf0e10cSrcweir  *  SettingsConfigItem destructor
72cdf0e10cSrcweir  */
73cdf0e10cSrcweir 
~SettingsConfigItem()74cdf0e10cSrcweir SettingsConfigItem::~SettingsConfigItem()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     if( IsModified() )
77cdf0e10cSrcweir         Commit();
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir /*
81cdf0e10cSrcweir  *  SettingsConfigItem::Commit
82cdf0e10cSrcweir  */
83cdf0e10cSrcweir 
Commit()84cdf0e10cSrcweir void SettingsConfigItem::Commit()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     if( ! IsValidConfigMgr() )
87cdf0e10cSrcweir         return;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     std::hash_map< OUString, SmallOUStrMap, rtl::OUStringHash >::const_iterator group;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     for( group = m_aSettings.begin(); group != m_aSettings.end(); ++group )
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         String aKeyName( group->first );
94cdf0e10cSrcweir         /*sal_Bool bAdded =*/ AddNode( OUString(), aKeyName );
95cdf0e10cSrcweir         Sequence< PropertyValue > aValues( group->second.size() );
96cdf0e10cSrcweir         PropertyValue* pValues = aValues.getArray();
97cdf0e10cSrcweir         int nIndex = 0;
98cdf0e10cSrcweir         SmallOUStrMap::const_iterator it;
99cdf0e10cSrcweir         for( it = group->second.begin(); it != group->second.end(); ++it )
100cdf0e10cSrcweir         {
101cdf0e10cSrcweir             String aName( aKeyName );
102cdf0e10cSrcweir             aName.Append( '/' );
103cdf0e10cSrcweir             aName.Append( String( it->first ) );
104cdf0e10cSrcweir             pValues[nIndex].Name	= aName;
105cdf0e10cSrcweir             pValues[nIndex].Handle	= 0;
106cdf0e10cSrcweir             pValues[nIndex].Value <<= it->second;
107cdf0e10cSrcweir             pValues[nIndex].State	= PropertyState_DIRECT_VALUE;
108cdf0e10cSrcweir             nIndex++;
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir         ReplaceSetProperties( aKeyName, aValues );
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir /*
115cdf0e10cSrcweir  *  SettingsConfigItem::Notify
116cdf0e10cSrcweir  */
117cdf0e10cSrcweir 
Notify(const Sequence<OUString> &)118cdf0e10cSrcweir void SettingsConfigItem::Notify( const Sequence< OUString >& )
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     getValues();
121cdf0e10cSrcweir }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir /*
124cdf0e10cSrcweir  *  SettingsConfigItem::getValues
125cdf0e10cSrcweir  */
getValues()126cdf0e10cSrcweir void SettingsConfigItem::getValues()
127cdf0e10cSrcweir {
128cdf0e10cSrcweir     if( ! IsValidConfigMgr() )
129cdf0e10cSrcweir         return;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     m_aSettings.clear();
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     Sequence< OUString > aNames( GetNodeNames( OUString() ) );
134*71fb1a33SHerbert Dürr     m_aSettings.rehash( aNames.getLength() );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     for( int j = 0; j < aNames.getLength(); j++ )
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
139cdf0e10cSrcweir         fprintf( stderr, "found settings data for \"%s\"\n",
140cdf0e10cSrcweir                  OUStringToOString( aNames.getConstArray()[j], RTL_TEXTENCODING_ASCII_US ).getStr()
141cdf0e10cSrcweir                  );
142cdf0e10cSrcweir #endif
143cdf0e10cSrcweir         String aKeyName( aNames.getConstArray()[j] );
144cdf0e10cSrcweir         Sequence< OUString > aKeys( GetNodeNames( aKeyName ) );
145cdf0e10cSrcweir         Sequence< OUString > aSettingsKeys( aKeys.getLength() );
146cdf0e10cSrcweir         const OUString* pFrom = aKeys.getConstArray();
147cdf0e10cSrcweir         OUString* pTo = aSettingsKeys.getArray();
148cdf0e10cSrcweir         for( int m = 0; m < aKeys.getLength(); m++ )
149cdf0e10cSrcweir         {
150cdf0e10cSrcweir             String aName( aKeyName );
151cdf0e10cSrcweir             aName.Append( '/' );
152cdf0e10cSrcweir             aName.Append( String( pFrom[m] ) );
153cdf0e10cSrcweir             pTo[m] = aName;
154cdf0e10cSrcweir         }
155cdf0e10cSrcweir         Sequence< Any > aValues( GetProperties( aSettingsKeys ) );
156cdf0e10cSrcweir         const Any* pValue = aValues.getConstArray();
157cdf0e10cSrcweir         for( int i = 0; i < aValues.getLength(); i++, pValue++ )
158cdf0e10cSrcweir         {
159cdf0e10cSrcweir             if( pValue->getValueTypeClass() == TypeClass_STRING )
160cdf0e10cSrcweir             {
161cdf0e10cSrcweir                 const OUString* pLine = (const OUString*)pValue->getValue();
162cdf0e10cSrcweir                 if( pLine->getLength() )
163cdf0e10cSrcweir                     m_aSettings[ aKeyName ][ pFrom[i] ] = *pLine;
164cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 2
165cdf0e10cSrcweir                 fprintf( stderr, "   \"%s\"=\"%.30s\"\n",
166cdf0e10cSrcweir                          OUStringToOString( aKeys.getConstArray()[i], RTL_TEXTENCODING_ASCII_US ).getStr(),
167cdf0e10cSrcweir                          OUStringToOString( *pLine, RTL_TEXTENCODING_ASCII_US ).getStr()
168cdf0e10cSrcweir                          );
169cdf0e10cSrcweir #endif
170cdf0e10cSrcweir             }
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir /*
176cdf0e10cSrcweir  *  SettingsConfigItem::getDefaultFont
177cdf0e10cSrcweir  */
178cdf0e10cSrcweir 
getValue(const OUString & rGroup,const OUString & rKey) const179cdf0e10cSrcweir const OUString& SettingsConfigItem::getValue( const OUString& rGroup, const OUString& rKey ) const
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     ::std::hash_map< OUString, SmallOUStrMap, rtl::OUStringHash >::const_iterator group = m_aSettings.find( rGroup );
182cdf0e10cSrcweir     if( group == m_aSettings.end() || group->second.find( rKey ) == group->second.end() )
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         static OUString aEmpty;
185cdf0e10cSrcweir         return aEmpty;
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir     return group->second.find(rKey)->second;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir /*
191cdf0e10cSrcweir  *  SettingsConfigItem::setDefaultFont
192cdf0e10cSrcweir  */
193cdf0e10cSrcweir 
setValue(const OUString & rGroup,const OUString & rKey,const OUString & rValue)194cdf0e10cSrcweir void SettingsConfigItem::setValue( const OUString& rGroup, const OUString& rKey, const OUString& rValue )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     bool bModified = m_aSettings[ rGroup ][ rKey ] != rValue;
197cdf0e10cSrcweir     if( bModified )
198cdf0e10cSrcweir     {
199cdf0e10cSrcweir         m_aSettings[ rGroup ][ rKey ] = rValue;
200cdf0e10cSrcweir         SetModified();
201cdf0e10cSrcweir     }
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
204