Enhancement #2000037: Check Library: Open book folder

This commit is contained in:
Charles Haley 2022-12-19 16:14:10 +00:00
parent 85eac7a5b4
commit 015bf3c71b

View File

@ -11,11 +11,12 @@ from qt.core import (
QApplication, QCheckBox, QCursor, QDialog, QDialogButtonBox, QGridLayout,
QHBoxLayout, QIcon, QLabel, QLineEdit, QProgressBar, QPushButton,
QStackedLayout, Qt, QTextEdit, QTreeWidget, QTreeWidgetItem, QVBoxLayout,
QWidget, pyqtSignal, QSplitter
QWidget, pyqtSignal, QSplitter, QToolButton
)
from threading import Thread
from calibre import as_unicode, prints
from calibre.gui2 import open_local_file
from calibre.gui2.dialogs.confirm_delete import confirm
from calibre.library.check_library import CHECKS, CheckLibrary
from calibre.utils.recycle_bin import delete_file, delete_tree
@ -107,8 +108,34 @@ class DBCheck(QDialog): # {{{
# }}}
class Item(QTreeWidgetItem):
pass
class TextWithButtonWidget(QWidget):
button_icon = None
def __init__(self, library_path, text, item_path):
QWidget.__init__(self)
if self.button_icon is None:
self.button_icon = QIcon.ic('document_open.png')
self.library_path = library_path
self.item_path = item_path
l = QHBoxLayout()
l.setContentsMargins(0, 0, 0, 0)
b = QToolButton()
b.setContentsMargins(0, 0, 0, 0)
b.clicked.connect(self.button_clicked)
b.setIcon(self.button_icon)
l.addWidget(b)
t = QLabel(text)
t.setContentsMargins(0, 0, 0, 0)
l.addWidget(t)
self.setLayout(l)
self.setContentsMargins(0, 0, 0, 0)
def button_clicked(self):
p = os.path.join(self.library_path, self.item_path)
if not os.path.isdir(p):
p = os.path.dirname(p)
open_local_file(p)
class CheckLibraryDialog(QDialog):
@ -301,9 +328,9 @@ class CheckLibraryDialog(QDialog):
else:
self.problem_count[attr] = len(list_)
tl = Item()
tl = QTreeWidgetItem()
tl.setText(0, h)
if fixable and list:
if fixable:
tl.setData(1, Qt.ItemDataRole.UserRole, self.is_fixable)
tl.setText(1, _('(fixable)'))
tl.setFlags(Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsUserCheckable)
@ -322,17 +349,17 @@ class CheckLibraryDialog(QDialog):
self.top_level_items[attr] = tl
for problem in list_:
it = Item()
it = QTreeWidgetItem()
tl.addChild(it)
if checkable:
it.setFlags(Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsUserCheckable)
it.setCheckState(2, Qt.CheckState.Unchecked)
it.setData(2, Qt.ItemDataRole.UserRole, self.is_deletable)
else:
it.setFlags(Qt.ItemFlag.ItemIsEnabled)
it.setText(0, problem[0])
tree.setItemWidget(it, 0, TextWithButtonWidget(self.db.library_path, problem[0], problem[1]))
it.setData(0, Qt.ItemDataRole.UserRole, problem[2])
it.setText(2, problem[1])
tl.addChild(it)
self.all_items.append(it)
plaintext.append(','.join([h, problem[0], problem[1]]))
tree.addTopLevelItem(tl)