From e5a2791d6efe18cb03adee0d249e0b355d812a57 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 18 Nov 2021 00:44:47 -0300 Subject: [PATCH] Implementing settings popup dialog. --- src/dialogs/settings/dialog.c | 67 ++++++++++++++++++------------------------------------------------- src/dialogs/settings/host.c | 2 ++ src/dialogs/settings/popup.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/include/v3270.h | 2 +- src/include/v3270/settings.h | 2 +- src/terminal/actions/table.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------- src/trace/exec.c | 69 +++++++++++++++++++++++++++++++++++++-------------------------------- v3270.cbp | 3 +++ 8 files changed, 213 insertions(+), 121 deletions(-) create mode 100644 src/dialogs/settings/popup.c diff --git a/src/dialogs/settings/dialog.c b/src/dialogs/settings/dialog.c index 64eb0e1..c258538 100644 --- a/src/dialogs/settings/dialog.c +++ b/src/dialogs/settings/dialog.c @@ -1,30 +1,20 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ + /* - * "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> - * - * 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. + * Copyright (C) 2008 Banco do Brasil S.A. * - * Contatos: + * 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. * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * 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 . */ #include "../private.h" @@ -301,6 +291,11 @@ void v3270_settings_dialog_set_terminal_widget(GtkWidget *widget, GtkWidget *ter g_message("No active page on settings dialog"); } + gtk_window_set_transient_for( + GTK_WINDOW(widget), + GTK_WINDOW(gtk_widget_get_toplevel(terminal)) + ); + } void v3270_settings_dialog_set_has_subtitle(GtkWidget *widget, gboolean has_subtitle) @@ -332,32 +327,6 @@ void v3270_setttings_dialog_response(GtkDialog *dialog, gint response_id, GtkWid } -void v3270_settings_popup_dialog(GtkWidget *widget, GtkWidget *terminal, gboolean modal) -{ - g_return_if_fail(GTK_IS_V3270(terminal) && GTK_IS_V3270_SETTINGS(widget)); - - GtkWidget * dialog = v3270_settings_dialog_new(); - V3270Settings * settings = GTK_V3270_SETTINGS(widget); - - v3270_settings_dialog_set_has_subtitle(dialog,FALSE); - - if(settings->title) - gtk_window_set_title(GTK_WINDOW(dialog),settings->title); - - gtk_container_add(GTK_CONTAINER(dialog), widget); - gtk_dialog_set_toplevel(dialog,terminal); - - gtk_window_set_modal(GTK_WINDOW(dialog),modal); - - v3270_settings_dialog_set_terminal_widget(dialog, terminal); - - g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); - g_signal_connect(dialog,"response",G_CALLBACK(v3270_setttings_dialog_response),NULL); - - gtk_widget_show_all(dialog); - -} - GtkWidget * v3270_settings_get_edit_dialog(GtkWidget *settings, GtkWidget *terminal, gboolean modal) { const gchar * title = GTK_V3270_SETTINGS(settings)->title; diff --git a/src/dialogs/settings/host.c b/src/dialogs/settings/host.c index c29331d..1633b13 100644 --- a/src/dialogs/settings/host.c +++ b/src/dialogs/settings/host.c @@ -588,6 +588,7 @@ LIB3270_EXPORT GtkWidget * v3270_host_select_new() return v3270_host_settings_new(); } +/* LIB3270_EXPORT void v3270_select_host(GtkWidget *widget) { g_return_if_fail(GTK_IS_V3270(widget)); @@ -633,6 +634,7 @@ LIB3270_EXPORT void v3270_select_host(GtkWidget *widget) gtk_widget_destroy(dialog); } +*/ static void apply(GtkWidget *w, GtkWidget *terminal) { diff --git a/src/dialogs/settings/popup.c b/src/dialogs/settings/popup.c new file mode 100644 index 0000000..c35baab --- /dev/null +++ b/src/dialogs/settings/popup.c @@ -0,0 +1,54 @@ +/* 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 . + */ + + #include "private.h" + #include + #include + + GtkWidget * v3270_settings_popup_dialog(GtkWidget *settings, GtkWidget *terminal, gboolean modal) + { +#ifdef DEBUG + g_message("terminal=%d settings=%d",(int) GTK_IS_V3270(terminal), (int) GTK_IS_V3270_SETTINGS(settings)); +#endif // DEBUG + if( !(GTK_IS_V3270(terminal) && GTK_IS_V3270_SETTINGS(settings))) { + g_message("%s was called with invalid arguments",__FUNCTION__); + if(g_object_is_floating(settings)) { + g_object_ref_sink(settings); + } + g_object_unref(settings); + return; + } + + GtkWidget * dialog = v3270_settings_dialog_new(); + v3270_settings_dialog_set_has_subtitle(dialog,FALSE); + + gtk_window_set_title(GTK_WINDOW(dialog), v3270_settings_get_title(settings)); + gtk_container_add(GTK_CONTAINER(dialog), settings); + + gtk_dialog_set_toplevel(dialog,terminal); + gtk_window_set_modal(GTK_WINDOW(dialog),modal); + + v3270_settings_dialog_set_terminal_widget(dialog, terminal); + + g_signal_connect(dialog,"response",G_CALLBACK(v3270_setttings_dialog_response),NULL); + g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); + + return dialog; + + } diff --git a/src/include/v3270.h b/src/include/v3270.h index a170532..9846d50 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -239,7 +239,7 @@ LIB3270_EXPORT const gchar * v3270_get_remap_filename(GtkWidget *widget); // Auxiliary widgets - LIB3270_EXPORT void v3270_select_host(GtkWidget *widget); + // LIB3270_EXPORT void v3270_select_host(GtkWidget *widget); // Print LIB3270_EXPORT int v3270_print(GtkWidget *widget, GError **error); diff --git a/src/include/v3270/settings.h b/src/include/v3270/settings.h index a73f649..6a20ede 100644 --- a/src/include/v3270/settings.h +++ b/src/include/v3270/settings.h @@ -102,7 +102,7 @@ LIB3270_EXPORT const gchar * v3270_settings_get_tooltip(GtkWidget *widget); /// @brief Popup a settings dialog for the terminal. - LIB3270_EXPORT void v3270_settings_popup_dialog(GtkWidget *settings, GtkWidget *terminal, gboolean modal); + LIB3270_EXPORT GtkWidget * v3270_settings_popup_dialog(GtkWidget *settings, GtkWidget *terminal, gboolean modal); /// @brief Get an edit dialog for the settings widget. LIB3270_EXPORT GtkWidget * v3270_settings_get_edit_dialog(GtkWidget *settings, GtkWidget *terminal, gboolean modal); diff --git a/src/terminal/actions/table.c b/src/terminal/actions/table.c index 7d57cb4..7fe2f58 100644 --- a/src/terminal/actions/table.c +++ b/src/terminal/actions/table.c @@ -1,43 +1,33 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ + /* - * "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> - * - * 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. + * Copyright (C) 2008 Banco do Brasil S.A. * - * 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 + * 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. * - * Este programa está nomeado como properties.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) + * 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 . */ #include "private.h" #include #include #include + #include #include -// static int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action * action); -// static int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action * action); - static int fire_copy_as_html(GtkWidget *widget, const struct _v3270_action * action); static int fire_copy_as_pixbuff(GtkWidget *widget, const struct _v3270_action * action); + static int fire_accelerators_dialog(GtkWidget *widget, const struct _v3270_action * action); + static int fire_host_dialog(GtkWidget *widget, const struct _v3270_action * action); /*--[ Implement ]------------------------------------------------------------------------------------*/ @@ -45,7 +35,9 @@ static const V3270_ACTION actions[] = { + // // Standard Clipboard actions + // { .flags = (V3270_ACTION_FLAGS) V3270_COPY_SMART, .name = "copy", @@ -320,6 +312,28 @@ }, + // + // Dialog actions + // + { + .group = LIB3270_ACTION_GROUP_NONE, + .name = "dialog-accelerators", + .label = N_("Change keyboard accelerators"), + .activate = fire_accelerators_dialog + + }, + + { + .group = LIB3270_ACTION_GROUP_OFFLINE, + .name = "dialog-host", + .label = N_("Change host settings"), + .activate = fire_host_dialog + + }, + + // + // Terminator + // { .name = NULL } @@ -339,26 +353,71 @@ return 0; } - /* - int fire_kp_add_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { + static int fire_accelerators_dialog(GtkWidget *widget, const struct _v3270_action * action) { + + /* + v3270_settings_popup_dialog( + v3270_accelerator_settings_new(), + widget, + TRUE + ); + */ + + return 0; + } - if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE)) - return lib3270_nextfield(GTK_V3270(widget)->host); + static int fire_host_dialog(GtkWidget *widget, const struct _v3270_action * action) { - v3270_set_string(widget, "+"); + gtk_widget_show_all( + v3270_settings_popup_dialog( + v3270_host_settings_new(), + widget, + TRUE + ) + ); return 0; - } + /* + GtkWidget * dialog = v3270_settings_dialog_new(); + GtkWidget * settings = v3270_host_settings_new(); - int fire_kp_sub_action(GtkWidget *widget, const struct _v3270_action G_GNUC_UNUSED(* action)) { + v3270_settings_dialog_set_has_subtitle(dialog,FALSE); - if(v3270_get_toggle(widget,LIB3270_TOGGLE_KP_ALTERNATIVE)) - return lib3270_previousfield(GTK_V3270(widget)->host); + gtk_window_set_title(GTK_WINDOW(dialog), v3270_settings_get_title(settings)); + gtk_container_add(GTK_CONTAINER(dialog), settings); - v3270_set_string(widget, "-"); + gtk_dialog_set_toplevel(dialog,widget); + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); - return 0; + v3270_settings_dialog_set_terminal_widget(dialog, widget); + + gtk_window_set_default_size(GTK_WINDOW(dialog), 700, 150); + gtk_widget_show_all(dialog); + + gboolean again = TRUE; + while(again) + { + gtk_widget_set_sensitive(dialog,TRUE); + gtk_widget_set_visible(dialog,TRUE); + + switch(gtk_dialog_run(GTK_DIALOG(dialog))) + { + case GTK_RESPONSE_APPLY: + debug("V3270HostSelectWidget::%s=%s",__FUNCTION__,"GTK_RESPONSE_APPLY"); + v3270_settings_dialog_apply(dialog); + again = lib3270_reconnect(v3270_get_session(widget),0); + break; + + case GTK_RESPONSE_CANCEL: + again = FALSE; + debug("V3270HostSelectWidget::%s=%s",__FUNCTION__,"GTK_RESPONSE_CANCEL"); + v3270_settings_dialog_revert(dialog); + break; + } + } + + gtk_widget_destroy(dialog); + */ } -*/ diff --git a/src/trace/exec.c b/src/trace/exec.c index 694e7a6..ef028f1 100644 --- a/src/trace/exec.c +++ b/src/trace/exec.c @@ -1,30 +1,20 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ + /* - * "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> - * - * 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. + * Copyright (C) 2008 Banco do Brasil S.A. * - * 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 + * 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. * - * 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) + * 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 . */ #include "private.h" @@ -34,6 +24,7 @@ #include #include #include + #include static const gchar * get_word(gchar **ptr) { @@ -308,19 +299,33 @@ } // Check for external interpreters - gboolean handled = FALSE; - gchar * args = cmdline; + { + gboolean handled = FALSE; + gchar * args = cmdline; - while(*args && !g_ascii_isspace(*args)) - args++; + while(*args && !g_ascii_isspace(*args)) + args++; - if(*args) - *(args++) = 0; + if(*args) + *(args++) = 0; - v3270_trace_signal_emit(GTK_WIDGET(t), V3270_TRACE_SIGNAL_COMMAND, cmdline, args, &handled); + v3270_trace_signal_emit(GTK_WIDGET(t), V3270_TRACE_SIGNAL_COMMAND, cmdline, args, &handled); - if(handled) - return 0; + if(handled) + return 0; + } + + // Check for v3270 actions + { + const V3270_ACTION * action = v3270_get_actions(); + + while(action->name) { + if(!g_ascii_strcasecmp(action->name,cmdline)) { + return action->activate(terminal,action); + } + action++; + } + } return errno = ENOENT; } diff --git a/v3270.cbp b/v3270.cbp index 181d36d..581950b 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -117,6 +117,9 @@ + +