Integrat patch from bug #910279.

This commit is contained in:
John Schember 2011-12-30 20:58:49 -05:00
parent 4cb752881f
commit 02b8659639

View File

@ -284,11 +284,11 @@ class KINDLE(USBMS):
class KINDLE2(KINDLE): class KINDLE2(KINDLE):
name = 'Kindle 2/3 Device Interface' name = 'Kindle 2/3/4 Device Interface'
description = _('Communicate with the Kindle 2/3 eBook reader.') description = _('Communicate with the Kindle 2/3/4 eBook reader.')
FORMATS = KINDLE.FORMATS + ['pdf', 'azw4', 'pobi'] FORMATS = KINDLE.FORMATS + ['pdf', 'azw4', 'pobi']
DELETE_EXTS = KINDLE.DELETE_EXTS DELETE_EXTS = KINDLE.DELETE_EXTS + ['.mbp1', '.mbs']
PRODUCT_ID = [0x0002, 0x0004] PRODUCT_ID = [0x0002, 0x0004]
BCD = [0x0100] BCD = [0x0100]
@ -307,13 +307,18 @@ class KINDLE2(KINDLE):
'generator will produce pages that correspond better to a printed book. ' 'generator will produce pages that correspond better to a printed book. '
'However, this method is slower and will slow down sending files ' 'However, this method is slower and will slow down sending files '
'to the Kindle.'), 'to the Kindle.'),
_('Use the sidecar (.sdr) folder for the page number file (Kindle 4)') +
':::' +
_('Enable this for the Kindle 4 Touch/Non Touch only. '),
] ]
EXTRA_CUSTOMIZATION_DEFAULT = [ EXTRA_CUSTOMIZATION_DEFAULT = [
True, True,
False, False,
False,
] ]
OPT_APNX = 0 OPT_APNX = 0
OPT_APNX_ACCURATE = 1 OPT_APNX_ACCURATE = 1
OPT_APNX_SIDECAR = 2
def books(self, oncard=None, end_session=True): def books(self, oncard=None, end_session=True):
bl = USBMS.books(self, oncard=oncard, end_session=end_session) bl = USBMS.books(self, oncard=oncard, end_session=end_session)
@ -347,6 +352,38 @@ class KINDLE2(KINDLE):
if h in path_map: if h in path_map:
book.device_collections = list(sorted(path_map[h])) book.device_collections = list(sorted(path_map[h]))
def delete_books(self, paths, end_session=True):
opts = self.settings()
for i, path in enumerate(paths):
self.report_progress((i+1) / float(len(paths)), _('Removing books from device...'))
path = self.normalize_path(path)
if os.path.exists(path):
# Delete the ebook
os.unlink(path)
filepath = os.path.splitext(path)[0]
if (opts.extra_customization[self.OPT_APNX_SIDECAR]):
filename = os.path.splitext(os.path.basename(path))[0]
sidecarpath = os.path.join(os.path.dirname(filepath), filename + ".sdr")
for ext in self.DELETE_EXTS:
if os.path.exists(filepath + ext):
os.unlink(filepath + ext)
if os.path.exists(path + ext):
os.unlink(path + ext)
if os.path.exists(os.path.join(sidecarpath, filename + ext)):
os.unlink(os.path.join(sidecarpath, filename + ext))
if self.SUPPORTS_SUB_DIRS:
try:
if (os.path.exists(sidecarpath)):
os.removedirs(sidecarpath)
os.removedirs(os.path.dirname(path))
except:
pass
self.report_progress(1.0, _('Removing books from device...'))
def upload_cover(self, path, filename, metadata, filepath): def upload_cover(self, path, filename, metadata, filepath):
''' '''
Hijacking this function to write the apnx file. Hijacking this function to write the apnx file.
@ -355,6 +392,12 @@ class KINDLE2(KINDLE):
if not opts.extra_customization[self.OPT_APNX]: if not opts.extra_customization[self.OPT_APNX]:
return return
if (opts.extra_customization[self.OPT_APNX_SIDECAR]):
path = os.path.join(os.path.dirname(filepath), filename+".sdr")
if not os.path.exists(path):
os.makedirs(path)
if os.path.splitext(filepath.lower())[1] not in ('.azw', '.mobi', '.prc'): if os.path.splitext(filepath.lower())[1] not in ('.azw', '.mobi', '.prc'):
return return