preparation for new hildon (desktop and widgets) support
[simple-launcher] / gconf-wrapper.cc
index e1120d6..44bd35e 100644 (file)
@@ -32,14 +32,76 @@ void GConfItem::allocateClient() {
 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,15 @@ 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),
+  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;
@@ -100,7 +163,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 +185,15 @@ 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),
+  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;
@@ -145,7 +209,7 @@ int GConfIntegerValue::value() const {
   return myValue;
 }
 
-int GConfIntegerValue::setValue(int newValue) {
+int GConfIntegerOption::setValue(int newValue) {
   if (!myIsSynchronized || (myValue != newValue)) {
     myValue = newValue;