Merge from trunk

This commit is contained in:
Charles Haley 2011-04-11 14:16:36 +01:00
commit d894473de9
23 changed files with 1490 additions and 391 deletions

View File

@ -170,8 +170,8 @@ from setup import __appname__, __version__ as version
# there.
pot_header = '''\
# Translation template file..
# Copyright (C) 2007 Kovid Goyal
# Kovid Goyal <kovid@kovidgoyal.net>, 2007.
# Copyright (C) %(year)s Kovid Goyal
# Kovid Goyal <kovid@kovidgoyal.net>, %(year)s.
#
msgid ""
msgstr ""
@ -185,7 +185,7 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\\n"
"Generated-By: pygettext.py %%(version)s\\n"
'''%dict(appname=__appname__, version=version)
'''%dict(appname=__appname__, version=version, year=time.strftime('%Y'))
def usage(code, msg=''):

View File

@ -26,6 +26,38 @@ class POT(Command):
ans.append(os.path.abspath(os.path.join(root, name)))
return ans
def get_tweaks_docs(self):
path = self.a(self.j(self.SRC, '..', 'resources', 'default_tweaks.py'))
with open(path, 'rb') as f:
raw = f.read().decode('utf-8')
msgs = []
lines = list(raw.splitlines())
for i, line in enumerate(lines):
if line.startswith('#:'):
msgs.append((i, line[2:].strip()))
j = i
block = []
while True:
j += 1
line = lines[j]
if not line.startswith('#'):
break
block.append(line[1:].strip())
if block:
msgs.append((i+1, '\n'.join(block)))
ans = []
for lineno, msg in msgs:
ans.append('#: %s:%d'%(path, lineno))
slash = unichr(92)
msg = msg.replace(slash, slash*2).replace('"', r'\"').replace('\n',
r'\n').replace('\r', r'\r').replace('\t', r'\t')
ans.append('msgid "%s"'%msg)
ans.append('msgstr ""')
ans.append('')
return '\n'.join(ans)
def run(self, opts):
files = self.source_files()
@ -35,10 +67,10 @@ class POT(Command):
atexit.register(shutil.rmtree, tempdir)
pygettext(buf, ['-k', '__', '-p', tempdir]+files)
src = buf.getvalue()
src += '\n\n' + self.get_tweaks_docs()
pot = os.path.join(self.PATH, __appname__+'.pot')
f = open(pot, 'wb')
f.write(src)
f.close()
with open(pot, 'wb') as f:
f.write(src)
self.info('Translations template:', os.path.abspath(pot))
return pot

View File

@ -173,7 +173,7 @@ class ComicMetadataReader(MetadataReaderPlugin):
stream.seek(pos)
if id_ == b'Rar':
ftype = 'cbr'
elif id.startswith(b'PK'):
elif id_.startswith(b'PK'):
ftype = 'cbz'
if ftype == 'cbr':
from calibre.libunrar import extract_first_alphabetically as extract_first
@ -1038,6 +1038,17 @@ class Server(PreferencesPlugin):
'give you access to your calibre library from anywhere, '
'on any device, over the internet')
class MetadataSources(PreferencesPlugin):
name = 'Metadata download'
icon = I('metadata.png')
gui_name = _('Metadata download')
category = 'Sharing'
gui_category = _('Sharing')
category_order = 4
name_order = 3
config_widget = 'calibre.gui2.preferences.metadata_sources'
description = _('Control how calibre downloads ebook metadata from the net')
class Plugins(PreferencesPlugin):
name = 'Plugins'
icon = I('plugins.png')
@ -1076,6 +1087,9 @@ plugins += [LookAndFeel, Behavior, Columns, Toolbar, Search, InputOptions,
CommonOptions, OutputOptions, Adding, Saving, Sending, Plugboard,
Email, Server, Plugins, Tweaks, Misc, TemplateFunctions]
if test_eight_code:
plugins.append(MetadataSources)
#}}}

View File

@ -75,6 +75,17 @@ def enable_plugin(plugin_or_name):
ep.add(x)
config['enabled_plugins'] = ep
def restore_plugin_state_to_default(plugin_or_name):
x = getattr(plugin_or_name, 'name', plugin_or_name)
dp = config['disabled_plugins']
if x in dp:
dp.remove(x)
config['disabled_plugins'] = dp
ep = config['enabled_plugins']
if x in ep:
ep.remove(x)
config['enabled_plugins'] = ep
default_disabled_plugins = set([
'Douban Books', 'Douban.com covers', 'Nicebooks', 'Nicebooks covers',
'Kent District Library'

View File

@ -37,7 +37,7 @@ class ANDROID(USBMS):
0x22b8 : { 0x41d9 : [0x216], 0x2d61 : [0x100], 0x2d67 : [0x100],
0x41db : [0x216], 0x4285 : [0x216], 0x42a3 : [0x216],
0x4286 : [0x216], 0x42b3 : [0x216], 0x42b4 : [0x216],
0x7086 : [0x0226],
0x7086 : [0x0226], 0x70a8: [0x9999],
},
# Sony Ericsson
@ -96,7 +96,8 @@ class ANDROID(USBMS):
VENDOR_NAME = ['HTC', 'MOTOROLA', 'GOOGLE_', 'ANDROID', 'ACER',
'GT-I5700', 'SAMSUNG', 'DELL', 'LINUX', 'GOOGLE', 'ARCHOS',
'TELECHIP', 'HUAWEI', 'T-MOBILE', 'SEMC', 'LGE', 'NVIDIA']
'TELECHIP', 'HUAWEI', 'T-MOBILE', 'SEMC', 'LGE', 'NVIDIA',
'GENERIC-']
WINDOWS_MAIN_MEM = ['ANDROID_PHONE', 'A855', 'A853', 'INC.NEXUS_ONE',
'__UMS_COMPOSITE', '_MB200', 'MASS_STORAGE', '_-_CARD', 'SGH-I897',
'GT-I9000', 'FILE-STOR_GADGET', 'SGH-T959', 'SAMSUNG_ANDROID',
@ -104,7 +105,7 @@ class ANDROID(USBMS):
'SGH-T849', '_MB300', 'A70S', 'S_ANDROID', 'A101IT', 'A70H',
'IDEOS_TABLET', 'MYTOUCH_4G', 'UMS_COMPOSITE', 'SCH-I800_CARD',
'7', 'A956', 'A955', 'A43', 'ANDROID_PLATFORM', 'TEGRA_2',
'MB860']
'MB860', 'MULTI-CARD']
WINDOWS_CARD_A_MEM = ['ANDROID_PHONE', 'GT-I9000_CARD', 'SGH-I897',
'FILE-STOR_GADGET', 'SGH-T959', 'SAMSUNG_ANDROID', 'GT-P1000_CARD',
'A70S', 'A101IT', '7']

View File

@ -28,7 +28,7 @@ class FB2Output(OutputFormatPlugin):
'sf_horror', # Horror & mystic
'sf_humor', # Humor
'sf_fantasy', # Fantasy
'sf', # Science Fiction
'sf', # Science Fiction
# Detectives & Thrillers
'det_classic', # Classical detectives
'det_police', # Police Stories
@ -41,20 +41,20 @@ class FB2Output(OutputFormatPlugin):
'det_maniac', # Maniacs
'det_hard', # Hard#boiled
'thriller', # Thrillers
'detective', # Detectives
'detective', # Detectives
# Prose
'prose_classic', # Classics prose
'prose_history', # Historical prose
'prose_contemporary', # Contemporary prose
'prose_counter', # Counterculture
'prose_rus_classic', # Russial classics prose
'prose_su_classics', # Soviet classics prose
'prose_su_classics', # Soviet classics prose
# Romance
'love_contemporary', # Contemporary Romance
'love_history', # Historical Romance
'love_detective', # Detective Romance
'love_short', # Short Romance
'love_erotica', # Erotica
'love_erotica', # Erotica
# Adventure
'adv_western', # Western
'adv_history', # History
@ -62,7 +62,7 @@ class FB2Output(OutputFormatPlugin):
'adv_maritime', # Maritime Fiction
'adv_geo', # Travel & geography
'adv_animal', # Nature & animals
'adventure', # Other
'adventure', # Other
# Children's
'child_tale', # Fairy Tales
'child_verse', # Verses
@ -71,17 +71,17 @@ class FB2Output(OutputFormatPlugin):
'child_det', # Detectives & Thrillers
'child_adv', # Adventures
'child_education', # Educational
'children', # Other
'children', # Other
# Poetry & Dramaturgy
'poetry', # Poetry
'dramaturgy', # Dramaturgy
'dramaturgy', # Dramaturgy
# Antique literature
'antique_ant', # Antique
'antique_european', # European
'antique_russian', # Old russian
'antique_east', # Old east
'antique_myths', # Myths. Legends. Epos
'antique', # Other
'antique', # Other
# Scientific#educational
'sci_history', # History
'sci_psychology', # Psychology
@ -98,7 +98,7 @@ class FB2Output(OutputFormatPlugin):
'sci_chem', # Chemistry
'sci_biology', # Biology
'sci_tech', # Technical
'science', # Other
'science', # Other
# Computers & Internet
'comp_www', # Internet
'comp_programming', # Programming
@ -106,29 +106,29 @@ class FB2Output(OutputFormatPlugin):
'comp_soft', # Software
'comp_db', # Databases
'comp_osnet', # OS & Networking
'computers', # Other
'computers', # Other
# Reference
'ref_encyc', # Encyclopedias
'ref_dict', # Dictionaries
'ref_ref', # Reference
'ref_guide', # Guidebooks
'reference', # Other
'reference', # Other
# Nonfiction
'nonf_biography', # Biography & Memoirs
'nonf_publicism', # Publicism
'nonf_criticism', # Criticism
'design', # Art & design
'nonfiction', # Other
'nonfiction', # Other
# Religion & Inspiration
'religion_rel', # Religion
'religion_esoterics', # Esoterics
'religion_self', # Self#improvement
'religion', # Other
'religion', # Other
# Humor
'humor_anecdote', # Anecdote (funny stories)
'humor_prose', # Prose
'humor_verse', # Verses
'humor', # Other
'humor', # Other
# Home & Family
'home_cooking', # Cooking
'home_pets', # Pets
@ -155,14 +155,14 @@ class FB2Output(OutputFormatPlugin):
OptionRecommendation(name='fb2_genre',
recommended_value='antique', level=OptionRecommendation.LOW,
choices=FB2_GENRES,
help=_('Genre for the book. Choices: %s\n\n See: ' % FB2_GENRES) + 'http://www.fictionbook.org/index.php/Eng:FictionBook_2.1_genres ' \
help=(_('Genre for the book. Choices: %s\n\n See: ') % FB2_GENRES) + 'http://www.fictionbook.org/index.php/Eng:FictionBook_2.1_genres ' \
+ _('for a complete list with descriptions.')),
])
def convert(self, oeb_book, output_path, input_plugin, opts, log):
from calibre.ebooks.oeb.transforms.jacket import linearize_jacket
from calibre.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable
try:
rasterizer = SVGRasterizer()
rasterizer(oeb_book, opts)

View File

@ -279,12 +279,13 @@ class Worker(Thread): # Get details {{{
class Amazon(Source):
name = 'Amazon Web'
name = 'Amazon.com'
description = _('Downloads metadata from Amazon')
capabilities = frozenset(['identify', 'cover'])
touched_fields = frozenset(['title', 'authors', 'identifier:amazon',
'identifier:isbn', 'rating', 'comments', 'publisher', 'pubdate'])
'identifier:isbn', 'rating', 'comments', 'publisher', 'pubdate',
'language'])
has_html_comments = True
supports_gzip_transfer_encoding = True
@ -341,9 +342,10 @@ class Amazon(Source):
# Insufficient metadata to make an identify query
return None
utf8q = dict([(x.encode('utf-8'), y.encode('utf-8')) for x, y in
latin1q = dict([(x.encode('latin1', 'ignore'), y.encode('latin1',
'ignore')) for x, y in
q.iteritems()])
url = 'http://www.amazon.%s/s/?'%domain + urlencode(utf8q)
url = 'http://www.amazon.%s/s/?'%domain + urlencode(latin1q)
return url
# }}}

View File

@ -131,7 +131,22 @@ def fixcase(x):
x = titlecase(x)
return x
class Option(object):
__slots__ = ['type', 'default', 'label', 'desc', 'name', 'choices']
def __init__(self, name, type_, default, label, desc, choices=None):
'''
:param name: The name of this option. Must be a valid python identifier
:param type_: The type of this option, one of ('number', 'string',
'bool', 'choices')
:param default: The default value for this option
:param label: A short (few words) description of this option
:param desc: A longer description of this option
:param choices: A list of possible values, used only if type='choices'
'''
self.name, self.type, self.default, self.label, self.desc = (name,
type_, default, label, desc)
self.choices = choices
class Source(Plugin):
@ -158,10 +173,14 @@ class Source(Plugin):
supports_gzip_transfer_encoding = False
#: Cached cover URLs can sometimes be unreliable (i.e. the download could
#: fail or the returned image could be bogus. If that is the case set this to
#: False
#: fail or the returned image could be bogus. If that is often the case
#: with this source set to False
cached_cover_url_is_reliable = True
#: A list of :class:`Option` objects. They will be used to automatically
#: construct the configuration widget for this plugin
options = ()
def __init__(self, *args, **kwargs):
Plugin.__init__(self, *args, **kwargs)
@ -170,6 +189,9 @@ class Source(Plugin):
self.cache_lock = threading.RLock()
self._config_obj = None
self._browser = None
self.prefs.defaults['ignore_fields'] = []
for opt in self.options:
self.prefs.defaults[opt.name] = opt.default
# Configuration {{{
@ -180,6 +202,16 @@ class Source(Plugin):
'''
return True
def is_customizable(self):
return True
def config_widget(self):
from calibre.gui2.metadata.config import ConfigWidget
return ConfigWidget(self)
def save_settings(self, config_widget):
config_widget.commit()
@property
def prefs(self):
if self._config_obj is None:

