Commit e7efe4fea4cc7075e2d3dfe64f76e1f24d1950a3

Authored by perry.werneck@gmail.com
1 parent 6267a1c5

Corrigindo diálogo de impressão

Showing 1 changed file with 85 additions and 67 deletions   Show diff stats
src/pw3270/print.c
@@ -51,6 +51,7 @@ @@ -51,6 +51,7 @@
51 int show_selection : 1; 51 int show_selection : 1;
52 PW3270_SRC src; 52 PW3270_SRC src;
53 53
  54 + GtkWidget * widget;
54 H3270 * session; 55 H3270 * session;
55 56
56 int baddr; 57 int baddr;
@@ -221,76 +222,104 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -221,76 +222,104 @@ static gchar * enum_to_string(GType type, guint enum_value)
221 222
222 #endif // WIN32 223 #endif // WIN32
223 224
  225 + static void show_print_error(GtkWidget *widget, GError *err)
  226 + {
  227 + GtkWidget *dialog = gtk_message_dialog_new_with_markup( GTK_WINDOW(gtk_widget_get_toplevel(widget)),
  228 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  229 + GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,
  230 + "%s",_( "Print operation failed" ));
  231 +
  232 + g_warning(err->message);
  233 +
  234 + gtk_window_set_title(GTK_WINDOW(dialog),_("Error"));
  235 +
  236 + gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",err->message);
  237 +
  238 + gtk_dialog_run(GTK_DIALOG(dialog));
  239 + gtk_widget_destroy(dialog);
  240 +}
  241 +
224 static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info) 242 static void done(GtkPrintOperation *prt, GtkPrintOperationResult result, PRINT_INFO *info)
225 { 243 {
226 -#ifdef WIN32 244 + if(result == GTK_PRINT_OPERATION_RESULT_ERROR)
  245 + {
  246 + GError * err = NULL;
227 247
228 - HKEY registry; 248 + gtk_print_operation_get_error(prt,&err);
  249 + show_print_error(info->widget,err);
  250 + g_error_free(err);
229 251
230 - if(get_registry_handle("print",&registry,KEY_SET_VALUE)) 252 + }
  253 + else
231 { 254 {
232 - HKEY hKey;  
233 - DWORD disp; 255 + // Save settings
  256 + GtkPrintSettings * settings = gtk_print_operation_get_print_settings(prt);
  257 + GtkPageSetup * pgsetup = gtk_print_operation_get_default_page_setup(prt);
234 258
235 - if(RegCreateKeyEx(registry,"settings",0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS)  
236 - {  
237 - gtk_print_settings_foreach( gtk_print_operation_get_print_settings(prt),  
238 - (GtkPrintSettingsFunc) save_settings,  
239 - hKey );  
240 - RegCloseKey(hKey);  
241 - } 259 + trace("Saving settings PrintSettings=%p page_setup=%p",settings,pgsetup);
242 260
243 - if(RegCreateKeyEx(registry,"pagesetup",0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS)  
244 - {  
245 - HKEY hPaperSize;  
246 - GtkPageSetup * setup = gtk_print_operation_get_default_page_setup(prt);  
247 - gchar * orientation = enum_to_string(GTK_TYPE_PAGE_ORIENTATION,gtk_page_setup_get_orientation(setup)); 261 +#ifdef WIN32
  262 + HKEY registry;
248 263
249 - // From http://git.gnome.org/browse/gtk+/tree/gtk/gtkpagesetup.c  
250 - save_double(hKey, "MarginTop", gtk_page_setup_get_top_margin(setup, GTK_UNIT_MM));  
251 - save_double(hKey, "MarginBottom", gtk_page_setup_get_bottom_margin(setup, GTK_UNIT_MM));  
252 - save_double(hKey, "MarginLeft", gtk_page_setup_get_left_margin(setup, GTK_UNIT_MM));  
253 - save_double(hKey, "MarginRight", gtk_page_setup_get_right_margin(setup, GTK_UNIT_MM));  
254 - save_string(hKey, "Orientation", orientation); 264 + if(get_registry_handle("print",&registry,KEY_SET_VALUE))
  265 + {
  266 + HKEY hKey;
  267 + DWORD disp;
255 268
256 - g_free (orientation); 269 + if(RegCreateKeyEx(registry,"settings",0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS)
  270 + {
  271 + gtk_print_settings_foreach( settings,(GtkPrintSettingsFunc) save_settings, hKey );
  272 + RegCloseKey(hKey);
  273 + }
257 274
258 - if(RegCreateKeyEx(hKey,"papersize",0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hPaperSize,&disp) == ERROR_SUCCESS) 275 + if(RegCreateKeyEx(registry,"pagesetup",0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hKey,&disp) == ERROR_SUCCESS)
259 { 276 {
260 - GtkPaperSize *size = gtk_page_setup_get_paper_size(setup);  
261 - if(size)  
262 - {  
263 - // From http://git.gnome.org/browse/gtk+/tree/gtk/gtkpapersize.c  
264 - const gchar *name = gtk_paper_size_get_name(size);  
265 - const gchar *display_name = gtk_paper_size_get_display_name(size);  
266 - const gchar *ppd_name = gtk_paper_size_get_ppd_name(size); 277 + HKEY hPaperSize;
  278 + gchar * orientation = enum_to_string(GTK_TYPE_PAGE_ORIENTATION,gtk_page_setup_get_orientation(pgsetup));
267 279
268 - if (ppd_name != NULL)  
269 - save_string(hPaperSize,"PPDName", ppd_name);  
270 - else  
271 - save_string(hPaperSize,"Name", name); 280 + // From http://git.gnome.org/browse/gtk+/tree/gtk/gtkpagesetup.c
  281 + save_double(hKey, "MarginTop", gtk_page_setup_get_top_margin(pgsetup, GTK_UNIT_MM));
  282 + save_double(hKey, "MarginBottom", gtk_page_setup_get_bottom_margin(pgsetup, GTK_UNIT_MM));
  283 + save_double(hKey, "MarginLeft", gtk_page_setup_get_left_margin(pgsetup, GTK_UNIT_MM));
  284 + save_double(hKey, "MarginRight", gtk_page_setup_get_right_margin(pgsetup, GTK_UNIT_MM));
  285 + save_string(hKey, "Orientation", orientation);
272 286
273 - if (display_name)  
274 - save_string(hPaperSize,"DisplayName", display_name); 287 + g_free (orientation);
275 288
276 - save_double(hPaperSize, "Width", gtk_paper_size_get_width (size, GTK_UNIT_MM));  
277 - save_double(hPaperSize, "Height", gtk_paper_size_get_height (size, GTK_UNIT_MM)); 289 + if(RegCreateKeyEx(hKey,"papersize",0,NULL,REG_OPTION_NON_VOLATILE,KEY_SET_VALUE,NULL,&hPaperSize,&disp) == ERROR_SUCCESS)
  290 + {
  291 + GtkPaperSize *size = gtk_page_setup_get_paper_size(pgsetup);
  292 + if(size)
  293 + {
  294 + // From http://git.gnome.org/browse/gtk+/tree/gtk/gtkpapersize.c
  295 + const gchar *name = gtk_paper_size_get_name(size);
  296 + const gchar *display_name = gtk_paper_size_get_display_name(size);
  297 + const gchar *ppd_name = gtk_paper_size_get_ppd_name(size);
  298 +
  299 + if (ppd_name != NULL)
  300 + save_string(hPaperSize,"PPDName", ppd_name);
  301 + else
  302 + save_string(hPaperSize,"Name", name);
  303 +
  304 + if (display_name)
  305 + save_string(hPaperSize,"DisplayName", display_name);
  306 +
  307 + save_double(hPaperSize, "Width", gtk_paper_size_get_width (size, GTK_UNIT_MM));
  308 + save_double(hPaperSize, "Height", gtk_paper_size_get_height (size, GTK_UNIT_MM));
  309 + }
  310 + RegCloseKey(hPaperSize);
278 } 311 }
279 - RegCloseKey(hPaperSize); 312 + RegCloseKey(hKey);
280 } 313 }
281 - RegCloseKey(hKey);  
282 - }  
283 -  
284 - RegCloseKey(registry);  
285 - }  
286 314
  315 + RegCloseKey(registry);
  316 + }
287 #else 317 #else
288 - GKeyFile * conf = get_application_keyfile();  
289 -  
290 - gtk_print_settings_to_key_file(gtk_print_operation_get_print_settings(prt),conf,"print_settings");  
291 - gtk_page_setup_to_key_file(gtk_print_operation_get_default_page_setup(prt),conf,"page_setup");  
292 - 318 + GKeyFile * conf = get_application_keyfile();
  319 + gtk_print_settings_to_key_file(settings,conf,"print_settings");
  320 + gtk_page_setup_to_key_file(pgsetup,conf,"page_setup");
293 #endif 321 #endif
  322 + }
294 323
295 if(info->font_scaled) 324 if(info->font_scaled)
296 cairo_scaled_font_destroy(info->font_scaled); 325 cairo_scaled_font_destroy(info->font_scaled);
@@ -470,6 +499,8 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -470,6 +499,8 @@ static gchar * enum_to_string(GType type, guint enum_value)
470 GtkWidget * combo = g_object_get_data(G_OBJECT(widget),"combo"); 499 GtkWidget * combo = g_object_get_data(G_OBJECT(widget),"combo");
471 GdkColor * clr = g_object_get_data(G_OBJECT(combo),"selected"); 500 GdkColor * clr = g_object_get_data(G_OBJECT(combo),"selected");
472 501
  502 + trace("%s starts combo=%p clr=%p widget=%p",__FUNCTION__,combo,clr,widget);
  503 +
473 if(info->font) 504 if(info->font)
474 set_string_to_config("print",FONT_CONFIG,info->font); 505 set_string_to_config("print",FONT_CONFIG,info->font);
475 506
@@ -487,7 +518,7 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -487,7 +518,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
487 set_string_to_config("print","colors","%s",str->str); 518 set_string_to_config("print","colors","%s",str->str);
488 g_string_free(str,TRUE); 519 g_string_free(str,TRUE);
489 } 520 }
490 - g_object_unref(combo); 521 +
491 } 522 }
492 523
493 #ifdef WIN32 524 #ifdef WIN32
@@ -507,6 +538,7 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -507,6 +538,7 @@ static gchar * enum_to_string(GType type, guint enum_value)
507 *info = g_new0(PRINT_INFO,1); 538 *info = g_new0(PRINT_INFO,1);
508 (*info)->session = v3270_get_session(widget); 539 (*info)->session = v3270_get_session(widget);
509 (*info)->cols = 80; 540 (*info)->cols = 80;
  541 + (*info)->widget = widget;
510 542
511 // Basic setup 543 // Basic setup
512 gtk_print_operation_set_allow_async(print,get_boolean_from_config("print","allow_async",TRUE)); 544 gtk_print_operation_set_allow_async(print,get_boolean_from_config("print","allow_async",TRUE));
@@ -692,22 +724,8 @@ static gchar * enum_to_string(GType type, guint enum_value) @@ -692,22 +724,8 @@ static gchar * enum_to_string(GType type, guint enum_value)
692 724
693 if(err) 725 if(err)
694 { 726 {
695 - GtkWidget *dialog;  
696 -  
697 - g_warning(err->message);  
698 -  
699 - dialog = gtk_message_dialog_new_with_markup( GTK_WINDOW(gtk_widget_get_toplevel(widget)),  
700 - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,  
701 - GTK_MESSAGE_ERROR,GTK_BUTTONS_CLOSE,  
702 - "%s",_( "Print operation failed" ));  
703 -  
704 - gtk_window_set_title(GTK_WINDOW(dialog),_("Error"));  
705 -  
706 - gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog),"%s",err->message); 727 + show_print_error(widget,err);
707 g_error_free(err); 728 g_error_free(err);
708 -  
709 - gtk_dialog_run(GTK_DIALOG(dialog));  
710 - gtk_widget_destroy(dialog);  
711 } 729 }
712 730
713 g_object_unref(print); 731 g_object_unref(print);