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::allocateClient() {
27 if (ourClient == NULL) {
28 ourClient = gconf_client_get_default();
32 GConfKey::GConfKey(const std::string& path): myKeyPath(path) {
35 std::string GConfKey::merge(const std::string& path) const {
36 std::string result = myKeyPath;
39 // this is actually a bad situation, what to do??
40 } else if (path[0] == '/') {
50 GConfStringValue::GConfStringValue(const GConfKey& key, const std::string& name, const std::string& defaultValue):
51 GConfOption(key, name),
52 myDefaultValue(defaultValue) {
55 const std::string& GConfStringValue::value() const {
56 if (!myIsSynchronized) {
57 GConfValue *value = getGConfValue(GCONF_VALUE_STRING);
60 myValue = myDefaultValue;
62 myValue = gconf_value_get_string(value);
64 gconf_value_free(value);
67 myIsSynchronized = true;
73 const std::string& GConfStringValue::setValue(const std::string& newValue) {
74 if (!myIsSynchronized || (myValue != newValue)) {
77 if (myValue == myDefaultValue) {
80 GConfValue *value = gconf_value_new(GCONF_VALUE_STRING);
82 gconf_value_set_string(value, myValue.c_str());
86 gconf_value_free(value);
89 myIsSynchronized = true;
95 GConfBooleanValue::GConfBooleanValue(const GConfKey& key, const std::string& name, bool defaultValue):
96 GConfOption(key, name),
97 myDefaultValue(defaultValue) {
100 bool GConfBooleanValue::value() const {
101 if (!myIsSynchronized) {
102 GConfValue *value = getGConfValue(GCONF_VALUE_BOOL);
105 myValue = myDefaultValue;
107 myValue = gconf_value_get_bool(value);
109 gconf_value_free(value);
112 myIsSynchronized = true;
118 bool GConfBooleanValue::setValue(bool newValue) {
119 if (!myIsSynchronized || (myValue != newValue)) {
122 if (myValue == myDefaultValue) {
125 GConfValue *value = gconf_value_new(GCONF_VALUE_BOOL);
127 gconf_value_set_bool(value, myValue);
129 setGConfValue(value);
131 gconf_value_free(value);
134 myIsSynchronized = true;
140 GConfIntegerValue::GConfIntegerValue(const GConfKey& key, const std::string& name, int defaultValue):
141 GConfOption(key, name),
142 myDefaultValue(defaultValue) {
145 int GConfIntegerValue::value() const {
146 if (!myIsSynchronized) {
147 GConfValue *value = getGConfValue(GCONF_VALUE_INT);
150 myValue = myDefaultValue;
152 myValue = gconf_value_get_int(value);
154 gconf_value_free(value);
157 myIsSynchronized = true;
163 int GConfIntegerValue::setValue(int newValue) {
164 if (!myIsSynchronized || (myValue != newValue)) {
167 if (myValue == myDefaultValue) {
170 GConfValue *value = gconf_value_new(GCONF_VALUE_INT);
172 gconf_value_set_int(value, myValue);
174 setGConfValue(value);
176 gconf_value_free(value);
179 myIsSynchronized = true;