1 // This file is a part of Simple Launcher
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #include "gconf-wrapper.h"
20 GConfClient *GConfItem::ourClient = NULL;
22 GConfItem::GConfItem() {
26 void GConfItem::validateClient() {
27 if (ourClient == NULL) {
28 ourClient = gconf_client_get_default();
32 GConfKey::GConfKey(const std::string& path): myKeyPath(path) {
35 GConfStringValue::GConfStringValue(const GConfKey& key, const std::string& name, const std::string& defaultValue):
36 GConfOption(key, name),
37 myDefaultValue(defaultValue) {
40 const std::string& GConfStringValue::value() const {
41 if (!myIsSynchronized) {
42 GConfValue *value = getGConfValue(GCONF_VALUE_STRING);
45 myValue = myDefaultValue;
47 myValue = gconf_value_get_string(value);
49 gconf_value_free(value);
52 myIsSynchronized = true;
58 const std::string& GConfStringValue::setValue(const std::string& newValue) {
59 if (!myIsSynchronized || (myValue != newValue)) {
62 if (myValue == myDefaultValue) {
65 GConfValue *value = gconf_value_new(GCONF_VALUE_STRING);
67 gconf_value_set_string(value, myValue.c_str());
71 gconf_value_free(value);
74 myIsSynchronized = true;
80 GConfBooleanValue::GConfBooleanValue(const GConfKey& key, const std::string& name, bool defaultValue):
81 GConfOption(key, name),
82 myDefaultValue(defaultValue) {
85 bool GConfBooleanValue::value() const {
86 if (!myIsSynchronized) {
87 GConfValue *value = getGConfValue(GCONF_VALUE_BOOL);
90 myValue = myDefaultValue;
92 myValue = gconf_value_get_bool(value);
94 gconf_value_free(value);
97 myIsSynchronized = true;
103 bool GConfBooleanValue::setValue(bool newValue) {
104 if (!myIsSynchronized || (myValue != newValue)) {
107 if (myValue == myDefaultValue) {
110 GConfValue *value = gconf_value_new(GCONF_VALUE_BOOL);
112 gconf_value_set_bool(value, myValue);
114 setGConfValue(value);
116 gconf_value_free(value);
119 myIsSynchronized = true;
125 GConfIntegerValue::GConfIntegerValue(const GConfKey& key, const std::string& name, int defaultValue):
126 GConfOption(key, name),
127 myDefaultValue(defaultValue) {
130 int GConfIntegerValue::value() const {
131 if (!myIsSynchronized) {
132 GConfValue *value = getGConfValue(GCONF_VALUE_INT);
135 myValue = myDefaultValue;
137 myValue = gconf_value_get_int(value);
139 gconf_value_free(value);
142 myIsSynchronized = true;
148 int GConfIntegerValue::setValue(int newValue) {
149 if (!myIsSynchronized || (myValue != newValue)) {
152 if (myValue == myDefaultValue) {
155 GConfValue *value = gconf_value_new(GCONF_VALUE_INT);
157 gconf_value_set_int(value, myValue);
159 setGConfValue(value);
161 gconf_value_free(value);
164 myIsSynchronized = true;