mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
When deleting books of a specific format, show the number of books with each format available
This commit is contained in:
parent
5d28e4bc1d
commit
370bc1992c
@ -6,6 +6,7 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
from PyQt4.Qt import QObject, QTimer
|
from PyQt4.Qt import QObject, QTimer
|
||||||
|
|
||||||
@ -117,13 +118,14 @@ class DeleteAction(InterfaceAction):
|
|||||||
|
|
||||||
def _get_selected_formats(self, msg, ids):
|
def _get_selected_formats(self, msg, ids):
|
||||||
from calibre.gui2.dialogs.select_formats import SelectFormats
|
from calibre.gui2.dialogs.select_formats import SelectFormats
|
||||||
fmts = set([])
|
c = Counter()
|
||||||
db = self.gui.library_view.model().db
|
db = self.gui.library_view.model().db
|
||||||
for x in ids:
|
for x in ids:
|
||||||
fmts_ = db.formats(x, index_is_id=True, verify_formats=False)
|
fmts_ = db.formats(x, index_is_id=True, verify_formats=False)
|
||||||
if fmts_:
|
if fmts_:
|
||||||
fmts.update(frozenset([x.lower() for x in fmts_.split(',')]))
|
for x in frozenset([x.lower() for x in fmts_.split(',')]):
|
||||||
d = SelectFormats(list(sorted(fmts)), msg, parent=self.gui)
|
c[x] += 1
|
||||||
|
d = SelectFormats(c, msg, parent=self.gui)
|
||||||
if d.exec_() != d.Accepted:
|
if d.exec_() != d.Accepted:
|
||||||
return None
|
return None
|
||||||
return d.selected_formats
|
return d.selected_formats
|
||||||
|
@ -14,9 +14,10 @@ from calibre.gui2 import NONE, file_icon_provider
|
|||||||
|
|
||||||
class Formats(QAbstractListModel):
|
class Formats(QAbstractListModel):
|
||||||
|
|
||||||
def __init__(self, fmts):
|
def __init__(self, fmt_count):
|
||||||
QAbstractListModel.__init__(self)
|
QAbstractListModel.__init__(self)
|
||||||
self.fmts = sorted(fmts)
|
self.fmts = sorted(set(fmt_count))
|
||||||
|
self.counts = fmt_count
|
||||||
self.fi = file_icon_provider()
|
self.fi = file_icon_provider()
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
@ -25,9 +26,17 @@ class Formats(QAbstractListModel):
|
|||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
row = index.row()
|
row = index.row()
|
||||||
if role == Qt.DisplayRole:
|
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:
|
if role == Qt.DecorationRole:
|
||||||
return QVariant(self.fi.icon_from_ext(self.fmts[row].lower()))
|
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
|
return NONE
|
||||||
|
|
||||||
def flags(self, index):
|
def flags(self, index):
|
||||||
@ -38,7 +47,7 @@ class Formats(QAbstractListModel):
|
|||||||
|
|
||||||
class SelectFormats(QDialog):
|
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)
|
QDialog.__init__(self, parent)
|
||||||
self._l = QVBoxLayout(self)
|
self._l = QVBoxLayout(self)
|
||||||
self.setLayout(self._l)
|
self.setLayout(self._l)
|
||||||
@ -46,7 +55,7 @@ class SelectFormats(QDialog):
|
|||||||
self._m = QLabel(msg)
|
self._m = QLabel(msg)
|
||||||
self._m.setWordWrap(True)
|
self._m.setWordWrap(True)
|
||||||
self._l.addWidget(self._m)
|
self._l.addWidget(self._m)
|
||||||
self.formats = Formats(fmt_list)
|
self.formats = Formats(fmt_count)
|
||||||
self.fview = QListView(self)
|
self.fview = QListView(self)
|
||||||
self._l.addWidget(self.fview)
|
self._l.addWidget(self.fview)
|
||||||
self.fview.setModel(self.formats)
|
self.fview.setModel(self.formats)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user