fix: dconfig配置默认不显示飞行模式

默认不显示飞行模式

Log: 不显示飞行模式
Influence: 飞行模式
Task: https://pms.uniontech.com/task-view-169635.html
Change-Id: I8627af8ba17aedb123a2cab58f8383c904a0fb28
This commit is contained in:
zengaoyuan 2022-07-26 09:51:17 +08:00 committed by wubw
parent 11abb21320
commit d847891f85
2 changed files with 48 additions and 14 deletions

View File

@ -22,15 +22,19 @@
#include "airplanemodeplugin.h"
#include "airplanemodeitem.h"
#include <DConfig>
#define AIRPLANEMODE_KEY "airplane-mode-key"
#define STATE_KEY "enable"
DCORE_USE_NAMESPACE
AirplaneModePlugin::AirplaneModePlugin(QObject *parent)
: QObject(parent)
, m_item(new AirplaneModeItem)
, m_dconfig(DConfig::create("org.deepin.dde.network", "org.deepin.dde.network", QString(), this))
{
connect(m_item, &AirplaneModeItem::airplaneEnableChanged, this, &AirplaneModePlugin::onAirplaneEnableChanged);
connect(m_dconfig, &DConfig::valueChanged, this, &AirplaneModePlugin::onWirelessAccessPointsOrAdapterChange);
}
const QString AirplaneModePlugin::pluginName() const
@ -47,12 +51,14 @@ void AirplaneModePlugin::init(PluginProxyInterface *proxyInter)
{
m_proxyInter = proxyInter;
m_networkInter = new NetworkInter("com.deepin.daemon.Network", "/com/deepin/daemon/Network", QDBusConnection::sessionBus(), this);
connect(m_networkInter, &NetworkInter::WirelessAccessPointsChanged, this, &AirplaneModePlugin::onWirelessAccessPointsOrAdapterChange);
if (supportAirplaneMode()) {
m_networkInter = new NetworkInter("com.deepin.daemon.Network", "/com/deepin/daemon/Network", QDBusConnection::sessionBus(), this);
connect(m_networkInter, &NetworkInter::WirelessAccessPointsChanged, this, &AirplaneModePlugin::onWirelessAccessPointsOrAdapterChange);
m_bluetoothInter = new BluetoothInter("com.deepin.daemon.Bluetooth", "/com/deepin/daemon/Bluetooth", QDBusConnection::sessionBus(), this);
connect(m_bluetoothInter, &BluetoothInter::AdapterAdded, this, &AirplaneModePlugin::onWirelessAccessPointsOrAdapterChange);
connect(m_bluetoothInter, &BluetoothInter::AdapterRemoved, this, &AirplaneModePlugin::onWirelessAccessPointsOrAdapterChange);
m_bluetoothInter = new BluetoothInter("com.deepin.daemon.Bluetooth", "/com/deepin/daemon/Bluetooth", QDBusConnection::sessionBus(), this);
connect(m_bluetoothInter, &BluetoothInter::AdapterAdded, this, &AirplaneModePlugin::onWirelessAccessPointsOrAdapterChange);
connect(m_bluetoothInter, &BluetoothInter::AdapterRemoved, this, &AirplaneModePlugin::onWirelessAccessPointsOrAdapterChange);
}
if (!pluginIsDisable()) {
if (supportAirplaneMode()) {
@ -60,9 +66,7 @@ void AirplaneModePlugin::init(PluginProxyInterface *proxyInter)
}
}
if (supportAirplaneMode()) {
refreshAirplaneEnableState();
}
refreshAirplaneEnableState();
}
void AirplaneModePlugin::pluginStateSwitched()
@ -97,6 +101,10 @@ QWidget *AirplaneModePlugin::itemTipsWidget(const QString &itemKey)
QWidget *AirplaneModePlugin::itemPopupApplet(const QString &itemKey)
{
if (!supportAirplaneMode()) {
return nullptr;
}
if (itemKey == AIRPLANEMODE_KEY) {
return m_item->popupApplet();
}
@ -106,6 +114,10 @@ QWidget *AirplaneModePlugin::itemPopupApplet(const QString &itemKey)
const QString AirplaneModePlugin::itemContextMenu(const QString &itemKey)
{
if (!supportAirplaneMode()) {
return QString();
}
if (itemKey == AIRPLANEMODE_KEY) {
return m_item->contextMenu();
}
@ -151,12 +163,20 @@ void AirplaneModePlugin::onAirplaneEnableChanged(bool enable)
if (!m_proxyInter)
return;
m_proxyInter->itemAdded(this, AIRPLANEMODE_KEY);
if (enable) {
m_proxyInter->saveValue(this, STATE_KEY, true);
}
else {
m_proxyInter->saveValue(this, STATE_KEY, false);
if (supportAirplaneMode()) {
m_proxyInter->itemAdded(this, AIRPLANEMODE_KEY);
if (enable) {
m_proxyInter->saveValue(this, STATE_KEY, true);
}
else {
m_proxyInter->saveValue(this, STATE_KEY, false);
}
} else {
if (enable) {
m_proxyInter->itemAdded(this, AIRPLANEMODE_KEY);
} else {
m_proxyInter->itemRemoved(this, AIRPLANEMODE_KEY);
}
}
}
@ -171,6 +191,15 @@ void AirplaneModePlugin::onWirelessAccessPointsOrAdapterChange()
bool AirplaneModePlugin::supportAirplaneMode() const
{
// dde-dconfig配置优先级高于设备优先级
bool bAirplane = false;
if (m_dconfig && m_dconfig->isValid()) {
bAirplane = m_dconfig->value("networkAirplaneMode", false).toBool();
}
if (!bAirplane) {
return bAirplane;
}
// 蓝牙和无线网络,只要有其中一个就允许显示飞行模式
QDBusInterface inter("com.deepin.system.Bluetooth",
"/com/deepin/system/Bluetooth",

View File

@ -26,9 +26,13 @@
#include "pluginsiteminterface.h"
#include "com_deepin_daemon_network.h"
#include "com_deepin_daemon_bluetooth.h"
#include "dtkcore_global.h"
using NetworkInter = com::deepin::daemon::Network;
using BluetoothInter = com::deepin::daemon::Bluetooth;
DCORE_BEGIN_NAMESPACE
class DConfig;
DCORE_END_NAMESPACE
class AirplaneModeItem;
class AirplaneModePlugin : public QObject, PluginsItemInterface
@ -67,6 +71,7 @@ private:
AirplaneModeItem *m_item;
NetworkInter *m_networkInter;
BluetoothInter *m_bluetoothInter;
DTK_CORE_NAMESPACE::DConfig *m_dconfig;
};
#endif // AIRPLANEMODEPLUGIN_H