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 void GConfOption::setGConfValue(const GConfValue *value) {
53 gconf_client_set(ourClient, myPath.c_str(), value, &error);
60 GConfValue *GConfOption::getGConfValue() const {
61 GConfValue *result = NULL;
64 result = gconf_client_get_without_default(ourClient, myPath.c_str(), &error);
70 gconf_value_free(result);
76 if (result->type != kind()) {
77 gconf_value_free(result);
86 void GConfOption::unsetGConfValue() {
89 // TODO: should I be picky about errors?
90 gconf_client_unset(ourClient, myPath.c_str(), &error);
97 GConfStringOption::GConfStringOption(const GConfKey& key, const std::string& name, const std::string& defaultValue):
98 GConfOption(key, name),
99 myDefaultValue(defaultValue) {
102 const std::string& GConfStringOption::value() const {
103 if (!myIsSynchronized) {
104 GConfValue *value = getGConfValue();
107 myValue = myDefaultValue;
109 myValue = gconf_value_get_string(value);
111 gconf_value_free(value);
114 myIsSynchronized = true;
120 const std::string& GConfStringOption::setValue(const std::string& newValue) {
121 if (!myIsSynchronized || (myValue != newValue)) {
124 if (myValue == myDefaultValue) {
127 GConfValue *value = gconf_value_new(GCONF_VALUE_STRING);
129 gconf_value_set_string(value, myValue.c_str());
131 setGConfValue(value);
133 gconf_value_free(value);
136 myIsSynchronized = true;
142 GConfBooleanOption::GConfBooleanOption(const GConfKey& key, const std::string& name, bool defaultValue):
143 GConfOption(key, name),
144 myDefaultValue(defaultValue) {
147 bool GConfBooleanOption::value() const {
148 if (!myIsSynchronized) {
149 GConfValue *value = getGConfValue();
152 myValue = myDefaultValue;
154 myValue = gconf_value_get_bool(value);
156 gconf_value_free(value);
159 myIsSynchronized = true;
165 bool GConfBooleanOption::setValue(bool newValue) {
166 if (!myIsSynchronized || (myValue != newValue)) {
169 if (myValue == myDefaultValue) {
172 GConfValue *value = gconf_value_new(GCONF_VALUE_BOOL);
174 gconf_value_set_bool(value, myValue);
176 setGConfValue(value);
178 gconf_value_free(value);
181 myIsSynchronized = true;
187 GConfIntegerOption::GConfIntegerOption(const GConfKey& key, const std::string& name, int defaultValue):
188 GConfOption(key, name),
189 myDefaultValue(defaultValue) {
192 int GConfIntegerOption::value() const {
193 if (!myIsSynchronized) {
194 GConfValue *value = getGConfValue();
197 myValue = myDefaultValue;
199 myValue = gconf_value_get_int(value);
201 gconf_value_free(value);
204 myIsSynchronized = true;
210 int GConfIntegerOption::setValue(int newValue) {
211 if (!myIsSynchronized || (myValue != newValue)) {
214 if (myValue == myDefaultValue) {
217 GConfValue *value = gconf_value_new(GCONF_VALUE_INT);
219 gconf_value_set_int(value, myValue);
221 setGConfValue(value);
223 gconf_value_free(value);
226 myIsSynchronized = true;