fix: 修复插入新的蓝牙设备后其他蓝牙设备自动关闭的问题

原来新增的类中接收到蓝牙新增信号的时候,会对所有的蓝牙设备进行关闭操作,该类为冗余的类,删除即可

Log:
Influence: 系统中已经存在一个蓝牙设备,且是打开状态,打开快捷面板,进入蓝牙详情页面,插入新的蓝牙设备,观察之前的蓝牙设备是否自动关闭
Bug: https://pms.uniontech.com/bug-view-171477.html
Change-Id: I6355496ca1be494ccba59921e82cc1921f1ebfff
This commit is contained in:
donghualin 2022-11-24 03:25:59 +00:00
parent 9033044f0a
commit 7ed4de91b8
4 changed files with 0 additions and 203 deletions

View File

@ -21,7 +21,6 @@
*/
#include "bluetoothplugin.h"
#include "bluetoothwidget.h"
#include "adaptersmanager.h"
#include <DGuiApplicationHelper>
@ -34,7 +33,6 @@ BluetoothPlugin::BluetoothPlugin(QObject *parent)
: QObject(parent)
, m_adapterManager(new AdaptersManager(this))
, m_bluetoothItem(nullptr)
, m_bluetoothWidget(new BluetoothWidget(m_adapterManager))
{
}

View File

@ -28,7 +28,6 @@
#include <QScopedPointer>
class BluetoothWidget;
class AdaptersManager;
class BluetoothPlugin : public QObject, PluginsItemInterface
@ -66,7 +65,6 @@ private:
private:
AdaptersManager *m_adapterManager;
QScopedPointer<BluetoothItem> m_bluetoothItem;
QScopedPointer<BluetoothWidget> m_bluetoothWidget;
bool m_enableState = true;
};

View File

@ -1,137 +0,0 @@
/*
* Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
*
* Author: donghualin <donghualin@uniontech.com>
*
* Maintainer: donghualin <donghualin@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bluetoothwidget.h"
#include "adaptersmanager.h"
#include "bloothadapterwidget.h"
#include "adapter.h"
#include "device.h"
#include <DSwitchButton>
#include <DListView>
#include <QVBoxLayout>
#include <QLabel>
BluetoothWidget::BluetoothWidget(AdaptersManager *adapterManager, QWidget *parent)
: QWidget(parent)
, m_switchButton(new DSwitchButton(this))
, m_headerWidget(new QWidget(this))
, m_adapterWidget(new QWidget(this))
, m_adaptersManager(adapterManager)
, m_adapterLayout(new QVBoxLayout(m_adapterWidget))
{
initUi();
initConnection();
}
BluetoothWidget::~BluetoothWidget()
{
}
void BluetoothWidget::onAdapterIncreased(Adapter *adapter)
{
BloothAdapterWidget *adapterWidget = new BloothAdapterWidget(adapter, m_adapterWidget);
m_adapterLayout->addWidget(adapterWidget);
connect(adapterWidget, &BloothAdapterWidget::requestConnectDevice, this, [ this, adapter ](Device *device) {
m_adaptersManager->connectDevice(device, adapter);
});
connect(adapterWidget, &BloothAdapterWidget::requestUpdate, this, [ this ] {
adjustHeight();
});
updateCheckStatus();
QMetaObject::invokeMethod(this, &BluetoothWidget::adjustHeight, Qt::QueuedConnection);
}
void BluetoothWidget::onAdapterDecreased(Adapter *adapter)
{
for (int i = 0; i < m_adapterLayout->count(); i++) {
BloothAdapterWidget *adapterWidget = static_cast<BloothAdapterWidget *>(m_adapterLayout->itemAt(i)->widget());
if (adapterWidget && adapterWidget->adapter() == adapter) {
m_adapterLayout->removeWidget(adapterWidget);
updateCheckStatus();
QMetaObject::invokeMethod(this, &BluetoothWidget::adjustHeight, Qt::QueuedConnection);
break;
}
}
}
void BluetoothWidget::onCheckedChanged(bool checked)
{
QList<const Adapter *> adapters = m_adaptersManager->adapters();
for (const Adapter *adapter : adapters)
m_adaptersManager->setAdapterPowered(adapter, checked);
}
void BluetoothWidget::initUi()
{
QHBoxLayout *headerLayout = new QHBoxLayout(m_headerWidget);
headerLayout->addStretch();
headerLayout->addWidget(m_switchButton);
headerLayout->addStretch();
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
mainLayout->addWidget(m_headerWidget);
mainLayout->addSpacing(3);
mainLayout->addWidget(m_adapterWidget);
m_adapterLayout->setContentsMargins(0, 0, 0, 0);
m_adapterLayout->setSpacing(0);
QList<const Adapter *> adapters = m_adaptersManager->adapters();
for (const Adapter *adapter : adapters) {
onAdapterIncreased(const_cast<Adapter *>(adapter));
}
}
void BluetoothWidget::initConnection()
{
connect(m_adaptersManager, &AdaptersManager::adapterIncreased, this, &BluetoothWidget::onAdapterIncreased);
connect(m_adaptersManager, &AdaptersManager::adapterDecreased, this, &BluetoothWidget::onAdapterDecreased);
connect(m_switchButton, &DSwitchButton::checkedChanged, this, &BluetoothWidget::onCheckedChanged);
}
void BluetoothWidget::updateCheckStatus()
{
bool checked = false;
QList<const Adapter *> adapters = m_adaptersManager->adapters();
for (const Adapter *adapter : adapters)
checked = adapter->powered();
m_switchButton->setChecked(checked);
}
void BluetoothWidget::adjustHeight()
{
int height = m_switchButton->height() + m_headerWidget->height();
for (int i = 0; i < m_adapterLayout->count(); i++) {
BloothAdapterWidget *adapterWidget = static_cast<BloothAdapterWidget *>(m_adapterLayout->itemAt(i)->widget());
if (!adapterWidget)
continue;
height += adapterWidget->height();
}
setFixedHeight(height);
}

View File

@ -1,62 +0,0 @@
/*
* Copyright (C) 2022 ~ 2022 Deepin Technology Co., Ltd.
*
* Author: donghualin <donghualin@uniontech.com>
*
* Maintainer: donghualin <donghualin@uniontech.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BLUETOOTHWIDGET_H
#define BLUETOOTHWIDGET_H
#include <QWidget>
class QLabel;
class AdaptersManager;
class Adapter;
class QVBoxLayout;
namespace Dtk { namespace Widget { class DListView; class DSwitchButton; } }
using namespace Dtk::Widget;
class BluetoothWidget : public QWidget
{
Q_OBJECT
public:
explicit BluetoothWidget(AdaptersManager *adapterManager, QWidget *parent = nullptr);
~BluetoothWidget() override;
protected Q_SLOTS:
void onAdapterIncreased(Adapter *adapter);
void onAdapterDecreased(Adapter *adapter);
void onCheckedChanged(bool checked);
private:
void initUi();
void initConnection();
void updateCheckStatus();
void adjustHeight();
private:
DSwitchButton *m_switchButton;
QWidget *m_headerWidget;
QWidget *m_adapterWidget;
AdaptersManager *m_adaptersManager;
QVBoxLayout *m_adapterLayout;
};
#endif // BLUETOOTHWIDGET_H