mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Import/Export support for booksmarks in the ebook viewer
This commit is contained in:
commit
9533676c22
@ -1,9 +1,12 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
|
|
||||||
|
import cPickle, os
|
||||||
|
|
||||||
from PyQt4.Qt import Qt, QDialog, QAbstractTableModel, QVariant, SIGNAL, \
|
from PyQt4.Qt import Qt, QDialog, QAbstractTableModel, QVariant, SIGNAL, \
|
||||||
QModelIndex, QInputDialog, QLineEdit
|
QModelIndex, QInputDialog, QLineEdit, QFileDialog
|
||||||
|
|
||||||
from calibre.gui2.viewer.bookmarkmanager_ui import Ui_BookmarkManager
|
from calibre.gui2.viewer.bookmarkmanager_ui import Ui_BookmarkManager
|
||||||
from calibre.gui2 import NONE, qstring_to_unicode
|
from calibre.gui2 import NONE, qstring_to_unicode
|
||||||
@ -20,9 +23,13 @@ class BookmarkManager(QDialog, Ui_BookmarkManager):
|
|||||||
self.connect(self.button_revert, SIGNAL('clicked()'), self.set_bookmarks)
|
self.connect(self.button_revert, SIGNAL('clicked()'), self.set_bookmarks)
|
||||||
self.connect(self.button_delete, SIGNAL('clicked()'), self.delete_bookmark)
|
self.connect(self.button_delete, SIGNAL('clicked()'), self.delete_bookmark)
|
||||||
self.connect(self.button_edit, SIGNAL('clicked()'), self.edit_bookmark)
|
self.connect(self.button_edit, SIGNAL('clicked()'), self.edit_bookmark)
|
||||||
|
self.connect(self.button_export, SIGNAL('clicked()'), self.export_bookmarks)
|
||||||
|
self.connect(self.button_import, SIGNAL('clicked()'), self.import_bookmarks)
|
||||||
|
|
||||||
def set_bookmarks(self):
|
def set_bookmarks(self, bookmarks=None):
|
||||||
self._model = BookmarkTableModel(self, self.bookmarks)
|
if bookmarks == None:
|
||||||
|
bookmarks = self.bookmarks[:]
|
||||||
|
self._model = BookmarkTableModel(self, bookmarks)
|
||||||
self.bookmarks_table.setModel(self._model)
|
self.bookmarks_table.setModel(self._model)
|
||||||
|
|
||||||
def delete_bookmark(self):
|
def delete_bookmark(self):
|
||||||
@ -41,6 +48,40 @@ class BookmarkManager(QDialog, Ui_BookmarkManager):
|
|||||||
def get_bookmarks(self):
|
def get_bookmarks(self):
|
||||||
return self._model.bookmarks
|
return self._model.bookmarks
|
||||||
|
|
||||||
|
def export_bookmarks(self):
|
||||||
|
filename = QFileDialog.getSaveFileName(self, _("Export Bookmarks"), '%s%suntitled.pickle' % (os.getcwdu(), os.sep), _("Pickled Bookmarks (*.pickle)"))
|
||||||
|
if filename == '':
|
||||||
|
return
|
||||||
|
|
||||||
|
with open(filename, 'w') as fileobj:
|
||||||
|
cPickle.dump(self._model.bookmarks, fileobj)
|
||||||
|
|
||||||
|
def import_bookmarks(self):
|
||||||
|
filename = QFileDialog.getOpenFileName(self, _("Import Bookmarks"), '%s' % os.getcwdu(), _("Pickled Bookmarks (*.pickle)"))
|
||||||
|
if filename == '':
|
||||||
|
return
|
||||||
|
|
||||||
|
imported = None
|
||||||
|
with open(filename, 'r') as fileobj:
|
||||||
|
imported = cPickle.load(fileobj)
|
||||||
|
|
||||||
|
if imported != None:
|
||||||
|
bad = False
|
||||||
|
try:
|
||||||
|
for bm in imported:
|
||||||
|
if len(bm) != 2:
|
||||||
|
bad = True
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not bad:
|
||||||
|
bookmarks = self._model.bookmarks[:]
|
||||||
|
for bm in imported:
|
||||||
|
if bm not in bookmarks and bm[0] != 'calibre_current_page_bookmark':
|
||||||
|
bookmarks.append(bm)
|
||||||
|
self.set_bookmarks(bookmarks)
|
||||||
|
|
||||||
|
|
||||||
class BookmarkTableModel(QAbstractTableModel):
|
class BookmarkTableModel(QAbstractTableModel):
|
||||||
headers = [_("Name")]
|
headers = [_("Name")]
|
||||||
|
@ -5,15 +5,59 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>451</width>
|
||||||
<height>300</height>
|
<height>363</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle" >
|
<property name="windowTitle" >
|
||||||
<string>Dialog</string>
|
<string>Bookmark Manager</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout" >
|
<layout class="QGridLayout" name="gridLayout" >
|
||||||
<item row="0" column="0" colspan="3" >
|
<item row="0" column="0" >
|
||||||
|
<widget class="QGroupBox" name="groupBox" >
|
||||||
|
<property name="title" >
|
||||||
|
<string>Actions</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" >
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_edit" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Edit</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_delete" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Delete</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_revert" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Reset</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_export" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Export</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_import" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Import</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1" >
|
||||||
<widget class="QTableView" name="bookmarks_table" >
|
<widget class="QTableView" name="bookmarks_table" >
|
||||||
<property name="showDropIndicator" stdset="0" >
|
<property name="showDropIndicator" stdset="0" >
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
@ -29,29 +73,48 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" >
|
<item row="1" column="0" colspan="2" >
|
||||||
<widget class="QPushButton" name="button_revert" >
|
<widget class="QDialogButtonBox" name="buttonBox" >
|
||||||
<property name="text" >
|
<property name="standardButtons" >
|
||||||
<string>Revert</string>
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1" >
|
|
||||||
<widget class="QPushButton" name="button_delete" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Delete</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="2" >
|
|
||||||
<widget class="QPushButton" name="button_edit" >
|
|
||||||
<property name="text" >
|
|
||||||
<string>Edit</string>
|
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>BookmarkManager</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel" >
|
||||||
|
<x>225</x>
|
||||||
|
<y>337</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel" >
|
||||||
|
<x>225</x>
|
||||||
|
<y>181</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>BookmarkManager</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel" >
|
||||||
|
<x>225</x>
|
||||||
|
<y>337</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel" >
|
||||||
|
<x>225</x>
|
||||||
|
<y>181</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -506,7 +506,8 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
|||||||
|
|
||||||
def manage_bookmarks(self):
|
def manage_bookmarks(self):
|
||||||
bmm = BookmarkManager(self, self.iterator.bookmarks)
|
bmm = BookmarkManager(self, self.iterator.bookmarks)
|
||||||
bmm.exec_()
|
if bmm.exec_() != BookmarkManager.Accepted:
|
||||||
|
return
|
||||||
|
|
||||||
bookmarks = bmm.get_bookmarks()
|
bookmarks = bmm.get_bookmarks()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user