testprogram.c
5.29 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
/*
* "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. 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 testprogram.c e possui - linhas de código.
*
* Contatos:
*
* perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
* erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
*
*/
/**
* @brief V3270 Widget test program.
*
*/
#include "private.h"
#include <v3270/filetransfer.h>
#include <v3270/ftprogress.h>
#include <v3270/colorscheme.h>
#include <v3270/settings.h>
#include <v3270/trace.h>
#include <lib3270/log.h>
#include <lib3270/properties.h>
#include <v3270/actions.h>
#include <stdlib.h>
#include <gdk/gdkkeysyms-compat.h>
#include <locale.h>
#include <libintl.h>
#include <v3270/selection.h>
/*---[ Implement ]----------------------------------------------------------------------------------*/
static void session_changed(GtkWidget *terminal, GtkWidget *window) {
gtk_window_set_title(GTK_WINDOW(window),v3270_get_session_title(terminal));
}
/*
static gboolean field_clicked(GtkWidget *widget, gboolean connected, V3270_OIA_FIELD field, GdkEventButton *event, GtkWidget *window) {
debug("%s: %s field=%d event=%p window=%p",__FUNCTION__,connected ? "Connected" : "Disconnected", field, event, window);
if(!connected)
return FALSE;
if(field == V3270_OIA_SSL) {
// v3270_popup_security_dialog(widget);
debug("%s: Show SSL connection info dialog",__FUNCTION__);
return TRUE;
}
return FALSE;
}
*/
static GKeyFile * get_key_file()
{
GKeyFile * key_file = g_key_file_new();
g_key_file_load_from_file(key_file,"terminal.conf",G_KEY_FILE_NONE,NULL);
return key_file;
}
static void save_settings(GtkWidget *terminal, GtkWidget *window)
{
debug("%s: Saving settings for window %p",__FUNCTION__,window);
GKeyFile * key_file = get_key_file();
v3270_to_key_file(terminal,key_file,"terminal");
v3270_accelerator_map_to_key_file(terminal, key_file, "accelerators");
g_key_file_save_to_file(key_file,"terminal.conf",NULL);
g_key_file_free(key_file);
}
static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) {
GtkWidget * window = gtk_application_window_new(app);
GtkWidget * terminal = v3270_new();
GtkWidget * vBox = gtk_box_new(GTK_ORIENTATION_VERTICAL,2);
GtkWidget * notebook = gtk_notebook_new();
// Hack to speed up the tests.
//lib3270_ssl_set_crl_download(v3270_get_session(terminal),0);
gtk_box_pack_start(GTK_BOX(vBox),create_toolbar(terminal),FALSE,TRUE,0);
gtk_box_pack_start(GTK_BOX(vBox),notebook,TRUE,TRUE,0);
// Create Terminal window
{
gtk_widget_set_can_default(terminal,TRUE);
#if GTK_CHECK_VERSION(3,20,0)
gtk_widget_set_focus_on_click(terminal,TRUE);
#endif // GTK 3,20,0
gtk_notebook_append_page(GTK_NOTEBOOK(notebook),terminal,gtk_label_new("Terminal"));
// Load settings before connecting the signals.
debug("%s: Loading settings...",__FUNCTION__);
GKeyFile * key_file = get_key_file();
v3270_load_key_file(terminal,key_file,NULL);
v3270_accelerator_map_load_key_file(terminal,key_file,NULL);
g_key_file_free(key_file);
}
// Create trace window
v3270_set_trace(terminal,TRUE);
// Setup and show main window
g_autofree gchar * title = v3270_get_session_title(terminal);
gtk_window_set_title(GTK_WINDOW(window),title);
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
gtk_window_set_default_size (GTK_WINDOW (window), 800, 500);
gtk_container_add(GTK_CONTAINER(window),vBox);
gtk_widget_show_all(window);
g_signal_connect(G_OBJECT(terminal),"session_changed",G_CALLBACK(session_changed),window);
g_signal_connect(G_OBJECT(terminal),"save-settings",G_CALLBACK(save_settings),window);
// g_signal_connect(G_OBJECT(terminal),"field_clicked",G_CALLBACK(field_clicked),window);
gtk_widget_grab_focus(terminal);
}
int main (int argc, char **argv) {
GtkApplication *app;
int status;
// Setup locale
#ifdef LC_ALL
setlocale( LC_ALL, "" );
#endif
#ifdef _WIN32
// https://stackoverflow.com/questions/37035936/how-to-get-native-windows-decorations-on-gtk3-on-windows-7-and-msys2
putenv("GTK_CSD=0");
#endif // _WIN32
bind_textdomain_codeset("libv3270", "UTF-8");
textdomain("libv3270");
app = gtk_application_new ("br.com.bb.libv3270",G_APPLICATION_FLAGS_NONE);
g_signal_connect (app, "activate", G_CALLBACK(activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
g_message("rc=%d",status);
return 0;
}