mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Implement set/get_ui_config and use those methods if config string starts with 'ui.'
This commit is contained in:
@@ -149,9 +149,13 @@ pub unsafe extern "C" fn dc_set_config(
|
||||
}
|
||||
|
||||
let context = &*context;
|
||||
|
||||
match config::Config::from_str(dc_tools::as_str(key)) {
|
||||
Ok(key) => context.set_config(key, as_opt_str(value)).is_ok() as libc::c_int,
|
||||
let key = dc_tools::as_str(key);
|
||||
let value = as_opt_str(value);
|
||||
if key.starts_with(".ui") {
|
||||
return context.set_ui_config(key, value).is_ok() as libc::c_int;
|
||||
}
|
||||
match config::Config::from_str(key) {
|
||||
Ok(key) => context.set_config(key, value).is_ok() as libc::c_int,
|
||||
Err(_) => 0,
|
||||
}
|
||||
}
|
||||
@@ -168,7 +172,11 @@ pub unsafe extern "C" fn dc_get_config(
|
||||
|
||||
let context = &*context;
|
||||
|
||||
let key = config::Config::from_str(dc_tools::as_str(key)).expect("invalid key");
|
||||
let key = dc_tools::as_str(key);
|
||||
if key.starts_with(".ui") {
|
||||
return context.get_ui_config(key).unwrap_or_default().strdup();
|
||||
}
|
||||
let key = config::Config::from_str(key).expect("invalid key");
|
||||
|
||||
// TODO: Translating None to NULL would be more sensible than translating None
|
||||
// to "", as it is now.
|
||||
|
||||
@@ -129,6 +129,23 @@ impl Context {
|
||||
_ => self.sql.set_config(self, key, value),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_ui_config(&self, key: &str, value: Option<&str>) -> Result<(), &str> {
|
||||
if !key.starts_with("ui.") {
|
||||
return Err("Ui config key has to be prefixed with 'ui.'")
|
||||
}
|
||||
|
||||
if self.sql.set_config(self, key, value).is_err() {
|
||||
return Err("Sql error")
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn get_ui_config(&self, key: &str) -> Option<String> {
|
||||
if key.starts_with("ui.") {
|
||||
return self.sql.get_config(self, key);
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns all available configuration keys concated together.
|
||||
|
||||
Reference in New Issue
Block a user