preparation for new hildon (desktop and widgets) support
[simple-launcher] / gconf-wrapper.cc
index cad3e04..44bd35e 100644 (file)
@@ -47,14 +47,61 @@ std::string GConfKey::merge(const std::string& path) const {
   return result;
 }
 
-GConfStringValue::GConfStringValue(const GConfKey& key, const std::string& name, const std::string& defaultValue):
+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;
@@ -70,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;
 
@@ -92,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;
@@ -115,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;
 
@@ -137,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;
@@ -160,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;