-
- btc = 1
- headline.extract()
- body.insert(1, headline)
- btc += 1
- if img:
- img.extract()
- body.insert(btc, img)
- btc += 1
- if caption:
- caption.extract()
- body.insert(btc, caption)
- btc += 1
-
- if len(imgs) > 1:
- if True:
- [img.extract() for img in imgs[1:]]
- else:
- # Format the remaining images
- # This doesn't work yet
- for img in imgs[1:]:
- print "img:\n%s\n" % img.prettify()
- divTag = Tag(soup, 'div')
- divTag['class'] = 'image'
-
- # Table for photo and credit
- tableTag = Tag(soup,'table')
-
- # Photo
- trimgTag = Tag(soup, 'tr')
- tdimgTag = Tag(soup, 'td')
- tdimgTag.insert(0,img)
- trimgTag.insert(0,tdimgTag)
- tableTag.insert(0,trimgTag)
-
- # Credit
- trcreditTag = Tag(soup, 'tr')
-
- tdcreditTag = Tag(soup, 'td')
- tdcreditTag['class'] = 'credit'
- try:
- tdcreditTag.insert(0,NavigableString(img['credit']))
- except:
- tdcreditTag.insert(0,NavigableString(''))
- trcreditTag.insert(0,tdcreditTag)
- tableTag.insert(1,trcreditTag)
- divTag.insert(0,tableTag)
- soup.img.replaceWith(divTag)
-
- return soup
-
- def postprocess_book(self, oeb, opts, log) :
-
- def extract_byline(href) :
- #
'' :
- return self.massageNCXText(self.tag_to_string(p,use_alt=False))
- else:
- print "Didn't find
in this soup:\n%s" % soup.prettify()
- return None
-
- # Method entry point here
- # Single section toc looks different than multi-section tocs
- if oeb.toc.depth() == 2 :
- for article in oeb.toc :
- if article.author is None :
- article.author = extract_byline(article.href)
- if article.description is None :
- article.description = extract_description(article.href)
- elif oeb.toc.depth() == 3 :
- for section in oeb.toc :
- for article in section :
- article.author = extract_byline(article.href)
- '''
- if article.author is None :
- article.author = self.massageNCXText(extract_byline(article.href))
- else:
- article.author = self.massageNCXText(article.author)
- '''
- if article.description is None :
- article.description = extract_description(article.href)
-
- def strip_anchors(self,soup):
- paras = soup.findAll(True)
- for para in paras:
- aTags = para.findAll('a')
- for a in aTags:
- if a.img is None:
- a.replaceWith(a.renderContents().decode('cp1252','replace'))
- return soup
diff --git a/src/calibre/ebooks/metadata/opf2.py b/src/calibre/ebooks/metadata/opf2.py
index 58c887bfdb..1d91236757 100644
--- a/src/calibre/ebooks/metadata/opf2.py
+++ b/src/calibre/ebooks/metadata/opf2.py
@@ -966,7 +966,9 @@ class OPF(object): # {{{
cover_id = covers[0].get('content')
for item in self.itermanifest():
if item.get('id', None) == cover_id:
- return item.get('href', None)
+ mt = item.get('media-type', '')
+ if 'xml' not in mt:
+ return item.get('href', None)
@dynamic_property
def cover(self):
diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py
index 4b262ad9dd..f6b19fc4aa 100644
--- a/src/calibre/gui2/actions/choose_library.py
+++ b/src/calibre/gui2/actions/choose_library.py
@@ -246,7 +246,7 @@ class ChooseLibraryAction(InterfaceAction):
def delete_requested(self, name, location):
loc = location.replace('/', os.sep)
if not question_dialog(self.gui, _('Are you sure?'), '
'+
- _('All files from %s will be '
+ _('All files from
%s
will be '
'permanently deleted. Are you sure?') % loc,
show_copy_button=False):
return
diff --git a/src/calibre/gui2/dialogs/tweak_epub.py b/src/calibre/gui2/dialogs/tweak_epub.py
index edc274c9b2..732d74b77d 100755
--- a/src/calibre/gui2/dialogs/tweak_epub.py
+++ b/src/calibre/gui2/dialogs/tweak_epub.py
@@ -7,16 +7,16 @@ __copyright__ = '2010, Kovid Goyal '
__docformat__ = 'restructuredtext en'
import os, shutil
-from contextlib import closing
from zipfile import ZipFile, ZIP_DEFLATED, ZIP_STORED
from PyQt4.Qt import QDialog
from calibre.constants import isosx
-from calibre.gui2 import open_local_file
+from calibre.gui2 import open_local_file, error_dialog
from calibre.gui2.dialogs.tweak_epub_ui import Ui_Dialog
from calibre.libunzip import extract as zipextract
-from calibre.ptempfile import PersistentTemporaryDirectory
+from calibre.ptempfile import (PersistentTemporaryDirectory,
+ PersistentTemporaryFile)
class TweakEpub(QDialog, Ui_Dialog):
'''
@@ -37,11 +37,15 @@ class TweakEpub(QDialog, Ui_Dialog):
self.cancel_button.clicked.connect(self.reject)
self.explode_button.clicked.connect(self.explode)
self.rebuild_button.clicked.connect(self.rebuild)
+ self.preview_button.clicked.connect(self.preview)
# Position update dialog overlaying top left of app window
parent_loc = parent.pos()
self.move(parent_loc.x(),parent_loc.y())
+ self.gui = parent
+ self._preview_files = []
+
def cleanup(self):
if isosx:
try:
@@ -55,6 +59,11 @@ class TweakEpub(QDialog, Ui_Dialog):
# Delete directory containing exploded ePub
if self._exploded is not None:
shutil.rmtree(self._exploded, ignore_errors=True)
+ for x in self._preview_files:
+ try:
+ os.remove(x)
+ except:
+ pass
def display_exploded(self):
'''
@@ -71,9 +80,8 @@ class TweakEpub(QDialog, Ui_Dialog):
self.rebuild_button.setEnabled(True)
self.explode_button.setEnabled(False)
- def rebuild(self, *args):
- self._output = os.path.join(self._exploded, 'rebuilt.epub')
- with closing(ZipFile(self._output, 'w', compression=ZIP_DEFLATED)) as zf:
+ def do_rebuild(self, src):
+ with ZipFile(src, 'w', compression=ZIP_DEFLATED) as zf:
# Write mimetype
zf.write(os.path.join(self._exploded,'mimetype'), 'mimetype', compress_type=ZIP_STORED)
# Write everything else
@@ -86,5 +94,23 @@ class TweakEpub(QDialog, Ui_Dialog):
zfn = os.path.relpath(absfn,
self._exploded).replace(os.sep, '/')
zf.write(absfn, zfn)
+
+ def preview(self):
+ if not self._exploded:
+ return error_dialog(self, _('Cannot preview'),
+ _('You must first explode the epub before previewing.'),
+ show=True)
+
+ tf = PersistentTemporaryFile('.epub')
+ tf.close()
+ self._preview_files.append(tf.name)
+
+ self.do_rebuild(tf.name)
+
+ self.gui.iactions['View']._view_file(tf.name)
+
+ def rebuild(self, *args):
+ self._output = os.path.join(self._exploded, 'rebuilt.epub')
+ self.do_rebuild(self._output)
return QDialog.accept(self)
diff --git a/src/calibre/gui2/dialogs/tweak_epub.ui b/src/calibre/gui2/dialogs/tweak_epub.ui
index fc6f24675f..a59af4fde1 100644
--- a/src/calibre/gui2/dialogs/tweak_epub.ui
+++ b/src/calibre/gui2/dialogs/tweak_epub.ui
@@ -23,6 +23,16 @@
false
+ -
+
+
+ <p>Explode the ePub to display contents in a file browser window. To tweak individual files, right-click, then 'Open with...' your editor of choice. When tweaks are complete, close the file browser window <b>and the editor windows you used to edit files in the epub</b>.</p><p>Rebuild the ePub, updating your calibre library.</p>
+
+
+ true
+
+
+
-
@@ -37,23 +47,6 @@
- -
-
-
- false
-
-
- Rebuild ePub from exploded contents
-
-
- &Rebuild ePub
-
-
-
- :/images/exec.png:/images/exec.png
-
-
-
-
@@ -68,13 +61,31 @@
- -
-
-
- <p>Explode the ePub to display contents in a file browser window. To tweak individual files, right-click, then 'Open with...' your editor of choice. When tweaks are complete, close the file browser window <b>and the editor windows you used to edit files in the epub</b>.</p><p>Rebuild the ePub, updating your calibre library.</p>
+
-
+
+
+ false
-
- true
+
+ Rebuild ePub from exploded contents
+
+
+ &Rebuild ePub
+
+
+
+ :/images/exec.png:/images/exec.png
+
+
+
+ -
+
+
+ &Preview ePub
+
+
+
+ :/images/view.png:/images/view.png
diff --git a/src/calibre/gui2/preferences/metadata_sources.py b/src/calibre/gui2/preferences/metadata_sources.py
index f487051d07..05ff23987d 100644
--- a/src/calibre/gui2/preferences/metadata_sources.py
+++ b/src/calibre/gui2/preferences/metadata_sources.py
@@ -190,7 +190,15 @@ class FieldsModel(QAbstractListModel): # {{{
return ans | Qt.ItemIsUserCheckable
def restore_defaults(self):
- self.overrides = dict([(f, self.state(f, True)) for f in self.fields])
+ self.overrides = dict([(f, self.state(f, Qt.Checked)) for f in self.fields])
+ self.reset()
+
+ def select_all(self):
+ self.overrides = dict([(f, Qt.Checked) for f in self.fields])
+ self.reset()
+
+ def clear_all(self):
+ self.overrides = dict([(f, Qt.Unchecked) for f in self.fields])
self.reset()
def setData(self, index, val, role):
@@ -273,6 +281,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.fields_view.setModel(self.fields_model)
self.fields_model.dataChanged.connect(self.changed_signal)
+ self.select_all_button.clicked.connect(self.fields_model.select_all)
+ self.clear_all_button.clicked.connect(self.fields_model.clear_all)
+
def configure_plugin(self):
for index in self.sources_view.selectionModel().selectedRows():
plugin = self.sources_model.data(index, Qt.UserRole)
diff --git a/src/calibre/gui2/preferences/metadata_sources.ui b/src/calibre/gui2/preferences/metadata_sources.ui
index e46069b036..ff161654dd 100644
--- a/src/calibre/gui2/preferences/metadata_sources.ui
+++ b/src/calibre/gui2/preferences/metadata_sources.ui
@@ -77,8 +77,8 @@
Downloaded metadata fields
-
- -
+
+
-
If you uncheck any fields, metadata for those fields will not be downloaded
@@ -88,6 +88,20 @@
+ -
+
+
+ &Select all
+
+
+
+ -
+
+
+ &Clear all
+
+
+
diff --git a/src/calibre/gui2/store/search/search.ui b/src/calibre/gui2/store/search/search.ui
index 7e8dd36284..fe5aaceda4 100644
--- a/src/calibre/gui2/store/search/search.ui
+++ b/src/calibre/gui2/store/search/search.ui
@@ -107,7 +107,7 @@
Open a selected book in the system's web browser
- Open external
+ Open in &external browser