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