Skip to content

Conversation

@pppanghu77
Copy link
Contributor

@pppanghu77 pppanghu77 commented Dec 19, 2025

…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

Summary by Sourcery

Unify audio device detection around IflytekAiAssistant and adapt D-Bus audio service usage based on the Qt version.

Bug Fixes:

  • Ensure correct D-Bus audio service and signal connections are used for different Qt versions to maintain audio device monitoring.

Enhancements:

  • Centralize audio device detection logic in IflytekAiAssistant and remove duplicate checks from TextEdit.

…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
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 19, 2025

Reviewer's Guide

Consolidates 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 PortEnabledChanged

sequenceDiagram
    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
Loading

Class diagram for unified audio device detection in IflytekAiAssistant and TextEdit

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Make DDE audio DBus service selection depend on Qt version in the central audio helper
  • Wrap audio service constants in a Qt-version preprocessor check
  • Use org.deepin.dde.Audio1 path/interface/service for Qt >= 6.0
  • Fallback to com.deepin.daemon.Audio path/interface/service for Qt < 6.0
src/common/iflytek_ai_assistant.cpp
Update TextEdit’s DBus signal connection to match the Qt-dependent audio service
  • Guard the DBus connection with a Qt-version preprocessor check
  • Connect to org.deepin.dde.Audio1’s PortEnabledChanged signal when building with Qt >= 6.0
  • Keep the legacy com.deepin.daemon.Audio PortEnabledChanged connection for Qt < 6.0
src/editor/dtextedit.cpp
Remove duplicated audio device checking logic from TextEdit and reuse IflytekAiAssistant
  • Delete local checkAudioOutputDevice and checkAudioInputDevice implementations from TextEdit
  • In onAudioPortEnabledChanged, replace local checks with IflytekAiAssistant::instance()->hasAudioOutputDevice()/hasAudioInputDevice()
  • Remove the corresponding method declarations from TextEdit’s header
src/editor/dtextedit.cpp
src/editor/dtextedit.h

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这个diff进行代码审查:

  1. 代码质量改进:
  • 优点:将DBus服务相关的常量根据Qt版本进行条件编译,提高了代码的可维护性和兼容性。
  • 优点:将重复的音频设备检测逻辑移到了IflytekAiAssistant类中,遵循了DRY(Don't Repeat Yourself)原则。
  • 优点:删除了重复的checkAudioOutputDevice和checkAudioInputDevice方法,减少了代码冗余。
  1. 代码逻辑改进:
  • 建议:在条件编译时,应该检查QT_VERSION_CHECK的参数是否正确。目前使用的是(6, 0, 0),建议确认这个版本号是否准确。
  • 建议:在onAudioPortEnabledChanged函数中,建议将hasOutputDevice和hasInputDevice的检查合并为一个方法,因为这两个检查逻辑非常相似。
  1. 代码性能改进:
  • 优点:将音频设备检测逻辑移到IflytekAiAssistant单例中,避免了重复的DBus调用,提高了性能。
  • 建议:可以考虑在IflytekAiAssistant中缓存音频设备状态,避免每次都进行DBus查询。
  1. 代码安全改进:
  • 建议:在处理DBus消息时,应该添加错误处理机制,比如检查DBus连接是否成功,处理可能的异常情况。
  • 建议:在解析JSON数据时,应该添加数据验证,确保数据格式正确。
  1. 其他建议:
  • 建议:在条件编译的注释中,可以更详细地说明为什么不同Qt版本需要使用不同的DBus服务。
  • 建议:可以考虑使用枚举或常量来替代硬编码的Direction值(1和2),提高代码可读性。

总体来说,这个改动是积极的,提高了代码的可维护性和性能,但还可以在错误处理和代码可读性方面进一步改进。

Copy link

@sourcery-ai sourcery-ai bot left a 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.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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[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.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pppanghu77
Copy link
Contributor Author

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Dec 19, 2025

This pr force merged! (status: unstable)

@deepin-bot deepin-bot bot merged commit 22b176c into linuxdeepin:master Dec 19, 2025
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants