From b393dbf62de4eff5224621a25734e9002aaca1be Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 17 Jun 2010 10:26:46 +0100 Subject: [PATCH 1/2] Change delete matching to use a checkbox. Make sorting work on authors and titles. Add a date column. --- src/calibre/gui2/actions.py | 4 +- .../dialogs/delete_matching_from_device.py | 72 +++++++++++++++---- .../dialogs/delete_matching_from_device.ui | 4 ++ 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/src/calibre/gui2/actions.py b/src/calibre/gui2/actions.py index 38ba922274..32552dde71 100644 --- a/src/calibre/gui2/actions.py +++ b/src/calibre/gui2/actions.py @@ -480,8 +480,8 @@ class DeleteAction(object): # {{{ return ids = self._get_selected_ids() if not ids: - #For some reason the delete dialog reports no selection, so - #we need to do it here + #_get_selected_ids shows a dialog box if nothing is selected, so we + #do not need to show one here return to_delete = {} some_to_delete = False diff --git a/src/calibre/gui2/dialogs/delete_matching_from_device.py b/src/calibre/gui2/dialogs/delete_matching_from_device.py index 63ee9c4012..dbac2fe4ad 100644 --- a/src/calibre/gui2/dialogs/delete_matching_from_device.py +++ b/src/calibre/gui2/dialogs/delete_matching_from_device.py @@ -3,22 +3,53 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' __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.gui2.dialogs.delete_matching_from_device_ui import Ui_DeleteMatchingFromDeviceDialog +from calibre import strftime +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): def __init__(self, text): QTableWidgetItem.__init__(self, text) self.setFlags(Qt.ItemIsEnabled) + self.sort = text.lower() def __ge__(self, other): - return unicode(self.text()).lower() >= unicode(other.text()).lower() + return self.sort >= other.sort 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): @@ -27,13 +58,16 @@ class DeleteMatchingFromDeviceDialog(QDialog, Ui_DeleteMatchingFromDeviceDialog) Ui_DeleteMatchingFromDeviceDialog.__init__(self) self.setupUi(self) + self.explanation.setText('

'+_('All checked books will be ' + 'permanently deleted from your ' + 'device. Please verify the list.'+'

')) self.buttonBox.accepted.connect(self.accepted) self.table.cellClicked.connect(self.cell_clicked) self.table.setSelectionMode(QAbstractItemView.NoSelection) self.table.setColumnCount(5) - self.table.setHorizontalHeaderLabels(['', _('Location'), _('Title'), - _('Author'), _('Format')]) - del_icon = QIcon(I('list_remove.svg')) + self.table.setHorizontalHeaderLabels( + ['', _('Location'), _('Title'), + _('Author'), _('Date'), _('Format')]) rows = 0 for card in items: rows += len(items[card][1]) @@ -42,26 +76,34 @@ class DeleteMatchingFromDeviceDialog(QDialog, Ui_DeleteMatchingFromDeviceDialog) for card in items: (model,books) = items[card] 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)) self.table.setItem(row, 0, item) self.table.setItem(row, 1, tableItem(card)) - self.table.setItem(row, 2, tableItem(book.title)) - self.table.setItem(row, 3, tableItem(authors_to_string(book.authors))) - self.table.setItem(row, 4, tableItem(book.path.rpartition('.')[2])) + self.table.setItem(row, 2, titleTableItem(book.title)) + self.table.setItem(row, 3, authorTableItem(book)) + self.table.setItem(row, 4, dateTableItem(book.datetime)) + self.table.setItem(row, 5, tableItem(book.path.rpartition('.')[2])) row += 1 + self.table.setCurrentCell(0, 1) self.table.resizeColumnsToContents() self.table.setSortingEnabled(True) 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): self.result = [] 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() path = unicode(path) self.result.append((model, id, path)) return - def cell_clicked(self, row, col): - if col == 0: - self.table.removeRow(row) \ No newline at end of file diff --git a/src/calibre/gui2/dialogs/delete_matching_from_device.ui b/src/calibre/gui2/dialogs/delete_matching_from_device.ui index eabd4d6346..fec08e5b00 100644 --- a/src/calibre/gui2/dialogs/delete_matching_from_device.ui +++ b/src/calibre/gui2/dialogs/delete_matching_from_device.ui @@ -20,6 +20,10 @@ Delete from device + + + + From 544b4648e115ccda84344bf2aec0dde18d661973 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 17 Jun 2010 11:08:31 +0100 Subject: [PATCH 2/2] Fix bug #5856 --- src/calibre/gui2/search_box.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index f34c52d221..848c3f2238 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -90,14 +90,18 @@ class SearchBox2(QComboBox): self.help_text = help_text self.colorize = colorize self.clear_to_help() - self.connect(self, SIGNAL('editTextChanged(QString)'), self.text_edited_slot) def normalize_state(self): - self.setEditText('') - self.line_edit.setStyleSheet( - 'QLineEdit { color: black; background-color: %s; }' % - self.normal_background) - self.help_state = False + if self.help_state: + self.setEditText('') + self.line_edit.setStyleSheet( + 'QLineEdit { color: black; background-color: %s; }' % + self.normal_background) + self.help_state = False + else: + self.line_edit.setStyleSheet( + 'QLineEdit { color: black; background-color: %s; }' % + self.normal_background) def clear_to_help(self): if self.help_state: @@ -131,17 +135,15 @@ class SearchBox2(QComboBox): self.line_edit.setStyleSheet('QLineEdit { color: black; background-color: %s; }' % col) def key_pressed(self, event): - if self.help_state: - self.normalize_state() + self.normalize_state() if not self.as_you_type: if event.key() in (Qt.Key_Return, Qt.Key_Enter): self.do_search() + else: + self.timer = self.startTimer(self.__class__.INTERVAL) def mouse_released(self, event): - if self.help_state: - self.normalize_state() - - def text_edited_slot(self, text): + self.normalize_state() if self.as_you_type: self.timer = self.startTimer(self.__class__.INTERVAL)