Fri, 12 Dec 2025 12:38:35 +0100
add function for loading application properties from a string
|
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 | |
|
588
59ea5791be5e
fix windows11 win32 build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
513
diff
changeset
|
35 | #ifdef _WIN32 |
|
59ea5791be5e
fix windows11 win32 build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
513
diff
changeset
|
36 | #include <direct.h> |
|
59ea5791be5e
fix windows11 win32 build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
513
diff
changeset
|
37 | #endif |
|
59ea5791be5e
fix windows11 win32 build
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
513
diff
changeset
|
38 | |
|
378
d41b1ffc5f77
implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
39 | #include "../ui/toolkit.h" |
|
d41b1ffc5f77
implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
40 | |
|
d41b1ffc5f77
implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
41 | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include "properties.h" |
| 174 | 43 | #include <cx/string.h> |
| 44 | #include <cx/buffer.h> | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
46 | #include <cx/hash_map.h> |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
47 | #include <cx/properties.h> |
| 174 | 48 | |
| 49 | static CxMap *application_properties; | |
| 50 | static CxMap *language; | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
52 | #ifndef UI_COCOA |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
53 | |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
54 | static char *locales_dir; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
55 | static char *pixmaps_dir; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
56 | |
|
974
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
57 | static UiBool use_xdg_config_home = TRUE; |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
58 | |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
59 | #endif |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
60 | |
|
993
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
61 | static UiBool load_on_startup = TRUE; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
62 | static void *properties_data = NULL; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
63 | static size_t properties_data_length = 0; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
64 | |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
65 | void ui_load_properties_file_on_startup(UiBool enable) { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
66 | load_on_startup = enable; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
67 | } |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
68 | |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
69 | void ui_set_properties_data(const char *str, size_t len) { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
70 | if(str && len > 0) { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
71 | properties_data = malloc(len); |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
72 | memcpy(properties_data, str, len); |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
73 | } else { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
74 | properties_data = NULL; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
75 | properties_data_length = 0; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
76 | } |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
77 | } |
|
378
d41b1ffc5f77
implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
78 | |
|
d41b1ffc5f77
implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
79 | char* ui_getappdir(void) { |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | if(ui_appname() == NULL) { |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | return NULL; |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | } |
|
378
d41b1ffc5f77
implement some missing WinUI functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
254
diff
changeset
|
83 | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | return ui_configfile(NULL); |
|
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 | |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
87 | #ifndef _WIN32 |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
88 | #define UI_PATH_SEPARATOR '/' |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
89 | #define UI_ENV_HOME "HOME" |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
90 | #else |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
91 | #define UI_PATH_SEPARATOR '\\' |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
92 | #define UI_ENV_HOME "USERPROFILE" |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
93 | #endif |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
94 | |
|
974
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
95 | #define UI_XDG_CONFIG_HOME_VAR "XDG_CONFIG_HOME" |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
96 | |
|
753
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
97 | char* ui_configfile(const char *name) { |
|
254
13997c76859b
fix some const related warnings
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
174
diff
changeset
|
98 | const char *appname = ui_appname(); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | if(!appname) { |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | return NULL; |
|
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 | |
| 174 | 103 | CxBuffer buf; |
| 104 | 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
|
105 | |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | // add base dir |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
107 | char *homeenv = getenv(UI_ENV_HOME); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | if(homeenv == NULL) { |
| 174 | 109 | cxBufferDestroy(&buf); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | return NULL; |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | } |
| 174 | 112 | cxstring home = cx_str(homeenv); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | |
| 174 | 114 | cxBufferWrite(home.ptr, 1, home.length, &buf); |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
115 | 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
|
116 | cxBufferPut(&buf, UI_PATH_SEPARATOR); |
|
24
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 | |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | #ifdef UI_COCOA |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | // 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
|
121 | cxBufferPutString(&buf, "Library/Application Support/"); |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
122 | #elif defined(_WIN32) |
|
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
123 | // 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
|
124 | cxBufferPutString(&buf, "AppData\\Local\\"); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | #else |
|
974
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
126 | if(use_xdg_config_home) { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
127 | // app dir is $HOME/.config/$APPNAME/ |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
128 | char *xdghome = getenv(UI_XDG_CONFIG_HOME_VAR); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
129 | size_t xdghomelen = xdghome ? strlen(xdghome) : 0; |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
130 | if(xdghome && xdghomelen > 0) { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
131 | cxBufferSeek(&buf, 0, SEEK_SET); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
132 | cxBufferPutString(&buf, xdghome); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
133 | if(xdghome[xdghomelen-1] != '/') { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
134 | cxBufferPut(&buf, '/'); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
135 | } |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
136 | } else { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
137 | cxBufferPutString(&buf, ".config/"); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
138 | } |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
139 | } else { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
140 | cxBufferPut(&buf, '.'); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
141 | } |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
142 | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | #endif |
| 174 | 144 | cxBufferPutString(&buf, appname); |
|
379
958bae372271
implement ui_dialog_window (WINUI)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
378
diff
changeset
|
145 | cxBufferPut(&buf, UI_PATH_SEPARATOR); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | // add file name |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | if(name) { |
| 174 | 149 | cxBufferPutString(&buf, name); |
|
24
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 | |
| 174 | 152 | cxBufferPut(&buf, 0); |
| 153 | ||
| 154 | return buf.space; | |
|
24
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 | static int ui_mkdir(char *path) { |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | #ifdef _WIN32 |
|
513
a4e0ef98a8b4
implement first toolkit functions (WIN32)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
395
diff
changeset
|
159 | return _mkdir(path); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | #else |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | return mkdir(path, S_IRWXU); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | #endif |
|
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 | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
165 | static int load_properties(FILE *file, CxMap *map) { |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
166 | CxProperties prop; |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
167 | cxPropertiesInitDefault(&prop); |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
168 | char buf[8192]; |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
169 | size_t r; |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
170 | CxPropertiesStatus status = CX_PROPERTIES_NO_ERROR; |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
171 | while((r = fread(buf, 1, 8192, file)) > 0) { |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
172 | cxPropertiesFilln(&prop, buf, r); |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
173 | cxstring key; |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
174 | cxstring value; |
|
993
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
175 | while((status = cxPropertiesNext(&prop, &key, &value)) == CX_PROPERTIES_NO_ERROR) { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
176 | cxMapPut(map, key, cx_strdup(value).ptr); |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
177 | } |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
178 | if(status > CX_PROPERTIES_OK) { |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
179 | break; |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
180 | } |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
181 | } |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
182 | return status == CX_PROPERTIES_NO_ERROR ? 0 : 1; |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
183 | } |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
184 | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | void uic_load_app_properties() { |
| 174 | 186 | application_properties = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 128); |
|
762
9452eccfc0f0
improve ui_set_property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
753
diff
changeset
|
187 | application_properties->collection.simple_destructor = free; |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | |
|
993
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
189 | if(!load_on_startup) { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
190 | if(properties_data) { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
191 | CxProperties prop; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
192 | cxPropertiesInitDefault(&prop); |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
193 | |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
194 | CxPropertiesStatus status = CX_PROPERTIES_NO_ERROR; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
195 | cxPropertiesFilln(&prop, properties_data, properties_data_length); |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
196 | |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
197 | cxstring key; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
198 | cxstring value; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
199 | while((status = cxPropertiesNext(&prop, &key, &value)) == CX_PROPERTIES_NO_ERROR) { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
200 | cxMapPut(application_properties, key, cx_strdup(value).ptr); |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
201 | } |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
202 | |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
203 | if(status != CX_PROPERTIES_NO_ERROR) { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
204 | fprintf(stderr, "Error: cannot load properties: %d\n", (int)status); |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
205 | } else { |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
206 | cxMapRehash(application_properties); |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
207 | } |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
208 | } |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
209 | return; |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
210 | } |
|
8ebf55d78341
add function for loading application properties from a string
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
992
diff
changeset
|
211 | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | if(!ui_appname()) { |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | // applications without name cannot load app properties |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | return; |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | char *dir = ui_configfile(NULL); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | if(!dir) { |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | return; |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | } |
|
974
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
221 | size_t len = strlen(dir); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
222 | if(len < 2) { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
223 | return; |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
224 | } |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | if(ui_mkdir(dir)) { |
|
974
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
226 | if(errno == ENOENT) { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
227 | char *parent = strdup(dir); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
228 | for(int i=len-2;i>=0;i--) { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
229 | if(parent[i] == '/') { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
230 | parent[i] = 0; |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
231 | break; |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
232 | } |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
233 | } |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
234 | // try creating the parent |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
235 | int err = ui_mkdir(parent); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
236 | if(err) { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
237 | fprintf(stderr, "Error: Cannot create directory %s: %s\n", strerror(errno)); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
238 | free(parent); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
239 | free(dir); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
240 | return; |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
241 | } |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
242 | free(parent); |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
243 | |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
244 | // try dir again |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
245 | if(!ui_mkdir(dir)) { |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
246 | errno = EEXIST; // success |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
247 | } |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
248 | } |
|
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
249 | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | if(errno != EEXIST) { |
|
974
dc72d666d721
move default config dir to ~/.config/
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
763
diff
changeset
|
251 | fprintf(stderr, "Error: Cannot create directory %s: %s\n", dir, strerror(errno)); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
252 | free(dir); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
253 | return; |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
254 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
255 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
256 | free(dir); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
257 | |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
258 | char *path = ui_configfile("application.properties"); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
259 | if(!path) { |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
260 | return; |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
261 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
262 | |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
263 | FILE *file = fopen(path, "r"); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
264 | if(!file) { |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
265 | free(path); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
266 | return; |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
267 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
268 | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
269 | if(load_properties(file, application_properties)) { |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
270 | fprintf(stderr, "Error: Cannot load application properties.\n"); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
271 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
272 | |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
273 | fclose(file); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
274 | free(path); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
275 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
276 | |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
277 | int uic_store_app_properties() { |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
278 | char *path = ui_configfile("application.properties"); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
279 | if(!path) { |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
280 | return 1; |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
281 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
282 | |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
283 | FILE *file = fopen(path, "w"); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
284 | if(!file) { |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
285 | fprintf(stderr, "Ui Error: Cannot open properties file: %s\n", path); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
286 | free(path); |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
287 | return 1; |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
288 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
289 | |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
290 | int ret = 0; |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
291 | CxMapIterator i = cxMapIterator(application_properties); |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
292 | cx_foreach(CxMapEntry *, entry, i) { |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
293 | fprintf(file, "%.*s: %s\n", (int)entry->key->len, entry->key->data, entry->value); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
294 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
295 | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
296 | cxMapRehash(application_properties); |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
297 | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
298 | fclose(file); |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
299 | free(path); |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
300 | |
|
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
301 | return ret; |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
302 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
303 | |
|
674
51670b0bc625
implement ui_app_exit_on_shutdown for Motif, Qt, Cocoa
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
588
diff
changeset
|
304 | // public |
|
51670b0bc625
implement ui_app_exit_on_shutdown for Motif, Qt, Cocoa
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
588
diff
changeset
|
305 | int ui_app_save_settings(void) { |
|
51670b0bc625
implement ui_app_exit_on_shutdown for Motif, Qt, Cocoa
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
588
diff
changeset
|
306 | return uic_store_app_properties(); |
|
51670b0bc625
implement ui_app_exit_on_shutdown for Motif, Qt, Cocoa
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
588
diff
changeset
|
307 | } |
|
51670b0bc625
implement ui_app_exit_on_shutdown for Motif, Qt, Cocoa
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
588
diff
changeset
|
308 | |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
309 | |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
310 | const char* ui_get_property(const char *name) { |
| 174 | 311 | return cxMapGet(application_properties, name); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
312 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
313 | |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
314 | void ui_set_property(const char *name, const char *value) { |
|
762
9452eccfc0f0
improve ui_set_property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
753
diff
changeset
|
315 | if(value) { |
|
763
258ec399fbe6
remember app window size (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
762
diff
changeset
|
316 | cxMapPut(application_properties, name, strdup(value)); |
|
762
9452eccfc0f0
improve ui_set_property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
753
diff
changeset
|
317 | } else { |
|
763
258ec399fbe6
remember app window size (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
762
diff
changeset
|
318 | cxMapRemove(application_properties, name); |
|
762
9452eccfc0f0
improve ui_set_property
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
753
diff
changeset
|
319 | } |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
320 | } |
|
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
321 | |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
322 | 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
|
323 | const char *v = cxMapGet(application_properties, name); |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
324 | if(!v) { |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
325 | 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
|
326 | v = value; |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
327 | } |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
328 | return v; |
|
24
06bceda81a03
added application properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
329 | } |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
330 | |
|
395
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
331 | int ui_properties_store(void) { |
|
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
332 | return uic_store_app_properties(); |
|
b8277deb75b8
remove global menu observer when destroying a window
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
379
diff
changeset
|
333 | } |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
334 | |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
335 | |
|
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
336 | 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
|
337 | size_t baselen = strlen(base); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
338 | |
| 174 | 339 | 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
|
340 | if(baselen > 0) { |
| 174 | 341 | cxBufferWrite(base, 1, baselen, buf); |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
342 | if(base[baselen - 1] != '/') { |
| 174 | 343 | cxBufferPut(buf, '/'); |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
344 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
345 | } |
| 174 | 346 | cxBufferWrite(p, 1, strlen(p), buf); |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
347 | if(ext) { |
| 174 | 348 | cxBufferWrite(ext, 1, strlen(ext), buf); |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
349 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
350 | |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
351 | char *str = buf->space; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
352 | free(buf); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
353 | return str; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
354 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
355 | |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
356 | #ifndef UI_COCOA |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
357 | |
|
753
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
358 | void ui_locales_dir(const char *path) { |
|
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
359 | free(locales_dir); |
|
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
360 | locales_dir = path ? strdup(path) : NULL; |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
361 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
362 | |
|
753
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
363 | void ui_pixmaps_dir(const char *path) { |
|
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
364 | free(pixmaps_dir); |
|
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
365 | pixmaps_dir = path ? strdup(path) : NULL; |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
366 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
367 | |
|
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
368 | char* uic_get_image_path(const char *imgfilename) { |
|
47
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
369 | if(pixmaps_dir) { |
|
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
370 | return uic_concat_path(pixmaps_dir, imgfilename, NULL); |
|
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
371 | } else { |
|
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
372 | return NULL; |
|
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
373 | } |
|
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
374 | } |
|
97792f44d919
added table view (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
33
diff
changeset
|
375 | |
|
753
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
376 | void ui_load_lang(const char *locale) { |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
377 | if(!locale) { |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
378 | locale = "en_EN"; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
379 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
380 | |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
381 | char *path = uic_concat_path(locales_dir, locale, ".properties"); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
382 | |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
383 | uic_load_language_file(path); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
384 | free(path); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
385 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
386 | |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
387 | 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
|
388 | char tmp[6]; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
389 | if(!locale) { |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
390 | char *lang = getenv("LANG"); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
391 | if(lang && strlen(lang) >= 5) { |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
392 | memcpy(tmp, lang, 5); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
393 | tmp[5] = '\0'; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
394 | locale = tmp; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
395 | } else { |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
396 | locale = default_locale; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
397 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
398 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
399 | |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
400 | char *path = uic_concat_path(locales_dir, locale, ".properties"); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
401 | |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
402 | if(uic_load_language_file(path)) { |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
403 | if(default_locale) { |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
404 | ui_load_lang_def(default_locale, NULL); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
405 | } else { |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
406 | // cannot find any language file |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
407 | fprintf(stderr, "Ui Error: Cannot load language.\n"); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
408 | free(path); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
409 | exit(-1); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
410 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
411 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
412 | free(path); |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
413 | } |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
414 | |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
415 | #endif |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
416 | |
|
146
dd0ae1c62a72
new icon/image api and pixbuf support in treeview (GTK)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
140
diff
changeset
|
417 | int uic_load_language_file(const char *path) { |
| 174 | 418 | 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
|
419 | |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
420 | FILE *file = fopen(path, "r"); |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
421 | if(!file) { |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
422 | return 1; |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
423 | } |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
424 | |
|
992
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
425 | if(load_properties(file, lang)) { |
|
f421aef8f865
remove old UCX2 properties
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
974
diff
changeset
|
426 | fprintf(stderr, "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
|
427 | } |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
428 | |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
429 | fclose(file); |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
430 | |
| 174 | 431 | cxMapRehash(lang); |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
432 | |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
433 | language = lang; |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
434 | |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
435 | return 0; |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
436 | } |
|
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
437 | |
|
753
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
438 | char* uistr(const char *name) { |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
439 | char *value = uistr_n(name); |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
440 | return value ? value : "missing string"; |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
441 | } |
|
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
442 | |
|
753
882e49cf7192
make some function parameters const
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
674
diff
changeset
|
443 | char* uistr_n(const char *name) { |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
444 | if(!language) { |
|
30
34513f76d5a8
added locale support (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
29
diff
changeset
|
445 | return NULL; |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
446 | } |
| 174 | 447 | return cxMapGet(language, name); |
|
29
c96169444d88
added locale support (Cocoa) and ucx update
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
24
diff
changeset
|
448 | } |