static VALUE rg_initialize(int argc, VALUE *argv, VALUE self) { VALUE arg1, arg2; GtkPrintSettings* settings = NULL; GError *error = NULL; rb_scan_args(argc, argv, "02", &arg1, &arg2); if (NIL_P(arg1)){ settings = gtk_print_settings_new(); } else if (NIL_P(arg2)){ settings = gtk_print_settings_new_from_file(RVAL2CSTR(arg1), &error); if (!settings) { RAISE_GERROR(error); } } else { settings = gtk_print_settings_new_from_key_file((GKeyFile*)RVAL2BOXED(arg1, G_TYPE_KEY_FILE), RVAL2CSTR(arg2), &error); if (!settings) { RAISE_GERROR(error); } } G_INITIALIZE(self, settings); return Qnil; }
GtkPrintSettings * xviewer_print_get_print_settings (void) { GtkPrintSettings *print_settings; GError *error = NULL; GKeyFile *key_file; key_file = xviewer_print_get_key_file (); if (key_file && g_key_file_has_group (key_file, XVIEWER_PRINT_SETTINGS_GROUP)) { print_settings = gtk_print_settings_new_from_key_file (key_file, XVIEWER_PRINT_SETTINGS_GROUP, &error); } else { print_settings = gtk_print_settings_new (); } if (error) { print_settings = gtk_print_settings_new (); g_warning ("Error loading print settings file: %s", error->message); g_error_free (error); } if (key_file) g_key_file_free (key_file); return print_settings; }
int PrintText(const char *name, gchar *text) { GKeyFile *conf = GetConf(); GtkPrintOperation *prt; const gchar *font; GtkPageSetup *page_setup = NULL; GtkPrintSettings *print_settings = NULL; if(!text) return -EINVAL; prt = gtk_print_operation_new(); if(!prt) return -1; // Set job parameters g_object_set_data_full(G_OBJECT(prt),"3270Text",g_strsplit(g_strchomp(text),"\n",-1),(void (*)(gpointer)) g_strfreev); // Set print font = GetString("Print","Font",""); if(!*font) font = GetString("Terminal","Font","Courier"); g_object_set_data_full(G_OBJECT(prt),"3270FontName",g_strdup(font),g_free); // Configure print operation gtk_print_operation_set_job_name(prt,name); gtk_print_operation_set_allow_async(prt,0); gtk_print_operation_set_show_progress(prt,1); gtk_print_operation_set_custom_tab_label(prt,_( "Font" )); g_signal_connect(prt, "begin-print", G_CALLBACK(begin_print), 0); g_signal_connect(prt, "draw-page", G_CALLBACK(draw_page), 0); #ifdef HAVE_PRINT_FONT_DIALOG g_signal_connect(prt, "create-custom-widget", G_CALLBACK(create_custom_widget), 0); g_signal_connect(prt, "custom-widget-apply", G_CALLBACK(custom_widget_apply), 0); #endif g_signal_connect(prt, "done", G_CALLBACK(print_done), 0); if(conf) { #if GTK_CHECK_VERSION(2,12,0) gchar *ptr = g_key_file_get_string(conf,"Print Settings","output-uri",NULL); if(ptr) { gchar *uri = NULL; switch(*(ptr++)) { case '$': if(g_str_has_prefix(ptr,"home/")) uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr+5); #if GTK_CHECK_VERSION(2,14,0) else if(g_str_has_prefix(ptr,"documents/")) uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DOCUMENTS),ptr+10); else if(g_str_has_prefix(ptr,"desktop/")) uri = g_strdup_printf("file:///%s/%s",g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP),ptr+8); #endif break; case '~': uri = g_strdup_printf("file:///%s/%s",g_get_home_dir(),ptr); break; } if(uri) { g_key_file_set_string(conf,"Print Settings","output-uri",uri); g_free(uri); } } print_settings = gtk_print_settings_new_from_key_file(conf,NULL,NULL); page_setup = gtk_page_setup_new_from_key_file(conf,NULL,NULL); if(!page_setup) page_setup = gtk_page_setup_new(); #else // GTK_CHECK_VERSION(2,12,0) print_settings = gtk_print_settings_new(); if(print_settings) { gchar **list; int f; list = g_key_file_get_keys(conf,"PrintSettings",NULL,NULL); if(list) { for(f=0;list[f];f++) gtk_print_settings_set(print_settings,list[f],g_key_file_get_string(conf,"PrintSettings",list[f],NULL)); g_strfreev(list); } } page_setup = gtk_page_setup_new(); #endif } else { page_setup = gtk_page_setup_new(); gtk_print_operation_set_print_settings(prt,gtk_print_settings_new()); } Trace("page_setup: %p print_settings: %p",page_setup,print_settings); gtk_print_operation_set_print_settings(prt,print_settings); gtk_print_operation_set_default_page_setup(prt,page_setup); // Run Print dialog gtk_print_operation_run(prt,GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,GTK_WINDOW(topwindow),NULL); g_object_unref(prt); return 0; }