Commit bae5af0e350083b98ac2871412315f867f4a441b
1 parent
ffdee95e
Exists in
master
and in
4 other branches
Refactoring application settings dialog as a GTK widget.
Showing
14 changed files
with
516 additions
and
137 deletions
Show diff stats
Makefile.in
... | ... | @@ -38,6 +38,7 @@ SOURCES= \ |
38 | 38 | $(wildcard src/objects/window/actions/*.c) \ |
39 | 39 | $(wildcard src/objects/terminal/*.c) \ |
40 | 40 | $(wildcard src/objects/toolbar/*.c) \ |
41 | + $(wildcard src/objects/settings/*.c) \ | |
41 | 42 | $(wildcard src/main/*.c) \ |
42 | 43 | $(wildcard src/main/@OSNAME@/*.c) \ |
43 | 44 | $(wildcard src/main/@OSNAME@/*.rc) | ... | ... |
pw3270.cbp
... | ... | @@ -109,6 +109,12 @@ |
109 | 109 | <Option compilerVar="CC" /> |
110 | 110 | </Unit> |
111 | 111 | <Unit filename="src/objects/application/private.h" /> |
112 | + <Unit filename="src/objects/settings/dialog.c"> | |
113 | + <Option compilerVar="CC" /> | |
114 | + </Unit> | |
115 | + <Unit filename="src/objects/settings/widget.c"> | |
116 | + <Option compilerVar="CC" /> | |
117 | + </Unit> | |
112 | 118 | <Unit filename="src/objects/toolbar/actions.c"> |
113 | 119 | <Option compilerVar="CC" /> |
114 | 120 | </Unit> | ... | ... |
src/include/pw3270.h
... | ... | @@ -52,7 +52,8 @@ |
52 | 52 | #define I_(string) g_intern_static_string (string) |
53 | 53 | |
54 | 54 | |
55 | - void pw3270_load_placeholders(GtkBuilder * builder); | |
55 | + void pw3270_load_placeholders(GtkBuilder * builder); | |
56 | + GtkWidget * pw3270_frame_new(GtkWidget * child, const gchar *title); | |
56 | 57 | |
57 | 58 | // Application settings widget |
58 | 59 | typedef struct _Pw3270SettingsPage Pw3270SettingsPage; |
... | ... | @@ -73,8 +74,6 @@ |
73 | 74 | /// @brief Check if the terminal has a customized session file. |
74 | 75 | gboolean v3270_allow_custom_settings(GtkWidget *widget); |
75 | 76 | |
76 | - GtkWidget * pw3270_settings_dialog_new(const gchar *title, GtkWindow *parent); | |
77 | - | |
78 | 77 | G_END_DECLS |
79 | 78 | |
80 | 79 | #endif // PW3270_H_INCLUDED | ... | ... |
src/include/pw3270/settings.h
... | ... | @@ -27,24 +27,66 @@ |
27 | 27 | * |
28 | 28 | */ |
29 | 29 | |
30 | -/** | |
31 | - * @brief Declares the pw3270 Application Settings widget. | |
32 | - * | |
33 | - */ | |
30 | +#ifndef PW3270SETTINGS_H_INCLUDED | |
31 | + | |
32 | + #define PW3270SETTINGS_H_INCLUDED 1 | |
33 | + | |
34 | +#ifdef _WIN32 | |
35 | + #include <windows.h> | |
36 | +#endif // _WIN32 | |
37 | + | |
38 | + #include <gtk/gtk.h> | |
39 | + | |
40 | + G_BEGIN_DECLS | |
41 | + | |
42 | +/*--[ PW3270 Settings Widget ]-----------------------------------------------------------------------*/ | |
43 | + | |
44 | + #define GTK_TYPE_PW3270_SETTINGS (PW3270Settings_get_type()) | |
45 | + #define GTK_PW3270_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PW3270_SETTINGS, PW3270Settings)) | |
46 | + #define GTK_PW3270_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PW3270_SETTINGS, PW3270SettingsClass)) | |
47 | + #define GTK_IS_PW3270_SETTINGS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PW3270_SETTINGS)) | |
48 | + #define GTK_IS_PW3270_SETTINGS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PW3270_SETTINGS)) | |
49 | + #define GTK_PW3270_SETTINGS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PW3270_SETTINGS, PW3270SettingsClass)) | |
50 | + | |
51 | + typedef struct _PW3270SettingsPrivate PW3270SettingsPrivate; | |
52 | + | |
53 | + typedef struct _PW3270Settings { | |
54 | + | |
55 | + GtkGrid parent; | |
56 | + | |
57 | + PW3270SettingsPrivate * settings; ///< @brief Private Data. | |
58 | + const gchar * label; ///< @brief Page lagel. | |
59 | + const gchar * title; ///< @brief Page title. | |
60 | + | |
61 | + void (*load)(GtkWidget *widget, PW3270SettingsPrivate *settings); ///< @brief Method to load the properties from terminal widget | |
62 | + void (*apply)(GtkWidget *widget, PW3270SettingsPrivate *settings); ///< @brief Method for GTK_RESPONSE_APPLY | |
63 | + void (*revert)(GtkWidget *widget, PW3270SettingsPrivate *settings); ///< @brief Method for GTK_RESPONSE_CANCEL | |
64 | + | |
65 | + } PW3270Settings; | |
66 | + | |
67 | + typedef struct _PW3270SettingsClass { | |
68 | + | |
69 | + GtkGridClass parent_class; | |
34 | 70 | |
35 | -#ifndef PW3270_SETTINGS_H_INCLUDED | |
71 | + } PW3270SettingsClass; | |
36 | 72 | |
37 | - #define PW3270_SETTINGS_H_INCLUDED | |
73 | + PW3270Settings * pw3270_settings_new(); | |
38 | 74 | |
39 | - #include <gtk/gtk.h> | |
40 | - #include <pw3270.h> | |
75 | +/*--[ PW3270 Settings Dialog ]-----------------------------------------------------------------------*/ | |
41 | 76 | |
42 | - G_BEGIN_DECLS | |
77 | + #define GTK_TYPE_PW3270_SETTINGS_DIALOG (PW3270SettingsDialog_get_type()) | |
78 | + #define GTK_PW3270_SETTINGS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PW3270_SETTINGS_DIALOG, PW3270SettingsDialog)) | |
79 | + #define GTK_PW3270_SETTINGS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PW3270_SETTINGS_DIALOG, PW3270SettingsDialogClass)) | |
80 | + #define GTK_IS_PW3270_SETTINGS_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PW3270_SETTINGS_DIALOG)) | |
81 | + #define GTK_IS_PW3270_SETTINGS_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PW3270_SETTINGS_DIALOG)) | |
82 | + #define GTK_PW3270_SETTINGS_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PW3270_SETTINGS_DIALOG, PW3270SettingsDialogClass)) | |
43 | 83 | |
44 | - Pw3270SettingsPage * pw3270_toolbar_settings_new(); | |
84 | + typedef struct _PW3270SettingsDialog PW3270SettingsDialog; | |
85 | + typedef struct _PW3270SettingsDialogClass PW3270SettingsDialogClass; | |
45 | 86 | |
46 | - GtkWidget * pw3270_frame_new(GtkWidget * child, const gchar *title); | |
87 | + GType PW3270SettingsDialog_get_type(void); | |
88 | + GtkWidget * pw3270_settings_dialog_new(); | |
47 | 89 | |
48 | - G_END_DECLS | |
90 | + G_END_DECLS | |
49 | 91 | |
50 | -#endif // PW3270_SETTINGS_H_INCLUDED | |
92 | +#endif // V3270SETTINGS_H_INCLUDED | ... | ... |
src/include/pw3270/toolbar.h
... | ... | @@ -55,6 +55,7 @@ |
55 | 55 | GType pw3270ToolBar_get_type(void) G_GNUC_CONST; |
56 | 56 | |
57 | 57 | GtkWidget * pw3270_toolbar_new(void); |
58 | + GtkWidget * pw3270_toolbar_settings_new(void); | |
58 | 59 | |
59 | 60 | // GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos); |
60 | 61 | GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, const gchar *name, gint pos); | ... | ... |
src/main/tools.c
src/objects/actions/dialog.c
... | ... | @@ -116,16 +116,18 @@ static void on_destroy(GtkWidget *dialog, PW3270DialogAction *action) { |
116 | 116 | if(action->dialog) { |
117 | 117 | |
118 | 118 | GtkWindow * window = gtk_application_get_active_window(application); |
119 | + pw3270_action_notify_enabled(G_ACTION(action)); | |
120 | + | |
119 | 121 | if(window) { |
122 | + gtk_window_set_destroy_with_parent(GTK_WINDOW(action->dialog), TRUE); | |
123 | + gtk_window_set_modal(GTK_WINDOW(action->dialog), TRUE); | |
120 | 124 | gtk_window_set_attached_to(GTK_WINDOW(action->dialog), GTK_WIDGET(window)); |
121 | 125 | gtk_window_set_transient_for(GTK_WINDOW(action->dialog),window); |
126 | + g_signal_connect(action->dialog,"destroy",G_CALLBACK(on_destroy),action); | |
127 | + g_signal_connect(action->dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
128 | + gtk_widget_show(GTK_WIDGET(action->dialog)); | |
122 | 129 | } |
123 | 130 | |
124 | - pw3270_action_notify_enabled(G_ACTION(action)); | |
125 | - g_signal_connect(action->dialog,"destroy",G_CALLBACK(on_destroy),action); | |
126 | - g_signal_connect(action->dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
127 | - gtk_widget_show(GTK_WIDGET(action->dialog)); | |
128 | - | |
129 | 131 | } |
130 | 132 | |
131 | 133 | } | ... | ... |
src/objects/application/actions/preferences.c
... | ... | @@ -30,8 +30,40 @@ |
30 | 30 | #include "../private.h" |
31 | 31 | #include <pw3270.h> |
32 | 32 | #include <pw3270/application.h> |
33 | + #include <pw3270/actions.h> | |
33 | 34 | #include <pw3270/settings.h> |
35 | + #include <pw3270/toolbar.h> | |
34 | 36 | |
37 | + static GtkWidget * factory(PW3270Action G_GNUC_UNUSED(*action), GtkApplication G_GNUC_UNUSED(*application)) { | |
38 | + | |
39 | + size_t ix; | |
40 | + GtkWidget * dialog = pw3270_settings_dialog_new(); | |
41 | + | |
42 | + GtkWidget * pages[] = { | |
43 | + pw3270_toolbar_settings_new() | |
44 | + }; | |
45 | + | |
46 | + for(ix = 0; ix < G_N_ELEMENTS(pages); ix++) { | |
47 | + gtk_container_add(GTK_CONTAINER(dialog),pages[ix]); | |
48 | + } | |
49 | + | |
50 | + gtk_widget_show_all(dialog); | |
51 | + return dialog; | |
52 | + | |
53 | + } | |
54 | + | |
55 | + GAction * pw3270_preferences_action_new() { | |
56 | + | |
57 | + PW3270Action * action = pw3270_dialog_action_new(factory); | |
58 | + | |
59 | + action->name = "preferences"; | |
60 | + action->label = _("Application preferences"); | |
61 | + action->icon_name = "preferences-system"; | |
62 | + | |
63 | + return G_ACTION(action); | |
64 | + } | |
65 | + | |
66 | + /* | |
35 | 67 | typedef struct _Pw3270SettingsDialog { |
36 | 68 | GApplication * application; |
37 | 69 | GSimpleAction * action; |
... | ... | @@ -181,3 +213,4 @@ |
181 | 213 | |
182 | 214 | } |
183 | 215 | |
216 | +*/ | ... | ... |
src/objects/application/application.c
src/objects/application/private.h
... | ... | @@ -51,6 +51,7 @@ |
51 | 51 | |
52 | 52 | // Actions |
53 | 53 | G_GNUC_INTERNAL GAction * pw3270_about_action_new(); |
54 | + G_GNUC_INTERNAL GAction * pw3270_preferences_action_new(); | |
54 | 55 | |
55 | 56 | G_GNUC_INTERNAL void pw3270_application_generic_activated(GSimpleAction * action, GVariant *parameter, gpointer application); |
56 | 57 | G_GNUC_INTERNAL void pw3270_application_quit_activated(GSimpleAction * action, GVariant *parameter, gpointer application); | ... | ... |
... | ... | @@ -0,0 +1,160 @@ |
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 <pw3270.h> | |
31 | + #include <pw3270/settings.h> | |
32 | + #include <lib3270.h> | |
33 | + #include <lib3270/log.h> | |
34 | + | |
35 | + struct _PW3270SettingsDialog { | |
36 | + GtkDialog parent; | |
37 | + GtkNotebook * tabs; | |
38 | + gboolean has_subtitle; | |
39 | + }; | |
40 | + | |
41 | + struct _PW3270SettingsDialogClass { | |
42 | + GtkDialogClass parent_class; | |
43 | + }; | |
44 | + | |
45 | + G_DEFINE_TYPE(PW3270SettingsDialog, PW3270SettingsDialog, GTK_TYPE_DIALOG); | |
46 | + | |
47 | + static void add(GtkContainer *container, GtkWidget *widget); | |
48 | + static void page_changed(GtkNotebook *notebook, GtkWidget *child, guint page_num, PW3270SettingsDialog *dialog); | |
49 | + static void switch_page(GtkNotebook *notebook, GtkWidget *settings, guint page_num, PW3270SettingsDialog *dialog); | |
50 | + static void dialog_close(GtkDialog *dialog); | |
51 | + static void response(GtkDialog *dialog, gint response_id); | |
52 | + | |
53 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
54 | + | |
55 | +static void PW3270SettingsDialog_class_init(PW3270SettingsDialogClass *klass) { | |
56 | + GTK_CONTAINER_CLASS(klass)->add = add; | |
57 | + GTK_DIALOG_CLASS(klass)->close = dialog_close; | |
58 | + GTK_DIALOG_CLASS(klass)->response = response; | |
59 | +} | |
60 | + | |
61 | +static void PW3270SettingsDialog_init(PW3270SettingsDialog *dialog) | |
62 | +{ | |
63 | + GtkWidget * content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | |
64 | + | |
65 | + // Get use of header bar. | |
66 | + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &dialog->has_subtitle, NULL); | |
67 | + | |
68 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en | |
69 | + //gtk_box_set_spacing(GTK_BOX(content_area),18); | |
70 | + //gtk_container_set_border_width(GTK_CONTAINER(content_area),18); | |
71 | + | |
72 | + gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | |
73 | + gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | |
74 | + | |
75 | + gtk_dialog_add_buttons( | |
76 | + GTK_DIALOG(dialog), | |
77 | + _("_Cancel"), GTK_RESPONSE_CANCEL, | |
78 | + _("_Apply"), GTK_RESPONSE_APPLY, | |
79 | + NULL | |
80 | + ); | |
81 | + | |
82 | + // Create notebook for settings widgets | |
83 | + dialog->tabs = GTK_NOTEBOOK(gtk_notebook_new()); | |
84 | + | |
85 | + gtk_notebook_set_scrollable(dialog->tabs,TRUE); | |
86 | + gtk_notebook_set_show_tabs(dialog->tabs,FALSE); | |
87 | + g_signal_connect(G_OBJECT(dialog->tabs), "page-added", G_CALLBACK(page_changed), dialog); | |
88 | + g_signal_connect(G_OBJECT(dialog->tabs), "page-removed", G_CALLBACK(page_changed), dialog); | |
89 | + g_signal_connect(G_OBJECT(dialog->tabs), "switch-page", G_CALLBACK(switch_page), dialog); | |
90 | + gtk_box_pack_start(GTK_BOX(content_area),GTK_WIDGET(dialog->tabs),TRUE,TRUE,0); | |
91 | + | |
92 | + gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | |
93 | + | |
94 | +} | |
95 | + | |
96 | +GtkWidget * pw3270_settings_dialog_new() { | |
97 | +#if GTK_CHECK_VERSION(3,12,0) | |
98 | + | |
99 | + gboolean use_header; | |
100 | + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL); | |
101 | + | |
102 | + GtkWidget * dialog = | |
103 | + GTK_WIDGET(g_object_new( | |
104 | + GTK_TYPE_PW3270_SETTINGS_DIALOG, | |
105 | + "use-header-bar", (use_header ? 1 : 0), | |
106 | + NULL | |
107 | + )); | |
108 | + | |
109 | +#else | |
110 | + | |
111 | + GtkWidget * dialog = GTK_WIDGET(g_object_new(GTK_TYPE_PW3270_SETTINGS_DIALOG, NULL)); | |
112 | + | |
113 | +#endif // GTK 3.12 | |
114 | + | |
115 | + return dialog; | |
116 | + | |
117 | +} | |
118 | + | |
119 | +void dialog_close(GtkDialog *dialog) { | |
120 | + gtk_widget_destroy(GTK_WIDGET(dialog)); | |
121 | +} | |
122 | + | |
123 | +void response(GtkDialog *dialog, gint response_id) { | |
124 | + | |
125 | + debug("%s(%d)",__FUNCTION__,response_id); | |
126 | + | |
127 | + gtk_widget_destroy(GTK_WIDGET(dialog)); | |
128 | +} | |
129 | + | |
130 | +void add(GtkContainer *container, GtkWidget *widget) { | |
131 | + | |
132 | + GtkWidget * label = NULL; | |
133 | + | |
134 | + gtk_notebook_append_page( | |
135 | + GTK_PW3270_SETTINGS_DIALOG(container)->tabs, | |
136 | + widget, | |
137 | + label | |
138 | + ); | |
139 | + | |
140 | +} | |
141 | + | |
142 | +void page_changed(GtkNotebook *notebook, GtkWidget G_GNUC_UNUSED(*child), guint G_GNUC_UNUSED(page_num), PW3270SettingsDialog G_GNUC_UNUSED(*dialog)) { | |
143 | + gtk_notebook_set_show_tabs(notebook,gtk_notebook_get_n_pages(notebook) > 1); | |
144 | +} | |
145 | + | |
146 | +void switch_page(GtkNotebook G_GNUC_UNUSED(*notebook), GtkWidget *settings, guint G_GNUC_UNUSED(page_num), PW3270SettingsDialog *dialog) { | |
147 | + | |
148 | + /* | |
149 | + debug("title: %s",settings->title); | |
150 | + debug("label: %s",settings->label); | |
151 | + | |
152 | + if(dialog->has_subtitle) { | |
153 | + GtkWidget * header_bar = gtk_dialog_get_header_bar(GTK_DIALOG(dialog)); | |
154 | + if(header_bar) { | |
155 | + gtk_header_bar_set_subtitle(GTK_HEADER_BAR(header_bar),settings->title); | |
156 | + } | |
157 | + } | |
158 | + */ | |
159 | +} | |
160 | + | ... | ... |
... | ... | @@ -0,0 +1,84 @@ |
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 <pw3270.h> | |
31 | + #include <pw3270/settings.h> | |
32 | + #include <lib3270.h> | |
33 | + #include <lib3270/log.h> | |
34 | + | |
35 | + G_DEFINE_TYPE(PW3270Settings, PW3270Settings, GTK_TYPE_GRID); | |
36 | + | |
37 | + static void load(GtkWidget *widget, PW3270SettingsPrivate *settings); | |
38 | + static void apply(GtkWidget *widget, PW3270SettingsPrivate *settings); | |
39 | + static void revert(GtkWidget *widget, PW3270SettingsPrivate *settings); | |
40 | + static void finalize(GObject *object); | |
41 | + | |
42 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
43 | + | |
44 | + PW3270Settings * pw3270_settings_new() { | |
45 | + return GTK_PW3270_SETTINGS(g_object_new(GTK_TYPE_PW3270_SETTINGS,NULL)); | |
46 | + } | |
47 | + | |
48 | + static void PW3270Settings_class_init(PW3270SettingsClass *klass) { | |
49 | + | |
50 | + G_OBJECT_CLASS(klass)->finalize = finalize; | |
51 | + } | |
52 | + | |
53 | + static void PW3270Settings_init(PW3270Settings *widget) { | |
54 | + | |
55 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en | |
56 | + gtk_grid_set_row_spacing(GTK_GRID(widget),6); | |
57 | + gtk_grid_set_column_spacing(GTK_GRID(widget),12); | |
58 | + | |
59 | + widget->settings = NULL; // Just in case. | |
60 | + widget->load = load; | |
61 | + widget->apply = apply; | |
62 | + widget->revert = revert; | |
63 | + | |
64 | + } | |
65 | + | |
66 | + static void finalize(GObject *object) { | |
67 | + | |
68 | + PW3270Settings * settings = GTK_PW3270_SETTINGS(object); | |
69 | + if(settings->settings) { | |
70 | + g_free(settings->settings); | |
71 | + settings->settings = NULL; | |
72 | + } | |
73 | + | |
74 | +} | |
75 | + | |
76 | + void load(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate G_GNUC_UNUSED(*settings)) { | |
77 | + } | |
78 | + | |
79 | + void apply(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate G_GNUC_UNUSED(*settings)) { | |
80 | + } | |
81 | + | |
82 | + void revert(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate G_GNUC_UNUSED(*settings)) { | |
83 | + } | |
84 | + | ... | ... |
src/objects/toolbar/settings.c
... | ... | @@ -28,10 +28,17 @@ |
28 | 28 | */ |
29 | 29 | |
30 | 30 | #include "private.h" |
31 | + #include <pw3270.h> | |
31 | 32 | #include <pw3270/settings.h> |
33 | + #include <pw3270/toolbar.h> | |
32 | 34 | #include <pw3270/actions.h> |
33 | 35 | #include <pw3270/window.h> |
34 | 36 | |
37 | + static void load(GtkWidget *widget, PW3270SettingsPrivate *settings); | |
38 | + static void apply(GtkWidget *widget, PW3270SettingsPrivate *settings); | |
39 | + | |
40 | + /*--[ Constants ]------------------------------------------------------------------------------------*/ | |
41 | + | |
35 | 42 | static const struct _comboboxes { |
36 | 43 | const gchar * name; |
37 | 44 | const gchar * label; |
... | ... | @@ -49,127 +56,42 @@ |
49 | 56 | |
50 | 57 | }; |
51 | 58 | |
52 | - typedef struct _ToolbarSettingsPage { | |
53 | - Pw3270SettingsPage parent; | |
59 | + struct _PW3270SettingsPrivate { | |
54 | 60 | GtkWidget * views[2]; |
55 | 61 | GtkWidget * buttons[2]; |
56 | 62 | GtkTreeModel * models[2]; |
57 | 63 | GtkWidget * combos[G_N_ELEMENTS(comboboxes)]; |
64 | + }; | |
58 | 65 | |
59 | - } ToolbarSettingsPage; | |
60 | - | |
61 | - static void load(Pw3270SettingsPage *pg, GtkApplication *application) { | |
62 | - | |
63 | - size_t ix; | |
64 | - ToolbarSettingsPage * page = (ToolbarSettingsPage *) pg; | |
65 | - g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); | |
66 | - | |
67 | - debug("%s",__FUNCTION__); | |
68 | - | |
69 | - // Populate views | |
70 | - Pw3270ActionList * action_list = pw3270_action_list_new(application); | |
71 | - | |
72 | - // Load current values. | |
73 | - g_autofree gchar * action_names = g_settings_get_string(settings,"toolbar-action-names"); | |
74 | - | |
75 | - gchar ** actions = g_strsplit(action_names,",",-1); | |
76 | - | |
77 | - for(ix = 0; actions[ix]; ix++) { | |
78 | - | |
79 | - if(g_ascii_strcasecmp(actions[ix],"separator")) { | |
80 | - | |
81 | - // It's an action | |
82 | - action_list = pw3270_action_list_move_action(action_list,actions[ix],page->views[0]); | |
83 | - | |
84 | - } else { | |
85 | - | |
86 | - // It's a separator | |
87 | - pw3270_action_view_append(page->views[0], _( "Separator"), NULL, "separator", 2); | |
88 | - | |
89 | - } | |
90 | - | |
91 | - } | |
92 | - | |
93 | - g_strfreev(actions); | |
94 | - | |
95 | - // Load available actions. | |
96 | - pw3270_action_view_set_actions(page->views[1], action_list); | |
97 | - pw3270_action_view_append(page->views[1], _( "Separator"), NULL, "separator", 1); | |
98 | - | |
99 | - pw3270_action_list_free(action_list); | |
100 | - | |
101 | - GtkTreeIter iter; | |
102 | - | |
103 | - for(ix = 0; ix < G_N_ELEMENTS(page->combos); ix++) { | |
104 | - | |
105 | - pw3270_model_get_iter_from_value( | |
106 | - gtk_combo_box_get_model(GTK_COMBO_BOX(page->combos[ix])), | |
107 | - &iter, | |
108 | - (guint) g_settings_get_int(settings,comboboxes[ix].name) | |
109 | - ); | |
110 | - | |
111 | - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(page->combos[ix]),&iter); | |
112 | - | |
113 | - } | |
114 | - | |
115 | - } | |
116 | - | |
117 | - static void apply(Pw3270SettingsPage *pg, GtkApplication G_GNUC_UNUSED(*application)) { | |
118 | - | |
119 | - size_t ix; | |
120 | - ToolbarSettingsPage * page = (ToolbarSettingsPage *) pg; | |
121 | - g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); | |
122 | - | |
123 | - debug("%s",__FUNCTION__); | |
124 | - | |
125 | - g_autofree gchar * action_names = pw3270_action_view_get_action_names(page->views[0]); | |
126 | - g_settings_set_string(settings,"toolbar-action-names",action_names); | |
127 | - | |
128 | - debug("[%s]",action_names); | |
129 | - | |
130 | - GtkTreeIter iter; | |
131 | - for(ix = 0; ix < G_N_ELEMENTS(page->combos); ix++) { | |
132 | - | |
133 | - if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(page->combos[ix]),&iter)) { | |
134 | - | |
135 | - g_settings_set_int( | |
136 | - settings, | |
137 | - comboboxes[ix].name, | |
138 | - (gint) pw3270_model_get_value_from_iter(gtk_combo_box_get_model(GTK_COMBO_BOX(page->combos[ix])),&iter) | |
139 | - ); | |
140 | - | |
141 | - } | |
142 | - | |
143 | - } | |
144 | - } | |
66 | + /*--[ Implement ]------------------------------------------------------------------------------------*/ | |
145 | 67 | |
146 | 68 | static void selection_changed(GtkTreeSelection *selection, GtkWidget *button) { |
147 | 69 | gtk_widget_set_sensitive(button,gtk_tree_selection_count_selected_rows(selection) > 0); |
148 | 70 | } |
149 | 71 | |
150 | - void toolbar_insert(GtkButton G_GNUC_UNUSED(*button), ToolbarSettingsPage *settings) { | |
72 | + void toolbar_insert(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
151 | 73 | debug("%s(%p)",__FUNCTION__,settings); |
152 | 74 | pw3270_action_view_move_selected(settings->views[1],settings->views[0]); |
153 | 75 | } |
154 | 76 | |
155 | - void toolbar_remove(GtkButton G_GNUC_UNUSED(*button), ToolbarSettingsPage *settings) { | |
77 | + void toolbar_remove(GtkButton G_GNUC_UNUSED(*button), PW3270SettingsPrivate *settings) { | |
156 | 78 | debug("%s(%p)",__FUNCTION__,settings); |
157 | 79 | pw3270_action_view_move_selected(settings->views[0],settings->views[1]); |
158 | 80 | } |
159 | 81 | |
160 | - Pw3270SettingsPage * pw3270_toolbar_settings_new() { | |
161 | - | |
162 | - size_t ix; | |
163 | - | |
164 | - ToolbarSettingsPage * page = g_new0(ToolbarSettingsPage,1); | |
82 | + GtkWidget * pw3270_toolbar_settings_new() { | |
165 | 83 | |
166 | - page->parent.load = load; | |
167 | - page->parent.apply = apply; | |
168 | - page->parent.label = _("Toolbar"); | |
169 | - page->parent.title = _("Setup toolbar"); | |
84 | + size_t ix; | |
170 | 85 | |
171 | - page->parent.widget = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); | |
86 | + // Create page widget. | |
87 | + PW3270Settings * settings = pw3270_settings_new(); | |
88 | + settings->label = _("Toolbar"); | |
89 | + settings->title = _("Setup toolbar"); | |
90 | + settings->apply = apply; | |
91 | + settings->load = load; | |
172 | 92 | |
93 | + // Create private data. | |
94 | + PW3270SettingsPrivate * page = settings->settings = g_new0(PW3270SettingsPrivate,1); | |
173 | 95 | |
174 | 96 | // |
175 | 97 | // Create views |
... | ... | @@ -180,13 +102,11 @@ |
180 | 102 | GtkGrid * grid = GTK_GRID(gtk_grid_new()); |
181 | 103 | gtk_grid_set_row_homogeneous(grid,FALSE); |
182 | 104 | |
183 | - gtk_box_pack_start( | |
184 | - GTK_BOX(page->parent.widget), | |
185 | - pw3270_frame_new(GTK_WIDGET(grid), _("Actions")), | |
186 | - TRUE, | |
187 | - TRUE, | |
188 | - 0 | |
189 | - ); | |
105 | + gtk_grid_attach( | |
106 | + GTK_GRID(settings), | |
107 | + pw3270_frame_new(GTK_WIDGET(grid), _("Actions")), | |
108 | + 0,0,4,3 | |
109 | + ); | |
190 | 110 | |
191 | 111 | static const gchar *labels[G_N_ELEMENTS(page->views)] = { |
192 | 112 | N_("Selected"), |
... | ... | @@ -281,13 +201,11 @@ |
281 | 201 | { |
282 | 202 | GtkGrid * grid = GTK_GRID(gtk_grid_new()); |
283 | 203 | |
284 | - gtk_box_pack_start( | |
285 | - GTK_BOX(page->parent.widget), | |
286 | - pw3270_frame_new(GTK_WIDGET(grid), _("Options")), | |
287 | - FALSE, | |
288 | - TRUE, | |
289 | - 0 | |
290 | - ); | |
204 | + gtk_grid_attach( | |
205 | + GTK_GRID(settings), | |
206 | + pw3270_frame_new(GTK_WIDGET(grid), _("Options")), | |
207 | + 0,5,4,1 | |
208 | + ); | |
291 | 209 | |
292 | 210 | // https://developer.gnome.org/hig/stable/visual-layout.html.en |
293 | 211 | gtk_grid_set_row_spacing(grid,6); |
... | ... | @@ -318,5 +236,133 @@ |
318 | 236 | |
319 | 237 | } |
320 | 238 | |
239 | + return GTK_WIDGET(settings); | |
240 | + } | |
241 | + | |
242 | + void load(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate *page) { | |
243 | + | |
244 | + size_t ix; | |
245 | + g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); | |
246 | + | |
247 | + // Populate views | |
248 | + Pw3270ActionList * action_list = pw3270_action_list_new(GTK_APPLICATION(g_application_get_default())); | |
249 | + | |
250 | + // Load current values. | |
251 | + g_autofree gchar * action_names = g_settings_get_string(settings,"toolbar-action-names"); | |
252 | + | |
253 | + gchar ** actions = g_strsplit(action_names,",",-1); | |
254 | + | |
255 | + for(ix = 0; actions[ix]; ix++) { | |
256 | + | |
257 | + if(g_ascii_strcasecmp(actions[ix],"separator")) { | |
258 | + | |
259 | + // It's an action | |
260 | + action_list = pw3270_action_list_move_action(action_list,actions[ix],page->views[0]); | |
261 | + | |
262 | + } else { | |
263 | + | |
264 | + // It's a separator | |
265 | + pw3270_action_view_append(page->views[0], _( "Separator"), NULL, "separator", 2); | |
266 | + | |
267 | + } | |
268 | + | |
269 | + } | |
270 | + | |
271 | + g_strfreev(actions); | |
272 | + | |
273 | + // Load available actions. | |
274 | + pw3270_action_view_set_actions(page->views[1], action_list); | |
275 | + pw3270_action_view_append(page->views[1], _( "Separator"), NULL, "separator", 1); | |
276 | + | |
277 | + pw3270_action_list_free(action_list); | |
278 | + | |
279 | + GtkTreeIter iter; | |
280 | + | |
281 | + for(ix = 0; ix < G_N_ELEMENTS(page->combos); ix++) { | |
282 | + | |
283 | + pw3270_model_get_iter_from_value( | |
284 | + gtk_combo_box_get_model(GTK_COMBO_BOX(page->combos[ix])), | |
285 | + &iter, | |
286 | + (guint) g_settings_get_int(settings,comboboxes[ix].name) | |
287 | + ); | |
288 | + | |
289 | + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(page->combos[ix]),&iter); | |
290 | + | |
291 | + } | |
292 | + | |
293 | + } | |
294 | + | |
295 | + void apply(GtkWidget G_GNUC_UNUSED(*widget), PW3270SettingsPrivate *page) { | |
296 | + | |
297 | + size_t ix; | |
298 | + g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); | |
299 | + | |
300 | + debug("%s",__FUNCTION__); | |
301 | + | |
302 | + g_autofree gchar * action_names = pw3270_action_view_get_action_names(page->views[0]); | |
303 | + g_settings_set_string(settings,"toolbar-action-names",action_names); | |
304 | + | |
305 | + debug("[%s]",action_names); | |
306 | + | |
307 | + GtkTreeIter iter; | |
308 | + for(ix = 0; ix < G_N_ELEMENTS(page->combos); ix++) { | |
309 | + | |
310 | + if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(page->combos[ix]),&iter)) { | |
311 | + | |
312 | + g_settings_set_int( | |
313 | + settings, | |
314 | + comboboxes[ix].name, | |
315 | + (gint) pw3270_model_get_value_from_iter(gtk_combo_box_get_model(GTK_COMBO_BOX(page->combos[ix])),&iter) | |
316 | + ); | |
317 | + | |
318 | + } | |
319 | + | |
320 | + } | |
321 | + | |
322 | + } | |
323 | + | |
324 | + /* | |
325 | + | |
326 | + typedef struct _ToolbarSettingsPage { | |
327 | + Pw3270SettingsPage parent; | |
328 | + GtkWidget * views[2]; | |
329 | + GtkWidget * buttons[2]; | |
330 | + GtkTreeModel * models[2]; | |
331 | + GtkWidget * combos[G_N_ELEMENTS(comboboxes)]; | |
332 | + | |
333 | + } ToolbarSettingsPage; | |
334 | + | |
335 | + static void load(Pw3270SettingsPage *pg, GtkApplication *application) { | |
336 | + | |
337 | + size_t ix; | |
338 | + ToolbarSettingsPage * page = (ToolbarSettingsPage *) pg; | |
339 | + g_autoptr(GSettings) settings = pw3270_application_window_settings_new(); | |
340 | + | |
341 | + debug("%s",__FUNCTION__); | |
342 | + | |
343 | + | |
344 | + } | |
345 | + | |
346 | + static void apply(Pw3270SettingsPage *pg, GtkApplication G_GNUC_UNUSED(*application)) { | |
347 | + | |
348 | + } | |
349 | + | |
350 | + | |
351 | + Pw3270SettingsPage * pw3270_toolbar_settings_new() { | |
352 | + | |
353 | + size_t ix; | |
354 | + | |
355 | + ToolbarSettingsPage * page = g_new0(ToolbarSettingsPage,1); | |
356 | + | |
357 | + page->parent.load = load; | |
358 | + page->parent.apply = apply; | |
359 | + page->parent.label = _("Toolbar"); | |
360 | + page->parent.title = _("Setup toolbar"); | |
361 | + | |
362 | + page->parent.widget = gtk_box_new(GTK_ORIENTATION_VERTICAL,0); | |
363 | + | |
364 | + | |
365 | + | |
321 | 366 | return (Pw3270SettingsPage *) page; |
322 | 367 | } |
368 | + */ | ... | ... |
src/objects/window/page.c
... | ... | @@ -240,6 +240,7 @@ |
240 | 240 | |
241 | 241 | debug("%s",__FUNCTION__); |
242 | 242 | |
243 | + /* | |
243 | 244 | GtkWidget * dialog = pw3270_settings_dialog_new( |
244 | 245 | _("Rename session"), |
245 | 246 | GTK_WINDOW(gtk_widget_get_toplevel(terminal)) |
... | ... | @@ -290,7 +291,7 @@ |
290 | 291 | } |
291 | 292 | |
292 | 293 | gtk_widget_destroy(dialog); |
293 | - | |
294 | + */ | |
294 | 295 | |
295 | 296 | } |
296 | 297 | ... | ... |