ui/common/properties.c

changeset 110
c00e968d018b
parent 108
77254bd6dccb
equal deleted inserted replaced
109:c3dfcb8f0be7 110:c00e968d018b
71 #else 71 #else
72 #define UI_PATH_SEPARATOR '\\' 72 #define UI_PATH_SEPARATOR '\\'
73 #define UI_ENV_HOME "USERPROFILE" 73 #define UI_ENV_HOME "USERPROFILE"
74 #endif 74 #endif
75 75
76 char* ui_configfile(char *name) { 76 char* ui_configfile(const char *name) {
77 const char *appname = ui_appname(); 77 const char *appname = ui_appname();
78 if(!appname) { 78 if(!appname) {
79 return NULL; 79 return NULL;
80 } 80 }
81 81
126 #endif 126 #endif
127 } 127 }
128 128
129 void uic_load_app_properties() { 129 void uic_load_app_properties() {
130 application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128); 130 application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128);
131 application_properties->collection.simple_destructor = free;
131 132
132 if(!ui_appname()) { 133 if(!ui_appname()) {
133 // applications without name cannot load app properties 134 // applications without name cannot load app properties
134 return; 135 return;
135 } 136 }
200 const char* ui_get_property(const char *name) { 201 const char* ui_get_property(const char *name) {
201 return cxMapGet(application_properties, name); 202 return cxMapGet(application_properties, name);
202 } 203 }
203 204
204 void ui_set_property(const char *name, const char *value) { 205 void ui_set_property(const char *name, const char *value) {
205 cxMapPut(application_properties, name, (char*)value); 206 if(value) {
207 cxMapPut(application_properties, name, strdup(value));
208 } else {
209 cxMapRemove(application_properties, name);
210 }
206 } 211 }
207 212
208 const char* ui_set_default_property(const char *name, const char *value) { 213 const char* ui_set_default_property(const char *name, const char *value) {
209 const char *v = cxMapGet(application_properties, name); 214 const char *v = cxMapGet(application_properties, name);
210 if(!v) { 215 if(!v) {
239 return str; 244 return str;
240 } 245 }
241 246
242 #ifndef UI_COCOA 247 #ifndef UI_COCOA
243 248
244 void ui_locales_dir(char *path) { 249 void ui_locales_dir(const char *path) {
245 locales_dir = path; 250 free(locales_dir);
246 } 251 locales_dir = path ? strdup(path) : NULL;
247 252 }
248 void ui_pixmaps_dir(char *path) { 253
249 pixmaps_dir = path; 254 void ui_pixmaps_dir(const char *path) {
255 free(pixmaps_dir);
256 pixmaps_dir = path ? strdup(path) : NULL;
250 } 257 }
251 258
252 char* uic_get_image_path(const char *imgfilename) { 259 char* uic_get_image_path(const char *imgfilename) {
253 if(pixmaps_dir) { 260 if(pixmaps_dir) {
254 return uic_concat_path(pixmaps_dir, imgfilename, NULL); 261 return uic_concat_path(pixmaps_dir, imgfilename, NULL);
255 } else { 262 } else {
256 return NULL; 263 return NULL;
257 } 264 }
258 } 265 }
259 266
260 void ui_load_lang(char *locale) { 267 void ui_load_lang(const char *locale) {
261 if(!locale) { 268 if(!locale) {
262 locale = "en_EN"; 269 locale = "en_EN";
263 } 270 }
264 271
265 char *path = uic_concat_path(locales_dir, locale, ".properties"); 272 char *path = uic_concat_path(locales_dir, locale, ".properties");
317 language = lang; 324 language = lang;
318 325
319 return 0; 326 return 0;
320 } 327 }
321 328
322 char* uistr(char *name) { 329 char* uistr(const char *name) {
323 char *value = uistr_n(name); 330 char *value = uistr_n(name);
324 return value ? value : "missing string"; 331 return value ? value : "missing string";
325 } 332 }
326 333
327 char* uistr_n(char *name) { 334 char* uistr_n(const char *name) {
328 if(!language) { 335 if(!language) {
329 return NULL; 336 return NULL;
330 } 337 }
331 return cxMapGet(language, name); 338 return cxMapGet(language, name);
332 } 339 }

mercurial