1 #include <calf/gui_config.h>
6 using namespace calf_utils
;
8 gui_config::gui_config()
16 gui_config::~gui_config()
20 void gui_config::load(config_db_iface
*db
)
22 rack_float
= db
->get_int("rack-float", gui_config().rack_float
);
23 float_size
= db
->get_int("float-size", gui_config().float_size
);
24 rack_ears
= db
->get_bool("show-rack-ears", gui_config().rack_ears
);
25 vu_meters
= db
->get_bool("show-vu-meters", gui_config().vu_meters
);
28 void gui_config::save(config_db_iface
*db
)
30 db
->set_int("rack-float", rack_float
);
31 db
->set_int("float-size", float_size
);
32 db
->set_bool("show-rack-ears", rack_ears
);
33 db
->set_bool("show-vu-meters", vu_meters
);
37 ////////////////////////////////////////////////////////////////////////////////////////////////////
39 gkeyfile_config_db::notifier::notifier(gkeyfile_config_db
*_parent
, config_listener_iface
*_listener
)
45 gkeyfile_config_db::notifier::~notifier()
47 parent
->remove_notifier(this);
51 ////////////////////////////////////////////////////////////////////////////////////////////////////
53 gkeyfile_config_db::gkeyfile_config_db(GKeyFile
*kf
, const char *_filename
, const char *_section
)
60 void gkeyfile_config_db::handle_error(GError
*error
)
64 string msg
= error
->message
;
66 throw config_exception(msg
.c_str());
70 void gkeyfile_config_db::remove_notifier(notifier
*n
)
72 for (size_t i
= 0; i
< notifiers
.size(); i
++)
74 if (notifiers
[i
] == n
)
76 notifiers
.erase(notifiers
.begin() + i
);
83 bool gkeyfile_config_db::has_dir(const char *key
)
85 return g_key_file_has_group(keyfile
, key
);
88 static bool check_not_found_and_delete(GError
*error
)
90 if (error
&& error
->domain
== G_KEY_FILE_ERROR
)
94 case G_KEY_FILE_ERROR_KEY_NOT_FOUND
:
95 case G_KEY_FILE_ERROR_GROUP_NOT_FOUND
:
105 bool gkeyfile_config_db::get_bool(const char *key
, bool def_value
)
108 bool value
= (bool)g_key_file_get_boolean(keyfile
, section
.c_str(), key
, &err
);
111 if (check_not_found_and_delete(err
))
118 int gkeyfile_config_db::get_int(const char *key
, int def_value
)
121 int value
= g_key_file_get_integer(keyfile
, section
.c_str(), key
, &err
);
124 if (check_not_found_and_delete(err
))
131 std::string
gkeyfile_config_db::get_string(const char *key
, const std::string
&def_value
)
134 gchar
*value
= g_key_file_get_string(keyfile
, section
.c_str(), key
, &err
);
137 if (check_not_found_and_delete(err
))
144 void gkeyfile_config_db::set_bool(const char *key
, bool value
)
146 g_key_file_set_boolean(keyfile
, section
.c_str(), key
, (gboolean
)value
);
149 void gkeyfile_config_db::set_int(const char *key
, int value
)
151 g_key_file_set_integer(keyfile
, section
.c_str(), key
, value
);
154 void gkeyfile_config_db::set_string(const char *key
, const std::string
&value
)
156 g_key_file_set_string(keyfile
, section
.c_str(), key
, value
.c_str());
159 void gkeyfile_config_db::save()
163 gchar
*data
= g_key_file_to_data(keyfile
, &length
, &err
);
167 if (!g_file_set_contents(filename
.c_str(), data
, length
, &err
))
174 for (size_t i
= 0; i
< notifiers
.size(); i
++)
175 notifiers
[i
]->listener
->on_config_change();
178 config_notifier_iface
*gkeyfile_config_db::add_listener(config_listener_iface
*listener
)
180 notifier
*n
= new notifier(this, listener
);
181 notifiers
.push_back(n
);
185 gkeyfile_config_db::~gkeyfile_config_db()