diff --git a/src/calibre/ebooks/epub/from_html.py b/src/calibre/ebooks/epub/from_html.py index ae2fa5eae1..dd52388763 100644 --- a/src/calibre/ebooks/epub/from_html.py +++ b/src/calibre/ebooks/epub/from_html.py @@ -204,7 +204,7 @@ TITLEPAGE = '''\
- cover + cover
diff --git a/src/calibre/ebooks/epub/iterator.py b/src/calibre/ebooks/epub/iterator.py index 127af6e55f..d47630a970 100644 --- a/src/calibre/ebooks/epub/iterator.py +++ b/src/calibre/ebooks/epub/iterator.py @@ -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(): diff --git a/src/calibre/gui2/library.py b/src/calibre/gui2/library.py index c529b55879..f2571c5de7 100644 --- a/src/calibre/gui2/library.py +++ b/src/calibre/gui2/library.py @@ -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) diff --git a/src/calibre/gui2/main.py b/src/calibre/gui2/main.py index 4c71ac2dd7..716406d5a6 100644 --- a/src/calibre/gui2/main.py +++ b/src/calibre/gui2/main.py @@ -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: diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index 224077072e..caf2011a75 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -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' diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 0fe8ef1c6a..9f5dae70dc 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -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