// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: LGPL-3.0-or-later import QtQuick 2.11 import QtQuick.Controls 2.4 import QtQuick.Layouts 1.11 import org.deepin.ds 1.0 AppletItem { id: root objectName: "graphics driver applet" implicitWidth: 320 implicitHeight: 400 property var applet: Applet Connections { target: root.applet function onInstallSuccess() { successDialog.open() } function onInstallFailed(error) { errorDialog.text = error errorDialog.open() } function onRequestReboot() { rebootDialog.open() } } Rectangle { anchors.fill: parent color: palette.window radius: 8 ColumnLayout { anchors.fill: parent anchors.margins: 16 spacing: 12 RowLayout { Layout.fillWidth: true Image { source: "qrc:/icons/graphics-card.svg" Layout.preferredWidth: 24 Layout.preferredHeight: 24 } Text { text: qsTr("Graphics Driver Manager") font.pixelSize: 14 font.bold: true color: palette.text Layout.fillWidth: true } Button { text: qsTr("Refresh") flat: true onClicked: root.applet.refreshDeviceInfo() } } Rectangle { Layout.fillWidth: true Layout.preferredHeight: 1 color: palette.separator } GroupBox { Layout.fillWidth: true title: qsTr("Device Information") ColumnLayout { anchors.fill: parent spacing: 8 RowLayout { Text { text: qsTr("Vendor:") font.pixelSize: 12 color: palette.placeholderText Layout.preferredWidth: 80 } Text { text: root.applet.deviceInfo ? JSON.parse(root.applet.deviceInfo).vendor || "-" : "-" font.pixelSize: 12 color: palette.text Layout.fillWidth: true } } RowLayout { Text { text: qsTr("Model:") font.pixelSize: 12 color: palette.placeholderText Layout.preferredWidth: 80 } Text { text: root.applet.deviceInfo ? JSON.parse(root.applet.deviceInfo).model || "-" : "-" font.pixelSize: 12 color: palette.text Layout.fillWidth: true } } RowLayout { Text { text: qsTr("Current Driver:") font.pixelSize: 12 color: palette.placeholderText Layout.preferredWidth: 80 } Text { text: root.applet.currentDriver || "-" font.pixelSize: 12 color: palette.text Layout.fillWidth: true } } } } GroupBox { Layout.fillWidth: true Layout.fillHeight: true title: qsTr("Available Drivers") ListView { anchors.fill: parent model: root.applet.availableDrivers clip: true delegate: ItemDelegate { width: parent.width height: 60 contentItem: ColumnLayout { spacing: 4 RowLayout { Text { text: modelData.name || qsTr("Unknown Driver") font.pixelSize: 13 font.bold: true color: palette.text Layout.fillWidth: true } Badge { visible: modelData.name === root.applet.currentDriver text: qsTr("Current") color: "green" } Badge { visible: modelData.name === root.applet.newDriver && modelData.name !== root.applet.currentDriver text: qsTr("Recommended") color: "blue" } } Text { text: modelData.description || "" font.pixelSize: 11 color: palette.placeholderText Layout.fillWidth: true elide: Text.ElideRight maximumLineCount: 1 } Button { visible: modelData.name !== root.applet.currentDriver && !root.applet.isInstalling text: qsTr("Switch") flat: true Layout.alignment: Qt.AlignRight onClicked: { root.applet.prepareInstall(modelData.name) installConfirmDialog.driverName = modelData.name installConfirmDialog.open() } } } } } } ColumnLayout { Layout.fillWidth: true visible: root.applet.isInstalling spacing: 8 RowLayout { Text { text: qsTr("Installing...") font.pixelSize: 12 color: palette.text Layout.fillWidth: true } Text { text: root.applet.installProgress + "%" font.pixelSize: 12 color: palette.text } } ProgressBar { Layout.fillWidth: true value: root.applet.installProgress / 100 } Button { text: qsTr("Cancel") flat: true Layout.alignment: Qt.AlignRight onClicked: root.applet.cancelInstall() } } } } Dialog { id: installConfirmDialog property string driverName title: qsTr("Confirm Driver Switch") modal: true anchors.centerIn: parent width: 300 contentItem: ColumnLayout { spacing: 16 Text { text: qsTr("Are you sure you want to switch to driver: %1?").arg(installConfirmDialog.driverName) wrapMode: Text.WordWrap Layout.fillWidth: true } RowLayout { Layout.fillWidth: true Layout.alignment: Qt.AlignRight spacing: 8 Button { text: qsTr("Cancel") flat: true onClicked: installConfirmDialog.close() } Button { text: qsTr("Confirm") onClicked: { root.applet.testInstall() installConfirmDialog.close() } } } } } Dialog { id: successDialog title: qsTr("Installation Success") modal: true anchors.centerIn: parent width: 300 contentItem: ColumnLayout { spacing: 16 Text { text: qsTr("Driver has been installed successfully. Do you want to reboot now?") wrapMode: Text.WordWrap Layout.fillWidth: true } RowLayout { Layout.fillWidth: true Layout.alignment: Qt.AlignRight spacing: 8 Button { text: qsTr("Later") flat: true onClicked: successDialog.close() } Button { text: qsTr("Reboot Now") onClicked: { DUtil.reboot() successDialog.close() } } } } } Dialog { id: errorDialog property string text title: qsTr("Installation Failed") modal: true anchors.centerIn: parent width: 300 contentItem: ColumnLayout { spacing: 16 Text { text: errorDialog.text wrapMode: Text.WordWrap Layout.fillWidth: true } RowLayout { Layout.fillWidth: true Layout.alignment: Qt.AlignRight Button { text: qsTr("OK") onClicked: errorDialog.close() } } } } Dialog { id: rebootDialog title: qsTr("Reboot Required") modal: true anchors.centerIn: parent width: 300 contentItem: ColumnLayout { spacing: 16 Text { text: qsTr("A reboot is required to apply the driver changes. Do you want to reboot now?") wrapMode: Text.WordWrap Layout.fillWidth: true } RowLayout { Layout.fillWidth: true Layout.alignment: Qt.AlignRight spacing: 8 Button { text: qsTr("Later") flat: true onClicked: rebootDialog.close() } Button { text: qsTr("Reboot Now") onClicked: { DUtil.reboot() rebootDialog.close() } } } } } component Badge: Rectangle { property string text property color color: "blue" width: badgeText.implicitWidth + 12 height: 18 radius: 9 color: Qt.rgba(color.r, color.g, color.b, 0.2) Text { id: badgeText anchors.centerIn: parent text: root.text font.pixelSize: 10 color: root.color } } }