Commit a8d704d6b2ff862e972f11f44f8e5c9784298faf
Exists in
master
and in
1 other branch
Applying fixes for the issues with the print dialog.
Showing
9 changed files
with
222 additions
and
32 deletions
Show diff stats
src/dialogs/print/convenience.c
| ... | ... | @@ -32,47 +32,67 @@ |
| 32 | 32 | #include <v3270/dialogs.h> |
| 33 | 33 | #include <terminal.h> |
| 34 | 34 | #include <lib3270/selection.h> |
| 35 | + #include <lib3270/log.h> | |
| 36 | + #include <lib3270/trace.h> | |
| 35 | 37 | |
| 36 | 38 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 37 | 39 | |
| 38 | 40 | int v3270_print_dialog(GtkWidget *widget, LIB3270_CONTENT_OPTION mode, GError **error) |
| 39 | 41 | { |
| 40 | - int rc; | |
| 42 | + int rc = 0; | |
| 41 | 43 | |
| 42 | 44 | if(!(widget && GTK_IS_V3270(widget))) |
| 43 | - { | |
| 44 | 45 | return errno = EINVAL; |
| 45 | - } | |
| 46 | 46 | |
| 47 | - lib3270_trace_event(v3270_get_session(widget),"print action activated (type=%d)",(int) mode); | |
| 47 | + lib3270_trace_event(v3270_get_session(widget),"print action activated (type=%d)\n",(int) mode); | |
| 48 | + | |
| 49 | + if(!v3270_is_connected(widget)) | |
| 50 | + return errno = ENOTCONN; | |
| 48 | 51 | |
| 49 | 52 | // Print operation. |
| 50 | 53 | GtkPrintOperation * operation = v3270_print_operation_new(widget, mode); |
| 54 | + if(!operation) | |
| 55 | + return errno = EPERM; | |
| 51 | 56 | |
| 52 | 57 | gtk_print_operation_set_show_progress(operation,TRUE); |
| 58 | + gtk_print_operation_set_allow_async(operation,TRUE); | |
| 59 | + | |
| 60 | + GtkPrintOperationResult result = GTK_PRINT_OPERATION_RESULT_ERROR; | |
| 53 | 61 | |
| 54 | 62 | if(error) |
| 55 | 63 | { |
| 56 | - gtk_print_operation_run( | |
| 64 | + result = | |
| 65 | + gtk_print_operation_run( | |
| 57 | 66 | operation, |
| 58 | 67 | GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, |
| 59 | 68 | GTK_WINDOW(gtk_widget_get_toplevel(widget)), |
| 60 | 69 | error |
| 61 | - ); | |
| 70 | + ); | |
| 71 | + | |
| 72 | + if(*error) | |
| 73 | + { | |
| 74 | + rc = (*error)->code ? (*error)->code : -1; | |
| 75 | + g_warning("Print operation has failed with errror\"%s\" (rc=%d)",(*error)->message,rc); | |
| 76 | + | |
| 77 | + } | |
| 78 | + else | |
| 79 | + { | |
| 80 | + rc = 0; | |
| 81 | + } | |
| 62 | 82 | |
| 63 | - rc = (*error == NULL ? 0 : -1); | |
| 64 | 83 | |
| 65 | 84 | } |
| 66 | 85 | else |
| 67 | 86 | { |
| 68 | 87 | GError *err = NULL; |
| 69 | 88 | |
| 70 | - gtk_print_operation_run( | |
| 89 | + result = | |
| 90 | + gtk_print_operation_run( | |
| 71 | 91 | operation, |
| 72 | 92 | GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, |
| 73 | 93 | GTK_WINDOW(gtk_widget_get_toplevel(widget)), |
| 74 | 94 | &err |
| 75 | - ); | |
| 95 | + ); | |
| 76 | 96 | |
| 77 | 97 | if(err) |
| 78 | 98 | { |
| ... | ... | @@ -89,7 +109,36 @@ |
| 89 | 109 | } |
| 90 | 110 | } |
| 91 | 111 | |
| 112 | + switch(result) | |
| 113 | + { | |
| 114 | + case GTK_PRINT_OPERATION_RESULT_ERROR: | |
| 115 | + debug("%s: Error on print operation\n",__FUNCTION__); | |
| 116 | + g_warning("Error on print operation"); | |
| 117 | + if(!rc) | |
| 118 | + rc = -1; | |
| 119 | + break; | |
| 120 | + | |
| 121 | + case GTK_PRINT_OPERATION_RESULT_APPLY: | |
| 122 | + debug("%s: The print settings should be stored.",__FUNCTION__); | |
| 123 | + rc = 0; | |
| 124 | + break; | |
| 125 | + | |
| 126 | + case GTK_PRINT_OPERATION_RESULT_CANCEL: | |
| 127 | + debug("%s: The print operation has been canceled, the print settings should not be stored.", __FUNCTION__); | |
| 128 | + break; | |
| 129 | + | |
| 130 | + case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS: | |
| 131 | + debug("%s: The print operation is running",__FUNCTION__); | |
| 132 | + break; | |
| 133 | + | |
| 134 | + default: | |
| 135 | + g_warning("Unexpected status %d in print operation",(int) result); | |
| 136 | + | |
| 137 | + } | |
| 138 | + | |
| 139 | + debug("%s(%p)",__FUNCTION__,operation); | |
| 92 | 140 | g_object_unref(operation); |
| 141 | + debug("%s(%p)",__FUNCTION__,operation); | |
| 93 | 142 | |
| 94 | 143 | return rc; |
| 95 | 144 | ... | ... |
src/dialogs/print/draw.c
| ... | ... | @@ -114,7 +114,7 @@ |
| 114 | 114 | size_t col; |
| 115 | 115 | rect.x = operation->font.info.margin.left; |
| 116 | 116 | |
| 117 | - debug("Drawing: %u row=%u selection=%p pos=%u", (unsigned int) drawing, row, selection, (unsigned int) pos); | |
| 117 | +// debug("Drawing: %u row=%u selection=%p pos=%u", (unsigned int) drawing, row, selection, (unsigned int) pos); | |
| 118 | 118 | |
| 119 | 119 | for(col = 0; col < selection->bounds.width;col++) |
| 120 | 120 | { | ... | ... |
src/dialogs/print/print.c
| ... | ... | @@ -42,7 +42,7 @@ |
| 42 | 42 | { |
| 43 | 43 | V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(prt); |
| 44 | 44 | |
| 45 | - debug("%s",__FUNCTION__); | |
| 45 | + debug("%s rc=%u",__FUNCTION__,(unsigned int) result); | |
| 46 | 46 | |
| 47 | 47 | if(result == GTK_PRINT_OPERATION_RESULT_ERROR) |
| 48 | 48 | { |
| ... | ... | @@ -62,21 +62,65 @@ |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | if(operation->widget) |
| 65 | + { | |
| 66 | + debug("%s: Emiting signal PRINT_DONE with result code %d",__FUNCTION__,result); | |
| 67 | + | |
| 68 | + switch(result) | |
| 69 | + { | |
| 70 | + case GTK_PRINT_OPERATION_RESULT_ERROR: | |
| 71 | + debug("%s: Error on print operation",__FUNCTION__); | |
| 72 | + lib3270_trace_event(operation->widget->host,"%s\n",_("Error on print operation")); | |
| 73 | + break; | |
| 74 | + | |
| 75 | + case GTK_PRINT_OPERATION_RESULT_APPLY: | |
| 76 | + debug("%s: The print settings should be stored.",__FUNCTION__); | |
| 77 | + lib3270_trace_event(operation->widget->host,"%s\n",_("The print settings should be stored.")); | |
| 78 | + break; | |
| 79 | + | |
| 80 | + case GTK_PRINT_OPERATION_RESULT_CANCEL: | |
| 81 | + debug("%s: The print operation has been canceled, the print settings should not be stored.", __FUNCTION__); | |
| 82 | + lib3270_trace_event(operation->widget->host,"%s\n",_("The print operation has been canceled, the print settings should not be stored.")); | |
| 83 | + break; | |
| 84 | + | |
| 85 | + case GTK_PRINT_OPERATION_RESULT_IN_PROGRESS: | |
| 86 | + debug("%s: The print operation is running",__FUNCTION__); | |
| 87 | + lib3270_trace_event(operation->widget->host,"%s\n",_("The print operation is running")); | |
| 88 | + break; | |
| 89 | + | |
| 90 | + default: | |
| 91 | + debug("Unexpected status %d in print operation",(int) result); | |
| 92 | + lib3270_trace_event(operation->widget->host,_("Unexpected status %d in print operation"),(int) result); | |
| 93 | + | |
| 94 | + } | |
| 95 | + | |
| 65 | 96 | g_signal_emit(GTK_WIDGET(operation->widget), v3270_widget_signal[V3270_SIGNAL_PRINT_DONE], 0, prt, (guint) result); |
| 97 | + } | |
| 66 | 98 | |
| 67 | 99 | } |
| 68 | 100 | |
| 69 | 101 | static void dispose(GObject *object) |
| 70 | 102 | { |
| 71 | - debug("%s",__FUNCTION__); | |
| 72 | - | |
| 73 | 103 | V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(object); |
| 74 | 104 | |
| 105 | + if(operation->widget) | |
| 106 | + { | |
| 107 | + g_object_unref(G_OBJECT(operation->widget)); | |
| 108 | + operation->widget = NULL; | |
| 109 | + } | |
| 110 | + | |
| 111 | + operation->contents.selection = NULL; | |
| 112 | + | |
| 75 | 113 | if(operation->font.info.scaled) |
| 114 | + { | |
| 76 | 115 | cairo_scaled_font_destroy(operation->font.info.scaled); |
| 116 | + operation->font.info.scaled = NULL; | |
| 117 | + } | |
| 77 | 118 | |
| 78 | 119 | if(operation->font.name) |
| 120 | + { | |
| 79 | 121 | g_free(operation->font.name); |
| 122 | + operation->font.name = NULL; | |
| 123 | + } | |
| 80 | 124 | |
| 81 | 125 | if(operation->contents.dynamic) |
| 82 | 126 | { |
| ... | ... | @@ -85,16 +129,15 @@ |
| 85 | 129 | #pragma GCC diagnostic ignored "-Wcast-function-type" |
| 86 | 130 | #endif // _WIN32 |
| 87 | 131 | |
| 88 | - g_list_free_full(operation->contents.dynamic,(GDestroyNotify) lib3270_free); | |
| 132 | + g_list_free_full(operation->contents.dynamic,g_free); | |
| 133 | + | |
| 89 | 134 | operation->contents.dynamic = NULL; |
| 90 | 135 | |
| 91 | 136 | #pragma GCC diagnostic pop |
| 92 | 137 | } |
| 93 | - operation->contents.selection = NULL; | |
| 94 | 138 | |
| 95 | 139 | G_OBJECT_CLASS(V3270PrintOperation_parent_class)->dispose(object); |
| 96 | 140 | |
| 97 | - | |
| 98 | 141 | } |
| 99 | 142 | |
| 100 | 143 | #ifndef _WIN32 |
| ... | ... | @@ -181,16 +224,48 @@ |
| 181 | 224 | return GTK_WIDGET(GTK_V3270_PRINT_OPERATION(operation)->widget); |
| 182 | 225 | } |
| 183 | 226 | |
| 184 | -GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode) | |
| 185 | -{ | |
| 227 | + void v3270_print_operation_set_terminal(GtkPrintOperation * operation, GtkWidget *widget) | |
| 228 | + { | |
| 229 | + g_return_if_fail(GTK_IS_V3270_PRINT_OPERATION(operation) && GTK_IS_V3270(widget)); | |
| 230 | + | |
| 231 | + V3270PrintOperation * opr = GTK_V3270_PRINT_OPERATION(operation); | |
| 232 | + | |
| 233 | + if(opr->widget) | |
| 234 | + { | |
| 235 | + g_object_unref(G_OBJECT(opr->widget)); | |
| 236 | + opr->widget = NULL; | |
| 237 | + opr->session = NULL; | |
| 238 | + } | |
| 239 | + | |
| 240 | + if(widget && GTK_IS_V3270(widget)) | |
| 241 | + { | |
| 242 | + opr->widget = GTK_V3270(widget); | |
| 243 | + opr->session = v3270_get_session(widget); | |
| 244 | + g_object_ref(G_OBJECT(opr->widget)); | |
| 245 | + } | |
| 246 | + | |
| 247 | + } | |
| 248 | + | |
| 249 | + GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode) | |
| 250 | + { | |
| 186 | 251 | g_return_val_if_fail(GTK_IS_V3270(widget),NULL); |
| 187 | 252 | |
| 253 | + H3270 *hSession = v3270_get_session(widget); | |
| 254 | + | |
| 255 | + if(!lib3270_is_connected(hSession)) | |
| 256 | + { | |
| 257 | + errno = ENOTCONN; | |
| 258 | + g_warning("Can't print from offline session"); | |
| 259 | + return NULL; | |
| 260 | + } | |
| 261 | + | |
| 188 | 262 | V3270PrintOperation * operation = GTK_V3270_PRINT_OPERATION(g_object_new(GTK_TYPE_V3270_PRINT_OPERATION, NULL)); |
| 189 | 263 | |
| 190 | 264 | operation->mode = mode; |
| 191 | - operation->widget = GTK_V3270(widget); | |
| 192 | - operation->session = v3270_get_session(widget); | |
| 265 | + operation->widget = NULL; | |
| 266 | + operation->session = NULL; | |
| 193 | 267 | |
| 268 | + v3270_print_operation_set_terminal(GTK_PRINT_OPERATION(operation),GTK_WIDGET(widget)); | |
| 194 | 269 | v3270_set_mono_color_table(operation->settings.colors,"#000000","#FFFFFF"); |
| 195 | 270 | |
| 196 | 271 | // Get contents. |
| ... | ... | @@ -198,8 +273,7 @@ GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT |
| 198 | 273 | { |
| 199 | 274 | case LIB3270_CONTENT_ALL: |
| 200 | 275 | debug("%s","LIB3270_CONTENT_ALL"); |
| 201 | - operation->contents.dynamic = g_new0(GList,1); | |
| 202 | - operation->contents.dynamic->data = (gpointer) lib3270_get_selection(operation->session,0,1); | |
| 276 | + operation->contents.dynamic = g_list_append_lib3270_selection(operation->contents.dynamic, operation->session,TRUE); | |
| 203 | 277 | operation->contents.selection = operation->contents.dynamic; |
| 204 | 278 | break; |
| 205 | 279 | |
| ... | ... | @@ -210,8 +284,7 @@ GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT |
| 210 | 284 | |
| 211 | 285 | case LIB3270_CONTENT_SELECTED: |
| 212 | 286 | debug("%s","LIB3270_CONTENT_SELECTED"); |
| 213 | - operation->contents.dynamic = g_new0(GList,1); | |
| 214 | - operation->contents.dynamic->data = (gpointer) lib3270_get_selection(operation->session,0,0); | |
| 287 | + operation->contents.dynamic = g_list_append_lib3270_selection(operation->contents.dynamic, operation->session,FALSE); | |
| 215 | 288 | operation->contents.selection = operation->contents.dynamic; |
| 216 | 289 | break; |
| 217 | 290 | } |
| ... | ... | @@ -232,7 +305,7 @@ GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT |
| 232 | 305 | } |
| 233 | 306 | |
| 234 | 307 | return GTK_PRINT_OPERATION(operation); |
| 235 | -} | |
| 308 | + } | |
| 236 | 309 | |
| 237 | 310 | gboolean v3270_print_operation_set_font_family(GtkPrintOperation *operation, const gchar *fontname) |
| 238 | 311 | { | ... | ... |
src/dialogs/save/save.c
| ... | ... | @@ -346,9 +346,7 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ |
| 346 | 346 | { |
| 347 | 347 | case LIB3270_CONTENT_ALL: |
| 348 | 348 | debug("%s","LIB3270_CONTENT_ALL"); |
| 349 | - dynamic = g_new0(GList,1); | |
| 350 | - dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0,1); | |
| 351 | - selection = dynamic; | |
| 349 | + selection = dynamic = g_list_append_lib3270_selection(dynamic, v3270_get_session(dialog->terminal),TRUE); | |
| 352 | 350 | break; |
| 353 | 351 | |
| 354 | 352 | case LIB3270_CONTENT_COPY: |
| ... | ... | @@ -358,9 +356,7 @@ static void icon_press(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconPosition icon_ |
| 358 | 356 | |
| 359 | 357 | case LIB3270_CONTENT_SELECTED: |
| 360 | 358 | debug("%s","LIB3270_CONTENT_SELECTED"); |
| 361 | - dynamic = g_new0(GList,1); | |
| 362 | - dynamic->data = (gpointer) lib3270_get_selection(v3270_get_session(dialog->terminal),0,0); | |
| 363 | - selection = dynamic; | |
| 359 | + selection = dynamic = g_list_append_lib3270_selection(dynamic, v3270_get_session(dialog->terminal),FALSE); | |
| 364 | 360 | break; |
| 365 | 361 | |
| 366 | 362 | default: | ... | ... |
src/include/internals.h
| ... | ... | @@ -139,6 +139,8 @@ |
| 139 | 139 | |
| 140 | 140 | G_GNUC_INTERNAL gchar * v3270_convert_to_3270_charset(GtkWidget *widget, const gchar *text, const gchar *encoding, GError **error); |
| 141 | 141 | |
| 142 | + /// @brief Add current lib3270 selection to a list | |
| 143 | + G_GNUC_INTERNAL GList * g_list_append_lib3270_selection(GList *list, H3270 *hSession, gboolean all); | |
| 142 | 144 | |
| 143 | 145 | /*--[ Internal Widgets & Tools ]---------------------------------------------------------------------*/ |
| 144 | 146 | ... | ... |
src/include/v3270/print.h
| ... | ... | @@ -64,8 +64,10 @@ |
| 64 | 64 | |
| 65 | 65 | LIB3270_EXPORT GType V3270PrintOperation_get_type(void); |
| 66 | 66 | LIB3270_EXPORT GtkPrintOperation * v3270_print_operation_new(GtkWidget *widget, LIB3270_CONTENT_OPTION mode); |
| 67 | + | |
| 67 | 68 | LIB3270_EXPORT void v3270_print_operation_apply_settings(GtkPrintOperation *operation, GtkWidget *settings); |
| 68 | 69 | |
| 70 | + LIB3270_EXPORT void v3270_print_operation_set_terminal(GtkPrintOperation * operation, GtkWidget *terminal); | |
| 69 | 71 | LIB3270_EXPORT GtkWidget * v3270_print_operation_get_terminal(GtkPrintOperation *operation); |
| 70 | 72 | |
| 71 | 73 | LIB3270_EXPORT gboolean v3270_print_operation_set_font_family(GtkPrintOperation *operation, const gchar *fontname); | ... | ... |
| ... | ... | @@ -0,0 +1,66 @@ |
| 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 <clipboard.h> | |
| 31 | + #include <ctype.h> | |
| 32 | + #include <lib3270/selection.h> | |
| 33 | + | |
| 34 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 35 | + | |
| 36 | + GList * g_list_append_lib3270_selection(GList *list, H3270 *hSession, gboolean all) | |
| 37 | + { | |
| 38 | + lib3270_selection * selection = lib3270_get_selection(hSession,0,all); | |
| 39 | + | |
| 40 | + if(selection) | |
| 41 | + { | |
| 42 | + size_t sz = sizeof(lib3270_selection) + (sizeof(lib3270_selection_element) * ((selection->bounds.width * selection->bounds.height)+1)); | |
| 43 | + | |
| 44 | + debug( | |
| 45 | + "width=%u height=%u length=%u (sz=%u, szHeader=%u, szElement=%u)", | |
| 46 | + selection->bounds.width, | |
| 47 | + selection->bounds.height, | |
| 48 | + (selection->bounds.width * selection->bounds.height), | |
| 49 | + sz, | |
| 50 | + sizeof(lib3270_selection), | |
| 51 | + sizeof(lib3270_selection_element) | |
| 52 | + ); | |
| 53 | + | |
| 54 | + gpointer data = g_malloc0(sz); | |
| 55 | + memcpy(data,selection,sz); | |
| 56 | + | |
| 57 | + lib3270_free(selection); | |
| 58 | + | |
| 59 | + return g_list_append(list,data); | |
| 60 | + } | |
| 61 | + | |
| 62 | + g_warning("Can't get TN3270 active selection"); | |
| 63 | + | |
| 64 | + return NULL; | |
| 65 | + | |
| 66 | + } | ... | ... |
src/terminal/properties/get.c
v3270.cbp
| ... | ... | @@ -188,6 +188,9 @@ |
| 188 | 188 | <Unit filename="src/selection/datablock.c"> |
| 189 | 189 | <Option compilerVar="CC" /> |
| 190 | 190 | </Unit> |
| 191 | + <Unit filename="src/selection/get.c"> | |
| 192 | + <Option compilerVar="CC" /> | |
| 193 | + </Unit> | |
| 191 | 194 | <Unit filename="src/selection/html.c"> |
| 192 | 195 | <Option compilerVar="CC" /> |
| 193 | 196 | </Unit> | ... | ... |