setting padding to 0 (instead of 2)
[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   std::string merge(const std::string&) const;
48
49 private:
50   const std::string myKeyPath;
51 };
52
53 class GConfOption : public GConfItem {
54 protected:
55   GConfOption(const GConfKey& key, const std::string& path): myIsSynchronized(false), myPath(key.merge(path)) { }
56
57   virtual GConfValueType kind() const = 0;
58
59   void setGConfValue(const GConfValue *);
60   GConfValue *getGConfValue() const;
61   void unsetGConfValue();
62
63 protected:
64   mutable bool myIsSynchronized;
65   const std::string myPath;
66 };
67
68 class GConfStringOption : public GConfOption {
69 public:
70   GConfStringOption(const GConfKey&, const std::string&, const std::string&);
71
72   virtual GConfValueType kind() const { return GCONF_VALUE_STRING; }
73
74   const std::string& value() const;
75   const std::string& setValue(const std::string& newValue);
76
77 private:
78   mutable std::string myValue;
79   const std::string myDefaultValue;
80 };
81
82 class GConfBooleanOption : public GConfOption {
83 public:
84   GConfBooleanOption(const GConfKey&, const std::string&, bool);
85
86   virtual GConfValueType kind() const { return GCONF_VALUE_BOOL; }
87
88   bool value() const;
89   bool setValue(bool newValue);
90
91 private:
92   mutable bool myValue;
93   const bool myDefaultValue;
94 };
95
96 class GConfIntegerOption : public GConfOption {
97 public:
98   GConfIntegerOption(const GConfKey&, const std::string&, int);
99
100   virtual GConfValueType kind() const { return GCONF_VALUE_INT; }
101
102   int value() const;
103   int setValue(int newValue);
104
105 private:
106   mutable int myValue;
107   const int myDefaultValue;
108 };
109
110 #endif
111
112 // vim:ts=2:sw=2:et