mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Adding books: Implement a copy to clipboard button for when duplicates are found during the adding process. Useful if you wish to review the list of duplicates later. See #1276918 (The Popup for duplicate records does not have a "copy to clipboard" option that would be most useful)
This commit is contained in:
parent
4175c1cf7f
commit
a1fa4a686b
@ -9,8 +9,9 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from PyQt4.Qt import (QDialog, QGridLayout, QIcon, QLabel, QTreeWidget,
|
from PyQt4.Qt import (
|
||||||
QTreeWidgetItem, Qt, QFont, QDialogButtonBox)
|
QDialog, QGridLayout, QIcon, QLabel, QTreeWidget, QTreeWidgetItem, Qt,
|
||||||
|
QFont, QDialogButtonBox, QApplication)
|
||||||
|
|
||||||
from calibre.gui2 import gprefs
|
from calibre.gui2 import gprefs
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
@ -50,9 +51,12 @@ class DuplicatesQuestion(QDialog):
|
|||||||
l.addWidget(bb, 2, 0, 1, 2)
|
l.addWidget(bb, 2, 0, 1, 2)
|
||||||
l.setColumnStretch(1, 10)
|
l.setColumnStretch(1, 10)
|
||||||
self.ab = ab = bb.addButton(_('Select &all'), bb.ActionRole)
|
self.ab = ab = bb.addButton(_('Select &all'), bb.ActionRole)
|
||||||
ab.clicked.connect(self.select_all)
|
ab.clicked.connect(self.select_all), ab.setIcon(QIcon(I('plus.png')))
|
||||||
self.nb = ab = bb.addButton(_('Select &none'), bb.ActionRole)
|
self.nb = ab = bb.addButton(_('Select &none'), bb.ActionRole)
|
||||||
ab.clicked.connect(self.select_none)
|
ab.clicked.connect(self.select_none), ab.setIcon(QIcon(I('minus.png')))
|
||||||
|
self.cb = cb = bb.addButton(_('&Copy to clipboard'), bb.ActionRole)
|
||||||
|
cb.setIcon(QIcon(I('edit-copy.png')))
|
||||||
|
cb.clicked.connect(self.copy_to_clipboard)
|
||||||
|
|
||||||
self.resize(self.sizeHint())
|
self.resize(self.sizeHint())
|
||||||
geom = gprefs.get('duplicates-question-dialog-geometry', None)
|
geom = gprefs.get('duplicates-question-dialog-geometry', None)
|
||||||
@ -60,6 +64,9 @@ class DuplicatesQuestion(QDialog):
|
|||||||
self.restoreGeometry(geom)
|
self.restoreGeometry(geom)
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
|
||||||
|
def copy_to_clipboard(self):
|
||||||
|
QApplication.clipboard().setText(self.as_text)
|
||||||
|
|
||||||
def select_all(self):
|
def select_all(self):
|
||||||
for i in xrange(self.dup_list.topLevelItemCount()):
|
for i in xrange(self.dup_list.topLevelItemCount()):
|
||||||
x = self.dup_list.topLevelItem(i)
|
x = self.dup_list.topLevelItem(i)
|
||||||
@ -130,8 +137,21 @@ class DuplicatesQuestion(QDialog):
|
|||||||
if x.checkState(0) == Qt.Checked:
|
if x.checkState(0) == Qt.Checked:
|
||||||
yield x.data(0, Qt.UserRole).toPyObject()
|
yield x.data(0, Qt.UserRole).toPyObject()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def as_text(self):
|
||||||
|
entries = []
|
||||||
|
for i in xrange(self.dup_list.topLevelItemCount()):
|
||||||
|
x = self.dup_list.topLevelItem(i)
|
||||||
|
check = '✓' if x.checkState(0) == Qt.Checked else '✗'
|
||||||
|
title = '%s %s' % (check, unicode(x.text(0)))
|
||||||
|
dups = []
|
||||||
|
for child in (x.child(j) for j in xrange(x.childCount())):
|
||||||
|
dups.append('\t' + unicode(child.text(0)))
|
||||||
|
entries.append(title + '\n' + '\n'.join(dups))
|
||||||
|
return '\n\n'.join(entries)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from PyQt4.Qt import QApplication
|
|
||||||
from calibre.ebooks.metadata.book.base import Metadata as M
|
from calibre.ebooks.metadata.book.base import Metadata as M
|
||||||
from calibre.library import db
|
from calibre.library import db
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user