2023-04-09 13:35:35 +08:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-02-15 19:54:35 +08:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Controls
|
|
|
|
import QtQuick.Layouts
|
|
|
|
|
|
|
|
Item {
|
|
|
|
id: root
|
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
ToolBar {
|
|
|
|
id: bar
|
|
|
|
width: parent.width
|
|
|
|
RowLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
ToolButton {
|
|
|
|
icon.source: AppPath + "/image/modmaker/back"
|
|
|
|
onClicked: mainStack.pop();
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
2023-06-04 19:31:44 +08:00
|
|
|
Label {
|
|
|
|
text: qsTr("Package Manager")
|
|
|
|
horizontalAlignment: Qt.AlignHCenter
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
ToolButton {
|
|
|
|
icon.source: AppPath + "/image/modmaker/menu"
|
|
|
|
onClicked: menu.open()
|
|
|
|
|
|
|
|
Menu {
|
|
|
|
id: menu
|
|
|
|
y: bar.height
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Enable All")
|
|
|
|
onTriggered: {
|
|
|
|
for (let i = 0; i < packageModel.count; i++) {
|
2023-06-09 17:23:02 +08:00
|
|
|
const name = packageModel.get(i).pkgName;
|
2023-06-04 19:31:44 +08:00
|
|
|
Pacman.enablePack(name);
|
|
|
|
}
|
|
|
|
updatePackageList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Disable All")
|
|
|
|
onTriggered: {
|
|
|
|
for (let i = 0; i < packageModel.count; i++) {
|
2023-06-09 17:23:02 +08:00
|
|
|
const name = packageModel.get(i).pkgName;
|
2023-06-04 19:31:44 +08:00
|
|
|
Pacman.disablePack(name);
|
|
|
|
}
|
|
|
|
updatePackageList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Upgrade All")
|
|
|
|
onTriggered: {
|
|
|
|
for (let i = 0; i < packageModel.count; i++) {
|
2023-06-09 17:23:02 +08:00
|
|
|
const name = packageModel.get(i).pkgName;
|
2023-06-04 19:31:44 +08:00
|
|
|
Pacman.upgradePack(name);
|
|
|
|
}
|
|
|
|
updatePackageList();
|
|
|
|
}
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
Rectangle {
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height - bar.height - urlInstaller.height
|
|
|
|
anchors.top: bar.bottom
|
|
|
|
color: "snow"
|
|
|
|
opacity: 0.75
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: packageList
|
2023-06-16 23:53:44 +08:00
|
|
|
clip: true
|
2023-06-04 19:31:44 +08:00
|
|
|
anchors.fill: parent
|
|
|
|
model: ListModel {
|
|
|
|
id: packageModel
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
2023-06-04 19:31:44 +08:00
|
|
|
delegate: ItemDelegate {
|
|
|
|
width: root.width
|
|
|
|
height: 64
|
2023-02-15 19:54:35 +08:00
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
ColumnLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.margins: 8
|
2023-02-15 19:54:35 +08:00
|
|
|
Text {
|
2023-06-04 19:31:44 +08:00
|
|
|
text: "<b>" + pkgName + "</b> (" + pkgVersion + ")"
|
|
|
|
font.pixelSize: 18
|
|
|
|
textFormat: Text.RichText
|
|
|
|
color: pkgEnabled === "1" ? "black" : "grey"
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
|
|
|
Text {
|
2023-06-04 19:31:44 +08:00
|
|
|
text: pkgURL
|
|
|
|
color: pkgEnabled === "1" ? "black" : "grey"
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
2023-06-04 19:31:44 +08:00
|
|
|
}
|
2023-02-15 19:54:35 +08:00
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
Button {
|
|
|
|
id: enableBtn
|
|
|
|
text: pkgEnabled === "0" ? qsTr("Enable") : qsTr("Disable")
|
|
|
|
anchors.right: upgradeBtn.left
|
|
|
|
anchors.rightMargin: 8
|
|
|
|
onClicked: {
|
|
|
|
if (pkgEnabled === "0") {
|
|
|
|
Pacman.enablePack(pkgName);
|
2023-08-02 21:40:00 +08:00
|
|
|
pkgEnabled = "1";
|
2023-06-04 19:31:44 +08:00
|
|
|
} else {
|
|
|
|
Pacman.disablePack(pkgName);
|
2023-08-02 21:40:00 +08:00
|
|
|
pkgEnabled = "0";
|
2023-06-04 19:31:44 +08:00
|
|
|
}
|
2023-08-02 21:40:00 +08:00
|
|
|
// updatePackageList();
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
Button {
|
|
|
|
id: upgradeBtn
|
|
|
|
text: qsTr("Upgrade")
|
|
|
|
anchors.right: delBtn.left
|
|
|
|
anchors.rightMargin: 8
|
|
|
|
onClicked: {
|
|
|
|
Pacman.upgradePack(pkgName);
|
2023-08-02 21:40:00 +08:00
|
|
|
// updatePackageList();
|
|
|
|
const data = JSON.parse(Pacman.listPackages());
|
|
|
|
const e = data[index];
|
|
|
|
packageModel.set(index, {
|
|
|
|
pkgName: e.name,
|
|
|
|
pkgURL: e.url,
|
|
|
|
pkgVersion: e.hash.substring(0, 8),
|
|
|
|
pkgEnabled: e.enabled
|
|
|
|
});
|
2023-06-04 19:31:44 +08:00
|
|
|
}
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
2023-06-04 19:31:44 +08:00
|
|
|
|
|
|
|
Button {
|
|
|
|
id: delBtn
|
|
|
|
text: qsTr("Remove")
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: 8
|
|
|
|
onClicked: {
|
|
|
|
Pacman.removePack(pkgName);
|
2023-08-02 21:40:00 +08:00
|
|
|
// updatePackageList();
|
|
|
|
packageModel.remove(index);
|
2023-06-04 19:31:44 +08:00
|
|
|
}
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
2023-06-04 19:31:44 +08:00
|
|
|
|
2023-02-15 19:54:35 +08:00
|
|
|
onClicked: {
|
2023-06-04 19:31:44 +08:00
|
|
|
Backend.copyToClipboard(pkgURL);
|
|
|
|
toast.show(qsTr("Copied %1.").arg(pkgURL));
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
Rectangle {
|
|
|
|
id: urlInstaller
|
|
|
|
width: parent.width
|
|
|
|
height: childrenRect.height
|
|
|
|
color: "snow"
|
|
|
|
opacity: 0.75
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
width: parent.width
|
|
|
|
TextField {
|
|
|
|
id: urlEdit
|
|
|
|
Layout.fillWidth: true
|
|
|
|
clip: true
|
|
|
|
}
|
2023-02-15 19:54:35 +08:00
|
|
|
|
2023-06-04 19:31:44 +08:00
|
|
|
Button {
|
|
|
|
text: qsTr("Install From URL")
|
|
|
|
enabled: urlEdit.text !== ""
|
|
|
|
onClicked: {
|
2023-06-09 17:23:02 +08:00
|
|
|
const url = urlEdit.text;
|
2023-06-04 19:31:44 +08:00
|
|
|
mainWindow.busy = true;
|
|
|
|
Pacman.downloadNewPack(url, true);
|
|
|
|
}
|
2023-02-15 19:54:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updatePackageList() {
|
|
|
|
packageModel.clear();
|
2023-06-09 17:23:02 +08:00
|
|
|
const data = JSON.parse(Pacman.listPackages());
|
2023-02-15 19:54:35 +08:00
|
|
|
data.forEach(e => packageModel.append({
|
|
|
|
pkgName: e.name,
|
|
|
|
pkgURL: e.url,
|
|
|
|
pkgVersion: e.hash.substring(0, 8),
|
|
|
|
pkgEnabled: e.enabled
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
function downloadComplete() {
|
2023-06-09 17:23:02 +08:00
|
|
|
const idx = packageList.currentIndex;
|
2023-02-15 19:54:35 +08:00
|
|
|
updatePackageList();
|
|
|
|
packageList.currentIndex = idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
Component.onCompleted: {
|
|
|
|
updatePackageList();
|
|
|
|
}
|
|
|
|
}
|