feat: 移除D-Bus依赖,改用 lspci 直接检测显卡,重构弹窗UI
- C++ 后端:移除 D-Bus 通信,改用 lspci -mm + /sys/bus/pci 直接检测显卡和驱动 - 新增 gpuSummary、ready 属性,通过 /sys/module 和 /proc/driver 读取驱动版本 - QML:使用 DTK 配色,卡片式布局展示 GPU 列表,每张显卡独立卡片 - 移除安装/测试/取消按钮,聚焦显卡信息展示 - 翻译精简为 5 条,同步 zh_CN / zh_TW
This commit is contained in:
+203
-108
@@ -7,6 +7,7 @@ import QtQuick.Controls 2.15
|
||||
import QtQuick.Layouts 1.15
|
||||
import org.deepin.ds 1.0
|
||||
import org.deepin.ds.dock 1.0
|
||||
import org.deepin.dtk 1.0
|
||||
|
||||
AppletItem {
|
||||
id: root
|
||||
@@ -17,24 +18,32 @@ AppletItem {
|
||||
implicitWidth: dockSize
|
||||
implicitHeight: dockSize
|
||||
|
||||
// 访问 C++ 后端
|
||||
readonly property var applet: Applet
|
||||
readonly property bool dbusAvailable: applet && applet.dbusAvailable
|
||||
readonly property string currentDriver: applet ? (applet.currentDriver || qsTr("Unknown")) : qsTr("Unknown")
|
||||
readonly property bool ready: applet ? applet.ready : false
|
||||
readonly property string gpuSummary: applet ? (applet.gpuSummary || qsTr("No GPU detected")) : qsTr("No GPU detected")
|
||||
readonly property string deviceInfo: applet ? (applet.deviceInfo || qsTr("Unknown")) : qsTr("Unknown")
|
||||
readonly property bool isInstalling: applet ? applet.isInstalling : false
|
||||
readonly property int installProgress: applet ? applet.installProgress : 0
|
||||
readonly property string currentDriver: applet ? (applet.currentDriver || qsTr("Unknown")) : qsTr("Unknown")
|
||||
|
||||
property Palette basePalette: DockPalette.iconTextPalette
|
||||
readonly property color primaryText: Qt.rgba(basePalette.r, basePalette.g, basePalette.b, 0.9)
|
||||
readonly property color secondaryText: Qt.rgba(basePalette.r, basePalette.g, basePalette.b, 0.65)
|
||||
readonly property color tertiaryText: Qt.rgba(basePalette.r, basePalette.g, basePalette.b, 0.5)
|
||||
readonly property color cardBackground: Qt.rgba(basePalette.r, basePalette.g, basePalette.b, 0.06)
|
||||
readonly property color cardBorder: Qt.rgba(basePalette.r, basePalette.g, basePalette.b, 0.1)
|
||||
readonly property color accentBlue: Qt.rgba(36 / 255, 118 / 255, 220 / 255, 1)
|
||||
readonly property color accentBlueLight: Qt.rgba(36 / 255, 118 / 255, 220 / 255, 0.15)
|
||||
|
||||
// 图标区域
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: "#3498db"
|
||||
color: accentBlue
|
||||
radius: 8
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "GPU"
|
||||
font.pixelSize: root.dockSize * 0.3
|
||||
font.bold: true
|
||||
color: "white"
|
||||
}
|
||||
}
|
||||
@@ -42,7 +51,7 @@ AppletItem {
|
||||
// 悬停提示
|
||||
PanelToolTip {
|
||||
id: toolTip
|
||||
text: qsTr("Graphics Driver: ") + root.currentDriver
|
||||
text: root.ready ? root.gpuSummary : qsTr("No GPU detected")
|
||||
toolTipX: DockPanelPositioner.x
|
||||
toolTipY: DockPanelPositioner.y
|
||||
}
|
||||
@@ -73,8 +82,8 @@ AppletItem {
|
||||
// 弹出窗口
|
||||
PanelPopup {
|
||||
id: driverPopup
|
||||
width: 320
|
||||
height: 400
|
||||
width: 360
|
||||
height: 320
|
||||
popupX: DockPanelPositioner.x
|
||||
popupY: DockPanelPositioner.y
|
||||
|
||||
@@ -90,114 +99,196 @@ AppletItem {
|
||||
padding: 16
|
||||
|
||||
contentItem: ColumnLayout {
|
||||
spacing: 12
|
||||
spacing: 14
|
||||
|
||||
Text {
|
||||
text: qsTr("Graphics Driver Manager")
|
||||
font.pixelSize: 16
|
||||
font.bold: true
|
||||
// 标题区域
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 10
|
||||
|
||||
Rectangle {
|
||||
width: 28
|
||||
height: 28
|
||||
color: accentBlueLight
|
||||
radius: 8
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "GPU"
|
||||
font.pixelSize: 12
|
||||
font.bold: true
|
||||
color: accentBlue
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: qsTr("Graphics Driver Manager")
|
||||
font.pixelSize: 16
|
||||
font.bold: true
|
||||
color: root.primaryText
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
|
||||
// 分隔线
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 1
|
||||
color: "#cccccc"
|
||||
color: root.cardBorder
|
||||
}
|
||||
|
||||
// D-Bus 不可用提示
|
||||
Rectangle {
|
||||
Layout.fillWidth: true
|
||||
height: 40
|
||||
visible: !root.dbusAvailable
|
||||
color: "#fff3cd"
|
||||
radius: 6
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: qsTr("Driver service is not available")
|
||||
color: "#856404"
|
||||
font.pixelSize: 12
|
||||
}
|
||||
}
|
||||
|
||||
// 设备信息
|
||||
GroupBox {
|
||||
Layout.fillWidth: true
|
||||
title: qsTr("Device Information")
|
||||
visible: root.dbusAvailable
|
||||
|
||||
ColumnLayout {
|
||||
anchors.fill: parent
|
||||
spacing: 8
|
||||
|
||||
Text {
|
||||
text: qsTr("Current Driver: ") + root.currentDriver
|
||||
font.pixelSize: 12
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
Text {
|
||||
text: qsTr("Device: ") + root.deviceInfo
|
||||
font.pixelSize: 12
|
||||
wrapMode: Text.WordWrap
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 操作按钮
|
||||
Button {
|
||||
text: qsTr("Refresh")
|
||||
Layout.fillWidth: true
|
||||
enabled: root.dbusAvailable && !root.isInstalling
|
||||
onClicked: {
|
||||
if (root.applet) {
|
||||
root.applet.refreshDeviceInfo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: qsTr("Test Install")
|
||||
Layout.fillWidth: true
|
||||
enabled: root.dbusAvailable && !root.isInstalling
|
||||
onClicked: {
|
||||
if (root.applet) {
|
||||
root.applet.testInstall()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 安装进度
|
||||
ColumnLayout {
|
||||
visible: root.isInstalling
|
||||
// 当前驱动信息
|
||||
RowLayout {
|
||||
Layout.fillWidth: true
|
||||
spacing: 8
|
||||
visible: root.ready
|
||||
|
||||
Text {
|
||||
text: qsTr("Installing... ") + root.installProgress + "%"
|
||||
text: qsTr("Current Driver:")
|
||||
font.pixelSize: 12
|
||||
color: root.secondaryText
|
||||
}
|
||||
|
||||
ProgressBar {
|
||||
Text {
|
||||
text: root.currentDriver
|
||||
font.pixelSize: 12
|
||||
font.bold: true
|
||||
color: root.primaryText
|
||||
Layout.fillWidth: true
|
||||
value: root.installProgress / 100
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
}
|
||||
|
||||
// GPU 列表区域
|
||||
Flickable {
|
||||
id: gpuListFlick
|
||||
Layout.fillWidth: true
|
||||
Layout.fillHeight: true
|
||||
clip: true
|
||||
contentWidth: width
|
||||
contentHeight: gpuColumn.height
|
||||
boundsBehavior: Flickable.StopAtBounds
|
||||
|
||||
Column {
|
||||
id: gpuColumn
|
||||
width: gpuListFlick.width
|
||||
spacing: 10
|
||||
visible: root.ready
|
||||
|
||||
Repeater {
|
||||
model: root.ready ? root.deviceInfo.split("\n").filter(function(line) { return line.trim().length > 0 }) : []
|
||||
|
||||
delegate: Rectangle {
|
||||
width: gpuColumn.width
|
||||
height: 72
|
||||
color: root.cardBackground
|
||||
radius: 10
|
||||
border.width: 1
|
||||
border.color: root.cardBorder
|
||||
|
||||
RowLayout {
|
||||
anchors.fill: parent
|
||||
anchors.margins: 12
|
||||
spacing: 12
|
||||
|
||||
// GPU 图标
|
||||
Rectangle {
|
||||
width: 44
|
||||
height: 44
|
||||
color: root.accentBlueLight
|
||||
radius: 8
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "GPU"
|
||||
font.pixelSize: 14
|
||||
font.bold: true
|
||||
color: root.accentBlue
|
||||
}
|
||||
}
|
||||
|
||||
// GPU 信息
|
||||
ColumnLayout {
|
||||
spacing: 4
|
||||
Layout.fillWidth: true
|
||||
|
||||
Text {
|
||||
text: parseGpuName(modelData)
|
||||
font.pixelSize: 13
|
||||
font.bold: true
|
||||
color: root.primaryText
|
||||
Layout.fillWidth: true
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
|
||||
Text {
|
||||
text: parseDriverInfo(modelData)
|
||||
font.pixelSize: 11
|
||||
color: root.secondaryText
|
||||
Layout.fillWidth: true
|
||||
elide: Text.ElideRight
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
text: qsTr("Cancel")
|
||||
Layout.fillWidth: true
|
||||
onClicked: {
|
||||
if (root.applet) {
|
||||
root.applet.cancelInstall()
|
||||
// 未检测到 GPU 提示
|
||||
Rectangle {
|
||||
anchors.centerIn: parent
|
||||
width: gpuListFlick.width - 32
|
||||
height: 80
|
||||
color: root.cardBackground
|
||||
radius: 10
|
||||
border.width: 1
|
||||
border.color: root.cardBorder
|
||||
visible: !root.ready
|
||||
|
||||
ColumnLayout {
|
||||
anchors.centerIn: parent
|
||||
spacing: 6
|
||||
|
||||
Text {
|
||||
text: "⚠"
|
||||
font.pixelSize: 24
|
||||
}
|
||||
|
||||
Text {
|
||||
text: qsTr("No GPU detected")
|
||||
font.pixelSize: 13
|
||||
color: root.secondaryText
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillHeight: true
|
||||
// 刷新按钮
|
||||
Button {
|
||||
id: refreshBtn
|
||||
text: qsTr("Refresh")
|
||||
Layout.fillWidth: true
|
||||
Layout.preferredHeight: 36
|
||||
font.pixelSize: 13
|
||||
|
||||
background: Rectangle {
|
||||
color: refreshBtn.hovered ? root.accentBlue : root.accentBlueLight
|
||||
radius: 8
|
||||
}
|
||||
|
||||
contentItem: Text {
|
||||
text: refreshBtn.text
|
||||
color: refreshBtn.hovered ? "white" : root.accentBlue
|
||||
font.pixelSize: refreshBtn.font.pixelSize
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
if (root.applet) {
|
||||
root.applet.refreshDeviceInfo()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,6 +301,25 @@ AppletItem {
|
||||
}
|
||||
}
|
||||
|
||||
// 解析 GPU 名称的辅助函数
|
||||
function parseGpuName(info) {
|
||||
var parts = info.split("(")
|
||||
if (parts.length > 0) {
|
||||
return parts[0].trim()
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
// 解析驱动信息的辅助函数
|
||||
function parseDriverInfo(info) {
|
||||
var startIndex = info.indexOf("(")
|
||||
var endIndex = info.lastIndexOf(")")
|
||||
if (startIndex !== -1 && endIndex !== -1) {
|
||||
return info.substring(startIndex + 1, endIndex)
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
// 点击处理
|
||||
TapHandler {
|
||||
acceptedButtons: Qt.LeftButton
|
||||
@@ -220,7 +330,6 @@ AppletItem {
|
||||
driverPopup.close()
|
||||
} else {
|
||||
Panel.requestClosePopup()
|
||||
// 在打开前设置定位,确保弹窗出现在插件附近
|
||||
const point = root.mapToItem(null, root.width / 2, root.height / 2)
|
||||
driverPopup.DockPanelPositioner.bounding = Qt.rect(point.x, point.y, driverPopup.width, driverPopup.height)
|
||||
driverPopup.open()
|
||||
@@ -228,18 +337,4 @@ AppletItem {
|
||||
toolTip.close()
|
||||
}
|
||||
}
|
||||
|
||||
// 后端信号处理
|
||||
Connections {
|
||||
target: root.applet
|
||||
function onInstallSuccess() {
|
||||
console.log("Install succeeded")
|
||||
}
|
||||
function onInstallFailed(error) {
|
||||
console.log("Install failed:", error)
|
||||
}
|
||||
function onRequestReboot() {
|
||||
console.log("Reboot requested")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user