mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 22:43:31 +02:00
Device driver customization: Allow user to tell calibre to send any ebook format to the device rather than just the list of formats that calibre thinks the device will support
This commit is contained in:
parent
f1348401c3
commit
8c5dbd7641
7 changed files with 37 additions and 10 deletions
|
|
@ -39,6 +39,7 @@
|
|||
class DriverBase(DeviceConfig, DevicePlugin):
|
||||
# Needed for config_widget to work
|
||||
FORMATS = ['epub', 'pdf']
|
||||
USER_CAN_ADD_NEW_FORMATS = False
|
||||
SUPPORTS_SUB_DIRS = True # To enable second checkbox in customize widget
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class BAMBOOK(DeviceConfig, DevicePlugin):
|
|||
ip = None
|
||||
|
||||
FORMATS = [ "snb" ]
|
||||
USER_CAN_ADD_NEW_FORMATS = False
|
||||
VENDOR_ID = 0x230b
|
||||
PRODUCT_ID = 0x0001
|
||||
BCD = None
|
||||
|
|
@ -421,7 +422,7 @@ def config_widget(cls):
|
|||
from calibre.gui2.device_drivers.configwidget import ConfigWidget
|
||||
cw = ConfigWidget(cls.settings(), cls.FORMATS, cls.SUPPORTS_SUB_DIRS,
|
||||
cls.MUST_READ_METADATA, cls.SUPPORTS_USE_AUTHOR_SORT,
|
||||
cls.EXTRA_CUSTOMIZATION_MESSAGE)
|
||||
cls.EXTRA_CUSTOMIZATION_MESSAGE, cls)
|
||||
# Turn off the Save template
|
||||
cw.opt_save_template.setVisible(False)
|
||||
cw.label.setVisible(False)
|
||||
|
|
|
|||
|
|
@ -98,7 +98,6 @@ def books(self, oncard=None, end_session=True):
|
|||
|
||||
def update_booklist(prefix, path, title, authors, mime, date, ContentType, ImageID, readstatus, MimeType):
|
||||
changed = False
|
||||
# if path_to_ext(path) in self.FORMATS:
|
||||
try:
|
||||
lpath = path.partition(self.normalize_path(prefix))[2]
|
||||
if lpath.startswith(os.sep):
|
||||
|
|
@ -220,7 +219,7 @@ def delete_via_sql(self, ContentID, ContentType):
|
|||
# 2) volume_shorcover
|
||||
# 2) content
|
||||
|
||||
debug_print('delete_via_sql: ContentID: ', ContentID, 'ContentType: ', ContentType)
|
||||
debug_print('delete_via_sql: ContentID: ', ContentID, 'ContentType: ', ContentType)
|
||||
connection = sqlite.connect(self.normalize_path(self._main_prefix + '.kobo/KoboReader.sqlite'))
|
||||
cursor = connection.cursor()
|
||||
t = (ContentID,)
|
||||
|
|
@ -532,7 +531,7 @@ def update_device_database_collections(self, booklists, collections_attributes,
|
|||
if result is None:
|
||||
datelastread = '1970-01-01T00:00:00'
|
||||
else:
|
||||
datelastread = result[0] if result[0] is not None else '1970-01-01T00:00:00'
|
||||
datelastread = result[0] if result[0] is not None else '1970-01-01T00:00:00'
|
||||
|
||||
t = (datelastread,ContentID,)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ class DeviceConfig(object):
|
|||
#: If None the default is used
|
||||
SAVE_TEMPLATE = None
|
||||
|
||||
#: If True the user can add new formats to the driver
|
||||
USER_CAN_ADD_NEW_FORMATS = True
|
||||
|
||||
|
||||
@classmethod
|
||||
def _default_save_template(cls):
|
||||
from calibre.library.save_to_disk import config
|
||||
|
|
@ -73,7 +77,7 @@ def config_widget(cls):
|
|||
from calibre.gui2.device_drivers.configwidget import ConfigWidget
|
||||
cw = ConfigWidget(cls.settings(), cls.FORMATS, cls.SUPPORTS_SUB_DIRS,
|
||||
cls.MUST_READ_METADATA, cls.SUPPORTS_USE_AUTHOR_SORT,
|
||||
cls.EXTRA_CUSTOMIZATION_MESSAGE)
|
||||
cls.EXTRA_CUSTOMIZATION_MESSAGE, cls)
|
||||
return cw
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -93,9 +93,11 @@ def books(self, oncard=None, end_session=True):
|
|||
for idx,b in enumerate(bl):
|
||||
bl_cache[b.lpath] = idx
|
||||
|
||||
all_formats = set(self.settings().format_map) | set(self.FORMATS)
|
||||
|
||||
def update_booklist(filename, path, prefix):
|
||||
changed = False
|
||||
if path_to_ext(filename) in self.FORMATS:
|
||||
if path_to_ext(filename) in all_formats:
|
||||
try:
|
||||
lpath = os.path.join(path, filename).partition(self.normalize_path(prefix))[2]
|
||||
if lpath.startswith(os.sep):
|
||||
|
|
|
|||
|
|
@ -204,7 +204,8 @@ def add_books(self, *args):
|
|||
]
|
||||
to_device = self.gui.stack.currentIndex() != 0
|
||||
if to_device:
|
||||
filters = [(_('Supported books'), self.gui.device_manager.device.FORMATS)]
|
||||
fmts = self.gui.device_manager.device.settings().format_map
|
||||
filters = [(_('Supported books'), fmts)]
|
||||
|
||||
books = choose_files(self.gui, 'add books dialog dir', 'Select books',
|
||||
filters=filters)
|
||||
|
|
|
|||
|
|
@ -9,15 +9,16 @@
|
|||
from PyQt4.Qt import QWidget, QListWidgetItem, Qt, QVariant, SIGNAL, \
|
||||
QLabel, QLineEdit, QCheckBox
|
||||
|
||||
from calibre.gui2 import error_dialog
|
||||
from calibre.gui2 import error_dialog, question_dialog
|
||||
from calibre.gui2.device_drivers.configwidget_ui import Ui_ConfigWidget
|
||||
from calibre.utils.formatter import validation_formatter
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
|
||||
class ConfigWidget(QWidget, Ui_ConfigWidget):
|
||||
|
||||
def __init__(self, settings, all_formats, supports_subdirs,
|
||||
must_read_metadata, supports_use_author_sort,
|
||||
extra_customization_message):
|
||||
extra_customization_message, device):
|
||||
|
||||
QWidget.__init__(self)
|
||||
Ui_ConfigWidget.__init__(self)
|
||||
|
|
@ -25,9 +26,15 @@ def __init__(self, settings, all_formats, supports_subdirs,
|
|||
|
||||
self.settings = settings
|
||||
|
||||
all_formats = set(all_formats)
|
||||
self.calibre_known_formats = device.FORMATS
|
||||
self.device_name = device.get_gui_name()
|
||||
if device.USER_CAN_ADD_NEW_FORMATS:
|
||||
all_formats = set(all_formats) | set(BOOK_EXTENSIONS)
|
||||
|
||||
format_map = settings.format_map
|
||||
disabled_formats = list(set(all_formats).difference(format_map))
|
||||
for format in format_map + disabled_formats:
|
||||
for format in format_map + list(sorted(disabled_formats)):
|
||||
item = QListWidgetItem(format, self.columns)
|
||||
item.setData(Qt.UserRole, QVariant(format))
|
||||
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable)
|
||||
|
|
@ -110,6 +117,18 @@ def use_author_sort(self):
|
|||
return self.opt_use_author_sort.isChecked()
|
||||
|
||||
def validate(self):
|
||||
formats = set(self.format_map())
|
||||
extra = formats - set(self.calibre_known_formats)
|
||||
if extra:
|
||||
fmts = sorted([x.upper() for x in extra])
|
||||
if not question_dialog(self, _('Unknown formats'),
|
||||
_('You have enabled the <b>{0}</b> formats for'
|
||||
' your {1}. The {1} may not support them.'
|
||||
' If you send these formats to your {1} they '
|
||||
'may not work. Are you sure?').format(
|
||||
(', '.join(fmts)), self.device_name)):
|
||||
return False
|
||||
|
||||
tmpl = unicode(self.opt_save_template.text())
|
||||
try:
|
||||
validation_formatter.validate(tmpl)
|
||||
|
|
|
|||
Loading…
Reference in a new issue