ui/common/properties.c

Sun, 06 Apr 2014 13:21:37 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 Apr 2014 13:21:37 +0200
changeset 28
794a5c91c479
parent 24
06bceda81a03
child 29
c96169444d88
permissions
-rw-r--r--

added open/save dialogs

24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31 #include <string.h>
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32 #include <sys/stat.h>
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include <errno.h>
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "properties.h"
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 #include "../../ucx/string.h"
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 #include "../../ucx/buffer.h"
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "../../ucx/properties.h"
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 static UiProperties *application_properties;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 char* ui_getappdir() {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 if(ui_appname() == NULL) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44 return NULL;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 return ui_configfile(NULL);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 char* ui_configfile(char *name) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 char *appname = ui_appname();
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 if(!appname) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 return NULL;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 UcxBuffer *buf = ucx_buffer_new(NULL, 128, UCX_BUFFER_AUTOEXTEND);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 // add base dir
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 char *homeenv = getenv("HOME");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 if(homeenv == NULL) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 ucx_buffer_free(buf);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 return NULL;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 sstr_t home = sstr(homeenv);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 ucx_buffer_write(home.ptr, 1, home.length, buf);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 if(home.ptr[home.length-1] != '/') {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 ucx_buffer_putc(buf, '/');
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 #ifdef UI_COCOA
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 // on OS X the app dir is $HOME/Library/Application Support/$APPNAME/
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 ucx_buffer_puts(buf, "Library/Application Support/");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 #else
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 // app dir is $HOME/.$APPNAME/
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 ucx_buffer_putc(buf, '.');
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 #endif
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 ucx_buffer_puts(buf, appname);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 ucx_buffer_putc(buf, '/');
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 // add file name
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 if(name) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 ucx_buffer_puts(buf, name);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 char *path = buf->space;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 free(buf);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 return path;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 static int ui_mkdir(char *path) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 #ifdef _WIN32
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 return mkdir(path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 #else
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 return mkdir(path, S_IRWXU);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 #endif
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 void uic_load_app_properties() {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 application_properties = ucx_map_new(128);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 if(!ui_appname()) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 // applications without name cannot load app properties
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 char *dir = ui_configfile(NULL);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 if(!dir) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 if(ui_mkdir(dir)) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 if(errno != EEXIST) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 fprintf(stderr, "Ui Error: Cannot create directory %s\n", dir);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 free(dir);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 free(dir);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 char *path = ui_configfile("application.properties");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 if(!path) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 FILE *file = fopen(path, "r");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 if(!file) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 free(path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 if(ucx_properties_load(application_properties, file)) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 fprintf(stderr, "Ui Error: Cannot load application properties.\n");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 fclose(file);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 free(path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 void uic_store_app_properties() {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 char *path = ui_configfile("application.properties");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 if(!path) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 FILE *file = fopen(path, "w");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 if(!file) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 fprintf(stderr, "Ui Error: Cannot open properties file: %s\n", path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 free(path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 if(ucx_properties_store(application_properties, file)) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 fprintf(stderr, "Ui Error: Cannot store application properties.\n");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 fclose(file);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 free(path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 char* ui_get_property(char *name) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 return ucx_map_cstr_get(application_properties, name);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 void ui_set_property(char *name, char *value) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 ucx_map_cstr_put(application_properties, name, value);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 void ui_set_default_property(char *name, char *value) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 char *v = ucx_map_cstr_get(application_properties, name);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 if(!v) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 ucx_map_cstr_put(application_properties, name, value);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 }

mercurial