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 #: long time
OPEN_FEEDBACK_MESSAGE = None 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 @classmethod
def get_gui_name(cls): def get_gui_name(cls):
if hasattr(cls, 'gui_name'): if hasattr(cls, 'gui_name'):

View File

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

View File

@ -430,6 +430,20 @@ class AddAction(object): # {{{
d.exec_() d.exec_()
return return
paths = [p for p in view._model.paths(rows) if p is not None] 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: if not paths or len(paths) == 0:
d = error_dialog(self, _('Add to library'), _('No book files found')) d = error_dialog(self, _('Add to library'), _('No book files found'))
d.exec_() d.exec_()
@ -830,7 +844,7 @@ class EditMetadataAction(object): # {{{
dest_mi.series = src_mi.series dest_mi.series = src_mi.series
dest_mi.series_index = src_mi.series_index dest_mi.series_index = src_mi.series_index
db.set_metadata(dest_id, dest_mi, ignore_errors=False) db.set_metadata(dest_id, dest_mi, ignore_errors=False)
for key in db.field_metadata: #loop thru all defined fields for key in db.field_metadata: #loop thru all defined fields
if db.field_metadata[key]['is_custom']: if db.field_metadata[key]['is_custom']:
colnum = db.field_metadata[key]['colnum'] colnum = db.field_metadata[key]['colnum']
@ -841,12 +855,12 @@ class EditMetadataAction(object): # {{{
dest_value = db.get_custom(dest_id, num=colnum, index_is_id=True) dest_value = db.get_custom(dest_id, num=colnum, index_is_id=True)
src_value = db.get_custom(src_id, num=colnum, index_is_id=True) src_value = db.get_custom(src_id, num=colnum, index_is_id=True)
if db.field_metadata[key]['datatype'] == 'comments': if db.field_metadata[key]['datatype'] == 'comments':
if src_value and src_value != orig_dest_value: if src_value and src_value != orig_dest_value:
if not dest_value: if not dest_value:
db.set_custom(dest_id, src_value, num=colnum) db.set_custom(dest_id, src_value, num=colnum)
else: else:
dest_value = unicode(dest_value) + u'\n\n' + unicode(src_value) dest_value = unicode(dest_value) + u'\n\n' + unicode(src_value)
db.set_custom(dest_id, dest_value, num=colnum) db.set_custom(dest_id, dest_value, num=colnum)
if db.field_metadata[key]['datatype'] in \ if db.field_metadata[key]['datatype'] in \
('bool', 'int', 'float', 'rating', 'datetime') \ ('bool', 'int', 'float', 'rating', 'datetime') \
and not dest_value: and not dest_value:
@ -861,7 +875,7 @@ class EditMetadataAction(object): # {{{
and not dest_value: and not dest_value:
db.set_custom(dest_id, src_value, num=colnum) db.set_custom(dest_id, src_value, num=colnum)
if db.field_metadata[key]['datatype'] == 'text' \ if db.field_metadata[key]['datatype'] == 'text' \
and db.field_metadata[key]['is_multiple']: and db.field_metadata[key]['is_multiple']:
if src_value: if src_value:
if not dest_value: if not dest_value:
dest_value = src_value dest_value = src_value