test: 配置为dock子插件,添加简单QML界面

This commit is contained in:
2026-07-12 21:05:39 +08:00
parent 7461ec43d2
commit 73655f3f6c
3 changed files with 12 additions and 368 deletions
+3 -1
View File
@@ -10,7 +10,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
find_package(Qt6 REQUIRED COMPONENTS Core) find_package(Qt6 REQUIRED COMPONENTS Core Quick)
find_package(Dtk6 REQUIRED COMPONENTS Core) find_package(Dtk6 REQUIRED COMPONENTS Core)
add_library(org.deepin.ds.graphics-driver SHARED add_library(org.deepin.ds.graphics-driver SHARED
@@ -27,9 +27,11 @@ target_include_directories(org.deepin.ds.graphics-driver PRIVATE
target_link_libraries(org.deepin.ds.graphics-driver PRIVATE target_link_libraries(org.deepin.ds.graphics-driver PRIVATE
Qt6::Core Qt6::Core
Qt6::Quick
Dtk6::Core Dtk6::Core
) )
# 安装到dde-shell插件目录 # 安装到dde-shell插件目录
install(TARGETS org.deepin.ds.graphics-driver DESTINATION /usr/lib/x86_64-linux-gnu/dde-shell) install(TARGETS org.deepin.ds.graphics-driver DESTINATION /usr/lib/x86_64-linux-gnu/dde-shell)
install(FILES package/metadata.json DESTINATION /usr/share/dde-shell/org.deepin.ds.graphics-driver) install(FILES package/metadata.json DESTINATION /usr/share/dde-shell/org.deepin.ds.graphics-driver)
install(FILES package/driverview.qml DESTINATION /usr/share/dde-shell/org.deepin.ds.graphics-driver)
+7 -367
View File
@@ -4,384 +4,24 @@
import QtQuick 2.11 import QtQuick 2.11
import QtQuick.Controls 2.4 import QtQuick.Controls 2.4
import QtQuick.Layouts 1.11
import org.deepin.ds 1.0 import org.deepin.ds 1.0
AppletItem { AppletItem {
id: root id: root
objectName: "graphics driver applet" objectName: "graphics driver applet"
implicitWidth: 320 implicitWidth: 100
implicitHeight: 400 implicitHeight: 32
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 { Rectangle {
anchors.fill: parent anchors.fill: parent
color: palette.window color: "#3498db"
radius: 8 radius: 4
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 { Text {
id: badgeText
anchors.centerIn: parent anchors.centerIn: parent
text: root.text text: "GPU"
font.pixelSize: 10 font.pixelSize: 12
color: root.color color: "white"
} }
} }
} }
+2
View File
@@ -2,6 +2,8 @@
"Plugin": { "Plugin": {
"Version": "1.0", "Version": "1.0",
"Id": "org.deepin.ds.graphics-driver", "Id": "org.deepin.ds.graphics-driver",
"Url": "driverview.qml",
"Parent": "org.deepin.ds.dock",
"Category": "DDE" "Category": "DDE"
} }
} }