HAAS Stereo Enhancer
[calf.git] / src / calf / gui_config.h
blob6e781a81406197483ccccf30cc7c79b8680d6d3c
1 #ifndef CALF_GUI_CONFIG_H
2 #define CALF_GUI_CONFIG_H
4 #include <glib.h>
5 #include <string>
6 #include <vector>
8 namespace calf_utils {
10 struct config_exception: public std::exception
12 std::string content;
13 const char *content_ptr;
14 config_exception(const std::string &text) : content(text) { content_ptr = content.c_str(); }
15 virtual const char *what() const throw() { return content_ptr; }
16 virtual ~config_exception() throw() { }
19 struct config_listener_iface
21 virtual void on_config_change() = 0;
22 virtual ~config_listener_iface() {}
25 struct config_notifier_iface
27 virtual ~config_notifier_iface() {}
30 struct config_db_iface
32 virtual bool has_dir(const char *key) = 0;
33 virtual bool get_bool(const char *key, bool def_value) = 0;
34 virtual int get_int(const char *key, int def_value) = 0;
35 virtual std::string get_string(const char *key, const std::string &def_value) = 0;
36 virtual void set_bool(const char *key, bool value) = 0;
37 virtual void set_int(const char *key, int value) = 0;
38 virtual void set_string(const char *key, const std::string &value) = 0;
39 virtual void save() = 0;
40 virtual config_notifier_iface *add_listener(config_listener_iface *listener) = 0;
41 virtual ~config_db_iface() {}
44 class gkeyfile_config_db: public config_db_iface
46 protected:
47 class notifier: public config_notifier_iface
49 protected:
50 gkeyfile_config_db *parent;
51 config_listener_iface *listener;
52 notifier(gkeyfile_config_db *_parent, config_listener_iface *_listener);
53 virtual ~notifier();
54 friend class gkeyfile_config_db;
56 protected:
57 GKeyFile *keyfile;
58 std::string filename;
59 std::string section;
60 std::vector<notifier *> notifiers;
62 void handle_error(GError *error);
63 void remove_notifier(notifier *n);
64 friend class notifier;
65 public:
66 gkeyfile_config_db(GKeyFile *kf, const char *filename, const char *section);
67 virtual bool has_dir(const char *key);
68 virtual bool get_bool(const char *key, bool def_value);
69 virtual int get_int(const char *key, int def_value);
70 virtual std::string get_string(const char *key, const std::string &def_value);
71 virtual void set_bool(const char *key, bool value);
72 virtual void set_int(const char *key, int value);
73 virtual void set_string(const char *key, const std::string &value);
74 virtual void save();
75 virtual config_notifier_iface *add_listener(config_listener_iface *listener);
76 virtual ~gkeyfile_config_db();
79 struct gui_config
81 int rack_float, float_size;
82 bool rack_ears;
83 bool vu_meters;
85 gui_config();
86 ~gui_config();
87 void load(config_db_iface *db);
88 void save(config_db_iface *db);
93 #endif