rewrote gconf wrappers (still work in progress and they are not tried yet)
[simple-launcher] / gconf-wrapper.h
index 7d622e5..a62fc56 100644 (file)
 
 #include <gconf/gconf-client.h>
 
-class GConfClientWrapper {
-  friend class GConfKey;
+class GConfItem {
+public:
+  virtual ~GConfItem() {}
+
+protected:
+  GConfItem();  // I do not want to create instances of this class
 
+  static void validateClient();
+
+protected:
+  static GConfClient *ourClient;
+};
+
+class GConfKey : public GConfItem {
 public:
-  GConfClientWrapper();
- ~GConfClientWrapper();
+  GConfKey(const std::string&);
+  GConfKey(const GConfKey&, const std::string&);
+ ~GConfKey() { }
+
+  const std::string& path() const { return myKeyPath; }
+
+  static std::string mergePath(const std::string&, const std::string);
+
+private:
+  std::string myKeyPath;
+};
+
+class GConfOption : public GConfItem {
+protected:
+  GConfOption(const GConfKey& key, const std::string& path): myIsSynchronized(false), myPath(GConfKey::mergePath(key.path(), path)) { }
 
-  GConfKey getKey(const std::string&);
+  void setGConfValue(const GConfValue *);
+  GConfValue *getGConfValue(GConfValueType) const;
+  void unsetGConfValue();
 
 protected:
-  bool getBool(const std::string& name);
-  void setBool(const std::string& name, bool);
+  mutable bool myIsSynchronized;
+  std::string myPath;
+};
 
-  int getInt(const std::string& name);
-  void setInt(const std::string& name, int);
+class GConfStringValue : public GConfOption {
+public:
+  GConfStringValue(const GConfKey&, const std::string&, const std::string& = "");
+ ~GConfStringValue();
+
+  const std::string& value() const;
+  const std::string& setValue(const std::string& newValue);
 
 private:
-  GConfClient *myClient;
+  mutable std::string myValue;
+  std::string myDefaultValue;
 };
 
-class GConfKey {
+class GConfBooleanValue : public GConfOption {
 public:
-  GConfKey(GConfClientWrapper&, const std::string&);
-  GConfKey(const GConfKey& what) : myWrapper(what.myWrapper), myPath(what.myPath) { }
- ~GConfKey();
+  GConfBooleanValue(const GConfKey&, const std::string&, bool = false);
+ ~GConfBooleanValue();
 
-  GConfKey& operator = (const GConfKey& what) {
-    myWrapper = what.myWrapper;
-    myPath = what.myPath;
+  bool value() const;
+  bool setValue(bool newValue);
 
-    return *this;
-  }
+private:
+  mutable bool myValue;
+  bool myDefaultValue;
+};
 
-  bool getBool(const std::string& name, bool defvalue = false);
-  void setBool(const std::string& name, bool value);
+class GConfIntegerValue : public GConfOption {
+public:
+  GConfIntegerValue(const GConfKey&, const std::string&, int = false);
+ ~GConfIntegerValue();
 
-  int getInt(const std::string& name, int defvalue = 0);
-  void setInt(const std::string& name, int value);
+  int value() const;
+  int setValue(int newValue);
 
 private:
-  GConfClientWrapper& myWrapper;
-  std::string myPath;
+  mutable int myValue;
+  int myDefaultValue;
 };
 
 #endif