diff --git a/crosspoint_reader/README.md b/crosspoint_reader/README.md index fa0b7dd..a45b09a 100644 --- a/crosspoint_reader/README.md +++ b/crosspoint_reader/README.md @@ -15,6 +15,7 @@ Default settings: - Host fallback: 192.168.4.1 - Port: 81 - Upload path: / +- Upload template: blank, which uses Calibre's send-to-device template Install: 1. Download the latest release from the [releases page](https://github.com/crosspoint-reader/calibre-plugins/releases) (or zip the contents of this directory). diff --git a/crosspoint_reader/config.py b/crosspoint_reader/config.py index 2765dcf..916364e 100644 --- a/crosspoint_reader/config.py +++ b/crosspoint_reader/config.py @@ -25,25 +25,30 @@ PREFS.defaults['debug'] = False PREFS.defaults['fetch_metadata'] = False PREFS.defaults['send_to_root'] = False +PREFS.defaults['upload_template'] = '' class CrossPointConfigWidget(QWidget): def __init__(self): super().__init__() layout = QFormLayout(self) + layout.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy.ExpandingFieldsGrow) self.host = QLineEdit(self) self.port = QSpinBox(self) self.port.setRange(1, 65535) self.path = QLineEdit(self) + self.upload_template = QLineEdit(self) self.chunk_size = QSpinBox(self) self.chunk_size.setRange(512, 65536) self.debug = QCheckBox('Enable debug logging', self) self.fetch_metadata = QCheckBox('Fetch metadata (slower device list)', self) - self.send_to_root = QCheckBox('Send to root (ignore folder template)', self) + self.send_to_root = QCheckBox('Send to root (ignore any template)', self) self.host.setText(PREFS['host']) self.port.setValue(PREFS['port']) self.path.setText(PREFS['path']) + self.upload_template.setText(PREFS['upload_template']) + self.upload_template.setPlaceholderText("Leave blank to use Calibre's send-to-device template") self.chunk_size.setValue(PREFS['chunk_size']) self.debug.setChecked(PREFS['debug']) self.fetch_metadata.setChecked(PREFS['fetch_metadata']) @@ -58,6 +63,7 @@ def __init__(self): layout.addRow('', notice) layout.addRow('Upload path', self.path) + layout.addRow('Upload template', self.upload_template) layout.addRow('Chunk size', self.chunk_size) layout.addRow('', self.debug) layout.addRow('', self.fetch_metadata) @@ -80,6 +86,7 @@ def save(self): PREFS['host'] = self.host.text().strip() or PREFS.defaults['host'] PREFS['port'] = int(self.port.value()) PREFS['path'] = self.path.text().strip() or PREFS.defaults['path'] + PREFS['upload_template'] = self.upload_template.text().strip() PREFS['chunk_size'] = int(self.chunk_size.value()) PREFS['debug'] = bool(self.debug.isChecked()) PREFS['fetch_metadata'] = bool(self.fetch_metadata.isChecked()) diff --git a/crosspoint_reader/driver.py b/crosspoint_reader/driver.py index 8dc9f7e..123d66f 100644 --- a/crosspoint_reader/driver.py +++ b/crosspoint_reader/driver.py @@ -210,7 +210,7 @@ def free_space(self, end_session=True): return 10 * 1024 * 1024 * 1024, 0, 0 def _format_upload_path(self, mi, original_name): - """Format an upload path using the send-to-device template. + """Format an upload path using the configured upload template. Returns (subdirs, filename) where subdirs is a list of directory components from the template (may be empty for flat templates). @@ -219,9 +219,11 @@ def _format_upload_path(self, mi, original_name): from calibre.library.save_to_disk import config as sconfig, get_components from calibre.utils.filenames import ascii_filename - template = self.save_template() + template = PREFS['upload_template'] if not template: - template = sconfig().parse().send_template + template = self.save_template() + if not template: + template = sconfig().parse().send_template components = get_components( template, mi, -1, '%b %Y', 250,