application.c
4.63 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
/*
* "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)
*
* References:
*
* https://fossies.org/linux/gtk+/examples/plugman.c
*
*/
#include "private.h"
#include <pw3270/application.h>
struct _pw3270ApplicationClass {
GtkApplicationClass parent_class;
};
struct _pw3270Application {
GtkApplication parent;
};
static void startup(GApplication * application);
static void activate(GApplication * application);
static void open(GApplication * application, GFile **files, gint n_files, const gchar *hint);
G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION);
static void pw3270Application_class_init(pw3270ApplicationClass *klass) {
GApplicationClass *application_class = G_APPLICATION_CLASS(klass);
application_class->startup = startup;
application_class->activate = activate;
application_class->open = open;
}
static void pw3270Application_init(pw3270Application *app) {
}
GtkApplication * pw3270_application_new(const gchar *application_id, GApplicationFlags flags) {
return g_object_new(
PW3270_TYPE_APPLICATION,
"application-id", application_id,
"flags", G_APPLICATION_HANDLES_OPEN,
NULL);
}
void startup(GApplication *application) {
G_APPLICATION_CLASS(pw3270Application_parent_class)->startup(application);
//
// Setup application default actions.
//
static GActionEntry actions[] = {
{
.name = "about",
.activate = pw3270_application_generic_activated,
},
{
.name = "preferences",
.activate = pw3270_application_generic_activated,
},
{
.name = "quit",
.activate = pw3270_application_quit_activated,
},
{
.name = "new.tab",
.activate = pw3270_application_new_tab_activated,
},
{
.name = "new.window",
.activate = pw3270_application_new_window_activated,
},
{
.name = "open",
.activate = pw3270_application_generic_activated,
},
{
.name = "open.tab",
.activate = pw3270_application_generic_activated,
},
{
.name = "open.window",
.activate = pw3270_application_generic_activated,
},
};
g_action_map_add_action_entries(
G_ACTION_MAP(application),
actions,
G_N_ELEMENTS(actions),
application
);
//
// Setup application menus
//
GtkBuilder * builder = gtk_builder_new_from_file("ui/application.xml");
gtk_application_set_app_menu(GTK_APPLICATION (application), G_MENU_MODEL(gtk_builder_get_object (builder, "app-menu")));
if(pw3270_application_get_ui_type(application) == PW3270_UI_STYLE_CLASSICAL)
gtk_application_set_menubar(GTK_APPLICATION (application), G_MENU_MODEL(gtk_builder_get_object (builder, "menubar")));
g_object_unref(builder);
}
void activate(GApplication *application) {
GtkWidget * window = pw3270_application_window_new(GTK_APPLICATION(application));
// Create terminal widget
pw3270_terminal_new(window);
// Present the new window
gtk_window_present(GTK_WINDOW(window));
pw3270_window_set_current_page(window,0);
}
void open(GApplication *application, GFile **files, gint n_files, const gchar *hint) {
GtkWindow * window = gtk_application_get_active_window(GTK_APPLICATION(application));
debug("%s was called with %d files (active_window=%p)", __FUNCTION__, n_files, window);
if(!window)
window = GTK_WINDOW(pw3270_application_window_new(GTK_APPLICATION(application)));
// Add tabs to the window
gint file;
gint last = -1;
for(file = 0; file < n_files; file++) {
last = pw3270_window_append_page(GTK_WIDGET(window), files[file]);
}
gtk_window_present(window);
if(last != -1)
pw3270_window_set_current_page(GTK_WIDGET(window),last);
}