From a6c5c09efe2a0e894110efd191b61ad0de255029 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8C=83=E6=9C=8B=E7=A8=8B?= Date: Fri, 26 Nov 2021 15:18:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8D=E9=A3=9E=E8=A1=8C?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 飞行模式开启时,应禁用蓝牙,飞行模式关闭后,取消禁用 Log: Influence: 飞行模块开启或关闭,需要禁用或启动蓝牙模块 Task: https://pms.uniontech.com/zentao/task-view-89206.html Change-Id: I1dbec5a1e02265d37f5d708276274c5e92811314 --- plugins/bluetooth/bluetoothitem.cpp | 2 +- plugins/bluetooth/componments/bluetoothapplet.cpp | 15 +++++++++++++++ plugins/bluetooth/componments/bluetoothapplet.h | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/plugins/bluetooth/bluetoothitem.cpp b/plugins/bluetooth/bluetoothitem.cpp index 428575b52..6eefe3559 100644 --- a/plugins/bluetooth/bluetoothitem.cpp +++ b/plugins/bluetooth/bluetoothitem.cpp @@ -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 settings; diff --git a/plugins/bluetooth/componments/bluetoothapplet.cpp b/plugins/bluetooth/componments/bluetoothapplet.cpp index acde1f7c2..cc4daf530 100644 --- a/plugins/bluetooth/componments/bluetoothapplet.cpp +++ b/plugins/bluetooth/componments/bluetoothapplet.cpp @@ -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; diff --git a/plugins/bluetooth/componments/bluetoothapplet.h b/plugins/bluetooth/componments/bluetoothapplet.h index a988ccb7c..2546fdd7f 100644 --- a/plugins/bluetooth/componments/bluetoothapplet.h +++ b/plugins/bluetooth/componments/bluetoothapplet.h @@ -29,6 +29,8 @@ #include +#include + 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 m_adapterItems; // 所有蓝牙适配器 + DBusAirplaneMode *m_airPlaneModeInter; + bool m_airplaneModeEnable; }; #endif // BLUETOOTHAPPLET_H