fix(bluetooth): fix audio-headphones device type support#3006
fix(bluetooth): fix audio-headphones device type support#3006deepin-bot[bot] merged 1 commit intolinuxdeepin:masterfrom
Conversation
Correct typo "autio-headphones" to "audio-headphones" in device type check and add corresponding icon mapping to ensure proper display and handling of audio headphone devices. log: fix audio-headphones device type support bug: PMS-285835
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes handling of the 'audio-headphones' Bluetooth device type by correcting a typo in the device type check and adding an icon mapping for the device type. Class diagram for BluetoothDevice icon mapping updateclassDiagram
class BluetoothDevice {
+QString id
+QString name
+QString deviceType()
+State state
}
class BluetoothWorker {
+void connectDevice(QString deviceId, QString adapterId)
}
class DeviceTypeIconMap {
+QMap~QString,QString~ deviceType2Icon
}
BluetoothWorker --> BluetoothDevice : uses
DeviceTypeIconMap .. BluetoothDevice : maps deviceType
class DeviceTypeIconEntries {
+input-keyboard : bluetooth_keyboard
+input-mouse : bluetooth_mouse
+input-tablet : bluetooth_touchpad
+audio-card : bluetooth_pheadset
+audio-headset : bluetooth_clang
+audio-headphones : bluetooth_headset
+network-wireless : bluetooth_lan
+camera-video : bluetooth_vidicon
+printer : bluetooth_print
}
DeviceTypeIconMap o-- DeviceTypeIconEntries : contains entries
Flow diagram for BluetoothWorker connectDevice type check updateflowchart TD
A[connectDevice called with deviceId and adapterId] --> B[Retrieve adapter via adapterById]
B --> C[Find device via adapter.deviceById]
C --> D{Device exists?}
D -- No --> E[Proceed with connection logic]
D -- Yes --> F{device.deviceType is audio-headset or audio-headphones?}
F -- No --> E[Proceed with connection logic]
F -- Yes --> G{device.state is BluetoothDevice::StateAvailable?}
G -- Yes --> H[Return early and do not reconnect]
G -- No --> E[Proceed with connection logic]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider centralizing Bluetooth device type strings (e.g.,
audio-headset,audio-headphones) into shared constants or an enum to avoid future typos and keep comparisons and icon mappings in sync.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider centralizing Bluetooth device type strings (e.g., `audio-headset`, `audio-headphones`) into shared constants or an enum to avoid future typos and keep comparisons and icon mappings in sync.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review这段代码修改主要是关于蓝牙设备类型字符串的修复。以下是对代码的详细审查和改进建议: 1. 语法逻辑审查修改内容分析:
结论:
2. 代码质量审查存在的问题:
3. 代码性能审查
4. 代码安全审查
改进建议为了提高代码质量、可维护性和健壮性,建议进行以下重构: 建议 1:使用枚举代替字符串(推荐)定义一个枚举类型来表示蓝牙设备类型,避免直接使用字符串进行比较。 // bluetoothdevice.h
enum class BluetoothDeviceType {
Unknown,
InputTablet,
AudioCard,
AudioHeadset,
AudioHeadphones, // 新增
NetworkWireless,
CameraVideo,
Printer
};
// 在类中添加一个转换函数
BluetoothDeviceType deviceType() const; 优点:
建议 2:使用常量定义字符串(次选)如果无法修改底层接口返回的数据类型,必须使用字符串,至少应该将它们定义为常量。 // bluetoothdevice.h
namespace BluetoothDeviceTypeStrings {
constexpr const char* InputTablet = "input-tablet";
constexpr const char* AudioHeadset = "audio-headset";
constexpr const char* AudioHeadphones = "audio-headphones"; // 新增
// ...
}使用方式: // bluetoothworker.cpp
const QString currentType = device->deviceType();
if (device &&
(currentType == BluetoothDeviceTypeStrings::AudioHeadset ||
currentType == BluetoothDeviceTypeStrings::AudioHeadphones) &&
device->state() == BluetoothDevice::StateAvailable) {
return;
}建议 3:优化
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, mhduiy 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 |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
Correct typo "autio-headphones" to "audio-headphones" in device type check and add corresponding icon mapping to ensure proper display and handling of audio headphone devices.
log: fix audio-headphones device type support
bug: PMS-285835
Summary by Sourcery
Fix handling of Bluetooth devices reported as audio headphones so they are recognized correctly and display the appropriate icon.
Bug Fixes:
Enhancements: