mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove use of legacy db.prefs API where possible
This commit is contained in:
parent
99bf8b9dac
commit
065becd6a6
@ -71,7 +71,7 @@ class ViewAction(InterfaceAction):
|
|||||||
for ac in self.history_actions:
|
for ac in self.history_actions:
|
||||||
self.view_menu.removeAction(ac)
|
self.view_menu.removeAction(ac)
|
||||||
self.history_actions = []
|
self.history_actions = []
|
||||||
history = db.prefs.get('gui_view_history', [])
|
history = db.new_api.pref('gui_view_history', [])
|
||||||
if history:
|
if history:
|
||||||
self.view_menu.insertAction(self.clear_sep2, self.clear_sep1)
|
self.view_menu.insertAction(self.clear_sep2, self.clear_sep1)
|
||||||
self.history_actions.append(self.clear_sep1)
|
self.history_actions.append(self.clear_sep1)
|
||||||
@ -317,7 +317,7 @@ class ViewAction(InterfaceAction):
|
|||||||
if views:
|
if views:
|
||||||
seen = set()
|
seen = set()
|
||||||
history = []
|
history = []
|
||||||
for id_, title in views + db.prefs.get('gui_view_history', []):
|
for id_, title in views + db.new_api.pref('gui_view_history', []):
|
||||||
if title not in seen:
|
if title not in seen:
|
||||||
seen.add(title)
|
seen.add(title)
|
||||||
history.append((id_, title))
|
history.append((id_, title))
|
||||||
@ -325,7 +325,7 @@ class ViewAction(InterfaceAction):
|
|||||||
db.new_api.set_pref('gui_view_history', history[:vh])
|
db.new_api.set_pref('gui_view_history', history[:vh])
|
||||||
self.build_menus(db)
|
self.build_menus(db)
|
||||||
if remove:
|
if remove:
|
||||||
history = db.prefs.get('gui_view_history', [])
|
history = db.new_api.pref('gui_view_history', [])
|
||||||
history = [x for x in history if x[0] not in remove]
|
history = [x for x in history if x[0] not in remove]
|
||||||
db.new_api.set_pref('gui_view_history', history[:vh])
|
db.new_api.set_pref('gui_view_history', history[:vh])
|
||||||
self.build_menus(db)
|
self.build_menus(db)
|
||||||
|
@ -164,7 +164,7 @@ class Bool(Base):
|
|||||||
l.addWidget(c)
|
l.addWidget(c)
|
||||||
c.clicked.connect(self.set_to_no)
|
c.clicked.connect(self.set_to_no)
|
||||||
|
|
||||||
if self.db.prefs.get('bools_are_tristate'):
|
if self.db.new_api.pref('bools_are_tristate'):
|
||||||
t = _('Clear')
|
t = _('Clear')
|
||||||
c = QPushButton(t, parent)
|
c = QPushButton(t, parent)
|
||||||
width = c.fontMetrics().boundingRect(t).width() + 7
|
width = c.fontMetrics().boundingRect(t).width() + 7
|
||||||
@ -179,7 +179,7 @@ class Bool(Base):
|
|||||||
w = self.combobox
|
w = self.combobox
|
||||||
items = [_('Yes'), _('No'), _('Undefined')]
|
items = [_('Yes'), _('No'), _('Undefined')]
|
||||||
icons = [I('ok.png'), I('list_remove.png'), I('blank.png')]
|
icons = [I('ok.png'), I('list_remove.png'), I('blank.png')]
|
||||||
if not self.db.prefs.get('bools_are_tristate'):
|
if not self.db.new_api.pref('bools_are_tristate'):
|
||||||
items = items[:-1]
|
items = items[:-1]
|
||||||
icons = icons[:-1]
|
icons = icons[:-1]
|
||||||
for icon, text in zip(icons, items):
|
for icon, text in zip(icons, items):
|
||||||
@ -187,7 +187,7 @@ class Bool(Base):
|
|||||||
|
|
||||||
def setter(self, val):
|
def setter(self, val):
|
||||||
val = {None: 2, False: 1, True: 0}[val]
|
val = {None: 2, False: 1, True: 0}[val]
|
||||||
if not self.db.prefs.get('bools_are_tristate') and val == 2:
|
if not self.db.new_api.pref('bools_are_tristate') and val == 2:
|
||||||
val = 1
|
val = 1
|
||||||
self.combobox.setCurrentIndex(val)
|
self.combobox.setCurrentIndex(val)
|
||||||
|
|
||||||
@ -908,7 +908,7 @@ class BulkBool(BulkBase, Bool):
|
|||||||
value = None
|
value = None
|
||||||
for book_id in book_ids:
|
for book_id in book_ids:
|
||||||
val = self.db.get_custom(book_id, num=self.col_id, index_is_id=True)
|
val = self.db.get_custom(book_id, num=self.col_id, index_is_id=True)
|
||||||
if not self.db.prefs.get('bools_are_tristate') and val is None:
|
if not self.db.new_api.pref('bools_are_tristate') and val is None:
|
||||||
val = False
|
val = False
|
||||||
if value is not None and value != val:
|
if value is not None and value != val:
|
||||||
return None
|
return None
|
||||||
@ -918,7 +918,7 @@ class BulkBool(BulkBase, Bool):
|
|||||||
def setup_ui(self, parent):
|
def setup_ui(self, parent):
|
||||||
self.make_widgets(parent, QComboBox)
|
self.make_widgets(parent, QComboBox)
|
||||||
items = [_('Yes'), _('No')]
|
items = [_('Yes'), _('No')]
|
||||||
if not self.db.prefs.get('bools_are_tristate'):
|
if not self.db.new_api.pref('bools_are_tristate'):
|
||||||
items.append('')
|
items.append('')
|
||||||
else:
|
else:
|
||||||
items.append(_('Undefined'))
|
items.append(_('Undefined'))
|
||||||
@ -930,7 +930,7 @@ class BulkBool(BulkBase, Bool):
|
|||||||
|
|
||||||
def getter(self):
|
def getter(self):
|
||||||
val = self.main_widget.currentIndex()
|
val = self.main_widget.currentIndex()
|
||||||
if not self.db.prefs.get('bools_are_tristate'):
|
if not self.db.new_api.pref('bools_are_tristate'):
|
||||||
return {2: False, 1: False, 0: True}[val]
|
return {2: False, 1: False, 0: True}[val]
|
||||||
else:
|
else:
|
||||||
return {2: None, 1: False, 0: True}[val]
|
return {2: None, 1: False, 0: True}[val]
|
||||||
@ -945,13 +945,13 @@ class BulkBool(BulkBase, Bool):
|
|||||||
return
|
return
|
||||||
val = self.gui_val
|
val = self.gui_val
|
||||||
val = self.normalize_ui_val(val)
|
val = self.normalize_ui_val(val)
|
||||||
if not self.db.prefs.get('bools_are_tristate') and val is None:
|
if not self.db.new_api.pref('bools_are_tristate') and val is None:
|
||||||
val = False
|
val = False
|
||||||
self.db.set_custom_bulk(book_ids, val, num=self.col_id, notify=notify)
|
self.db.set_custom_bulk(book_ids, val, num=self.col_id, notify=notify)
|
||||||
|
|
||||||
def a_c_checkbox_changed(self):
|
def a_c_checkbox_changed(self):
|
||||||
if not self.ignore_change_signals:
|
if not self.ignore_change_signals:
|
||||||
if not self.db.prefs.get('bools_are_tristate') and \
|
if not self.db.new_api.pref('bools_are_tristate') and \
|
||||||
self.main_widget.currentIndex() == 2:
|
self.main_widget.currentIndex() == 2:
|
||||||
self.a_c_checkbox.setChecked(False)
|
self.a_c_checkbox.setChecked(False)
|
||||||
else:
|
else:
|
||||||
|
@ -1372,7 +1372,7 @@ class DeviceMixin(object): # {{{
|
|||||||
'Set of ids to be sent to device'
|
'Set of ids to be sent to device'
|
||||||
ans = []
|
ans = []
|
||||||
try:
|
try:
|
||||||
ans = self.library_view.model().db.prefs.get('news_to_be_synced',
|
ans = self.library_view.model().db.new_api.pref('news_to_be_synced',
|
||||||
[])
|
[])
|
||||||
except:
|
except:
|
||||||
import traceback
|
import traceback
|
||||||
@ -1563,7 +1563,7 @@ class DeviceMixin(object): # {{{
|
|||||||
'''
|
'''
|
||||||
Upload metadata to device.
|
Upload metadata to device.
|
||||||
'''
|
'''
|
||||||
plugboards = self.library_view.model().db.prefs.get('plugboards', {})
|
plugboards = self.library_view.model().db.new_api.pref('plugboards', {})
|
||||||
self.device_manager.sync_booklists(Dispatcher(lambda x: x),
|
self.device_manager.sync_booklists(Dispatcher(lambda x: x),
|
||||||
self.booklists(), plugboards)
|
self.booklists(), plugboards)
|
||||||
|
|
||||||
@ -1571,7 +1571,7 @@ class DeviceMixin(object): # {{{
|
|||||||
'''
|
'''
|
||||||
Upload metadata to device.
|
Upload metadata to device.
|
||||||
'''
|
'''
|
||||||
plugboards = self.library_view.model().db.prefs.get('plugboards', {})
|
plugboards = self.library_view.model().db.new_api.pref('plugboards', {})
|
||||||
self.device_manager.sync_booklists(FunctionDispatcher(self.metadata_synced),
|
self.device_manager.sync_booklists(FunctionDispatcher(self.metadata_synced),
|
||||||
self.booklists(), plugboards,
|
self.booklists(), plugboards,
|
||||||
add_as_step_to_job=add_as_step_to_job)
|
add_as_step_to_job=add_as_step_to_job)
|
||||||
@ -1611,7 +1611,7 @@ class DeviceMixin(object): # {{{
|
|||||||
:param files: List of either paths to files or file like objects
|
:param files: List of either paths to files or file like objects
|
||||||
'''
|
'''
|
||||||
titles = [i.title for i in metadata]
|
titles = [i.title for i in metadata]
|
||||||
plugboards = self.library_view.model().db.prefs.get('plugboards', {})
|
plugboards = self.library_view.model().db.new_api.pref('plugboards', {})
|
||||||
job = self.device_manager.upload_books(
|
job = self.device_manager.upload_books(
|
||||||
FunctionDispatcher(self.books_uploaded),
|
FunctionDispatcher(self.books_uploaded),
|
||||||
files, names, on_card=on_card,
|
files, names, on_card=on_card,
|
||||||
@ -1947,7 +1947,7 @@ class DeviceMixin(object): # {{{
|
|||||||
|
|
||||||
if update_metadata:
|
if update_metadata:
|
||||||
if self.device_manager.is_device_connected:
|
if self.device_manager.is_device_connected:
|
||||||
plugboards = self.library_view.model().db.prefs.get('plugboards', {})
|
plugboards = self.library_view.model().db.new_api.pref('plugboards', {})
|
||||||
self.device_manager.sync_booklists(
|
self.device_manager.sync_booklists(
|
||||||
FunctionDispatcher(self.metadata_synced), booklists,
|
FunctionDispatcher(self.metadata_synced), booklists,
|
||||||
plugboards, add_as_step_to_job)
|
plugboards, add_as_step_to_job)
|
||||||
|
@ -208,7 +208,7 @@ class CheckLibraryDialog(QDialog):
|
|||||||
ln = QLabel(_('Names to ignore:'))
|
ln = QLabel(_('Names to ignore:'))
|
||||||
h.addWidget(ln)
|
h.addWidget(ln)
|
||||||
self.name_ignores = QLineEdit()
|
self.name_ignores = QLineEdit()
|
||||||
self.name_ignores.setText(db.prefs.get('check_library_ignore_names', ''))
|
self.name_ignores.setText(db.new_api.pref('check_library_ignore_names', ''))
|
||||||
self.name_ignores.setToolTip(
|
self.name_ignores.setToolTip(
|
||||||
_('Enter comma-separated standard file name wildcards, such as synctoy*.dat'))
|
_('Enter comma-separated standard file name wildcards, such as synctoy*.dat'))
|
||||||
ln.setBuddy(self.name_ignores)
|
ln.setBuddy(self.name_ignores)
|
||||||
@ -216,7 +216,7 @@ class CheckLibraryDialog(QDialog):
|
|||||||
le = QLabel(_('Extensions to ignore:'))
|
le = QLabel(_('Extensions to ignore:'))
|
||||||
h.addWidget(le)
|
h.addWidget(le)
|
||||||
self.ext_ignores = QLineEdit()
|
self.ext_ignores = QLineEdit()
|
||||||
self.ext_ignores.setText(db.prefs.get('check_library_ignore_extensions', ''))
|
self.ext_ignores.setText(db.new_api.pref('check_library_ignore_extensions', ''))
|
||||||
self.ext_ignores.setToolTip(
|
self.ext_ignores.setToolTip(
|
||||||
_('Enter comma-separated extensions without a leading dot. Used only in book folders'))
|
_('Enter comma-separated extensions without a leading dot. Used only in book folders'))
|
||||||
le.setBuddy(self.ext_ignores)
|
le.setBuddy(self.ext_ignores)
|
||||||
|
@ -92,7 +92,7 @@ class TagCategories(QDialog, Ui_TagCategories):
|
|||||||
self.category_icons.append(cc_icon)
|
self.category_icons.append(cc_icon)
|
||||||
category_names.append(cc['name'])
|
category_names.append(cc['name'])
|
||||||
self.category_values.append(lambda col=key: [t.original_name for t in self.db_categories[col]])
|
self.category_values.append(lambda col=key: [t.original_name for t in self.db_categories[col]])
|
||||||
self.categories = dict.copy(db.prefs.get('user_categories', {}))
|
self.categories = dict.copy(db.new_api.pref('user_categories', {}))
|
||||||
if self.categories is None:
|
if self.categories is None:
|
||||||
self.categories = {}
|
self.categories = {}
|
||||||
self.initialize_category_lists(book_ids=None)
|
self.initialize_category_lists(book_ids=None)
|
||||||
|
@ -460,7 +460,7 @@ class VLTabs(QTabBar): # {{{
|
|||||||
vl = unicode_type(self.tabData(index) or '')
|
vl = unicode_type(self.tabData(index) or '')
|
||||||
if vl: # Dont allow closing the All Books tab
|
if vl: # Dont allow closing the All Books tab
|
||||||
self.current_db.new_api.set_pref('virt_libs_hidden', list(
|
self.current_db.new_api.set_pref('virt_libs_hidden', list(
|
||||||
self.current_db.prefs['virt_libs_hidden']) + [vl])
|
self.current_db.new_api.pref('virt_libs_hidden', ())) + [vl])
|
||||||
self.removeTab(index)
|
self.removeTab(index)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -476,13 +476,13 @@ class VLTabs(QTabBar): # {{{
|
|||||||
|
|
||||||
def _rebuild(self):
|
def _rebuild(self):
|
||||||
db = self.current_db
|
db = self.current_db
|
||||||
vl_map = db.prefs.get('virtual_libraries', {})
|
vl_map = db.new_api.pref('virtual_libraries', {})
|
||||||
virt_libs = frozenset(vl_map)
|
virt_libs = frozenset(vl_map)
|
||||||
hidden = set(db.prefs['virt_libs_hidden'])
|
hidden = set(db.new_api.pref('virt_libs_hidden', ()))
|
||||||
if hidden - virt_libs:
|
if hidden - virt_libs:
|
||||||
hidden = hidden.intersection(virt_libs)
|
hidden = hidden.intersection(virt_libs)
|
||||||
db.new_api.set_pref('virt_libs_hidden', list(hidden))
|
db.new_api.set_pref('virt_libs_hidden', list(hidden))
|
||||||
order = db.prefs['virt_libs_order']
|
order = db.new_api.pref('virt_libs_order', ())
|
||||||
while self.count():
|
while self.count():
|
||||||
self.removeTab(0)
|
self.removeTab(0)
|
||||||
current_lib = db.data.get_base_restriction_name()
|
current_lib = db.data.get_base_restriction_name()
|
||||||
@ -521,7 +521,7 @@ class VLTabs(QTabBar): # {{{
|
|||||||
def contextMenuEvent(self, ev):
|
def contextMenuEvent(self, ev):
|
||||||
m = QMenu(self)
|
m = QMenu(self)
|
||||||
m.addAction(_('Sort tabs alphabetically'), self.sort_alphabetically)
|
m.addAction(_('Sort tabs alphabetically'), self.sort_alphabetically)
|
||||||
hidden = self.current_db.prefs['virt_libs_hidden']
|
hidden = self.current_db.new_api.pref('virt_libs_hidden')
|
||||||
if hidden:
|
if hidden:
|
||||||
s = m._s = m.addMenu(_('Restore hidden tabs'))
|
s = m._s = m.addMenu(_('Restore hidden tabs'))
|
||||||
for x in hidden:
|
for x in hidden:
|
||||||
@ -545,7 +545,7 @@ class VLTabs(QTabBar): # {{{
|
|||||||
self.rebuild()
|
self.rebuild()
|
||||||
|
|
||||||
def restore(self, x):
|
def restore(self, x):
|
||||||
h = self.current_db.prefs['virt_libs_hidden']
|
h = self.current_db.new_api.pref('virt_libs_hidden', ())
|
||||||
self.current_db.new_api.set_pref('virt_libs_hidden', list(set(h) - {x}))
|
self.current_db.new_api.set_pref('virt_libs_hidden', list(set(h) - {x}))
|
||||||
self.rebuild()
|
self.rebuild()
|
||||||
|
|
||||||
|
@ -699,7 +699,7 @@ class CcBoolDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
|
|||||||
editor = DelegateCB(parent)
|
editor = DelegateCB(parent)
|
||||||
items = [_('Y'), _('N'), ' ']
|
items = [_('Y'), _('N'), ' ']
|
||||||
icons = [I('ok.png'), I('list_remove.png'), I('blank.png')]
|
icons = [I('ok.png'), I('list_remove.png'), I('blank.png')]
|
||||||
if not index.model().db.prefs.get('bools_are_tristate'):
|
if not index.model().db.new_api.pref('bools_are_tristate'):
|
||||||
items = items[:-1]
|
items = items[:-1]
|
||||||
icons = icons[:-1]
|
icons = icons[:-1]
|
||||||
self.longest_text = ''
|
self.longest_text = ''
|
||||||
@ -721,7 +721,7 @@ class CcBoolDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
|
|||||||
def setEditorData(self, editor, index):
|
def setEditorData(self, editor, index):
|
||||||
m = index.model()
|
m = index.model()
|
||||||
val = m.db.data[index.row()][m.custom_columns[m.column_map[index.column()]]['rec_index']]
|
val = m.db.data[index.row()][m.custom_columns[m.column_map[index.column()]]['rec_index']]
|
||||||
if not m.db.prefs.get('bools_are_tristate'):
|
if not m.db.new_api.pref('bools_are_tristate'):
|
||||||
val = 1 if not val or check_key_modifier(Qt.ControlModifier) else 0
|
val = 1 if not val or check_key_modifier(Qt.ControlModifier) else 0
|
||||||
else:
|
else:
|
||||||
val = 2 if val is None or check_key_modifier(Qt.ControlModifier) \
|
val = 2 if val is None or check_key_modifier(Qt.ControlModifier) \
|
||||||
|
@ -660,7 +660,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
cover_as_data=True)
|
cover_as_data=True)
|
||||||
newmi = None
|
newmi = None
|
||||||
if use_plugboard and format.lower() in plugboard_formats:
|
if use_plugboard and format.lower() in plugboard_formats:
|
||||||
plugboards = self.db.prefs.get('plugboards', {})
|
plugboards = self.new_api.pref('plugboards', {})
|
||||||
cpb = find_plugboard(use_plugboard, format.lower(),
|
cpb = find_plugboard(use_plugboard, format.lower(),
|
||||||
plugboards)
|
plugboards)
|
||||||
if cpb:
|
if cpb:
|
||||||
@ -895,7 +895,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
if col >= len(self.column_to_dc_map):
|
if col >= len(self.column_to_dc_map):
|
||||||
return None
|
return None
|
||||||
if role == Qt.DisplayRole:
|
if role == Qt.DisplayRole:
|
||||||
rules = self.db.prefs['column_icon_rules']
|
rules = self.db.new_api.pref('column_icon_rules')
|
||||||
if rules:
|
if rules:
|
||||||
key = self.column_map[col]
|
key = self.column_map[col]
|
||||||
id_ = None
|
id_ = None
|
||||||
@ -928,7 +928,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
id_ = self.id(index)
|
id_ = self.id(index)
|
||||||
self.column_color.mi = None
|
self.column_color.mi = None
|
||||||
|
|
||||||
for k, fmt in self.db.prefs['column_color_rules']:
|
for k, fmt in self.db.new_api.pref('column_color_rules', ()):
|
||||||
if k == key:
|
if k == key:
|
||||||
ccol = self.column_color(id_, key, fmt, self.db,
|
ccol = self.column_color(id_, key, fmt, self.db,
|
||||||
self.color_cache, self.color_template_cache)
|
self.color_cache, self.color_template_cache)
|
||||||
@ -952,7 +952,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
|
|
||||||
if self.color_row_fmt_cache is None:
|
if self.color_row_fmt_cache is None:
|
||||||
self.color_row_fmt_cache = tuple(fmt for key, fmt in
|
self.color_row_fmt_cache = tuple(fmt for key, fmt in
|
||||||
self.db.prefs['column_color_rules'] if key == color_row_key)
|
self.db.new_api.pref('column_color_rules', ()) if key == color_row_key)
|
||||||
for fmt in self.color_row_fmt_cache:
|
for fmt in self.color_row_fmt_cache:
|
||||||
ccol = self.column_color(id_, color_row_key, fmt, self.db,
|
ccol = self.column_color(id_, color_row_key, fmt, self.db,
|
||||||
self.color_cache, self.color_template_cache)
|
self.color_cache, self.color_template_cache)
|
||||||
@ -965,7 +965,7 @@ class BooksModel(QAbstractTableModel): # {{{
|
|||||||
default_icon = None
|
default_icon = None
|
||||||
if self.column_to_dc_decorator_map[col] is not None:
|
if self.column_to_dc_decorator_map[col] is not None:
|
||||||
default_icon = self.column_to_dc_decorator_map[index.column()](index.row())
|
default_icon = self.column_to_dc_decorator_map[index.column()](index.row())
|
||||||
rules = self.db.prefs['column_icon_rules']
|
rules = self.db.new_api.pref('column_icon_rules')
|
||||||
if rules:
|
if rules:
|
||||||
key = self.column_map[col]
|
key = self.column_map[col]
|
||||||
id_ = None
|
id_ = None
|
||||||
|
@ -760,7 +760,7 @@ class BooksView(QTableView): # {{{
|
|||||||
name += ' books view state'
|
name += ' books view state'
|
||||||
db = getattr(self.model(), 'db', None)
|
db = getattr(self.model(), 'db', None)
|
||||||
if db is not None:
|
if db is not None:
|
||||||
ans = db.prefs.get(name, None)
|
ans = db.new_api.pref(name)
|
||||||
if ans is None:
|
if ans is None:
|
||||||
ans = gprefs.get(name, None)
|
ans = gprefs.get(name, None)
|
||||||
try:
|
try:
|
||||||
|
@ -119,7 +119,7 @@ class PinTableView(QTableView):
|
|||||||
def restore_state(self):
|
def restore_state(self):
|
||||||
db = getattr(self.model(), 'db', None)
|
db = getattr(self.model(), 'db', None)
|
||||||
if db is not None:
|
if db is not None:
|
||||||
state = db.prefs.get('books view split pane state', None)
|
state = db.new_api.pref('books view split pane state', None)
|
||||||
if self.splitter is not None:
|
if self.splitter is not None:
|
||||||
self.splitter.restore_state()
|
self.splitter.restore_state()
|
||||||
if state:
|
if state:
|
||||||
|
@ -211,7 +211,7 @@ class ConditionEditor(QWidget): # {{{
|
|||||||
dt = m['datatype']
|
dt = m['datatype']
|
||||||
if dt == 'bool':
|
if dt == 'bool':
|
||||||
from calibre.gui2.ui import get_gui
|
from calibre.gui2.ui import get_gui
|
||||||
if not get_gui().current_db.prefs.get('bools_are_tristate'):
|
if not get_gui().current_db.new_api.pref('bools_are_tristate'):
|
||||||
dt = 'bool2'
|
dt = 'bool2'
|
||||||
if dt in self.action_map:
|
if dt in self.action_map:
|
||||||
actions = self.action_map[dt]
|
actions = self.action_map[dt]
|
||||||
|
@ -170,7 +170,7 @@ class CreateVirtualLibrary(QDialog): # {{{
|
|||||||
|
|
||||||
if editing:
|
if editing:
|
||||||
db = self.gui.current_db
|
db = self.gui.current_db
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.new_api.pref('virtual_libraries', {})
|
||||||
for dex,vl in enumerate(sorted(virt_libs.keys(), key=sort_key)):
|
for dex,vl in enumerate(sorted(virt_libs.keys(), key=sort_key)):
|
||||||
self.vl_name.addItem(vl, virt_libs.get(vl, ''))
|
self.vl_name.addItem(vl, virt_libs.get(vl, ''))
|
||||||
if vl == editing:
|
if vl == editing:
|
||||||
@ -348,14 +348,14 @@ class SearchRestrictionMixin(object):
|
|||||||
self.search_restriction_list_built = False
|
self.search_restriction_list_built = False
|
||||||
|
|
||||||
def add_virtual_library(self, db, name, search):
|
def add_virtual_library(self, db, name, search):
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.new_api.pref('virtual_libraries', {})
|
||||||
virt_libs[name] = search
|
virt_libs[name] = search
|
||||||
db.new_api.set_pref('virtual_libraries', virt_libs)
|
db.new_api.set_pref('virtual_libraries', virt_libs)
|
||||||
db.new_api.clear_search_caches()
|
db.new_api.clear_search_caches()
|
||||||
|
|
||||||
def do_create_edit(self, name=None):
|
def do_create_edit(self, name=None):
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.new_api.pref('virtual_libraries', {})
|
||||||
cd = CreateVirtualLibrary(self, virt_libs.keys(), editing=name)
|
cd = CreateVirtualLibrary(self, virt_libs.keys(), editing=name)
|
||||||
if cd.exec_() == cd.Accepted:
|
if cd.exec_() == cd.Accepted:
|
||||||
if name:
|
if name:
|
||||||
@ -371,7 +371,7 @@ class SearchRestrictionMixin(object):
|
|||||||
a = m.addAction(_('Create Virtual library'))
|
a = m.addAction(_('Create Virtual library'))
|
||||||
a.triggered.connect(partial(self.do_create_edit, name=None))
|
a.triggered.connect(partial(self.do_create_edit, name=None))
|
||||||
db = self.current_db
|
db = self.current_db
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.new_api.pref('virtual_libraries', {})
|
||||||
|
|
||||||
a = self.edit_menu
|
a = self.edit_menu
|
||||||
self.build_virtual_library_list(a, self.do_create_edit)
|
self.build_virtual_library_list(a, self.do_create_edit)
|
||||||
@ -437,7 +437,7 @@ class SearchRestrictionMixin(object):
|
|||||||
|
|
||||||
def apply_virtual_library(self, library=None, update_tabs=True):
|
def apply_virtual_library(self, library=None, update_tabs=True):
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.new_api.pref('virtual_libraries', {})
|
||||||
if not library:
|
if not library:
|
||||||
db.data.set_base_restriction('')
|
db.data.set_base_restriction('')
|
||||||
db.data.set_base_restriction_name('')
|
db.data.set_base_restriction_name('')
|
||||||
@ -475,7 +475,7 @@ class SearchRestrictionMixin(object):
|
|||||||
|
|
||||||
def build_virtual_library_list(self, menu, handler):
|
def build_virtual_library_list(self, menu, handler):
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.new_api.pref('virtual_libraries', {})
|
||||||
menu.clear()
|
menu.clear()
|
||||||
menu.setIcon(self.empty)
|
menu.setIcon(self.empty)
|
||||||
|
|
||||||
@ -502,7 +502,7 @@ class SearchRestrictionMixin(object):
|
|||||||
def choose_vl_triggerred(self):
|
def choose_vl_triggerred(self):
|
||||||
from calibre.gui2.tweak_book.widgets import QuickOpen, emphasis_style
|
from calibre.gui2.tweak_book.widgets import QuickOpen, emphasis_style
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.new_api.pref('virtual_libraries', {})
|
||||||
if not virt_libs:
|
if not virt_libs:
|
||||||
return error_dialog(self, _('No Virtual libraries'), _(
|
return error_dialog(self, _('No Virtual libraries'), _(
|
||||||
'No Virtual libraries present, create some first'), show=True)
|
'No Virtual libraries present, create some first'), show=True)
|
||||||
@ -524,7 +524,7 @@ class SearchRestrictionMixin(object):
|
|||||||
|
|
||||||
def _remove_vl(self, name, reapply=True):
|
def _remove_vl(self, name, reapply=True):
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
virt_libs = db.prefs.get('virtual_libraries', {})
|
virt_libs = db.new_api.pref('virtual_libraries', {})
|
||||||
virt_libs.pop(name, None)
|
virt_libs.pop(name, None)
|
||||||
db.new_api.set_pref('virtual_libraries', virt_libs)
|
db.new_api.set_pref('virtual_libraries', virt_libs)
|
||||||
if reapply and db.data.get_base_restriction_name() == name:
|
if reapply and db.data.get_base_restriction_name() == name:
|
||||||
|
@ -400,7 +400,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
# Note that _get_category_nodes can indirectly change the
|
# Note that _get_category_nodes can indirectly change the
|
||||||
# user_categories dict.
|
# user_categories dict.
|
||||||
data = self._get_category_nodes(config['sort_tags_by'])
|
data = self._get_category_nodes(config['sort_tags_by'])
|
||||||
gst = self.db.prefs.get('grouped_search_terms', {})
|
gst = self.db.new_api.pref('grouped_search_terms', {})
|
||||||
|
|
||||||
last_category_node = None
|
last_category_node = None
|
||||||
category_node_map = {}
|
category_node_map = {}
|
||||||
@ -726,7 +726,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if result is None:
|
if result is None:
|
||||||
result = not (
|
result = not (
|
||||||
key in ['authors', 'publisher', 'news', 'formats', 'rating'] or
|
key in ['authors', 'publisher', 'news', 'formats', 'rating'] or
|
||||||
key not in self.db.prefs.get('categories_using_hierarchy', []) or
|
key not in self.db.new_api.pref('categories_using_hierarchy', []) or
|
||||||
config['sort_tags_by'] != 'name')
|
config['sort_tags_by'] != 'name')
|
||||||
self.hierarchical_categories[key] = result
|
self.hierarchical_categories[key] = result
|
||||||
return result
|
return result
|
||||||
@ -867,7 +867,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
is_uc, dest_key, c)
|
is_uc, dest_key, c)
|
||||||
return copied
|
return copied
|
||||||
|
|
||||||
user_cats = self.db.prefs.get('user_categories', {})
|
user_cats = self.db.new_api.pref('user_categories', {})
|
||||||
path = None
|
path = None
|
||||||
for s in src:
|
for s in src:
|
||||||
src_parent, src_parent_is_gst = s[1:3]
|
src_parent, src_parent_is_gst = s[1:3]
|
||||||
@ -929,7 +929,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def handle_user_category_drop(self, on_node, ids, column):
|
def handle_user_category_drop(self, on_node, ids, column):
|
||||||
categories = self.db.prefs.get('user_categories', {})
|
categories = self.db.new_api.pref('user_categories', {})
|
||||||
cat_contents = categories.get(on_node.category_key[1:], None)
|
cat_contents = categories.get(on_node.category_key[1:], None)
|
||||||
if cat_contents is None:
|
if cat_contents is None:
|
||||||
return
|
return
|
||||||
@ -1147,7 +1147,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
'renaming User categories'), show=True)
|
'renaming User categories'), show=True)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
user_cats = self.db.prefs.get('user_categories', {})
|
user_cats = self.db.new_api.pref('user_categories', {})
|
||||||
user_cat_keys_lower = [icu_lower(k) for k in user_cats]
|
user_cat_keys_lower = [icu_lower(k) for k in user_cats]
|
||||||
ckey = item.category_key[1:]
|
ckey = item.category_key[1:]
|
||||||
ckey_lower = icu_lower(ckey)
|
ckey_lower = icu_lower(ckey)
|
||||||
@ -1250,7 +1250,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
item_category and rename them to new_name. The caller must arrange to
|
item_category and rename them to new_name. The caller must arrange to
|
||||||
redisplay the tree as appropriate.
|
redisplay the tree as appropriate.
|
||||||
'''
|
'''
|
||||||
user_cats = self.db.prefs.get('user_categories', {})
|
user_cats = self.db.new_api.pref('user_categories', {})
|
||||||
for k in user_cats.keys():
|
for k in user_cats.keys():
|
||||||
new_contents = []
|
new_contents = []
|
||||||
for tup in user_cats[k]:
|
for tup in user_cats[k]:
|
||||||
@ -1267,7 +1267,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
item_category and delete them. The caller must arrange to redisplay the
|
item_category and delete them. The caller must arrange to redisplay the
|
||||||
tree as appropriate.
|
tree as appropriate.
|
||||||
'''
|
'''
|
||||||
user_cats = self.db.prefs.get('user_categories', {})
|
user_cats = self.db.new_api.pref('user_categories', {})
|
||||||
for cat in user_cats.keys():
|
for cat in user_cats.keys():
|
||||||
self.delete_item_from_user_category(cat, item_name, item_category,
|
self.delete_item_from_user_category(cat, item_name, item_category,
|
||||||
user_categories=user_cats)
|
user_categories=user_cats)
|
||||||
@ -1278,7 +1278,7 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
if user_categories is not None:
|
if user_categories is not None:
|
||||||
user_cats = user_categories
|
user_cats = user_categories
|
||||||
else:
|
else:
|
||||||
user_cats = self.db.prefs.get('user_categories', {})
|
user_cats = self.db.new_api.pref('user_categories', {})
|
||||||
new_contents = []
|
new_contents = []
|
||||||
for tup in user_cats[category]:
|
for tup in user_cats[category]:
|
||||||
if tup[0] != item_name or tup[1] != item_category:
|
if tup[0] != item_name or tup[1] != item_category:
|
||||||
|
@ -108,7 +108,7 @@ class TagBrowserMixin(object): # {{{
|
|||||||
opportunity to edit the name.
|
opportunity to edit the name.
|
||||||
'''
|
'''
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
user_cats = db.prefs.get('user_categories', {})
|
user_cats = db.new_api.pref('user_categories', {})
|
||||||
|
|
||||||
# Ensure that the temporary name we will use is not already there
|
# Ensure that the temporary name we will use is not already there
|
||||||
i = 0
|
i = 0
|
||||||
@ -157,7 +157,7 @@ class TagBrowserMixin(object): # {{{
|
|||||||
if category_name.startswith('@'):
|
if category_name.startswith('@'):
|
||||||
category_name = category_name[1:]
|
category_name = category_name[1:]
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
user_cats = db.prefs.get('user_categories', {})
|
user_cats = db.new_api.pref('user_categories', {})
|
||||||
cat_keys = sorted(user_cats.keys(), key=sort_key)
|
cat_keys = sorted(user_cats.keys(), key=sort_key)
|
||||||
has_children = False
|
has_children = False
|
||||||
found = False
|
found = False
|
||||||
@ -192,7 +192,7 @@ class TagBrowserMixin(object): # {{{
|
|||||||
if user_cat.startswith('@'):
|
if user_cat.startswith('@'):
|
||||||
user_cat = user_cat[1:]
|
user_cat = user_cat[1:]
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
user_cats = db.prefs.get('user_categories', {})
|
user_cats = db.new_api.pref('user_categories', {})
|
||||||
if user_cat not in user_cats:
|
if user_cat not in user_cats:
|
||||||
error_dialog(self.tags_view, _('Remove category'),
|
error_dialog(self.tags_view, _('Remove category'),
|
||||||
_('User category %s does not exist')%user_cat,
|
_('User category %s does not exist')%user_cat,
|
||||||
@ -209,7 +209,7 @@ class TagBrowserMixin(object): # {{{
|
|||||||
dest_category. Any leading '@' is removed
|
dest_category. Any leading '@' is removed
|
||||||
'''
|
'''
|
||||||
db = self.library_view.model().db
|
db = self.library_view.model().db
|
||||||
user_cats = db.prefs.get('user_categories', {})
|
user_cats = db.new_api.pref('user_categories', {})
|
||||||
|
|
||||||
if dest_category and dest_category.startswith('@'):
|
if dest_category and dest_category.startswith('@'):
|
||||||
dest_category = dest_category[1:]
|
dest_category = dest_category[1:]
|
||||||
|
@ -785,7 +785,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
# Always show the User categories editor
|
# Always show the User categories editor
|
||||||
self.context_menu.addSeparator()
|
self.context_menu.addSeparator()
|
||||||
if key.startswith('@') and \
|
if key.startswith('@') and \
|
||||||
key[1:] in self.db.prefs.get('user_categories', {}).keys():
|
key[1:] in self.db.new_api.pref('user_categories', {}).keys():
|
||||||
self.context_menu.addAction(_('Manage User categories'),
|
self.context_menu.addAction(_('Manage User categories'),
|
||||||
partial(self.context_menu_handler, action='manage_categories',
|
partial(self.context_menu_handler, action='manage_categories',
|
||||||
category=key[1:]))
|
category=key[1:]))
|
||||||
|
@ -373,8 +373,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
self.library_view.model().database_changed.connect(self.populate_tb_manage_menu, type=Qt.QueuedConnection)
|
self.library_view.model().database_changed.connect(self.populate_tb_manage_menu, type=Qt.QueuedConnection)
|
||||||
|
|
||||||
# ######################## Search Restriction ##########################
|
# ######################## Search Restriction ##########################
|
||||||
if db.prefs['virtual_lib_on_startup']:
|
if db.new_api.pref('virtual_lib_on_startup'):
|
||||||
self.apply_virtual_library(db.prefs['virtual_lib_on_startup'])
|
self.apply_virtual_library(db.new_api.pref('virtual_lib_on_startup'))
|
||||||
self.rebuild_vl_tabs()
|
self.rebuild_vl_tabs()
|
||||||
|
|
||||||
# ########################## Cover Flow ################################
|
# ########################## Cover Flow ################################
|
||||||
@ -713,7 +713,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
try:
|
try:
|
||||||
olddb = self.library_view.model().db
|
olddb = self.library_view.model().db
|
||||||
if copy_structure:
|
if copy_structure:
|
||||||
default_prefs = olddb.prefs
|
default_prefs = dict(olddb.prefs)
|
||||||
except:
|
except:
|
||||||
olddb = None
|
olddb = None
|
||||||
if copy_structure and olddb is not None and default_prefs is not None:
|
if copy_structure and olddb is not None and default_prefs is not None:
|
||||||
@ -758,8 +758,8 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
|
|||||||
self.set_window_title()
|
self.set_window_title()
|
||||||
self.apply_named_search_restriction('') # reset restriction to null
|
self.apply_named_search_restriction('') # reset restriction to null
|
||||||
self.saved_searches_changed(recount=False) # reload the search restrictions combo box
|
self.saved_searches_changed(recount=False) # reload the search restrictions combo box
|
||||||
if db.prefs['virtual_lib_on_startup']:
|
if db.new_api.pref('virtual_lib_on_startup'):
|
||||||
self.apply_virtual_library(db.prefs['virtual_lib_on_startup'])
|
self.apply_virtual_library(db.new_api.pref('virtual_lib_on_startup'))
|
||||||
self.rebuild_vl_tabs()
|
self.rebuild_vl_tabs()
|
||||||
for action in self.iactions.values():
|
for action in self.iactions.values():
|
||||||
action.library_changed(db)
|
action.library_changed(db)
|
||||||
|
@ -632,7 +632,7 @@ class CatalogBuilder(object):
|
|||||||
|
|
||||||
# Handle condition where bools_are_tristate is False,
|
# Handle condition where bools_are_tristate is False,
|
||||||
# field is a bool and contents is None, which is displayed as No
|
# field is a bool and contents is None, which is displayed as No
|
||||||
if (not self.db.prefs.get('bools_are_tristate') and
|
if (not self.db.new_api.pref('bools_are_tristate') and
|
||||||
self.db.metadata_for_field(rule['field'])['datatype'] == 'bool' and
|
self.db.metadata_for_field(rule['field'])['datatype'] == 'bool' and
|
||||||
field_contents is None):
|
field_contents is None):
|
||||||
field_contents = _('False')
|
field_contents = _('False')
|
||||||
@ -1070,7 +1070,7 @@ class CatalogBuilder(object):
|
|||||||
|
|
||||||
if self.DEBUG:
|
if self.DEBUG:
|
||||||
if self.prefix_rules:
|
if self.prefix_rules:
|
||||||
self.opts.log.info(" Added prefixes (bools_are_tristate: {0}):".format(self.db.prefs.get('bools_are_tristate')))
|
self.opts.log.info(" Added prefixes (bools_are_tristate: {0}):".format(self.db.new_api.pref('bools_are_tristate')))
|
||||||
else:
|
else:
|
||||||
self.opts.log.info(" No added prefixes")
|
self.opts.log.info(" No added prefixes")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user