started to fill in the application item
[simple-launcher] / gconf-wrapper.h
index 6cc0a4c..be94905 100644 (file)
 
 #include <string>
 
-class GConfWrapper {
+#include <gconf/gconf-client.h>
+
+class GConfItem {
+public:
+  virtual ~GConfItem() {}
+
+protected:
+  GConfItem();  // I do not want to create instances of this class
+
+  static void allocateClient();
+
+protected:
+  // TODO: should I count the references and unref the client when the last user is gone??
+  static GConfClient *ourClient;
+};
+
+class GConfKey : public GConfItem {
 public:
-  GConfWrapper(const std::string&);
- ~GConfWrapper();
+  GConfKey(const std::string&);
+  GConfKey(const GConfKey&, const std::string&);
+ ~GConfKey() { }
+
+  const std::string& path() const { return myKeyPath; }
+
+  std::string merge(const std::string&) const;
+
+private:
+  const std::string myKeyPath;
+};
+
+class GConfOption : public GConfItem {
+protected:
+  GConfOption(const GConfKey& key, const std::string& path): myIsSynchronized(false), myPath(key.merge(path)) { }
+
+  virtual GConfValueType kind() const = 0;
+
+  void setGConfValue(const GConfValue *);
+  GConfValue *getGConfValue() const;
+  void unsetGConfValue();
+
+protected:
+  mutable bool myIsSynchronized;
+  const std::string myPath;
+};
+
+class GConfStringOption : public GConfOption {
+public:
+  GConfStringOption(const GConfKey&, const std::string&, const std::string&);
+
+  virtual GConfValueType kind() const { return GCONF_VALUE_STRING; }
+
+  const std::string& value() const;
+  const std::string& setValue(const std::string& newValue);
+
+private:
+  mutable std::string myValue;
+  const std::string myDefaultValue;
+};
+
+class GConfBooleanOption : public GConfOption {
+public:
+  GConfBooleanOption(const GConfKey&, const std::string&, bool);
+
+  virtual GConfValueType kind() const { return GCONF_VALUE_BOOL; }
+
+  bool value() const;
+  bool setValue(bool newValue);
+
+private:
+  mutable bool myValue;
+  const bool myDefaultValue;
+};
+
+class GConfIntegerOption : public GConfOption {
+public:
+  GConfIntegerOption(const GConfKey&, const std::string&, int);
+
+  virtual GConfValueType kind() const { return GCONF_VALUE_INT; }
 
-  bool getBool(const std::string& name);
-  void setBool(const std::string& name, bool);
+  int value() const;
+  int setValue(int newValue);
 
-  int getInt(const std::string& name);
-  void setInt(const std::string& name, int);
+private:
+  mutable int myValue;
+  const int myDefaultValue;
 };
 
 #endif