fix two potential memory leaks
[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 GConfClientWrapper {
26   friend class GConfKey;
27
28 public:
29   GConfClientWrapper();
30  ~GConfClientWrapper();
31
32   GConfKey getKey(const std::string&);
33
34 protected:
35   bool getBool(const std::string& name);
36   void setBool(const std::string& name, bool);
37
38   int getInt(const std::string& name);
39   void setInt(const std::string& name, int);
40
41 private:
42   GConfClient *myClient;
43 };
44
45 class GConfKey {
46 public:
47   GConfKey(GConfClientWrapper&, const std::string&);
48   GConfKey(const GConfKey& what) : myWrapper(what.myWrapper), myPath(what.myPath) { }
49  ~GConfKey();
50
51   GConfKey& operator = (const GConfKey& what) {
52     myWrapper = what.myWrapper;
53     myPath = what.myPath;
54
55     return *this;
56   }
57
58   bool getBool(const std::string& name, bool defvalue = false);
59   void setBool(const std::string& name, bool value);
60
61   int getInt(const std::string& name, int defvalue = 0);
62   void setInt(const std::string& name, int value);
63
64 private:
65   GConfClientWrapper& myWrapper;
66   std::string myPath;
67 };
68
69 #endif
70
71 // vim:ts=2:sw=2:et