mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix(blutooth): 创建新用户后任务栏蓝牙状态与控制中心不一致
原因后端connectState值有错为false,控制中心根据这个字段+state设置蓝牙状态,任务栏只根据state设置状态,导致两边不一致 Log: 修复创建新用户后任务栏蓝牙状态与控制中心不一致问题 Bug: https://pms.uniontech.com/zentao/bug-view-43271.html Change-Id: I0b57ff951f40cb3fe056656de071fa0d0c073aa4 Reviewed-on: http://gerrit.uniontech.com/c/dde-dock/+/2541 Reviewed-by: <mailman@uniontech.com> Reviewed-by: fanpengcheng <fanpengcheng@uniontech.com> Tested-by: <mailman@uniontech.com>
This commit is contained in:
parent
6b04b788e0
commit
73dff8bd03
@ -53,6 +53,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
|
||||
const bool paired = deviceObj["Paired"].toBool();
|
||||
const int rssi = deviceObj["RSSI"].toInt();
|
||||
const Device::State state = Device::State(deviceObj["State"].toInt());
|
||||
const bool connectState = deviceObj["ConnectState"].toBool();
|
||||
const QString bluetoothDeviceType = deviceObj["Icon"].toString();
|
||||
|
||||
removeDevice(id);
|
||||
@ -63,6 +64,7 @@ void Adapter::addDevice(const QJsonObject &deviceObj)
|
||||
device->setName(name);
|
||||
device->setPaired(paired);
|
||||
device->setState(state);
|
||||
device->setConnectState(connectState);
|
||||
device->setRssi(rssi);
|
||||
device->setAdapterId(m_id);
|
||||
device->setDeviceType(bluetoothDeviceType);
|
||||
@ -92,6 +94,7 @@ void Adapter::updateDevice(const QJsonObject &dviceJson)
|
||||
const bool paired = dviceJson["Paired"].toBool();
|
||||
const int rssi = dviceJson["RSSI"].toInt();
|
||||
const Device::State state = Device::State(dviceJson["State"].toInt());
|
||||
const bool connectState = dviceJson["ConnectState"].toBool();
|
||||
const QString bluetoothDeviceType = dviceJson["Icon"].toString();
|
||||
|
||||
const Device *constdevice = m_devices.value(id);
|
||||
@ -102,6 +105,7 @@ void Adapter::updateDevice(const QJsonObject &dviceJson)
|
||||
device->setPaired(paired);
|
||||
device->setRssi(rssi);
|
||||
device->setState(state);
|
||||
device->setConnectState(connectState);
|
||||
device->setDeviceType(bluetoothDeviceType);
|
||||
}
|
||||
}
|
||||
@ -156,6 +160,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
|
||||
const bool paired = deviceObj["Paired"].toBool();
|
||||
const int rssi = deviceObj["RSSI"].toInt();
|
||||
const Device::State state = Device::State(deviceObj["State"].toInt());
|
||||
const bool connectState = deviceObj["ConnectState"].toBool();
|
||||
const QString bluetoothDeviceType = deviceObj["Icon"].toString();
|
||||
|
||||
auto device = new Device(this);
|
||||
@ -163,6 +168,7 @@ void Adapter::initDevicesList(const QJsonDocument &doc)
|
||||
device->setName(name);
|
||||
device->setPaired(paired);
|
||||
device->setState(state);
|
||||
device->setConnectState(connectState);
|
||||
device->setRssi(rssi);
|
||||
device->setAdapterId(adapterId);
|
||||
device->setDeviceType(bluetoothDeviceType);
|
||||
|
@ -79,7 +79,7 @@ AdapterItem::AdapterItem(AdaptersManager *adapterManager, Adapter *adapter, QWid
|
||||
m_initDeviceState = Device::StateAvailable;
|
||||
continue;
|
||||
}
|
||||
if (device->state() == Device::StateConnected) {
|
||||
if (device->state() == Device::StateConnected && device->connectState()) {
|
||||
m_initDeviceState = Device::StateConnected;
|
||||
break;
|
||||
}
|
||||
@ -207,18 +207,23 @@ void AdapterItem::addDeviceItem(const Device *constDevice)
|
||||
void AdapterItem::deviceChangeState(const Device::State state)
|
||||
{
|
||||
auto device = qobject_cast<Device *>(sender());
|
||||
|
||||
auto setUnavailableItem = [this](const Device::State state, DeviceItem *deviceItem){
|
||||
int index = m_sortUnConnect.indexOf(deviceItem);
|
||||
if (index < 0) {
|
||||
m_sortConnected.removeOne(deviceItem);
|
||||
m_sortUnConnect << deviceItem;
|
||||
qSort(m_sortUnConnect);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
}
|
||||
};
|
||||
|
||||
if (device) {
|
||||
DeviceItem *deviceItem = m_deviceItems.value(device->id());
|
||||
if (deviceItem) {
|
||||
switch (state) {
|
||||
case Device::StateUnavailable: {
|
||||
int index = m_sortUnConnect.indexOf(deviceItem);
|
||||
if (index < 0) {
|
||||
m_sortConnected.removeOne(deviceItem);
|
||||
m_sortUnConnect << deviceItem;
|
||||
qSort(m_sortUnConnect);
|
||||
moveDeviceItem(state, deviceItem);
|
||||
}
|
||||
setUnavailableItem(state, deviceItem);
|
||||
}
|
||||
break;
|
||||
case Device::StateAvailable: {
|
||||
@ -228,6 +233,10 @@ void AdapterItem::deviceChangeState(const Device::State state)
|
||||
}
|
||||
break;
|
||||
case Device::StateConnected: {
|
||||
if (!device->connectState()) {
|
||||
setUnavailableItem(state, deviceItem);
|
||||
break;
|
||||
}
|
||||
int index = m_sortConnected.indexOf(deviceItem);
|
||||
if (index < 0) {
|
||||
m_sortUnConnect.removeOne(deviceItem);
|
||||
|
@ -48,6 +48,7 @@ Device::Device(QObject *parent)
|
||||
, m_connecting(false)
|
||||
, m_rssi(0)
|
||||
, m_state(StateUnavailable)
|
||||
, m_connectState(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -85,6 +86,14 @@ void Device::setState(const State &state)
|
||||
}
|
||||
}
|
||||
|
||||
void Device::setConnectState(const bool connectState)
|
||||
{
|
||||
if (connectState != m_connectState) {
|
||||
m_connectState = connectState;
|
||||
Q_EMIT connectStateChanged(connectState);
|
||||
}
|
||||
}
|
||||
|
||||
void Device::setTrusted(bool trusted)
|
||||
{
|
||||
if (trusted != m_trusted) {
|
||||
|
@ -57,6 +57,9 @@ public:
|
||||
inline State state() const { return m_state; }
|
||||
void setState(const State &state);
|
||||
|
||||
inline bool connectState() const { return m_connectState; }
|
||||
void setConnectState(const bool connectState);
|
||||
|
||||
inline bool trusted() const { return m_trusted; }
|
||||
void setTrusted(bool trusted);
|
||||
|
||||
@ -76,6 +79,7 @@ Q_SIGNALS:
|
||||
void nameChanged(const QString &name) const;
|
||||
void pairedChanged(const bool paired) const;
|
||||
void stateChanged(const State state) const;
|
||||
void connectStateChanged(const bool connectState) const;
|
||||
void trustedChanged(const bool trusted) const;
|
||||
void connectingChanged(const bool &connecting) const;
|
||||
void rssiChanged(const int rssi) const;
|
||||
@ -88,6 +92,7 @@ private:
|
||||
bool m_connecting;
|
||||
int m_rssi;
|
||||
State m_state;
|
||||
bool m_connectState;
|
||||
QString m_adapterId;
|
||||
QString m_deviceType;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user