From a1fa4a686ba85678168209394a9a3f5dc07d6b59 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 6 Feb 2014 12:28:01 +0530 Subject: [PATCH] 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) --- src/calibre/gui2/dialogs/duplicates.py | 30 +++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/dialogs/duplicates.py b/src/calibre/gui2/dialogs/duplicates.py index f9f1ccc1a2..ae82912994 100644 --- a/src/calibre/gui2/dialogs/duplicates.py +++ b/src/calibre/gui2/dialogs/duplicates.py @@ -9,8 +9,9 @@ __docformat__ = 'restructuredtext en' import os.path -from PyQt4.Qt import (QDialog, QGridLayout, QIcon, QLabel, QTreeWidget, - QTreeWidgetItem, Qt, QFont, QDialogButtonBox) +from PyQt4.Qt import ( + QDialog, QGridLayout, QIcon, QLabel, QTreeWidget, QTreeWidgetItem, Qt, + QFont, QDialogButtonBox, QApplication) from calibre.gui2 import gprefs from calibre.ebooks.metadata import authors_to_string @@ -50,9 +51,12 @@ class DuplicatesQuestion(QDialog): l.addWidget(bb, 2, 0, 1, 2) l.setColumnStretch(1, 10) 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) - 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()) geom = gprefs.get('duplicates-question-dialog-geometry', None) @@ -60,6 +64,9 @@ class DuplicatesQuestion(QDialog): self.restoreGeometry(geom) self.exec_() + def copy_to_clipboard(self): + QApplication.clipboard().setText(self.as_text) + def select_all(self): for i in xrange(self.dup_list.topLevelItemCount()): x = self.dup_list.topLevelItem(i) @@ -130,8 +137,21 @@ class DuplicatesQuestion(QDialog): if x.checkState(0) == Qt.Checked: 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__': - from PyQt4.Qt import QApplication from calibre.ebooks.metadata.book.base import Metadata as M from calibre.library import db