1 #ifndef CALF_GUI_CONFIG_H 2 #define CALF_GUI_CONFIG_H 3 4 #include <glib.h> 5 #include <string> 6 #include <vector> 7 8 namespace calf_utils { 9 10 struct config_exception: public std::exception 11 { 12 std::string content; 13 const char *content_ptr; config_exceptionconfig_exception14 config_exception(const std::string &text) : content(text) { content_ptr = content.c_str(); } whatconfig_exception15 virtual const char *what() const throw() { return content_ptr; } ~config_exceptionconfig_exception16 virtual ~config_exception() throw() { } 17 }; 18 19 struct config_listener_iface 20 { 21 virtual void on_config_change() = 0; ~config_listener_ifaceconfig_listener_iface22 virtual ~config_listener_iface() {} 23 }; 24 25 struct config_notifier_iface 26 { ~config_notifier_ifaceconfig_notifier_iface27 virtual ~config_notifier_iface() {} 28 }; 29 30 struct config_db_iface 31 { 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; ~config_db_ifaceconfig_db_iface41 virtual ~config_db_iface() {} 42 }; 43 44 class gkeyfile_config_db: public config_db_iface 45 { 46 protected: 47 class notifier: public config_notifier_iface 48 { 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; 55 }; 56 protected: 57 GKeyFile *keyfile; 58 std::string filename; 59 std::string section; 60 std::vector<notifier *> notifiers; 61 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(); 77 }; 78 79 struct gui_config 80 { 81 int rack_float, float_size; 82 bool rack_ears; 83 bool vu_meters; 84 bool win_to_tray; 85 bool win_start_hidden; 86 std::string style; 87 88 gui_config(); 89 ~gui_config(); 90 void load(config_db_iface *db); 91 void save(config_db_iface *db); 92 }; 93 94 }; 95 96 #endif 97