builder.c
3.15 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
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/*
* Copyright (C) <2008> <Banco do Brasil S.A.>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "private.h"
#include <pw3270/application.h>
#include <pw3270/keypad.h>
static GMenu * get_keypad_menu(GApplication *application) {
GList * keypads = pw3270_application_get_keypad_models(application);
if(!keypads)
return NULL;
GMenu * menu = g_menu_new();
// Create keypad items.
GList *item;
for(item = keypads; item; item = g_list_next(item)) {
GObject * model = G_OBJECT(item->data);
g_autofree gchar * action_name = g_strconcat("win.keypad.",pw3270_keypad_model_get_name(model),NULL);
g_menu_append(menu,pw3270_keypad_model_get_label(model),action_name);
}
return menu;
}
GtkBuilder * pw3270_application_builder_new(GApplication *application) {
#if !defined(DEBUG)
lib3270_autoptr(char) filename = lib3270_build_data_filename(G_STRINGIFY(PRODUCT_NAME) ".ui.xml",NULL);
#elif defined(G_OS_UNIX)
static const char * filename = "ui/linux.ui.xml";
#elif defined(G_OS_WIN32)
static const char * filename = "ui/windows.ui.xml";
#else
#error Cant determine platform based UI definition
#endif // DEBUG
GtkBuilder * builder = gtk_builder_new_from_file(filename);
//
// Load placeholders
//
GObject * placeholder;
size_t ix;
//
// Load fonts
//
placeholder = gtk_builder_get_object(builder, "font-select-placeholder");
if(placeholder && G_IS_MENU(placeholder)) {
GMenu * font_menu = G_MENU(placeholder);
gint n_families;
PangoFontFamily **families;
pango_context_list_families(gdk_pango_context_get_for_screen(gdk_screen_get_default()),&families, &n_families);
for(ix=0; ix < (size_t) n_families; ix++) {
if(!pango_font_family_is_monospace(families[ix]))
continue;
const gchar * family = pango_font_family_get_name(families[ix]);
g_autofree gchar * detailed_action = g_strconcat("win.font-family::",family,NULL);
g_menu_append(font_menu,family,detailed_action);
}
}
//
// View options
//
GMenu * keypad_menu = get_keypad_menu(application);
if(keypad_menu) {
static const gchar * placeholders[] = {
"view-menu-placeholder",
"view-when-offline-placeholder",
"view-when-online-placeholder"
};
for(ix = 0; ix < G_N_ELEMENTS(placeholders); ix++) {
placeholder = gtk_builder_get_object(builder, placeholders[ix]);
if(placeholder && G_IS_MENU(placeholder)) {
g_menu_append_item(G_MENU(placeholder), g_menu_item_new_submenu(_("Keypads"),G_MENU_MODEL(keypad_menu)));
}
}
g_object_unref(keypad_menu);
}
return builder;
}