From: mishas Date: Thu, 12 Apr 2007 08:27:57 +0000 (+0000) Subject: * GConfOption now knows what type it is X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;ds=sidebyside;h=e1fe4eeb4079792c6be4d47694a7288ef79d423d;p=simple-launcher * GConfOption now knows what type it is * we do not need to pass it getGConfValue any more * we can use it later :)) * implemented setGConfValue, getGConfValue, unsetGConfValue methods git-svn-id: file:///svnroot/simple-launcher/trunk@171 3ba93dab-e023-0410-b42a-de7732cf370a --- diff --git a/gconf-wrapper.cc b/gconf-wrapper.cc index cad3e04..37a573e 100644 --- a/gconf-wrapper.cc +++ b/gconf-wrapper.cc @@ -47,14 +47,61 @@ std::string GConfKey::merge(const std::string& path) const { 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); + } +} + GConfStringValue::GConfStringValue(const GConfKey& key, const std::string& name, const std::string& defaultValue): - GConfOption(key, name), + GConfOption(GCONF_VALUE_STRING, key, name), myDefaultValue(defaultValue) { } const std::string& GConfStringValue::value() const { if (!myIsSynchronized) { - GConfValue *value = getGConfValue(GCONF_VALUE_STRING); + GConfValue *value = getGConfValue(); if (value == NULL) { myValue = myDefaultValue; @@ -93,13 +140,13 @@ const std::string& GConfStringValue::setValue(const std::string& newValue) { } GConfBooleanValue::GConfBooleanValue(const GConfKey& key, const std::string& name, bool defaultValue): - GConfOption(key, name), + GConfOption(GCONF_VALUE_BOOL, key, name), myDefaultValue(defaultValue) { } bool GConfBooleanValue::value() const { if (!myIsSynchronized) { - GConfValue *value = getGConfValue(GCONF_VALUE_BOOL); + GConfValue *value = getGConfValue(); if (value == NULL) { myValue = myDefaultValue; @@ -138,13 +185,13 @@ bool GConfBooleanValue::setValue(bool newValue) { } GConfIntegerValue::GConfIntegerValue(const GConfKey& key, const std::string& name, int defaultValue): - GConfOption(key, name), + GConfOption(GCONF_VALUE_INT, key, name), myDefaultValue(defaultValue) { } int GConfIntegerValue::value() const { if (!myIsSynchronized) { - GConfValue *value = getGConfValue(GCONF_VALUE_INT); + GConfValue *value = getGConfValue(); if (value == NULL) { myValue = myDefaultValue; diff --git a/gconf-wrapper.h b/gconf-wrapper.h index a3e4518..ab52c5a 100644 --- a/gconf-wrapper.h +++ b/gconf-wrapper.h @@ -52,15 +52,18 @@ private: class GConfOption : public GConfItem { protected: - GConfOption(const GConfKey& key, const std::string& path): myIsSynchronized(false), myPath(key.merge(path)) { } + GConfOption(GConfValueType kind, const GConfKey& key, const std::string& path): myKind(kind), myIsSynchronized(false), myPath(key.merge(path)) { } + + GConfValueType kind() const { return myKind; } void setGConfValue(const GConfValue *); - GConfValue *getGConfValue(GConfValueType) const; + GConfValue *getGConfValue() const; void unsetGConfValue(); protected: + const GConfValueType myKind; mutable bool myIsSynchronized; - std::string myPath; + const std::string myPath; }; class GConfStringValue : public GConfOption {