changed defaults: non-transparent, iconsize = 48
[simple-launcher] / gconf-wrapper.h
index 7d622e5..be94905 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 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:
-  GConfClientWrapper();
- ~GConfClientWrapper();
+  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;
+};
 
-  GConfKey getKey(const std::string&);
+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:
-  bool getBool(const std::string& name);
-  void setBool(const std::string& name, bool);
+  mutable bool myIsSynchronized;
+  const std::string myPath;
+};
+
+class GConfStringOption : public GConfOption {
+public:
+  GConfStringOption(const GConfKey&, const std::string&, const std::string&);
 
-  int getInt(const std::string& name);
-  void setInt(const std::string& name, int);
+  virtual GConfValueType kind() const { return GCONF_VALUE_STRING; }
+
+  const std::string& value() const;
+  const std::string& setValue(const std::string& newValue);
 
 private:
-  GConfClient *myClient;
+  mutable std::string myValue;
+  const std::string myDefaultValue;
 };
 
-class GConfKey {
+class GConfBooleanOption : public GConfOption {
 public:
-  GConfKey(GConfClientWrapper&, const std::string&);
-  GConfKey(const GConfKey& what) : myWrapper(what.myWrapper), myPath(what.myPath) { }
- ~GConfKey();
+  GConfBooleanOption(const GConfKey&, const std::string&, bool);
+
+  virtual GConfValueType kind() const { return GCONF_VALUE_BOOL; }
+
+  bool value() const;
+  bool setValue(bool newValue);
 
-  GConfKey& operator = (const GConfKey& what) {
-    myWrapper = what.myWrapper;
-    myPath = what.myPath;
+private:
+  mutable bool myValue;
+  const bool myDefaultValue;
+};
 
-    return *this;
-  }
+class GConfIntegerOption : public GConfOption {
+public:
+  GConfIntegerOption(const GConfKey&, const std::string&, int);
 
-  bool getBool(const std::string& name, bool defvalue = false);
-  void setBool(const std::string& name, bool value);
+  virtual GConfValueType kind() const { return GCONF_VALUE_INT; }
 
-  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;
+  const int myDefaultValue;
 };
 
 #endif