Commit b7b8a75e589e4f2b29567fd3375995bc380bd236

Authored by Perry Werneck
1 parent 4b6b7ca3

Refactoring terminal support methods.

pw3270.cbp
... ... @@ -108,6 +108,9 @@
108 108 <Unit filename="src/objects/application/application.c">
109 109 <Option compilerVar="CC" />
110 110 </Unit>
  111 + <Unit filename="src/objects/application/open.c">
  112 + <Option compilerVar="CC" />
  113 + </Unit>
111 114 <Unit filename="src/objects/application/private.h" />
112 115 <Unit filename="src/objects/toolbar/actions.c">
113 116 <Option compilerVar="CC" />
... ... @@ -143,6 +146,9 @@
143 146 <Unit filename="src/objects/window/header.c">
144 147 <Option compilerVar="CC" />
145 148 </Unit>
  149 + <Unit filename="src/objects/window/page.c">
  150 + <Option compilerVar="CC" />
  151 + </Unit>
146 152 <Unit filename="src/objects/window/private.h" />
147 153 <Unit filename="src/objects/window/terminal.c">
148 154 <Option compilerVar="CC" />
... ...
src/include/pw3270/window.h
... ... @@ -71,9 +71,6 @@
71 71 /// @brief Switches to the page number page_num.
72 72 void pw3270_window_set_current_page(GtkWidget *window, gint page_num);
73 73  
74   - /// @brief Appends a new terminal to window.
75   - gint pw3270_window_append_page(GtkWidget *window, GFile *file);
76   -
77 74 /// @brief Set window sub-title (If enabled).
78 75 void pw3270_window_set_subtitle(GtkWidget *window, const gchar *subtitle);
79 76  
... ...
src/objects/application/application.c
... ... @@ -60,7 +60,6 @@
60 60  
61 61 static void startup(GApplication * application);
62 62 static void activate(GApplication * application);
63   - static void open(GApplication * application, GFile **files, gint n_files, const gchar *hint);
64 63 static void finalize(GObject *object);
65 64  
66 65 G_DEFINE_TYPE(pw3270Application, pw3270Application, GTK_TYPE_APPLICATION);
... ... @@ -102,7 +101,7 @@
102 101  
103 102 application_class->startup = startup;
104 103 application_class->activate = activate;
105   - application_class->open = open;
  104 + application_class->open = pw3270_application_open;
106 105  
107 106 props[PROP_UI_STYLE] =
108 107 g_param_spec_uint(
... ... @@ -294,37 +293,6 @@
294 293  
295 294 }
296 295  
297   - void open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) {
298   -
299   -#ifndef DEBUG
300   - #error Implementar
301   -#endif // DEBUG
302   -
303   - /*
304   - GtkWindow * window = gtk_application_get_active_window(GTK_APPLICATION(application));
305   -
306   - debug("%s was called with %d files (active_window=%p)", __FUNCTION__, n_files, window);
307   -
308   - if(!window)
309   - window = GTK_WINDOW(pw3270_application_window_new(GTK_APPLICATION(application)));
310   -
311   - // Add tabs to the window
312   - gint file;
313   - gint last = -1;
314   -
315   - for(file = 0; file < n_files; file++) {
316   - last = pw3270_window_append_page(GTK_WIDGET(window), files[file]);
317   - }
318   -
319   - gtk_window_present(window);
320   -
321   - if(last != -1)
322   - pw3270_window_set_current_page(GTK_WIDGET(window),last);
323   -
324   - */
325   -
326   - }
327   -
328 296 void pw3270_application_set_ui_style(GApplication *app, PW3270_UI_STYLE type) {
329 297  
330 298 g_return_if_fail(PW3270_IS_APPLICATION(app));
... ...
src/objects/application/open.c 0 → 100644
... ... @@ -0,0 +1,63 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include "private.h"
  31 +
  32 + void pw3270_application_open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) {
  33 +
  34 + GtkWindow * window = gtk_application_get_active_window(GTK_APPLICATION(application));
  35 +
  36 + gint file;
  37 + gint last = -1;
  38 +
  39 + for(file = 0; file < n_files; file++) {
  40 +
  41 +
  42 + }
  43 +
  44 + /*
  45 +
  46 + debug("%s was called with %d files (active_window=%p)", __FUNCTION__, n_files, window);
  47 +
  48 + if(!window)
  49 + window = GTK_WINDOW(pw3270_application_window_new(GTK_APPLICATION(application)));
  50 +
  51 + // Add tabs to the window
  52 + last = pw3270_window_append_page(GTK_WIDGET(window), files[file]);
  53 + }
  54 +
  55 +
  56 + if(last != -1)
  57 + pw3270_window_set_current_page(GTK_WIDGET(window),last);
  58 +
  59 + */
  60 +
  61 + gtk_window_present(window);
  62 + }
  63 +
