mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
...
This commit is contained in:
parent
624bb54a49
commit
5556a1604c
@ -75,6 +75,17 @@ def enable_plugin(plugin_or_name):
|
|||||||
ep.add(x)
|
ep.add(x)
|
||||||
config['enabled_plugins'] = ep
|
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([
|
default_disabled_plugins = set([
|
||||||
'Douban Books', 'Douban.com covers', 'Nicebooks', 'Nicebooks covers',
|
'Douban Books', 'Douban.com covers', 'Nicebooks', 'Nicebooks covers',
|
||||||
'Kent District Library'
|
'Kent District Library'
|
||||||
|
@ -341,7 +341,8 @@ class Amazon(Source):
|
|||||||
# Insufficient metadata to make an identify query
|
# Insufficient metadata to make an identify query
|
||||||
return None
|
return None
|
||||||
|
|
||||||
latin1q = dict([(x.encode('latin1'), y.encode('latin1')) for x, y in
|
latin1q = dict([(x.encode('latin1', 'ignore'), y.encode('latin1',
|
||||||
|
'ignore')) for x, y in
|
||||||
q.iteritems()])
|
q.iteritems()])
|
||||||
url = 'http://www.amazon.%s/s/?'%domain + urlencode(latin1q)
|
url = 'http://www.amazon.%s/s/?'%domain + urlencode(latin1q)
|
||||||
return url
|
return url
|
||||||
|
@ -7,14 +7,157 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
from operator import attrgetter
|
||||||
|
|
||||||
|
from PyQt4.Qt import (QAbstractTableModel, Qt)
|
||||||
|
|
||||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||||
from calibre.gui2.preferences.metadata_sources_ui import Ui_Form
|
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, restore_plugin_state_to_default)
|
||||||
|
from calibre.gui2 import NONE
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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):
|
||||||
|
del msprefs['cover_priorities']
|
||||||
|
self.enabled_overrides = {}
|
||||||
|
self.cover_overrides = {}
|
||||||
|
for plugin in self.plugins:
|
||||||
|
restore_plugin_state_to_default(plugin)
|
||||||
|
self.reset()
|
||||||
|
|
||||||
|
# }}}
|
||||||
|
|
||||||
class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||||
pass
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
def configure_plugin(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def initialize(self):
|
||||||
|
ConfigWidgetBase.initialize(self)
|
||||||
|
self.sources_model.initialize()
|
||||||
|
self.sources_view.resizeColumnsToContents()
|
||||||
|
|
||||||
|
def restore_defaults(self):
|
||||||
|
ConfigWidgetBase.restore_defaults(self)
|
||||||
|
self.sources_model.restore_defaults()
|
||||||
|
self.changed_signal.emit()
|
||||||
|
|
||||||
|
def commit(self):
|
||||||
|
self.sources_model.commit()
|
||||||
|
return ConfigWidgetBase.commit(self)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from PyQt4.Qt import QApplication
|
from PyQt4.Qt import QApplication
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
test_widget('Interface', 'Behavior')
|
test_widget('Sharing', 'Metadata download')
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="label">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string><p>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>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.
|
||||||
<p>Double click on a metadata source to customize it.</string>
|
</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
@ -39,7 +39,25 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="sources_list"/>
|
<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>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -51,7 +69,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListView" name="fields_list">
|
<widget class="QListView" name="fields_view">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>If you uncheck any fields, metadata for those fields will not be downloaded</string>
|
<string>If you uncheck any fields, metadata for those fields will not be downloaded</string>
|
||||||
</property>
|
</property>
|
||||||
@ -100,7 +118,7 @@
|
|||||||
<item row="4" column="1">
|
<item row="4" column="1">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Max. time to wait after &cover is found:</string>
|
<string>Max. time to wait after first &cover is found:</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="buddy">
|
<property name="buddy">
|
||||||
<cstring>opt_wait_after_first_cover_result</cstring>
|
<cstring>opt_wait_after_first_cover_result</cstring>
|
||||||
@ -121,6 +139,8 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources>
|
||||||
|
<include location="../../../../resources/images.qrc"/>
|
||||||
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user