]> icculus.org git repositories - mikachu/openbox.git/blob - otk/configuration.hh
move the Openbox::instance pointer to simply "openbox".
[mikachu/openbox.git] / otk / configuration.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __configuration_hh
3 #define   __configuration_hh
4
5 /*! @file configuration.hh
6   @brief Loads, saves, and provides configuration options for the window
7          manager
8 */
9
10 extern "C" {
11 #include <X11/Xlib.h>
12 #include <X11/Xresource.h>
13 }
14
15 #include <string>
16
17 namespace otk {
18
19 /*
20  * The Configuration class is a generic wrapper for configuration settings.
21  *
22  * This class is used for the global rc/config file, and for styles.
23  *
24  * This implementation of the Configuration class wraps an X resource database
25  * file.
26  */
27 class Configuration {
28 public:
29   explicit Configuration(const std::string &file, bool autosave = True);
30   Configuration(bool autosave = True);
31   virtual ~Configuration();
32
33   inline const std::string &file() const {
34     return static_cast<const std::string &>(_file);
35   }
36   void setFile(const std::string &file);
37
38   // defaults to true!
39   inline bool autoSave() const {
40     return _autosave;
41   }
42   void setAutoSave(bool);
43
44   inline bool isModified() const {
45     return _modified;
46   }
47
48   void save();
49   bool load();
50   bool merge(const std::string &file, bool overwrite = False);
51   void create();
52
53   void setValue(const std::string &rname, bool value);
54   inline void setValue(const std::string &rname, int value) {
55     setValue(rname, (long) value);
56   }
57   inline void setValue(const std::string &rname, unsigned int value) {
58     setValue(rname, (unsigned long) value);
59   }
60   void setValue(const std::string &rname, long value);
61   void setValue(const std::string &rname, unsigned long value);
62   void setValue(const std::string &rname, const std::string &value);
63   void setValue(const std::string &rname, const char *value);
64
65   bool getValue(const std::string &rname, bool &value) const;
66   inline bool getValue(const std::string &rname, int &value) const {
67     return getValue(rname, (long) value);
68   }
69   inline bool getValue(const std::string &rname, unsigned int &value) const {
70     return getValue(rname, (unsigned long) value);
71   }
72   bool getValue(const std::string &rname, long &value) const;
73   bool getValue(const std::string &rname, unsigned long &value) const;
74   bool getValue(const std::string &rname, std::string &value) const;
75
76 private:
77   std::string createClassName(const std::string &rname) const;
78   char toUpper(char) const;
79   
80   static bool _initialized;
81   std::string _file;
82   bool _modified;
83   bool _autosave;
84   XrmDatabase _database;
85 };
86
87 }
88
89 #endif // __configuration_hh