mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
icon rules: fix sometimes creating identical names when items contain special characters. Example: currently aaa:/b and aaa:?b generate the same name. Disambiguate them by including the item id.
This commit is contained in:
parent
e98e5c863d
commit
b831f139d4
@ -673,11 +673,12 @@ class TagsView(QTreeView): # {{{
|
|||||||
# category is None if the user asked to specify a template
|
# category is None if the user asked to specify a template
|
||||||
# index is None if the user clicked on a category (top level) node
|
# index is None if the user clicked on a category (top level) node
|
||||||
# extra is a tuple: (icon_file_name: string or None, children: True or False)
|
# extra is a tuple: (icon_file_name: string or None, children: True or False)
|
||||||
def make_icon_name(key, index):
|
def make_icon_name(key, index, db):
|
||||||
icon_file_name = 'icon_' + sanitize_file_name(key)
|
icon_file_name = 'icon_' + sanitize_file_name(key)
|
||||||
if index is not None:
|
if index is not None:
|
||||||
item_val = self._model.get_node(index).tag.original_name
|
item_val = self._model.get_node(index).tag.original_name
|
||||||
icon_file_name = icon_file_name + '@@' + sanitize_file_name(item_val)
|
item_id = db.new_api.get_item_id(key, item_val)
|
||||||
|
icon_file_name = f'{icon_file_name}@@{sanitize_file_name(item_val)}_{item_id}'
|
||||||
else:
|
else:
|
||||||
item_val = None
|
item_val = None
|
||||||
icon_file_name += '.png'
|
icon_file_name += '.png'
|
||||||
@ -713,7 +714,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
self.recount()
|
self.recount()
|
||||||
return
|
return
|
||||||
icon_file_name, for_children = extra if extra is not None else (None, None)
|
icon_file_name, for_children = extra if extra is not None else (None, None)
|
||||||
item_val, desired_file_name = make_icon_name(key, index)
|
item_val, desired_file_name = make_icon_name(key, index, self.db)
|
||||||
if icon_file_name is None:
|
if icon_file_name is None:
|
||||||
# User wants to specify a specific icon
|
# User wants to specify a specific icon
|
||||||
try:
|
try:
|
||||||
@ -753,7 +754,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
self._model.remove_all_value_icons(key, keep_template=True)
|
self._model.remove_all_value_icons(key, keep_template=True)
|
||||||
elif extra == 'value':
|
elif extra == 'value':
|
||||||
if index is not None:
|
if index is not None:
|
||||||
val, icon_name = make_icon_name(key, index)
|
val, icon_name = make_icon_name(key, index, self.db)
|
||||||
if not confirm(
|
if not confirm(
|
||||||
_('The icon for the value "{0}" of the "{1}" category '
|
_('The icon for the value "{0}" of the "{1}" category '
|
||||||
'will be <b>permanently deleted</b>. Are you sure?').format(val, category),
|
'will be <b>permanently deleted</b>. Are you sure?').format(val, category),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user