mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Store edit book state in the cache directory rather than the config directory
This commit is contained in:
parent
2a0ee491e9
commit
2a288a49f1
@ -65,8 +65,6 @@ d['spell_check_case_sensitive_search'] = False
|
|||||||
d['add_cover_preserve_aspect_ratio'] = False
|
d['add_cover_preserve_aspect_ratio'] = False
|
||||||
d['templates'] = {}
|
d['templates'] = {}
|
||||||
d['auto_close_tags'] = True
|
d['auto_close_tags'] = True
|
||||||
d['edit_book_state'] = {}
|
|
||||||
d['edit_book_state_order'] = []
|
|
||||||
d['restore_book_state'] = True
|
d['restore_book_state'] = True
|
||||||
del d
|
del d
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ from PyQt5.Qt import (
|
|||||||
QDialogButtonBox, QIcon, QPixmap, QInputDialog, QUrl, pyqtSignal)
|
QDialogButtonBox, QIcon, QPixmap, QInputDialog, QUrl, pyqtSignal)
|
||||||
|
|
||||||
from calibre import prints, isbytestring
|
from calibre import prints, isbytestring
|
||||||
|
from calibre.constants import cache_dir
|
||||||
from calibre.ptempfile import PersistentTemporaryDirectory, TemporaryDirectory
|
from calibre.ptempfile import PersistentTemporaryDirectory, TemporaryDirectory
|
||||||
from calibre.ebooks.oeb.base import urlnormalize
|
from calibre.ebooks.oeb.base import urlnormalize
|
||||||
from calibre.ebooks.oeb.polish.main import SUPPORTED, tweak_polish
|
from calibre.ebooks.oeb.polish.main import SUPPORTED, tweak_polish
|
||||||
@ -45,6 +46,7 @@ from calibre.gui2.tweak_book.spell import find_next as find_next_word, find_next
|
|||||||
from calibre.gui2.tweak_book.widgets import (
|
from calibre.gui2.tweak_book.widgets import (
|
||||||
RationalizeFolders, MultiSplit, ImportForeign, QuickOpen, InsertLink,
|
RationalizeFolders, MultiSplit, ImportForeign, QuickOpen, InsertLink,
|
||||||
InsertSemantics, BusyCursor, InsertTag, FilterCSS, AddCover)
|
InsertSemantics, BusyCursor, InsertTag, FilterCSS, AddCover)
|
||||||
|
from calibre.utils.config import JSONConfig
|
||||||
|
|
||||||
_diff_dialogs = []
|
_diff_dialogs = []
|
||||||
|
|
||||||
@ -67,6 +69,7 @@ _boss = None
|
|||||||
def get_boss():
|
def get_boss():
|
||||||
return _boss
|
return _boss
|
||||||
|
|
||||||
|
|
||||||
class Boss(QObject):
|
class Boss(QObject):
|
||||||
|
|
||||||
handle_completion_result_signal = pyqtSignal(object)
|
handle_completion_result_signal = pyqtSignal(object)
|
||||||
@ -88,6 +91,10 @@ class Boss(QObject):
|
|||||||
completion_worker().result_callback = self.handle_completion_result_signal.emit
|
completion_worker().result_callback = self.handle_completion_result_signal.emit
|
||||||
self.handle_completion_result_signal.connect(self.handle_completion_result, Qt.QueuedConnection)
|
self.handle_completion_result_signal.connect(self.handle_completion_result, Qt.QueuedConnection)
|
||||||
self.completion_request_count = 0
|
self.completion_request_count = 0
|
||||||
|
self.editor_cache = JSONConfig('editor-cache', base_path=cache_dir())
|
||||||
|
d = self.editor_cache.defaults
|
||||||
|
d['edit_book_state'] = {}
|
||||||
|
d['edit_book_state_order'] = []
|
||||||
|
|
||||||
def __call__(self, gui):
|
def __call__(self, gui):
|
||||||
self.gui = gui
|
self.gui = gui
|
||||||
@ -1459,13 +1466,15 @@ class Boss(QObject):
|
|||||||
self.save_manager.wait(0.1)
|
self.save_manager.wait(0.1)
|
||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
|
with self.editor_cache:
|
||||||
|
self.save_book_edit_state()
|
||||||
with tprefs:
|
with tprefs:
|
||||||
self.gui.save_state()
|
self.gui.save_state()
|
||||||
self.save_book_edit_state()
|
|
||||||
|
|
||||||
def save_book_edit_state(self):
|
def save_book_edit_state(self):
|
||||||
c = current_container()
|
c = current_container()
|
||||||
if c and c.path_to_ebook:
|
if c and c.path_to_ebook:
|
||||||
|
tprefs = self.editor_cache
|
||||||
mem = tprefs['edit_book_state']
|
mem = tprefs['edit_book_state']
|
||||||
order = tprefs['edit_book_state_order']
|
order = tprefs['edit_book_state_order']
|
||||||
extra = len(order) - 99
|
extra = len(order) - 99
|
||||||
@ -1488,6 +1497,7 @@ class Boss(QObject):
|
|||||||
def restore_book_edit_state(self):
|
def restore_book_edit_state(self):
|
||||||
c = current_container()
|
c = current_container()
|
||||||
if c and c.path_to_ebook:
|
if c and c.path_to_ebook:
|
||||||
|
tprefs = self.editor_cache
|
||||||
state = tprefs['edit_book_state'].get(c.path_to_ebook)
|
state = tprefs['edit_book_state'].get(c.path_to_ebook)
|
||||||
if state is not None:
|
if state is not None:
|
||||||
opened = set()
|
opened = set()
|
||||||
|
@ -268,11 +268,11 @@ class XMLConfig(dict):
|
|||||||
|
|
||||||
EXTENSION = '.plist'
|
EXTENSION = '.plist'
|
||||||
|
|
||||||
def __init__(self, rel_path_to_cf_file):
|
def __init__(self, rel_path_to_cf_file, base_path=config_dir):
|
||||||
dict.__init__(self)
|
dict.__init__(self)
|
||||||
self.no_commit = False
|
self.no_commit = False
|
||||||
self.defaults = {}
|
self.defaults = {}
|
||||||
self.file_path = os.path.join(config_dir,
|
self.file_path = os.path.join(base_path,
|
||||||
*(rel_path_to_cf_file.split('/')))
|
*(rel_path_to_cf_file.split('/')))
|
||||||
self.file_path = os.path.abspath(self.file_path)
|
self.file_path = os.path.abspath(self.file_path)
|
||||||
if not self.file_path.endswith(self.EXTENSION):
|
if not self.file_path.endswith(self.EXTENSION):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user