fix(bluetooth): 修复蓝牙设备名称更新后未实时刷新的问题

修复任务栏的蓝牙设备列表偶尔出现空白设备名称的问题
修复蓝牙设备名称更新后控制中心实时刷新而任务栏未实时刷新的问题

Bug: https://pms.uniontech.com/zentao/bug-view-59120.html
Log: 蓝牙列表中部分设备名称显示空白和蓝牙设备名称更新后没有实时刷新
Change-Id: Iaa27f5a8422a9c804635a99de77a814611344088
This commit is contained in:
myj 2021-03-04 09:58:05 +08:00 committed by mayijian
parent 339016cd51
commit 6a28c55153
11 changed files with 74 additions and 51 deletions

View File

@ -116,8 +116,7 @@ void BluetoothItem::invokeMenuItem(const QString menuId, const bool checked)
if (menuId == SHIFT) {
m_applet->setAdapterPowered(!m_adapterPowered);
}
else if (menuId == SETTINGS)
} else if (menuId == SETTINGS) {
DDBusSender()
.service("com.deepin.dde.ControlCenter")
.interface("com.deepin.dde.ControlCenter")
@ -126,6 +125,7 @@ void BluetoothItem::invokeMenuItem(const QString menuId, const bool checked)
.arg(QString("bluetooth"))
.call();
}
}
void BluetoothItem::refreshIcon()
{

View File

@ -100,6 +100,10 @@ void Adapter::updateDevice(const QJsonObject &dviceJson)
const bool connectState = dviceJson["ConnectState"].toBool();
const QString bluetoothDeviceType = dviceJson["Icon"].toString();
// FIXME: Solve the problem that the device name in the Bluetooth list is blank
if (name.isEmpty() && alias.isEmpty())
return ;
const Device *constdevice = m_devices.value(id);
auto device = const_cast<Device *>(constdevice);
if (device) {
@ -112,6 +116,7 @@ void Adapter::updateDevice(const QJsonObject &dviceJson)
device->setConnectState(connectState);
device->setState(state);
device->setDeviceType(bluetoothDeviceType);
emit deviceNameUpdated(device);
}
}

View File

@ -63,6 +63,7 @@ Q_SIGNALS:
void nameChanged(const QString &name) const;
void deviceAdded(const Device *device) const;
void deviceRemoved(const Device *device) const;
void deviceNameUpdated(const Device *device) const;
void poweredChanged(const bool powered) const;
void discoveringChanged(const bool discover) const;

View File

@ -241,6 +241,20 @@ void BluetoothAdapterItem::onDeviceRemoved(const Device *device)
emit deviceCountChanged();
}
void BluetoothAdapterItem::onDeviceNameUpdated(const Device *device)
{
if (m_deviceItems.isEmpty())
return;
// 修复蓝牙设备列表中,设备名称更新后未实时刷新的问题
if (m_deviceItems.contains(device->id())) {
BluetoothDeviceItem *item = m_deviceItems[device->id()];
if (item && !item->device()->alias().isEmpty()) {
item->updateDeviceState(item->device()->state());
}
}
}
void BluetoothAdapterItem::initUi()
{
m_refreshBtn->setFixedSize(24, 24);
@ -287,6 +301,7 @@ void BluetoothAdapterItem::initConnect()
connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, &BluetoothAdapterItem::updateIconTheme);
connect(m_adapter, &Adapter::deviceAdded, this, &BluetoothAdapterItem::onDeviceAdded);
connect(m_adapter, &Adapter::deviceRemoved, this, &BluetoothAdapterItem::onDeviceRemoved);
connect(m_adapter, &Adapter::deviceNameUpdated, this, &BluetoothAdapterItem::onDeviceNameUpdated);
connect(m_adapter, &Adapter::nameChanged, this, &BluetoothAdapterItem::onAdapterNameChanged);
connect(m_deviceListview, &DListView::clicked, this, &BluetoothAdapterItem::onConnectDevice);
connect(m_adapter, &Adapter::discoveringChanged, this, [ = ](bool state) {

View File

@ -100,6 +100,8 @@ public slots:
void onDeviceAdded(const Device *device);
// 移除蓝牙设备
void onDeviceRemoved(const Device *device);
// 蓝牙设备名称更新
void onDeviceNameUpdated(const Device *device);
// 连接蓝牙设备
void onConnectDevice(const QModelIndex &index);
// 将已连接的蓝牙设备放到列表第一个