mirror of
https://github.com/leminlimez/Nugget.git
synced 2025-04-08 04:23:05 +08:00
count descriptors and update icon
This commit is contained in:
@@ -41,6 +41,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
self.ui = Ui_Nugget()
|
self.ui = Ui_Nugget()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
self.show_uuid = False
|
self.show_uuid = False
|
||||||
|
self.pb_mainLayout = None
|
||||||
self.loadSettings()
|
self.loadSettings()
|
||||||
|
|
||||||
# Check for an update
|
# Check for an update
|
||||||
@@ -835,52 +836,61 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
tweaks["Daemons"].set_multiple_values(Daemon.VoiceControl.value, value=checked)
|
tweaks["Daemons"].set_multiple_values(Daemon.VoiceControl.value, value=checked)
|
||||||
|
|
||||||
## PosterBoard Page
|
## PosterBoard Page
|
||||||
def delete_pb_file(self, file):
|
def delete_pb_file(self, file, widget):
|
||||||
if file in tweaks["PosterBoard"].zip_paths:
|
if file in tweaks["PosterBoard"].tendies:
|
||||||
tweaks["PosterBoard"].zip_paths.remove(file)
|
tweaks["PosterBoard"].tendies.remove(file)
|
||||||
#self.load_posterboard()
|
widget.deleteLater()
|
||||||
|
|
||||||
def load_posterboard(self):
|
def load_posterboard(self):
|
||||||
# Clear the layout
|
if len(tweaks["PosterBoard"].tendies) == 0:
|
||||||
layout = self.ui.pbFilesList.layout()
|
|
||||||
if layout:
|
|
||||||
while layout.count():
|
|
||||||
child = layout.takeAt(0)
|
|
||||||
widget = child.widget()
|
|
||||||
if widget:
|
|
||||||
widget.deleteLater()
|
|
||||||
del child
|
|
||||||
del layout
|
|
||||||
self.ui.pbFilesList.setLayout(None)
|
|
||||||
|
|
||||||
# Clear the widget contents
|
|
||||||
for child in self.ui.pbFilesList.children():
|
|
||||||
child.deleteLater()
|
|
||||||
|
|
||||||
if len(tweaks["PosterBoard"].zip_paths) == 0:
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Create scroll layout
|
if self.pb_mainLayout == None:
|
||||||
mainLayout = QtWidgets.QVBoxLayout()
|
# Create scroll layout
|
||||||
mainLayout.setContentsMargins(0, 0, 0, 0)
|
self.pb_mainLayout = QtWidgets.QVBoxLayout()
|
||||||
mainLayout.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
|
self.pb_mainLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
self.pb_mainLayout.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop)
|
||||||
|
# Create a QWidget to act as the container for the scroll area
|
||||||
|
scrollWidget = QtWidgets.QWidget()
|
||||||
|
|
||||||
|
# Set the main layout (containing all the widgets) on the scroll widget
|
||||||
|
scrollWidget.setLayout(self.pb_mainLayout)
|
||||||
|
|
||||||
|
# Create a QScrollArea to hold the content widget (scrollWidget)
|
||||||
|
scrollArea = QtWidgets.QScrollArea()
|
||||||
|
scrollArea.setWidgetResizable(True) # Allow the content widget to resize within the scroll area
|
||||||
|
scrollArea.setFrameStyle(QtWidgets.QScrollArea.NoFrame) # Remove the outline from the scroll area
|
||||||
|
|
||||||
|
# Set the scrollWidget as the content widget of the scroll area
|
||||||
|
scrollArea.setWidget(scrollWidget)
|
||||||
|
|
||||||
|
# Set the size policy of the scroll area to expand in both directions
|
||||||
|
scrollArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
|
||||||
|
|
||||||
|
# Set the scroll area as the central widget of the main window
|
||||||
|
scrollLayout = QtWidgets.QVBoxLayout()
|
||||||
|
scrollLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
scrollLayout.addWidget(scrollArea)
|
||||||
|
self.ui.pbFilesList.setLayout(scrollLayout)
|
||||||
|
|
||||||
# Iterate through the files
|
# Iterate through the files
|
||||||
for tendie in tweaks["PosterBoard"].zip_paths:
|
for tendie in tweaks["PosterBoard"].tendies:
|
||||||
|
if tendie.loaded:
|
||||||
|
continue
|
||||||
widget = QtWidgets.QWidget()
|
widget = QtWidgets.QWidget()
|
||||||
|
|
||||||
# create the icon/label
|
# create the icon/label
|
||||||
titleBtn = QtWidgets.QToolButton(widget)
|
titleBtn = QtWidgets.QToolButton(widget)
|
||||||
titleBtn.setIcon(QtGui.QIcon(":/icon/photo-stack.svg"))
|
titleBtn.setIcon(QtGui.QIcon(tendie.get_icon()))
|
||||||
titleBtn.setIconSize(QtCore.QSize(20, 20))
|
titleBtn.setIconSize(QtCore.QSize(20, 20))
|
||||||
titleBtn.setText(f" {tendie}")
|
titleBtn.setText(f" {tendie.path}")
|
||||||
titleBtn.setStyleSheet("QToolButton {\n background-color: transparent;\n icon-size: 20px;\n}")
|
titleBtn.setStyleSheet("QToolButton {\n background-color: transparent;\n icon-size: 20px;\n}")
|
||||||
titleBtn.setToolButtonStyle(QtCore.Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
|
titleBtn.setToolButtonStyle(QtCore.Qt.ToolButtonStyle.ToolButtonTextBesideIcon)
|
||||||
titleBtn.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
titleBtn.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
|
||||||
|
|
||||||
delBtn = QtWidgets.QToolButton(widget)
|
delBtn = QtWidgets.QToolButton(widget)
|
||||||
delBtn.setIcon(QtGui.QIcon(":/icon/trash.svg"))
|
delBtn.setIcon(QtGui.QIcon(":/icon/trash.svg"))
|
||||||
delBtn.clicked.connect(lambda _, file=tendie: self.delete_pb_file(file))
|
delBtn.clicked.connect(lambda _, file=tendie: self.delete_pb_file(file, widget))
|
||||||
|
|
||||||
spacer = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
spacer = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
|
||||||
# main layout
|
# main layout
|
||||||
@@ -891,30 +901,8 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
layout.addWidget(delBtn)
|
layout.addWidget(delBtn)
|
||||||
# Add the widget to the mainLayout
|
# Add the widget to the mainLayout
|
||||||
widget.setLayout(layout)
|
widget.setLayout(layout)
|
||||||
mainLayout.addWidget(widget)
|
self.pb_mainLayout.addWidget(widget)
|
||||||
|
tendie.loaded = True
|
||||||
# Create a QWidget to act as the container for the scroll area
|
|
||||||
scrollWidget = QtWidgets.QWidget()
|
|
||||||
|
|
||||||
# Set the main layout (containing all the widgets) on the scroll widget
|
|
||||||
scrollWidget.setLayout(mainLayout)
|
|
||||||
|
|
||||||
# Create a QScrollArea to hold the content widget (scrollWidget)
|
|
||||||
scrollArea = QtWidgets.QScrollArea()
|
|
||||||
scrollArea.setWidgetResizable(True) # Allow the content widget to resize within the scroll area
|
|
||||||
scrollArea.setFrameStyle(QtWidgets.QScrollArea.NoFrame) # Remove the outline from the scroll area
|
|
||||||
|
|
||||||
# Set the scrollWidget as the content widget of the scroll area
|
|
||||||
scrollArea.setWidget(scrollWidget)
|
|
||||||
|
|
||||||
# Set the size policy of the scroll area to expand in both directions
|
|
||||||
scrollArea.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
|
|
||||||
|
|
||||||
# Set the scroll area as the central widget of the main window
|
|
||||||
scrollLayout = QtWidgets.QVBoxLayout()
|
|
||||||
scrollLayout.setContentsMargins(0, 0, 0, 0)
|
|
||||||
scrollLayout.addWidget(scrollArea)
|
|
||||||
self.ui.pbFilesList.setLayout(scrollLayout)
|
|
||||||
|
|
||||||
def on_modifyPosterboardsChk_clicked(self, checked: bool):
|
def on_modifyPosterboardsChk_clicked(self, checked: bool):
|
||||||
tweaks["PosterBoard"].set_enabled(checked)
|
tweaks["PosterBoard"].set_enabled(checked)
|
||||||
@@ -924,17 +912,15 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
tweaks["PosterBoard"].resetting = False
|
tweaks["PosterBoard"].resetting = False
|
||||||
if selected_files != None and len(selected_files) > 0:
|
if selected_files != None and len(selected_files) > 0:
|
||||||
# user selected files, add them
|
# user selected files, add them
|
||||||
# but limit to 10
|
for file in selected_files:
|
||||||
if len(selected_files) + len(tweaks["PosterBoard"].zip_paths) > 10:
|
if not tweaks["PosterBoard"].add_tendie(file):
|
||||||
# alert that there are too many
|
# alert that there are too many
|
||||||
detailsBox = QtWidgets.QMessageBox()
|
detailsBox = QtWidgets.QMessageBox()
|
||||||
detailsBox.setIcon(QtWidgets.QMessageBox.Critical)
|
detailsBox.setIcon(QtWidgets.QMessageBox.Critical)
|
||||||
detailsBox.setWindowTitle("Error!")
|
detailsBox.setWindowTitle("Error!")
|
||||||
detailsBox.setText("You selected too many descriptors! The limit is 10.")
|
detailsBox.setText("You selected too many descriptors! The limit is 10.")
|
||||||
detailsBox.exec()
|
detailsBox.exec()
|
||||||
else:
|
self.load_posterboard()
|
||||||
tweaks["PosterBoard"].zip_paths.extend(selected_files)
|
|
||||||
self.load_posterboard()
|
|
||||||
|
|
||||||
def on_deleteAllDescriptorsBtn_clicked(self):
|
def on_deleteAllDescriptorsBtn_clicked(self):
|
||||||
if tweaks["PosterBoard"].resetting and tweaks["PosterBoard"].resetType == 0:
|
if tweaks["PosterBoard"].resetting and tweaks["PosterBoard"].resetType == 0:
|
||||||
|
|||||||
@@ -9,14 +9,67 @@ from Sparserestore.restore import FileToRestore
|
|||||||
from controllers.plist_handler import set_plist_value
|
from controllers.plist_handler import set_plist_value
|
||||||
from qt.ui_mainwindow import Ui_Nugget
|
from qt.ui_mainwindow import Ui_Nugget
|
||||||
|
|
||||||
|
class TendieFile:
|
||||||
|
path: str
|
||||||
|
descriptor_cnt: int
|
||||||
|
loaded: bool
|
||||||
|
|
||||||
|
def __init__(self, path: str):
|
||||||
|
self.path = path
|
||||||
|
self.descriptor_cnt = 0
|
||||||
|
self.loaded = False
|
||||||
|
# read the contents
|
||||||
|
with zipfile.ZipFile(path, mode="r") as archive:
|
||||||
|
for option in archive.namelist():
|
||||||
|
if "__macosx/" in option.lower():
|
||||||
|
continue
|
||||||
|
elif "container" in option.lower():
|
||||||
|
self.descriptor_cnt = -1
|
||||||
|
return
|
||||||
|
elif "descriptor/" in option.lower():
|
||||||
|
item = option.lower().split("descriptor/")[1]
|
||||||
|
if item.count('/') == 1 and item.endswith('/'):
|
||||||
|
self.descriptor_cnt += 1
|
||||||
|
elif "descriptors/" in option.lower():
|
||||||
|
item = option.lower().split("descriptors/")[1]
|
||||||
|
if item.count('/') == 1 and item.endswith('/'):
|
||||||
|
self.descriptor_cnt += 1
|
||||||
|
|
||||||
|
def get_icon(self):
|
||||||
|
if self.descriptor_cnt == -1:
|
||||||
|
# container
|
||||||
|
return ":/icon/shippingbox.svg"
|
||||||
|
elif self.descriptor_cnt == 1:
|
||||||
|
# single descriptor
|
||||||
|
return ":/icon/photo.svg"
|
||||||
|
else:
|
||||||
|
# multiple descriptors
|
||||||
|
return ":/icon/photo-stack.svg"
|
||||||
|
|
||||||
class PosterboardTweak(Tweak):
|
class PosterboardTweak(Tweak):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(key=None)
|
super().__init__(key=None)
|
||||||
self.zip_paths: list[str] = []
|
self.tendies: list[TendieFile] = []
|
||||||
self.bundle_id = "com.apple.PosterBoard"
|
self.bundle_id = "com.apple.PosterBoard"
|
||||||
self.resetting = False
|
self.resetting = False
|
||||||
self.resetType = 0 # 0 for descriptor 1 for prb
|
self.resetType = 0 # 0 for descriptor 1 for prb
|
||||||
|
|
||||||
|
def add_tendie(self, file: str):
|
||||||
|
new_tendie = TendieFile(path=file)
|
||||||
|
if new_tendie.descriptor_cnt + self.get_descriptor_count() <= 10:
|
||||||
|
self.tendies.append(new_tendie)
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_descriptor_count(self):
|
||||||
|
cnt = 0
|
||||||
|
for tendie in self.tendies:
|
||||||
|
if tendie.descriptor_cnt == -1:
|
||||||
|
cnt += 1
|
||||||
|
else:
|
||||||
|
cnt += tendie.descriptor_cnt
|
||||||
|
return cnt
|
||||||
|
|
||||||
def update_plist_id(self, file_path: str, file_name: str, randomizedID: int):
|
def update_plist_id(self, file_path: str, file_name: str, randomizedID: int):
|
||||||
if file_name == "com.apple.posterkit.provider.descriptor.identifier":
|
if file_name == "com.apple.posterkit.provider.descriptor.identifier":
|
||||||
return str(randomizedID).encode()
|
return str(randomizedID).encode()
|
||||||
@@ -96,10 +149,10 @@ class PosterboardTweak(Tweak):
|
|||||||
domain=f"AppDomain-{self.bundle_id}"
|
domain=f"AppDomain-{self.bundle_id}"
|
||||||
))
|
))
|
||||||
return
|
return
|
||||||
elif self.zip_paths == None or len(self.zip_paths) == 0:
|
elif self.tendies == None or len(self.tendies) == 0:
|
||||||
return
|
return
|
||||||
for zip_path in self.zip_paths:
|
for tendie in self.tendies:
|
||||||
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
with zipfile.ZipFile(tendie.path, 'r') as zip_ref:
|
||||||
zip_ref.extractall(output_dir)
|
zip_ref.extractall(output_dir)
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
# try to get past directory name limit on windows
|
# try to get past directory name limit on windows
|
||||||
|
|||||||
Reference in New Issue
Block a user