constructs as the asinine epubchecker complains
diff --git a/src/calibre/ebooks/oeb/transforms/metadata.py b/src/calibre/ebooks/oeb/transforms/metadata.py
index 19c209b74d..f719ee3eb5 100644
--- a/src/calibre/ebooks/oeb/transforms/metadata.py
+++ b/src/calibre/ebooks/oeb/transforms/metadata.py
@@ -36,7 +36,7 @@ def meta_info_to_oeb_metadata(mi, m, log, override_input_metadata=False):
m.clear('description')
m.add('description', mi.comments)
elif override_input_metadata:
- m.clear('description')
+ m.clear('description')
if not mi.is_null('publisher'):
m.clear('publisher')
m.add('publisher', mi.publisher)
diff --git a/src/calibre/ebooks/rtf/rtfml.py b/src/calibre/ebooks/rtf/rtfml.py
index 97fa175d1a..f3febb1743 100644
--- a/src/calibre/ebooks/rtf/rtfml.py
+++ b/src/calibre/ebooks/rtf/rtfml.py
@@ -15,7 +15,6 @@ import cStringIO
from lxml import etree
from calibre.ebooks.metadata import authors_to_string
-from calibre.utils.filenames import ascii_text
from calibre.utils.magick.draw import save_cover_data_to, identify_data
TAGS = {
@@ -79,8 +78,7 @@ def txt2rtf(text):
elif val <= 127:
buf.write(x)
else:
- repl = ascii_text(x)
- c = r'\uc{2}\u{0:d}{1}'.format(val, repl, len(repl))
+ c = r'\u{0:d}?'.format(val)
buf.write(c)
return buf.getvalue()
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/layout.py b/src/calibre/gui2/layout.py
index b5cc0163ed..b3c9bd3a02 100644
--- a/src/calibre/gui2/layout.py
+++ b/src/calibre/gui2/layout.py
@@ -44,18 +44,19 @@ class LocationManager(QObject): # {{{
receiver = partial(self._location_selected, name)
ac.triggered.connect(receiver)
self.tooltips[name] = tooltip
+
+ m = QMenu(parent)
+ self._mem.append(m)
+ a = m.addAction(icon, tooltip)
+ a.triggered.connect(receiver)
if name != 'library':
- m = QMenu(parent)
- self._mem.append(m)
- a = m.addAction(icon, tooltip)
- a.triggered.connect(receiver)
self._mem.append(a)
a = m.addAction(QIcon(I('eject.png')), _('Eject this device'))
a.triggered.connect(self._eject_requested)
- ac.setMenu(m)
self._mem.append(a)
else:
ac.setToolTip(tooltip)
+ ac.setMenu(m)
ac.calibre_name = name
return ac
@@ -71,7 +72,12 @@ class LocationManager(QObject): # {{{
def set_switch_actions(self, quick_actions, rename_actions, delete_actions,
switch_actions, choose_action):
- self.switch_menu = QMenu()
+ self.switch_menu = self.library_action.menu()
+ if self.switch_menu:
+ self.switch_menu.addSeparator()
+ else:
+ self.switch_menu = QMenu()
+
self.switch_menu.addAction(choose_action)
self.cs_menus = []
for t, acs in [(_('Quick switch'), quick_actions),
@@ -85,7 +91,9 @@ class LocationManager(QObject): # {{{
self.switch_menu.addSeparator()
for ac in switch_actions:
self.switch_menu.addAction(ac)
- self.library_action.setMenu(self.switch_menu)
+
+ if self.switch_menu != self.library_action.menu():
+ self.library_action.setMenu(self.switch_menu)
def _location_selected(self, location, *args):
if location != self.current_location and hasattr(self,
diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py
index 26f6788a75..1cfb04921d 100644
--- a/src/calibre/gui2/library/views.py
+++ b/src/calibre/gui2/library/views.py
@@ -439,10 +439,16 @@ class BooksView(QTableView): # {{{
if tweaks['sort_columns_at_startup'] is not None:
sh = []
- for c,d in tweaks['sort_columns_at_startup']:
- if not isinstance(d, bool):
- d = True if d == 0 else False
- sh.append((c, d))
+ try:
+ for c,d in tweaks['sort_columns_at_startup']:
+ if not isinstance(d, bool):
+ d = True if d == 0 else False
+ sh.append((c, d))
+ except:
+ # Ignore invalid tweak values as users seem to often get them
+ # wrong
+ import traceback
+ traceback.print_exc()
old_state['sort_history'] = sh
self.apply_state(old_state)
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.py b/src/calibre/gui2/store/search/search.py
index 5654df8ffc..07d4afca54 100644
--- a/src/calibre/gui2/store/search/search.py
+++ b/src/calibre/gui2/store/search/search.py
@@ -155,6 +155,7 @@ class SearchDialog(QDialog, Ui_Dialog):
self.config['results_view_column_width'] = [self.results_view.columnWidth(i) for i in range(self.results_view.model().columnCount())]
self.config['sort_col'] = self.results_view.model().sort_col
self.config['sort_order'] = self.results_view.model().sort_order
+ self.config['open_external'] = self.open_external.isChecked()
store_check = {}
for n in self.store_plugins:
@@ -179,6 +180,8 @@ class SearchDialog(QDialog, Ui_Dialog):
else:
self.resize_columns()
+ self.open_external.setChecked(self.config.get('open_external', False))
+
store_check = self.config.get('store_checked', None)
if store_check:
for n in store_check:
@@ -212,7 +215,7 @@ class SearchDialog(QDialog, Ui_Dialog):
def open_store(self, index):
result = self.results_view.model().get_result(index)
- self.store_plugins[result.store_name].open(self, result.detail_item)
+ self.store_plugins[result.store_name].open(self, result.detail_item, self.open_external.isChecked())
def check_progress(self):
if not self.search_pool.threads_running() and not self.results_view.model().cover_pool.threads_running() and not self.results_view.model().details_pool.threads_running():
diff --git a/src/calibre/gui2/store/search/search.ui b/src/calibre/gui2/store/search/search.ui
index 0d39a70a29..fe5aaceda4 100644
--- a/src/calibre/gui2/store/search/search.ui
+++ b/src/calibre/gui2/store/search/search.ui
@@ -70,7 +70,7 @@
0
0
215
- 116
+ 93
@@ -101,6 +101,16 @@
+ -
+
+
+ Open a selected book in the system's web browser
+
+
+ Open in &external browser
+
+
+
diff --git a/src/odf/odf2xhtml.py b/src/odf/odf2xhtml.py
index 26da9d9905..a04aa48bf7 100644
--- a/src/odf/odf2xhtml.py
+++ b/src/odf/odf2xhtml.py
@@ -841,11 +841,19 @@ ol, ul { padding-left: 2em; }
self.styledict[name] = styles
# Write the styles to HTML
self.writeout(self.default_styles)
+ # Changed by Kovid to not write out endless copies of the same style
+ css_styles = {}
for name in self.stylestack:
styles = self.styledict.get(name)
- css2 = self.cs.convert_styles(styles)
- self.writeout("%s {\n" % name)
- for style, val in css2.items():
+ css2 = tuple(self.cs.convert_styles(styles).iteritems())
+ if css2 in css_styles:
+ css_styles[css2].append(name)
+ else:
+ css_styles[css2] = [name]
+
+ for css2, names in css_styles.iteritems():
+ self.writeout("%s {\n" % ', '.join(names))
+ for style, val in css2:
self.writeout("\t%s: %s;\n" % (style, val) )
self.writeout("}\n")