1 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
4 * Smart Common Input Method
6 * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22 * Boston, MA 02111-1307 USA
24 * $Id: scim_config_base.cpp,v 1.19 2005/04/09 15:38:39 suzhe Exp $
27 #define Uses_SCIM_CONFIG_BASE
28 #define Uses_SCIM_CONFIG_PATH
29 #define Uses_SCIM_CONFIG_MODULE
30 #include "scim_private.h"
35 static ConfigPointer _scim_default_config (0);
36 static ConfigModule _scim_default_config_module;
39 _create_config (const String &default_module)
41 if (!_scim_default_config_module.valid ()) {
45 if (!default_module.length ())
46 module = scim_global_config_read (SCIM_GLOBAL_CONFIG_DEFAULT_CONFIG_MODULE, String ("simple"));
48 module = default_module;
50 _scim_default_config_module.load (module);
53 if (_scim_default_config_module.valid ()) {
54 _scim_default_config = _scim_default_config_module.create_config ();
55 return _scim_default_config;
58 return ConfigPointer (0);
61 ConfigBase::ConfigBase ()
65 ConfigBase::~ConfigBase ()
70 ConfigBase::valid () const
76 ConfigBase::read (const String& key, const String& defVal) const
79 if (!read (key, &tmp)) {
80 SCIM_DEBUG_CONFIG(1) << "Warning : No default scim::String value for key \"" << key << "\", "
81 << "using default value.\n";
88 ConfigBase::read (const String& key, int defVal) const
91 if (!read (key, &tmp)) {
92 SCIM_DEBUG_CONFIG(1) << "Warning : No default int value for key \"" << key << "\", "
93 << "using default value.\n";
100 ConfigBase::read (const String& key, double defVal) const
103 if (!read (key, &tmp)) {
104 SCIM_DEBUG_CONFIG(1) << "Warning : No default float value for key \"" << key << "\", "
105 << "using default value.\n";
112 ConfigBase::read (const String& key, bool defVal) const
115 if (!read (key, &tmp)) {
116 SCIM_DEBUG_CONFIG(1) << "Warning : No default bool value for key \"" << key << "\", "
117 << "using default value.\n";
124 ConfigBase::read (const String& key, const std::vector <String>& defVal) const
126 std::vector <String> tmp;
127 if (!read (key, &tmp)) {
128 SCIM_DEBUG_CONFIG(1) << "Warning : No default scim::String list value for key \"" << key << "\", "
129 << "using default value.\n";
136 ConfigBase::read (const String& key, const std::vector <int>& defVal) const
138 std::vector <int> tmp;
139 if (!read (key, &tmp)) {
140 SCIM_DEBUG_CONFIG(1) << "Warning : No default int list value for key \"" << key << "\", "
141 << "using default value.\n";
148 ConfigBase::reload ()
150 if (!ConfigBase::valid ()) return false;
152 m_signal_reload.emit (this);
158 ConfigBase::signal_connect_reload (ConfigSlotVoid *slot)
160 return m_signal_reload.connect (slot);
164 ConfigBase::set (const ConfigPointer &p_config)
166 ConfigPointer old = _scim_default_config;
168 _scim_default_config = p_config;
174 ConfigBase::get (bool create_on_demand, const String &default_module)
176 if (create_on_demand && _scim_default_config.null ())
177 _create_config (default_module);
178 return _scim_default_config;
182 * Implementation of DummyConfig
185 DummyConfig::DummyConfig ()
189 DummyConfig::~DummyConfig ()
194 DummyConfig::valid () const
196 return ConfigBase::valid();
200 DummyConfig::get_name () const
207 DummyConfig::read (const String& key, String *pStr) const
214 DummyConfig::read (const String& key, int *pl) const
221 DummyConfig::read (const String& key, double* val) const
228 DummyConfig::read (const String& key, bool* val) const
235 DummyConfig::read (const String& key, std::vector <String>* val) const
242 DummyConfig::read (const String& key, std::vector <int>* val) const
247 // write the value (return true on success)
249 DummyConfig::write (const String& key, const String& value)
255 DummyConfig::write (const String& key, int value)
261 DummyConfig::write (const String& key, double value)
267 DummyConfig::write (const String& key, bool value)
273 DummyConfig::write (const String& key, const std::vector <String>& value)
279 DummyConfig::write (const String& key, const std::vector <int>& value)
285 // permanently writes all changes
294 DummyConfig::erase (const String& key)
299 // reload the configurations.
301 DummyConfig::reload ()
303 return ConfigBase::reload ();
309 vi:ts=4:nowrap:ai:expandtab