X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/blobdiff_plain/83d9f3aaf8206aa081ead0ff630a1c33ed670d71..848befbcc166fff6fdde6a635cf7a31f9f9185e0:/application/settings.c diff --git a/application/settings.c b/application/settings.c index ab2fb98..d3a670b 100644 --- a/application/settings.c +++ b/application/settings.c @@ -35,10 +35,11 @@ #include "utils.h" #include "json.h" -#include -#include -#include -#include +#include +#include +//include +#include +#include #define CONFIG_BASE_DIR ".config" #define UWP_CONFIG_DIR "uwplayer" @@ -59,12 +60,12 @@ static JSONObject *uwp_config; /* * global settings from json config converted to key/value pairs */ -static UcxMap *uwp_settings; +static CxMap *uwp_settings; /* * default settings */ -static UcxMap *uwp_default; +static CxMap *uwp_default; static int check_config_dir(void) { char *home = getenv("HOME"); @@ -100,8 +101,8 @@ int load_config(void) { return 1; } - uwp_settings = ucx_map_new(16); - uwp_default = ucx_map_new(32); + uwp_settings = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); + uwp_default = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 32); char *cfgfile_path = util_concat_path(uwp_config_dir, UWP_CONFIG_FILE); FILE *cfgfile = fopen(cfgfile_path, "r"); @@ -151,8 +152,8 @@ int load_config(void) { // check if mpv or mplayer binaries are configured - char *player_bin = ucx_map_cstr_get(uwp_settings, UWP_PLAYER_BIN); - char *player_type = ucx_map_cstr_get(uwp_settings, UWP_PLAYER_TYPE); + char *player_bin = cxMapGet(uwp_settings, cx_hash_key_str(UWP_PLAYER_BIN)); + char *player_type = cxMapGet(uwp_settings, cx_hash_key_str(UWP_PLAYER_TYPE)); if(!player_bin) { // try to find the mpv or mplayer binary path @@ -181,17 +182,17 @@ static void conf_load_global_settings(void) { for(size_t i=0;isize;i++) { JSONObjValue *gs = &s->values[i]; if(gs->value->type == JSON_STRING) { - ucx_map_cstr_put(uwp_settings, gs->name, strdup(gs->value->value.string.string)); + cxMapPut(uwp_settings, cx_hash_key_str(gs->name), strdup(gs->value->value.string.string)); } } } -static char* get_which_output(FILE *f, UcxBuffer *buf) { +static char* get_which_output(FILE *f, CxBuffer *buf) { buf->pos = 0; buf->size = 0; - ucx_stream_copy(f, buf, (read_func)fread, (write_func)ucx_buffer_write); + cx_stream_copy(f, buf, (cx_read_func)fread, (cx_write_func)cxBufferWrite); if(!pclose(f)) { - ucx_buffer_putc(buf, 0); + cxBufferPut(buf, 0); size_t i; for(i=0;ipos;i++) { if(buf->space[i] == '\n') { @@ -206,32 +207,33 @@ static char* get_which_output(FILE *f, UcxBuffer *buf) { static Boolean finish_bin_search(XtPointer data) { PlayerInfo *playerInfo = data; - ucx_map_cstr_put(uwp_settings, UWP_PLAYER_BIN, playerInfo->bin); - ucx_map_cstr_put(uwp_settings, UWP_PLAYER_TYPE, playerInfo->type); + cxMapPut(uwp_settings, cx_hash_key_str(UWP_PLAYER_BIN), playerInfo->bin); + cxMapPut(uwp_settings, cx_hash_key_str(UWP_PLAYER_TYPE), playerInfo->type); free(playerInfo); return 0; } static void* player_bin_search_thread(void *data) { - UcxBuffer *buf = ucx_buffer_new(NULL, 256, UCX_BUFFER_AUTOEXTEND); + CxBuffer buf; + cxBufferInit(&buf, NULL, 256, cxDefaultAllocator, CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS); FILE *f = popen("which mpv", "r"); if(f) { - char *bin = get_which_output(f, buf); + char *bin = get_which_output(f, &buf); if(bin) { PlayerInfo *playerInfo = malloc(sizeof(PlayerInfo)); playerInfo->bin = strdup(bin); playerInfo->type = strdup("mpv"); AppExecProc(finish_bin_search, playerInfo); - ucx_buffer_free(buf); + cxBufferDestroy(&buf); return NULL; } } f = popen("which mplayer", "r"); if(f) { - char *bin = get_which_output(f, buf); + char *bin = get_which_output(f, &buf); if(bin) { PlayerInfo *playerInfo = malloc(sizeof(PlayerInfo)); playerInfo->bin = strdup(bin); @@ -240,10 +242,10 @@ static void* player_bin_search_thread(void *data) { } } - ucx_buffer_free(buf); + cxBufferDestroy(&buf); return NULL; } char* SettingsGetPlayerBin(void) { - return ucx_map_cstr_get(uwp_settings, UWP_PLAYER_BIN); + return cxMapGet(uwp_settings, cx_hash_key_str(UWP_PLAYER_BIN)); }