From 58ae34b3af6021196954e6f2290e301f3ec92976 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 18 Dec 2019 10:55:45 -0300 Subject: [PATCH] Adding key-file save & load on print operation object. Adding signal for keyfile load on terminal widget. --- src/dialogs/print/keyfile.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/dialogs/print/print.c | 4 +++- src/include/internals.h | 1 + src/include/v3270/print.h | 3 +++ src/terminal/widget.c | 9 +++++++++ v3270.cbp | 3 +++ 6 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 src/dialogs/print/keyfile.c diff --git a/src/dialogs/print/keyfile.c b/src/dialogs/print/keyfile.c new file mode 100644 index 0000000..9f4fe2e --- /dev/null +++ b/src/dialogs/print/keyfile.c @@ -0,0 +1,107 @@ +/* + * "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. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include "private.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + void v3270_print_operation_to_key_file(GtkPrintOperation *operation, GKeyFile *key_file) { + + GtkPrintSettings * settings = gtk_print_operation_get_print_settings(operation); + GtkPageSetup * pgsetup = gtk_print_operation_get_default_page_setup(operation); + GtkPaperSize * papersize = gtk_page_setup_get_paper_size(pgsetup); + + trace("%s(%p)",__FUNCTION__,operation); + g_message("Saving print settings"); + + gtk_print_settings_to_key_file(settings,key_file,"print_settings"); + gtk_page_setup_to_key_file(pgsetup,key_file,"page_setup"); + gtk_paper_size_to_key_file(papersize,key_file,"paper_size"); + + // Store font family + g_autofree gchar * font_family = v3270_print_operation_get_font_family(operation); + g_key_file_set_string(key_file,"print","font-family",font_family); + + // Store color settings + g_autofree gchar * colors = v3270_print_operation_get_color_scheme(operation); + g_key_file_set_string(key_file,"print","colors",colors); + + } + + void v3270_print_operation_load_key_file(GtkPrintOperation *operation, GKeyFile *key_file) { + + GtkPrintSettings * settings = gtk_print_settings_new(); + GtkPageSetup * setup = gtk_page_setup_new(); + GtkPaperSize * papersize = NULL; + GError * error = NULL; + + // Load page and print settings + + if(g_key_file_has_group(key_file,"print_settings") && !gtk_print_settings_load_key_file(settings,key_file,"print_settings",&error)) { + g_warning("Error getting print settings: %s",error->message); + g_error_free(error); + error = NULL; + } + + if(g_key_file_has_group(key_file,"page_setup") && !gtk_page_setup_load_key_file(setup,key_file,"page_setup",&error)) { + g_warning("Error getting page setup: %s",error->message); + g_error_free(error); + error = NULL; + } + + if(g_key_file_has_group(key_file,"paper_size")) { + // Use saved paper size + + papersize = gtk_paper_size_new_from_key_file(key_file,"paper_size",&error); + if(error) + { + g_warning("Error loading paper size: %s",error->message); + g_error_free(error); + error = NULL; + } + + } else { + // Create default + papersize = gtk_paper_size_new(NULL); + } + + gtk_print_operation_set_print_settings(operation,settings); + gtk_page_setup_set_paper_size_and_default_margins(setup,papersize); + gtk_print_operation_set_default_page_setup(operation,setup); + + // Load font and colors + g_autofree gchar * font_family = g_key_file_get_string(key_file,"print","font-family",NULL); + if(font_family && *font_family) + v3270_print_operation_set_font_family(operation,font_family); + + g_autofree gchar * color_scheme = g_key_file_get_string(key_file,"print","colors",NULL); + if(color_scheme && *color_scheme) + v3270_print_operation_set_color_scheme(operation,color_scheme); + + } diff --git a/src/dialogs/print/print.c b/src/dialogs/print/print.c index ea8752b..6d23d44 100644 --- a/src/dialogs/print/print.c +++ b/src/dialogs/print/print.c @@ -244,6 +244,8 @@ g_object_ref(G_OBJECT(opr->widget)); } + g_signal_emit(GTK_WIDGET(opr->widget), v3270_widget_signal[V3270_SIGNAL_PRINT_SETUP], 0, operation); + } GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode) @@ -265,8 +267,8 @@ operation->widget = NULL; operation->session = NULL; - v3270_print_operation_set_terminal(GTK_PRINT_OPERATION(operation),GTK_WIDGET(widget)); v3270_set_mono_color_table(operation->settings.colors,"#000000","#FFFFFF"); + v3270_print_operation_set_terminal(GTK_PRINT_OPERATION(operation),GTK_WIDGET(widget)); // Get contents. switch(operation->mode) diff --git a/src/include/internals.h b/src/include/internals.h index 50a7217..7f7e781 100644 --- a/src/include/internals.h +++ b/src/include/internals.h @@ -103,6 +103,7 @@ // Print session signals. // V3270_SIGNAL_PRINT_DONE, + V3270_SIGNAL_PRINT_SETUP, // // Settings signals (Mostly fired by V3270Settings dialogs). diff --git a/src/include/v3270/print.h b/src/include/v3270/print.h index d893101..f59af17 100644 --- a/src/include/v3270/print.h +++ b/src/include/v3270/print.h @@ -67,6 +67,9 @@ LIB3270_EXPORT void v3270_print_operation_apply_settings(GtkPrintOperation *operation, GtkWidget *settings); + LIB3270_EXPORT void v3270_print_operation_to_key_file(GtkPrintOperation *operation, GKeyFile *key_file); + LIB3270_EXPORT void v3270_print_operation_load_key_file(GtkPrintOperation *operation, GKeyFile *key_file); + LIB3270_EXPORT void v3270_print_operation_set_terminal(GtkPrintOperation * operation, GtkWidget *terminal); LIB3270_EXPORT GtkWidget * v3270_print_operation_get_terminal(GtkPrintOperation *operation); diff --git a/src/terminal/widget.c b/src/terminal/widget.c index 8788320..0c73c9e 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -435,6 +435,15 @@ static void v3270_class_init(v3270Class *klass) v3270_VOID__VOID_POINTER_UINT, G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_UINT, 0); + v3270_widget_signal[V3270_SIGNAL_PRINT_SETUP] = + g_signal_new( I_("print-setup"), + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_FIRST, + 0, + NULL, NULL, + v3270_VOID__VOID_POINTER, + G_TYPE_NONE, 2, G_TYPE_POINTER, 0); + v3270_widget_signal[V3270_SIGNAL_SAVE_SETTINGS] = g_signal_new( I_("save-settings"), G_OBJECT_CLASS_TYPE (gobject_class), diff --git a/v3270.cbp b/v3270.cbp index 13b8576..20b6555 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -75,6 +75,9 @@ + + -- libgit2 0.21.2