GConfClient *GConfItem::ourClient = NULL;
GConfItem::GConfItem() {
- validateClient();
+ allocateClient();
}
-void GConfItem::validateClient() {
+void GConfItem::allocateClient() {
if (ourClient == NULL) {
ourClient = gconf_client_get_default();
}
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;
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;
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),
+ myValue(defaultValue),
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;
return myValue;
}
-bool GConfBooleanValue::setValue(bool newValue) {
+bool GConfBooleanOption::setValue(bool newValue) {
if (!myIsSynchronized || (myValue != newValue)) {
myValue = 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),
+ myValue(defaultValue),
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;
return myValue;
}
-int GConfIntegerValue::setValue(int newValue) {
+int GConfIntegerOption::setValue(int newValue) {
if (!myIsSynchronized || (myValue != newValue)) {
myValue = newValue;