update emoji autocorrect entries from po-files
[LibreOffice.git] / vcl / source / gdi / configsettings.cxx
blob6ec9e3b4660bed52f91709eba4c190f65537633c
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>
28 using namespace utl;
29 using namespace vcl;
30 using namespace com::sun::star::uno;
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::beans;
33 using namespace com::sun::star::container;
35 #define SETTINGS_CONFIGNODE "VCL/Settings"
37 SettingsConfigItem* SettingsConfigItem::get()
39 ImplSVData* pSVData = ImplGetSVData();
40 if( ! pSVData->mpSettingsConfigItem )
41 pSVData->mpSettingsConfigItem = new SettingsConfigItem();
42 return pSVData->mpSettingsConfigItem;
45 SettingsConfigItem::SettingsConfigItem()
47 ConfigItem( OUString( SETTINGS_CONFIGNODE ),
48 ConfigItemMode::DelayedUpdate ),
49 m_aSettings( 0 )
51 getValues();
54 SettingsConfigItem::~SettingsConfigItem()
56 assert(!IsModified()); // should have been committed
59 void SettingsConfigItem::ImplCommit()
61 std::unordered_map< OUString, SmallOUStrMap, OUStringHash >::const_iterator group;
63 for( group = m_aSettings.begin(); group != m_aSettings.end(); ++group )
65 OUString aKeyName( group->first );
66 /*bool bAdded =*/ AddNode( OUString(), aKeyName );
67 Sequence< PropertyValue > aValues( group->second.size() );
68 PropertyValue* pValues = aValues.getArray();
69 int nIndex = 0;
70 SmallOUStrMap::const_iterator it;
71 for( it = group->second.begin(); it != group->second.end(); ++it )
73 OUString aName( aKeyName );
74 aName += OUString('/');
75 aName += it->first;
76 pValues[nIndex].Name = aName;
77 pValues[nIndex].Handle = 0;
78 pValues[nIndex].Value <<= it->second;
79 pValues[nIndex].State = PropertyState_DIRECT_VALUE;
80 nIndex++;
82 ReplaceSetProperties( aKeyName, aValues );
86 void SettingsConfigItem::Notify( const Sequence< OUString >& )
88 getValues();
91 void SettingsConfigItem::getValues()
93 m_aSettings.clear();
95 Sequence< OUString > aNames( GetNodeNames( OUString() ) );
97 for( int j = 0; j < aNames.getLength(); j++ )
99 #if OSL_DEBUG_LEVEL > 2
100 OSL_TRACE( "found settings data for \"%s\"\n",
101 OUStringToOString( aNames.getConstArray()[j], RTL_TEXTENCODING_ASCII_US ).getStr()
103 #endif
104 OUString aKeyName( aNames.getConstArray()[j] );
105 Sequence< OUString > aKeys( GetNodeNames( aKeyName ) );
106 Sequence< OUString > aSettingsKeys( aKeys.getLength() );
107 const OUString* pFrom = aKeys.getConstArray();
108 OUString* pTo = aSettingsKeys.getArray();
109 for( int m = 0; m < aKeys.getLength(); m++ )
111 OUString aName( aKeyName );
112 aName += OUString('/');
113 aName += pFrom[m];
114 pTo[m] = aName;
116 Sequence< Any > aValues( GetProperties( aSettingsKeys ) );
117 const Any* pValue = aValues.getConstArray();
118 for( int i = 0; i < aValues.getLength(); i++, pValue++ )
120 if( pValue->getValueTypeClass() == TypeClass_STRING )
122 const OUString* pLine = static_cast<const OUString*>(pValue->getValue());
123 if( !pLine->isEmpty() )
124 m_aSettings[ aKeyName ][ pFrom[i] ] = *pLine;
125 #if OSL_DEBUG_LEVEL > 2
126 OSL_TRACE( " \"%s\"=\"%.30s\"\n",
127 OUStringToOString( aKeys.getConstArray()[i], RTL_TEXTENCODING_ASCII_US ).getStr(),
128 OUStringToOString( *pLine, RTL_TEXTENCODING_ASCII_US ).getStr()
130 #endif
136 const OUString& SettingsConfigItem::getValue( const OUString& rGroup, const OUString& rKey ) const
138 std::unordered_map< OUString, SmallOUStrMap, OUStringHash >::const_iterator group = m_aSettings.find( rGroup );
139 if( group == m_aSettings.end() || group->second.find( rKey ) == group->second.end() )
141 static OUString aEmpty;
142 return aEmpty;
144 return group->second.find(rKey)->second;
147 void SettingsConfigItem::setValue( const OUString& rGroup, const OUString& rKey, const OUString& rValue )
149 bool bModified = m_aSettings[ rGroup ][ rKey ] != rValue;
150 if( bModified )
152 m_aSettings[ rGroup ][ rKey ] = rValue;
153 SetModified();
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */