Show number of books in library

This commit is contained in:
Kovid Goyal 2008-12-10 13:39:03 -08:00
parent fa7a8785a7
commit 8e114c3efa
6 changed files with 29 additions and 9 deletions

View File

@ -204,7 +204,7 @@ TITLEPAGE = '''\
</head>
<body>
<div>
<img src="%s" alt="cover" />
<img src="%s" alt="cover" style="height: 100%%" />
</div>
</body>
</html>

View File

@ -168,7 +168,8 @@ class EbookIterator(object):
if bookmarks is None:
bookmarks = self.bookmarks
dat = self.serialize_bookmarks(bookmarks)
if os.path.splitext(self.pathtoebook)[1].lower() == '.epub':
if os.path.splitext(self.pathtoebook)[1].lower() == '.epub' and \
os.access(self.pathtoebook, os.R_OK):
zf = open(self.pathtoebook, 'r+b')
zipf = ZipFile(zf, mode='a')
for name in zipf.namelist():

View File

@ -163,11 +163,18 @@ class BooksModel(QAbstractTableModel):
self.reset()
def add_books(self, paths, formats, metadata, uris=[], add_duplicates=False):
return self.db.add_books(paths, formats, metadata, uris,
ret = self.db.add_books(paths, formats, metadata, uris,
add_duplicates=add_duplicates)
self.count_changed()
return ret
def add_news(self, path, recipe):
return self.db.add_news(path, recipe)
ret = self.db.add_news(path, recipe)
self.count_changed()
return ret
def count_changed(self, *args):
self.emit(SIGNAL('count_changed(int)'), self.db.count())
def row_indices(self, index):
''' Return list indices of all cells in index.row()'''
@ -189,9 +196,11 @@ class BooksModel(QAbstractTableModel):
self.beginRemoveRows(QModelIndex(), row, row)
self.db.delete_book(id)
self.endRemoveRows()
self.count_changed()
self.clear_caches()
self.reset()
def delete_books_by_id(self, ids):
for id in ids:
try:
@ -203,12 +212,14 @@ class BooksModel(QAbstractTableModel):
self.db.delete_book(id)
if row > -1:
self.endRemoveRows()
self.count_changed()
self.clear_caches()
def books_added(self, num):
if num > 0:
self.beginInsertRows(QModelIndex(), 0, num-1)
self.endInsertRows()
self.count_changed()
def search(self, text, refinement, reset=True):
self.db.search(text)

View File

@ -297,6 +297,8 @@ class Main(MainWindow, Ui_MainWindow):
self.connect(self.status_bar.tag_view_button, SIGNAL('toggled(bool)'), self.toggle_tags_view)
self.connect(self.search, SIGNAL('search(PyQt_PyObject, PyQt_PyObject)'),
self.tags_view.model().reinit)
self.connect(self.library_view.model(), SIGNAL('count_changed(int)'), self.location_view.count_changed)
self.library_view.model().count_changed()
########################### Cover Flow ################################
self.cover_flow = None
if CoverFlow is not None:

View File

@ -136,10 +136,11 @@ class LocationModel(QAbstractListModel):
self.icons = [QVariant(QIcon(':/library')),
QVariant(QIcon(':/images/reader.svg')),
QVariant(QIcon(':/images/sd.svg'))]
self.text = [_('Library'),
self.text = [_('Library\n%d\nbooks'),
_('Reader\n%s\navailable'),
_('Card\n%s\navailable')]
self.free = [-1, -1]
self.count = 0
self.highlight_row = 0
self.tooltips = [
_('Click to see the list of books available on your computer'),
@ -155,7 +156,7 @@ class LocationModel(QAbstractListModel):
data = NONE
if role == Qt.DisplayRole:
text = self.text[row]%(human_readable(self.free[row-1])) if row > 0 \
else self.text[row]
else self.text[row]%self.count
data = QVariant(text)
elif role == Qt.DecorationRole:
data = self.icons[row]
@ -192,6 +193,10 @@ class LocationView(QListView):
QObject.connect(self.selectionModel(), SIGNAL('currentChanged(QModelIndex, QModelIndex)'), self.current_changed)
self.setCursor(Qt.PointingHandCursor)
def count_changed(self, new_count):
self.model().count = new_count
self.model().reset()
def current_changed(self, current, previous):
i = current.row()
location = 'library' if i == 0 else 'main' if i == 1 else 'card'

View File

@ -255,6 +255,9 @@ class ResultCache(SearchQueryParser):
if id in self._map: self._map.remove(id)
if id in self._map_filtered: self._map_filtered.remove(id)
def count(self):
return len(self._map)
def refresh(self, db, field=None, ascending=True):
temp = db.conn.get('SELECT * FROM meta')
self._data = list(itertools.repeat(None, temp[-1][0]+2)) if temp else []
@ -375,6 +378,7 @@ class LibraryDatabase2(LibraryDatabase):
self.refresh_ids = functools.partial(self.data.refresh_ids, self.conn)
self.row = self.data.row
self.has_id = self.data.has_id
self.count = self.data.count
self.refresh()
@ -1191,9 +1195,6 @@ class LibraryDatabase2(LibraryDatabase):
for i in iter(self):
yield i['id']
def count(self):
return len(self.data._map)
def get_data_as_dict(self, prefix=None, authors_as_string=False):
'''
Return all metadata stored in the database as a dict. Includes paths to