From aa1eb8f9d6652fbffd0297691cf95f5723228463 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 18 Nov 2021 22:11:11 -0300 Subject: [PATCH] Implementing the 'open-url' property. --- src/include/internals.h | 36 +++++++++++++----------------------- src/include/terminal.h | 87 ++++++++++++++++++++++++++------------------------------------------------------------- src/terminal/callbacks.c | 11 +++++++++-- src/terminal/properties/get.c | 40 +++++++++++++++++----------------------- src/terminal/properties/init.c | 52 +++++++++++++++++++++++++++++----------------------- src/terminal/properties/private.h | 39 +++++++++++++++------------------------ src/terminal/properties/set.c | 40 +++++++++++++++++----------------------- src/terminal/widget.c | 37 ++++++++++++++----------------------- 8 files changed, 140 insertions(+), 202 deletions(-) diff --git a/src/include/internals.h b/src/include/internals.h index 229efb8..7179e00 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -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 . */ #ifndef V3270_INTERNALS_H_INCLUDED diff --git a/src/include/terminal.h b/src/include/terminal.h index 88ec5ce..2f28573 100644 --- a/src/include/terminal.h +++ b/src/include/terminal.h @@ -1,63 +1,27 @@ +/* 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 + * Copyright (C) 2008 Banco do Brasil S.A. * - * Este programa está nomeado como - e possui - linhas de código. + * 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. * - * 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 -#include -#include - -G_BEGIN_DECLS + #include + #include + #include -/* - /// @brief V3270 Properties saved to the configuration file. - typedef enum - { - V3270_SETTING_URL, - V3270_SETTING_FONT_FAMILY, - V3270_SETTING_AUTO_DISCONNECT, - V3270_SETTING_REMAP_FILE, - V3270_SETTING_DYNAMIC_SPACING, - V3270_SETTING_LU_NAMES, - V3270_SETTING_MODEL_NUMBER, - V3270_SETTING_OVERSIZE, - V3270_SETTING_HOST_CHARSET, - V3270_SETTING_UNLOCK_DELAY, - V3270_SETTING_COLOR_TYPE, - V3270_SETTING_HOST_TYPE, - V3270_SETTING_CRL_PROTOCOL, - V3270_SETTING_TERMINAL_COLORS, - V3270_SETTING_SELECTION_OPTIONS, - - V3270_SETTING_COUNT ///< @brief Number of setting properties. - } V3270_SETTING; - - G_GNUC_INTERNAL void v3270_notify_setting(GtkWidget *widget, V3270_SETTING id); -*/ + G_BEGIN_DECLS struct _v3270Class { @@ -151,14 +115,15 @@ G_BEGIN_DECLS GtkWidget parent; // flags - int selecting : 1; /// @brief Selecting region - int moving : 1; /// @brief Moving selected region - int resizing : 1; /// @brief Resizing selected region - int scaled_fonts : 1; /// @brief Use scaled fonts - int drawing : 1; /// @brief Draw widget? - int freeze : 1; /// @brief Truee when the "save settings" signal is disabled. - int append : 1; /// @brief Next smart-copy operation will be append. - int copying : 1; /// @brief Copy with center mouse button + int selecting : 1; ///< @brief Selecting region + int moving : 1; ///< @brief Moving selected region + int resizing : 1; ///< @brief Resizing selected region + int scaled_fonts : 1; ///< @brief Use scaled fonts + int drawing : 1; ///< @brief Draw widget? + int freeze : 1; ///< @brief Truee when the "save settings" signal is disabled. + int append : 1; ///< @brief Next smart-copy operation will be append. + int copying : 1; ///< @brief Copy with center mouse button + int open_url : 1; ///< @brief Emit 'open-url' signal when and http:// or https:// url is selected by 'word-select' action. /// @brief Action properties. // GtkResponseType responses[V3270_TOGGLEABLE_DIALOG_CUSTOM]; diff --git a/src/terminal/callbacks.c b/src/terminal/callbacks.c index 2f06b43..da4582a 100644 --- a/src/terminal/callbacks.c +++ b/src/terminal/callbacks.c @@ -422,13 +422,20 @@ static int load(H3270 *session, const char *filename) static gboolean bg_word_selected(struct _word_selected *cfg) { - if(cfg->len > 3) { + v3270 *terminal = (v3270 *) lib3270_get_user_data(cfg->hSession); + + debug("%s(open-url=%d)",__FUNCTION__,terminal->open_url); + + if(cfg->len > 3 && terminal->open_url) { + lib3270_autoptr(char) text = lib3270_get_string_at_address(cfg->hSession,cfg->offset,cfg->len,0); if(text && (g_str_has_prefix(text,"http://") || g_str_has_prefix(text,"https://")) ) { + debug("Emitting '%s'", text); + v3270_signal_emit( - lib3270_get_user_data(cfg->hSession), + terminal, V3270_SIGNAL_OPEN_URL, text ); diff --git a/src/terminal/properties/get.c b/src/terminal/properties/get.c index 8fb27e0..ac392b6 100644 --- a/src/terminal/properties/get.c +++ b/src/terminal/properties/get.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 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" @@ -147,6 +137,10 @@ g_value_set_boolean(value,window->timer != NULL); break; + case V3270_PROPERTY_OPEN_URL: + g_value_set_boolean(value,window->open_url != 0); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); diff --git a/src/terminal/properties/init.c b/src/terminal/properties/init.c index 6b568de..03b5365 100644 --- a/src/terminal/properties/init.c +++ b/src/terminal/properties/init.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 + * Copyright (C) 2008 Banco do Brasil S.A. * - * Este programa está nomeado como properties.c e possui - linhas de código. + * 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. * - * 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" @@ -170,6 +160,22 @@ spec ); + // Open URL + spec = + g_param_spec_boolean( + "open-url", + "open-url", + _( "Emit signal 'open-url' when an http:// or https:// string is selected by action 'word-select'" ), + FALSE, + G_PARAM_READABLE|G_PARAM_WRITABLE + ); + + g_object_class_install_property( + gobject_class, + V3270_PROPERTY_OPEN_URL, + spec + ); + // Lu names spec = g_param_spec_string( diff --git a/src/terminal/properties/private.h b/src/terminal/properties/private.h index 0631f86..719689e 100644 --- a/src/terminal/properties/private.h +++ b/src/terminal/properties/private.h @@ -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 properties.c 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 . */ #ifdef WIN32 @@ -60,8 +50,9 @@ V3270_PROPERTY_SELECTION_OPTIONS = 11, V3270_PROPERTY_HAS_COPY = 12, ///< @brief Terminal has copy. V3270_PROPERTY_HAS_TIMER = 13, ///< @brief Timer indicator state. + V3270_PROPERTY_OPEN_URL = 14, ///< @brief Open URL when 'word' selected. - V3270_PROPERTY_DYNAMIC = 14 ///< @brief Id of the first LIB3270 internal property. + V3270_PROPERTY_DYNAMIC = 15 ///< @brief Id of the first LIB3270 internal property. }; G_GNUC_INTERNAL void v3270_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); diff --git a/src/terminal/properties/set.c b/src/terminal/properties/set.c index 812d21f..835607a 100644 --- a/src/terminal/properties/set.c +++ b/src/terminal/properties/set.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 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" @@ -143,6 +133,10 @@ GTK_V3270(object)->selection.options = (V3270SelectionOption) g_value_get_uint(value); break; + case V3270_PROPERTY_OPEN_URL: + GTK_V3270(object)->open_url = (g_value_get_boolean(value) ? 1 : 0); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); diff --git a/src/terminal/widget.c b/src/terminal/widget.c index b553ff8..b148555 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.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 @@ -63,6 +53,7 @@ /// @brief Persistent properties (load/save from session file). static const gchar *persistent_properties[] = { "url", + "open-url", "model-number", "oversize", "host-charset", -- libgit2 0.21.2