... ...
src/objects/application/private.h
... ... @@ -46,6 +46,10 @@
46 46 #include <lib3270.h>
47 47 #include <lib3270/log.h>
48 48  
  49 + G_GNUC_INTERNAL void pw3270_application_open(GApplication * application, GFile **files, gint n_files, const gchar *hint);
  50 + G_GNUC_INTERNAL gint pw3270_application_window_append_page(GtkWidget *window, GtkWidget *terminal);
  51 + G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file);
  52 +
49 53 // Actions
50 54 G_GNUC_INTERNAL void pw3270_application_generic_activated(GSimpleAction * action, GVariant *parameter, gpointer application);
51 55 G_GNUC_INTERNAL void pw3270_application_quit_activated(GSimpleAction * action, GVariant *parameter, gpointer application);
... ...
src/objects/window/header.c
... ... @@ -84,7 +84,7 @@
84 84  
85 85 }
86 86  
87   - static void on_sensitive(GtkWidget G_GNUC_UNUSED(*button), GParamSpec G_GNUC_UNUSED(*spec), GtkWidget *widget) {
  87 + static void on_sensitive(GtkWidget G_GNUC_UNUSED(*button), GParamSpec G_GNUC_UNUSED(*spec), GtkWidget G_GNUC_UNUSED(*widget)) {
88 88  
89 89 gboolean sensitive;
90 90 g_object_get(button, "sensitive", &sensitive, NULL);
... ...
src/objects/window/page.c 0 → 100644
... ... @@ -0,0 +1,228 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + *
  28 + */
  29 +
  30 + #include "private.h"
  31 + #include <pw3270/actions.h>
  32 + #include <lib3270/toggle.h>
  33 + #include <v3270/settings.h>
  34 + #include <v3270/actions.h>
  35 + #include <v3270/print.h>
  36 +
  37 + static gboolean on_terminal_focus(GtkWidget *terminal, GdkEvent G_GNUC_UNUSED(*event), GtkWindow * window);
  38 + static void session_changed(GtkWidget *terminal, GtkWidget *label);
  39 + static void disconnected(GtkWidget *terminal, GtkWindow * window);
  40 + static void connected(GtkWidget *terminal, const gchar *host, GtkWindow * window);
  41 + static void destroy(GtkWidget *terminal, GtkWindow * window);
  42 + static void close_page(GtkButton *button, GtkWidget *terminal);
  43 + static gboolean on_popup_menu(GtkWidget *widget, gboolean selected, gboolean online, GdkEvent *event, pw3270ApplicationWindow * window);
  44 +
  45 + gint pw3270_application_window_append_page(pw3270ApplicationWindow * window, GtkWidget * terminal) {
  46 +
  47 + GtkWidget * label = gtk_label_new(v3270_get_session_name(terminal));
  48 + GtkWidget * tab = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2);
  49 + GtkWidget * button = gtk_button_new_from_icon_name("window-close-symbolic",GTK_ICON_SIZE_MENU);
  50 +
  51 + gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE);
  52 +
  53 + debug("notebook: %p", window->notebook);
  54 +
  55 + g_signal_connect(G_OBJECT(terminal), "focus-in-event", G_CALLBACK(on_terminal_focus), window);
  56 + g_signal_connect(G_OBJECT(terminal), "session_changed", G_CALLBACK(session_changed),label);
  57 + g_signal_connect(G_OBJECT(terminal), "disconnected", G_CALLBACK(disconnected),window);
  58 + g_signal_connect(G_OBJECT(terminal), "connected", G_CALLBACK(connected),window);
  59 + g_signal_connect(G_OBJECT(terminal), "popup", G_CALLBACK(on_popup_menu), window);
  60 + g_signal_connect(G_OBJECT(terminal), "destroy", G_CALLBACK(destroy),window);
  61 +
  62 + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(close_page), terminal);
  63 +
  64 + gtk_box_pack_start(GTK_BOX(tab),label,FALSE,FALSE,0);
  65 + gtk_box_pack_end(GTK_BOX(tab),button,FALSE,FALSE,0);
  66 +
  67 + gtk_widget_show_all(terminal);
  68 + gtk_widget_show_all(tab);
  69 +
  70 + gint page = gtk_notebook_append_page(window->notebook,terminal,tab);
  71 +
  72 + gtk_notebook_set_tab_detachable(window->notebook,terminal,TRUE);
  73 + gtk_notebook_set_tab_reorderable(window->notebook,terminal,TRUE);
  74 +
  75 + // Setup session.
  76 +
  77 +// H3270 * hSession = v3270_get_session(terminal);
  78 +
  79 + return page;
  80 +
  81 + }
  82 +
  83 + static gboolean on_terminal_focus(GtkWidget *terminal, GdkEvent G_GNUC_UNUSED(*event), GtkWindow * window) {
  84 +
  85 + if(gtk_window_get_default_widget(window) == terminal) {
  86 + return FALSE;
  87 + }
  88 +
  89 + // Store the active terminal widget.
  90 + gtk_widget_grab_default(terminal);
  91 + debug("Terminal %p is now default",terminal);
  92 +
  93 + // Change window title
  94 + g_autofree gchar * title = v3270_get_session_title(terminal);
  95 + gtk_window_set_title(window, title);
  96 +
  97 + pw3270_window_set_subtitle(GTK_WIDGET(window), v3270_is_connected(terminal) ? _("Connected to host") : _("Disconnected from host"));
  98 +
  99 + // Update actions
  100 + size_t ix;
  101 + gchar ** actions = g_action_group_list_actions(G_ACTION_GROUP(window));
  102 +
  103 + for(ix = 0; actions[ix]; ix++) {
  104 +
  105 +// debug("%s",actions[ix]);
  106 +
  107 + GAction * action = g_action_map_lookup_action(G_ACTION_MAP(window), actions[ix]);
  108 +
  109 + if(action) {
  110 +
  111 + if(V3270_IS_ACTION(action)) {
  112 + v3270_action_set_terminal_widget(action,terminal);
  113 + } else if(PW3270_IS_ACTION(action)) {
  114 + pw3270_action_set_terminal_widget(action,terminal);
  115 + }
  116 +
  117 + }
  118 +
  119 + }
  120 +
  121 + g_strfreev(actions);
  122 +
  123 + return FALSE;
  124 + }
  125 +
  126 + static void session_changed(GtkWidget *terminal, GtkWidget *label) {
  127 +
  128 + gtk_label_set_text(GTK_LABEL(label),v3270_get_session_name(terminal));
  129 +
  130 + // Do I have to change the window title?
  131 + GtkWidget * toplevel = gtk_widget_get_toplevel(terminal);
  132 + if(PW3270_IS_APPLICATION_WINDOW(toplevel)) {
  133 +
  134 + pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(toplevel);
  135 +
  136 + if(gtk_widget_has_default(terminal)) {
  137 + g_autofree gchar * title = v3270_get_session_title(terminal);
  138 + gtk_window_set_title(GTK_WINDOW(window), title);
  139 + }
  140 +
  141 + }
  142 +
  143 + }
  144 +
  145 + static void disconnected(GtkWidget *terminal, GtkWindow * window) {
  146 +
  147 + debug("%s",__FUNCTION__);
  148 +
  149 + if(terminal != gtk_window_get_default_widget(window))
  150 + return;
  151 +
  152 + pw3270_window_set_subtitle(GTK_WIDGET(window), _("Disconnected from host"));
  153 +
  154 + }
  155 +
  156 + static void connected(GtkWidget *terminal, const gchar *host, GtkWindow * window) {
  157 +
  158 + debug("%s(%s)",__FUNCTION__,host);
  159 +
  160 + if(terminal != gtk_window_get_default_widget(window))
  161 + return;
  162 +
  163 + pw3270_window_set_subtitle(GTK_WIDGET(window), _("Connected to host"));
  164 +
  165 + }
  166 +
  167 + static void destroy(GtkWidget *terminal, GtkWindow * window) {
  168 +
  169 + if(gtk_window_get_default_widget(window) != terminal) {
  170 + return;
  171 + }
  172 +
  173 + gtk_window_set_default(window,NULL);
  174 + pw3270_window_set_subtitle(GTK_WIDGET(window), _("Disconnected from host"));
  175 +
  176 + // Update actions
  177 + size_t ix;
  178 + gchar ** actions = g_action_group_list_actions(G_ACTION_GROUP(window));
  179 +
  180 + for(ix = 0; actions[ix]; ix++) {
  181 +
  182 + GAction * action = g_action_map_lookup_action(G_ACTION_MAP(window), actions[ix]);
  183 +
  184 + if(action) {
  185 +
  186 + if(PW3270_IS_ACTION(action)) {
  187 + pw3270_action_set_terminal_widget(action,NULL);
  188 + } else if(V3270_IS_ACTION(action)) {
  189 + v3270_action_set_terminal_widget(action,NULL);
  190 + }
  191 +
  192 + }
  193 +
  194 + }
  195 +
  196 + g_strfreev(actions);
  197 +
  198 + }
  199 +
  200 + static void close_page(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) {
  201 +
  202 + GtkNotebook * notebook = GTK_NOTEBOOK(gtk_widget_get_parent(terminal));
  203 + gtk_notebook_remove_page(notebook,gtk_notebook_page_num(notebook, terminal));
  204 +
  205 + }
  206 +
  207 + static gboolean on_popup_menu(GtkWidget *widget, gboolean selected, gboolean online, GdkEvent *event, pw3270ApplicationWindow * window) {
  208 +
  209 + GtkWidget * popup = window->popups[PW3270_APP_WINDOW_POPUP_OVER_UNSELECTED_AREA];
  210 +
  211 + if(!online && window->popups[PW3270_APP_WINDOW_POPUP_WHEN_OFFLINE])
  212 + popup = window->popups[PW3270_APP_WINDOW_POPUP_WHEN_OFFLINE];
  213 + else if(selected && window->popups[PW3270_APP_WINDOW_POPUP_OVER_SELECTED_AREA])
  214 + popup = window->popups[PW3270_APP_WINDOW_POPUP_OVER_SELECTED_AREA];
  215 + else
  216 + popup = window->popups[PW3270_APP_WINDOW_POPUP_DEFAULT];
  217 +
  218 + if(!popup)
  219 + return FALSE;
  220 +
  221 + gtk_widget_show_all(popup);
  222 + gtk_menu_set_screen(GTK_MENU(popup), gtk_widget_get_screen(widget));
  223 + gtk_menu_popup_at_pointer(GTK_MENU(popup), event);
  224 +
  225 + return TRUE;
  226 +
  227 + }
  228 +
