Commit 33cff6e713376fafb7d313086a013e24c413fd0f

Authored by Perry Werneck
1 parent 25d497e8
Exists in master and in 1 other branch develop

Working on load/save settings engine.

src/include/terminal.h
... ... @@ -33,6 +33,7 @@
33 33  
34 34 G_BEGIN_DECLS
35 35  
  36 +/*
36 37 /// @brief V3270 Properties saved to the configuration file.
37 38 typedef enum
38 39 {
... ... @@ -56,6 +57,7 @@ G_BEGIN_DECLS
56 57 } V3270_SETTING;
57 58  
58 59 G_GNUC_INTERNAL void v3270_notify_setting(GtkWidget *widget, V3270_SETTING id);
  60 +*/
59 61  
60 62 struct _v3270Class
61 63 {
... ... @@ -69,7 +71,7 @@ G_BEGIN_DECLS
69 71 GParamSpec * toggle[LIB3270_TOGGLE_COUNT]; // Toggle properties.
70 72  
71 73 // Properties saved to the configuration file.
72   - GParamSpec * settings[V3270_SETTING_COUNT];
  74 + const gchar **persistent;
73 75  
74 76 // Signal related properties
75 77 GParamSpec * online;
... ... @@ -92,9 +94,6 @@ G_BEGIN_DECLS
92 94  
93 95 } properties;
94 96  
95   - // Predefined responses.
96   -// GParamSpec * responses[V3270_TOGGLEABLE_DIALOG_CUSTOM];
97   -
98 97 // Cursors
99 98 GdkCursor * cursors[LIB3270_POINTER_COUNT];
100 99  
... ...
src/include/v3270/settings.h
... ... @@ -48,7 +48,7 @@
48 48 LIB3270_EXPORT void v3270_to_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name);
49 49  
50 50 /// @brief Emit the "save-settings" signal.
51   - LIB3270_EXPORT void v3270_emit_save_settings(GtkWidget *widget);
  51 + LIB3270_EXPORT void v3270_emit_save_settings(GtkWidget *widget, const gchar *property_name);
52 52  
53 53 #ifdef _WIN32
54 54  
... ...
src/selection/selection.c
... ... @@ -151,7 +151,7 @@ void v3270_selection_set_font_family(GtkWidget *widget, const gchar *name) {
151 151 terminal->selection.font_family = g_strdup(name);
152 152 }
153 153  
154   - v3270_emit_save_settings(widget);
  154 + v3270_emit_save_settings(widget,NULL);
155 155  
156 156 }
157 157  
... ... @@ -181,7 +181,7 @@ void v3270_selection_set_color_scheme(GtkWidget *widget, const gchar *name) {
181 181 terminal->selection.color.scheme = g_strdup(name);
182 182 }
183 183  
184   - v3270_emit_save_settings(widget);
  184 + v3270_emit_save_settings(widget,NULL);
185 185  
186 186 }
187 187  
... ...
src/terminal/callbacks.c
... ... @@ -112,7 +112,8 @@ static gboolean v3270_update_url(v3270 *terminal)
112 112 {
113 113 GtkWidget * widget = GTK_WIDGET(terminal);
114 114 debug("url=%s",v3270_get_url(widget));
115   - v3270_notify_setting(widget,V3270_SETTING_URL);
  115 +
  116 + v3270_emit_save_settings(widget,"url");
116 117 v3270_signal_emit(widget, V3270_SIGNAL_SESSION_CHANGED);
117 118 return FALSE;
118 119 }
... ... @@ -201,9 +202,7 @@ static void update_model(H3270 *session, const char *name, int model, G_GNUC_UNU
201 202 {
202 203 GtkWidget * widget = GTK_WIDGET(lib3270_get_user_data(session));
203 204  
204   - debug("%s: terminal=%p pspec=%p",__FUNCTION__,widget,GTK_V3270_GET_CLASS(widget)->properties.settings[V3270_SETTING_MODEL_NUMBER]);
205   - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.settings[V3270_SETTING_MODEL_NUMBER]);
206   -
  205 +// g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.settings[V3270_SETTING_MODEL_NUMBER]);
207 206 v3270_signal_emit(widget,V3270_SIGNAL_MODEL_CHANGED, (guint) model, name);
208 207 }
209 208  
... ...
src/terminal/charset.c
... ... @@ -337,8 +337,7 @@
337 337 g_free(cfg.host);
338 338 g_free(cfg.display);
339 339  
340   - debug("%s=%p",__FUNCTION__,GTK_V3270_GET_CLASS(widget)->properties.settings[V3270_SETTING_REMAP_FILE]);
341   - v3270_notify_setting(widget,V3270_SETTING_REMAP_FILE);
  340 + v3270_emit_save_settings(widget,"remap_file");