View File

@ -357,11 +357,8 @@ def identify(log, abort, # {{{
if r.plugin.has_html_comments and r.comments:
r.comments = html2text(r.comments)
dummy = Metadata(_('Unknown'))
max_tags = msprefs['max_tags']
for r in results:
for f in msprefs['ignore_fields']:
setattr(r, f, getattr(dummy, f))
r.tags = r.tags[:max_tags]
return results

View File

@ -12,7 +12,7 @@ from calibre.ebooks.metadata.sources.base import Source
class OpenLibrary(Source):
name = 'Open Library'
description = _('Downloads metadata from The Open Library')
description = _('Downloads covers from The Open Library')
capabilities = frozenset(['cover'])

View File

@ -193,7 +193,10 @@ class PluginWidget(QWidget,Ui_Form):
opts_dict['header_note_source_field'] = self.header_note_source_field_name
# Append the output profile
opts_dict['output_profile'] = [load_defaults('page_setup')['output_profile']]
try:
opts_dict['output_profile'] = [load_defaults('page_setup')['output_profile']]
except:
opts_dict['output_profile'] = ['default']
if False:
print "opts_dict"
for opt in sorted(opts_dict.keys()):

View File

@ -172,6 +172,7 @@ class AuthorsEdit(MultiCompleteComboBox):
self.books_to_refresh = set([])
all_authors = db.all_authors()
all_authors.sort(key=lambda x : sort_key(x[1]))
self.clear()
for i in all_authors:
id, name = i
name = [name.strip().replace('|', ',') for n in name.split(',')]
@ -326,6 +327,7 @@ class SeriesEdit(MultiCompleteComboBox):
self.update_items_cache([x[1] for x in all_series])
series_id = db.series_id(id_, index_is_id=True)
idx, c = None, 0
self.clear()
for i in all_series:
id, name = i
if id == series_id:
@ -988,13 +990,13 @@ class PublisherEdit(MultiCompleteComboBox): # {{{
all_publishers.sort(key=lambda x : sort_key(x[1]))
self.update_items_cache([x[1] for x in all_publishers])
publisher_id = db.publisher_id(id_, index_is_id=True)
idx, c = None, 0
for i in all_publishers:
id, name = i
if id == publisher_id:
idx = c
idx = None
self.clear()
for i, x in enumerate(all_publishers):
id_, name = x
if id_ == publisher_id:
idx = i
self.addItem(name)
c += 1
self.setEditText('')
if idx is not None:

View File

@ -0,0 +1,122 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import textwrap
from PyQt4.Qt import (QWidget, QGridLayout, QGroupBox, QListView, Qt, QSpinBox,
QDoubleSpinBox, QCheckBox, QLineEdit, QComboBox, QLabel)
from calibre.gui2.preferences.metadata_sources import FieldsModel as FM
class FieldsModel(FM): # {{{
def __init__(self, plugin):
FM.__init__(self)
self.plugin = plugin
self.exclude = frozenset(['title', 'authors']) | self.exclude
self.prefs = self.plugin.prefs
def initialize(self):
fields = self.plugin.touched_fields
self.fields = []
for x in fields:
if not x.startswith('identifier:') and x not in self.exclude:
self.fields.append(x)
self.fields.sort(key=lambda x:self.descs.get(x, x))
self.reset()
def state(self, field, defaults=False):
src = self.prefs.defaults if defaults else self.prefs
return (Qt.Unchecked if field in src['ignore_fields']
else Qt.Checked)
def restore_defaults(self):
self.overrides = dict([(f, self.state(f, True)) for f in self.fields])
self.reset()
def commit(self):
val = [k for k, v in self.overrides.iteritems() if v == Qt.Unchecked]
self.prefs['ignore_fields'] = val
# }}}
class ConfigWidget(QWidget):
def __init__(self, plugin):
QWidget.__init__(self)
self.plugin = plugin
self.l = l = QGridLayout()
self.setLayout(l)
self.gb = QGroupBox(_('Downloaded metadata fields'), self)
l.addWidget(self.gb, 0, 0, 1, 2)
self.gb.l = QGridLayout()
self.gb.setLayout(self.gb.l)
self.fields_view = v = QListView(self)
self.gb.l.addWidget(v, 0, 0)
v.setFlow(v.LeftToRight)
v.setWrapping(True)
v.setResizeMode(v.Adjust)
self.fields_model = FieldsModel(self.plugin)
self.fields_model.initialize()
v.setModel(self.fields_model)
self.memory = []
self.widgets = []
for opt in plugin.options:
self.create_widgets(opt)
def create_widgets(self, opt):
val = self.plugin.prefs[opt.name]
if opt.type == 'number':
c = QSpinBox if isinstance(opt.default, int) else QDoubleSpinBox
widget = c(self)
widget.setValue(val)
elif opt.type == 'string':
widget = QLineEdit(self)
widget.setText(val)
elif opt.type == 'bool':
widget = QCheckBox(opt.label, self)
widget.setChecked(bool(val))
elif opt.type == 'choices':
widget = QComboBox(self)
for x in opt.choices:
widget.addItem(x)
idx = opt.choices.index(val)
widget.setCurrentIndex(idx)
widget.opt = opt
widget.setToolTip(textwrap.fill(opt.desc))
self.widgets.append(widget)
r = self.l.rowCount()
if opt.type == 'bool':
self.l.addWidget(widget, r, 0, 1, self.l.columnCount())
else:
l = QLabel(opt.label)
l.setToolTip(widget.toolTip())
self.memory.append(l)
l.setBuddy(widget)
self.l.addWidget(l, r, 0, 1, 1)
self.l.addWidget(widget, r, 1, 1, 1)
def commit(self):
self.fields_model.commit()
for w in self.widgets:
if isinstance(w, (QSpinBox, QDoubleSpinBox)):
val = w.value()
elif isinstance(w, QLineEdit):
val = unicode(w.text())
elif isinstance(w, QCheckBox):
val = w.isChecked()
elif isinstance(w, QComboBox):
val = unicode(w.currentText())
self.plugin.prefs[w.opt.name] = val

View File

@ -24,6 +24,7 @@ from calibre.gui2.metadata.basic_widgets import (TitleEdit, AuthorsEdit,
from calibre.gui2.metadata.single_download import FullFetch
from calibre.gui2.custom_column_widgets import populate_metadata_page
from calibre.utils.config import tweaks
from calibre.ebooks.metadata.book.base import Metadata
class MetadataSingleDialogBase(ResizableDialog):
@ -166,6 +167,11 @@ class MetadataSingleDialogBase(ResizableDialog):
font.setBold(True)
self.fetch_metadata_button.setFont(font)
self.config_metadata_button = QToolButton(self)
self.config_metadata_button.setIcon(QIcon(I('config.png')))
self.config_metadata_button.clicked.connect(self.configure_metadata)
self.config_metadata_button.setToolTip(
_('Change how calibre downloads metadata'))
# }}}
@ -309,12 +315,22 @@ class MetadataSingleDialogBase(ResizableDialog):
ret = d.start(title=self.title.current_val, authors=self.authors.current_val,
identifiers=self.identifiers.current_val)
if ret == d.Accepted:
from calibre.ebooks.metadata.sources.base import msprefs
mi = d.book
dummy = Metadata(_('Unknown'))
for f in msprefs['ignore_fields']:
setattr(mi, f, getattr(dummy, f))
if mi is not None:
self.update_from_mi(mi)
if d.cover_pixmap is not None:
self.cover.current_val = pixmap_to_data(d.cover_pixmap)
def configure_metadata(self):
from calibre.gui2.preferences import show_config_widget
gui = self.parent()
show_config_widget('Sharing', 'Metadata download', parent=self,
gui=gui, never_shutdown=True)
def download_cover(self, *args):
from calibre.gui2.metadata.single_download import CoverFetch
d = CoverFetch(self.cover.pixmap(), self)
@ -451,7 +467,8 @@ class MetadataSingleDialog(MetadataSingleDialogBase): # {{{
sto = QWidget.setTabOrder
sto(self.button_box, self.fetch_metadata_button)
sto(self.fetch_metadata_button, self.title)
sto(self.fetch_metadata_button, self.config_metadata_button)
sto(self.config_metadata_button, self.title)
def create_row(row, one, two, three, col=1, icon='forward.png'):
ql = BuddyLabel(one)
@ -530,7 +547,8 @@ class MetadataSingleDialog(MetadataSingleDialogBase): # {{{
self.tabs[0].spc_two = QSpacerItem(10, 10, QSizePolicy.Expanding,
QSizePolicy.Expanding)
l.addItem(self.tabs[0].spc_two, 8, 0, 1, 3)
l.addWidget(self.fetch_metadata_button, 9, 0, 1, 3)
l.addWidget(self.fetch_metadata_button, 9, 0, 1, 2)
l.addWidget(self.config_metadata_button, 9, 2, 1, 1)
self.tabs[0].gb2 = gb = QGroupBox(_('Co&mments'), self)
gb.l = l = QVBoxLayout()

View File

@ -7,8 +7,9 @@ __docformat__ = 'restructuredtext en'
import textwrap
from PyQt4.Qt import QWidget, pyqtSignal, QCheckBox, QAbstractSpinBox, \
QLineEdit, QComboBox, QVariant, Qt
from PyQt4.Qt import (QWidget, pyqtSignal, QCheckBox, QAbstractSpinBox,
QLineEdit, QComboBox, QVariant, Qt, QIcon, QDialog, QVBoxLayout,
QDialogButtonBox)
from calibre.customize.ui import preferences_plugins
from calibre.utils.config import ConfigProxy
@ -21,7 +22,7 @@ class ConfigWidgetInterface(object):
'''
This class defines the interface that all widgets displayed in the
Preferences dialog must implement. See :class:`ConfigWidgetBase` for
a base class that implements this interface and defines various conveninece
a base class that implements this interface and defines various convenience
methods as well.
'''
@ -284,7 +285,14 @@ def get_plugin(category, name):
'No Preferences Plugin with category: %s and name: %s found' %
(category, name))
# Testing {{{
class ConfigDialog(QDialog):
def set_widget(self, w): self.w = w
def accept(self):
try:
self.restart_required = self.w.commit()
except AbortCommit:
return
QDialog.accept(self)
def init_gui():
from calibre.gui2.ui import Main
@ -298,21 +306,24 @@ def init_gui():
gui.initialize(db.library_path, db, None, actions, show_gui=False)
return gui
def test_widget(category, name, gui=None):
from PyQt4.Qt import QDialog, QVBoxLayout, QDialogButtonBox
class Dialog(QDialog):
def set_widget(self, w): self.w = w
def accept(self):
try:
self.restart_required = self.w.commit()
except AbortCommit:
return
QDialog.accept(self)
def show_config_widget(category, name, gui=None, show_restart_msg=False,
parent=None, never_shutdown=False):
'''
Show the preferences plugin identified by category and name
:param gui: gui instance, if None a hidden gui is created
:param show_restart_msg: If True and the preferences plugin indicates a
restart is required, show a message box telling the user to restart
:param parent: The parent of the displayed dialog
:return: True iff a restart is required for the changes made by the user to
take effect
'''
pl = get_plugin(category, name)
d = Dialog()
d = ConfigDialog(parent)
d.resize(750, 550)
d.setWindowTitle(category + " - " + name)
d.setWindowTitle(_('Configure ') + name)
d.setWindowIcon(QIcon(I('config.png')))
bb = QDialogButtonBox(d)
bb.setStandardButtons(bb.Apply|bb.Cancel|bb.RestoreDefaults)
bb.accepted.connect(d.accept)
@ -335,11 +346,18 @@ def test_widget(category, name, gui=None):
w.genesis(gui)
w.initialize()
d.exec_()
if getattr(d, 'restart_required', False):
rr = getattr(d, 'restart_required', False)
if show_restart_msg and rr:
from calibre.gui2 import warning_dialog
warning_dialog(gui, 'Restart required', 'Restart required', show=True)
if mygui:
if mygui and not never_shutdown:
gui.shutdown()
return rr
# Testing {{{
def test_widget(category, name, gui=None):
show_config_widget(category, name, gui=gui, show_restart_msg=True)
def test_all():
from PyQt4.Qt import QApplication

View File

@ -43,6 +43,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
r('overwrite_author_title_metadata', config)
r('get_social_metadata', config)
if test_eight_code:
self.opt_overwrite_author_title_metadata.setVisible(False)
self.opt_get_social_metadata.setVisible(False)
r('new_version_notification', config)
r('upload_news_to_device', config)
r('delete_news_from_library_on_upload', config)

View File

@ -0,0 +1,308 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from operator import attrgetter
from PyQt4.Qt import (QAbstractTableModel, Qt, QAbstractListModel, QWidget,
pyqtSignal, QVBoxLayout, QDialogButtonBox, QFrame, QLabel)
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
from calibre.gui2.preferences.metadata_sources_ui import Ui_Form
from calibre.ebooks.metadata.sources.base import msprefs
from calibre.customize.ui import (all_metadata_plugins, is_disabled,
enable_plugin, disable_plugin, default_disabled_plugins)
from calibre.gui2 import NONE, error_dialog
class SourcesModel(QAbstractTableModel): # {{{
def __init__(self, parent=None):
QAbstractTableModel.__init__(self, parent)
self.plugins = []
self.enabled_overrides = {}
self.cover_overrides = {}
def initialize(self):
self.plugins = list(all_metadata_plugins())
self.plugins.sort(key=attrgetter('name'))
self.enabled_overrides = {}
self.cover_overrides = {}
self.reset()
def rowCount(self, parent=None):
return len(self.plugins)
def columnCount(self, parent=None):
return 2
def headerData(self, section, orientation, role):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
if section == 0:
return _('Source')
if section == 1:
return _('Cover priority')
return NONE
def data(self, index, role):
try:
plugin = self.plugins[index.row()]
except:
return NONE
col = index.column()
if role == Qt.DisplayRole:
if col == 0:
return plugin.name
elif col == 1:
orig = msprefs['cover_priorities'].get(plugin.name, 1)
return self.cover_overrides.get(plugin, orig)
elif role == Qt.CheckStateRole and col == 0:
orig = Qt.Unchecked if is_disabled(plugin) else Qt.Checked
return self.enabled_overrides.get(plugin, orig)
elif role == Qt.UserRole:
return plugin
return NONE
def setData(self, index, val, role):
try:
plugin = self.plugins[index.row()]
except:
return False
col = index.column()
ret = False
if col == 0 and role == Qt.CheckStateRole:
val, ok = val.toInt()
if ok:
self.enabled_overrides[plugin] = val
ret = True
if col == 1 and role == Qt.EditRole:
val, ok = val.toInt()
if ok:
self.cover_overrides[plugin] = val
ret = True
if ret:
self.dataChanged.emit(index, index)
return ret
def flags(self, index):
col = index.column()
ans = QAbstractTableModel.flags(self, index)
if col == 0:
return ans | Qt.ItemIsUserCheckable
return Qt.ItemIsEditable | ans
def commit(self):
for plugin, val in self.enabled_overrides.iteritems():
if val == Qt.Checked:
enable_plugin(plugin)
elif val == Qt.Unchecked:
disable_plugin(plugin)
if self.cover_overrides:
cp = msprefs['cover_priorities']
for plugin, val in self.cover_overrides.iteritems():
if val == 1:
cp.pop(plugin.name, None)
else:
cp[plugin.name] = val
msprefs['cover_priorities'] = cp
self.enabled_overrides = {}
self.cover_overrides = {}
def restore_defaults(self):
self.enabled_overrides = dict([(p, (Qt.Unchecked if p.name in
default_disabled_plugins else Qt.Checked)) for p in self.plugins])
self.cover_overrides = dict([(p,
msprefs.defaults['cover_priorities'].get(p.name, 1))
for p in self.plugins])
self.reset()
# }}}
class FieldsModel(QAbstractListModel): # {{{
def __init__(self, parent=None):
QAbstractTableModel.__init__(self, parent)
self.fields = []
self.descs = {
'authors': _('Authors'),
'comments': _('Comments'),
'pubdate': _('Published date'),
'publisher': _('Publisher'),
'rating' : _('Rating'),
'tags' : _('Tags'),
'title': _('Title'),
'series': _('Series'),
'language': _('Language'),
}
self.overrides = {}
self.exclude = frozenset(['series_index'])
def rowCount(self, parent=None):
return len(self.fields)
def initialize(self):
fields = set()
for p in all_metadata_plugins():
fields |= p.touched_fields
self.fields = []
for x in fields:
if not x.startswith('identifier:') and x not in self.exclude:
self.fields.append(x)
self.fields.sort(key=lambda x:self.descs.get(x, x))
self.reset()
def state(self, field, defaults=False):
src = msprefs.defaults if defaults else msprefs
return (Qt.Unchecked if field in src['ignore_fields']
else Qt.Checked)
def data(self, index, role):
try:
field = self.fields[index.row()]
except:
return None
if role == Qt.DisplayRole:
return self.descs.get(field, field)
if role == Qt.CheckStateRole:
return self.overrides.get(field, self.state(field))
return NONE
def flags(self, index):
ans = QAbstractTableModel.flags(self, index)
return ans | Qt.ItemIsUserCheckable
def restore_defaults(self):
self.overrides = dict([(f, self.state(f, True)) for f in self.fields])
self.reset()
def setData(self, index, val, role):
try:
field = self.fields[index.row()]
except:
return False
ret = False
if role == Qt.CheckStateRole:
val, ok = val.toInt()
if ok:
self.overrides[field] = val
ret = True
if ret:
self.dataChanged.emit(index, index)
return ret
def commit(self):
val = [k for k, v in self.overrides.iteritems() if v == Qt.Unchecked]
msprefs['ignore_fields'] = val
# }}}
class PluginConfig(QWidget): # {{{
finished = pyqtSignal()
def __init__(self, plugin, parent):
QWidget.__init__(self, parent)
self.plugin = plugin
self.l = l = QVBoxLayout()
self.setLayout(l)
self.c = c = QLabel(_('<b>Configure %s</b><br>%s') % (plugin.name,
plugin.description))
c.setAlignment(Qt.AlignHCenter)
l.addWidget(c)
self.config_widget = plugin.config_widget()
self.l.addWidget(self.config_widget)
self.bb = QDialogButtonBox(
QDialogButtonBox.Save|QDialogButtonBox.Cancel,
parent=self)
self.bb.accepted.connect(self.finished)
self.bb.rejected.connect(self.finished)
self.bb.accepted.connect(self.commit)
l.addWidget(self.bb)
self.f = QFrame(self)
self.f.setFrameShape(QFrame.HLine)
l.addWidget(self.f)
def commit(self):
self.plugin.save_settings(self.config_widget)
# }}}
class ConfigWidget(ConfigWidgetBase, Ui_Form):
def genesis(self, gui):
r = self.register
r('txt_comments', msprefs)
r('max_tags', msprefs)
r('wait_after_first_identify_result', msprefs)
r('wait_after_first_cover_result', msprefs)
self.configure_plugin_button.clicked.connect(self.configure_plugin)
self.sources_model = SourcesModel(self)
self.sources_view.setModel(self.sources_model)
self.sources_model.dataChanged.connect(self.changed_signal)
self.fields_model = FieldsModel(self)
self.fields_view.setModel(self.fields_model)
self.fields_model.dataChanged.connect(self.changed_signal)
def configure_plugin(self):
for index in self.sources_view.selectionModel().selectedRows():
plugin = self.sources_model.data(index, Qt.UserRole)
if plugin is not NONE:
return self.do_config(plugin)
error_dialog(self, _('No source selected'),
_('No source selected, cannot configure.'), show=True)
def do_config(self, plugin):
self.pc = PluginConfig(plugin, self)
self.stack.insertWidget(1, self.pc)
self.stack.setCurrentIndex(1)
self.pc.finished.connect(self.pc_finished)
def pc_finished(self):
try:
self.pc.finished.diconnect()
except:
pass
self.stack.setCurrentIndex(0)
self.stack.removeWidget(self.pc)
self.pc = None
def initialize(self):
ConfigWidgetBase.initialize(self)
self.sources_model.initialize()
self.sources_view.resizeColumnsToContents()
self.fields_model.initialize()
def restore_defaults(self):
ConfigWidgetBase.restore_defaults(self)
self.sources_model.restore_defaults()
self.fields_model.restore_defaults()
self.changed_signal.emit()
def commit(self):
self.sources_model.commit()
self.fields_model.commit()
return ConfigWidgetBase.commit(self)
if __name__ == '__main__':
from PyQt4.Qt import QApplication
app = QApplication([])
test_widget('Sharing', 'Metadata download')

View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>781</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QStackedWidget" name="stack">
<widget class="QWidget" name="page">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" rowspan="5">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Metadata sources</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Disable any metadata sources you do not want by unchecking them. You can also set the cover priority. Covers from sources that have a higher (smaller) priority will be preferred when bulk downloading metadata.
</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="sources_view">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="configure_plugin_button">
<property name="text">
<string>Configure selected source</string>
</property>
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/plugins.png</normaloff>:/images/plugins.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Downloaded metadata fields</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListView" name="fields_view">
<property name="toolTip">
<string>If you uncheck any fields, metadata for those fields will not be downloaded</string>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QCheckBox" name="opt_txt_comments">
<property name="text">
<string>Convert all downloaded comments to plain &amp;text</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Max. number of &amp;tags to download:</string>
</property>
<property name="buddy">
<cstring>opt_max_tags</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="opt_max_tags"/>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Max. &amp;time to wait after first match is found:</string>
</property>
<property name="buddy">
<cstring>opt_wait_after_first_identify_result</cstring>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QSpinBox" name="opt_wait_after_first_identify_result">
<property name="suffix">
<string> secs</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Max. time to wait after first &amp;cover is found:</string>
</property>
<property name="buddy">
<cstring>opt_wait_after_first_cover_result</cstring>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QSpinBox" name="opt_wait_after_first_cover_result">
<property name="suffix">
<string> secs</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../../../resources/images.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -14,9 +14,9 @@ from calibre.utils.config import read_raw_tweaks, write_tweaks
from calibre.gui2.widgets import PythonHighlighter
from calibre import isbytestring
from PyQt4.Qt import QAbstractListModel, Qt, QStyledItemDelegate, QStyle, \
QStyleOptionViewItem, QFont, QDialogButtonBox, QDialog, \
QVBoxLayout, QPlainTextEdit, QLabel
from PyQt4.Qt import (QAbstractListModel, Qt, QStyledItemDelegate, QStyle,
QStyleOptionViewItem, QFont, QDialogButtonBox, QDialog,
QVBoxLayout, QPlainTextEdit, QLabel)
class Delegate(QStyledItemDelegate): # {{{
def __init__(self, view):
@ -35,8 +35,9 @@ class Delegate(QStyledItemDelegate): # {{{
class Tweak(object): # {{{
def __init__(self, name, doc, var_names, defaults, custom):
self.name = name
self.doc = doc.strip()
translate = __builtins__['_']
self.name = translate(name)
self.doc = translate(doc.strip())
self.var_names = var_names
self.default_values = {}
for x in var_names:

View File

@ -449,12 +449,12 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
self.library_view.model().count_changed()
prefs['library_path'] = self.library_path
db = self.library_view.model().db
for action in self.iactions.values():
action.library_changed(db)
self.set_window_title()
self.apply_named_search_restriction('') # reset restriction to null
self.saved_searches_changed() # reload the search restrictions combo box
self.apply_named_search_restriction(db.prefs['gui_restriction'])
for action in self.iactions.values():
action.library_changed(db)
if olddb is not None:
try:
if call_close:

View File

@ -65,6 +65,22 @@ There are two aspects to this problem:
2. When adding HTML files to |app|, you may need to tell |app| what encoding the files are in. To do this go to :guilabel:`Preferences->Advanced->Plugins->File Type plugins` and customize the HTML2Zip plugin, telling it what encoding your HTML files are in. Now when you add HTML files to |app| they will be correctly processed. HTML files from different sources often have different encodings, so you may have to change this setting repeatedly. A common encoding for many files from the web is ``cp1252`` and I would suggest you try that first. Note that when converting HTML files, leave the input encoding setting mentioned above blank. This is because the HTML2ZIP plugin automatically converts the HTML files to a standard encoding (utf-8).
3. Embedding fonts: If you are generating an LRF file to read on your SONY Reader, you are limited by the fact that the Reader only supports a few non-English characters in the fonts it comes pre-loaded with. You can work around this problem by embedding a unicode-aware font that supports the character set your file uses into the LRF file. You should embed atleast a serif and a sans-serif font. Be aware that embedding fonts significantly slows down page-turn speed on the reader.
What's the deal with Table of Contents in MOBI files?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The first thing to realize is that most ebooks have two tables of contents. One is the traditional Table of Contents, like the TOC you find in paper books. This Table of Contents is part of the main document flow and can be styled however you like. This TOC is called the *content TOC*.
Then there is the *metadata TOC*. A metadata TOC is a TOC that is not part of the book text and is typically accessed by some special button on a reader. For example, in the calibre viewer, you use the Show Table of Contents button to see this TOC. This TOC cannot be styled by the book creator. How it is represented is up to the viewer program.
In the MOBI format, the situation is a little confused. This is because the MOBI format, alone amongst mainstream ebook formats, *does not* have decent support for a metadata TOC. A MOBI book simulates the presence of a metadata TOC by putting an *extra* content TOC at the end of the book. When you click Goto Table of Contents on your Kindle, it is to this extra content TOC that the Kindle takes you.
Now it might well seem to you that the MOBI book has two identical TOCs. Remember that one is semantically a content TOC and the other is a metadata TOC, even though both might have exactly the same entries and look the same. One can be accessed directly from the Kindle's menus, the other cannot.
When converting to MOBI, calibre detects the *metadata TOC* in the input document and generates an end-of-file TOC in the output MOBI file. You can turn this off by an option in the MOBI Output settings. You cannot control where this generated TOC will go. Remember this TOC is semantically a *metadata TOC*, in any format other than MOBI it *cannot not be part of the text*. The fact that it is part of the text in MOBI is an accident caused by the limitations of MOBI. If you want a TOC at a particular location in your document text, create one by hand.
If you have a hand edited TOC in the input document, you can use the TOC detection options in calibre to automatically generate the metadata TOC from it. See the conversion section of the User Manual for more details on how to use these options.
Finally, I encourage you to ditch the content TOC and only have a metadata TOC in your ebooks. Metadata TOCs will give the people reading your ebooks a much superior navigation experience (except on the Kindle, where they are essentially the same as a content TOC).
How do I use some of the advanced features of the conversion tools?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

File diff suppressed because it is too large Load Diff

View File

@ -785,8 +785,6 @@ def write_tweaks(raw):
tweaks = read_tweaks()
test_eight_code = tweaks.get('test_eight_code', False)
# test_eight_code notes
# Change Amazon plugin name to just Amazon
def migrate():
if hasattr(os, 'geteuid') and os.geteuid() == 0: