On windows `GtkPrintSettings` can be corrupted - no print dialog is shown
On Windows, a driver/windows or GTK update can result in a corrupted GtkPrintSettings
, which prevents Software utilizing it from opening the print dialog.
Steps to reproduce
- Use a software which utilizes
GtkPrintSettings
- Update Windows / gtk
- Use the same software and try to print again
- Sometimes no Print Dialog will occur
Alternative:
- Download corrupted ini file
- Use it as input for
GtkPrintSettings
- Use the same software and try to print again
- No Print Dialog will occur
Current behavior
Print Dialog is not shown with corrupted GtkPrintSettings
Expected outcome
Print Dialog is shown, but GtkPrintSettings
are reset.
Version information
libgtk-version: 3.24.23 OS: Windows
Additional information
Corrupted File: print-config.ini
Code:
void PrintHandler::print(Document* doc, int currentPage) {
auto filepath = Util::getConfigFile(PRINT_CONFIG_FILE);
GtkPrintSettings* settings = gtk_print_settings_new_from_file(filepath.u8string().c_str(), nullptr);
if (settings == nullptr) {
settings = gtk_print_settings_new();
}
this->doc = doc;
GtkPrintOperation* op = gtk_print_operation_new();
gtk_print_operation_set_print_settings(op, settings);
gtk_print_operation_set_n_pages(op, doc->getPageCount());
gtk_print_operation_set_current_page(op, currentPage);
gtk_print_operation_set_job_name(op, "Xournal++");
gtk_print_operation_set_unit(op, GTK_UNIT_POINTS);
gtk_print_operation_set_use_full_page(op, true);
g_signal_connect(op, "draw_page", G_CALLBACK(drawPage), this);
g_signal_connect(op, "request-page-setup", G_CALLBACK(requestPageSetup), this);
GtkPrintOperationResult res =
gtk_print_operation_run(op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, nullptr, nullptr);
if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
g_object_unref(settings);
settings = gtk_print_operation_get_print_settings(op);
gtk_print_settings_to_file(settings, filepath.u8string().c_str(), nullptr);
settings = nullptr;
}
g_object_unref(op);
this->doc = nullptr;
}
Linked Issue: https://github.com/xournalpp/xournalpp/issues/2974