From 1be272e67903d7a3f68189c8d25966e9df236dea Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 27 Jul 2009 07:46:25 -0400 Subject: [PATCH] Reading of metadata from devices is configurable. Putting files into sub directories on device is confirgurable. --- src/calibre/devices/prs500/driver.py | 3 +++ src/calibre/devices/prs505/driver.py | 1 + src/calibre/devices/usbms/device.py | 3 ++- src/calibre/devices/usbms/deviceconfig.py | 17 +++++++++++----- src/calibre/devices/usbms/driver.py | 13 +++++++----- .../gui2/device_drivers/configwidget.py | 18 ++++++++++++++++- .../gui2/device_drivers/configwidget.ui | 20 ++++++++++++++++--- 7 files changed, 60 insertions(+), 15 deletions(-) diff --git a/src/calibre/devices/prs500/driver.py b/src/calibre/devices/prs500/driver.py index 0e9bb58f3e..aba8a9d088 100644 --- a/src/calibre/devices/prs500/driver.py +++ b/src/calibre/devices/prs500/driver.py @@ -108,6 +108,9 @@ class PRS500(DeviceConfig, DevicePlugin): CARD_PATH_PREFIX = __appname__ _packet_number = 0 #: Keep track of the packet number for packet tracing + SUPPORTS_SUB_DIRS = False + MUST_READ_METADATA = True + def log_packet(self, packet, header, stream=sys.stderr): """ Log C{packet} to stream C{stream}. diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py index e736ba0864..8107d7cc97 100644 --- a/src/calibre/devices/prs505/driver.py +++ b/src/calibre/devices/prs505/driver.py @@ -44,6 +44,7 @@ class PRS505(CLI, Device): CARD_PATH_PREFIX = __appname__ SUPPORTS_SUB_DIRS = True + MUST_READ_METADATA = True def open(self): Device.open(self) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 007f132b24..5f01e00c05 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -44,6 +44,7 @@ class Device(DeviceConfig, DevicePlugin): STORAGE_CARD2_VOLUME_LABEL = None SUPPORTS_SUB_DIRS = False + MUST_READ_METADATA = False FDI_TEMPLATE = \ ''' @@ -618,7 +619,7 @@ class Device(DeviceConfig, DevicePlugin): def create_upload_path(self, path, mdata, fname): resizable = [] newpath = path - if self.SUPPORTS_SUB_DIRS: + if self.SUPPORTS_SUB_DIRS and self.settings().use_subdirs: if 'tags' in mdata.keys(): for tag in mdata['tags']: diff --git a/src/calibre/devices/usbms/deviceconfig.py b/src/calibre/devices/usbms/deviceconfig.py index bbe3a13646..344b8fcc46 100644 --- a/src/calibre/devices/usbms/deviceconfig.py +++ b/src/calibre/devices/usbms/deviceconfig.py @@ -8,13 +8,15 @@ from calibre.utils.config import Config, ConfigProxy class DeviceConfig(object): - HELP_MESSAGE = _('Ordered list of formats the device will accept') + HELP_MESSAGE = _('Configure Device') @classmethod def _config(cls): klass = cls if isinstance(cls, type) else cls.__class__ c = Config('device_drivers_%s' % klass.__name__, _('settings for device drivers')) - c.add_opt('format_map', default=cls.FORMATS, help=cls.HELP_MESSAGE) + c.add_opt('format_map', default=cls.FORMATS, help=_('Ordered list of formats the device will accept')) + c.add_opt('use_subdirs', default=True, help=_('Place files in sub directories if the device supports them')) + c.add_opt('read_metadata', default=True, help=_('Read metadata from files on device')) return c @classmethod @@ -24,17 +26,22 @@ class DeviceConfig(object): @classmethod def config_widget(cls): from calibre.gui2.device_drivers.configwidget import ConfigWidget - cw = ConfigWidget(cls.settings(), cls.FORMATS) + cw = ConfigWidget(cls.settings(), cls.FORMATS, cls.SUPPORTS_SUB_DIRS, + cls.MUST_READ_METADATA) return cw @classmethod def save_settings(cls, config_widget): cls._configProxy()['format_map'] = config_widget.format_map() + if cls.SUPPORTS_SUB_DIRS: + cls._configProxy()['use_subdirs'] = config_widget.use_subdirs() + if not cls.MUST_READ_METADATA: + cls._configProxy()['read_metadata'] = config_widget.read_metadata() @classmethod def settings(cls): return cls._config().parse() - + + @classmethod def customization_help(cls, gui=False): return cls.HELP_MESSAGE - diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index cdcf99546b..7df3911cdc 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -1,4 +1,3 @@ -from __future__ import with_statement __license__ = 'GPL v3' __copyright__ = '2009, John Schember ' ''' @@ -203,11 +202,15 @@ class USBMS(CLI, Device): @classmethod def book_from_path(cls, path): from calibre.ebooks.metadata.meta import path_to_ext - fileext = path_to_ext(path) - mi = cls.metadata_from_path(path) - mime = mime_type_ext(fileext) + mime = mime_type_ext(path_to_ext(path)) + + if cls.settings().read_metadata or cls.MUST_READ_METADATA: + mi = cls.metadata_from_path(path) + else: + from calibre.ebooks.metadata import MetaInformation + mi = MetaInformation(os.path.basename(path)) + authors = authors_to_string(mi.authors) book = Book(path, mi.title, authors, mime) return book - diff --git a/src/calibre/gui2/device_drivers/configwidget.py b/src/calibre/gui2/device_drivers/configwidget.py index 79b370d0bb..ef81e0533d 100644 --- a/src/calibre/gui2/device_drivers/configwidget.py +++ b/src/calibre/gui2/device_drivers/configwidget.py @@ -10,7 +10,9 @@ from calibre.gui2.device_drivers.configwidget_ui import Ui_ConfigWidget class ConfigWidget(QWidget, Ui_ConfigWidget): - def __init__(self, settings, all_formats): + def __init__(self, settings, all_formats, supports_subdirs, + must_read_metadata): + QWidget.__init__(self) Ui_ConfigWidget.__init__(self) self.setupUi(self) @@ -28,6 +30,15 @@ class ConfigWidget(QWidget, Ui_ConfigWidget): self.connect(self.column_up, SIGNAL('clicked()'), self.up_column) self.connect(self.column_down, SIGNAL('clicked()'), self.down_column) + if supports_subdirs: + self.opt_use_subdirs.setChecked(self.settings.use_subdirs) + else: + self.opt_use_subdirs.hide() + if not must_read_metadata: + self.opt_read_metadata.setChecked(self.settings.read_metadata) + else: + self.opt_read_metadata.hide() + def up_column(self): idx = self.columns.currentRow() if idx > 0: @@ -44,3 +55,8 @@ class ConfigWidget(QWidget, Ui_ConfigWidget): formats = [unicode(self.columns.item(i).data(Qt.UserRole).toString()) for i in range(self.columns.count()) if self.columns.item(i).checkState()==Qt.Checked] return formats + def use_subdirs(self): + return self.opt_use_subdirs.isChecked() + + def read_metadata(self): + return self.opt_read_metadata.isChecked() diff --git a/src/calibre/gui2/device_drivers/configwidget.ui b/src/calibre/gui2/device_drivers/configwidget.ui index 15b50664c4..660e4f9925 100644 --- a/src/calibre/gui2/device_drivers/configwidget.ui +++ b/src/calibre/gui2/device_drivers/configwidget.ui @@ -40,7 +40,7 @@ ... - + :/images/arrow-up.svg:/images/arrow-up.svg @@ -64,7 +64,7 @@ ... - + :/images/arrow-down.svg:/images/arrow-down.svg @@ -73,13 +73,27 @@ + + + + Use sub directories + + + + + + + Read metadata from files on device + + + - +