This commit is contained in:
Kovid Goyal 2011-04-11 09:47:20 -06:00
parent 92d810ac2e
commit ea42c67e05
2 changed files with 48 additions and 17 deletions

View File

@ -22,6 +22,8 @@ from calibre.constants import preferred_encoding, filesystem_encoding
from calibre.gui2.actions import InterfaceAction from calibre.gui2.actions import InterfaceAction
from calibre.gui2 import config, question_dialog from calibre.gui2 import config, question_dialog
from calibre.ebooks.metadata import MetaInformation from calibre.ebooks.metadata import MetaInformation
from calibre.utils.config import test_eight_code
from calibre.ebooks.metadata.sources.base import msprefs
def get_filters(): def get_filters():
return [ return [
@ -178,13 +180,26 @@ class AddAction(InterfaceAction):
except IndexError: except IndexError:
self.gui.library_view.model().books_added(self.isbn_add_dialog.value) self.gui.library_view.model().books_added(self.isbn_add_dialog.value)
self.isbn_add_dialog.accept() self.isbn_add_dialog.accept()
orig = config['overwrite_author_title_metadata'] if test_eight_code:
config['overwrite_author_title_metadata'] = True orig = msprefs['ignore_fields']
try: new = list(orig)
self.gui.iactions['Edit Metadata'].do_download_metadata( for x in ('title', 'authors'):
self.add_by_isbn_ids) if x in new:
finally: new.remove(x)
config['overwrite_author_title_metadata'] = orig msprefs['ignore_fields'] = new
try:
self.gui.iactions['Edit Metadata'].download_metadata(
ids=self.add_by_isbn_ids)
finally:
msprefs['ignore_fields'] = orig
else:
orig = config['overwrite_author_title_metadata']
config['overwrite_author_title_metadata'] = True
try:
self.gui.iactions['Edit Metadata'].do_download_metadata(
self.add_by_isbn_ids)
finally:
config['overwrite_author_title_metadata'] = orig
return return

View File

@ -35,16 +35,23 @@ class EditMetadataAction(InterfaceAction):
md.addAction(_('Edit metadata in bulk'), md.addAction(_('Edit metadata in bulk'),
partial(self.edit_metadata, False, bulk=True)) partial(self.edit_metadata, False, bulk=True))
md.addSeparator() md.addSeparator()
md.addAction(_('Download metadata and covers'), if test_eight_code:
partial(self.download_metadata, False, covers=True), dall = self.download_metadata
dident = partial(self.download_metadata, covers=False)
dcovers = partial(self.download_metadata, identify=False)
else:
dall = partial(self.download_metadata_old, False, covers=True)
dident = partial(self.download_metadata_old, False, covers=False)
dcovers = partial(self.download_metadata_old, False, covers=True,
set_metadata=False, set_social_metadata=False)
md.addAction(_('Download metadata and covers'), dall,
Qt.ControlModifier+Qt.Key_D) Qt.ControlModifier+Qt.Key_D)
md.addAction(_('Download only metadata'), md.addAction(_('Download only metadata'), dident)
partial(self.download_metadata, False, covers=False)) md.addAction(_('Download only covers'), dcovers)
md.addAction(_('Download only covers'), if not test_eight_code:
partial(self.download_metadata, False, covers=True, md.addAction(_('Download only social metadata'),
set_metadata=False, set_social_metadata=False)) partial(self.download_metadata_old, False, covers=False,
md.addAction(_('Download only social metadata'),
partial(self.download_metadata, False, covers=False,
set_metadata=False, set_social_metadata=True)) set_metadata=False, set_social_metadata=True))
self.metadata_menu = md self.metadata_menu = md
@ -73,7 +80,16 @@ class EditMetadataAction(InterfaceAction):
self.qaction.setEnabled(enabled) self.qaction.setEnabled(enabled)
self.action_merge.setEnabled(enabled) self.action_merge.setEnabled(enabled)
def download_metadata(self, checked, covers=True, set_metadata=True, def download_metadata(self, identify=True, covers=True, ids=None):
if ids is None:
rows = self.gui.library_view.selectionModel().selectedRows()
if not rows or len(rows) == 0:
return error_dialog(self.gui, _('Cannot download metadata'),
_('No books selected'), show=True)
db = self.gui.library_view.model().db
ids = [db.id(row.row()) for row in rows]
def download_metadata_old(self, checked, covers=True, set_metadata=True,
set_social_metadata=None): set_social_metadata=None):
rows = self.gui.library_view.selectionModel().selectedRows() rows = self.gui.library_view.selectionModel().selectedRows()
if not rows or len(rows) == 0: if not rows or len(rows) == 0: