bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / gdi / configsettings.cxx
blobf8b9edb7c50c938171920433b4790a580f3c54b2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <svdata.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>
28 #include <sal/log.hxx>
30 using namespace utl;
31 using namespace vcl;
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::lang;
34 using namespace com::sun::star::beans;
35 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.reset( new SettingsConfigItem() );
44 return pSVData->mpSettingsConfigItem.get();
47 SettingsConfigItem::SettingsConfigItem()
48 : ConfigItem( SETTINGS_CONFIGNODE, ConfigItemMode::NONE ),
49 m_aSettings( 0 )
51 getValues();
54 SettingsConfigItem::~SettingsConfigItem()
56 assert(!IsModified()); // should have been committed
59 void SettingsConfigItem::ImplCommit()
61 for (auto const& setting : m_aSettings)
63 OUString aKeyName( setting.first );
64 /*bool bAdded =*/ AddNode( OUString(), aKeyName );
65 Sequence< PropertyValue > aValues( setting.second.size() );
66 PropertyValue* pValues = aValues.getArray();
67 int nIndex = 0;
68 for (auto const& elem : setting.second)
70 pValues[nIndex].Name = aKeyName + "/" + elem.first;
71 pValues[nIndex].Handle = 0;
72 pValues[nIndex].Value <<= elem.second;
73 pValues[nIndex].State = PropertyState_DIRECT_VALUE;
74 nIndex++;
76 ReplaceSetProperties( aKeyName, aValues );
80 void SettingsConfigItem::Notify( const Sequence< OUString >& )
82 getValues();
85 void SettingsConfigItem::getValues()
87 m_aSettings.clear();
89 const Sequence< OUString > aNames( GetNodeNames( OUString() ) );
91 for( const auto& aKeyName : aNames )
93 #if OSL_DEBUG_LEVEL > 2
94 SAL_INFO( "vcl", "found settings data for " << aKeyName );
95 #endif
96 Sequence< OUString > aKeys( GetNodeNames( aKeyName ) );
97 Sequence< OUString > aSettingsKeys( aKeys.getLength() );
98 std::transform(aKeys.begin(), aKeys.end(), aSettingsKeys.begin(),
99 [&aKeyName](const OUString& rKey) -> OUString { return aKeyName + "/" + rKey; });
100 Sequence< Any > aValues( GetProperties( aSettingsKeys ) );
101 const OUString* pFrom = aKeys.getConstArray();
102 const Any* pValue = aValues.getConstArray();
103 for( int i = 0; i < aValues.getLength(); i++, pValue++ )
105 if( auto pLine = o3tl::tryAccess<OUString>(*pValue) )
107 if( !pLine->isEmpty() )
108 m_aSettings[ aKeyName ][ pFrom[i] ] = *pLine;
109 #if OSL_DEBUG_LEVEL > 2
110 SAL_INFO( "vcl", " \"" << aKeys.getConstArray()[i] << "\"=\"" << *pLine << "\"" );
111 #endif
117 OUString SettingsConfigItem::getValue( const OUString& rGroup, const OUString& rKey ) const
119 std::unordered_map< OUString, SmallOUStrMap >::const_iterator group = m_aSettings.find( rGroup );
120 if( group == m_aSettings.end() || group->second.find( rKey ) == group->second.end() )
122 return OUString();
124 return group->second.find(rKey)->second;
127 void SettingsConfigItem::setValue( const OUString& rGroup, const OUString& rKey, const OUString& rValue )
129 bool bModified = m_aSettings[ rGroup ][ rKey ] != rValue;
130 if( bModified )
132 m_aSettings[ rGroup ][ rKey ] = rValue;
133 SetModified();
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */