Properly hande user trying to add .kobo books to calibre from device

This commit is contained in:
Kovid Goyal 2010-08-01 09:21:19 -06:00
parent b0b904fbf1
commit 9bd69f1437
3 changed files with 29 additions and 8 deletions

View File

@ -52,6 +52,11 @@ class DevicePlugin(Plugin):
#: long time
OPEN_FEEDBACK_MESSAGE = None
#: Set of extensions that are "virtual books" on the device
#: and therefore cannot be viewed/saved/added to library
#: For example: ``frozenset(['kobo'])``
VIRTUAL_BOOK_EXTENSIONS = frozenset([])
@classmethod
def get_gui_name(cls):
if hasattr(cls, 'gui_name'):

View File

@ -38,6 +38,8 @@ class KOBO(USBMS):
EBOOK_DIR_MAIN = ''
SUPPORTS_SUB_DIRS = True
VIRTUAL_BOOK_EXTENSIONS = frozenset(['kobo'])
def initialize(self):
USBMS.initialize(self)
self.book_class = Book

View File

@ -430,6 +430,20 @@ class AddAction(object): # {{{
d.exec_()
return
paths = [p for p in view._model.paths(rows) if p is not None]
ve = self.device_manager.device.VIRTUAL_BOOK_EXTENSIONS
def ext(x):
ans = os.path.splitext(x)[1]
ans = ans[1:] if len(ans) > 1 else ans
return ans.lower()
remove = set([p for p in paths if ext(p) in ve])
if remove:
paths = [p for p in paths if p not in remove]
info_dialog(self, _('Not Implemented'),
_('The following books are virtual and cannot be added'
' to the calibre library:'), '\n'.join(remove),
show=True)
if not paths:
return
if not paths or len(paths) == 0:
d = error_dialog(self, _('Add to library'), _('No book files found'))
d.exec_()