UI to configure APNX settings

This commit is contained in:
Daniel Pecos Martinez 2025-07-15 21:22:08 +02:00
parent 84a3f8818d
commit b1f84b9b31
No known key found for this signature in database
GPG Key ID: 38E9D1E4A1ED64EF
3 changed files with 63 additions and 4 deletions

View File

@ -26,6 +26,7 @@ class DeviceDefaults:
'format_map': ['azw3', 'mobi', 'azw',
'azw1', 'azw4', 'kfx', 'pdf'],
'send_to': ['documents', 'kindle', 'books'],
'apnx': {'send': True, 'method': 'fast', 'custom_column_page_count': None, 'custom_column_method': None}
}
),
# B&N devices

View File

@ -87,7 +87,7 @@ class MTP_DEVICE(BASE):
p.defaults['rules'] = []
p.defaults['ignored_folders'] = {}
p.defaults['apnx'] = {
'send': True,
'send': False,
'method': 'fast',
'custom_column_page_count': None,
'custom_column_method': None,
@ -643,6 +643,7 @@ class MTP_DEVICE(BASE):
# }}}
def upload_apnx(self, parent, filename, storage, mi, filepath):
debug('upload_apnx() called')
from calibre.devices.kindle.apnx import APNXBuilder
from calibre.ptempfile import PersistentTemporaryFile
@ -651,16 +652,19 @@ class MTP_DEVICE(BASE):
apnx_local_file.close()
try:
pref = self.get_pref('apnx')
custom_page_count = 0
cust_col_name = self.get_pref('apnx').get('custom_column_page_count', None)
cust_col_name = pref.get('custom_column_page_count', None)
if cust_col_name:
try:
custom_page_count = int(mi.get(cust_col_name, 0))
except Exception:
pass
method = self.get_pref('apnx').get('method', 'fast')
cust_col_method = self.get_pref('apnx').get('custom_column_method', None)
method = pref.get('method', 'fast')
cust_col_method = pref.get('custom_column_method', None)
if cust_col_method:
try:
method = str(mi.get(cust_col_method)).lower()
@ -689,6 +693,7 @@ class MTP_DEVICE(BASE):
traceback.print_exc()
finally:
os.remove(apnx_local_path)
debug('upload_apnx() ended')
def add_books_to_metadata(self, mtp_files, metadata, booklists):
debug('add_books_to_metadata() called')

View File

@ -31,6 +31,7 @@ from qt.core import (
QVBoxLayout,
QWidget,
pyqtSignal,
QCheckBox,
)
from calibre.ebooks import BOOK_EXTENSIONS
@ -351,6 +352,51 @@ class FormatRules(QGroupBox):
yield r
# }}}
class APNX(QWidget):
def __init__(self, apnx):
QWidget.__init__(self)
self.layout = l = QVBoxLayout()
self.setLayout(l)
self.layout.setAlignment(Qt.AlignTop)
self.send = f1 = QCheckBox(_('Send page number information when sending books'))
f1.setChecked(apnx.get('send', False))
l.addWidget(f1)
label2 = QLabel('<p>' + _('Page count calculation method') + '</p>')
label2.setWordWrap(True)
l.addWidget(label2)
self.method = f2 = QComboBox(self)
f2.addItem('fast', 'fast')
f2.addItem('accurate', 'accurate')
f2.addItem('pagebrek', 'pagebreak')
f2.setCurrentIndex(f2.findText(apnx.get('method', 'fast')))
l.addWidget(f2)
label3 = QLabel('<p>' + _('Custom column name to retrieve page counts from') + '</p>')
label3.setWordWrap(True)
l.addWidget(label3)
self.column_page_count = f3 = QLineEdit(self)
f3.setText(apnx.get('custom_column_page_count', ''))
l.addWidget(f3)
label4 = QLabel('<p>' + _('Custom column name to retrieve calculation method from') + '</p>')
label4.setWordWrap(True)
l.addWidget(label4)
self.column_method = f4 = QLineEdit(self)
f4.setText(apnx.get('custom_column_method', ''))
l.addWidget(f4)
@property
def apnx(self):
result = {
'send': self.send.isChecked(),
'method': str(self.method.currentData()).strip(),
'custom_column_page_count': str(self.column_page_count.text()).strip(),
'custom_column_method': str(self.column_method.text()).strip(),
}
return result
class MTPConfig(QTabWidget):
@ -421,6 +467,10 @@ class MTPConfig(QTabWidget):
l.addWidget(r, 7, 0, 1, 2)
l.setRowStretch(7, 100)
if self.device.is_kindle:
self.apnxTab = APNX(self.get_pref('apnx'))
self.addTab(self.apnxTab, _('Page numbering (APNX)'))
self.igntab = IgnoredDevices(self.device.prefs['history'],
self.device.prefs['blacklist'])
self.addTab(self.igntab, _('Ignored devices'))
@ -509,6 +559,9 @@ class MTPConfig(QTabWidget):
if self.current_ignored_folders != self.initial_ignored_folders:
p['ignored_folders'] = self.current_ignored_folders
p.pop('apnx', None)
p['apnx'] = self.apnxTab.apnx
if self.current_device_key is not None:
self.device.prefs[self.current_device_key] = p