fix: 任务栏初始化未显示飞行模式

使用systemdbus来获取蓝牙和无线网络状态

Log: systemdbus在dde-dock运行前已完成初始化
Influence: 飞行模式
Task: https://pms.uniontech.com/bug-view-147871.html
Change-Id: I9d9eabf38e66826ec691b7175e64a548c378352b
This commit is contained in:
zengaoyuan 2022-07-15 14:49:45 +08:00 committed by wubw
parent bd5ae48187
commit f543b732d1
2 changed files with 46 additions and 27 deletions

View File

@ -47,36 +47,14 @@ void AirplaneModePlugin::init(PluginProxyInterface *proxyInter)
{
m_proxyInter = proxyInter;
bool hasBluetooth = false;
QDBusInterface inter("com.deepin.daemon.Bluetooth",
"/com/deepin/daemon/Bluetooth",
"com.deepin.daemon.Bluetooth",
QDBusConnection::sessionBus());
if (inter.isValid()) {
QDBusReply<QString> reply = inter.call("GetAdapters");
QString replyStr = reply.value();
QJsonDocument json = QJsonDocument::fromJson(replyStr.toUtf8());
QJsonArray array = json.array();
if (array.size() > 0 && !array[0].toObject()["Path"].toString().isEmpty()) {
hasBluetooth = true;
}
}
bool hasWireless = false;
NetworkInter networkInter("com.deepin.daemon.Network", "/com/deepin/daemon/Network", QDBusConnection::sessionBus(), this);
if (networkInter.isValid()) {
if (!networkInter.wirelessAccessPoints().isEmpty()) {
hasWireless = true;
}
}
if (!pluginIsDisable()) {
if (hasBluetooth || hasWireless) {
if (supportAirplaneMode()) {
m_proxyInter->itemAdded(this, AIRPLANEMODE_KEY);
}
}
// 蓝牙和无线网络,只要有其中一个就允许显示飞行模式
if (hasBluetooth || hasWireless) {
if (supportAirplaneMode()) {
refreshAirplaneEnableState();
}
}
@ -176,4 +154,45 @@ void AirplaneModePlugin::onAirplaneEnableChanged(bool enable)
}
}
bool AirplaneModePlugin::supportAirplaneMode() const
{
// 蓝牙和无线网络,只要有其中一个就允许显示飞行模式
QDBusInterface inter("com.deepin.system.Bluetooth",
"/com/deepin/system/Bluetooth",
"com.deepin.system.Bluetooth",
QDBusConnection::systemBus());
if (inter.isValid()) {
QDBusReply<QString> reply = inter.call("GetAdapters");
QString replyStr = reply.value();
QJsonDocument json = QJsonDocument::fromJson(replyStr.toUtf8());
QJsonArray array = json.array();
if (array.size() > 0 && !array[0].toObject()["Path"].toString().isEmpty()) {
return true;
}
}
QDBusInterface networkInter("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager",
"org.freedesktop.NetworkManager",
QDBusConnection::systemBus());
if (networkInter.isValid()) {
QDBusReply<QList<QDBusObjectPath>> reply = networkInter.call("GetAllDevices");
QList<QDBusObjectPath> replyStrList = reply.value();
for (QDBusObjectPath objPath : replyStrList) {
QDBusInterface deviceInter("org.freedesktop.NetworkManager",
objPath.path(),
"org.freedesktop.NetworkManager.Device",
QDBusConnection::systemBus());
if (deviceInter.isValid()) {
QVariant reply = deviceInter.property("DeviceType");
if (2 == reply.toUInt()) {
return true;
}
}
}
}
return false;
}

View File

@ -24,9 +24,6 @@
#define AIRPLANEMODEPLUGIN_H
#include "pluginsiteminterface.h"
#include "com_deepin_daemon_network.h"
using NetworkInter = com::deepin::daemon::Network;
class AirplaneModeItem;
class AirplaneModePlugin : public QObject, PluginsItemInterface
@ -53,6 +50,9 @@ public:
void setSortKey(const QString &itemKey, const int order) Q_DECL_OVERRIDE;
void refreshIcon(const QString &itemKey) Q_DECL_OVERRIDE;
private:
bool supportAirplaneMode() const;
public slots:
void refreshAirplaneEnableState();
void onAirplaneEnableChanged(bool enable);