342 341  
343 342 }
344 343  
... ...
src/terminal/colors.c
... ... @@ -135,7 +135,7 @@ LIB3270_EXPORT void v3270_set_colors(GtkWidget *widget, const gchar *colors)
135 135 }
136 136  
137 137 v3270_set_color_table(GTK_V3270(widget)->color,colors);
138   - v3270_emit_save_settings(widget);
  138 + v3270_emit_save_settings(widget,NULL);
139 139 v3270_reload(widget);
140 140  
141 141 }
... ...
src/terminal/font/properties.c
... ... @@ -162,10 +162,7 @@ LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name)
162 162 terminal->font.family = g_strdup(name);
163 163 terminal->font.weight = lib3270_get_toggle(terminal->host,LIB3270_TOGGLE_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
164 164  
165   - v3270_emit_save_settings(widget);
166   -
167   - debug("%s: %p",__FUNCTION__,GTK_V3270_GET_CLASS(widget)->properties.settings[V3270_SETTING_FONT_FAMILY]);
168   - v3270_notify_setting(widget,V3270_SETTING_FONT_FAMILY);
  165 + v3270_emit_save_settings(widget,"font_family");
169 166  
170 167 if(gtk_widget_get_realized(widget) && gtk_widget_get_has_window(widget))
171 168 {
... ... @@ -177,13 +174,6 @@ LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name)
177 174  
178 175 }
179 176  
180   -void v3270_notify_setting(GtkWidget *widget, V3270_SETTING id)
181   -{
182   - debug("%s(%u)",__FUNCTION__,(unsigned int) id);
183   - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.settings[id]);
184   - v3270_emit_save_settings(widget);
185   -}
186   -
187 177 LIB3270_EXPORT const gchar * v3270_get_font_family(GtkWidget *widget)
188 178 {
189 179 g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
... ...
src/terminal/keyfile.c
... ... @@ -308,15 +308,17 @@
308 308 for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++)
309 309 save_by_pspec(widget,klass->properties.toggle[ix],key_file,group_name);
310 310  
311   - // Save V3270 Responses
312   - /*
313   - for(ix = 0; ix < G_N_ELEMENTS(terminal->responses); ix++)
314   - save_by_pspec(widget,klass->responses[ix],key_file,group_name);
315   - */
316   -
317 311 // Save V3270 properties
318   - for(ix = 0; ix < V3270_SETTING_COUNT; ix++)
319   - save_by_pspec(widget,klass->properties.settings[ix],key_file,group_name);
  312 + for(ix = 0; klass->properties.persistent[ix];ix++)
  313 + {
  314 + save_by_pspec(
  315 + widget,
  316 + g_object_class_find_property(G_OBJECT_CLASS(klass),klass->properties.persistent[ix]),
  317 + key_file,
  318 + group_name
  319 + );
  320 +
  321 + }
320 322  
321 323 }
322 324  
... ... @@ -362,15 +364,17 @@
362 364 for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++)
363 365 load_by_pspec(widget,klass->properties.toggle[ix],key_file,group_name);
364 366  
365   - /*
366   - // Load V3270 Responses
367   - for(ix = 0; ix < G_N_ELEMENTS(terminal->responses); ix++)
368   - load_by_pspec(widget,klass->responses[ix],key_file,group_name);
369   - */
370   -
371 367 // Load V3270 properties
372   - for(ix = 0; ix < V3270_SETTING_COUNT; ix++)
373   - load_by_pspec(widget,klass->properties.settings[ix],key_file,group_name);
  368 + for(ix = 0; klass->properties.persistent[ix];ix++)
  369 + {
  370 + load_by_pspec(
  371 + widget,
  372 + g_object_class_find_property(G_OBJECT_CLASS(klass),klass->properties.persistent[ix]),
  373 + key_file,
  374 + group_name
  375 + );
  376 +
  377 + }
374 378  
375 379 g_object_thaw_notify(G_OBJECT(widget));
376 380 terminal->freeze = 0;
... ...
src/terminal/properties/init.c
... ... @@ -43,15 +43,7 @@
43 43 } properties[] = {
44 44 { "connected", &klass->properties.online },
45 45 { "associated-lu", &klass->properties.associated_lu },
46   - { "url", &klass->properties.settings[V3270_SETTING_URL] },
47   - { "model-number", &klass->properties.settings[V3270_SETTING_MODEL_NUMBER] },
48 46 { "has-selection", &klass->properties.selection },
49   - { "oversize", &klass->properties.settings[V3270_SETTING_OVERSIZE] },
50   - { "host-charset", &klass->properties.settings[V3270_SETTING_HOST_CHARSET] },
51   - { "unlock-delay", &klass->properties.settings[V3270_SETTING_UNLOCK_DELAY] },
52   - { "color-type", &klass->properties.settings[V3270_SETTING_COLOR_TYPE] },
53   - { "host-type", &klass->properties.settings[V3270_SETTING_HOST_TYPE] },
54   - { "crl-preferred-protocol", &klass->properties.settings[V3270_SETTING_CRL_PROTOCOL] },
55 47 };
56 48  
57 49 size_t ix;
... ... @@ -83,7 +75,7 @@
83 75 // Setup internal properties.
84 76  
85 77 // Font family
86   - klass->properties.settings[V3270_SETTING_FONT_FAMILY] =
  78 + spec =
87 79 g_param_spec_string(
88 80 "font_family",
89 81 "font_family",
... ... @@ -95,7 +87,7 @@
95 87 g_object_class_install_property(
96 88 gobject_class,
97 89 V3270_PROPERTY_FONT_FAMILY,
98   - klass->properties.settings[V3270_SETTING_FONT_FAMILY]
  90 + spec
99 91 );
100 92  
101 93 // Session name.
... ... @@ -114,7 +106,7 @@
114 106 );
115 107  
116 108 // Auto disconnect
117   - klass->properties.settings[V3270_SETTING_AUTO_DISCONNECT] =
  109 + spec =
118 110 g_param_spec_uint(
119 111 "auto_disconnect",
120 112 "auto_disconnect",
... ... @@ -128,7 +120,7 @@
128 120 g_object_class_install_property(
129 121 gobject_class,
130 122 V3270_PROPERTY_AUTO_DISCONNECT,
131   - klass->properties.settings[V3270_SETTING_AUTO_DISCONNECT]
  123 + spec
132 124 );
133 125  
134 126 // Clipboard
... ... @@ -147,7 +139,7 @@
147 139 );
148 140  
149 141 // Remap file
150   - klass->properties.settings[V3270_SETTING_REMAP_FILE] =
  142 + spec =
151 143 g_param_spec_string(
152 144 "remap_file",
153 145 "remap_file",
... ... @@ -159,11 +151,11 @@
159 151 g_object_class_install_property(
160 152 gobject_class,
161 153 V3270_PROPERTY_REMAP_FILE,
162   - klass->properties.settings[V3270_SETTING_REMAP_FILE]
  154 + spec
163 155 );
164 156  
165 157 // Dynamic font spacing
166   - klass->properties.settings[V3270_SETTING_DYNAMIC_SPACING] =
  158 + spec =
167 159 g_param_spec_boolean(
168 160 "dynamic_font_spacing",
169 161 "dynamic_font_spacing",
... ... @@ -175,11 +167,11 @@
175 167 g_object_class_install_property(
176 168 gobject_class,
177 169 V3270_PROPERTY_DYNAMIC_SPACING,
178   - klass->properties.settings[V3270_SETTING_DYNAMIC_SPACING]
  170 + spec
179 171 );
180 172  
181 173 // Lu names
182   - klass->properties.settings[V3270_SETTING_LU_NAMES] =
  174 + spec =
183 175 g_param_spec_string(
184 176 "lu_names",
185 177 "lu_names",
... ... @@ -191,7 +183,7 @@
191 183 g_object_class_install_property(
192 184 gobject_class,
193 185 V3270_PROPERTY_LU_NAMES,
194   - klass->properties.settings[V3270_SETTING_LU_NAMES]
  186 + spec
195 187 );
196 188  
197 189 // Trace
... ... @@ -209,7 +201,7 @@
209 201 );
210 202  
211 203 // Colors
212   - klass->properties.settings[V3270_SETTING_TERMINAL_COLORS] =
  204 + spec =
213 205 g_param_spec_string(
214 206 "colors",
215 207 "colors",
... ... @@ -221,11 +213,11 @@
221 213 g_object_class_install_property(
222 214 gobject_class,
223 215 V3270_PROPERTY_TERMINAL_COLORS,
224   - klass->properties.settings[V3270_SETTING_TERMINAL_COLORS]
  216 + spec
225 217 );
226 218  
227 219 // Clipboard options
228   - klass->properties.settings[V3270_SETTING_SELECTION_OPTIONS] =
  220 + spec =
229 221 g_param_spec_uint(
230 222 "selection_flags",
231 223 "selection_flags",
... ... @@ -239,7 +231,7 @@
239 231 g_object_class_install_property(
240 232 gobject_class,
241 233 V3270_PROPERTY_SELECTION_OPTIONS,
242   - klass->properties.settings[V3270_SETTING_SELECTION_OPTIONS]
  234 + spec
243 235 );
244 236  
245 237 klass->properties.has_copy =
... ...
src/terminal/properties/set.c
... ... @@ -256,7 +256,7 @@ LIB3270_EXPORT void v3270_set_auto_disconnect(GtkWidget *widget, guint minutes)
256 256 if(terminal->activity.disconnect != minutes)
257 257 {
258 258 terminal->activity.disconnect = minutes;
259   - v3270_notify_setting(widget,V3270_SETTING_AUTO_DISCONNECT);
  259 + v3270_emit_save_settings(widget,"auto_disconnect");
260 260 }
261 261  
262 262 }
... ... @@ -273,7 +273,7 @@ LIB3270_EXPORT void v3270_set_dynamic_font_spacing(GtkWidget *widget, gboolean s
273 273 terminal->font.spacing.dynamic = state;
274 274 v3270_reconfigure(terminal);
275 275 gtk_widget_queue_draw(widget);
276   - v3270_notify_setting(widget,V3270_SETTING_DYNAMIC_SPACING);
  276 + v3270_emit_save_settings(widget,"dynamic_font_spacing");
277 277 }
278 278  
279 279 }
... ... @@ -282,6 +282,6 @@ LIB3270_EXPORT void v3270_set_lunames(GtkWidget *widget, const gchar *lunames)
282 282 {
283 283 g_return_if_fail(GTK_IS_V3270(widget));
284 284 lib3270_set_lunames(GTK_V3270(widget)->host,(lunames && *lunames ? lunames : NULL));
285   - v3270_notify_setting(widget,V3270_SETTING_LU_NAMES);
  285 + v3270_emit_save_settings(widget,"lu_names");
286 286 }
287 287  
... ...
src/terminal/widget.c
... ... @@ -58,6 +58,26 @@
58 58 *
59 59 */
60 60  
  61 +/// @brief Persistent properties (load/save from session file).
  62 +static const gchar *persistent_properties[] = {
  63 + "url",
  64 + "model-number",
  65 + "oversize",
  66 + "host-charset",
  67 + "unlock-delay",
  68 + "color-type",
  69 + "host-type",
  70 + "crl-preferred-protocol",
  71 + "remap_file",
  72 + "dynamic_font_spacing",
  73 + "lu_names",
  74 + "font_family",
  75 + "auto_disconnect",
  76 + "colors",
  77 + "selection_flags",
  78 + NULL
  79 +};
  80 +
61 81 /*--[ Widget definition ]----------------------------------------------------------------------------*/
62 82  
63 83 G_DEFINE_TYPE(v3270, v3270, GTK_TYPE_WIDGET);
... ... @@ -207,6 +227,8 @@ static void finalize(GObject *object) {
207 227 GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass);
208 228 GtkBindingSet * binding = gtk_binding_set_by_class(klass);
209 229  
  230 + klass->properties.persistent = persistent_properties;
  231 +
210 232 // Setup widget key bindings
211 233 gtk_binding_entry_skip(binding,GDK_F10,0);
212 234  
... ... @@ -824,8 +846,11 @@ static gboolean bg_emit_save_settings(v3270 *terminal)
824 846 return FALSE;
825 847 }
826 848  
827   -LIB3270_EXPORT void v3270_emit_save_settings(GtkWidget *widget)
  849 +LIB3270_EXPORT void v3270_emit_save_settings(GtkWidget *widget, const gchar *property_name)
828 850 {
  851 + if(property_name)
  852 + g_object_notify(G_OBJECT(widget),property_name);
  853 +
829 854 debug("%s(Freeze is %s)",__FUNCTION__,GTK_V3270(widget)->freeze ? "ON" : "OFF");
830 855 if(widget && GTK_IS_V3270(widget) && !GTK_V3270(widget)->freeze)
831 856 {
... ...