test: 创建最简测试插件
This commit is contained in:
+4
-10
@@ -9,33 +9,27 @@ project(dde-graphics-driver-applet VERSION 1.0.0 LANGUAGES CXX)
|
|||||||
set(CMAKE_CXX_STANDARD 17)
|
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)
|
||||||
set(CMAKE_AUTORCC ON)
|
|
||||||
|
|
||||||
find_package(Qt6 REQUIRED COMPONENTS Widgets DBus Quick)
|
find_package(Qt6 REQUIRED COMPONENTS Core)
|
||||||
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
|
||||||
graphicsdriverapplet.h
|
graphicsdriverapplet.h
|
||||||
graphicsdriverapplet.cpp
|
graphicsdriverapplet.cpp
|
||||||
gpuindicator.h
|
|
||||||
gpuindicator.cpp
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set_target_properties(org.deepin.ds.graphics-driver PROPERTIES PREFIX "")
|
||||||
|
|
||||||
target_include_directories(org.deepin.ds.graphics-driver PRIVATE
|
target_include_directories(org.deepin.ds.graphics-driver PRIVATE
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
/usr/include/dde-shell
|
/usr/include/dde-shell
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(org.deepin.ds.graphics-driver PROPERTIES PREFIX "")
|
|
||||||
|
|
||||||
target_link_libraries(org.deepin.ds.graphics-driver PRIVATE
|
target_link_libraries(org.deepin.ds.graphics-driver PRIVATE
|
||||||
Qt6::Widgets
|
Qt6::Core
|
||||||
Qt6::DBus
|
|
||||||
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)
|
|
||||||
|
|||||||
@@ -5,324 +5,23 @@
|
|||||||
#include "graphicsdriverapplet.h"
|
#include "graphicsdriverapplet.h"
|
||||||
#include <pluginfactory.h>
|
#include <pluginfactory.h>
|
||||||
|
|
||||||
#include <QDBusConnection>
|
|
||||||
#include <QDBusError>
|
|
||||||
#include <QDBusPendingReply>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <DConfig>
|
|
||||||
|
|
||||||
DCORE_USE_NAMESPACE
|
|
||||||
|
|
||||||
DS_BEGIN_NAMESPACE
|
DS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
static const QString DBUS_SERVICE = "com.deepin.daemon.GraphicsDriver";
|
|
||||||
static const QString DBUS_PATH = "/com/deepin/daemon/GraphicsDriver";
|
|
||||||
static const QString DBUS_INTERFACE = "com.deepin.daemon.GraphicsDriver";
|
|
||||||
|
|
||||||
GraphicsDriverApplet::GraphicsDriverApplet(QObject *parent)
|
GraphicsDriverApplet::GraphicsDriverApplet(QObject *parent)
|
||||||
: DApplet(parent)
|
: DApplet(parent)
|
||||||
, m_dbusInterface(nullptr)
|
|
||||||
, m_progressTimer(new QTimer(this))
|
|
||||||
, m_installProgress(0)
|
|
||||||
, m_isInstalling(false)
|
|
||||||
, m_isTestSuccess(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphicsDriverApplet::~GraphicsDriverApplet()
|
|
||||||
{
|
|
||||||
if (m_dbusInterface) {
|
|
||||||
delete m_dbusInterface;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GraphicsDriverApplet::load()
|
bool GraphicsDriverApplet::load()
|
||||||
{
|
{
|
||||||
initDBusConnection();
|
|
||||||
|
|
||||||
connect(m_progressTimer, &QTimer::timeout, this, &GraphicsDriverApplet::onPollProgress);
|
|
||||||
|
|
||||||
return DApplet::load();
|
return DApplet::load();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicsDriverApplet::init()
|
bool GraphicsDriverApplet::init()
|
||||||
{
|
{
|
||||||
refreshDeviceInfo();
|
|
||||||
|
|
||||||
return DApplet::init();
|
return DApplet::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GraphicsDriverApplet::currentDriver() const
|
|
||||||
{
|
|
||||||
return m_currentDriver;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GraphicsDriverApplet::newDriver() const
|
|
||||||
{
|
|
||||||
return m_newDriver;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString GraphicsDriverApplet::deviceInfo() const
|
|
||||||
{
|
|
||||||
return m_deviceInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GraphicsDriverApplet::installProgress() const
|
|
||||||
{
|
|
||||||
return m_installProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GraphicsDriverApplet::isInstalling() const
|
|
||||||
{
|
|
||||||
return m_isInstalling;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GraphicsDriverApplet::isTestSuccess() const
|
|
||||||
{
|
|
||||||
return m_isTestSuccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonArray GraphicsDriverApplet::availableDrivers() const
|
|
||||||
{
|
|
||||||
return m_availableDrivers;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::refreshDeviceInfo()
|
|
||||||
{
|
|
||||||
if (!m_dbusInterface || !m_dbusInterface->isValid()) {
|
|
||||||
qWarning() << "DBus interface is not valid";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDBusPendingCall call = m_dbusInterface->asyncCall("GetDevice");
|
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
|
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, this, &GraphicsDriverApplet::onDBusReply);
|
|
||||||
|
|
||||||
QDBusPendingCall currCall = m_dbusInterface->asyncCall("GetCurrDriverName");
|
|
||||||
QDBusPendingCallWatcher *currWatcher = new QDBusPendingCallWatcher(currCall, this);
|
|
||||||
connect(currWatcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher *call) {
|
|
||||||
QDBusPendingReply<QString> reply = *call;
|
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << "Failed to get current driver:" << reply.error().message();
|
|
||||||
} else {
|
|
||||||
m_currentDriver = reply.value();
|
|
||||||
emit currentDriverChanged();
|
|
||||||
}
|
|
||||||
call->deleteLater();
|
|
||||||
});
|
|
||||||
|
|
||||||
QDBusPendingCall newCall = m_dbusInterface->asyncCall("GetNewDriverName");
|
|
||||||
QDBusPendingCallWatcher *newWatcher = new QDBusPendingCallWatcher(newCall, this);
|
|
||||||
connect(newWatcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher *call) {
|
|
||||||
QDBusPendingReply<QString> reply = *call;
|
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << "Failed to get new driver:" << reply.error().message();
|
|
||||||
} else {
|
|
||||||
m_newDriver = reply.value();
|
|
||||||
emit newDriverChanged();
|
|
||||||
}
|
|
||||||
call->deleteLater();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::prepareInstall(const QString &driverName)
|
|
||||||
{
|
|
||||||
if (!m_dbusInterface || !m_dbusInterface->isValid()) {
|
|
||||||
qWarning() << "DBus interface is not valid";
|
|
||||||
emit installFailed("DBus interface is not valid");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_pendingInstallDriver = driverName;
|
|
||||||
|
|
||||||
QLocale locale;
|
|
||||||
QString language = locale.name();
|
|
||||||
|
|
||||||
QDBusPendingCall call = m_dbusInterface->asyncCall("PrepareInstall", driverName, language);
|
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
|
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher *call) {
|
|
||||||
QDBusPendingReply<> reply = *call;
|
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << "Failed to prepare install:" << reply.error().message();
|
|
||||||
emit installFailed(reply.error().message());
|
|
||||||
} else {
|
|
||||||
qDebug() << "Prepare install succeeded";
|
|
||||||
}
|
|
||||||
call->deleteLater();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::testInstall()
|
|
||||||
{
|
|
||||||
if (!m_dbusInterface || !m_dbusInterface->isValid()) {
|
|
||||||
qWarning() << "DBus interface is not valid";
|
|
||||||
emit installFailed("DBus interface is not valid");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setInstalling(true);
|
|
||||||
|
|
||||||
QDBusPendingCall call = m_dbusInterface->asyncCall("TestInstall");
|
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
|
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, this, &GraphicsDriverApplet::onDBusReply);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::realInstall()
|
|
||||||
{
|
|
||||||
if (!m_dbusInterface || !m_dbusInterface->isValid()) {
|
|
||||||
qWarning() << "DBus interface is not valid";
|
|
||||||
emit installFailed("DBus interface is not valid");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDBusPendingCall call = m_dbusInterface->asyncCall("RealInstall");
|
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
|
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher *call) {
|
|
||||||
QDBusPendingReply<> reply = *call;
|
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << "Failed to real install:" << reply.error().message();
|
|
||||||
emit installFailed(reply.error().message());
|
|
||||||
setInstalling(false);
|
|
||||||
} else {
|
|
||||||
qDebug() << "Real install succeeded";
|
|
||||||
emit installSuccess();
|
|
||||||
emit requestReboot();
|
|
||||||
}
|
|
||||||
call->deleteLater();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::cancelInstall()
|
|
||||||
{
|
|
||||||
if (!m_dbusInterface || !m_dbusInterface->isValid()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_dbusInterface->asyncCall("CancelInstall");
|
|
||||||
setInstalling(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::onDBusReply(QDBusPendingCallWatcher *call)
|
|
||||||
{
|
|
||||||
QDBusPendingReply<QString> reply = *call;
|
|
||||||
if (reply.isError()) {
|
|
||||||
qWarning() << "DBus call failed:" << reply.error().message();
|
|
||||||
} else {
|
|
||||||
QString result = reply.value();
|
|
||||||
qDebug() << "DBus call result:" << result;
|
|
||||||
parseDeviceInfo(result);
|
|
||||||
}
|
|
||||||
call->deleteLater();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::onReportProgress(const QString &ratio)
|
|
||||||
{
|
|
||||||
bool ok;
|
|
||||||
int progress = ratio.toInt(&ok);
|
|
||||||
if (ok) {
|
|
||||||
m_installProgress = progress;
|
|
||||||
emit installProgressChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::onCancel()
|
|
||||||
{
|
|
||||||
setInstalling(false);
|
|
||||||
m_installProgress = 0;
|
|
||||||
emit installProgressChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::onPollProgress()
|
|
||||||
{
|
|
||||||
if (!m_dbusInterface || !m_dbusInterface->isValid()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QDBusPendingCall call = m_dbusInterface->asyncCall("GetCurrDriverName");
|
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
|
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher *call) {
|
|
||||||
QDBusPendingReply<QString> reply = *call;
|
|
||||||
if (!reply.isError()) {
|
|
||||||
QString newDriver = reply.value();
|
|
||||||
if (newDriver != m_currentDriver) {
|
|
||||||
m_newDriver = newDriver;
|
|
||||||
emit newDriverChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
call->deleteLater();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::initDBusConnection()
|
|
||||||
{
|
|
||||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
|
||||||
|
|
||||||
if (!bus.isConnected()) {
|
|
||||||
qWarning() << "Cannot connect to D-Bus session bus";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_dbusInterface = new QDBusInterface(
|
|
||||||
DBUS_SERVICE,
|
|
||||||
DBUS_PATH,
|
|
||||||
DBUS_INTERFACE,
|
|
||||||
bus,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!m_dbusInterface->isValid()) {
|
|
||||||
qWarning() << "DBus interface is not valid:" << m_dbusInterface->lastError().message();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(m_dbusInterface, SIGNAL(ReportProgress(QString)),
|
|
||||||
this, SLOT(onReportProgress(QString)));
|
|
||||||
connect(m_dbusInterface, SIGNAL(Cancel()),
|
|
||||||
this, SLOT(onCancel()));
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::updateDeviceInfo()
|
|
||||||
{
|
|
||||||
refreshDeviceInfo();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::parseDeviceInfo(const QString &jsonStr)
|
|
||||||
{
|
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(jsonStr.toUtf8());
|
|
||||||
if (doc.isNull() || !doc.isObject()) {
|
|
||||||
qWarning() << "Invalid JSON:" << jsonStr;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject obj = doc.object();
|
|
||||||
m_deviceInfo = jsonStr;
|
|
||||||
emit deviceInfoChanged();
|
|
||||||
|
|
||||||
if (obj.contains("drivers")) {
|
|
||||||
m_availableDrivers = obj["drivers"].toArray();
|
|
||||||
emit availableDriversChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void GraphicsDriverApplet::setInstalling(bool installing)
|
|
||||||
{
|
|
||||||
if (m_isInstalling != installing) {
|
|
||||||
m_isInstalling = installing;
|
|
||||||
emit isInstallingChanged();
|
|
||||||
|
|
||||||
if (installing) {
|
|
||||||
m_progressTimer->start(1000);
|
|
||||||
} else {
|
|
||||||
m_progressTimer->stop();
|
|
||||||
m_installProgress = 0;
|
|
||||||
emit installProgressChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
D_APPLET_CLASS(GraphicsDriverApplet)
|
D_APPLET_CLASS(GraphicsDriverApplet)
|
||||||
|
|
||||||
DS_END_NAMESPACE
|
DS_END_NAMESPACE
|
||||||
|
|||||||
@@ -6,82 +6,17 @@
|
|||||||
|
|
||||||
#include <applet.h>
|
#include <applet.h>
|
||||||
|
|
||||||
#include <QDBusInterface>
|
|
||||||
#include <QDBusPendingCallWatcher>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
|
|
||||||
DS_BEGIN_NAMESPACE
|
DS_BEGIN_NAMESPACE
|
||||||
|
|
||||||
class GraphicsDriverApplet : public DApplet
|
class GraphicsDriverApplet : public DApplet
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QString currentDriver READ currentDriver NOTIFY currentDriverChanged)
|
|
||||||
Q_PROPERTY(QString newDriver READ newDriver NOTIFY newDriverChanged)
|
|
||||||
Q_PROPERTY(QString deviceInfo READ deviceInfo NOTIFY deviceInfoChanged)
|
|
||||||
Q_PROPERTY(int installProgress READ installProgress NOTIFY installProgressChanged)
|
|
||||||
Q_PROPERTY(bool isInstalling READ isInstalling NOTIFY isInstallingChanged)
|
|
||||||
Q_PROPERTY(bool isTestSuccess READ isTestSuccess NOTIFY isTestSuccessChanged)
|
|
||||||
Q_PROPERTY(QJsonArray availableDrivers READ availableDrivers NOTIFY availableDriversChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GraphicsDriverApplet(QObject *parent = nullptr);
|
explicit GraphicsDriverApplet(QObject *parent = nullptr);
|
||||||
~GraphicsDriverApplet();
|
|
||||||
|
|
||||||
virtual bool load() override;
|
virtual bool load() override;
|
||||||
virtual bool init() override;
|
virtual bool init() override;
|
||||||
|
|
||||||
QString currentDriver() const;
|
|
||||||
QString newDriver() const;
|
|
||||||
QString deviceInfo() const;
|
|
||||||
int installProgress() const;
|
|
||||||
bool isInstalling() const;
|
|
||||||
bool isTestSuccess() const;
|
|
||||||
QJsonArray availableDrivers() const;
|
|
||||||
|
|
||||||
Q_INVOKABLE void refreshDeviceInfo();
|
|
||||||
Q_INVOKABLE void prepareInstall(const QString &driverName);
|
|
||||||
Q_INVOKABLE void testInstall();
|
|
||||||
Q_INVOKABLE void realInstall();
|
|
||||||
Q_INVOKABLE void cancelInstall();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void currentDriverChanged();
|
|
||||||
void newDriverChanged();
|
|
||||||
void deviceInfoChanged();
|
|
||||||
void installProgressChanged();
|
|
||||||
void isInstallingChanged();
|
|
||||||
void isTestSuccessChanged();
|
|
||||||
void availableDriversChanged();
|
|
||||||
void installSuccess();
|
|
||||||
void installFailed(const QString &error);
|
|
||||||
void requestReboot();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void onDBusReply(QDBusPendingCallWatcher *call);
|
|
||||||
void onReportProgress(const QString &ratio);
|
|
||||||
void onCancel();
|
|
||||||
void onPollProgress();
|
|
||||||
|
|
||||||
private:
|
|
||||||
void initDBusConnection();
|
|
||||||
void updateDeviceInfo();
|
|
||||||
void parseDeviceInfo(const QString &jsonStr);
|
|
||||||
void setInstalling(bool installing);
|
|
||||||
|
|
||||||
QDBusInterface *m_dbusInterface;
|
|
||||||
QTimer *m_progressTimer;
|
|
||||||
|
|
||||||
QString m_currentDriver;
|
|
||||||
QString m_newDriver;
|
|
||||||
QString m_deviceInfo;
|
|
||||||
int m_installProgress;
|
|
||||||
bool m_isInstalling;
|
|
||||||
bool m_isTestSuccess;
|
|
||||||
QJsonArray m_availableDrivers;
|
|
||||||
QString m_pendingInstallDriver;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DS_END_NAMESPACE
|
DS_END_NAMESPACE
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
"Plugin": {
|
"Plugin": {
|
||||||
"Version": "1.0",
|
"Version": "1.0",
|
||||||
"Id": "org.deepin.ds.graphics-driver",
|
"Id": "org.deepin.ds.graphics-driver",
|
||||||
"Url": "driverview.qml",
|
|
||||||
"Category": "DDE"
|
"Category": "DDE"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user