introduce set_stock_translation and remove call to DC_EVENT_GET_STRING

This commit is contained in:
holger krekel
2019-10-09 09:48:24 +02:00
parent 24d744b94c
commit af9ae153ae
4 changed files with 64 additions and 30 deletions

View File

@@ -402,6 +402,16 @@ int dc_set_config (dc_context_t* context, const char*
*/
char* dc_get_config (dc_context_t* context, const char* key);
/**
* Set (translated) stock string
*
* @param context The context object
* @param stock_id the integer id of the stock message
* @param stock_msg the message to be used
* @return void
*/
int dc_set_stock_translation(dc_context_t* context, uint32_t, const char* value);
/**
* Get information about the context.
@@ -4316,7 +4326,8 @@ void dc_array_add_id (dc_array_t*, uint32_t); // depreca
#define DC_STR_MSGLOCATIONENABLED 64
#define DC_STR_MSGLOCATIONDISABLED 65
#define DC_STR_LOCATION 66
#define DC_STR_COUNT 66
#define DC_STR_STICKER 67
#define DC_STR_COUNT 67
void dc_str_unref (char*);

View File

@@ -342,6 +342,29 @@ pub unsafe extern "C" fn dc_get_config(
}
}
#[no_mangle]
pub unsafe extern "C" fn dc_set_stock_translation(
context: *mut dc_context_t,
stock_id: u32,
stock_msg: *mut libc::c_char,
) -> libc::c_int {
if context.is_null() || stock_msg.is_null() {
eprintln!("ignoring careless call to dc_set_stock_string");
return;
}
let msg = as_str(stock_msg);
let ffi_context = &*context;
ffi_context
.with_inner(|ctx| match ctx.set_stock_translation(stock_id, msg) {
Ok(()) => 1,
Err(err) => {
warn!(ctx, "could not set translation: {}", err);
0
}
})
.unwrap_or(())
}
#[no_mangle]
pub unsafe extern "C" fn dc_get_info(context: *mut dc_context_t) -> *mut libc::c_char {
if context.is_null() {