added a small todo for future
[simple-launcher] / gconf-wrapper.h
1 // This file is a part of Simple Launcher
2 //
3 // Copyright (C) 2006, 2007, Mikhail Sobolev
4 //
5 // Simple Launcher is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU General Public License version 2 as published by
7 // the Free Software Foundation.
8 //
9 // This program is distributed in the hope that it will be useful, but WITHOUT
10 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12 // more details.
13 //
14 // You should have received a copy of the GNU General Public License along with
15 // this program; if not, write to the Free Software Foundation, Inc., 51
16 // Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18 #ifndef _GCONF_WRAPPER_H_
19 #define _GCONF_WRAPPER_H_
20
21 #include <string>
22
23 #include <gconf/gconf-client.h>
24
25 class GConfItem {
26 public:
27   virtual ~GConfItem() {}
28
29 protected:
30   GConfItem();  // I do not want to create instances of this class
31
32   static void allocateClient();
33
34 protected:
35   // TODO: should I count the references and unref the client when the last user is gone??
36   static GConfClient *ourClient;
37 };
38
39 class GConfKey : public GConfItem {
40 public:
41   GConfKey(const std::string&);
42   GConfKey(const GConfKey&, const std::string&);
43  ~GConfKey() { }
44
45   const std::string& path() const { return myKeyPath; }
46
47   static std::string mergePath(const std::string&, const std::string);
48
49 private:
50   std::string myKeyPath;
51 };
52
53 class GConfOption : public GConfItem {
54 protected:
55   GConfOption(const GConfKey& key, const std::string& path): myIsSynchronized(false), myPath(GConfKey::mergePath(key.path(), path)) { }
56
57   void setGConfValue(const GConfValue *);
58   GConfValue *getGConfValue(GConfValueType) const;
59   void unsetGConfValue();
60
61 protected:
62   mutable bool myIsSynchronized;
63   std::string myPath;
64 };
65
66 class GConfStringValue : public GConfOption {
67 public:
68   GConfStringValue(const GConfKey&, const std::string&, const std::string& = "");
69  ~GConfStringValue();
70
71   const std::string& value() const;
72   const std::string& setValue(const std::string& newValue);
73
74 private:
75   mutable std::string myValue;
76   std::string myDefaultValue;
77 };
78
79 class GConfBooleanValue : public GConfOption {
80 public:
81   GConfBooleanValue(const GConfKey&, const std::string&, bool = false);
82  ~GConfBooleanValue();
83
84   bool value() const;
85   bool setValue(bool newValue);
86
87 private:
88   mutable bool myValue;
89   bool myDefaultValue;
90 };
91
92 class GConfIntegerValue : public GConfOption {
93 public:
94   GConfIntegerValue(const GConfKey&, const std::string&, int = false);
95  ~GConfIntegerValue();
96
97   int value() const;
98   int setValue(int newValue);
99
100 private:
101   mutable int myValue;
102   int myDefaultValue;
103 };
104
105 #endif
106
107 // vim:ts=2:sw=2:et