Implement #6450 (Bookmarks in Calibre's Viewer)

This commit is contained in:
Kovid Goyal 2010-09-08 17:18:47 -06:00
parent 5b1d98aba9
commit 31db5a16dd

View File

@ -173,6 +173,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
self.pending_anchor = None self.pending_anchor = None
self.pending_reference = None self.pending_reference = None
self.pending_bookmark = None self.pending_bookmark = None
self.existing_bookmarks= []
self.selected_text = None self.selected_text = None
self.read_settings() self.read_settings()
self.dictionary_box.hide() self.dictionary_box.hide()
@ -415,15 +416,6 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
self.action_font_size_smaller.setEnabled(self.view.multiplier() > 0.2) self.action_font_size_smaller.setEnabled(self.view.multiplier() > 0.2)
self.set_page_number(frac) self.set_page_number(frac)
def bookmark(self, *args):
title, ok = QInputDialog.getText(self, _('Add bookmark'), _('Enter title for bookmark:'))
title = unicode(title).strip()
if ok and title:
pos = self.view.bookmark()
bookmark = '%d#%s'%(self.current_index, pos)
self.iterator.add_bookmark((title, bookmark))
self.set_bookmarks(self.iterator.bookmarks)
def find(self, text, repeat=False, backwards=False): def find(self, text, repeat=False, backwards=False):
if not text: if not text:
@ -539,15 +531,34 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
getattr(self, o).setEnabled(False) getattr(self, o).setEnabled(False)
self.setCursor(Qt.BusyCursor) self.setCursor(Qt.BusyCursor)
def bookmark(self, *args):
num = 1
bm = None
while True:
bm = _('Bookmark #%d')%num
if bm not in self.existing_bookmarks:
break
num += 1
title, ok = QInputDialog.getText(self, _('Add bookmark'),
_('Enter title for bookmark:'), text=bm)
title = unicode(title).strip()
if ok and title:
pos = self.view.bookmark()
bookmark = '%d#%s'%(self.current_index, pos)
self.iterator.add_bookmark((title, bookmark))
self.set_bookmarks(self.iterator.bookmarks)
def set_bookmarks(self, bookmarks): def set_bookmarks(self, bookmarks):
self.bookmarks_menu.clear() self.bookmarks_menu.clear()
self.bookmarks_menu.addAction(_("Manage Bookmarks"), self.manage_bookmarks) self.bookmarks_menu.addAction(_("Manage Bookmarks"), self.manage_bookmarks)
self.bookmarks_menu.addSeparator() self.bookmarks_menu.addSeparator()
current_page = None current_page = None
self.existing_bookmarks = []
for bm in bookmarks: for bm in bookmarks:
if bm[0] == 'calibre_current_page_bookmark': if bm[0] == 'calibre_current_page_bookmark':
current_page = bm current_page = bm
else: else:
self.existing_bookmarks.append(bm[0])
self.bookmarks_menu.addAction(bm[0], partial(self.goto_bookmark, bm)) self.bookmarks_menu.addAction(bm[0], partial(self.goto_bookmark, bm))
return current_page return current_page