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