mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
1) Save field_metadata to preference on shutdown and in cli.py
2) refactor to use remove_dynamic_categories
This commit is contained in:
parent
61ea8ad894
commit
9242bc4f8a
@ -424,10 +424,8 @@ class TagsModel(QAbstractItemModel): # {{{
|
|||||||
self.categories = []
|
self.categories = []
|
||||||
|
|
||||||
# Reconstruct the user categories, putting them into metadata
|
# Reconstruct the user categories, putting them into metadata
|
||||||
|
self.db.field_metadata.remove_dynamic_categories()
|
||||||
tb_cats = self.db.field_metadata
|
tb_cats = self.db.field_metadata
|
||||||
for k in tb_cats.keys():
|
|
||||||
if tb_cats[k]['kind'] in ['user', 'search']:
|
|
||||||
del tb_cats[k]
|
|
||||||
for user_cat in sorted(self.db.prefs.get('user_categories', {}).keys()):
|
for user_cat in sorted(self.db.prefs.get('user_categories', {}).keys()):
|
||||||
cat_name = user_cat+':' # add the ':' to avoid name collision
|
cat_name = user_cat+':' # add the ':' to avoid name collision
|
||||||
tb_cats.add_user_category(label=cat_name, name=user_cat)
|
tb_cats.add_user_category(label=cat_name, name=user_cat)
|
||||||
|
@ -523,11 +523,16 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
|
|||||||
|
|
||||||
def shutdown(self, write_settings=True):
|
def shutdown(self, write_settings=True):
|
||||||
try:
|
try:
|
||||||
cf = self.library_view.model().db.clean
|
db = self.library_view.model().db
|
||||||
|
cf = db.clean
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
cf()
|
cf()
|
||||||
|
# Save the current field_metadata for applications like calibre2opds
|
||||||
|
# Goes here, because if cf is valid, db is valid.
|
||||||
|
db.field_metadata.remove_dynamic_categories()
|
||||||
|
db.prefs['field_metadata'] = db.field_metadata.all_metadata()
|
||||||
for action in self.iactions.values():
|
for action in self.iactions.values():
|
||||||
if not action.shutting_down():
|
if not action.shutting_down():
|
||||||
return
|
return
|
||||||
|
@ -576,6 +576,9 @@ def command_add_custom_column(args, dbpath):
|
|||||||
return 1
|
return 1
|
||||||
do_add_custom_column(get_db(dbpath, opts), args[0], args[1], args[2],
|
do_add_custom_column(get_db(dbpath, opts), args[0], args[1], args[2],
|
||||||
opts.is_multiple, json.loads(opts.display))
|
opts.is_multiple, json.loads(opts.display))
|
||||||
|
# Re-open the DB so that field_metadata is reflects the column changes
|
||||||
|
db = get_db(dbpath, opts)
|
||||||
|
db.prefs['field_metadata'] = db.field_metadata.all_metadata()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def catalog_option_parser(args):
|
def catalog_option_parser(args):
|
||||||
@ -799,6 +802,9 @@ def command_remove_custom_column(args, dbpath):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
do_remove_custom_column(get_db(dbpath, opts), args[0], opts.force)
|
do_remove_custom_column(get_db(dbpath, opts), args[0], opts.force)
|
||||||
|
# Re-open the DB so that field_metadata is reflects the column changes
|
||||||
|
db = get_db(dbpath, opts)
|
||||||
|
db.prefs['field_metadata'] = db.field_metadata.all_metadata()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def saved_searches_option_parser():
|
def saved_searches_option_parser():
|
||||||
|
@ -290,10 +290,8 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
|
|
||||||
# Reconstruct the user categories, putting them into field_metadata
|
# Reconstruct the user categories, putting them into field_metadata
|
||||||
# Assumption is that someone else will fix them if they change.
|
# Assumption is that someone else will fix them if they change.
|
||||||
|
self.field_metadata.remove_dynamic_categories()
|
||||||
tb_cats = self.field_metadata
|
tb_cats = self.field_metadata
|
||||||
for k in tb_cats.keys():
|
|
||||||
if tb_cats[k]['kind'] in ['user', 'search']:
|
|
||||||
del tb_cats[k]
|
|
||||||
for user_cat in sorted(self.prefs.get('user_categories', {}).keys()):
|
for user_cat in sorted(self.prefs.get('user_categories', {}).keys()):
|
||||||
cat_name = user_cat+':' # add the ':' to avoid name collision
|
cat_name = user_cat+':' # add the ':' to avoid name collision
|
||||||
tb_cats.add_user_category(label=cat_name, name=user_cat)
|
tb_cats.add_user_category(label=cat_name, name=user_cat)
|
||||||
@ -338,9 +336,6 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
|
|||||||
setattr(self, 'title_sort', functools.partial(get_property,
|
setattr(self, 'title_sort', functools.partial(get_property,
|
||||||
loc=self.FIELD_MAP['sort']))
|
loc=self.FIELD_MAP['sort']))
|
||||||
|
|
||||||
# Save the current field_metadata for applications like calibre2opds
|
|
||||||
self.prefs['field_metadata'] = self.field_metadata.all_metadata()
|
|
||||||
|
|
||||||
def initialize_database(self):
|
def initialize_database(self):
|
||||||
metadata_sqlite = open(P('metadata_sqlite.sql'), 'rb').read()
|
metadata_sqlite = open(P('metadata_sqlite.sql'), 'rb').read()
|
||||||
self.conn.executescript(metadata_sqlite)
|
self.conn.executescript(metadata_sqlite)
|
||||||
|
@ -414,6 +414,12 @@ class FieldMetadata(dict):
|
|||||||
self._add_search_terms_to_map(key, [key])
|
self._add_search_terms_to_map(key, [key])
|
||||||
self.custom_label_to_key_map[label+'_index'] = key
|
self.custom_label_to_key_map[label+'_index'] = key
|
||||||
|
|
||||||
|
def remove_dynamic_categories(self):
|
||||||
|
for key in list(self._tb_cats.keys()):
|
||||||
|
val = self._tb_cats[key]
|
||||||
|
if val['is_category'] and val['kind'] in ('user', 'search'):
|
||||||
|
del self._tb_cats[key]
|
||||||
|
|
||||||
def cc_series_index_column_for(self, key):
|
def cc_series_index_column_for(self, key):
|
||||||
return self._tb_cats[key]['rec_index'] + 1
|
return self._tb_cats[key]['rec_index'] + 1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user