Commit 379bb4a9291cac09320133eea89b659bcd75ddc5
1 parent
dc08a8f5
Exists in
master
and in
1 other branch
Adding method to save terminal settings to windows registry.
Showing
3 changed files
with
259 additions
and
2 deletions
Show diff stats
src/include/v3270/settings.h
| ... | ... | @@ -49,9 +49,9 @@ |
| 49 | 49 | |
| 50 | 50 | #ifdef _WIN32 |
| 51 | 51 | |
| 52 | - LIB3270_EXPORT gboolean v3270_load_registry(GtkWidget *widget, HKEY *key, const gchar *group_name); | |
| 52 | + LIB3270_EXPORT gboolean v3270_load_registry(GtkWidget *widget, HKEY *hKey, const gchar *group_name); | |
| 53 | 53 | |
| 54 | - LIB3270_EXPORT void v3270_to_registry(GtkWidget *widget, HKEY *key, const gchar *group_name); | |
| 54 | + LIB3270_EXPORT void v3270_to_registry(GtkWidget *widget, HKEY *hKey, const gchar *group_name); | |
| 55 | 55 | |
| 56 | 56 | #endif // _WIN32 |
| 57 | 57 | ... | ... |
| ... | ... | @@ -0,0 +1,254 @@ |
| 1 | +/* | |
| 2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
| 3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
| 4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
| 5 | + * | |
| 6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
| 7 | + * | |
| 8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
| 9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
| 10 | + * Free Software Foundation. | |
| 11 | + * | |
| 12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
| 13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
| 14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
| 15 | + * obter mais detalhes. | |
| 16 | + * | |
| 17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
| 18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include <config.h> | |
| 31 | + #include <windows.h> | |
| 32 | + #include <terminal.h> | |
| 33 | + #include <internals.h> | |
| 34 | + #include <v3270/settings.h> | |
| 35 | + #include <lib3270/toggle.h> | |
| 36 | + #include <lib3270/log.h> | |
| 37 | + #include <lib3270/trace.h> | |
| 38 | + | |
| 39 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 40 | + | |
| 41 | + static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, HKEY hKey) | |
| 42 | + { | |
| 43 | + const gchar * name = g_param_spec_get_name(pspec); | |
| 44 | + | |
| 45 | + GValue value = G_VALUE_INIT; | |
| 46 | + g_value_init(&value, pspec->value_type); | |
| 47 | + g_object_get_property(G_OBJECT(widget),name,&value); | |
| 48 | + | |
| 49 | + switch(pspec->value_type) | |
| 50 | + { | |
| 51 | + case G_TYPE_STRING: | |
| 52 | + { | |
| 53 | + const gchar * current = g_value_get_string(&value); | |
| 54 | + | |
| 55 | + debug("%s=%s (default: %s)",name,current,G_PARAM_SPEC_STRING(pspec)->default_value); | |
| 56 | + | |
| 57 | + if(current && strcmp(current,G_PARAM_SPEC_STRING(pspec)->default_value ? G_PARAM_SPEC_STRING(pspec)->default_value : "")) | |
| 58 | + { | |
| 59 | + RegSetValueEx(hKey,name,0,REG_SZ,(const BYTE *) current,strlen(current)+1); | |
| 60 | + } | |
| 61 | + else | |
| 62 | + { | |
| 63 | + RegDeleteKey(hKey,name); | |
| 64 | + } | |
| 65 | + } | |
| 66 | + break; | |
| 67 | + | |
| 68 | + case G_TYPE_BOOLEAN: | |
| 69 | + { | |
| 70 | + gboolean current = g_value_get_boolean(&value); | |
| 71 | + | |
| 72 | + if(current != G_PARAM_SPEC_BOOLEAN(pspec)->default_value) | |
| 73 | + { | |
| 74 | + DWORD dw = (DWORD) current; | |
| 75 | + RegSetValueEx(hKey, name, 0, REG_DWORD,(const BYTE *) &dw,sizeof(dw)); | |
| 76 | + } | |
| 77 | + else | |
| 78 | + { | |
| 79 | + RegDeleteKey(hKey,name); | |
| 80 | + } | |
| 81 | + } | |
| 82 | + break; | |
| 83 | + | |
| 84 | + case G_TYPE_INT: | |
| 85 | + { | |
| 86 | + gint current = g_value_get_int(&value); | |
| 87 | + | |
| 88 | + if(current != G_PARAM_SPEC_INT(pspec)->default_value) | |
| 89 | + { | |
| 90 | + DWORD dw = (DWORD) current; | |
| 91 | + RegSetValueEx(hKey, name, 0, REG_DWORD,(const BYTE *) &dw,sizeof(dw)); | |
| 92 | + } | |
| 93 | + else | |
| 94 | + { | |
| 95 | + RegDeleteKey(hKey,name); | |
| 96 | + } | |
| 97 | + | |
| 98 | + } | |
| 99 | + break; | |
| 100 | + | |
| 101 | + case G_TYPE_UINT: | |
| 102 | + { | |
| 103 | + guint current = (gint) g_value_get_uint(&value); | |
| 104 | + | |
| 105 | + if(current != G_PARAM_SPEC_UINT(pspec)->default_value) | |
| 106 | + { | |
| 107 | + DWORD dw = (DWORD) current; | |
| 108 | + RegSetValueEx(hKey, name, 0, REG_DWORD,(const BYTE *) &dw,sizeof(dw)); | |
| 109 | + } | |
| 110 | + else | |
| 111 | + { | |
| 112 | + RegDeleteKey(hKey,name); | |
| 113 | + } | |
| 114 | + | |
| 115 | + } | |
| 116 | + break; | |
| 117 | + | |
| 118 | + default: | |
| 119 | + lib3270_write_trace(v3270_get_session(widget),"%s has an unexpected value type\n",name); | |
| 120 | + | |
| 121 | + } | |
| 122 | + | |
| 123 | + g_value_unset(&value); | |
| 124 | + | |
| 125 | + } | |
| 126 | + | |
| 127 | + static void load_by_pspec(GtkWidget *widget, GParamSpec *pspec, HKEY hKey) | |
| 128 | + { | |
| 129 | + const gchar * name = g_param_spec_get_name(pspec); | |
| 130 | + | |
| 131 | + GValue value = G_VALUE_INIT; | |
| 132 | + g_value_init(&value, pspec->value_type); | |
| 133 | + | |
| 134 | + switch(pspec->value_type) | |
| 135 | + { | |
| 136 | + case G_TYPE_STRING: | |
| 137 | + break; | |
| 138 | + | |
| 139 | + case G_TYPE_BOOLEAN: | |
| 140 | + break; | |
| 141 | + | |
| 142 | + case G_TYPE_INT: | |
| 143 | + break; | |
| 144 | + | |
| 145 | + case G_TYPE_UINT: | |
| 146 | + break; | |
| 147 | + | |
| 148 | + default: | |
| 149 | + lib3270_write_trace(v3270_get_session(widget),"%s has an unexpected value type\n",name); | |
| 150 | + g_value_unset(&value); | |
| 151 | + return; | |
| 152 | + | |
| 153 | + } | |
| 154 | + | |
| 155 | + g_object_set_property(G_OBJECT(widget),name,&value); | |
| 156 | + g_value_unset(&value); | |
| 157 | + | |
| 158 | + } | |
| 159 | + | |
| 160 | + /// @brief Reads the terminal settings from the group group_name in registry. | |
| 161 | + LIB3270_EXPORT void v3270_to_registry(GtkWidget *widget, HKEY *hParent, const gchar *group_name) | |
| 162 | + { | |
| 163 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
| 164 | + | |
| 165 | + // Open registry | |
| 166 | + HKEY hKey; | |
| 167 | + DWORD disp; | |
| 168 | + | |
| 169 | + if(RegCreateKeyEx(hParent,group_name,0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) != ERROR_SUCCESS) | |
| 170 | + { | |
| 171 | + g_warning("Can't open registry"); | |
| 172 | + return; | |
| 173 | + } | |
| 174 | + | |
| 175 | + // Save settings | |
| 176 | + size_t ix; | |
| 177 | + GString * str; | |
| 178 | + | |
| 179 | + v3270 * terminal = GTK_V3270(widget); | |
| 180 | + v3270Class * klass = GTK_V3270_GET_CLASS(widget); | |
| 181 | + | |
| 182 | + // Save Toggles | |
| 183 | + for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++) | |
| 184 | + save_by_pspec(widget,klass->properties.toggle[ix],hKey); | |
| 185 | + | |
| 186 | + // Save V3270 Responses | |
| 187 | + for(ix = 0; ix < G_N_ELEMENTS(terminal->responses); ix++) | |
| 188 | + save_by_pspec(widget,klass->responses[ix],hKey); | |
| 189 | + | |
| 190 | + // Save V3270 properties | |
| 191 | + for(ix = 0; ix < V3270_SETTING_COUNT; ix++) | |
| 192 | + save_by_pspec(widget,klass->properties.settings[ix],hKey); | |
| 193 | + | |
| 194 | + // Save V3270 colors | |
| 195 | + str = g_string_new(""); | |
| 196 | + for(ix=0; ix<V3270_COLOR_COUNT; ix++) | |
| 197 | + { | |
| 198 | + if(ix) | |
| 199 | + g_string_append_c(str,';'); | |
| 200 | + g_string_append_printf(str,"%s",gdk_rgba_to_string(v3270_get_color(widget,ix))); | |
| 201 | + } | |
| 202 | + | |
| 203 | + RegSetValueEx(hKey,"colors",0,REG_SZ,(const BYTE *) str->str,strlen(str->str)+1); | |
| 204 | + | |
| 205 | + g_string_free(str,TRUE); | |
| 206 | + | |
| 207 | + RegCloseKey(hKey); | |
| 208 | + | |
| 209 | + } | |
| 210 | + | |
| 211 | + /// @brief This function adds the terminal settings from widget to windows registry. | |
| 212 | + LIB3270_EXPORT gboolean v3270_load_registry(GtkWidget *widget, HKEY *hParent, const gchar *group_name) | |
| 213 | + { | |
| 214 | + g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | |
| 215 | + | |
| 216 | + // Open registry | |
| 217 | + HKEY hKey; | |
| 218 | + DWORD disp; | |
| 219 | + | |
| 220 | + if(RegCreateKeyEx(hParent,group_name,0,NULL,REG_OPTION_NON_VOLATILE,KEY_READ,NULL,&hKey,&disp) != ERROR_SUCCESS) | |
| 221 | + { | |
| 222 | + g_warning("Can't open registry"); | |
| 223 | + return FALSE; | |
| 224 | + } | |
| 225 | + | |
| 226 | + // Load settings. | |
| 227 | + size_t ix; | |
| 228 | + | |
| 229 | + v3270 * terminal = GTK_V3270(widget); | |
| 230 | + v3270Class * klass = GTK_V3270_GET_CLASS(widget); | |
| 231 | + | |
| 232 | + g_object_freeze_notify(G_OBJECT(widget)); | |
| 233 | + | |
| 234 | + // Load Toggles | |
| 235 | + for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++) | |
| 236 | + load_by_pspec(widget,klass->properties.toggle[ix],hKey); | |
| 237 | + | |
| 238 | + // Load V3270 Responses | |
| 239 | + for(ix = 0; ix < G_N_ELEMENTS(terminal->responses); ix++) | |
| 240 | + load_by_pspec(widget,klass->responses[ix],hKey); | |
| 241 | + | |
| 242 | + // Load V3270 properties | |
| 243 | + for(ix = 0; ix < V3270_SETTING_COUNT; ix++) | |
| 244 | + load_by_pspec(widget,klass->properties.settings[ix],hKey); | |
| 245 | + | |
| 246 | + // Load V3270 colors | |
| 247 | + // v3270_set_colors(widget,g_key_file_get_string(key_file,group_name,"colors",NULL)); | |
| 248 | + | |
| 249 | + g_object_thaw_notify(G_OBJECT(widget)); | |
| 250 | + | |
| 251 | + RegCloseKey(hKey); | |
| 252 | + | |
| 253 | + return TRUE; | |
| 254 | + } | ... | ... |
v3270.cbp
| ... | ... | @@ -299,6 +299,9 @@ |
| 299 | 299 | <Unit filename="src/terminal/windows/iosource.c"> |
| 300 | 300 | <Option compilerVar="CC" /> |
| 301 | 301 | </Unit> |
| 302 | + <Unit filename="src/terminal/windows/registry.c"> | |
| 303 | + <Option compilerVar="CC" /> | |
| 304 | + </Unit> | |
| 302 | 305 | <Unit filename="src/terminal/windows/resources.rc"> |
| 303 | 306 | <Option compilerVar="WINDRES" /> |
| 304 | 307 | </Unit> | ... | ... |