1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <vcl/configsettings.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/beans/PropertyValue.hpp>
31 using namespace com::sun::star::uno
;
32 using namespace com::sun::star::lang
;
33 using namespace com::sun::star::beans
;
34 using namespace com::sun::star::container
;
37 #define SETTINGS_CONFIGNODE "VCL/Settings"
39 SettingsConfigItem
* SettingsConfigItem::get()
41 ImplSVData
* pSVData
= ImplGetSVData();
42 if( ! pSVData
->mpSettingsConfigItem
)
43 pSVData
->mpSettingsConfigItem
= new SettingsConfigItem();
44 return pSVData
->mpSettingsConfigItem
;
47 SettingsConfigItem::SettingsConfigItem()
49 ConfigItem( OUString( SETTINGS_CONFIGNODE
),
50 CONFIG_MODE_DELAYED_UPDATE
),
56 SettingsConfigItem::~SettingsConfigItem()
62 void SettingsConfigItem::Commit()
64 if( ! IsValidConfigMgr() )
67 boost::unordered_map
< OUString
, SmallOUStrMap
, OUStringHash
>::const_iterator group
;
69 for( group
= m_aSettings
.begin(); group
!= m_aSettings
.end(); ++group
)
71 String
aKeyName( group
->first
);
72 /*sal_Bool bAdded =*/ AddNode( OUString(), aKeyName
);
73 Sequence
< PropertyValue
> aValues( group
->second
.size() );
74 PropertyValue
* pValues
= aValues
.getArray();
76 SmallOUStrMap::const_iterator it
;
77 for( it
= group
->second
.begin(); it
!= group
->second
.end(); ++it
)
79 String
aName( aKeyName
);
81 aName
.Append( String( it
->first
) );
82 pValues
[nIndex
].Name
= aName
;
83 pValues
[nIndex
].Handle
= 0;
84 pValues
[nIndex
].Value
<<= it
->second
;
85 pValues
[nIndex
].State
= PropertyState_DIRECT_VALUE
;
88 ReplaceSetProperties( aKeyName
, aValues
);
92 void SettingsConfigItem::Notify( const Sequence
< OUString
>& )
97 void SettingsConfigItem::getValues()
99 if( ! IsValidConfigMgr() )
104 Sequence
< OUString
> aNames( GetNodeNames( OUString() ) );
106 for( int j
= 0; j
< aNames
.getLength(); j
++ )
108 #if OSL_DEBUG_LEVEL > 2
109 OSL_TRACE( "found settings data for \"%s\"\n",
110 OUStringToOString( aNames
.getConstArray()[j
], RTL_TEXTENCODING_ASCII_US
).getStr()
113 String
aKeyName( aNames
.getConstArray()[j
] );
114 Sequence
< OUString
> aKeys( GetNodeNames( aKeyName
) );
115 Sequence
< OUString
> aSettingsKeys( aKeys
.getLength() );
116 const OUString
* pFrom
= aKeys
.getConstArray();
117 OUString
* pTo
= aSettingsKeys
.getArray();
118 for( int m
= 0; m
< aKeys
.getLength(); m
++ )
120 String
aName( aKeyName
);
122 aName
.Append( String( pFrom
[m
] ) );
125 Sequence
< Any
> aValues( GetProperties( aSettingsKeys
) );
126 const Any
* pValue
= aValues
.getConstArray();
127 for( int i
= 0; i
< aValues
.getLength(); i
++, pValue
++ )
129 if( pValue
->getValueTypeClass() == TypeClass_STRING
)
131 const OUString
* pLine
= (const OUString
*)pValue
->getValue();
132 if( !pLine
->isEmpty() )
133 m_aSettings
[ aKeyName
][ pFrom
[i
] ] = *pLine
;
134 #if OSL_DEBUG_LEVEL > 2
135 OSL_TRACE( " \"%s\"=\"%.30s\"\n",
136 OUStringToOString( aKeys
.getConstArray()[i
], RTL_TEXTENCODING_ASCII_US
).getStr(),
137 OUStringToOString( *pLine
, RTL_TEXTENCODING_ASCII_US
).getStr()
145 const OUString
& SettingsConfigItem::getValue( const OUString
& rGroup
, const OUString
& rKey
) const
147 ::boost::unordered_map
< OUString
, SmallOUStrMap
, OUStringHash
>::const_iterator group
= m_aSettings
.find( rGroup
);
148 if( group
== m_aSettings
.end() || group
->second
.find( rKey
) == group
->second
.end() )
150 static OUString aEmpty
;
153 return group
->second
.find(rKey
)->second
;
156 void SettingsConfigItem::setValue( const OUString
& rGroup
, const OUString
& rKey
, const OUString
& rValue
)
158 bool bModified
= m_aSettings
[ rGroup
][ rKey
] != rValue
;
161 m_aSettings
[ rGroup
][ rKey
] = rValue
;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */