mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix delete bug in library view and apply search after sort.
This commit is contained in:
parent
d8c8b1703b
commit
4ea00e817a
@ -13,7 +13,7 @@
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
''' E-book management software'''
|
||||
__version__ = "0.3.90"
|
||||
__version__ = "0.3.91"
|
||||
__docformat__ = "epytext"
|
||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||
__appname__ = 'libprs500'
|
||||
|
@ -156,6 +156,7 @@ class FileDialog(QObject):
|
||||
QObject.__init__(self)
|
||||
initialize_file_icon_provider()
|
||||
self.fd = QFileDialog(parent)
|
||||
self.fd.setFileMode(mode)
|
||||
self.fd.setIconProvider(_file_icon_provider)
|
||||
self.fd.setModal(modal)
|
||||
settings = QSettings()
|
||||
|
@ -103,11 +103,12 @@ class BooksModel(QAbstractTableModel):
|
||||
return [ self.index(index.row(), c) for c in range(self.columnCount(None))]
|
||||
|
||||
def delete_books(self, indices):
|
||||
rows = [ i.row() for i in indices ]
|
||||
for row in rows:
|
||||
ids = [ self.id(i) for i in indices ]
|
||||
for id in ids:
|
||||
row = self.db.index(id)
|
||||
self.beginRemoveRows(QModelIndex(), row, row)
|
||||
self.db.delete_books(rows)
|
||||
self.endRemoveRows()
|
||||
self.db.delete_book(id)
|
||||
self.endRemoveRows()
|
||||
self.emit(SIGNAL('deleted()'))
|
||||
|
||||
def search_tokens(self, text):
|
||||
@ -139,6 +140,7 @@ class BooksModel(QAbstractTableModel):
|
||||
return
|
||||
ascending = order == Qt.AscendingOrder
|
||||
self.db.refresh(self.cols[col], ascending)
|
||||
self.research()
|
||||
self.reset()
|
||||
self.sorted_on = (col, order)
|
||||
|
||||
|
@ -64,6 +64,8 @@ class Main(QObject, Ui_MainWindow):
|
||||
####################### Location View ########################
|
||||
QObject.connect(self.location_view, SIGNAL('location_selected(PyQt_PyObject)'),
|
||||
self.location_selected)
|
||||
QObject.connect(self.stack, SIGNAL('currentChanged(int)'),
|
||||
self.location_view.location_changed)
|
||||
|
||||
####################### Vanity ########################
|
||||
self.vanity_template = self.vanity.text().arg(__version__)
|
||||
|
@ -30,6 +30,7 @@ class LocationModel(QAbstractListModel):
|
||||
'Reader\n%s available',
|
||||
'Card\n%s available']
|
||||
self.free = [-1, -1]
|
||||
self.highlight_row = 0
|
||||
|
||||
def rowCount(self, parent):
|
||||
return 1 + sum([1 for i in self.free if i >= 0])
|
||||
@ -46,7 +47,7 @@ class LocationModel(QAbstractListModel):
|
||||
elif role == Qt.SizeHintRole:
|
||||
if row == 1:
|
||||
return QVariant(QSize(150, 65))
|
||||
elif role == Qt.FontRole:
|
||||
elif role == Qt.FontRole and row == self.highlight_row:
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
data = QVariant(font)
|
||||
@ -62,6 +63,10 @@ class LocationModel(QAbstractListModel):
|
||||
self.free[1] = -1
|
||||
self.reset()
|
||||
|
||||
def location_changed(self, row):
|
||||
self.highlight_row = row
|
||||
self.reset()
|
||||
|
||||
class LocationView(QListView):
|
||||
|
||||
def __init__(self, parent):
|
||||
@ -70,10 +75,13 @@ class LocationView(QListView):
|
||||
self.reset()
|
||||
QObject.connect(self.selectionModel(), SIGNAL('currentChanged(QModelIndex, QModelIndex)'), self.current_changed)
|
||||
|
||||
|
||||
def current_changed(self, current, previous):
|
||||
i = current.row()
|
||||
location = 'library' if i == 0 else 'main' if i == 1 else 'card'
|
||||
self.emit(SIGNAL('location_selected(PyQt_PyObject)'), location)
|
||||
|
||||
def location_changed(self, row):
|
||||
if 0 <= row and row <= 2:
|
||||
self.model().location_changed(row)
|
||||
|
||||
|
||||
|
@ -589,7 +589,6 @@ class LibraryDatabase(object):
|
||||
order = 'DESC'
|
||||
|
||||
|
||||
self.cache = self.conn.execute('select * from meta order by size').fetchall()
|
||||
self.cache = self.conn.execute('SELECT * from meta ORDER BY '+field+' '
|
||||
+order).fetchall()
|
||||
self.data = self.cache
|
||||
@ -882,16 +881,20 @@ class LibraryDatabase(object):
|
||||
self.conn.commit()
|
||||
|
||||
|
||||
def delete_books(self, indices):
|
||||
def index(self, id, cache=False):
|
||||
data = self.cache if cache else self.data
|
||||
for i in range(len(data)):
|
||||
if data[i][0] == id:
|
||||
return i
|
||||
|
||||
def delete_book(self, id):
|
||||
'''
|
||||
Removes books from self.cache, self.data and underlying database.
|
||||
Removes book from self.cache, self.data and underlying database.
|
||||
'''
|
||||
ids = [ self.id(i) for i in indices ]
|
||||
cache_indices = [ idx for idx in range(len(self.cache)-1, -1, -1) if self.cache[idx][0] in ids ]
|
||||
for idx in cache_indices:
|
||||
self.cache[idx:idx+1] = []
|
||||
for idx in indices:
|
||||
self.data[idx:idx+1] = []
|
||||
for id in ids:
|
||||
self.conn.execute('DELETE FROM books WHERE id=?', (id,))
|
||||
try:
|
||||
self.cache.pop(self.index(id, cache=True))
|
||||
self.data.pop(self.index(id, cache=False))
|
||||
except TypeError: #If data and cache are the same object
|
||||
pass
|
||||
self.conn.execute('DELETE FROM books WHERE id=?', (id,))
|
||||
self.conn.commit()
|
Loading…
x
Reference in New Issue
Block a user