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;
}
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;
}
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;
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 {