diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index 0455f75043..5f9e58d7b8 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -6,6 +6,7 @@ __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' from functools import partial +from collections import Counter from PyQt4.Qt import QObject, QTimer @@ -117,13 +118,14 @@ class DeleteAction(InterfaceAction): def _get_selected_formats(self, msg, ids): from calibre.gui2.dialogs.select_formats import SelectFormats - fmts = set([]) + c = Counter() db = self.gui.library_view.model().db for x in ids: fmts_ = db.formats(x, index_is_id=True, verify_formats=False) if fmts_: - fmts.update(frozenset([x.lower() for x in fmts_.split(',')])) - d = SelectFormats(list(sorted(fmts)), msg, parent=self.gui) + for x in frozenset([x.lower() for x in fmts_.split(',')]): + c[x] += 1 + d = SelectFormats(c, msg, parent=self.gui) if d.exec_() != d.Accepted: return None return d.selected_formats diff --git a/src/calibre/gui2/dialogs/select_formats.py b/src/calibre/gui2/dialogs/select_formats.py index aea56ad196..814051479b 100644 --- a/src/calibre/gui2/dialogs/select_formats.py +++ b/src/calibre/gui2/dialogs/select_formats.py @@ -14,9 +14,10 @@ from calibre.gui2 import NONE, file_icon_provider class Formats(QAbstractListModel): - def __init__(self, fmts): + def __init__(self, fmt_count): QAbstractListModel.__init__(self) - self.fmts = sorted(fmts) + self.fmts = sorted(set(fmt_count)) + self.counts = fmt_count self.fi = file_icon_provider() def rowCount(self, parent): @@ -25,9 +26,17 @@ class Formats(QAbstractListModel): def data(self, index, role): row = index.row() if role == Qt.DisplayRole: - return QVariant(self.fmts[row].upper()) + fmt = self.fmts[row] + count = self.counts[fmt] + return QVariant('%s [%d]'%(fmt.upper(), count)) if role == Qt.DecorationRole: return QVariant(self.fi.icon_from_ext(self.fmts[row].lower())) + if role == Qt.ToolTipRole: + fmt = self.fmts[row] + count = self.counts[fmt] + return QVariant( + _('The are %(count)d book(s) with the %(fmt)s format')%dict( + count=count, fmt=fmt.upper())) return NONE def flags(self, index): @@ -38,7 +47,7 @@ class Formats(QAbstractListModel): class SelectFormats(QDialog): - def __init__(self, fmt_list, msg, single=False, parent=None): + def __init__(self, fmt_count, msg, single=False, parent=None): QDialog.__init__(self, parent) self._l = QVBoxLayout(self) self.setLayout(self._l) @@ -46,7 +55,7 @@ class SelectFormats(QDialog): self._m = QLabel(msg) self._m.setWordWrap(True) self._l.addWidget(self._m) - self.formats = Formats(fmt_list) + self.formats = Formats(fmt_count) self.fview = QListView(self) self._l.addWidget(self.fview) self.fview.setModel(self.formats)