mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
feat: 修复任务栏与控制中心是否显示没有名称的蓝牙设备不同步
解析蓝牙Dbus中的数据,通过判断json数据中的name字段值是否为空判断是否未命名, 根据控制中心的设置,同步更新是否在蓝牙视图中显示没有名称的蓝牙设备 Log: 修复任务栏不显示没有名称的蓝牙设备问题 Task: https://pms.uniontech.com/zentao/task-view-62958.html Change-Id: Idd3c84721258a40161b0e1ce565518887f1add37
This commit is contained in:
parent
1201947955
commit
4e2dcf118b
@ -49,7 +49,8 @@ void Adapter::setName(const QString &name)
|
||||
void Adapter::addDevice(const QJsonObject &deviceObj)
|
||||
{
|
||||
const QString id = deviceObj["Path"].toString();
|
||||
const QString name = deviceObj["Alias"].toString();
|
||||
const QString name = deviceObj["Name"].toString();
|
||||
const QString alias = deviceObj["Alias"].toString();
|
||||
const bool paired = deviceObj["Paired"].toBool();
|
||||
const int rssi = deviceObj["RSSI"].toInt();
|
||||
const Device::State state = Device::State(deviceObj["State"].toInt());
|
||||
@ -62,6 +63,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
|
||||
|
||||
device->setId(id);
|
||||
device->setName(name);
|
||||
device->setAlias(alias);
|
||||
device->setPaired(paired);
|
||||
device->setState(state);
|
||||
device->setConnectState(connectState);
|
||||
@ -90,7 +92,8 @@ void Adapter::removeDevice(const QString &deviceId)
|
||||
void Adapter::updateDevice(const QJsonObject &dviceJson)
|
||||
{
|
||||
const QString id = dviceJson["Path"].toString();
|
||||
const QString name = dviceJson["Alias"].toString();
|
||||
const QString name = dviceJson["Name"].toString();
|
||||
const QString alias = dviceJson["Alias"].toString();
|
||||
const bool paired = dviceJson["Paired"].toBool();
|
||||
const int rssi = dviceJson["RSSI"].toInt();
|
||||
const Device::State state = Device::State(dviceJson["State"].toInt());
|
||||
@ -102,6 +105,7 @@ void Adapter::updateDevice(const QJsonObject &dviceJson)
|
||||
if (device) {
|
||||
device->setId(id);
|
||||
device->setName(name);
|
||||
device->setAlias(alias);
|
||||
device->setPaired(paired);
|
||||
device->setRssi(rssi);
|
||||
//setState放后面,是因为用到了connectState,fix bug 55245
|
||||
@ -157,7 +161,8 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
|
||||
QJsonObject deviceObj = val.toObject();
|
||||
const QString adapterId = deviceObj["AdapterPath"].toString();
|
||||
const QString id = deviceObj["Path"].toString();
|
||||
const QString name = deviceObj["Alias"].toString();
|
||||
const QString name = deviceObj["Name"].toString();
|
||||
const QString alias = deviceObj["Alias"].toString();
|
||||
const bool paired = deviceObj["Paired"].toBool();
|
||||
const int rssi = deviceObj["RSSI"].toInt();
|
||||
const Device::State state = Device::State(deviceObj["State"].toInt());
|
||||
@ -167,6 +172,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
|
||||
auto device = new Device(this);
|
||||
device->setId(id);
|
||||
device->setName(name);
|
||||
device->setAlias(alias);
|
||||
device->setPaired(paired);
|
||||
device->setState(state);
|
||||
device->setConnectState(connectState);
|
||||
|
@ -119,14 +119,14 @@ void AdaptersManager::connectDevice(const Device *device, Adapter *adapter)
|
||||
switch (device->state()) {
|
||||
case Device::StateUnavailable: {
|
||||
m_bluetoothInter->ConnectDevice(path, QDBusObjectPath(adapter->id()));
|
||||
qDebug() << "connect to device: " << device->name();
|
||||
qDebug() << "connect to device: " << device->alias();
|
||||
}
|
||||
break;
|
||||
case Device::StateAvailable:
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
m_bluetoothInter->DisconnectDevice(path);
|
||||
qDebug() << "disconnect device: " << device->name();
|
||||
qDebug() << "disconnect device: " << device->alias();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -62,11 +62,11 @@ void BluetoothDeviceItem::initActionList()
|
||||
m_loading->setFixedSize(QSize(24, 24));
|
||||
m_stateAction->setWidget(m_loading);
|
||||
|
||||
m_standarditem->setAccessibleText(m_device->name());
|
||||
m_standarditem->setAccessibleText(m_device->alias());
|
||||
m_standarditem->setActionList(Qt::RightEdge, {m_stateAction});
|
||||
m_standarditem->setActionList(Qt::LeftEdge, {m_labelAction});
|
||||
|
||||
m_labelAction->setText(m_device->name());
|
||||
m_labelAction->setText(m_device->alias());
|
||||
updateDeviceState(m_device->state());
|
||||
updateIconTheme(DGuiApplicationHelper::instance()->themeType());
|
||||
}
|
||||
@ -97,7 +97,7 @@ void BluetoothDeviceItem::updateIconTheme(DGuiApplicationHelper::ColorType type)
|
||||
|
||||
void BluetoothDeviceItem::updateDeviceState(Device::State state)
|
||||
{
|
||||
m_labelAction->setText(m_device->name());
|
||||
m_labelAction->setText(m_device->alias());
|
||||
if (state == Device::StateAvailable) {
|
||||
m_loading->start();
|
||||
m_stateAction->setVisible(true);
|
||||
@ -123,6 +123,11 @@ BluetoothAdapterItem::BluetoothAdapterItem(Adapter *adapter, QWidget *parent)
|
||||
, m_deviceListview(new DListView(this))
|
||||
, m_deviceModel(new QStandardItemModel(m_deviceListview))
|
||||
, m_refreshBtn(new RefreshButton(this))
|
||||
, m_bluetoothInter(new DBusBluetooth("com.deepin.daemon.Bluetooth",
|
||||
"/com/deepin/daemon/Bluetooth",
|
||||
QDBusConnection::sessionBus(),
|
||||
this))
|
||||
, m_showUnnamedDevices(false)
|
||||
{
|
||||
initData();
|
||||
initUi();
|
||||
@ -183,7 +188,7 @@ QStringList BluetoothAdapterItem::connectedDevicesName()
|
||||
QStringList devsName;
|
||||
for (BluetoothDeviceItem *devItem : m_deviceItems) {
|
||||
if (devItem && devItem->device()->state() == Device::StateConnected) {
|
||||
devsName << devItem->device()->name();
|
||||
devsName << devItem->device()->alias();
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,6 +197,7 @@ QStringList BluetoothAdapterItem::connectedDevicesName()
|
||||
|
||||
void BluetoothAdapterItem::initData()
|
||||
{
|
||||
m_showUnnamedDevices = m_bluetoothInter->displaySwitch();
|
||||
if (!m_adapter->powered())
|
||||
return;
|
||||
|
||||
@ -199,6 +205,7 @@ void BluetoothAdapterItem::initData()
|
||||
if (!m_deviceItems.contains(device->id()))
|
||||
onDeviceAdded(device);
|
||||
}
|
||||
setUnnamedDevicesVisible(m_showUnnamedDevices);
|
||||
emit deviceCountChanged();
|
||||
}
|
||||
|
||||
@ -216,6 +223,9 @@ void BluetoothAdapterItem::onDeviceAdded(const Device *device)
|
||||
connect(item, &BluetoothDeviceItem::deviceStateChanged, this, &BluetoothAdapterItem::deviceStateChanged);
|
||||
|
||||
m_deviceItems.insert(device->id(), item);
|
||||
if (!m_showUnnamedDevices && device->name().isEmpty() && Device::StateConnected != device->state())
|
||||
return;
|
||||
|
||||
m_deviceModel->insertRow(insertRow, item->standardItem());
|
||||
emit deviceCountChanged();
|
||||
}
|
||||
@ -308,4 +318,55 @@ void BluetoothAdapterItem::initConnect()
|
||||
m_refreshBtn->setVisible(state);
|
||||
emit requestSetAdapterPower(m_adapter, state);
|
||||
});
|
||||
connect(m_bluetoothInter, &DBusBluetooth::DisplaySwitchChanged, this, [ = ](bool value) {
|
||||
m_showUnnamedDevices = value;
|
||||
setUnnamedDevicesVisible(value);
|
||||
});
|
||||
}
|
||||
|
||||
void BluetoothAdapterItem::setUnnamedDevicesVisible(bool isShow)
|
||||
{
|
||||
QMap<QString, BluetoothDeviceItem *>::iterator i;
|
||||
|
||||
if (isShow) {
|
||||
// 计算已连接蓝牙设备数
|
||||
int connectCount = 0;
|
||||
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); i++) {
|
||||
BluetoothDeviceItem *deviceItem = i.value();
|
||||
|
||||
if (deviceItem && deviceItem->device() && deviceItem->device()->paired()
|
||||
&& (Device::StateConnected == deviceItem->device()->state() || deviceItem->device()->connecting()))
|
||||
connectCount++;
|
||||
}
|
||||
|
||||
// 显示所有蓝牙设备
|
||||
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); i++) {
|
||||
BluetoothDeviceItem *deviceItem = i.value();
|
||||
|
||||
if (deviceItem && deviceItem->device() && deviceItem->device()->name().isEmpty()) {
|
||||
DStandardItem *dListItem = deviceItem->standardItem();
|
||||
QModelIndex index = m_deviceModel->indexFromItem(dListItem);
|
||||
if (!index.isValid()) {
|
||||
m_deviceModel->insertRow(((connectCount > -1 && connectCount < m_deviceItems.count()) ? connectCount : 0), dListItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (i = m_deviceItems.begin(); i != m_deviceItems.end(); i++) {
|
||||
BluetoothDeviceItem *deviceItem = i.value();
|
||||
|
||||
// 将名称为空的蓝牙设备过滤,如果蓝牙正在连接或者已连接不过滤
|
||||
if (deviceItem && deviceItem->device() && deviceItem->device()->name().isEmpty()
|
||||
&& (Device::StateConnected != deviceItem->device()->state() || !deviceItem->device()->connecting())) {
|
||||
DStandardItem *dListItem = deviceItem->standardItem();
|
||||
QModelIndex index = m_deviceModel->indexFromItem(dListItem);
|
||||
if (index.isValid()) {
|
||||
m_deviceModel->takeRow(index.row());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,10 @@
|
||||
#include <DStyleHelper>
|
||||
#include <DApplicationHelper>
|
||||
|
||||
#include <com_deepin_daemon_bluetooth.h>
|
||||
|
||||
using DBusBluetooth = com::deepin::daemon::Bluetooth;
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
DWIDGET_BEGIN_NAMESPACE
|
||||
@ -116,6 +120,7 @@ private:
|
||||
void initData();
|
||||
void initUi();
|
||||
void initConnect();
|
||||
void setUnnamedDevicesVisible(bool isShow);
|
||||
|
||||
Adapter *m_adapter = nullptr;
|
||||
SettingLabel *m_adapterLabel = nullptr;
|
||||
@ -123,6 +128,8 @@ private:
|
||||
DListView *m_deviceListview = nullptr;
|
||||
QStandardItemModel *m_deviceModel = nullptr;
|
||||
RefreshButton *m_refreshBtn = nullptr;
|
||||
DBusBluetooth *m_bluetoothInter;
|
||||
bool m_showUnnamedDevices;
|
||||
|
||||
QMap<QString, BluetoothDeviceItem *> m_deviceItems;
|
||||
};
|
||||
|
@ -77,6 +77,14 @@ void Device::setName(const QString &name)
|
||||
}
|
||||
}
|
||||
|
||||
void Device::setAlias(const QString &alias)
|
||||
{
|
||||
if (alias != m_alias) {
|
||||
m_alias = alias;
|
||||
Q_EMIT aliasChanged(alias);
|
||||
}
|
||||
}
|
||||
|
||||
void Device::setPaired(bool paired)
|
||||
{
|
||||
if (paired != m_paired) {
|
||||
|
@ -51,6 +51,9 @@ public:
|
||||
inline QString name() const { return m_name; }
|
||||
void setName(const QString &name);
|
||||
|
||||
inline QString alias() const { return m_alias; }
|
||||
void setAlias(const QString &alias);
|
||||
|
||||
inline bool paired() const { return m_paired; }
|
||||
void setPaired(bool paired);
|
||||
|
||||
@ -80,6 +83,7 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
void nameChanged(const QString &name) const;
|
||||
void aliasChanged(const QString &alias) const;
|
||||
void pairedChanged(const bool paired) const;
|
||||
void stateChanged(const State state) const;
|
||||
void connectStateChanged(const bool connectState) const;
|
||||
@ -90,6 +94,7 @@ Q_SIGNALS:
|
||||
private:
|
||||
QString m_id;
|
||||
QString m_name;
|
||||
QString m_alias;
|
||||
bool m_paired;
|
||||
bool m_trusted;
|
||||
bool m_connecting;
|
||||
|
Loading…
x
Reference in New Issue
Block a user