-
Notifications
You must be signed in to change notification settings - Fork 31
fix: clear bluetooth device list when adapter is powered off #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: clear bluetooth device list when adapter is powered off #420
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdate Bluetooth adapter powered-state handling so that device items and backing models are cleared when the adapter powers off, while preserving existing initialization when it powers on. Sequence diagram for bluetooth adapter poweredChanged handlingsequenceDiagram
participant Adapter
participant BluetoothAdapterItem
participant MyDeviceModel
participant OtherDeviceModel
Adapter->>BluetoothAdapterItem: poweredChanged(state)
alt state is true (adapter powered on)
BluetoothAdapterItem->>BluetoothAdapterItem: initData()
BluetoothAdapterItem->>MyDeviceModel: populate device list
BluetoothAdapterItem->>OtherDeviceModel: populate device list
else state is false (adapter powered off)
BluetoothAdapterItem->>BluetoothAdapterItem: qDeleteAll(m_deviceItems)
BluetoothAdapterItem->>BluetoothAdapterItem: m_deviceItems.clear()
BluetoothAdapterItem->>MyDeviceModel: clear()
BluetoothAdapterItem->>OtherDeviceModel: clear()
end
BluetoothAdapterItem->>BluetoothAdapterItem: m_refreshBtn.setVisible(state)
BluetoothAdapterItem->>BluetoothAdapterItem: m_myDeviceWidget.setVisible(m_myDeviceModel.rowCount() > 0 and state)
BluetoothAdapterItem->>BluetoothAdapterItem: m_otherDeviceListView.setVisible(state and (m_otherDeviceControlWidget.isExpand() or m_myDeviceModel.rowCount() < 1))
Class diagram for BluetoothAdapterItem powered state handlingclassDiagram
class BluetoothAdapterItem {
- Adapter m_adapter
- QList~BluetoothDeviceItem~ m_deviceItems
- DeviceModel m_myDeviceModel
- DeviceModel m_otherDeviceModel
- QPushButton m_refreshBtn
- QWidget m_myDeviceWidget
- QListView m_otherDeviceListView
- OtherDeviceControlWidget m_otherDeviceControlWidget
+ initConnect() void
+ initData() void
}
class Adapter {
+ poweredChanged(bool state) signal
}
class DeviceModel {
+ clear() void
+ rowCount() int
}
class BluetoothDeviceItem
class OtherDeviceControlWidget {
+ isExpand() bool
}
class QPushButton {
+ setVisible(bool visible) void
}
class QWidget {
+ setVisible(bool visible) void
}
class QListView {
+ setVisible(bool visible) void
}
BluetoothAdapterItem --> Adapter : uses
BluetoothAdapterItem o-- BluetoothDeviceItem : m_deviceItems
BluetoothAdapterItem --> DeviceModel : uses m_myDeviceModel
BluetoothAdapterItem --> DeviceModel : uses m_otherDeviceModel
BluetoothAdapterItem --> QPushButton : uses m_refreshBtn
BluetoothAdapterItem --> QWidget : uses m_myDeviceWidget
BluetoothAdapterItem --> QListView : uses m_otherDeviceListView
BluetoothAdapterItem --> OtherDeviceControlWidget : uses m_otherDeviceControlWidget
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- Consider extracting the device-list clearing logic into a dedicated helper method (e.g.,
clearDevices()), so it can be reused from other code paths that may need to reset the adapter state and to keep thepoweredChangedlambda focused and readable. - Since you are manually deleting
m_deviceItemswithqDeleteAll, it may be worth revisiting ownership of these objects to see if Qt parent-child ownership could handle their lifetime instead of keeping a separate list of raw pointers to manage.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the device-list clearing logic into a dedicated helper method (e.g., `clearDevices()`), so it can be reused from other code paths that may need to reset the adapter state and to keep the `poweredChanged` lambda focused and readable.
- Since you are manually deleting `m_deviceItems` with `qDeleteAll`, it may be worth revisiting ownership of these objects to see if Qt parent-child ownership could handle their lifetime instead of keeping a separate list of raw pointers to manage.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
ff7e8b7 to
479c52d
Compare
When airplane mode is enabled, bluetooth is automatically turned off. However, the device list was not being cleared, causing residual device information to be displayed in the bluetooth plugin panel. This fix ensures that when the bluetooth adapter is powered off, all device items and models are properly cleared to prevent display issues. Log: clear bluetooth device list when adapter is powered off Pms: BUG-338867
479c52d to
6a6ab82
Compare
deepin pr auto review这段代码主要对蓝牙适配器的状态变化处理进行了重构,提取了公共的清理逻辑。以下是对这段代码的审查意见,包括语法逻辑、代码质量、代码性能和代码安全四个方面: 1. 语法逻辑
2. 代码质量
3. 代码性能
4. 代码安全
总结这是一次良好的重构,主要提升了代码的可维护性和逻辑的清晰度。代码性能符合预期。唯一需要关注的是 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 18202781743, yixinshark The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
When airplane mode is enabled, bluetooth is automatically turned off. However, the device list was not being cleared, causing residual device information to be displayed in the bluetooth plugin panel.
This fix ensures that when the bluetooth adapter is powered off, all device items and models are properly cleared to prevent display issues.
Log: clear bluetooth device list when adapter is powered off
Pms: BUG-338867
Summary by Sourcery
Bug Fixes: