mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Don't resort when adding books to library. Fixes #1023
This commit is contained in:
parent
3502579474
commit
c66ea072e9
@ -168,6 +168,11 @@ class BooksModel(QAbstractTableModel):
|
|||||||
|
|
||||||
def search_tokens(self, text):
|
def search_tokens(self, text):
|
||||||
return text_to_tokens(text)
|
return text_to_tokens(text)
|
||||||
|
|
||||||
|
def books_added(self, num):
|
||||||
|
if num > 0:
|
||||||
|
self.beginInsertRows(QModelIndex(), 0, num-1)
|
||||||
|
self.endInsertRows()
|
||||||
|
|
||||||
def search(self, text, refinement, reset=True):
|
def search(self, text, refinement, reset=True):
|
||||||
tokens, OR = self.search_tokens(text)
|
tokens, OR = self.search_tokens(text)
|
||||||
|
@ -529,16 +529,18 @@ in which you want to store your books files. Any existing books will be automati
|
|||||||
paths[i] = path
|
paths[i] = path
|
||||||
else:
|
else:
|
||||||
formats[i] = 'zip'
|
formats[i] = 'zip'
|
||||||
duplicates = model.add_books(paths, formats, metadata)
|
duplicates, number_added = model.add_books(paths, formats, metadata)
|
||||||
if duplicates:
|
if duplicates:
|
||||||
files = _('<p>Books with the same title as the following already exist in the database. Add them anyway?<ul>')
|
files = _('<p>Books with the same title as the following already exist in the database. Add them anyway?<ul>')
|
||||||
for mi in duplicates[2]:
|
for mi in duplicates[2]:
|
||||||
files += '<li>'+mi.title+'</li>\n'
|
files += '<li>'+mi.title+'</li>\n'
|
||||||
d = WarningDialog(_('Duplicates found!'), _('Duplicates found!'), files+'</ul></p>', parent=self)
|
d = WarningDialog(_('Duplicates found!'), _('Duplicates found!'), files+'</ul></p>', parent=self)
|
||||||
if d.exec_() == QDialog.Accepted:
|
if d.exec_() == QDialog.Accepted:
|
||||||
model.add_books(*duplicates, **dict(add_duplicates=True))
|
num = model.add_books(*duplicates, **dict(add_duplicates=True))[1]
|
||||||
self.library_view.sortByColumn(3, Qt.DescendingOrder)
|
number_added += num
|
||||||
model.research()
|
#self.library_view.sortByColumn(3, Qt.DescendingOrder)
|
||||||
|
#model.research()
|
||||||
|
model.books_added(number_added)
|
||||||
else:
|
else:
|
||||||
self.upload_books(paths, names, infos, on_card=on_card)
|
self.upload_books(paths, names, infos, on_card=on_card)
|
||||||
|
|
||||||
|
@ -48,6 +48,7 @@ class CoverCache(QThread):
|
|||||||
self.load_queue_lock = QReadWriteLock(QReadWriteLock.Recursive)
|
self.load_queue_lock = QReadWriteLock(QReadWriteLock.Recursive)
|
||||||
self.cache = {}
|
self.cache = {}
|
||||||
self.cache_lock = QReadWriteLock()
|
self.cache_lock = QReadWriteLock()
|
||||||
|
self.id_map_stale = True
|
||||||
self.keep_running = True
|
self.keep_running = True
|
||||||
|
|
||||||
def build_id_map(self):
|
def build_id_map(self):
|
||||||
@ -61,6 +62,7 @@ class CoverCache(QThread):
|
|||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
self.id_map_lock.unlock()
|
self.id_map_lock.unlock()
|
||||||
|
self.id_map_stale = False
|
||||||
|
|
||||||
|
|
||||||
def set_cache(self, ids):
|
def set_cache(self, ids):
|
||||||
@ -80,9 +82,9 @@ class CoverCache(QThread):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while self.keep_running:
|
while self.keep_running:
|
||||||
if self.id_map is None:
|
if self.id_map is None or self.id_map_stale:
|
||||||
self.build_id_map()
|
self.build_id_map()
|
||||||
while True:
|
while True: # Load images from the load queue
|
||||||
self.load_queue_lock.lockForWrite()
|
self.load_queue_lock.lockForWrite()
|
||||||
try:
|
try:
|
||||||
id = self.load_queue.popleft()
|
id = self.load_queue.popleft()
|
||||||
@ -102,6 +104,8 @@ class CoverCache(QThread):
|
|||||||
self.id_map_lock.lockForRead()
|
self.id_map_lock.lockForRead()
|
||||||
if id in self.id_map.keys():
|
if id in self.id_map.keys():
|
||||||
path = self.id_map[id]
|
path = self.id_map[id]
|
||||||
|
else:
|
||||||
|
self.id_map_stale = True
|
||||||
self.id_map_lock.unlock()
|
self.id_map_lock.unlock()
|
||||||
if path and os.access(path, os.R_OK):
|
if path and os.access(path, os.R_OK):
|
||||||
try:
|
try:
|
||||||
@ -215,6 +219,15 @@ class ResultCache(object):
|
|||||||
self._data[id] = conn.execute('SELECT * from meta WHERE id=?', (id,)).fetchone()
|
self._data[id] = conn.execute('SELECT * from meta WHERE id=?', (id,)).fetchone()
|
||||||
return map(self.row, ids)
|
return map(self.row, ids)
|
||||||
|
|
||||||
|
def books_added(self, ids, conn):
|
||||||
|
if not ids:
|
||||||
|
return
|
||||||
|
self._data.extend(repeat(None, max(ids)-len(self._data)+2))
|
||||||
|
for id in ids:
|
||||||
|
self._data[id] = conn.execute('SELECT * from meta WHERE id=?', (id,)).fetchone()
|
||||||
|
self._map[0:0] = ids
|
||||||
|
self._map_filtered[0:0] = ids
|
||||||
|
|
||||||
def refresh(self, db, field, ascending):
|
def refresh(self, db, field, ascending):
|
||||||
field = field.lower()
|
field = field.lower()
|
||||||
method = getattr(self, 'sort_on_' + self.METHOD_MAP[field])
|
method = getattr(self, 'sort_on_' + self.METHOD_MAP[field])
|
||||||
@ -867,13 +880,15 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
if not hasattr(path, 'read'):
|
if not hasattr(path, 'read'):
|
||||||
stream.close()
|
stream.close()
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
if ids:
|
||||||
|
self.data.books_added(ids, self.conn)
|
||||||
if duplicates:
|
if duplicates:
|
||||||
paths = tuple(duplicate[0] for duplicate in duplicates)
|
paths = tuple(duplicate[0] for duplicate in duplicates)
|
||||||
formats = tuple(duplicate[1] for duplicate in duplicates)
|
formats = tuple(duplicate[1] for duplicate in duplicates)
|
||||||
metadata = tuple(duplicate[2] for duplicate in duplicates)
|
metadata = tuple(duplicate[2] for duplicate in duplicates)
|
||||||
uris = tuple(duplicate[3] for duplicate in duplicates)
|
uris = tuple(duplicate[3] for duplicate in duplicates)
|
||||||
return (paths, formats, metadata, uris)
|
return (paths, formats, metadata, uris), len(ids)
|
||||||
return None
|
return None, len(ids)
|
||||||
|
|
||||||
def import_book(self, mi, formats):
|
def import_book(self, mi, formats):
|
||||||
series_index = 1 if mi.series_index is None else mi.series_index
|
series_index = 1 if mi.series_index is None else mi.series_index
|
||||||
@ -890,6 +905,7 @@ class LibraryDatabase2(LibraryDatabase):
|
|||||||
stream = open(path, 'rb')
|
stream = open(path, 'rb')
|
||||||
self.add_format(id, ext, stream, index_is_id=True)
|
self.add_format(id, ext, stream, index_is_id=True)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
self.data.books_added([id], self.conn)
|
||||||
self.notify('add', [id])
|
self.notify('add', [id])
|
||||||
|
|
||||||
def move_library_to(self, newloc):
|
def move_library_to(self, newloc):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user