Linux: Fix a crash caused by broken/incompatible CUPS Qt system plugin. Fixes #1861741 [Linux Calibre 4.9.1 - Crash to desktop](https://bugs.launchpad.net/calibre/+bug/1861741)

Dont use QPrinter() to query the system for default paper size
This commit is contained in:
Kovid Goyal 2020-02-06 10:47:06 +05:30
parent 357762c70a
commit e94361e527
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -14,6 +14,7 @@ from PyQt5.Qt import (QIcon, QFont, QLabel, QListWidget, QAction,
QLineEdit, QComboBox, QPen, QGraphicsScene, QMenu, QStringListModel, QLineEdit, QComboBox, QPen, QGraphicsScene, QMenu, QStringListModel,
QCompleter, QTimer, QRect, QGraphicsView, QPagedPaintDevice) QCompleter, QTimer, QRect, QGraphicsView, QPagedPaintDevice)
from calibre.constants import iswindows, isosx
from calibre.gui2 import (error_dialog, pixmap_to_data, gprefs, from calibre.gui2 import (error_dialog, pixmap_to_data, gprefs,
warning_dialog) warning_dialog)
from calibre.gui2.filename_pattern_ui import Ui_Form from calibre.gui2.filename_pattern_ui import Ui_Form
@ -1243,7 +1244,11 @@ class PaperSizes(QComboBox): # {{{
def initialize(self, choices=None): def initialize(self, choices=None):
from calibre.utils.icu import numeric_sort_key from calibre.utils.icu import numeric_sort_key
if self.system_default_paper_size is None: if self.system_default_paper_size is None:
QComboBox.system_default_paper_size = 'letter' if QPrinter().pageSize() == QPagedPaintDevice.Letter else 'a4' PaperSizes.system_default_paper_size = 'a4'
if iswindows or isosx:
# On Linux, this can cause Qt to load the system cups plugin
# which can crash: https://bugs.launchpad.net/calibre/+bug/1861741
PaperSizes.system_default_paper_size = 'letter' if QPrinter().pageSize() == QPagedPaintDevice.Letter else 'a4'
if not choices: if not choices:
from calibre.ebooks.conversion.plugins.pdf_output import PAPER_SIZES from calibre.ebooks.conversion.plugins.pdf_output import PAPER_SIZES
choices = PAPER_SIZES choices = PAPER_SIZES
@ -1260,7 +1265,7 @@ class PaperSizes(QComboBox): # {{{
@get_value_for_config.setter @get_value_for_config.setter
def set_value_for_config(self, val): def set_value_for_config(self, val):
idx = self.findData(val or self.system_default_paper_size) idx = self.findData(val or PaperSizes.system_default_paper_size)
if idx == -1: if idx == -1:
idx = self.findData('a4') idx = self.findData('a4')
self.setCurrentIndex(idx) self.setCurrentIndex(idx)