| 56 |
56 |
| 57 static UiBool use_xdg_config_home = TRUE; |
57 static UiBool use_xdg_config_home = TRUE; |
| 58 |
58 |
| 59 #endif |
59 #endif |
| 60 |
60 |
| |
61 static UiBool load_on_startup = TRUE; |
| |
62 static void *properties_data = NULL; |
| |
63 static size_t properties_data_length = 0; |
| |
64 |
| |
65 void ui_load_properties_file_on_startup(UiBool enable) { |
| |
66 load_on_startup = enable; |
| |
67 } |
| |
68 |
| |
69 void ui_set_properties_data(const char *str, size_t len) { |
| |
70 if(str && len > 0) { |
| |
71 properties_data = malloc(len); |
| |
72 memcpy(properties_data, str, len); |
| |
73 } else { |
| |
74 properties_data = NULL; |
| |
75 properties_data_length = 0; |
| |
76 } |
| |
77 } |
| 61 |
78 |
| 62 char* ui_getappdir(void) { |
79 char* ui_getappdir(void) { |
| 63 if(ui_appname() == NULL) { |
80 if(ui_appname() == NULL) { |
| 64 return NULL; |
81 return NULL; |
| 65 } |
82 } |
| 153 CxPropertiesStatus status = CX_PROPERTIES_NO_ERROR; |
170 CxPropertiesStatus status = CX_PROPERTIES_NO_ERROR; |
| 154 while((r = fread(buf, 1, 8192, file)) > 0) { |
171 while((r = fread(buf, 1, 8192, file)) > 0) { |
| 155 cxPropertiesFilln(&prop, buf, r); |
172 cxPropertiesFilln(&prop, buf, r); |
| 156 cxstring key; |
173 cxstring key; |
| 157 cxstring value; |
174 cxstring value; |
| 158 status = cxPropertiesNext(&prop, &key, &value); |
175 while((status = cxPropertiesNext(&prop, &key, &value)) == CX_PROPERTIES_NO_ERROR) { |
| |
176 cxMapPut(map, key, cx_strdup(value).ptr); |
| |
177 } |
| 159 if(status > CX_PROPERTIES_OK) { |
178 if(status > CX_PROPERTIES_OK) { |
| 160 break; |
179 break; |
| 161 } |
180 } |
| 162 cxMapPut(map, key, cx_strdup(value).ptr); |
|
| 163 } |
181 } |
| 164 return status == CX_PROPERTIES_NO_ERROR ? 0 : 1; |
182 return status == CX_PROPERTIES_NO_ERROR ? 0 : 1; |
| 165 } |
183 } |
| 166 |
184 |
| 167 void uic_load_app_properties() { |
185 void uic_load_app_properties() { |
| 168 application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128); |
186 application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128); |
| 169 application_properties->collection.simple_destructor = free; |
187 application_properties->collection.simple_destructor = free; |
| |
188 |
| |
189 if(!load_on_startup) { |
| |
190 if(properties_data) { |
| |
191 CxProperties prop; |
| |
192 cxPropertiesInitDefault(&prop); |
| |
193 |
| |
194 CxPropertiesStatus status = CX_PROPERTIES_NO_ERROR; |
| |
195 cxPropertiesFilln(&prop, properties_data, properties_data_length); |
| |
196 |
| |
197 cxstring key; |
| |
198 cxstring value; |
| |
199 while((status = cxPropertiesNext(&prop, &key, &value)) == CX_PROPERTIES_NO_ERROR) { |
| |
200 cxMapPut(application_properties, key, cx_strdup(value).ptr); |
| |
201 } |
| |
202 |
| |
203 if(status != CX_PROPERTIES_NO_ERROR) { |
| |
204 fprintf(stderr, "Error: cannot load properties: %d\n", (int)status); |
| |
205 } else { |
| |
206 cxMapRehash(application_properties); |
| |
207 } |
| |
208 } |
| |
209 return; |
| |
210 } |
| 170 |
211 |
| 171 if(!ui_appname()) { |
212 if(!ui_appname()) { |
| 172 // applications without name cannot load app properties |
213 // applications without name cannot load app properties |
| 173 return; |
214 return; |
| 174 } |
215 } |