feat: 初始化项目骨架
- 创建插件元数据 package/metadata.json - 实现主插件类 GraphicsDriverApplet (D-Bus通信) - 实现GPU指示器类 GpuIndicator (设备信息解析) - 创建QML界面 driverview.qml (驱动管理UI) - 添加CMake构建配置 - 编写开发指南文档 docs/DEVELOPMENT.md
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "gpuindicator.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QDebug>
|
||||
|
||||
GpuIndicator::GpuIndicator(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
GpuIndicator::~GpuIndicator()
|
||||
{
|
||||
}
|
||||
|
||||
QString GpuIndicator::vendor() const
|
||||
{
|
||||
return m_vendor;
|
||||
}
|
||||
|
||||
QString GpuIndicator::model() const
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
|
||||
QString GpuIndicator::driverVersion() const
|
||||
{
|
||||
return m_driverVersion;
|
||||
}
|
||||
|
||||
QString GpuIndicator::driverStatus() const
|
||||
{
|
||||
return m_driverStatus;
|
||||
}
|
||||
|
||||
QString GpuIndicator::icon() const
|
||||
{
|
||||
return determineIcon();
|
||||
}
|
||||
|
||||
bool GpuIndicator::isNvidia() const
|
||||
{
|
||||
return m_vendor.toLower().contains("nvidia");
|
||||
}
|
||||
|
||||
bool GpuIndicator::isAmd() const
|
||||
{
|
||||
return m_vendor.toLower().contains("amd") || m_vendor.toLower().contains("ati");
|
||||
}
|
||||
|
||||
bool GpuIndicator::isIntel() const
|
||||
{
|
||||
return m_vendor.toLower().contains("intel");
|
||||
}
|
||||
|
||||
void GpuIndicator::updateFromJson(const QJsonObject &json)
|
||||
{
|
||||
parseDeviceInfo(json);
|
||||
}
|
||||
|
||||
void GpuIndicator::updateFromDeviceInfo(const QString &jsonStr)
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson(jsonStr.toUtf8());
|
||||
if (doc.isNull() || !doc.isObject()) {
|
||||
qWarning() << "Invalid JSON:" << jsonStr;
|
||||
return;
|
||||
}
|
||||
|
||||
parseDeviceInfo(doc.object());
|
||||
}
|
||||
|
||||
void GpuIndicator::parseDeviceInfo(const QJsonObject &obj)
|
||||
{
|
||||
bool changed = false;
|
||||
|
||||
if (obj.contains("vendor")) {
|
||||
QString vendor = obj["vendor"].toString();
|
||||
if (m_vendor != vendor) {
|
||||
m_vendor = vendor;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.contains("model")) {
|
||||
QString model = obj["model"].toString();
|
||||
if (m_model != model) {
|
||||
m_model = model;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.contains("driverVersion")) {
|
||||
QString version = obj["driverVersion"].toString();
|
||||
if (m_driverVersion != version) {
|
||||
m_driverVersion = version;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.contains("driverStatus")) {
|
||||
QString status = obj["driverStatus"].toString();
|
||||
if (m_driverStatus != status) {
|
||||
m_driverStatus = status;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
emit infoChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QString GpuIndicator::determineIcon() const
|
||||
{
|
||||
if (isNvidia()) {
|
||||
return "nvidia";
|
||||
} else if (isAmd()) {
|
||||
return "amd";
|
||||
} else if (isIntel()) {
|
||||
return "intel";
|
||||
}
|
||||
return "graphics-card";
|
||||
}
|
||||
Reference in New Issue
Block a user