* GConfOption now knows what type it is
authormishas <mikhail.sobolev@gmail.com>
Thu, 12 Apr 2007 08:27:57 +0000 (08:27 +0000)
committermishas <mikhail.sobolev@gmail.com>
Thu, 12 Apr 2007 08:27:57 +0000 (08:27 +0000)
 * 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

gconf-wrapper.cc
gconf-wrapper.h

index cad3e04..37a573e 100644 (file)
@@ -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;
index a3e4518..ab52c5a 100644 (file)
@@ -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 {