From f826dcd050ae262aaef1aa7d6a75188515f54b67 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Mon, 29 Nov 2010 22:14:23 -0400 Subject: [PATCH 1/5] Fix deleting txt documents --- src/calibre/devices/kobo/driver.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 0eddf26549..ebb3f60101 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -220,6 +220,7 @@ class KOBO(USBMS): # 2) volume_shorcover # 2) content +# 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,) @@ -400,6 +401,9 @@ class KOBO(USBMS): elif extension == '.pdf' or extension == '.epub': # print "ePub or pdf" ContentType = 16 + elif extension == '.txt': + # print "txt" + ContentType = 901 else: # if extension == '.html' or extension == '.txt': ContentType = 999 # Yet another hack: to get around Kobo changing how ContentID is stored return ContentType From 26aef9cc53b91b2c94d096597adc435e2bf5f823 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 29 Nov 2010 20:17:33 -0700 Subject: [PATCH 2/5] Conversion pipeline: Do not override CSS for images with the value of the img width/height attributes, unless no CSS is specified for the image --- src/calibre/ebooks/oeb/stylizer.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/calibre/ebooks/oeb/stylizer.py b/src/calibre/ebooks/oeb/stylizer.py index d10ea12394..4f8ae68943 100644 --- a/src/calibre/ebooks/oeb/stylizer.py +++ b/src/calibre/ebooks/oeb/stylizer.py @@ -240,18 +240,26 @@ class Stylizer(object): else: for elem in matches: self.style(elem)._update_cssdict(cssdict) - for elem in xpath(tree, '//h:img[@width or @height]'): - base = elem.get('style', '').strip() - if base: - base += ';' - for prop in ('width', 'height'): - val = elem.get(prop, False) - if val: - base += '%s: %s;'%(prop, val) - del elem.attrib[prop] - elem.set('style', base) for elem in xpath(tree, '//h:*[@style]'): self.style(elem)._apply_style_attr() + num_pat = re.compile(r'\d+$') + for elem in xpath(tree, '//h:img[@width or @height]'): + style = self.style(elem) + # Check if either height or width is not default + is_styled = style._style.get('width', 'auto') != 'auto' or \ + style._style.get('height', 'auto') != 'auto' + if not is_styled: + # Update img style dimension using width and height + upd = {} + for prop in ('width', 'height'): + val = elem.get(prop, '').strip() + del elem.attrib[prop] + if val: + if num_pat.match(val) is not None: + val += 'px' + upd[prop] = val + if upd: + style._update_cssdict(upd) def _fetch_css_file(self, path): hrefs = self.oeb.manifest.hrefs From a5d7a19c341326d3359798a724ed4e4d1de1d916 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Mon, 29 Nov 2010 23:24:31 -0400 Subject: [PATCH 3/5] Allow html, htm and rtf documents to be deleted --- src/calibre/devices/kobo/driver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index ebb3f60101..981bf3decb 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -401,7 +401,7 @@ class KOBO(USBMS): elif extension == '.pdf' or extension == '.epub': # print "ePub or pdf" ContentType = 16 - elif extension == '.txt': + elif extension == '.rtf' or extension == '.txt' or extension == '.htm' or extension == '.html': # print "txt" ContentType = 901 else: # if extension == '.html' or extension == '.txt': From 8a6e316e9fdcfd36c61b9a52a8a65c5ac6d0e1a2 Mon Sep 17 00:00:00 2001 From: Timothy Legge Date: Mon, 29 Nov 2010 23:51:55 -0400 Subject: [PATCH 4/5] Fix the deletion of html, htm, txt and rtf by firmware version --- src/calibre/devices/kobo/driver.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 981bf3decb..b76ee4b1c3 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -79,11 +79,11 @@ class KOBO(USBMS): # Determine the firmware version f = open(self.normalize_path(self._main_prefix + '.kobo/version'), 'r') - fwversion = f.readline().split(',')[2] + self.fwversion = f.readline().split(',')[2] f.close() - if fwversion != '1.0' and fwversion != '1.4': + if self.fwversion != '1.0' and self.fwversion != '1.4': self.has_kepubs = True - debug_print('Version of firmware: ', fwversion, 'Has kepubs:', self.has_kepubs) + debug_print('Version of firmware: ', self.fwversion, 'Has kepubs:', self.has_kepubs) self.booklist_class.rebuild_collections = self.rebuild_collections @@ -220,7 +220,7 @@ class KOBO(USBMS): # 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,) @@ -403,7 +403,10 @@ class KOBO(USBMS): ContentType = 16 elif extension == '.rtf' or extension == '.txt' or extension == '.htm' or extension == '.html': # print "txt" - ContentType = 901 + if self.fwversion == '1.0' or self.fwversion == '1.4' or self.fwversion == '1.7.4': + ContentType = 999 + else: + ContentType = 901 else: # if extension == '.html' or extension == '.txt': ContentType = 999 # Yet another hack: to get around Kobo changing how ContentID is stored return ContentType From 549b73e248e0ec3a38b64843b0d2feb8d97de2d6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 29 Nov 2010 21:10:36 -0700 Subject: [PATCH 5/5] Force overwrite title/author metadata to True when downloading metadata for books added by ISBN --- src/calibre/gui2/actions/add.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/actions/add.py b/src/calibre/gui2/actions/add.py index 5cc72c3ff0..9b348d8285 100644 --- a/src/calibre/gui2/actions/add.py +++ b/src/calibre/gui2/actions/add.py @@ -18,6 +18,7 @@ from calibre.ebooks import BOOK_EXTENSIONS from calibre.utils.filenames import ascii_filename from calibre.constants import preferred_encoding, filesystem_encoding from calibre.gui2.actions import InterfaceAction +from calibre.gui2 import config class AddAction(InterfaceAction): @@ -101,7 +102,12 @@ class AddAction(InterfaceAction): else: ids.add(db.import_book(mi, [])) self.gui.library_view.model().books_added(len(books)) - self.gui.iactions['Edit Metadata'].do_download_metadata(ids) + orig = config['overwrite_author_title_metadata'] + config['overwrite_author_title_metadata'] = True + try: + self.gui.iactions['Edit Metadata'].do_download_metadata(ids) + finally: + config['overwrite_author_title_metadata'] = orig def files_dropped(self, paths):