feat: 适配飞行模式

飞行模式开启时,应禁用蓝牙,飞行模式关闭后,取消禁用

Log:
Influence: 飞行模块开启或关闭,需要禁用或启动蓝牙模块
Task: https://pms.uniontech.com/zentao/task-view-89206.html
Change-Id: I1dbec5a1e02265d37f5d708276274c5e92811314
This commit is contained in:
范朋程 2021-11-26 15:18:49 +08:00
parent 2af79235be
commit a6c5c09efe
3 changed files with 25 additions and 1 deletions

View File

@ -92,7 +92,7 @@ const QString BluetoothItem::contextMenu() const
shift["itemText"] = tr("Turn off");
else
shift["itemText"] = tr("Turn on");
shift["isActive"] = true;
shift["isActive"] = !m_applet->airplaneModeEnable();
items.push_back(shift);
QMap<QString, QVariant> settings;

View File

@ -100,6 +100,8 @@ BluetoothApplet::BluetoothApplet(QWidget *parent)
, m_mainLayout(new QVBoxLayout(this))
, m_contentLayout(new QVBoxLayout(m_contentWidget))
, m_seperator(new HorizontalSeperator(this))
, m_airPlaneModeInter(new DBusAirplaneMode("com.deepin.daemon.AirplaneMode", "/com/deepin/daemon/AirplaneMode", QDBusConnection::systemBus(), this))
, m_airplaneModeEnable(false)
{
initUi();
initConnect();
@ -235,6 +237,9 @@ void BluetoothApplet::initUi()
m_mainLayout->setContentsMargins(0, 0, 0, 0);
m_mainLayout->addWidget(m_scroarea);
updateSize();
setAirplaneModeEnabled(m_airPlaneModeInter->enabled());
setDisabled(m_airPlaneModeInter->enabled());
}
void BluetoothApplet::initConnect()
@ -252,6 +257,8 @@ void BluetoothApplet::initConnect()
.call();
});
connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, &BluetoothApplet::updateIconTheme);
connect(m_airPlaneModeInter, &DBusAirplaneMode::EnabledChanged, this, &BluetoothApplet::setAirplaneModeEnabled);
connect(m_airPlaneModeInter, &DBusAirplaneMode::EnabledChanged, this, &BluetoothApplet::setDisabled);
}
/**
@ -273,6 +280,14 @@ void BluetoothApplet::updateIconTheme()
m_scroarea->setPalette(scroareaBackgroud);
}
void BluetoothApplet::setAirplaneModeEnabled(bool enable)
{
if (m_airplaneModeEnable == enable)
return;
m_airplaneModeEnable = enable;
}
void BluetoothApplet::updateSize()
{
int height = 0;

View File

@ -29,6 +29,8 @@
#include <dtkwidget_global.h>
#include <com_deepin_daemon_airplanemode.h>
class QVBoxLayout;
class QHBoxLayout;
@ -46,6 +48,8 @@ DWIDGET_END_NAMESPACE
DWIDGET_USE_NAMESPACE
using DBusAirplaneMode = com::deepin::daemon::AirplaneMode;
class SettingLabel : public QWidget
{
Q_OBJECT
@ -82,6 +86,8 @@ public:
// 已连接蓝牙设备名称列表用于获取鼠标悬浮在蓝牙插件上时tips显示内容
QStringList connectedDevicesName();
inline bool airplaneModeEnable() const { return m_airplaneModeEnable;}
signals:
void noAdapter();
void justHasAdapter();
@ -97,6 +103,7 @@ public slots:
void onSetAdapterPower(Adapter *adapter, bool state);
// 更新蓝牙适配器电源状态,用于更新任务栏蓝牙插件图标的显示状态
void updateBluetoothPowerState();
void setAirplaneModeEnabled(bool enable);
private:
void initUi();
@ -116,6 +123,8 @@ private:
QStringList m_connectDeviceName;
QMap<QString, BluetoothAdapterItem *> m_adapterItems; // 所有蓝牙适配器
DBusAirplaneMode *m_airPlaneModeInter;
bool m_airplaneModeEnable;
};
#endif // BLUETOOTHAPPLET_H