mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Enhancement: add restricting to the current VL in the tag browser category editor. See https://www.mobileread.com/forums/showthread.php?t=315414
This commit is contained in:
parent
306959fd4a
commit
a0f92e9fbb
@ -91,7 +91,7 @@ class EditColumnDelegate(QItemDelegate):
|
|||||||
|
|
||||||
class TagListEditor(QDialog, Ui_TagListEditor):
|
class TagListEditor(QDialog, Ui_TagListEditor):
|
||||||
|
|
||||||
def __init__(self, window, cat_name, tag_to_match, data, sorter):
|
def __init__(self, window, cat_name, tag_to_match, get_book_ids, sorter):
|
||||||
QDialog.__init__(self, window)
|
QDialog.__init__(self, window)
|
||||||
Ui_TagListEditor.__init__(self)
|
Ui_TagListEditor.__init__(self)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
@ -113,15 +113,9 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
# initialization
|
# initialization
|
||||||
self.to_rename = {}
|
self.ordered_tags = []
|
||||||
self.to_delete = set([])
|
self.sorter = sorter
|
||||||
self.all_tags = {}
|
self.get_book_ids = get_book_ids
|
||||||
self.original_names = {}
|
|
||||||
|
|
||||||
for k,v,count in data:
|
|
||||||
self.all_tags[v] = {'key': k, 'count': count, 'cur_name': v, 'is_deleted': False}
|
|
||||||
self.original_names[k] = v
|
|
||||||
self.ordered_tags = sorted(self.all_tags.keys(), key=sorter)
|
|
||||||
|
|
||||||
# Set up the column headings
|
# Set up the column headings
|
||||||
self.down_arrow_icon = QIcon(I('arrow-down.png'))
|
self.down_arrow_icon = QIcon(I('arrow-down.png'))
|
||||||
@ -140,7 +134,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
self.table.setItemDelegate(EditColumnDelegate(self.table))
|
self.table.setItemDelegate(EditColumnDelegate(self.table))
|
||||||
|
|
||||||
# Add the data
|
# Add the data
|
||||||
select_item = self.fill_in_table(self.ordered_tags, tag_to_match)
|
select_item = self.fill_in_table(None, tag_to_match)
|
||||||
|
|
||||||
# Scroll to the selected item if there is one
|
# Scroll to the selected item if there is one
|
||||||
if select_item is not None:
|
if select_item is not None:
|
||||||
@ -160,6 +154,8 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
self.search_button.clicked.connect(self.all_matching_clicked)
|
self.search_button.clicked.connect(self.all_matching_clicked)
|
||||||
self.search_button.setDefault(True)
|
self.search_button.setDefault(True)
|
||||||
|
|
||||||
|
self.apply_vl_checkbox.clicked.connect(self.vl_box_changed)
|
||||||
|
|
||||||
self.table.setEditTriggers(QTableWidget.EditKeyPressed)
|
self.table.setEditTriggers(QTableWidget.EditKeyPressed)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -171,7 +167,23 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def vl_box_changed(self):
|
||||||
|
self.fill_in_table(None, None)
|
||||||
|
|
||||||
def fill_in_table(self, tags, tag_to_match):
|
def fill_in_table(self, tags, tag_to_match):
|
||||||
|
self.to_rename = {}
|
||||||
|
self.to_delete = set([])
|
||||||
|
self.all_tags = {}
|
||||||
|
self.original_names = {}
|
||||||
|
|
||||||
|
data = self.get_book_ids(self.apply_vl_checkbox.isChecked())
|
||||||
|
for k,v,count in data:
|
||||||
|
self.all_tags[v] = {'key': k, 'count': count, 'cur_name': v, 'is_deleted': False}
|
||||||
|
self.original_names[k] = v
|
||||||
|
self.ordered_tags = sorted(self.all_tags.keys(), key=self.sorter)
|
||||||
|
if tags is None:
|
||||||
|
tags = self.ordered_tags
|
||||||
|
|
||||||
select_item = None
|
select_item = None
|
||||||
self.table.blockSignals(True)
|
self.table.blockSignals(True)
|
||||||
self.table.clear()
|
self.table.clear()
|
||||||
@ -220,7 +232,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
self.all_tags[tag]['is_deleted'] = item.is_deleted
|
self.all_tags[tag]['is_deleted'] = item.is_deleted
|
||||||
search_for = icu_lower(unicode(self.search_box.text()))
|
search_for = icu_lower(unicode(self.search_box.text()))
|
||||||
if len(search_for) == 0:
|
if len(search_for) == 0:
|
||||||
self.fill_in_table(self.ordered_tags, None)
|
self.fill_in_table(None, None)
|
||||||
result = []
|
result = []
|
||||||
for k in self.ordered_tags:
|
for k in self.ordered_tags:
|
||||||
if search_for in icu_lower(unicode(self.all_tags[k]['cur_name'])):
|
if search_for in icu_lower(unicode(self.all_tags[k]['cur_name'])):
|
||||||
|
@ -59,7 +59,19 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0" colspan="3">
|
||||||
|
<widget class="QCheckBox" name="apply_vl_checkbox">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><p>Show items in the Available items box only if they appear in the
|
||||||
|
current virtual library. Applied items not in the VL will be marked
|
||||||
|
"not on any book".</p></string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>&Show only available items in current virtual library</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="delete_button">
|
<widget class="QToolButton" name="delete_button">
|
||||||
@ -132,7 +144,7 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QTableWidget" name="table">
|
<widget class="QTableWidget" name="table">
|
||||||
<property name="alternatingRowColors">
|
<property name="alternatingRowColors">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
@ -237,13 +237,15 @@ class TagBrowserMixin(object): # {{{
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
db = self.current_db
|
db = self.current_db
|
||||||
data = db.new_api.get_categories()
|
|
||||||
if category in data:
|
def get_book_ids(use_virtual_library):
|
||||||
result = [(t.id, t.original_name, t.count) for t in data[category] if t.count > 0]
|
book_ids = None if not use_virtual_library else self.tags_view.model().get_book_ids_to_use()
|
||||||
else:
|
data = db.new_api.get_categories(book_ids=book_ids)
|
||||||
result = None
|
if category in data:
|
||||||
if result is None:
|
result = [(t.id, t.original_name, t.count) for t in data[category] if t.count > 0]
|
||||||
return
|
else:
|
||||||
|
result = None
|
||||||
|
return result
|
||||||
|
|
||||||
if category == 'series':
|
if category == 'series':
|
||||||
key = lambda x:sort_key(title_sort(x))
|
key = lambda x:sort_key(title_sort(x))
|
||||||
@ -251,7 +253,7 @@ class TagBrowserMixin(object): # {{{
|
|||||||
key = sort_key
|
key = sort_key
|
||||||
|
|
||||||
d = TagListEditor(self, cat_name=db.field_metadata[category]['name'],
|
d = TagListEditor(self, cat_name=db.field_metadata[category]['name'],
|
||||||
tag_to_match=tag, data=result, sorter=key)
|
tag_to_match=tag, get_book_ids=get_book_ids, sorter=key)
|
||||||
d.exec_()
|
d.exec_()
|
||||||
if d.result() == d.Accepted:
|
if d.result() == d.Accepted:
|
||||||
to_rename = d.to_rename # dict of old id to new name
|
to_rename = d.to_rename # dict of old id to new name
|
||||||
|
Loading…
x
Reference in New Issue
Block a user