mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Reading of metadata from devices is configurable. Putting files into sub directories on device is confirgurable.
This commit is contained in:
parent
cb224d28bf
commit
1be272e679
@ -108,6 +108,9 @@ class PRS500(DeviceConfig, DevicePlugin):
|
|||||||
CARD_PATH_PREFIX = __appname__
|
CARD_PATH_PREFIX = __appname__
|
||||||
_packet_number = 0 #: Keep track of the packet number for packet tracing
|
_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):
|
def log_packet(self, packet, header, stream=sys.stderr):
|
||||||
"""
|
"""
|
||||||
Log C{packet} to stream C{stream}.
|
Log C{packet} to stream C{stream}.
|
||||||
|
@ -44,6 +44,7 @@ class PRS505(CLI, Device):
|
|||||||
CARD_PATH_PREFIX = __appname__
|
CARD_PATH_PREFIX = __appname__
|
||||||
|
|
||||||
SUPPORTS_SUB_DIRS = True
|
SUPPORTS_SUB_DIRS = True
|
||||||
|
MUST_READ_METADATA = True
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
Device.open(self)
|
Device.open(self)
|
||||||
|
@ -44,6 +44,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
STORAGE_CARD2_VOLUME_LABEL = None
|
STORAGE_CARD2_VOLUME_LABEL = None
|
||||||
|
|
||||||
SUPPORTS_SUB_DIRS = False
|
SUPPORTS_SUB_DIRS = False
|
||||||
|
MUST_READ_METADATA = False
|
||||||
|
|
||||||
FDI_TEMPLATE = \
|
FDI_TEMPLATE = \
|
||||||
'''
|
'''
|
||||||
@ -618,7 +619,7 @@ class Device(DeviceConfig, DevicePlugin):
|
|||||||
def create_upload_path(self, path, mdata, fname):
|
def create_upload_path(self, path, mdata, fname):
|
||||||
resizable = []
|
resizable = []
|
||||||
newpath = path
|
newpath = path
|
||||||
if self.SUPPORTS_SUB_DIRS:
|
if self.SUPPORTS_SUB_DIRS and self.settings().use_subdirs:
|
||||||
|
|
||||||
if 'tags' in mdata.keys():
|
if 'tags' in mdata.keys():
|
||||||
for tag in mdata['tags']:
|
for tag in mdata['tags']:
|
||||||
|
@ -8,13 +8,15 @@ from calibre.utils.config import Config, ConfigProxy
|
|||||||
|
|
||||||
class DeviceConfig(object):
|
class DeviceConfig(object):
|
||||||
|
|
||||||
HELP_MESSAGE = _('Ordered list of formats the device will accept')
|
HELP_MESSAGE = _('Configure Device')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _config(cls):
|
def _config(cls):
|
||||||
klass = cls if isinstance(cls, type) else cls.__class__
|
klass = cls if isinstance(cls, type) else cls.__class__
|
||||||
c = Config('device_drivers_%s' % klass.__name__, _('settings for device drivers'))
|
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
|
return c
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -24,17 +26,22 @@ class DeviceConfig(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def config_widget(cls):
|
def config_widget(cls):
|
||||||
from calibre.gui2.device_drivers.configwidget import ConfigWidget
|
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
|
return cw
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def save_settings(cls, config_widget):
|
def save_settings(cls, config_widget):
|
||||||
cls._configProxy()['format_map'] = config_widget.format_map()
|
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
|
@classmethod
|
||||||
def settings(cls):
|
def settings(cls):
|
||||||
return cls._config().parse()
|
return cls._config().parse()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def customization_help(cls, gui=False):
|
def customization_help(cls, gui=False):
|
||||||
return cls.HELP_MESSAGE
|
return cls.HELP_MESSAGE
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from __future__ import with_statement
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2009, John Schember <john at nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john at nachtimwald.com>'
|
||||||
'''
|
'''
|
||||||
@ -203,11 +202,15 @@ class USBMS(CLI, Device):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def book_from_path(cls, path):
|
def book_from_path(cls, path):
|
||||||
from calibre.ebooks.metadata.meta import path_to_ext
|
from calibre.ebooks.metadata.meta import path_to_ext
|
||||||
fileext = path_to_ext(path)
|
mime = mime_type_ext(path_to_ext(path))
|
||||||
mi = cls.metadata_from_path(path)
|
|
||||||
mime = mime_type_ext(fileext)
|
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)
|
authors = authors_to_string(mi.authors)
|
||||||
|
|
||||||
book = Book(path, mi.title, authors, mime)
|
book = Book(path, mi.title, authors, mime)
|
||||||
return book
|
return book
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ from calibre.gui2.device_drivers.configwidget_ui import Ui_ConfigWidget
|
|||||||
|
|
||||||
class ConfigWidget(QWidget, 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)
|
QWidget.__init__(self)
|
||||||
Ui_ConfigWidget.__init__(self)
|
Ui_ConfigWidget.__init__(self)
|
||||||
self.setupUi(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_up, SIGNAL('clicked()'), self.up_column)
|
||||||
self.connect(self.column_down, SIGNAL('clicked()'), self.down_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):
|
def up_column(self):
|
||||||
idx = self.columns.currentRow()
|
idx = self.columns.currentRow()
|
||||||
if idx > 0:
|
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]
|
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
|
return formats
|
||||||
|
|
||||||
|
def use_subdirs(self):
|
||||||
|
return self.opt_use_subdirs.isChecked()
|
||||||
|
|
||||||
|
def read_metadata(self):
|
||||||
|
return self.opt_read_metadata.isChecked()
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../gui2/images.qrc">
|
<iconset resource="../images.qrc">
|
||||||
<normaloff>:/images/arrow-up.svg</normaloff>:/images/arrow-up.svg</iconset>
|
<normaloff>:/images/arrow-up.svg</normaloff>:/images/arrow-up.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -64,7 +64,7 @@
|
|||||||
<string>...</string>
|
<string>...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../gui2/images.qrc">
|
<iconset resource="../images.qrc">
|
||||||
<normaloff>:/images/arrow-down.svg</normaloff>:/images/arrow-down.svg</iconset>
|
<normaloff>:/images/arrow-down.svg</normaloff>:/images/arrow-down.svg</iconset>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
@ -73,13 +73,27 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</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>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../gui2/images.qrc"/>
|
<include location="../images.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user