... ...
src/objects/window/terminal.c
... ... @@ -41,71 +41,7 @@
41 41 gchar filename[1];
42 42 };
43 43  
44   - static void session_changed(GtkWidget *terminal, GtkWidget *label) {
45   -
46   - gtk_label_set_text(GTK_LABEL(label),v3270_get_session_name(terminal));
47   -
48   - // Do I have to change the window title?
49   - GtkWidget * toplevel = gtk_widget_get_toplevel(terminal);
50   - if(PW3270_IS_APPLICATION_WINDOW(toplevel)) {
51   -
52   - pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(toplevel);
53   -
54   - if(gtk_widget_has_default(terminal)) {
55   - g_autofree gchar * title = v3270_get_session_title(terminal);
56   - gtk_window_set_title(GTK_WINDOW(window), title);
57   - }
58   -
59   - }
60   -
61   - }
62   -
63   - static gboolean on_terminal_focus(GtkWidget *terminal, GdkEvent G_GNUC_UNUSED(*event), GtkWindow * window) {
64   -
65   - if(gtk_window_get_default_widget(window) == terminal) {
66   - return FALSE;
67   - }
68   -
69   - // Store the active terminal widget.
70   - gtk_widget_grab_default(terminal);
71   - debug("Terminal %p is now default",terminal);
72   -
73   - // Change window title
74   - g_autofree gchar * title = v3270_get_session_title(terminal);
75   - gtk_window_set_title(window, title);
76   -
77   - pw3270_window_set_subtitle(GTK_WIDGET(window), v3270_is_connected(terminal) ? _("Connected to host") : _("Disconnected from host"));
78   -
79   - // Update actions
80   - size_t ix;
81   - gchar ** actions = g_action_group_list_actions(G_ACTION_GROUP(window));
82   -
83   - for(ix = 0; actions[ix]; ix++) {
84   -
85   -// debug("%s",actions[ix]);
86   -
87   - GAction * action = g_action_map_lookup_action(G_ACTION_MAP(window), actions[ix]);
88   -
89   - if(action) {
90   -
91   - if(V3270_IS_ACTION(action)) {
92   - v3270_action_set_terminal_widget(action,terminal);
93   - } else if(PW3270_IS_ACTION(action)) {
94   - pw3270_action_set_terminal_widget(action,terminal);
95   - }
96   -
97   - }
98   -
99   - }
100   -
101   - g_strfreev(actions);
102   -
103   - return FALSE;
104   - }
105   -
106   - static void check_for_session_changed(GtkWidget *terminal) {
107   -
108   - struct SessionDescriptor * session = (struct SessionDescriptor *) g_object_get_data(G_OBJECT(terminal),"session-descriptor");
  44 + static void destroy(GtkWidget *terminal, struct SessionDescriptor * session) {
109 45  
110 46 if(session->changed) {
111 47  
... ... @@ -129,131 +65,6 @@
129 65  
130 66 }
131 67  
132   -
133   - static void on_terminal_destroy(GtkWidget *terminal, GtkWindow * window) {
134   -
135   - check_for_session_changed(terminal);
136   -
137   - if(gtk_window_get_default_widget(window) != terminal) {
138   - return;
139   - }
140   -
141   - gtk_window_set_default(window,NULL);
142   - pw3270_window_set_subtitle(GTK_WIDGET(window), _("Disconnected from host"));
143   -
144   - // Update actions
145   - size_t ix;
146   - gchar ** actions = g_action_group_list_actions(G_ACTION_GROUP(window));
147   -
148   - for(ix = 0; actions[ix]; ix++) {
149   -
150   - GAction * action = g_action_map_lookup_action(G_ACTION_MAP(window), actions[ix]);
151   -
152   - if(action) {
153   -
154   - if(PW3270_IS_ACTION(action)) {
155   - pw3270_action_set_terminal_widget(action,NULL);
156   - } else if(V3270_IS_ACTION(action)) {
157   - v3270_action_set_terminal_widget(action,NULL);
158   - }
159   -
160   - }
161   -
162   - }
163   -
164   - g_strfreev(actions);
165   -
166   - }
167   -
168   - static void disconnected(GtkWidget *terminal, GtkWindow * window) {
169   -
170   - debug("%s",__FUNCTION__);
171   -
172   - if(terminal != gtk_window_get_default_widget(window))
173   - return;
174   -
175   - pw3270_window_set_subtitle(GTK_WIDGET(window), _("Disconnected from host"));
176   -
177   - }
178   -
179   - static void connected(GtkWidget *terminal, const gchar *host, GtkWindow * window) {
180   -
181   - debug("%s(%s)",__FUNCTION__,host);
182   -
183   - if(terminal != gtk_window_get_default_widget(window))
184   - return;
185   -
186   - pw3270_window_set_subtitle(GTK_WIDGET(window), _("Connected to host"));
187   -
188   - }
189   -
190   - static void on_close_tab(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) {
191   -
192   - GtkNotebook * notebook = GTK_NOTEBOOK(gtk_widget_get_parent(terminal));
193   - gtk_notebook_remove_page(notebook,gtk_notebook_page_num(notebook, terminal));
194   -
195   - }
196   -
197   - static gboolean on_popup_menu(GtkWidget *widget, gboolean selected, gboolean online, GdkEvent *event, pw3270ApplicationWindow * window) {
198   -
199   - GtkWidget * popup = window->popups[PW3270_APP_WINDOW_POPUP_OVER_UNSELECTED_AREA];
200   -
201   - if(!online && window->popups[PW3270_APP_WINDOW_POPUP_WHEN_OFFLINE])
202   - popup = window->popups[PW3270_APP_WINDOW_POPUP_WHEN_OFFLINE];
203   - else if(selected && window->popups[PW3270_APP_WINDOW_POPUP_OVER_SELECTED_AREA])
204   - popup = window->popups[PW3270_APP_WINDOW_POPUP_OVER_SELECTED_AREA];
205   - else
206   - popup = window->popups[PW3270_APP_WINDOW_POPUP_DEFAULT];
207   -
208   - if(!popup)
209   - return FALSE;
210   -
211   - gtk_widget_show_all(popup);
212   - gtk_menu_set_screen(GTK_MENU(popup), gtk_widget_get_screen(widget));
213   - gtk_menu_popup_at_pointer(GTK_MENU(popup), event);
214   -
215   - return TRUE;
216   -
217   - }
218   -
219   - static gint append_terminal_page(pw3270ApplicationWindow * window, GtkWidget * terminal) {
220   -
221   - GtkWidget * label = gtk_label_new(v3270_get_session_name(terminal));
222   - GtkWidget * tab = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2);
223   - GtkWidget * button = gtk_button_new_from_icon_name("window-close-symbolic",GTK_ICON_SIZE_MENU);
224   -
225   - gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE);
226   -
227   - debug("notebook: %p", window->notebook);
228   -
229   - g_signal_connect(G_OBJECT(terminal), "focus-in-event", G_CALLBACK(on_terminal_focus), window);
230   - g_signal_connect(G_OBJECT(terminal), "session_changed", G_CALLBACK(session_changed),label);
231   - g_signal_connect(G_OBJECT(terminal), "disconnected", G_CALLBACK(disconnected),window);
232   - g_signal_connect(G_OBJECT(terminal), "connected", G_CALLBACK(connected),window);
233   - g_signal_connect(G_OBJECT(terminal), "destroy", G_CALLBACK(on_terminal_destroy),window);
234   - g_signal_connect(G_OBJECT(terminal), "popup", G_CALLBACK(on_popup_menu), window);
235   -
236   - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_close_tab), terminal);
237   -
238   - gtk_box_pack_start(GTK_BOX(tab),label,FALSE,FALSE,0);
239   - gtk_box_pack_end(GTK_BOX(tab),button,FALSE,FALSE,0);
240   -
241   - gtk_widget_show_all(terminal);
242   - gtk_widget_show_all(tab);
243   -
244   - gint page = gtk_notebook_append_page(window->notebook,terminal,tab);
245   -
246   - gtk_notebook_set_tab_detachable(window->notebook,terminal,TRUE);
247   - gtk_notebook_set_tab_reorderable(window->notebook,terminal,TRUE);
248   -
249   - // Setup session.
250   -
251   -// H3270 * hSession = v3270_get_session(terminal);
252   -
253   - return page;
254   -
255   - }
256   -
257 68 static void save_settings(GtkWidget *terminal, struct SessionDescriptor * session) {
258 69  
259 70 session->changed = FALSE;
... ... @@ -376,16 +187,12 @@
376 187  
377 188 }
378 189  
  190 + GtkWidget * pw3270_terminal_new(const gchar *session_file) {
379 191  
380   - GtkWidget * pw3270_application_window_new_tab(GtkWidget *widget, const gchar *session_file) {
381   -
382   - struct SessionDescriptor * descriptor;
383   -
384   - g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),NULL);
385   -
386   - pw3270ApplicationWindow * window = PW3270_APPLICATION_WINDOW(widget);
387 192 GtkWidget * terminal = v3270_new();
388 193  
  194 + struct SessionDescriptor * descriptor = NULL;
  195 +
