settings.c
8.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
* "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
* (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
* aplicativos mainframe. Registro no INPI sob o nome G3270.
*
* Copyright (C) <2008> <Banco do Brasil S.A.>
*
* Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
* os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
* Free Software Foundation.
*
* Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
* GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
* A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
* obter mais detalhes.
*
* Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
* programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
* St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Este programa está nomeado como - e possui - linhas de código.
*
* Contatos:
*
* perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
* erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
*
*/
#include "private.h"
#include <pw3270.h>
#include <pw3270/settings.h>
#include <pw3270/toolbar.h>
#include <pw3270/actions.h>
#include <pw3270/window.h>
#include <v3270/dialogs.h>
static void load(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
static void apply(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page);
/*--[ Constants ]------------------------------------------------------------------------------------*/
static const struct _comboboxes {
const gchar * name; ///< @brief The gsettings name.
const gchar * label; ///< @brief The combo name.
guint left;
guint top;
} comboboxes[] = {
{
.left = 0,
.top = 0,
.name = "toolbar-icon-size",
.label = N_("Icon Size"),
},
{
.left = 3,
.top = 0,
.name = "toolbar-icon-type",
.label = N_("Icon Style")
},
{
.left = 0,
.top = 1,
.name = "toolbar-style",
.label = N_("Toolbar Style")
},
{
.left = 3,
.top = 1,
.name = "toolbar-position",
.label = N_("Toolbar position")
}
};
struct _PW3270SettingsPage {
GtkWidget * views[2];
GtkWidget * combos[G_N_ELEMENTS(comboboxes)];
};
/*--[ Implement ]------------------------------------------------------------------------------------*/
GtkWidget * pw3270_toolbar_settings_new() {
size_t ix;
// Create page widget.
PW3270Settings * settings = pw3270_settings_new();
settings->label = _("Toolbar");
settings->title = _("Setup toolbar");
settings->apply = apply;
settings->load = load;
// Create private data.
PW3270SettingsPage * page = settings->settings = g_new0(PW3270SettingsPage,1);
//
// Create views
//
{
GtkTreeSelection * selection;
GtkGrid * grid = GTK_GRID(gtk_grid_new());
gtk_grid_set_row_homogeneous(grid,FALSE);
gtk_grid_attach(
GTK_GRID(settings),
v3270_dialog_section_new(_("Itens"), _("Select the toolbar itens"), GTK_WIDGET(grid)),
0,0,4,3
);
static const gchar *labels[G_N_ELEMENTS(page->views)] = {
N_("Selected"),
N_("Available")
};
for(ix = 0; ix < G_N_ELEMENTS(page->views); ix++) {
GtkWidget * label = gtk_label_new(gettext(labels[ix]));
gtk_label_set_xalign(GTK_LABEL(label),0);
page->views[ix] = pw3270_action_view_new();
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(page->views[ix]));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE);
gtk_grid_attach(
grid,
label,
ix * 3,0,2,1
);
GtkWidget * box = gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(box),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(box),GTK_SHADOW_ETCHED_IN);
gtk_container_add(GTK_CONTAINER(box),page->views[ix]);
gtk_grid_attach(
grid,
box,
ix * 3,1,2,4
);
}
gtk_tree_view_set_reorderable(GTK_TREE_VIEW(page->views[0]),TRUE);
pw3270_action_view_order_by_label(page->views[1]);
// Create buttons
GtkWidget * box = gtk_button_box_new(GTK_ORIENTATION_VERTICAL);
gtk_widget_set_hexpand(box,FALSE);
gtk_widget_set_vexpand(box,FALSE);
GtkWidget * buttons[] = {
pw3270_action_view_move_button_new(page->views[0],page->views[1],"go-next"),
pw3270_action_view_move_button_new(page->views[1],page->views[0],"go-previous"),
};
gtk_box_pack_start(GTK_BOX(box),buttons[0],FALSE,FALSE,0);
gtk_box_pack_end(GTK_BOX(box),buttons[1],FALSE,FALSE,0);
gtk_grid_attach(
grid,
box,
2,2,1,1
);
}
//
// Create Combos.
//
{
GtkGrid * grid = GTK_GRID(gtk_grid_new());
gtk_grid_attach(
GTK_GRID(settings),
v3270_dialog_section_new(_("Style & Position"), _("Setup the toolbar style and position"), GTK_WIDGET(grid)),
0,5,4,1
);
// https://developer.gnome.org/hig/stable/visual-layout.html.en
gtk_grid_set_row_spacing(grid,6);
gtk_grid_set_column_spacing(grid,12);
gtk_widget_set_hexpand(GTK_WIDGET(grid),TRUE);
GtkCellRenderer * renderer = gtk_cell_renderer_text_new();
for(ix = 0; ix < G_N_ELEMENTS(page->combos); ix++) {
GtkTreeModel *model = pw3270_model_from_name(comboboxes[ix].name);
GtkWidget * label = gtk_label_new(gettext(comboboxes[ix].label));
gtk_label_set_xalign(GTK_LABEL(label),1);
gtk_grid_attach(grid,label,comboboxes[ix].left,comboboxes[ix].top,1,1);
page->combos[ix] = gtk_combo_box_new_with_model(model);
gtk_widget_set_hexpand(page->combos[ix],FALSE);
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(page->combos[ix]), renderer, TRUE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(page->combos[ix]), renderer, "text", 0, NULL);
gtk_grid_attach(grid,page->combos[ix],comboboxes[ix].left+1,comboboxes[ix].top,2,1);
}
{
GtkWidget * label = gtk_label_new("");
gtk_label_set_markup(GTK_LABEL(label),_("<small><b>The toolbar position only takes effect after restart</b></small>"));
g_object_set(G_OBJECT(label),"margin-top",12,NULL);
gtk_grid_attach(grid,label,0,3,6,1);
}
}
return GTK_WIDGET(settings);
}
void load(GtkWidget *widget, GSettings *settings, PW3270SettingsPage *page) {
size_t ix;
if(!G_IS_SETTINGS(settings)) {
g_warning("The settings object is not valid, disabling dialog to avoid segfaults");
gtk_widget_set_sensitive(widget,FALSE);
return;
}
// Populate views
Pw3270ActionList * action_list = pw3270_action_list_new(GTK_APPLICATION(g_application_get_default()));
// Load current values.
g_autofree gchar * action_names = g_settings_get_string(settings,"toolbar-action-names");
gchar ** actions = g_strsplit(action_names,",",-1);
for(ix = 0; actions[ix]; ix++) {
if(g_ascii_strcasecmp(actions[ix],"separator")) {
// It's an action
action_list = pw3270_action_list_move_action(action_list,actions[ix],page->views[0]);
} else {
// It's a separator
pw3270_action_view_append(page->views[0], _( "Separator"), NULL, "separator", 2);
}
}
g_strfreev(actions);
// Load available actions.
pw3270_action_view_set_actions(page->views[1], action_list);
pw3270_action_view_append(page->views[1], _( "Separator"), NULL, "separator", PW3270_ACTION_VIEW_FLAG_ALLOW_ADD);
pw3270_action_list_free(action_list);
GtkTreeIter iter;
for(ix = 0; ix < G_N_ELEMENTS(page->combos); ix++) {
pw3270_model_get_iter_from_value(
gtk_combo_box_get_model(GTK_COMBO_BOX(page->combos[ix])),
&iter,
(guint) g_settings_get_int(settings,comboboxes[ix].name)
);
gtk_combo_box_set_active_iter(GTK_COMBO_BOX(page->combos[ix]),&iter);
}
}
void apply(GtkWidget G_GNUC_UNUSED(*widget), GSettings *settings, PW3270SettingsPage *page) {
size_t ix;
g_autofree gchar * action_names = pw3270_action_view_get_action_names(page->views[0]);
g_settings_set_string(settings,"toolbar-action-names",action_names);
GtkTreeIter iter;
for(ix = 0; ix < G_N_ELEMENTS(page->combos); ix++) {
if(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(page->combos[ix]),&iter)) {
g_settings_set_int(
settings,
comboboxes[ix].name,
(gint) pw3270_model_get_value_from_iter(gtk_combo_box_get_model(GTK_COMBO_BOX(page->combos[ix])),&iter)
);
}
}
}