text stringlengths 0 357 |
|---|
* @param key The option to change, see above. |
* @param value The value to save for "key" |
* @return 0=failure, 1=success |
*/ |
int dc_set_config(dc_context_t* context, const char* key, const char* value) |
{ |
int ret = 0; |
char* rel_path = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || key==NULL || !is_settable_config_key(key)) { /* "value" may be NULL */ |
return 0; |
} |
if (strcmp(key, "selfavatar")==0 && value) |
{ |
rel_path = dc_strdup(value); |
if (!dc_make_rel_and_copy(context, &rel_path)) { |
goto cleanup; |
} |
ret = dc_sqlite3_set_config(context->sql, key, rel_path); |
} |
else if(strcmp(key, "inbox_watch")==0) |
{ |
ret = dc_sqlite3_set_config(context->sql, key, value); |
dc_interrupt_imap_idle(context); // force idle() to be called again with the new mode |
} |
else if(strcmp(key, "sentbox_watch")==0) |
{ |
ret = dc_sqlite3_set_config(context->sql, key, value); |
dc_interrupt_sentbox_idle(context); // force idle() to be called again with the new mode |
} |
else if(strcmp(key, "mvbox_watch")==0) |
{ |
ret = dc_sqlite3_set_config(context->sql, key, value); |
dc_interrupt_mvbox_idle(context); // force idle() to be called again with the new mode |
} |
else if (strcmp(key, "selfstatus")==0) { |
// if the status text equals to the default, |
// store it as NULL to support future updatates of this text |
char* def = dc_stock_str(context, DC_STR_STATUSLINE); |
ret = dc_sqlite3_set_config(context->sql, key, |
(value==NULL || strcmp(value, def)==0)? NULL : value); |
free(def); |
} |
else |
{ |
ret = dc_sqlite3_set_config(context->sql, key, value); |
} |
cleanup: |
free(rel_path); |
return ret; |
} |
/** |
* Get a configuration option. |
* The configuration option is set by dc_set_config() or by the library itself. |
* |
* Beside the options shown at dc_set_config(), |
* this function can be used to query some global system values: |
* |
* - `sys.version` = get the version string eg. as `1.2.3` or as `1.2.3special4` |
* - `sys.msgsize_max_recommended` = maximal recommended attachment size in bytes. |
* All possible overheads are already subtracted and this value can be used eg. for direct comparison |
* with the size of a file the user wants to attach. If an attachment is larger than this value, |
* an error (no warning as it should be shown to the user) is logged but the attachment is sent anyway. |
* - `sys.config_keys` = get a space-separated list of all config-keys available. |
* The config-keys are the keys that can be passed to the parameter `key` of this function. |
* |
* @memberof dc_context_t |
* @param context The context object as created by dc_context_new(). For querying system values, this can be NULL. |
* @param key The key to query. |
* @return Returns current value of "key", if "key" is unset, the default value is returned. |
* The returned value must be free()'d, NULL is never returned. |
*/ |
char* dc_get_config(dc_context_t* context, const char* key) |
{ |
char* value = NULL; |
if (key && key[0]=='s' && key[1]=='y' && key[2]=='s' && key[3]=='.') { |
return get_sys_config_str(key); |
} |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || key==NULL || !is_gettable_config_key(key)) { |
return dc_strdup(""); |
} |
if (strcmp(key, "selfavatar")==0) { |
char* rel_path = dc_sqlite3_get_config(context->sql, key, NULL); |
if (rel_path) { |
value = dc_get_abs_path(context, rel_path); |
free(rel_path); |
} |
} |
else { |
value = dc_sqlite3_get_config(context->sql, key, NULL); |
} |
if (value==NULL) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.