LibreOffice Module vcl (master) 1
configsettings.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <configsettings.hxx>
21
22#include <svdata.hxx>
23
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>
29
30using namespace utl;
31using namespace vcl;
32using namespace com::sun::star::uno;
33using namespace com::sun::star::lang;
34using namespace com::sun::star::beans;
35using namespace com::sun::star::container;
36
37constexpr OUStringLiteral SETTINGS_CONFIGNODE = u"VCL/Settings";
38
39SettingsConfigItem* SettingsConfigItem::get()
40{
41 ImplSVData* pSVData = ImplGetSVData();
42 if( ! pSVData->mpSettingsConfigItem )
43 pSVData->mpSettingsConfigItem.reset( new SettingsConfigItem() );
44 return pSVData->mpSettingsConfigItem.get();
45}
46
49 m_aSettings( 0 )
50{
51 getValues();
52}
53
55{
56 assert(!IsModified()); // should have been committed
57}
58
60{
61 for (auto const& setting : m_aSettings)
62 {
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)
69 {
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++;
75 }
76 ReplaceSetProperties( aKeyName, aValues );
77 }
78}
79
81{
82 getValues();
83}
84
86{
87 m_aSettings.clear();
88
89 const Sequence< OUString > aNames( GetNodeNames( OUString() ) );
90
91 for( const auto& aKeyName : aNames )
92 {
93#if OSL_DEBUG_LEVEL > 2
94 SAL_INFO( "vcl", "found settings data for " << aKeyName );
95#endif
96 const Sequence< OUString > aKeys( GetNodeNames( aKeyName ) );
97 Sequence< OUString > aSettingsKeys( aKeys.getLength() );
98 std::transform(aKeys.begin(), aKeys.end(), aSettingsKeys.getArray(),
99 [&aKeyName](const OUString& rKey) -> OUString { return aKeyName + "/" + rKey; });
100 const Sequence< Any > aValues( GetProperties( aSettingsKeys ) );
101 for( int i = 0; i < aValues.getLength(); i++ )
102 {
103 if( auto pLine = o3tl::tryAccess<OUString>(aValues[i]) )
104 {
105 if( !pLine->isEmpty() )
106 m_aSettings[ aKeyName ][ aKeys[i] ] = *pLine;
107#if OSL_DEBUG_LEVEL > 2
108 SAL_INFO( "vcl", " \"" << aKeys.getConstArray()[i] << "\"=\"" << *pLine << "\"" );
109#endif
110 }
111 }
112 }
113}
114
115OUString SettingsConfigItem::getValue( const OUString& rGroup, const OUString& rKey ) const
116{
117 std::unordered_map< OUString, SmallOUStrMap >::const_iterator group = m_aSettings.find( rGroup );
118 if( group == m_aSettings.end() || group->second.find( rKey ) == group->second.end() )
119 {
120 return OUString();
121 }
122 return group->second.find(rKey)->second;
123}
124
125void SettingsConfigItem::setValue( const OUString& rGroup, const OUString& rKey, const OUString& rValue )
126{
127 bool bModified = m_aSettings[ rGroup ][ rKey ] != rValue;
128 if( bModified )
129 {
130 m_aSettings[ rGroup ][ rKey ] = rValue;
131 SetModified();
132 }
133}
134
135/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
bool IsModified() const
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
static bool ReplaceSetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const OUString &rNode, const css::uno::Sequence< css::beans::PropertyValue > &rValues, bool bAllLocales)
bool AddNode(const OUString &rNode, const OUString &rNewNode)
static css::uno::Sequence< OUString > GetNodeNames(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const OUString &rNode, ConfigNameFormat eFormat)
OUString getValue(const OUString &rGroup, const OUString &rKey) const
std::unordered_map< OUString, SmallOUStrMap > m_aSettings
virtual ~SettingsConfigItem() override
virtual void ImplCommit() override
void setValue(const OUString &rGroup, const OUString &rKey, const OUString &rValue)
virtual void Notify(const css::uno::Sequence< OUString > &rPropertyNames) override
ConfigItemMode
constexpr OUStringLiteral SETTINGS_CONFIGNODE
float u
sal_Int32 nIndex
#define SAL_INFO(area, stream)
NONE
int i
group
std::unique_ptr< vcl::SettingsConfigItem > mpSettingsConfigItem
Definition: svdata.hxx:413
::comphelper::NamedValueCollection m_aSettings
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:77