ui/common/properties.c

Wed, 27 Nov 2024 18:46:45 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 27 Nov 2024 18:46:45 +0100
branch
newapi
changeset 395
b8277deb75b8
parent 379
958bae372271
permissions
-rw-r--r--

remove global menu observer when destroying a window

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 *
140
c03c338a7dcf refactors value binding system
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 47
diff changeset
4 * Copyright 2017 Olaf Wintermann. All rights reserved.
24
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
378
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
35 #include "../ui/toolkit.h"
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
36
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
37
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "properties.h"
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
39 #include <cx/string.h>
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
40 #include <cx/buffer.h>
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
42 #include <cx/hash_map.h>
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
43 #include "ucx_properties.h"
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
44
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
45 static CxMap *application_properties;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
46 static CxMap *language;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
48 #ifndef UI_COCOA
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
49
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
50 static char *locales_dir;
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
51 static char *pixmaps_dir;
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
52
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
53 #endif
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
54
378
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
55
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
56 char* ui_getappdir(void) {
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 if(ui_appname() == NULL) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 return NULL;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 }
378
d41b1ffc5f77 implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 254
diff changeset
60
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 return ui_configfile(NULL);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
64 #ifndef _WIN32
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
65 #define UI_PATH_SEPARATOR '/'
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
66 #define UI_ENV_HOME "HOME"
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
67 #else
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
68 #define UI_PATH_SEPARATOR '\\'
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
69 #define UI_ENV_HOME "USERPROFILE"
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
70 #endif
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
71
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 char* ui_configfile(char *name) {
254
13997c76859b fix some const related warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 174
diff changeset
73 const char *appname = ui_appname();
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 if(!appname) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 return NULL;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
78 CxBuffer buf;
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
79 cxBufferInit(&buf, NULL, 128, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
24
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 base dir
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
82 char *homeenv = getenv(UI_ENV_HOME);
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 if(homeenv == NULL) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
84 cxBufferDestroy(&buf);
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 return NULL;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 }
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
87 cxstring home = cx_str(homeenv);
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
89 cxBufferWrite(home.ptr, 1, home.length, &buf);
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
90 if(home.ptr[home.length-1] != UI_PATH_SEPARATOR) {
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
91 cxBufferPut(&buf, UI_PATH_SEPARATOR);
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 #ifdef UI_COCOA
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 // on OS X the app dir is $HOME/Library/Application Support/$APPNAME/
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
96 cxBufferPutString(&buf, "Library/Application Support/");
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
97 #elif defined(_WIN32)
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
98 // on Windows the app dir is $USERPROFILE/AppData/Local/$APPNAME/
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
99 cxBufferPutString(&buf, "AppData\\Local\\");
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 #else
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 // app dir is $HOME/.$APPNAME/
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
102 cxBufferPut(&buf, '.');
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 #endif
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
104 cxBufferPutString(&buf, appname);
379
958bae372271 implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 378
diff changeset
105 cxBufferPut(&buf, UI_PATH_SEPARATOR);
24
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 // add file name
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 if(name) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
109 cxBufferPutString(&buf, name);
24
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
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
112 cxBufferPut(&buf, 0);
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
113
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
114 return buf.space;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
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 static int ui_mkdir(char *path) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 #ifdef _WIN32
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 return mkdir(path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 #else
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 return mkdir(path, S_IRWXU);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 #endif
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 void uic_load_app_properties() {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
126 application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128);
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 if(!ui_appname()) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 // applications without name cannot load app properties
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 char *dir = ui_configfile(NULL);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 if(!dir) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 if(ui_mkdir(dir)) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 if(errno != EEXIST) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 fprintf(stderr, "Ui Error: Cannot create directory %s\n", dir);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 free(dir);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 }
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 free(dir);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 char *path = ui_configfile("application.properties");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 if(!path) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 return;
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 }
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 FILE *file = fopen(path, "r");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 if(!file) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 free(path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 return;
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
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 if(ucx_properties_load(application_properties, file)) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 fprintf(stderr, "Ui Error: Cannot load application properties.\n");
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 fclose(file);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 free(path);
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
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
165 int uic_store_app_properties() {
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 char *path = ui_configfile("application.properties");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 if(!path) {
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
168 return 1;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 FILE *file = fopen(path, "w");
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172 if(!file) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173 fprintf(stderr, "Ui Error: Cannot open properties file: %s\n", path);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 free(path);
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
175 return 1;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
178 int ret = 0;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 if(ucx_properties_store(application_properties, file)) {
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 fprintf(stderr, "Ui Error: Cannot store application properties.\n");
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
181 ret = 1;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 fclose(file);
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 free(path);
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
186
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
187 return ret;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
191 const char* ui_get_property(const char *name) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
192 return cxMapGet(application_properties, name);
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
195 void ui_set_property(const char *name, const char *value) {
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
196 cxMapPut(application_properties, name, (char*)value);
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 }
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
199 const char* ui_set_default_property(const char *name, const char *value) {
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
200 const char *v = cxMapGet(application_properties, name);
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 if(!v) {
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
202 cxMapPut(application_properties, name, (char*)value);
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
203 v = value;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 }
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
205 return v;
24
06bceda81a03 added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 }
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
207
395
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
208 int ui_properties_store(void) {
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
209 return uic_store_app_properties();
b8277deb75b8 remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 379
diff changeset
210 }
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
211
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
212
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
213 static char* uic_concat_path(const char *base, const char *p, const char *ext) {
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
214 size_t baselen = strlen(base);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
215
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
216 CxBuffer *buf = cxBufferCreate(NULL, 32, cxDefaultAllocator, CX_BUFFER_FREE_CONTENTS|CX_BUFFER_AUTO_EXTEND);
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
217 if(baselen > 0) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
218 cxBufferWrite(base, 1, baselen, buf);
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
219 if(base[baselen - 1] != '/') {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
220 cxBufferPut(buf, '/');
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
221 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
222 }
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
223 cxBufferWrite(p, 1, strlen(p), buf);
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
224 if(ext) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
225 cxBufferWrite(ext, 1, strlen(ext), buf);
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
226 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
227
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
228 char *str = buf->space;
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
229 free(buf);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
230 return str;
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
231 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
232
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
233 #ifndef UI_COCOA
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
234
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
235 void ui_locales_dir(char *path) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
236 locales_dir = path;
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
237 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
238
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
239 void ui_pixmaps_dir(char *path) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
240 pixmaps_dir = path;
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
241 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
242
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
243 char* uic_get_image_path(const char *imgfilename) {
47
97792f44d919 added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
244 if(pixmaps_dir) {
97792f44d919 added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
245 return uic_concat_path(pixmaps_dir, imgfilename, NULL);
97792f44d919 added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
246 } else {
97792f44d919 added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
247 return NULL;
97792f44d919 added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
248 }
97792f44d919 added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
249 }
97792f44d919 added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 33
diff changeset
250
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
251 void ui_load_lang(char *locale) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
252 if(!locale) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
253 locale = "en_EN";
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
254 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
255
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
256 char *path = uic_concat_path(locales_dir, locale, ".properties");
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
257
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
258 uic_load_language_file(path);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
259 free(path);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
260 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
261
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
262 void ui_load_lang_def(char *locale, char *default_locale) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
263 char tmp[6];
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
264 if(!locale) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
265 char *lang = getenv("LANG");
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
266 if(lang && strlen(lang) >= 5) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
267 memcpy(tmp, lang, 5);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
268 tmp[5] = '\0';
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
269 locale = tmp;
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
270 } else {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
271 locale = default_locale;
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
272 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
273 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
274
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
275 char *path = uic_concat_path(locales_dir, locale, ".properties");
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
276
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
277 if(uic_load_language_file(path)) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
278 if(default_locale) {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
279 ui_load_lang_def(default_locale, NULL);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
280 } else {
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
281 // cannot find any language file
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
282 fprintf(stderr, "Ui Error: Cannot load language.\n");
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
283 free(path);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
284 exit(-1);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
285 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
286 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
287 free(path);
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
288 }
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
289
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
290 #endif
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
291
146
dd0ae1c62a72 new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 140
diff changeset
292 int uic_load_language_file(const char *path) {
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
293 CxMap *lang = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 256);
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
294
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
295 FILE *file = fopen(path, "r");
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
296 if(!file) {
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
297 return 1;
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
298 }
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
299
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
300 if(ucx_properties_load(lang, file)) {
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
301 fprintf(stderr, "Ui Error: Cannot parse language file: %s.\n", path);
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
302 }
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
303
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
304 fclose(file);
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
305
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
306 cxMapRehash(lang);
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
307
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
308 language = lang;
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
309
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
310 return 0;
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
311 }
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
312
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
313 char* uistr(char *name) {
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
314 char *value = uistr_n(name);
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
315 return value ? value : "missing string";
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
316 }
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
317
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
318 char* uistr_n(char *name) {
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
319 if(!language) {
30
34513f76d5a8 added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 29
diff changeset
320 return NULL;
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
321 }
174
0358f1d9c506 upgrade ucx
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 157
diff changeset
322 return cxMapGet(language, name);
29
c96169444d88 added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 24
diff changeset
323 }

mercurial