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 .
20 #include <vcl/configsettings.hxx>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <o3tl/any.hxx>
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
;
36 #define SETTINGS_CONFIGNODE "VCL/Settings"
38 SettingsConfigItem
* SettingsConfigItem::get()
40 ImplSVData
* pSVData
= ImplGetSVData();
41 if( ! pSVData
->mpSettingsConfigItem
)
42 pSVData
->mpSettingsConfigItem
= new SettingsConfigItem();
43 return pSVData
->mpSettingsConfigItem
;
46 SettingsConfigItem::SettingsConfigItem()
47 : ConfigItem( SETTINGS_CONFIGNODE
, ConfigItemMode::DelayedUpdate
),
53 SettingsConfigItem::~SettingsConfigItem()
55 assert(!IsModified()); // should have been committed
58 void SettingsConfigItem::ImplCommit()
60 std::unordered_map
< OUString
, SmallOUStrMap
, OUStringHash
>::const_iterator group
;
62 for( group
= m_aSettings
.begin(); group
!= m_aSettings
.end(); ++group
)
64 OUString
aKeyName( group
->first
);
65 /*bool bAdded =*/ AddNode( OUString(), aKeyName
);
66 Sequence
< PropertyValue
> aValues( group
->second
.size() );
67 PropertyValue
* pValues
= aValues
.getArray();
69 SmallOUStrMap::const_iterator it
;
70 for( it
= group
->second
.begin(); it
!= group
->second
.end(); ++it
)
72 pValues
[nIndex
].Name
= aKeyName
+ "/" + it
->first
;
73 pValues
[nIndex
].Handle
= 0;
74 pValues
[nIndex
].Value
<<= it
->second
;
75 pValues
[nIndex
].State
= PropertyState_DIRECT_VALUE
;
78 ReplaceSetProperties( aKeyName
, aValues
);
82 void SettingsConfigItem::Notify( const Sequence
< OUString
>& )
87 void SettingsConfigItem::getValues()
91 Sequence
< OUString
> aNames( GetNodeNames( OUString() ) );
93 for( int j
= 0; j
< aNames
.getLength(); j
++ )
95 #if OSL_DEBUG_LEVEL > 2
96 SAL_INFO( "vcl", "found settings data for " << aNames
.getConstArray()[j
] );
98 OUString
aKeyName( aNames
.getConstArray()[j
] );
99 Sequence
< OUString
> aKeys( GetNodeNames( aKeyName
) );
100 Sequence
< OUString
> aSettingsKeys( aKeys
.getLength() );
101 const OUString
* pFrom
= aKeys
.getConstArray();
102 OUString
* pTo
= aSettingsKeys
.getArray();
103 for( int m
= 0; m
< aKeys
.getLength(); m
++ )
105 pTo
[m
] = aKeyName
+ "/" + pFrom
[m
];
107 Sequence
< Any
> aValues( GetProperties( aSettingsKeys
) );
108 const Any
* pValue
= aValues
.getConstArray();
109 for( int i
= 0; i
< aValues
.getLength(); i
++, pValue
++ )
111 if( auto pLine
= o3tl::tryAccess
<OUString
>(*pValue
) )
113 if( !pLine
->isEmpty() )
114 m_aSettings
[ aKeyName
][ pFrom
[i
] ] = *pLine
;
115 #if OSL_DEBUG_LEVEL > 2
116 SAL_INFO( "vcl", " \"" << aKeys
.getConstArray()[i
] << "\"=\"" << *pLine
<< "\"" );
123 OUString
SettingsConfigItem::getValue( const OUString
& rGroup
, const OUString
& rKey
) const
125 std::unordered_map
< OUString
, SmallOUStrMap
, OUStringHash
>::const_iterator group
= m_aSettings
.find( rGroup
);
126 if( group
== m_aSettings
.end() || group
->second
.find( rKey
) == group
->second
.end() )
130 return group
->second
.find(rKey
)->second
;
133 void SettingsConfigItem::setValue( const OUString
& rGroup
, const OUString
& rKey
, const OUString
& rValue
)
135 bool bModified
= m_aSettings
[ rGroup
][ rKey
] != rValue
;
138 m_aSettings
[ rGroup
][ rKey
] = rValue
;
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */