mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Change delete matching to use a checkbox. Make sorting work on authors and titles. Add a date column.
This commit is contained in:
parent
146daab864
commit
b393dbf62d
@ -480,8 +480,8 @@ class DeleteAction(object): # {{{
|
|||||||
return
|
return
|
||||||
ids = self._get_selected_ids()
|
ids = self._get_selected_ids()
|
||||||
if not ids:
|
if not ids:
|
||||||
#For some reason the delete dialog reports no selection, so
|
#_get_selected_ids shows a dialog box if nothing is selected, so we
|
||||||
#we need to do it here
|
#do not need to show one here
|
||||||
return
|
return
|
||||||
to_delete = {}
|
to_delete = {}
|
||||||
some_to_delete = False
|
some_to_delete = False
|
||||||
|
@ -3,22 +3,53 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
|
|
||||||
from PyQt4.Qt import Qt, QDialog, QTableWidgetItem, QAbstractItemView, QIcon
|
from PyQt4.Qt import Qt, QDialog, QTableWidgetItem, QAbstractItemView
|
||||||
|
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre import strftime
|
||||||
from calibre.gui2.dialogs.delete_matching_from_device_ui import Ui_DeleteMatchingFromDeviceDialog
|
from calibre.ebooks.metadata import authors_to_string, authors_to_sort_string, \
|
||||||
|
title_sort
|
||||||
|
from calibre.gui2.dialogs.delete_matching_from_device_ui import \
|
||||||
|
Ui_DeleteMatchingFromDeviceDialog
|
||||||
|
from calibre.utils.date import UNDEFINED_DATE
|
||||||
|
|
||||||
class tableItem(QTableWidgetItem):
|
class tableItem(QTableWidgetItem):
|
||||||
|
|
||||||
def __init__(self, text):
|
def __init__(self, text):
|
||||||
QTableWidgetItem.__init__(self, text)
|
QTableWidgetItem.__init__(self, text)
|
||||||
self.setFlags(Qt.ItemIsEnabled)
|
self.setFlags(Qt.ItemIsEnabled)
|
||||||
|
self.sort = text.lower()
|
||||||
|
|
||||||
def __ge__(self, other):
|
def __ge__(self, other):
|
||||||
return unicode(self.text()).lower() >= unicode(other.text()).lower()
|
return self.sort >= other.sort
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
return unicode(self.text()).lower() < unicode(other.text()).lower()
|
return self.sort < other.sort
|
||||||
|
|
||||||
|
class titleTableItem(tableItem):
|
||||||
|
|
||||||
|
def __init__(self, text):
|
||||||
|
tableItem.__init__(self, text)
|
||||||
|
self.sort = title_sort(text.lower())
|
||||||
|
|
||||||
|
class authorTableItem(tableItem):
|
||||||
|
|
||||||
|
def __init__(self, book):
|
||||||
|
tableItem.__init__(self, authors_to_string(book.authors))
|
||||||
|
if book.author_sort is not None:
|
||||||
|
self.sort = book.author_sort.lower()
|
||||||
|
else:
|
||||||
|
self.sort = authors_to_sort_string(book.authors).lower()
|
||||||
|
|
||||||
|
class dateTableItem(tableItem):
|
||||||
|
|
||||||
|
def __init__(self, date):
|
||||||
|
if date is not None:
|
||||||
|
tableItem.__init__(self, strftime('%x', date))
|
||||||
|
self.sort = date
|
||||||
|
else:
|
||||||
|
tableItem.__init__(self, '')
|
||||||
|
self.sort = UNDEFINED_DATE
|
||||||
|
|
||||||
|
|
||||||
class DeleteMatchingFromDeviceDialog(QDialog, Ui_DeleteMatchingFromDeviceDialog):
|
class DeleteMatchingFromDeviceDialog(QDialog, Ui_DeleteMatchingFromDeviceDialog):
|
||||||
|
|
||||||
@ -27,13 +58,16 @@ class DeleteMatchingFromDeviceDialog(QDialog, Ui_DeleteMatchingFromDeviceDialog)
|
|||||||
Ui_DeleteMatchingFromDeviceDialog.__init__(self)
|
Ui_DeleteMatchingFromDeviceDialog.__init__(self)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
|
self.explanation.setText('<p>'+_('All checked books will be '
|
||||||
|
'<b>permanently deleted</b> from your '
|
||||||
|
'device. Please verify the list.'+'</p>'))
|
||||||
self.buttonBox.accepted.connect(self.accepted)
|
self.buttonBox.accepted.connect(self.accepted)
|
||||||
self.table.cellClicked.connect(self.cell_clicked)
|
self.table.cellClicked.connect(self.cell_clicked)
|
||||||
self.table.setSelectionMode(QAbstractItemView.NoSelection)
|
self.table.setSelectionMode(QAbstractItemView.NoSelection)
|
||||||
self.table.setColumnCount(5)
|
self.table.setColumnCount(5)
|
||||||
self.table.setHorizontalHeaderLabels(['', _('Location'), _('Title'),
|
self.table.setHorizontalHeaderLabels(
|
||||||
_('Author'), _('Format')])
|
['', _('Location'), _('Title'),
|
||||||
del_icon = QIcon(I('list_remove.svg'))
|
_('Author'), _('Date'), _('Format')])
|
||||||
rows = 0
|
rows = 0
|
||||||
for card in items:
|
for card in items:
|
||||||
rows += len(items[card][1])
|
rows += len(items[card][1])
|
||||||
@ -42,26 +76,34 @@ class DeleteMatchingFromDeviceDialog(QDialog, Ui_DeleteMatchingFromDeviceDialog)
|
|||||||
for card in items:
|
for card in items:
|
||||||
(model,books) = items[card]
|
(model,books) = items[card]
|
||||||
for (id,book) in books:
|
for (id,book) in books:
|
||||||
item = QTableWidgetItem(del_icon, '')
|
item = QTableWidgetItem()
|
||||||
|
item.setFlags(Qt.ItemIsUserCheckable|Qt.ItemIsEnabled)
|
||||||
|
item.setCheckState(Qt.Checked)
|
||||||
item.setData(Qt.UserRole, (model, id, book.path))
|
item.setData(Qt.UserRole, (model, id, book.path))
|
||||||
self.table.setItem(row, 0, item)
|
self.table.setItem(row, 0, item)
|
||||||
self.table.setItem(row, 1, tableItem(card))
|
self.table.setItem(row, 1, tableItem(card))
|
||||||
self.table.setItem(row, 2, tableItem(book.title))
|
self.table.setItem(row, 2, titleTableItem(book.title))
|
||||||
self.table.setItem(row, 3, tableItem(authors_to_string(book.authors)))
|
self.table.setItem(row, 3, authorTableItem(book))
|
||||||
self.table.setItem(row, 4, tableItem(book.path.rpartition('.')[2]))
|
self.table.setItem(row, 4, dateTableItem(book.datetime))
|
||||||
|
self.table.setItem(row, 5, tableItem(book.path.rpartition('.')[2]))
|
||||||
row += 1
|
row += 1
|
||||||
|
self.table.setCurrentCell(0, 1)
|
||||||
self.table.resizeColumnsToContents()
|
self.table.resizeColumnsToContents()
|
||||||
self.table.setSortingEnabled(True)
|
self.table.setSortingEnabled(True)
|
||||||
self.table.sortByColumn(2, Qt.AscendingOrder)
|
self.table.sortByColumn(2, Qt.AscendingOrder)
|
||||||
|
self.table.setCurrentCell(0, 1)
|
||||||
|
|
||||||
|
def cell_clicked(self, row, col):
|
||||||
|
if col == 0:
|
||||||
|
self.table.setCurrentCell(row, 1)
|
||||||
|
|
||||||
def accepted(self):
|
def accepted(self):
|
||||||
self.result = []
|
self.result = []
|
||||||
for row in range(self.table.rowCount()):
|
for row in range(self.table.rowCount()):
|
||||||
|
if self.table.item(row, 0).checkState() == Qt.Unchecked:
|
||||||
|
continue
|
||||||
(model, id, path) = self.table.item(row, 0).data(Qt.UserRole).toPyObject()
|
(model, id, path) = self.table.item(row, 0).data(Qt.UserRole).toPyObject()
|
||||||
path = unicode(path)
|
path = unicode(path)
|
||||||
self.result.append((model, id, path))
|
self.result.append((model, id, path))
|
||||||
return
|
return
|
||||||
|
|
||||||
def cell_clicked(self, row, col):
|
|
||||||
if col == 0:
|
|
||||||
self.table.removeRow(row)
|
|
@ -20,6 +20,10 @@
|
|||||||
<string>Delete from device</string>
|
<string>Delete from device</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="explanation">
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="table">
|
<widget class="QTableWidget" name="table">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user