Reading of metadata from devices is configurable. Putting files into sub directories on device is confirgurable.

This commit is contained in:
John Schember 2009-07-27 07:46:25 -04:00
parent cb224d28bf
commit 1be272e679
7 changed files with 60 additions and 15 deletions

View File

@ -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}.

View File

@ -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)

View File

@ -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']:

View File

@ -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

View File

@ -1,4 +1,3 @@
from __future__ import with_statement
__license__ = 'GPL v3'
__copyright__ = '2009, John Schember <john at nachtimwald.com>'
'''
@ -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

View File

@ -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()

View File

@ -40,7 +40,7 @@
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../gui2/images.qrc">
<iconset resource="../images.qrc">
<normaloff>:/images/arrow-up.svg</normaloff>:/images/arrow-up.svg</iconset>
</property>
</widget>
@ -64,7 +64,7 @@
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../gui2/images.qrc">
<iconset resource="../images.qrc">
<normaloff>:/images/arrow-down.svg</normaloff>:/images/arrow-down.svg</iconset>
</property>
</widget>
@ -73,13 +73,27 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="opt_use_subdirs">
<property name="text">
<string>Use sub directories</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="opt_read_metadata">
<property name="text">
<string>Read metadata from files on device</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../gui2/images.qrc"/>
<include location="../images.qrc"/>
</resources>
<connections/>
</ui>