Edit metadata single dialog is now fully functional

This commit is contained in:
Kovid Goyal 2011-04-09 21:41:20 -06:00
parent 0d57316475
commit 23111cec27
3 changed files with 73 additions and 6 deletions

View File

@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en'
import textwrap, re, os import textwrap, re, os
from PyQt4.Qt import (Qt, QDateEdit, QDate, from PyQt4.Qt import (Qt, QDateEdit, QDate, pyqtSignal,
QIcon, QToolButton, QWidget, QLabel, QGridLayout, QIcon, QToolButton, QWidget, QLabel, QGridLayout,
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, QDoubleSpinBox, QListWidgetItem, QSize, QPixmap,
QPushButton, QSpinBox, QLineEdit, QSizePolicy) QPushButton, QSpinBox, QLineEdit, QSizePolicy)
@ -613,6 +613,8 @@ class FormatsManager(QWidget): # {{{
class Cover(ImageView): # {{{ class Cover(ImageView): # {{{
download_cover = pyqtSignal()
def __init__(self, parent): def __init__(self, parent):
ImageView.__init__(self, parent) ImageView.__init__(self, parent)
self.dialog = parent self.dialog = parent
@ -703,9 +705,6 @@ class Cover(ImageView): # {{{
cdata = im.export('png') cdata = im.export('png')
self.current_val = cdata self.current_val = cdata
def download_cover(self, *args):
pass # TODO: Implement this
def generate_cover(self, *args): def generate_cover(self, *args):
from calibre.ebooks import calibre_cover from calibre.ebooks import calibre_cover
from calibre.ebooks.metadata import fmt_sidx from calibre.ebooks.metadata import fmt_sidx

View File

@ -133,6 +133,7 @@ class MetadataSingleDialogBase(ResizableDialog):
self.formats_manager.cover_from_format_button.clicked.connect( self.formats_manager.cover_from_format_button.clicked.connect(
self.cover_from_format) self.cover_from_format)
self.cover = Cover(self) self.cover = Cover(self)
self.cover.download_cover.connect(self.download_cover)
self.basic_metadata_widgets.append(self.cover) self.basic_metadata_widgets.append(self.cover)
self.comments = CommentsEdit(self, self.one_line_comments_toolbar) self.comments = CommentsEdit(self, self.one_line_comments_toolbar)
@ -159,7 +160,7 @@ class MetadataSingleDialogBase(ResizableDialog):
self.basic_metadata_widgets.extend([self.timestamp, self.pubdate]) self.basic_metadata_widgets.extend([self.timestamp, self.pubdate])
self.fetch_metadata_button = QPushButton( self.fetch_metadata_button = QPushButton(
_('&Fetch metadata from server'), self) _('&Download metadata'), self)
self.fetch_metadata_button.clicked.connect(self.fetch_metadata) self.fetch_metadata_button.clicked.connect(self.fetch_metadata)
font = self.fmb_font = QFont() font = self.fmb_font = QFont()
font.setBold(True) font.setBold(True)
@ -313,6 +314,17 @@ class MetadataSingleDialogBase(ResizableDialog):
self.update_from_mi(mi) self.update_from_mi(mi)
if d.cover_pixmap is not None: if d.cover_pixmap is not None:
self.cover.current_val = pixmap_to_data(d.cover_pixmap) self.cover.current_val = pixmap_to_data(d.cover_pixmap)
def download_cover(self, *args):
from calibre.gui2.metadata.single_download import CoverFetch
d = CoverFetch(self.cover.pixmap(), self)
ret = d.start(self.title.current_val, self.authors.current_val,
self.identifiers.current_val)
if ret == d.Accepted:
if d.cover_pixmap is not None:
self.cover.current_val = pixmap_to_data(d.cover_pixmap)
# }}} # }}}
def apply_changes(self): def apply_changes(self):

View File

@ -678,7 +678,8 @@ class CoversWidget(QWidget): # {{{
def start(self, book, current_cover, title, authors): def start(self, book, current_cover, title, authors):
self.book, self.current_cover = book, current_cover self.book, self.current_cover = book, current_cover
self.title, self.authors = title, authors self.title, self.authors = title, authors
self.log('\n\nStarting cover download for:', book.title) self.log('Starting cover download for:', book.title)
self.log('Query:', title, authors, self.book.identifiers)
self.msg.setText('<p>'+_('Downloading covers for <b>%s</b>, please wait...')%book.title) self.msg.setText('<p>'+_('Downloading covers for <b>%s</b>, please wait...')%book.title)
self.covers_view.start() self.covers_view.start()
@ -850,6 +851,7 @@ class FullFetch(QDialog): # {{{
self.ok_button.setVisible(True) self.ok_button.setVisible(True)
self.book = book self.book = book
self.stack.setCurrentIndex(1) self.stack.setCurrentIndex(1)
self.log('\n\n')
self.covers_widget.start(book, self.current_cover, self.covers_widget.start(book, self.current_cover,
self.title, self.authors) self.title, self.authors)
@ -859,6 +861,7 @@ class FullFetch(QDialog): # {{{
def reject(self): def reject(self):
self.identify_widget.cancel() self.identify_widget.cancel()
self.covers_widget.cancel()
return QDialog.reject(self) return QDialog.reject(self)
def cleanup(self): def cleanup(self):
@ -888,6 +891,59 @@ class FullFetch(QDialog): # {{{
return self.exec_() return self.exec_()
# }}} # }}}
class CoverFetch(QDialog): # {{{
def __init__(self, current_cover=None, parent=None):
QDialog.__init__(self, parent)
self.current_cover = current_cover
self.log = Log()
self.cover_pixmap = None
self.setWindowTitle(_('Downloading cover...'))
self.setWindowIcon(QIcon(I('book.png')))
self.l = l = QVBoxLayout()
self.setLayout(l)
self.covers_widget = CoversWidget(self.log, self.current_cover, parent=self)
self.covers_widget.chosen.connect(self.accept)
l.addWidget(self.covers_widget)
self.resize(850, 550)
self.finished.connect(self.cleanup)
self.bb = QDialogButtonBox(QDialogButtonBox.Cancel|QDialogButtonBox.Ok)
l.addWidget(self.bb)
self.log_button = self.bb.addButton(_('View log'), self.bb.ActionRole)
self.log_button.clicked.connect(self.view_log)
self.log_button.setIcon(QIcon(I('debug.png')))
self.bb.rejected.connect(self.reject)
self.bb.accepted.connect(self.accept)
def cleanup(self):
self.covers_widget.cleanup()
def reject(self):
self.covers_widget.cancel()
return QDialog.reject(self)
def accept(self, *args):
self.cover_pixmap = self.covers_widget.cover_pixmap()
QDialog.accept(self)
def start(self, title, authors, identifiers):
book = Metadata(title, authors)
book.identifiers = identifiers
self.covers_widget.start(book, self.current_cover,
title, authors)
return self.exec_()
def view_log(self):
self._lv = LogViewer(self.log, self)
# }}}
if __name__ == '__main__': if __name__ == '__main__':
#DEBUG_DIALOG = True #DEBUG_DIALOG = True
app = QApplication([]) app = QApplication([])