From 33b69d2574530311deb46a04f3c28a89fb9479c2 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Mon, 25 Nov 2019 10:13:11 -0300 Subject: [PATCH] Implementing method to save terminal properties to file. --- src/include/internals.h | 2 +- src/include/terminal.h | 25 +++++++++++++++++++------ src/include/v3270/settings.h | 8 ++++++++ src/terminal/callbacks.c | 2 +- src/terminal/charset.c | 4 ++-- src/terminal/font/properties.c | 10 ++++++++-- src/terminal/keyfile.c | 9 ++------- src/terminal/properties/init.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------- src/terminal/properties/private.h | 2 +- src/terminal/properties/set.c | 6 +++--- 10 files changed, 97 insertions(+), 69 deletions(-) diff --git a/src/include/internals.h b/src/include/internals.h index 9cb9ca5..042e6f6 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -72,7 +72,7 @@ ENTRY_FIELD_HEAD }; -/*--[ Signals ]--------------------------------------------------------------------------------------*/ +//--[ Globals ]-------------------------------------------------------------------------------------- /// @brief V3270 Signal list enum diff --git a/src/include/terminal.h b/src/include/terminal.h index aed903c..67aa694 100644 --- a/src/include/terminal.h +++ b/src/include/terminal.h @@ -32,6 +32,22 @@ G_BEGIN_DECLS + /// @brief V3270 Properties saved to the configuration file. + typedef enum + { + V3270_SETTING_URL, + V3270_SETTING_FONT_FAMILY, + V3270_SETTING_AUTO_DISCONNECT, + V3270_SETTING_REMAP_FILE, + V3270_SETTING_DYNAMIC_SPACING, + V3270_SETTING_LU_NAMES, + V3270_SETTING_MODEL_NUMBER, + + V3270_SETTING_COUNT ///< @brief Number of setting properties. + } V3270_SETTING; + + G_GNUC_INTERNAL void v3270_notify_setting(GtkWidget *widget, V3270_SETTING id); + struct _v3270Class { GtkWidgetClass parent_class; @@ -41,20 +57,17 @@ G_BEGIN_DECLS size_t count; // Number of properties. - GParamSpec * font_family; GParamSpec * toggle[LIB3270_TOGGLE_COUNT]; // Toggle properties. + // Properties saved to the configuration file. + GParamSpec * settings[V3270_SETTING_COUNT]; + // Signal related properties GParamSpec * online; - GParamSpec * url; GParamSpec * associated_lu; GParamSpec * model; GParamSpec * selection; GParamSpec * session_name; - GParamSpec * auto_disconnect; - GParamSpec * remap_file; - GParamSpec * dynamic_spacing; - GParamSpec * lu_names; GParamSpec * trace; struct diff --git a/src/include/v3270/settings.h b/src/include/v3270/settings.h index 4238f41..41b4ba7 100644 --- a/src/include/v3270/settings.h +++ b/src/include/v3270/settings.h @@ -43,6 +43,14 @@ /// @brief This function adds the terminal settings from widget to key_file. LIB3270_EXPORT void v3270_to_key_file(GtkWidget *widget, GKeyFile *key_file, const gchar *group_name); +#ifdef _WIN32 + + LIB3270_EXPORT gboolean v3270_load_registry(GtkWidget *widget, HKEY *key, const gchar *group_name, GError **error); + + LIB3270_EXPORT void v3270_to_registry(GtkWidget *widget, HKEY *key, const gchar *group_name); + +#endif // _WIN32 + /*--[ V3270 Settings Widget ]------------------------------------------------------------------------*/ #define GTK_TYPE_V3270_SETTINGS (V3270Settings_get_type()) diff --git a/src/terminal/callbacks.c b/src/terminal/callbacks.c index 82d4291..1d49987 100644 --- a/src/terminal/callbacks.c +++ b/src/terminal/callbacks.c @@ -105,7 +105,7 @@ static void update_luname(H3270 *session, const char G_GNUC_UNUSED(*name)) static gboolean v3270_update_url(v3270 *terminal) { debug("url=%s",v3270_get_url(GTK_WIDGET(terminal))); - g_object_notify_by_pspec(G_OBJECT(terminal), GTK_V3270_GET_CLASS(terminal)->properties.url); + v3270_notify_setting(GTK_WIDGET(terminal),V3270_SETTING_URL); return FALSE; } diff --git a/src/terminal/charset.c b/src/terminal/charset.c index 90b2c26..c7ce0d8 100644 --- a/src/terminal/charset.c +++ b/src/terminal/charset.c @@ -337,8 +337,8 @@ g_free(cfg.host); g_free(cfg.display); - debug("%s=%p",__FUNCTION__,GTK_V3270_GET_CLASS(widget)->properties.remap_file); - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.remap_file); + debug("%s=%p",__FUNCTION__,GTK_V3270_GET_CLASS(widget)->properties.settings[V3270_SETTING_REMAP_FILE]); + v3270_notify_setting(widget,V3270_SETTING_REMAP_FILE); } diff --git a/src/terminal/font/properties.c b/src/terminal/font/properties.c index 9c7a3c4..8a48e5c 100644 --- a/src/terminal/font/properties.c +++ b/src/terminal/font/properties.c @@ -107,8 +107,8 @@ LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name) g_signal_emit(widget,v3270_widget_signal[V3270_SIGNAL_UPDATE_CONFIG], 0, "font-family", name); - debug("%s: %p",__FUNCTION__,GTK_V3270_GET_CLASS(widget)->properties.font_family); - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.font_family); + debug("%s: %p",__FUNCTION__,GTK_V3270_GET_CLASS(widget)->properties.settings[V3270_SETTING_FONT_FAMILY]); + v3270_notify_setting(widget,V3270_SETTING_FONT_FAMILY); if(gtk_widget_get_realized(widget) && gtk_widget_get_has_window(widget)) { @@ -120,6 +120,12 @@ LIB3270_EXPORT void v3270_set_font_family(GtkWidget *widget, const gchar *name) } +void v3270_notify_setting(GtkWidget *widget, V3270_SETTING id) +{ + g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.settings[id]); + v3270_emit_save_settings(widget); +} + LIB3270_EXPORT const gchar * v3270_get_font_family(GtkWidget *widget) { g_return_val_if_fail(GTK_IS_V3270(widget),NULL); diff --git a/src/terminal/keyfile.c b/src/terminal/keyfile.c index bec57a8..f418ab1 100644 --- a/src/terminal/keyfile.c +++ b/src/terminal/keyfile.c @@ -179,13 +179,8 @@ save_by_pspec(widget,klass->responses[ix],key_file,group_name); // Save V3270 properties - save_by_pspec(widget,klass->properties.font_family,key_file,group_name); - save_by_pspec(widget,klass->properties.url,key_file,group_name); - save_by_pspec(widget,klass->properties.session_name,key_file,group_name); - save_by_pspec(widget,klass->properties.auto_disconnect,key_file,group_name); - save_by_pspec(widget,klass->properties.remap_file,key_file,group_name); - save_by_pspec(widget,klass->properties.dynamic_spacing,key_file,group_name); - save_by_pspec(widget,klass->properties.lu_names,key_file,group_name); + for(ix = 0; ix < V3270_SETTING_COUNT; ix++) + save_by_pspec(widget,klass->properties.settings[ix],key_file,group_name); // Save V3270 colors str = g_string_new(""); diff --git a/src/terminal/properties/init.c b/src/terminal/properties/init.c index ab05b3f..8ebbe96 100644 --- a/src/terminal/properties/init.c +++ b/src/terminal/properties/init.c @@ -41,11 +41,11 @@ const char *name; GParamSpec **prop; } properties[] = { - { "connected", &klass->properties.online }, - { "associated-lu", &klass->properties.associated_lu }, - { "url", &klass->properties.url }, - { "model-number", &klass->properties.model }, - { "has-selection", &klass->properties.selection }, + { "connected", &klass->properties.online }, + { "associated-lu", &klass->properties.associated_lu }, + { "url", &klass->properties.settings[V3270_SETTING_URL] }, + { "model-number", &klass->properties.settings[V3270_SETTING_MODEL_NUMBER] }, + { "has-selection", &klass->properties.selection }, }; size_t ix; @@ -77,18 +77,19 @@ // Setup internal properties. // Font family - klass->properties.font_family = g_param_spec_string( - "font_family", - "font_family", - _("Font family for terminal contents"), - v3270_get_default_font_name(), - G_PARAM_READABLE|G_PARAM_WRITABLE - ); + klass->properties.settings[V3270_SETTING_FONT_FAMILY] = + g_param_spec_string( + "font_family", + "font_family", + _("Font family for terminal contents"), + v3270_get_default_font_name(), + G_PARAM_READABLE|G_PARAM_WRITABLE + ); g_object_class_install_property( gobject_class, V3270_PROPERTY_FONT_FAMILY, - klass->properties.font_family + klass->properties.settings[V3270_SETTING_FONT_FAMILY] ); // Session name. @@ -107,20 +108,21 @@ ); // Auto disconnect - klass->properties.auto_disconnect = g_param_spec_uint( - "auto_disconnect", - "auto_disconnect", - _("IDLE minutes for automatic disconnection"), - 0, - G_MAXUINT, - 0, - G_PARAM_READABLE|G_PARAM_WRITABLE - ); + klass->properties.settings[V3270_SETTING_AUTO_DISCONNECT] = + g_param_spec_uint( + "auto_disconnect", + "auto_disconnect", + _("IDLE minutes for automatic disconnection"), + 0, + G_MAXUINT, + 0, + G_PARAM_READABLE|G_PARAM_WRITABLE + ); g_object_class_install_property( gobject_class, V3270_PROPERTY_AUTO_DISCONNECT, - klass->properties.auto_disconnect + klass->properties.settings[V3270_SETTING_AUTO_DISCONNECT] ); // Clipboard @@ -139,47 +141,51 @@ ); // Remap file - klass->properties.remap_file = g_param_spec_string( - "remap_file", - "remap_file", - _("XML file with remap table"), - FALSE, - G_PARAM_READABLE|G_PARAM_WRITABLE - ); + klass->properties.settings[V3270_SETTING_REMAP_FILE] = + g_param_spec_string( + "remap_file", + "remap_file", + _("XML file with remap table"), + FALSE, + G_PARAM_READABLE|G_PARAM_WRITABLE + ); g_object_class_install_property( gobject_class, V3270_PROPERTY_REMAP_FILE, - klass->properties.remap_file + klass->properties.settings[V3270_SETTING_REMAP_FILE] ); // Dynamic font spacing - klass->properties.dynamic_spacing = g_param_spec_boolean( - "dynamic_font_spacing", - "dynamic_font_spacing", - _( "State of the dynamic font spacing" ), - FALSE, - G_PARAM_READABLE|G_PARAM_WRITABLE); + klass->properties.settings[V3270_SETTING_DYNAMIC_SPACING] = + g_param_spec_boolean( + "dynamic_font_spacing", + "dynamic_font_spacing", + _( "State of the dynamic font spacing" ), + FALSE, + G_PARAM_READABLE|G_PARAM_WRITABLE + ); g_object_class_install_property( gobject_class, V3270_PROPERTY_DYNAMIC_SPACING, - klass->properties.dynamic_spacing + klass->properties.settings[V3270_SETTING_DYNAMIC_SPACING] ); // Lu names - klass->properties.lu_names = g_param_spec_string( - "lu_names", - "lu_names", - _("Comma separated list of LU names"), - FALSE, - G_PARAM_READABLE|G_PARAM_WRITABLE - ); + klass->properties.settings[V3270_SETTING_LU_NAMES] = + g_param_spec_string( + "lu_names", + "lu_names", + _("Comma separated list of LU names"), + NULL, + G_PARAM_READABLE|G_PARAM_WRITABLE + ); g_object_class_install_property( gobject_class, V3270_PROPERTY_LU_NAMES, - klass->properties.lu_names + klass->properties.settings[V3270_SETTING_LU_NAMES] ); // Trace diff --git a/src/terminal/properties/private.h b/src/terminal/properties/private.h index 6d63c73..0089340 100644 --- a/src/terminal/properties/private.h +++ b/src/terminal/properties/private.h @@ -61,7 +61,7 @@ V3270_PROPERTY_DYNAMIC = 10 ///< @brief Id of the first LIB3270 internal property. }; - G_GNUC_INTERNAL void v3270_get_property(GObject *object,guint prop_id, GValue *value, GParamSpec *pspec); + G_GNUC_INTERNAL void v3270_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); G_GNUC_INTERNAL void v3270_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); diff --git a/src/terminal/properties/set.c b/src/terminal/properties/set.c index 75e50e6..bffe2ba 100644 --- a/src/terminal/properties/set.c +++ b/src/terminal/properties/set.c @@ -219,7 +219,7 @@ LIB3270_EXPORT void v3270_set_auto_disconnect(GtkWidget *widget, guint minutes) if(terminal->activity.disconnect != minutes) { terminal->activity.disconnect = minutes; - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.auto_disconnect); + v3270_notify_setting(widget,V3270_SETTING_AUTO_DISCONNECT); } } @@ -236,7 +236,7 @@ LIB3270_EXPORT void v3270_set_dynamic_font_spacing(GtkWidget *widget, gboolean s terminal->font.spacing.dynamic = state; v3270_reconfigure(terminal); gtk_widget_queue_draw(widget); - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.dynamic_spacing); + v3270_notify_setting(widget,V3270_SETTING_DYNAMIC_SPACING); } } @@ -245,6 +245,6 @@ LIB3270_EXPORT void v3270_set_lunames(GtkWidget *widget, const gchar *lunames) { g_return_if_fail(GTK_IS_V3270(widget)); lib3270_set_lunames(GTK_V3270(widget)->host,(lunames && *lunames ? lunames : NULL)); - g_object_notify_by_pspec(G_OBJECT(widget), GTK_V3270_GET_CLASS(widget)->properties.lu_names); + v3270_notify_setting(widget,V3270_SETTING_LU_NAMES); } -- libgit2 0.21.2