389 196 if(session_file) {
390 197  
391 198 // Use the supplied session file
... ... @@ -446,62 +253,30 @@
446 253  
447 254 }
448 255  
449   - append_terminal_page(window,terminal);
450   -
451 256 // Setup signals.
452 257 g_signal_connect(G_OBJECT(terminal),"save-settings",G_CALLBACK(save_settings),descriptor);
453 258 g_signal_connect(G_OBJECT(terminal),"toggle_changed",G_CALLBACK(toggle_changed),descriptor);
454 259 g_signal_connect(G_OBJECT(terminal),"print-done",G_CALLBACK(print_done),descriptor);
455 260 g_signal_connect(G_OBJECT(terminal),"print-setup",G_CALLBACK(print_setup),descriptor);
  261 + g_signal_connect(G_OBJECT(terminal),"destroy", G_CALLBACK(destroy),descriptor);
456 262  
457 263 return terminal;
458   -
459 264 }
460 265  
461   - gint pw3270_window_append_page(GtkWidget *widget, GFile * file) {
462   -
463   - g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),-1);
464   -
465   - g_autofree gchar *path = g_file_get_path(file);
466   - debug("Path: \"%s\"",path);
467   -
468   - if(path) {
469   -
470   - // It's a session file
471   - pw3270_application_window_new_tab(widget, path);
472   - return 0;
473   -
474   - }
475   -
476   - g_autofree gchar * scheme = g_file_get_uri_scheme(file);
477   -
478   - if(!(g_ascii_strcasecmp(scheme,"tn3270") && g_ascii_strcasecmp(scheme,"tn3270s"))) {
479   -
480   - // It's a TN3270 URL.
481   -
482   - GtkWidget * terminal = v3270_new();
483   -
484   - g_autofree gchar * uri = g_file_get_uri(file);
485   - size_t sz = strlen(uri);
  266 + GtkWidget * pw3270_application_window_new_tab(GtkWidget *widget, const gchar *session_file) {
486 267  
487   - if(sz > 0 && uri[sz-1] == '/')
488   - uri[sz-1] = 0;
  268 + struct SessionDescriptor * descriptor;
489 269  
490   - v3270_set_url(terminal,uri);
491   - append_terminal_page(PW3270_APPLICATION_WINDOW(widget), terminal);
492   - return 0;
  270 + g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(widget),NULL);
493 271  
494   - }
  272 + GtkWidget * window = PW3270_APPLICATION_WINDOW(widget);
  273 + GtkWidget * terminal = pw3270_terminal_new(session_file);
495 274  
496   - // Create a default window.
497   - {
498   - GtkWidget * terminal = v3270_new();
499   - g_warning("Unexpected session URL, creating a default window");
500   - append_terminal_page(PW3270_APPLICATION_WINDOW(widget), terminal);
501   - }
  275 + pw3270_window_set_current_page(window,pw3270_application_window_append_page(window,terminal));
502 276  
503   - return -1;
  277 + return terminal;
504 278  
505 279 }
506 280  
507 281  
  282 +
... ...