Commit b37993dbeb8d6fb44eded52792214052f0af5d76
1 parent
33b69d25
Exists in
master
and in
1 other branch
Fixing keyfile manager.
Showing
3 changed files
with
92 additions
and
6 deletions
Show diff stats
src/include/v3270/settings.h
@@ -38,14 +38,14 @@ | @@ -38,14 +38,14 @@ | ||
38 | /*--[ Tools ]----------------------------------------------------------------------------------------*/ | 38 | /*--[ Tools ]----------------------------------------------------------------------------------------*/ |
39 | 39 | ||
40 | /// @brief Reads the terminal settings from the group group_name in key_file. | 40 | /// @brief Reads the terminal settings from the group group_name in key_file. |
41 | - LIB3270_EXPORT gboolean v3270_load_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name, GError **error); | 41 | + LIB3270_EXPORT gboolean v3270_load_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name); |
42 | 42 | ||
43 | /// @brief This function adds the terminal settings from widget to key_file. | 43 | /// @brief This function adds the terminal settings from widget to key_file. |
44 | LIB3270_EXPORT void v3270_to_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name); | 44 | LIB3270_EXPORT void v3270_to_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name); |
45 | 45 | ||
46 | #ifdef _WIN32 | 46 | #ifdef _WIN32 |
47 | 47 | ||
48 | - LIB3270_EXPORT gboolean v3270_load_registry(GtkWidget *widget, HKEY *key, const gchar *group_name, GError **error); | 48 | + LIB3270_EXPORT gboolean v3270_load_registry(GtkWidget *widget, HKEY *key, const gchar *group_name); |
49 | 49 | ||
50 | LIB3270_EXPORT void v3270_to_registry(GtkWidget *widget, HKEY *key, const gchar *group_name); | 50 | LIB3270_EXPORT void v3270_to_registry(GtkWidget *widget, HKEY *key, const gchar *group_name); |
51 | 51 |
src/terminal/keyfile.c
@@ -51,7 +51,9 @@ | @@ -51,7 +51,9 @@ | ||
51 | { | 51 | { |
52 | const gchar * current = g_value_get_string(&value); | 52 | const gchar * current = g_value_get_string(&value); |
53 | 53 | ||
54 | - if(current && G_PARAM_SPEC_STRING(pspec)->default_value && strcmp(current,G_PARAM_SPEC_STRING(pspec)->default_value)) | 54 | + debug("%s=%s (default: %s)",name,current,G_PARAM_SPEC_STRING(pspec)->default_value); |
55 | + | ||
56 | + if(current && strcmp(current,G_PARAM_SPEC_STRING(pspec)->default_value ? G_PARAM_SPEC_STRING(pspec)->default_value : "")) | ||
55 | { | 57 | { |
56 | g_key_file_set_string( | 58 | g_key_file_set_string( |
57 | key_file, | 59 | key_file, |
@@ -156,6 +158,53 @@ | @@ -156,6 +158,53 @@ | ||
156 | 158 | ||
157 | g_value_unset(&value); | 159 | g_value_unset(&value); |
158 | 160 | ||
161 | + } | ||
162 | + | ||
163 | + static void load_by_pspec(GtkWidget *widget, GParamSpec *pspec, GKeyFile *key_file, const gchar *group_name) | ||
164 | + { | ||
165 | + const gchar * name = g_param_spec_get_name(pspec); | ||
166 | + GError * error = NULL; | ||
167 | + | ||
168 | + if(!g_key_file_has_key(key_file,group_name,name,&error)) | ||
169 | + { | ||
170 | + if(error) | ||
171 | + { | ||
172 | + g_message("%s::%s: %s",group_name,name,error->message); | ||
173 | + g_error_free(error); | ||
174 | + } | ||
175 | + return; | ||
176 | + } | ||
177 | + | ||
178 | + GValue value = G_VALUE_INIT; | ||
179 | + g_value_init(&value, pspec->value_type); | ||
180 | + | ||
181 | + switch(pspec->value_type) | ||
182 | + { | ||
183 | + case G_TYPE_STRING: | ||
184 | + g_value_set_string(&value, g_key_file_get_string(key_file,group_name,name,NULL)); | ||
185 | + break; | ||
186 | + | ||
187 | + case G_TYPE_BOOLEAN: | ||
188 | + g_value_set_boolean(&value, g_key_file_get_boolean(key_file,group_name,name,NULL)); | ||
189 | + break; | ||
190 | + | ||
191 | + case G_TYPE_INT: | ||
192 | + g_value_set_int(&value, g_key_file_get_integer(key_file,group_name,name,NULL)); | ||
193 | + break; | ||
194 | + | ||
195 | + case G_TYPE_UINT: | ||
196 | + g_value_set_uint(&value, (guint) g_key_file_get_integer(key_file,group_name,name,NULL)); | ||
197 | + break; | ||
198 | + | ||
199 | + default: | ||
200 | + lib3270_write_trace(v3270_get_session(widget),"%s has an unexpected value type\n",name); | ||
201 | + g_value_unset(&value); | ||
202 | + return; | ||
203 | + | ||
204 | + } | ||
205 | + | ||
206 | + g_object_set_property(G_OBJECT(widget),name,&value); | ||
207 | + g_value_unset(&value); | ||
159 | 208 | ||
160 | } | 209 | } |
161 | 210 | ||
@@ -203,10 +252,33 @@ | @@ -203,10 +252,33 @@ | ||
203 | } | 252 | } |
204 | 253 | ||
205 | /// @brief This function adds the terminal settings from widget to key_file. | 254 | /// @brief This function adds the terminal settings from widget to key_file. |
206 | - LIB3270_EXPORT gboolean v3270_load_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name, GError **error) | 255 | + LIB3270_EXPORT gboolean v3270_load_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name) |
207 | { | 256 | { |
208 | g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | 257 | g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); |
209 | 258 | ||
259 | + size_t ix; | ||
260 | + | ||
261 | + v3270 * terminal = GTK_V3270(widget); | ||
262 | + v3270Class * klass = GTK_V3270_GET_CLASS(widget); | ||
263 | + | ||
264 | + g_object_freeze_notify(G_OBJECT(widget)); | ||
265 | + | ||
266 | + // Load Toggles | ||
267 | + for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++) | ||
268 | + load_by_pspec(widget,klass->properties.toggle[ix],key_file,group_name); | ||
269 | + | ||
270 | + // Load V3270 Responses | ||
271 | + for(ix = 0; ix < G_N_ELEMENTS(terminal->responses); ix++) | ||
272 | + load_by_pspec(widget,klass->responses[ix],key_file,group_name); | ||
273 | + | ||
274 | + // Load V3270 properties | ||
275 | + for(ix = 0; ix < V3270_SETTING_COUNT; ix++) | ||
276 | + load_by_pspec(widget,klass->properties.settings[ix],key_file,group_name); | ||
277 | + | ||
278 | + // Load V3270 colors | ||
279 | + v3270_set_colors(widget,g_key_file_get_string(key_file,group_name,"colors",NULL)); | ||
280 | + | ||
281 | + g_object_thaw_notify(G_OBJECT(widget)); | ||
210 | 282 | ||
211 | - return FALSE; | 283 | + return TRUE; |
212 | } | 284 | } |
src/testprogram/testprogram.c
@@ -65,14 +65,22 @@ | @@ -65,14 +65,22 @@ | ||
65 | } | 65 | } |
66 | */ | 66 | */ |
67 | 67 | ||
68 | + static GKeyFile * get_key_file() | ||
69 | + { | ||
70 | + GKeyFile * key_file = g_key_file_new(); | ||
71 | + g_key_file_load_from_file(key_file,"terminal.conf",G_KEY_FILE_KEEP_COMMENTS,NULL); | ||
72 | + return key_file; | ||
73 | + } | ||
74 | + | ||
68 | static void save_settings(GtkWidget *terminal, GtkWidget *window) | 75 | static void save_settings(GtkWidget *terminal, GtkWidget *window) |
69 | { | 76 | { |
70 | debug("%s: Saving settings for windows %p",__FUNCTION__,window); | 77 | debug("%s: Saving settings for windows %p",__FUNCTION__,window); |
71 | 78 | ||
72 | - GKeyFile * key_file = g_key_file_new(); | 79 | + GKeyFile * key_file = get_key_file(); |
73 | v3270_to_key_file(terminal,key_file,"terminal"); | 80 | v3270_to_key_file(terminal,key_file,"terminal"); |
74 | g_key_file_save_to_file(key_file,"terminal.conf",NULL); | 81 | g_key_file_save_to_file(key_file,"terminal.conf",NULL); |
75 | g_key_file_free(key_file); | 82 | g_key_file_free(key_file); |
83 | + | ||
76 | } | 84 | } |
77 | 85 | ||
78 | static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { | 86 | static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
@@ -99,6 +107,12 @@ | @@ -99,6 +107,12 @@ | ||
99 | v3270_set_font_family(terminal,"Lucida Console"); | 107 | v3270_set_font_family(terminal,"Lucida Console"); |
100 | #endif // _WIN32 | 108 | #endif // _WIN32 |
101 | 109 | ||
110 | + // Load settings before connecting the signals. | ||
111 | + debug("%s: Loading settings...",__FUNCTION__); | ||
112 | + GKeyFile * key_file = get_key_file(); | ||
113 | + v3270_load_key_file(terminal,key_file,"terminal"); | ||
114 | + g_key_file_free(key_file); | ||
115 | + | ||
102 | } | 116 | } |
103 | 117 | ||
104 | // Create trace window | 118 | // Create trace window |