X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=gconf-wrapper.cc;h=8ad3ddac35f7896c08870c710541f26b2406ca77;hb=30a96982c959f9c5d99cbb6e980a938608844dee;hp=6b487753bcd1bce43c50b7f857735b0221dbe86a;hpb=d2b872b02e5b31055d3788fdabfe0d1fa563591d;p=simple-launcher diff --git a/gconf-wrapper.cc b/gconf-wrapper.cc index 6b48775..8ad3dda 100644 --- a/gconf-wrapper.cc +++ b/gconf-wrapper.cc @@ -20,10 +20,10 @@ GConfClient *GConfItem::ourClient = NULL; GConfItem::GConfItem() { - validateClient(); + allocateClient(); } -void GConfItem::validateClient() { +void GConfItem::allocateClient() { if (ourClient == NULL) { ourClient = gconf_client_get_default(); } @@ -32,14 +32,76 @@ void GConfItem::validateClient() { GConfKey::GConfKey(const std::string& path): myKeyPath(path) { } -GConfStringValue::GConfStringValue(const GConfKey& key, const std::string& name, const std::string& defaultValue): +std::string GConfKey::merge(const std::string& path) const { + std::string result = myKeyPath; + + if (path.empty()) { + // this is actually a bad situation, what to do?? + } else if (path[0] == '/') { + result.append(path); + } else { + result.append("/"); + result.append(path); + } + + return result; +} + +void GConfOption::setGConfValue(const GConfValue *value) { + GError *error = NULL; + + gconf_client_set(ourClient, myPath.c_str(), value, &error); + + if (error != NULL) { + g_error_free(error); + } +} + +GConfValue *GConfOption::getGConfValue() const { + GConfValue *result = NULL; + GError *error = NULL; + + result = gconf_client_get_without_default(ourClient, myPath.c_str(), &error); + + if (error != NULL) { + g_error_free(error); + + if (result != NULL) { + gconf_value_free(result); + result = NULL; + } + } + + if (result != NULL) { + if (result->type != kind()) { + gconf_value_free(result); + + result = 0; + } + } + + return result; +} + +void GConfOption::unsetGConfValue() { + GError *error = NULL; + + // TODO: should I be picky about errors? + gconf_client_unset(ourClient, myPath.c_str(), &error); + + if (error != NULL) { + g_error_free(error); + } +} + +GConfStringOption::GConfStringOption(const GConfKey& key, const std::string& name, const std::string& defaultValue): GConfOption(key, name), myDefaultValue(defaultValue) { } -const std::string& GConfStringValue::value() const { +const std::string& GConfStringOption::value() const { if (!myIsSynchronized) { - GConfValue *value = getGConfValue(GCONF_VALUE_STRING); + GConfValue *value = getGConfValue(); if (value == NULL) { myValue = myDefaultValue; @@ -55,7 +117,7 @@ const std::string& GConfStringValue::value() const { return myValue; } -const std::string& GConfStringValue::setValue(const std::string& newValue) { +const std::string& GConfStringOption::setValue(const std::string& newValue) { if (!myIsSynchronized || (myValue != newValue)) { myValue = newValue; @@ -77,14 +139,14 @@ const std::string& GConfStringValue::setValue(const std::string& newValue) { return myValue; } -GConfBooleanValue::GConfBooleanValue(const GConfKey& key, const std::string& name, bool defaultValue): +GConfBooleanOption::GConfBooleanOption(const GConfKey& key, const std::string& name, bool defaultValue): GConfOption(key, name), myDefaultValue(defaultValue) { } -bool GConfBooleanValue::value() const { +bool GConfBooleanOption::value() const { if (!myIsSynchronized) { - GConfValue *value = getGConfValue(GCONF_VALUE_BOOL); + GConfValue *value = getGConfValue(); if (value == NULL) { myValue = myDefaultValue; @@ -100,7 +162,7 @@ bool GConfBooleanValue::value() const { return myValue; } -bool GConfBooleanValue::setValue(bool newValue) { +bool GConfBooleanOption::setValue(bool newValue) { if (!myIsSynchronized || (myValue != newValue)) { myValue = newValue; @@ -122,14 +184,14 @@ bool GConfBooleanValue::setValue(bool newValue) { return myValue; } -GConfIntegerValue::GConfIntegerValue(const GConfKey& key, const std::string& name, int defaultValue): +GConfIntegerOption::GConfIntegerOption(const GConfKey& key, const std::string& name, int defaultValue): GConfOption(key, name), myDefaultValue(defaultValue) { } -int GConfIntegerValue::value() const { +int GConfIntegerOption::value() const { if (!myIsSynchronized) { - GConfValue *value = getGConfValue(GCONF_VALUE_INT); + GConfValue *value = getGConfValue(); if (value == NULL) { myValue = myDefaultValue; @@ -145,7 +207,7 @@ int GConfIntegerValue::value() const { return myValue; } -int GConfIntegerValue::setValue(int newValue) { +int GConfIntegerOption::setValue(int newValue) { if (!myIsSynchronized || (myValue != newValue)) { myValue = newValue;