diff --git a/src/calibre/customize/profiles.py b/src/calibre/customize/profiles.py
index 44628c22db..bebaebced6 100644
--- a/src/calibre/customize/profiles.py
+++ b/src/calibre/customize/profiles.py
@@ -583,6 +583,7 @@ class CybookG3Output(OutputProfile):
# Screen size is a best guess
screen_size = (600, 800)
+ comic_screen_size = (600, 757)
dpi = 168.451
fbase = 16
fsizes = [12, 12, 14, 16, 18, 20, 22, 24]
diff --git a/src/calibre/ebooks/conversion/utils.py b/src/calibre/ebooks/conversion/utils.py
index 7882d82d47..ad2214fcb5 100644
--- a/src/calibre/ebooks/conversion/utils.py
+++ b/src/calibre/ebooks/conversion/utils.py
@@ -155,7 +155,7 @@ class HeuristicProcessor(object):
]
for word in ITALICIZE_WORDS:
- html = re.sub(r'(?<=\s|>)' + word + r'(?=\s|<)', '%s' % word, html)
+ html = re.sub(r'(?<=\s|>)' + re.escape(word) + r'(?=\s|<)', '%s' % word, html)
for pat in ITALICIZE_STYLE_PATS:
html = re.sub(pat, lambda mo: '%s' % mo.group('words'), html)
diff --git a/src/calibre/ebooks/txt/output.py b/src/calibre/ebooks/txt/output.py
index 29b3d899bc..b73a6e8908 100644
--- a/src/calibre/ebooks/txt/output.py
+++ b/src/calibre/ebooks/txt/output.py
@@ -8,7 +8,6 @@ import os
from calibre.customize.conversion import OutputFormatPlugin, \
OptionRecommendation
-from calibre.ebooks.txt.markdownml import MarkdownMLizer
from calibre.ebooks.txt.txtml import TXTMLizer
from calibre.ebooks.txt.newlines import TxtNewlines, specified_newlines
@@ -44,24 +43,32 @@ class TXTOutput(OutputFormatPlugin):
recommended_value=False, level=OptionRecommendation.LOW,
help=_('Force splitting on the max-line-length value when no space '
'is present. Also allows max-line-length to be below the minimum')),
- OptionRecommendation(name='markdown_format',
- recommended_value=False, level=OptionRecommendation.LOW,
- help=_('Produce Markdown formatted text.')),
+ OptionRecommendation(name='txt_output_formatting',
+ recommended_value='plain',
+ choices=['plain', 'markdown', 'textile'],
+ help=_('Formatting used within the document.\n'
+ '* plain: Produce plain text.\n'
+ '* markdown: Produce Markdown formatted text.\n'
+ '* textile: Produce Textile formatted text.')),
OptionRecommendation(name='keep_links',
recommended_value=False, level=OptionRecommendation.LOW,
help=_('Do not remove links within the document. This is only ' \
- 'useful when paired with the markdown-format option because' \
- ' links are always removed with plain text output.')),
+ 'useful when paired with a txt-output-formatting option that '
+ 'is not none because links are always removed with plain text output.')),
OptionRecommendation(name='keep_image_references',
recommended_value=False, level=OptionRecommendation.LOW,
help=_('Do not remove image references within the document. This is only ' \
- 'useful when paired with the markdown-format option because' \
- ' image references are always removed with plain text output.')),
+ 'useful when paired with a txt-output-formatting option that '
+ 'is not none because links are always removed with plain text output.')),
])
def convert(self, oeb_book, output_path, input_plugin, opts, log):
- if opts.markdown_format:
+ if opts.txt_output_formatting.lower() == 'markdown':
+ from calibre.ebooks.txt.markdownml import MarkdownMLizer
writer = MarkdownMLizer(log)
+ elif opts.txt_output_formatting.lower() == 'textile':
+ from calibre.ebooks.txt.textileml import TextileMLizer
+ writer = TextileMLizer(log)
else:
writer = TXTMLizer(log)
diff --git a/src/calibre/ebooks/txt/textileml.py b/src/calibre/ebooks/txt/textileml.py
new file mode 100644
index 0000000000..94834d8e79
--- /dev/null
+++ b/src/calibre/ebooks/txt/textileml.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+
+__license__ = 'GPL 3'
+__copyright__ = '2011, John Schember '
+__docformat__ = 'restructuredtext en'
+
+'''
+Transform OEB content into Textile formatted plain text
+'''
+
+import re
+
+from lxml import etree
+
+from calibre.ebooks.oeb.base import XHTML
+from calibre.utils.html2textile import html2textile
+
+class TextileMLizer(object):
+
+ def __init__(self, log):
+ self.log = log
+
+ def extract_content(self, oeb_book, opts):
+ self.log.info('Converting XHTML to Textile formatted TXT...')
+ self.oeb_book = oeb_book
+ self.opts = opts
+
+ return self.mlize_spine()
+
+ def mlize_spine(self):
+ output = [u'']
+
+ for item in self.oeb_book.spine:
+ self.log.debug('Converting %s to Textile formatted TXT...' % item.href)
+
+ html = unicode(etree.tostring(item.data.find(XHTML('body')), encoding=unicode))
+
+ if not self.opts.keep_links:
+ html = re.sub(r'<\s*a[^>]*>', '', html)
+ html = re.sub(r'<\s*/\s*a\s*>', '', html)
+ if not self.opts.keep_image_references:
+ html = re.sub(r'<\s*img[^>]*>', '', html)
+ html = re.sub(r'<\s*img\s*>', '', html)
+
+ text = html2textile(html)
+
+ # Ensure the section ends with at least two new line characters.
+ # This is to prevent the last paragraph from a section being
+ # combined into the fist paragraph of the next.
+ end_chars = text[-4:]
+ # Convert all newlines to \n
+ end_chars = end_chars.replace('\r\n', '\n')
+ end_chars = end_chars.replace('\r', '\n')
+ end_chars = end_chars[-2:]
+ if not end_chars[1] == '\n':
+ text += '\n\n'
+ if end_chars[1] == '\n' and not end_chars[0] == '\n':
+ text += '\n'
+
+ output += text
+
+ output = u''.join(output)
+
+ return output
diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py
index a8f80ab35a..9150172fc1 100644
--- a/src/calibre/gui2/__init__.py
+++ b/src/calibre/gui2/__init__.py
@@ -120,6 +120,8 @@ def _config():
help='Search history for the LRF viewer')
c.add_opt('scheduler_search_history', default=[],
help='Search history for the recipe scheduler')
+ c.add_opt('plugin_search_history', default=[],
+ help='Search history for the recipe scheduler')
c.add_opt('worker_limit', default=6,
help=_('Maximum number of waiting worker processes'))
c.add_opt('get_social_metadata', default=True,
@@ -138,6 +140,7 @@ def _config():
help=_('Show the average rating per item indication in the tag browser'))
c.add_opt('disable_animations', default=False,
help=_('Disable UI animations'))
+ c.add_opt
return ConfigProxy(c)
config = _config()
@@ -197,14 +200,10 @@ def error_dialog(parent, title, msg, det_msg='', show=False,
return d.exec_()
return d
-def question_dialog(parent, title, msg, det_msg='', show_copy_button=False,
- buttons=None, yes_button=None):
+def question_dialog(parent, title, msg, det_msg='', show_copy_button=False):
from calibre.gui2.dialogs.message_box import MessageBox
d = MessageBox(MessageBox.QUESTION, title, msg, det_msg, parent=parent,
show_copy_button=show_copy_button)
- if buttons is not None:
- d.bb.setStandardButtons(buttons)
-
return d.exec_() == d.Accepted
def info_dialog(parent, title, msg, det_msg='', show=False,
diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py
index fd20d88049..7034380a56 100644
--- a/src/calibre/gui2/actions/choose_library.py
+++ b/src/calibre/gui2/actions/choose_library.py
@@ -16,7 +16,6 @@ from calibre.utils.config import prefs
from calibre.gui2 import gprefs, warning_dialog, Dispatcher, error_dialog, \
question_dialog, info_dialog
from calibre.gui2.actions import InterfaceAction
-from calibre.gui2.dialogs.check_library import CheckLibraryDialog, DBCheck
class LibraryUsageStats(object): # {{{
@@ -139,6 +138,12 @@ class ChooseLibraryAction(InterfaceAction):
None, None), attr='action_check_library')
ac.triggered.connect(self.check_library, type=Qt.QueuedConnection)
self.maintenance_menu.addAction(ac)
+ ac = self.create_action(spec=(_('Restore database'), 'lt.png',
+ None, None),
+ attr='action_restore_database')
+ ac.triggered.connect(self.restore_database, type=Qt.QueuedConnection)
+ self.maintenance_menu.addAction(ac)
+
self.choose_menu.addMenu(self.maintenance_menu)
def pick_random(self, *args):
@@ -267,7 +272,17 @@ class ChooseLibraryAction(InterfaceAction):
_('Metadata will be backed up while calibre is running, at the '
'rate of approximately 1 book every three seconds.'), show=True)
+ def restore_database(self):
+ from calibre.gui2.dialogs.restore_library import restore_database
+ m = self.gui.library_view.model()
+ m.stop_metadata_backup()
+ db = m.db
+ db.prefs.disable_setting = True
+ if restore_database(db, self.gui):
+ self.gui.library_moved(db.library_path, call_close=False)
+
def check_library(self):
+ from calibre.gui2.dialogs.check_library import CheckLibraryDialog, DBCheck
self.gui.library_view.save_state()
m = self.gui.library_view.model()
m.stop_metadata_backup()
diff --git a/src/calibre/gui2/convert/txt_output.py b/src/calibre/gui2/convert/txt_output.py
index 0e6a6b9574..33ed64cef1 100644
--- a/src/calibre/gui2/convert/txt_output.py
+++ b/src/calibre/gui2/convert/txt_output.py
@@ -4,7 +4,6 @@ __license__ = 'GPL 3'
__copyright__ = '2009, John Schember '
__docformat__ = 'restructuredtext en'
-from PyQt4.Qt import Qt
from calibre.gui2.convert.txt_output_ui import Ui_Form
from calibre.gui2.convert import Widget
@@ -21,26 +20,14 @@ class PluginWidget(Widget, Ui_Form):
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent,
['newline', 'max_line_length', 'force_max_line_length',
- 'inline_toc', 'markdown_format', 'keep_links', 'keep_image_references',
+ 'inline_toc', 'txt_output_formatting', 'keep_links', 'keep_image_references',
'txt_output_encoding'])
self.db, self.book_id = db, book_id
for x in get_option('newline').option.choices:
self.opt_newline.addItem(x)
+ for x in get_option('txt_output_formatting').option.choices:
+ self.opt_txt_output_formatting.addItem(x)
self.initialize_options(get_option, get_help, db, book_id)
- self.opt_markdown_format.stateChanged.connect(self.enable_markdown_format)
- self.enable_markdown_format(self.opt_markdown_format.checkState())
-
def break_cycles(self):
Widget.break_cycles(self)
-
- try:
- self.opt_markdown_format.stateChanged.disconnect()
- except:
- pass
-
- def enable_markdown_format(self, state):
- state = state == Qt.Checked
- self.opt_keep_links.setEnabled(state)
- self.opt_keep_image_references.setEnabled(state)
-
diff --git a/src/calibre/gui2/convert/txt_output.ui b/src/calibre/gui2/convert/txt_output.ui
index 57fe702db7..1ef9e6e6b9 100644
--- a/src/calibre/gui2/convert/txt_output.ui
+++ b/src/calibre/gui2/convert/txt_output.ui
@@ -6,100 +6,123 @@
0
0
- 477
- 300
+ 392
+ 346
Form
-
- -
-
-
- &Line ending style:
-
-
- opt_newline
+
+
-
+
+
+ General
+
+
-
+
+
+ Output &Encoding:
+
+
+ opt_txt_output_encoding
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ &Line ending style:
+
+
+ opt_newline
+
+
+
+ -
+
+
+ -
+
+
+ &Formatting:
+
+
+ opt_txt_output_formatting
+
+
+
+ -
+
+
+
- -
-
-
- -
-
-
- Qt::Vertical
-
-
-
- 20
- 246
-
-
-
-
- -
-
-
- &Inline TOC
+
-
+
+
+ Plain
+
+
-
+
+
+ &Maximum line length:
+
+
+ opt_max_line_length
+
+
+
+ -
+
+
+ -
+
+
+ Force maximum line length
+
+
+
+ -
+
+
+ &Inline TOC
+
+
+
+
- -
-
-
- -
-
-
- &Maximum line length:
-
-
- opt_max_line_length
-
-
-
- -
-
-
- Force maximum line length
-
-
-
- -
-
-
- Apply Markdown formatting to text
-
-
-
- -
-
-
- Do not remove links (<a> tags) before processing
-
-
-
- -
-
-
- Do not remove image references before processing
-
-
-
- -
-
-
- Output Encoding:
-
-
-
- -
-
-
- true
+
-
+
+
+ Markdown, Textile
+
+
-
+
+
+ Do not remove links (<a> tags) before processing
+
+
+
+ -
+
+
+ Do not remove image references before processing
+
+
+
+
diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py
index 5df69442eb..1cf0fa5d67 100644
--- a/src/calibre/gui2/device.py
+++ b/src/calibre/gui2/device.py
@@ -7,7 +7,7 @@ import os, traceback, Queue, time, cStringIO, re, sys
from threading import Thread
from PyQt4.Qt import QMenu, QAction, QActionGroup, QIcon, SIGNAL, \
- Qt, pyqtSignal, QDialog, QMessageBox
+ Qt, pyqtSignal, QDialog
from calibre.customize.ui import available_input_formats, available_output_formats, \
device_plugins
@@ -609,10 +609,8 @@ class DeviceMixin(object): # {{{
autos = u'\n'.join(map(unicode, map(force_unicode, autos)))
return self.ask_a_yes_no_question(
_('No suitable formats'), msg,
- buttons=QMessageBox.Yes|QMessageBox.Cancel,
ans_when_user_unavailable=True,
- det_msg=autos,
- show_copy_button=False
+ det_msg=autos
)
def set_default_thumbnail(self, height):
diff --git a/src/calibre/gui2/dialogs/check_library.py b/src/calibre/gui2/dialogs/check_library.py
index bd665a7e2e..b6b15d8be8 100644
--- a/src/calibre/gui2/dialogs/check_library.py
+++ b/src/calibre/gui2/dialogs/check_library.py
@@ -74,21 +74,27 @@ class DBCheck(QDialog):
self.reject()
def start_load(self):
- self.conn.close()
- self.pb.setMaximum(self.count)
- self.pb.setValue(0)
- self.msg.setText(_('Loading database from SQL'))
- self.db.conn.close()
- self.ndbpath = PersistentTemporaryFile('.db')
- self.ndbpath.close()
- self.ndbpath = self.ndbpath.name
- t = DBThread(self.ndbpath, False)
- t.connect()
- self.conn = t.conn
- self.conn.execute('create temporary table temp_sequence(id INTEGER PRIMARY KEY AUTOINCREMENT)')
- self.conn.commit()
+ try:
+ self.conn.close()
+ self.pb.setMaximum(self.count)
+ self.pb.setValue(0)
+ self.msg.setText(_('Loading database from SQL'))
+ self.db.conn.close()
+ self.ndbpath = PersistentTemporaryFile('.db')
+ self.ndbpath.close()
+ self.ndbpath = self.ndbpath.name
+ t = DBThread(self.ndbpath, False)
+ t.connect()
+ self.conn = t.conn
+ self.conn.execute('create temporary table temp_sequence(id INTEGER PRIMARY KEY AUTOINCREMENT)')
+ self.conn.commit()
+
+ QTimer.singleShot(0, self.do_one_load)
+ except Exception, e:
+ import traceback
+ self.error = (as_unicode(e), traceback.format_exc())
+ self.reject()
- QTimer.singleShot(0, self.do_one_load)
def do_one_load(self):
if self.rejected:
diff --git a/src/calibre/gui2/dialogs/message_box.py b/src/calibre/gui2/dialogs/message_box.py
index 45ab73f8a1..565fb147fc 100644
--- a/src/calibre/gui2/dialogs/message_box.py
+++ b/src/calibre/gui2/dialogs/message_box.py
@@ -92,7 +92,10 @@ class MessageBox(QDialog, Ui_Dialog):
def showEvent(self, ev):
ret = QDialog.showEvent(self, ev)
if self.is_question:
- self.bb.button(self.bb.Yes).setFocus(Qt.OtherFocusReason)
+ try:
+ self.bb.button(self.bb.Yes).setFocus(Qt.OtherFocusReason)
+ except:
+ pass# Buttons were changed
else:
self.bb.button(self.bb.Ok).setFocus(Qt.OtherFocusReason)
return ret
diff --git a/src/calibre/gui2/dialogs/metadata_bulk.py b/src/calibre/gui2/dialogs/metadata_bulk.py
index cf4252e9ed..533a344de5 100644
--- a/src/calibre/gui2/dialogs/metadata_bulk.py
+++ b/src/calibre/gui2/dialogs/metadata_bulk.py
@@ -7,7 +7,7 @@ import re, os
from PyQt4.Qt import Qt, QDialog, QGridLayout, QVBoxLayout, QFont, QLabel, \
pyqtSignal, QDialogButtonBox, QInputDialog, QLineEdit, \
- QMessageBox, QDate
+ QDate
from calibre.gui2.dialogs.metadata_bulk_ui import Ui_MetadataBulkDialog
from calibre.gui2.dialogs.tag_editor import TagEditor
@@ -15,7 +15,8 @@ from calibre.ebooks.metadata import string_to_authors, authors_to_string
from calibre.ebooks.metadata.book.base import composite_formatter
from calibre.ebooks.metadata.meta import get_metadata
from calibre.gui2.custom_column_widgets import populate_metadata_page
-from calibre.gui2 import error_dialog, ResizableDialog, UNDEFINED_QDATE, gprefs
+from calibre.gui2 import error_dialog, ResizableDialog, UNDEFINED_QDATE, \
+ gprefs, question_dialog
from calibre.gui2.progress_indicator import ProgressIndicator
from calibre.utils.config import dynamic, JSONConfig
from calibre.utils.titlecase import titlecase
@@ -888,12 +889,9 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog):
if self.query_field.currentIndex() == 0:
return
- ret = QMessageBox.question(self, _("Delete saved search/replace"),
+ if not question_dialog(self, _("Delete saved search/replace"),
_("The selected saved search/replace will be deleted. "
- "Are you sure?"),
- QMessageBox.Ok, QMessageBox.Cancel)
-
- if ret == QMessageBox.Cancel:
+ "Are you sure?")):
return
item_id = self.query_field.currentIndex()
@@ -917,11 +915,9 @@ class MetadataBulkDialog(ResizableDialog, Ui_MetadataBulkDialog):
new = True
name = unicode(name)
if name in self.queries.keys():
- ret = QMessageBox.question(self, _("Save search/replace"),
+ if not question_dialog(self, _("Save search/replace"),
_("That saved search/replace already exists and will be overwritten. "
- "Are you sure?"),
- QMessageBox.Ok, QMessageBox.Cancel)
- if ret == QMessageBox.Cancel:
+ "Are you sure?")):
return
new = False
diff --git a/src/calibre/gui2/dialogs/metadata_single.py b/src/calibre/gui2/dialogs/metadata_single.py
index 9156ef7101..7a8e4ea8d0 100644
--- a/src/calibre/gui2/dialogs/metadata_single.py
+++ b/src/calibre/gui2/dialogs/metadata_single.py
@@ -11,7 +11,7 @@ from functools import partial
from threading import Thread
from PyQt4.Qt import SIGNAL, QObject, Qt, QTimer, QDate, \
- QPixmap, QListWidgetItem, QDialog, pyqtSignal, QMessageBox, QIcon, \
+ QPixmap, QListWidgetItem, QDialog, pyqtSignal, QIcon, \
QPushButton
from calibre.gui2 import error_dialog, file_icon_provider, dynamic, \
@@ -770,9 +770,7 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
if question_dialog(self, _('Tags changed'),
_('You have changed the tags. In order to use the tags'
' editor, you must either discard or apply these '
- 'changes'), show_copy_button=False,
- buttons=QMessageBox.Apply|QMessageBox.Discard,
- yes_button=QMessageBox.Apply):
+ 'changes. Apply changes?'), show_copy_button=False):
self.apply_tags(commit=True, notify=True)
self.original_tags = unicode(self.tags.text())
else:
diff --git a/src/calibre/gui2/dialogs/restore_library.py b/src/calibre/gui2/dialogs/restore_library.py
new file mode 100644
index 0000000000..dd1befc11b
--- /dev/null
+++ b/src/calibre/gui2/dialogs/restore_library.py
@@ -0,0 +1,115 @@
+#!/usr/bin/env python
+# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
+
+__license__ = 'GPL v3'
+__copyright__ = '2011, Kovid Goyal '
+__docformat__ = 'restructuredtext en'
+
+from PyQt4.Qt import QDialog, QLabel, QVBoxLayout, QDialogButtonBox, \
+ QProgressBar, QSize, QTimer, pyqtSignal, Qt
+
+from calibre.library.restore import Restore
+from calibre.gui2 import error_dialog, question_dialog, warning_dialog, \
+ info_dialog
+
+class DBRestore(QDialog):
+
+ update_signal = pyqtSignal(object, object)
+
+ def __init__(self, parent, library_path):
+ QDialog.__init__(self, parent)
+ self.l = QVBoxLayout()
+ self.setLayout(self.l)
+ self.l1 = QLabel(''+_('Restoring database from backups, do not'
+ ' interrupt, this will happen in two stages')+'...')
+ self.setWindowTitle(_('Restoring database'))
+ self.l.addWidget(self.l1)
+ self.pb = QProgressBar(self)
+ self.l.addWidget(self.pb)
+ self.pb.setMaximum(0)
+ self.pb.setMinimum(0)
+ self.msg = QLabel('')
+ self.l.addWidget(self.msg)
+ self.msg.setWordWrap(True)
+ self.bb = QDialogButtonBox(QDialogButtonBox.Cancel)
+ self.l.addWidget(self.bb)
+ self.bb.rejected.connect(self.reject)
+ self.resize(self.sizeHint() + QSize(100, 50))
+ self.error = None
+ self.rejected = False
+ self.library_path = library_path
+ self.update_signal.connect(self.do_update, type=Qt.QueuedConnection)
+
+ self.restorer = Restore(library_path, self)
+ self.restorer.daemon = True
+
+ # Give the metadata backup thread time to stop
+ QTimer.singleShot(2000, self.start)
+
+
+ def start(self):
+ self.restorer.start()
+ QTimer.singleShot(10, self.update)
+
+ def reject(self):
+ self.rejected = True
+ self.restorer.progress_callback = lambda x, y: x
+ QDialog.rejecet(self)
+
+ def update(self):
+ if self.restorer.is_alive():
+ QTimer.singleShot(10, self.update)
+ else:
+ self.restorer.progress_callback = lambda x, y: x
+ self.accept()
+
+ def __call__(self, msg, step):
+ self.update_signal.emit(msg, step)
+
+ def do_update(self, msg, step):
+ if msg is None:
+ self.pb.setMaximum(step)
+ else:
+ self.msg.setText(msg)
+ self.pb.setValue(step)
+
+
+def restore_database(db, parent=None):
+ if not question_dialog(parent, _('Are you sure?'), ''+
+ _('Your list of books, with all their metadata is '
+ 'stored in a single file, called a database. '
+ 'In addition, metadata for each individual '
+ 'book is stored in that books\' folder, as '
+ 'a backup.'
+ '
This operation will rebuild '
+ 'the database from the individual book '
+ 'metadata. This is useful if the '
+ 'database has been corrupted and you get a '
+ 'blank list of books. Note that restoring only '
+ 'restores books, not any settings stored in the '
+ 'database, or any custom recipes.'
+ '
Do you want to restore the database?')):
+ return False
+ db.conn.close()
+ d = DBRestore(parent, db.library_path)
+ d.exec_()
+ r = d.restorer
+ d.restorer = None
+ if d.rejected:
+ return True
+ if r.tb is not None:
+ error_dialog(parent, _('Failed'),
+ _('Restoring database failed, click Show details to see details'),
+ det_msg=r.tb, show=True)
+ else:
+ if r.errors_occurred:
+ warning_dialog(parent, _('Success'),
+ _('Restoring the database succeeded with some warnings',
+ ' click Show details to see the details.'),
+ det_msg=r.report, show=True)
+ else:
+ info_dialog(parent, _('Success'),
+ _('Restoring database was successful'), show=True,
+ show_copy_button=False)
+ return True
+
diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py
index b88b1d680d..976b679726 100644
--- a/src/calibre/gui2/main.py
+++ b/src/calibre/gui2/main.py
@@ -4,7 +4,7 @@ __copyright__ = '2008, Kovid Goyal '
import sys, os, time, socket, traceback
from functools import partial
-from PyQt4.Qt import QCoreApplication, QIcon, QMessageBox, QObject, QTimer, \
+from PyQt4.Qt import QCoreApplication, QIcon, QObject, QTimer, \
QThread, pyqtSignal, Qt, QProgressDialog, QString, QPixmap, \
QSplashScreen, QApplication
@@ -319,9 +319,6 @@ def run_gui(opts, args, actions, listener, app, gui_debug=None):
def cant_start(msg=_('If you are sure it is not running')+', ',
what=None):
- d = QMessageBox(QMessageBox.Critical, _('Cannot Start ')+__appname__,
- ''+(_('%s is already running.')%__appname__)+'
',
- QMessageBox.Ok)
base = '%s
%s %s'
where = __appname__ + ' '+_('may be running in the system tray, in the')+' '
if isosx:
@@ -334,8 +331,10 @@ def cant_start(msg=_('If you are sure it is not running')+', ',
else:
what = _('try deleting the file')+': '+ADDRESS
- d.setInformativeText(base%(where, msg, what))
- d.exec_()
+ info = base%(where, msg, what)
+ error_dialog(None, _('Cannot Start ')+__appname__,
+ '
'+(_('%s is already running.')%__appname__)+'
'+info, show=True)
+
raise SystemExit(1)
def communicate(args):
diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py
index dc85bad012..590a8be3bb 100644
--- a/src/calibre/gui2/metadata/basic_widgets.py
+++ b/src/calibre/gui2/metadata/basic_widgets.py
@@ -10,7 +10,7 @@ import textwrap, re, os
from PyQt4.Qt import Qt, QDateEdit, QDate, \
QIcon, QToolButton, QWidget, QLabel, QGridLayout, \
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, \
- QPushButton, QSpinBox, QMessageBox, QLineEdit
+ QPushButton, QSpinBox, QLineEdit
from calibre.gui2.widgets import EnLineEdit, CompleteComboBox, \
EnComboBox, FormatList, ImageView, CompleteLineEdit
@@ -848,9 +848,7 @@ class TagsEdit(CompleteLineEdit): # {{{
if question_dialog(self, _('Tags changed'),
_('You have changed the tags. In order to use the tags'
' editor, you must either discard or apply these '
- 'changes'), show_copy_button=False,
- buttons=QMessageBox.Apply|QMessageBox.Discard,
- yes_button=QMessageBox.Apply):
+ 'changes. Apply changes?'), show_copy_button=False):
self.commit(db, id_)
db.commit()
self.original_val = self.current_val
diff --git a/src/calibre/gui2/preferences/plugins.py b/src/calibre/gui2/preferences/plugins.py
index ba5b921d44..1edd4fe5f9 100644
--- a/src/calibre/gui2/preferences/plugins.py
+++ b/src/calibre/gui2/preferences/plugins.py
@@ -17,11 +17,14 @@ from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin
remove_plugin
from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files, \
question_dialog
+from calibre.utils.search_query_parser import SearchQueryParser
+from calibre.utils.icu import lower
-class PluginModel(QAbstractItemModel): # {{{
+class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{
def __init__(self, *args):
QAbstractItemModel.__init__(self, *args)
+ SearchQueryParser.__init__(self, ['all'])
self.icon = QVariant(QIcon(I('plugins.png')))
p = QIcon(self.icon).pixmap(32, 32, QIcon.Disabled, QIcon.On)
self.disabled_icon = QVariant(QIcon(p))
@@ -40,6 +43,72 @@ class PluginModel(QAbstractItemModel): # {{{
for plugins in self._data.values():
plugins.sort(cmp=lambda x, y: cmp(x.name.lower(), y.name.lower()))
+ def universal_set(self):
+ ans = set([])
+ for c, category in enumerate(self.categories):
+ ans.add((c, -1))
+ for p, plugin in enumerate(self._data[category]):
+ ans.add((c, p))
+ return ans
+
+ def get_matches(self, location, query, candidates=None):
+ if candidates is None:
+ candidates = self.universal_set()
+ ans = set([])
+ if not query:
+ return ans
+ query = lower(query)
+ for c, p in candidates:
+ if p < 0:
+ if query in lower(self.categories[c]):
+ ans.add((c, p))
+ else:
+ try:
+ plugin = self._data[self.categories[c]][p]
+ except:
+ continue
+ if query in lower(plugin.name) or query in lower(plugin.author) or \
+ query in lower(plugin.description):
+ ans.add((c, p))
+ return ans
+
+ def find(self, query):
+ query = query.strip()
+ matches = self.parse(query)
+ if not matches:
+ return QModelIndex()
+ matches = list(sorted(matches))
+ c, p = matches[0]
+ cat_idx = self.index(c, 0, QModelIndex())
+ if p == -1:
+ return cat_idx
+ return self.index(p, 0, cat_idx)
+
+ def find_next(self, idx, query, backwards=False):
+ query = query.strip()
+ matches = self.parse(query)
+ if not matches:
+ return idx
+ if idx.parent().isValid():
+ loc = (idx.parent().row(), idx.row())
+ else:
+ loc = (idx.row(), -1)
+ if loc not in matches:
+ return self.find(query)
+ if len(matches) == 1:
+ return QModelIndex()
+ matches = list(sorted(matches))
+ i = matches.index(loc)
+ if backwards:
+ ans = i - 1 if i - 1 >= 0 else len(matches)-1
+ else:
+ ans = i + 1 if i + 1 < len(matches) else 0
+
+ ans = matches[ans]
+
+ return self.index(ans[0], 0, QModelIndex()) if ans[1] < 0 else \
+ self.index(ans[1], 0, self.index(ans[0], 0, QModelIndex()))
+
def index(self, row, column, parent):
if not self.hasIndex(row, column, parent):
return QModelIndex()
@@ -127,6 +196,7 @@ class PluginModel(QAbstractItemModel): # {{{
return plugin
return NONE
+
# }}}
class ConfigWidget(ConfigWidgetBase, Ui_Form):
@@ -144,6 +214,42 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.customize_plugin_button.clicked.connect(self.customize_plugin)
self.remove_plugin_button.clicked.connect(self.remove_plugin)
self.button_plugin_add.clicked.connect(self.add_plugin)
+ self.search.initialize('plugin_search_history',
+ help_text=_('Search for plugin'))
+ self.search.search.connect(self.find)
+ self.next_button.clicked.connect(self.find_next)
+ self.previous_button.clicked.connect(self.find_previous)
+
+ def find(self, query):
+ idx = self._plugin_model.find(query)
+ if not idx.isValid():
+ return info_dialog(self, _('No matches'),
+ _('Could not find any matching plugins'), show=True,
+ show_copy_button=False)
+ self.highlight_index(idx)
+
+ def highlight_index(self, idx):
+ self.plugin_view.scrollTo(idx)
+ self.plugin_view.selectionModel().select(idx,
+ self.plugin_view.selectionModel().ClearAndSelect)
+ self.plugin_view.setCurrentIndex(idx)
+
+ def find_next(self, *args):
+ idx = self.plugin_view.currentIndex()
+ if not idx.isValid():
+ idx = self._plugin_model.index(0, 0)
+ idx = self._plugin_model.find_next(idx,
+ unicode(self.search.currentText()))
+ self.highlight_index(idx)
+
+ def find_previous(self, *args):
+ idx = self.plugin_view.currentIndex()
+ if not idx.isValid():
+ idx = self._plugin_model.index(0, 0)
+ idx = self._plugin_model.find_next(idx,
+ unicode(self.search.currentText()), backwards=True)
+ self.highlight_index(idx)
+
def toggle_plugin(self, *args):
self.modify_plugin(op='toggle')
@@ -184,13 +290,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
show=True, show_copy_button=False)
idx = self._plugin_model.plugin_to_index_by_properties(plugin)
if idx.isValid():
- self.plugin_view.scrollTo(idx,
- self.plugin_view.PositionAtCenter)
- self.plugin_view.scrollTo(idx,
- self.plugin_view.PositionAtCenter)
- self.plugin_view.selectionModel().select(idx,
- self.plugin_view.selectionModel().ClearAndSelect)
- self.plugin_view.setCurrentIndex(idx)
+ self.highlight_index(idx)
else:
error_dialog(self, _('No valid plugin path'),
_('%s is not a valid plugin path')%path).exec_()
diff --git a/src/calibre/gui2/preferences/plugins.ui b/src/calibre/gui2/preferences/plugins.ui
index 83a904eb08..ebf422dfe3 100644
--- a/src/calibre/gui2/preferences/plugins.ui
+++ b/src/calibre/gui2/preferences/plugins.ui
@@ -24,6 +24,47 @@
+ -
+
+
-
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ &Next
+
+
+
+ :/images/arrow-down.png:/images/arrow-down.png
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ &Previous
+
+
+
+ :/images/arrow-up.png:/images/arrow-up.png
+
+
+
+
+
-
@@ -84,6 +125,13 @@
+
+
+ SearchBox2
+ QComboBox
+ calibre/gui2/search_box.h
+
+
diff --git a/src/calibre/gui2/tools.py b/src/calibre/gui2/tools.py
index 50c384b24c..655c7ea7c6 100644
--- a/src/calibre/gui2/tools.py
+++ b/src/calibre/gui2/tools.py
@@ -275,7 +275,7 @@ def generate_catalog(parent, dbspec, ids, device_manager, db):
if device_manager.is_device_connected:
device = device_manager.device
- connected_device['name'] = device.gui_name
+ connected_device['name'] = device.get_gui_name()
try:
storage = []
if device._main_prefix:
diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py
index d6d6b7fd01..907dd577b8 100644
--- a/src/calibre/gui2/ui.py
+++ b/src/calibre/gui2/ui.py
@@ -12,11 +12,9 @@ __docformat__ = 'restructuredtext en'
import collections, os, sys, textwrap, time
from Queue import Queue, Empty
from threading import Thread
-from PyQt4.Qt import Qt, SIGNAL, QTimer, \
- QPixmap, QMenu, QIcon, pyqtSignal, \
- QDialog, \
- QSystemTrayIcon, QApplication, QKeySequence, \
- QMessageBox, QHelpEvent, QAction
+from PyQt4.Qt import Qt, SIGNAL, QTimer, QHelpEvent, QAction, \
+ QMenu, QIcon, pyqtSignal, \
+ QDialog, QSystemTrayIcon, QApplication, QKeySequence
from calibre import prints
from calibre.constants import __appname__, isosx
@@ -357,11 +355,12 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
def is_minimized_to_tray(self):
return getattr(self, '__systray_minimized', False)
- def ask_a_yes_no_question(self, title, msg, **kwargs):
- awu = kwargs.pop('ans_when_user_unavailable', True)
+ def ask_a_yes_no_question(self, title, msg, det_msg='',
+ show_copy_button=False, ans_when_user_unavailable=True):
if self.is_minimized_to_tray:
- return awu
- return question_dialog(self, title, msg, **kwargs)
+ return ans_when_user_unavailable
+ return question_dialog(self, title, msg, det_msg=det_msg,
+ show_copy_button=show_copy_button)
def hide_windows(self):
for window in QApplication.topLevelWidgets():
@@ -601,11 +600,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
Quitting may cause corruption on the device.
Are you sure you want to quit?''')+'
'
- d = QMessageBox(QMessageBox.Warning, _('WARNING: Active jobs'), msg,
- QMessageBox.Yes|QMessageBox.No, self)
- d.setIconPixmap(QPixmap(I('dialog_warning.png')))
- d.setDefaultButton(QMessageBox.No)
- if d.exec_() != QMessageBox.Yes:
+ if not question_dialog(self, _('Active jobs'), msg):
return False
return True
diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py
index 3e4687be95..a18def29de 100644
--- a/src/calibre/library/server/browse.py
+++ b/src/calibre/library/server/browse.py
@@ -356,9 +356,9 @@ class BrowseServer(object):
if category in category_icon_map:
icon = category_icon_map[category]
elif meta['is_custom']:
- icon = category_icon_map[':custom']
+ icon = category_icon_map['custom:']
elif meta['kind'] == 'user':
- icon = category_icon_map[':user']
+ icon = category_icon_map['user:']
else:
icon = 'blank.png'
cats.append((meta['name'], category, icon))
diff --git a/src/calibre/utils/html2textile.py b/src/calibre/utils/html2textile.py
new file mode 100644
index 0000000000..82797a81ad
--- /dev/null
+++ b/src/calibre/utils/html2textile.py
@@ -0,0 +1,209 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2010, Webreactor - Marcin Lulek
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# * Neither the name of the nor the
+# names of its contributors may be used to endorse or promote products
+# derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+from lxml import etree
+from calibre.ebooks.oeb.base import barename
+
+class EchoTarget:
+
+ def __init__(self):
+ self.final_output = []
+ self.block = False
+ self.ol_ident = 0
+ self.ul_ident = 0
+ self.list_types = []
+ self.haystack = []
+
+ def start(self, tag, attrib):
+ tag = barename(tag)
+
+ newline = '\n'
+ dot = ''
+ new_tag = ''
+
+ if tag in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6'):
+ new_tag = tag
+ dot = '. '
+ elif tag == 'p':
+ new_tag = ''
+ dot = ''
+ elif tag == 'blockquote':
+ new_tag = 'bq'
+ dot = '. '
+ elif tag in ('b', 'strong'):
+ new_tag = '*'
+ newline = ''
+ elif tag in ('em', 'i'):
+ new_tag = '_'
+ newline = ''
+ elif tag == 'cite':
+ new_tag = '??'
+ newline = ''
+ elif tag == 'del':
+ new_tag = '-'
+ newline = ''
+ elif tag == 'ins':
+ new_tag = '+'
+ newline = ''
+ elif tag == 'sup':
+ new_tag = '^'
+ newline = ''
+ elif tag == 'sub':
+ new_tag = '~'
+ newline = ''
+ elif tag == 'span':
+ new_tag = '%'
+ newline = ''
+ elif tag == 'a':
+ self.block = True
+ if 'title' in attrib:
+ self.a_part = {'title':attrib.get('title'),
+ 'href':attrib.get('href', '')}
+ else:
+ self.a_part = {'title':None, 'href':attrib.get('href', '')}
+ new_tag = ''
+ newline = ''
+
+ elif tag == 'img':
+ if 'alt' in attrib:
+ new_tag = ' !%s(%s)' % (attrib.get('src'), attrib.get('title'),)
+ else:
+ new_tag = ' !%s' % attrib.get('src')
+ newline = ''
+
+ elif tag in ('ul', 'ol'):
+ new_tag = ''
+ newline = ''
+ self.list_types.append(tag)
+ if tag == 'ul':
+ self.ul_ident += 1
+ else:
+ self.ol_ident += 1
+
+ elif tag == 'li':
+ indent = self.ul_ident + self.ol_ident
+ if self.list_types[-1] == 'ul':
+ new_tag = '*' * indent + ' '
+ newline = '\n'
+ else:
+ new_tag = '#' * indent + ' '
+ newline = '\n'
+
+
+ if tag not in ('ul', 'ol'):
+ textile = '%(newline)s%(tag)s%(dot)s' % \
+ {
+ 'newline':newline,
+ 'tag':new_tag,
+ 'dot':dot
+ }
+ if not self.block:
+ self.final_output.append(textile)
+ else:
+ self.haystack.append(textile)
+
+ def end(self, tag):
+ tag = barename(tag)
+
+ if tag in ('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p'):
+ self.final_output.append('\n')
+ elif tag in ('b', 'strong'):
+ self.final_output.append('*')
+ elif tag in ('em', 'i'):
+ self.final_output.append('_')
+ elif tag == 'cite':
+ self.final_output.append('??')
+ elif tag == 'del':
+ self.final_output.append('-')
+ elif tag == 'ins':
+ self.final_output.append('+')
+ elif tag == 'sup':
+ self.final_output.append('^')
+ elif tag == 'sub':
+ self.final_output.append('~')
+ elif tag == 'span':
+ self.final_output.append('%')
+ elif tag == 'a':
+ if self.a_part['title']:
+ textilized = ' "%s (%s)":%s ' % (
+ ''.join(self.haystack),
+ self.a_part.get('title'),
+ self.a_part.get('href'),
+ )
+ self.haystack = []
+ else:
+ textilized = ' "%s":%s ' % (
+ ''.join(self.haystack),
+ self.a_part.get('href'),
+ )
+ self.haystack = []
+ self.final_output.append(textilized)
+ self.block = False
+ elif tag == 'img':
+ self.final_output.append('!')
+ elif tag == 'ul':
+ self.ul_ident -= 1
+ self.list_types.pop()
+ if len(self.list_types) == 0:
+ self.final_output.append('\n')
+ elif tag == 'ol':
+ self.ol_ident -= 1
+ self.list_types.pop()
+ if len(self.list_types) == 0:
+ self.final_output.append('\n')
+
+ def data(self, data):
+ #we dont want any linebreaks inside our tags
+ node_data = data.replace('\n','')
+ if not self.block:
+ self.final_output.append(node_data)
+ else:
+ self.haystack.append(node_data)
+
+ def comment(self, text):
+ pass
+
+ def close(self):
+ return "closed!"
+
+
+def html2textile(html):
+ #1st pass
+ #clean the whitespace and convert html to xhtml
+ parser = etree.HTMLParser()
+ tree = etree.fromstring(html, parser)
+ xhtml = etree.tostring(tree, method="xml")
+ parser = etree.XMLParser(remove_blank_text=True)
+ root = etree.XML(xhtml, parser)
+ cleaned_html = etree.tostring(root)
+ #2nd pass build textile
+ target = EchoTarget()
+ parser = etree.XMLParser(target=target)
+ root = etree.fromstring(cleaned_html, parser)
+ textilized_text = ''.join(target.final_output).lstrip().rstrip()
+ return textilized_text
diff --git a/src/calibre/utils/search_query_parser.py b/src/calibre/utils/search_query_parser.py
index 4e4da9d1df..a50ca20fc1 100644
--- a/src/calibre/utils/search_query_parser.py
+++ b/src/calibre/utils/search_query_parser.py
@@ -260,12 +260,12 @@ class SearchQueryParser(object):
'''
Should return the set of matches for :param:'location` and :param:`query`.
- The search must be performed over all entries is :param:`candidates` is
+ The search must be performed over all entries if :param:`candidates` is
None otherwise only over the items in candidates.
:param:`location` is one of the items in :member:`SearchQueryParser.DEFAULT_LOCATIONS`.
:param:`query` is a string literal.
- :param: None or a subset of the set returned by :meth:`universal_set`.
+ :return: None or a subset of the set returned by :meth:`universal_set`.
'''
return set([])