tools.c
2.74 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
/* 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/>.
*/
/**
* @brief Misc tools for pw3270 application.
*
*/
#include "private.h"
#include <pw3270.h>
#include <pw3270/application.h>
#include <pw3270/settings.h>
#include <pw3270/window.h>
/*---[ Implement ]----------------------------------------------------------------------------------*/
GtkBuilder * pw3270_application_get_builder(const gchar *name) {
#ifdef DEBUG
g_autofree gchar * filename = g_build_filename("ui",name,NULL);
#else
lib3270_autoptr(char) filename = lib3270_build_data_filename("ui",name,NULL);
#endif // DEBUG
return gtk_builder_new_from_file(filename);
}
void gtk_container_remove_all(GtkContainer *container) {
GList * children = gtk_container_get_children(container);
GList * item;
for(item = children; item; item = g_list_next(item)) {
gtk_container_remove(container,GTK_WIDGET(item->data));
}
g_list_free(children);
}
void gtk_file_chooser_set_pw3270_filters(GtkFileChooser *chooser) {
static const struct Filter {
const gchar * name;
const gchar * pattern;
} filters[] = {
{
.name = N_("TN3270 Session Files"),
.pattern = "*.3270"
},
{
.name = N_("All files"),
.pattern = "*.*"
}
};
size_t ix;
for(ix = 0; ix < G_N_ELEMENTS(filters); ix++) {
GtkFileFilter *filter = gtk_file_filter_new();
gtk_file_filter_add_pattern (filter, filters[ix].pattern);
gtk_file_filter_set_name(filter, filters[ix].name);
gtk_file_chooser_add_filter(chooser,filter);
}
}
GtkWidget * pw3270_get_active_terminal() {
GApplication *app = g_application_get_default();
g_return_val_if_fail(GTK_IS_APPLICATION(app),NULL);
GtkWindow * window = gtk_application_get_active_window(GTK_APPLICATION(app));
return pw3270_application_window_get_active_terminal(GTK_WIDGET(window));
}
H3270 * pw3270_get_active_session() {
GApplication *app = g_application_get_default();
g_return_val_if_fail(GTK_IS_APPLICATION(app),NULL);
GtkWindow * window = gtk_application_get_active_window(GTK_APPLICATION(app));
return pw3270_window_get_session_handle(GTK_WIDGET(window));
}