rewrote gconf wrappers (still work in progress and they are not tried yet)
[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 validateClient();
33
34 protected:
35   static GConfClient *ourClient;
36 };
37
38 class GConfKey : public GConfItem {
39 public:
40   GConfKey(const std::string&);
41   GConfKey(const GConfKey&, const std::string&);
42  ~GConfKey() { }
43
44   const std::string& path() const { return myKeyPath; }
45
46   static std::string mergePath(const std::string&, const std::string);
47
48 private:
49   std::string myKeyPath;
50 };
51
52 class GConfOption : public GConfItem {
53 protected:
54   GConfOption(const GConfKey& key, const std::string& path): myIsSynchronized(false), myPath(GConfKey::mergePath(key.path(), path)) { }
55
56   void setGConfValue(const GConfValue *);
57   GConfValue *getGConfValue(GConfValueType) const;
58   void unsetGConfValue();
59
60 protected:
61   mutable bool myIsSynchronized;
62   std::string myPath;
63 };
64
65 class GConfStringValue : public GConfOption {
66 public:
67   GConfStringValue(const GConfKey&, const std::string&, const std::string& = "");
68  ~GConfStringValue();
69
70   const std::string& value() const;
71   const std::string& setValue(const std::string& newValue);
72
73 private:
74   mutable std::string myValue;
75   std::string myDefaultValue;
76 };
77
78 class GConfBooleanValue : public GConfOption {
79 public:
80   GConfBooleanValue(const GConfKey&, const std::string&, bool = false);
81  ~GConfBooleanValue();
82
83   bool value() const;
84   bool setValue(bool newValue);
85
86 private:
87   mutable bool myValue;
88   bool myDefaultValue;
89 };
90
91 class GConfIntegerValue : public GConfOption {
92 public:
93   GConfIntegerValue(const GConfKey&, const std::string&, int = false);
94  ~GConfIntegerValue();
95
96   int value() const;
97   int setValue(int newValue);
98
99 private:
100   mutable int myValue;
101   int myDefaultValue;
102 };
103
104 #endif
105
106 // vim:ts=2:sw=2:et