Skip to content

fix: Improve input device Bus interface detection#523

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
add-uos:develop/eagle
Aug 27, 2025
Merged

fix: Improve input device Bus interface detection#523
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
add-uos:develop/eagle

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Aug 27, 2025

  • Use case-insensitive contains matching instead of exact string comparison
  • Support interface name variations like 'ps/2', 'bluetooth low energy', etc.
  • Refactor hardcoded interface checks to use static list and loop
  • Fix device availability detection for input devices with non-standard interface names

Log: Improve input device Bus interface detection
Bug: https://pms.uniontech.com/bug-view-331181.html
Change-Id: Ifbc7c40f44f45e146f07fe101ed3fc960e945459

Summary by Sourcery

Improve detection of supported input device interfaces by using case-insensitive substring matching and iterating over a static list of interfaces.

Bug Fixes:

  • Fix availability detection for input devices with non-standard interface name variations

Enhancements:

  • Refactor hardcoded interface comparisons into a static list and loop
  • Switch to case-insensitive contains matching for interface names

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 27, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactor DeviceInput::available() to replace hardcoded interface checks with a static list and case-insensitive substring matching, enabling support for interface name variations and fixing availability detection for non-standard names.

Class diagram for updated DeviceInput::available() method

classDiagram
    class DeviceInput {
        - QString m_Interface
        - bool m_Available
        - bool m_forcedDisplay
        + bool available()
    }
    DeviceInput : available() uses static QStringList supportInterfaces
    DeviceInput : available() uses case-insensitive substring matching for interface detection
Loading

File-Level Changes

Change Details Files
Refactor interface detection to use static list and loop
  • Introduce static QStringList supportInterfaces for known interfaces
  • Replace hardcoded if statements with a for-loop over supportInterfaces
  • Remove exact string comparisons of m_Interface
deepin-devicemanager/src/DeviceManager/DeviceInput.cpp
Implement case-insensitive contains matching
  • Compare interface.toLower().contains(m_Interface.toLower())
  • Enable detection of variations like 'ps/2' and 'bluetooth low energy'
  • Fix availability flag setting for non-standard interface names
deepin-devicemanager/src/DeviceManager/DeviceInput.cpp

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

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 contains check seems inverted – you probably want to check if m_Interface.toLower() contains the known interface strings, not the other way around.
  • Add a break after setting m_Available to true to avoid unnecessary iterations once a match is found.
  • Use a const reference in the range-for (for example, 'const auto& iface') to avoid copying QStrings on each loop iteration.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The contains check seems inverted – you probably want to check if m_Interface.toLower() contains the known interface strings, not the other way around.
- Add a break after setting m_Available to true to avoid unnecessary iterations once a match is found.
- Use a const reference in the range-for (for example, 'const auto& iface') to avoid copying QStrings on each loop iteration.

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.

- Use case-insensitive contains matching instead of exact string
comparison
- Support interface name variations like 'ps/2', 'bluetooth low energy',
etc.
- Refactor hardcoded interface checks to use static list and loop
- Fix device availability detection for input devices with non-standard
interface names

Log: Improve input device Bus interface detection
Bug: https://pms.uniontech.com/bug-view-331181.html
Change-Id: Ifbc7c40f44f45e146f07fe101ed3fc960e945459
@deepin-ci-robot
Copy link

deepin pr auto review

我对这段代码的审查意见如下:

  1. 代码逻辑改进:
  • 原代码中使用多个字符串比较判断接口类型,现在改用QStringList的contains方法,逻辑更清晰,维护性更好
  • 添加了静态成员变量m_supportInterfaces来集中管理支持的接口类型,符合DRY(Don't Repeat Yourself)原则
  1. 代码质量改进:
  • 将支持的接口类型集中管理在m_supportInterfaces中,提高了代码的可维护性
  • 使用Qt::CaseInsensitive参数进行不区分大小写的比较,增强了代码的健壮性
  1. 代码性能改进:
  • 使用QStringList::contains()比多个字符串比较更高效,特别是在需要扩展支持接口类型时
  • 静态成员变量的使用避免了重复创建字符串列表
  1. 代码安全改进:
  • 使用Qt::CaseInsensitive参数避免了因大小写不同导致的判断错误
  • 将支持的接口类型集中管理,减少了硬编码,降低了出错风险
  1. 其他建议:
  • 考虑在构造函数中初始化m_supportInterfaces,而不是在类定义外初始化,这样更符合C++的初始化规范
  • 可以考虑将m_supportInterfaces设为const,因为支持的接口类型通常不会改变
  • 建议添加注释说明m_supportInterfaces的用途和维护方式

改进后的代码结构更清晰,性能更好,安全性更高,且更易于维护和扩展。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, max-lvs

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

@add-uos
Copy link
Contributor Author

add-uos commented Aug 27, 2025

/merge

@deepin-bot deepin-bot bot merged commit b8c68ae into linuxdeepin:develop/eagle Aug 27, 2025
14 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