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