-
Notifications
You must be signed in to change notification settings - Fork 78
fix: [Audio] Unify audio device detection and adapt DBus service for … #413
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
Conversation
…Qt version
This commit consolidates the duplicate audio device detection logic and adapts
the DBus service selection based on Qt version:
1. In iflytek_ai_assistant.cpp:
- Add Qt version check to select appropriate DBus service
- Qt >= 6.0: uses "org.deepin.dde.Audio1" (new DDE audio service)
- Qt < 6.0: uses "com.deepin.daemon.Audio" (legacy audio service)
2. In dtextedit.cpp:
- Remove duplicate checkAudioOutputDevice() and checkAudioInputDevice() methods
- Update onAudioPortEnabledChanged() to use IflytekAiAssistant's unified methods
- Add Qt version check for DBus signal connection to PortEnabledChanged
3. In dtextedit.h:
- Remove declarations of checkAudioOutputDevice() and checkAudioInputDevice()
This refactoring eliminates code duplication by using IflytekAiAssistant as
the single source of truth for audio device detection, improving maintainability
and ensuring consistent behavior across the application.
本次提交整合了重复的音频设备检测逻辑,并根据Qt版本适配不同的DBus服务:
1. iflytek_ai_assistant.cpp:
- 添加Qt版本判断来选择合适的DBus服务
- Qt >= 6.0: 使用 "org.deepin.dde.Audio1" (新版DDE音频服务)
- Qt < 6.0: 使用 "com.deepin.daemon.Audio" (旧版音频服务)
2. dtextedit.cpp:
- 删除重复的 checkAudioOutputDevice() 和 checkAudioInputDevice() 方法
- 修改 onAudioPortEnabledChanged() 使用 IflytekAiAssistant 的统一方法
- 为 PortEnabledChanged 信号连接添加Qt版本判断
3. dtextedit.h:
- 删除 checkAudioOutputDevice() 和 checkAudioInputDevice() 的声明
此次重构消除了代码重复,使用 IflytekAiAssistant 作为音频设备检测的唯一
入口,提高了代码可维护性并确保应用程序行为的一致性。
Log: fix: [Audio] Unify audio device detection and adapt DBus service for Qt version
Reviewer's GuideConsolidates audio device detection into IflytekAiAssistant and adapts both the DBus service constants and TextEdit’s DBus signal wiring based on the Qt version, removing duplicated detection logic from TextEdit. Sequence diagram for unified audio device detection on PortEnabledChangedsequenceDiagram
participant AudioService as AudioService
participant DBus as QDBusConnection_sessionBus
participant TextEdit as TextEdit
participant Assistant as IflytekAiAssistant
AudioService->>DBus: PortEnabledChanged(cardId, portName, enabled)
DBus->>TextEdit: onAudioPortEnabledChanged(cardId, portName, enabled)
TextEdit->>TextEdit: check enabled flag
alt enabled is false
TextEdit->>Assistant: hasAudioOutputDevice()
Assistant->>Assistant: build DBus Get CardsWithoutUnavailable
Assistant->>DBus: call using AUDIO_SERVICE AUDIO_PATH AUDIO_INTERFACE
DBus-->>Assistant: reply cards JSON
Assistant-->>TextEdit: bool hasOutputDevice
TextEdit->>Assistant: hasAudioInputDevice()
Assistant->>Assistant: build DBus Get CardsWithoutUnavailable
Assistant->>DBus: call using AUDIO_SERVICE AUDIO_PATH AUDIO_INTERFACE
DBus-->>Assistant: reply cards JSON
Assistant-->>TextEdit: bool hasInputDevice
alt hasOutputDevice is false
TextEdit->>TextEdit: show no output device warning
end
alt hasInputDevice is false
TextEdit->>TextEdit: show no input device warning
end
end
Class diagram for unified audio device detection in IflytekAiAssistant and TextEditclassDiagram
class IflytekAiAssistant {
- static IflytekAiAssistant* m_instance
- static QString AUDIO_SERVICE
- static QString AUDIO_PATH
- static QString AUDIO_INTERFACE
+ static IflytekAiAssistant* instance()
+ bool hasAudioOutputDevice()
+ bool hasAudioInputDevice()
}
class TextEdit {
+ TextEdit(QWidget* parent)
+ void onAudioPortEnabledChanged(quint32 cardId, QString portName, bool enabled)
}
class QDBusConnection_sessionBus {
+ bool connect(QString service, QString path, QString interfaceName, QString signalName, QObject* receiver, const char* slot)
+ QDBusReply call(QDBusMessage message)
}
TextEdit ..> IflytekAiAssistant : uses
TextEdit ..> QDBusConnection_sessionBus : connectsPortEnabledChanged
IflytekAiAssistant ..> QDBusConnection_sessionBus : queriesAudioCards
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我来对这个diff进行代码审查:
总体来说,这个改动是积极的,提高了代码的可维护性和性能,但还可以在错误处理和代码可读性方面进一步改进。 |
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 there - I've reviewed your changes - here's some feedback:
- The DBus service name and path selection based on Qt version are now duplicated between
iflytek_ai_assistant.cppandTextEdit’s constructor; consider exposing helpers or constants fromIflytekAiAssistant(or a shared header) so the service identifiers are defined in a single place. - Since
onAudioPortEnabledChangednow relies onIflytekAiAssistant::instance(), it may be safer to guard against a null/static initialization issue (e.g., check the pointer or ensure the singleton is initialized before connecting the DBus signal) to avoid potential crashes in edge initialization orders.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The DBus service name and path selection based on Qt version are now duplicated between `iflytek_ai_assistant.cpp` and `TextEdit`’s constructor; consider exposing helpers or constants from `IflytekAiAssistant` (or a shared header) so the service identifiers are defined in a single place.
- Since `onAudioPortEnabledChanged` now relies on `IflytekAiAssistant::instance()`, it may be safer to guard against a null/static initialization issue (e.g., check the pointer or ensure the singleton is initialized before connecting the DBus signal) to avoid potential crashes in edge initialization orders.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pppanghu77 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: unstable) |
…Qt version
This commit consolidates the duplicate audio device detection logic and adapts the DBus service selection based on Qt version:
In iflytek_ai_assistant.cpp: - Add Qt version check to select appropriate DBus service - Qt >= 6.0: uses "org.deepin.dde.Audio1" (new DDE audio service) - Qt < 6.0: uses "com.deepin.daemon.Audio" (legacy audio service)
In dtextedit.cpp:
In dtextedit.h: - Remove declarations of checkAudioOutputDevice() and checkAudioInputDevice()
This refactoring eliminates code duplication by using IflytekAiAssistant as
the single source of truth for audio device detection, improving maintainability
and ensuring consistent behavior across the application.
本次提交整合了重复的音频设备检测逻辑,并根据Qt版本适配不同的DBus服务:
iflytek_ai_assistant.cpp:
dtextedit.cpp: - 删除重复的 checkAudioOutputDevice() 和 checkAudioInputDevice() 方法 - 修改 onAudioPortEnabledChanged() 使用 IflytekAiAssistant 的统一方法 - 为 PortEnabledChanged 信号连接添加Qt版本判断
dtextedit.h:
此次重构消除了代码重复,使用 IflytekAiAssistant 作为音频设备检测的唯一
入口,提高了代码可维护性并确保应用程序行为的一致性。
Log: fix: [Audio] Unify audio device detection and adapt DBus service for Qt version
Summary by Sourcery
Unify audio device detection around IflytekAiAssistant and adapt D-Bus audio service usage based on the Qt version.
Bug Fixes:
Enhancements: