1 #include <calf/gui_config.h>
6 using namespace calf_utils
;
8 gui_config::gui_config()
14 style
= "Calf_Default";
17 gui_config::~gui_config()
21 void gui_config::load(config_db_iface
*db
)
23 rack_float
= db
->get_int("rack-float", gui_config().rack_float
);
24 float_size
= db
->get_int("float-size", gui_config().float_size
);
25 rack_ears
= db
->get_bool("show-rack-ears", gui_config().rack_ears
);
26 vu_meters
= db
->get_bool("show-vu-meters", gui_config().vu_meters
);
27 style
= db
->get_string("style", gui_config().style
);
30 void gui_config::save(config_db_iface
*db
)
32 db
->set_int("rack-float", rack_float
);
33 db
->set_int("float-size", float_size
);
34 db
->set_bool("show-rack-ears", rack_ears
);
35 db
->set_bool("show-vu-meters", vu_meters
);
36 db
->set_string("style", style
);
40 ////////////////////////////////////////////////////////////////////////////////////////////////////
42 gkeyfile_config_db::notifier::notifier(gkeyfile_config_db
*_parent
, config_listener_iface
*_listener
)
48 gkeyfile_config_db::notifier::~notifier()
50 parent
->remove_notifier(this);
54 ////////////////////////////////////////////////////////////////////////////////////////////////////
56 gkeyfile_config_db::gkeyfile_config_db(GKeyFile
*kf
, const char *_filename
, const char *_section
)
63 void gkeyfile_config_db::handle_error(GError
*error
)
67 string msg
= error
->message
;
69 throw config_exception(msg
.c_str());
73 void gkeyfile_config_db::remove_notifier(notifier
*n
)
75 for (size_t i
= 0; i
< notifiers
.size(); i
++)
77 if (notifiers
[i
] == n
)
79 notifiers
.erase(notifiers
.begin() + i
);
86 bool gkeyfile_config_db::has_dir(const char *key
)
88 return g_key_file_has_group(keyfile
, key
);
91 static bool check_not_found_and_delete(GError
*error
)
93 if (error
&& error
->domain
== G_KEY_FILE_ERROR
)
97 case G_KEY_FILE_ERROR_KEY_NOT_FOUND
:
98 case G_KEY_FILE_ERROR_GROUP_NOT_FOUND
:
108 bool gkeyfile_config_db::get_bool(const char *key
, bool def_value
)
111 bool value
= (bool)g_key_file_get_boolean(keyfile
, section
.c_str(), key
, &err
);
114 if (check_not_found_and_delete(err
))
121 int gkeyfile_config_db::get_int(const char *key
, int def_value
)
124 int value
= g_key_file_get_integer(keyfile
, section
.c_str(), key
, &err
);
127 if (check_not_found_and_delete(err
))
134 std::string
gkeyfile_config_db::get_string(const char *key
, const std::string
&def_value
)
137 gchar
*value
= g_key_file_get_string(keyfile
, section
.c_str(), key
, &err
);
140 if (check_not_found_and_delete(err
))
147 void gkeyfile_config_db::set_bool(const char *key
, bool value
)
149 g_key_file_set_boolean(keyfile
, section
.c_str(), key
, (gboolean
)value
);
152 void gkeyfile_config_db::set_int(const char *key
, int value
)
154 g_key_file_set_integer(keyfile
, section
.c_str(), key
, value
);
157 void gkeyfile_config_db::set_string(const char *key
, const std::string
&value
)
159 g_key_file_set_string(keyfile
, section
.c_str(), key
, value
.c_str());
162 void gkeyfile_config_db::save()
166 gchar
*data
= g_key_file_to_data(keyfile
, &length
, &err
);
170 if (!g_file_set_contents(filename
.c_str(), data
, length
, &err
))
177 for (size_t i
= 0; i
< notifiers
.size(); i
++)
178 notifiers
[i
]->listener
->on_config_change();
181 config_notifier_iface
*gkeyfile_config_db::add_listener(config_listener_iface
*listener
)
183 notifier
*n
= new notifier(this, listener
);
184 notifiers
.push_back(n
);
188 gkeyfile_config_db::~gkeyfile_config_db()