Skip to content

fix: the flmx device of monitor display#558

Merged
deepin-bot[bot] merged 5 commits intolinuxdeepin:masterfrom
add-uos:master
Nov 28, 2025
Merged

fix: the flmx device of monitor display#558
deepin-bot[bot] merged 5 commits intolinuxdeepin:masterfrom
add-uos:master

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Nov 28, 2025

Merge: pick some commits to master

fix the flmx device of monitor display

pick form: linuxdeepin@4d4e3f7

Log: fix the flmx device of monitor display

Task: https://pms.uniontech.com/task-view-368603.html
@sourcery-ai
Copy link

sourcery-ai bot commented Nov 28, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Gate TOML-based monitor info initialization on a specific communication type so that m_IsTomlSet is only marked true for specialComType == 2, preventing unintended TOML overrides for other monitor devices.

Sequence diagram for TOML-based monitor info initialization gating

sequenceDiagram
    participant System as System
    participant DeviceMonitor as DeviceMonitor
    participant Common as Common

    System->>DeviceMonitor: setInfoFromTomlOneByOne(mapInfo)
    DeviceMonitor->>Common: read specialComType
    alt specialComType == 2
        DeviceMonitor->>DeviceMonitor: m_IsTomlSet = true
        DeviceMonitor->>DeviceMonitor: setTomlAttribute(Type, m_Model)
        DeviceMonitor->>DeviceMonitor: setTomlAttribute(Brand, m_Brand)
        DeviceMonitor-->>System: TomlFixMethod (TOML_* based on processing)
    else specialComType != 2
        DeviceMonitor->>DeviceMonitor: m_IsTomlSet remains false
        DeviceMonitor->>DeviceMonitor: setTomlAttribute(Type, m_Model)
        DeviceMonitor->>DeviceMonitor: setTomlAttribute(Brand, m_Brand)
        DeviceMonitor-->>System: TomlFixMethod (TOML_* based on processing)
    end
Loading

Updated class diagram for DeviceMonitor TOML handling

classDiagram
    class Common {
        <<namespace>>
        +int specialComType
    }

    class DeviceMonitor {
        -bool m_IsTomlSet
        -QString m_Model
        -QString m_Brand
        +void setInfoFromHwinfo(QMap<QString, QString> mapInfo)
        +TomlFixMethod setInfoFromTomlOneByOne(QMap<QString, QString> mapInfo)
    }

    class TomlFixMethod {
        <<enum>>
        TOML_None
        TOML_Success
        TOML_Error
        TOML_Partial
    }

    DeviceMonitor ..> Common : reads_specialComType
    DeviceMonitor ..> TomlFixMethod : returns

    %% Highlighted logic change in setInfoFromTomlOneByOne
    class DeviceMonitor {
        +void setInfoFromTomlOneByOne(QMap<QString, QString> mapInfo)
    }
Loading

File-Level Changes

Change Details Files
Restrict when monitor TOML configuration is considered applied to only the specific communication type.
  • Wrap the assignment to m_IsTomlSet in setInfoFromTomlOneByOne with a condition that checks Common::specialComType == 2
  • Ensure TOML-based monitor information is only flagged as set for the designated communication type, avoiding side effects for other devices
deepin-devicemanager/src/DeviceManager/DeviceMonitor.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:

  • Consider replacing the magic value Common::specialComType == 2 with a named enum or constant (or at least a brief comment) so it's clear under what condition TOML-based monitor info should be applied.
  • If m_IsTomlSet was previously relied on unconditionally elsewhere, it may be worth verifying whether non-specialComType == 2 cases need a different flag or handling path rather than silently leaving m_IsTomlSet false.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider replacing the magic value `Common::specialComType == 2` with a named enum or constant (or at least a brief comment) so it's clear under what condition TOML-based monitor info should be applied.
- If `m_IsTomlSet` was previously relied on unconditionally elsewhere, it may be worth verifying whether non-`specialComType == 2` cases need a different flag or handling path rather than silently leaving `m_IsTomlSet` false.

## Individual Comments

### Comment 1
<location> `deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp:178` </location>
<code_context>
 {
     qCDebug(appLog) << "Setting monitor info from TOML configuration";
-    m_IsTomlSet = true;
+    if (Common::specialComType == 2)
+        m_IsTomlSet = true;
     TomlFixMethod ret = TOML_None;
</code_context>

<issue_to_address>
**nitpick:** Consider avoiding the magic number `2` for `specialComType` and use a named constant or enum instead.

Using the raw value makes this condition harder to understand and more brittle if `specialComType` values change. Prefer comparing against a named enum value or constant to make the intent explicit and reduce maintenance risk.
</issue_to_address>

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.

{
qCDebug(appLog) << "Setting monitor info from TOML configuration";
m_IsTomlSet = true;
if (Common::specialComType == 2)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: Consider avoiding the magic number 2 for specialComType and use a named constant or enum instead.

Using the raw value makes this condition harder to understand and more brittle if specialComType values change. Prefer comparing against a named enum value or constant to make the intent explicit and reduce maintenance risk.

add-uos and others added 4 commits November 28, 2025 14:42
fix the pgux device of monitor display

pick from: linuxdeepin@958f62c
Log: fix the pgux device of monitor display

Task: https://pms.uniontech.com/task-view-368603.html
add communication network  support

pick from: linuxdeepin@da8e009

Log:  add communication network  support

Bug: https://pms.uniontech.com/task-view-360593.html
add communication network  support

pick from: linuxdeepin@093ad2a

Log:  add communication network  support

Bug: https://pms.uniontech.com/task-view-360593.html
@deepin-ci-robot
Copy link

deepin pr auto review

我来分析一下这些代码变更:

  1. DeviceInfo.cpp/h 中的新函数 setVendorNameBylsusbLspci:
    • 语法逻辑:基本正确,但缺少错误处理
    • 代码质量:
      • 函数名不符合驼峰命名规范,建议改为 setVendorNameByLsusbLspci
      • 缺少对 process 执行结果的检查
      • 字符串操作可以优化
    • 性能问题:
      • 每次调用都启动新的 QProcess,开销较大
      • 使用 foreach 已被 Qt 官方不推荐
    • 安全问题:
      • 直接拼接命令字符串存在注入风险
      • 没有处理 process 执行失败的情况

建议改进:

void DeviceBaseInfo::setVendorNameByLsusbLspci(const QString &vidpid, const QString &modalias)
{
    if (vidpid.isEmpty() || !modalias.contains("usb")) {
        return;
    }

    QProcess process;
    QString vendorId = vidpid.toLower().remove("0x").trimmed().left(4);
    QString deviceId = vidpid.toLower().remove("0x").trimmed().right(4);
    
    // 使用参数列表避免命令注入
    QStringList args;
    args << "-v" << "-d" << QString("%1:%2").arg(vendorId).arg(deviceId);
    process.start("lsusb", args);
    
    if (!process.waitForFinished(3000)) {  // 设置超时
        qCWarning(appLog) << "lsusb command timeout";
        return;
    }

    QString output = process.readAllStandardOutput();
    const QStringList lines = output.split('\n');
    
    for (const QString &line : lines) {
        if (line.contains("idVendor")) {
            int index = line.indexOf(vendorId);
            if (index != -1) {
                m_Vendor = line.mid(index + 4).trimmed();
            }
        } else if (line.contains("idProduct")) {
            int index = line.indexOf(deviceId);
            if (index != -1) {
                m_Name = line.mid(index + 4).trimmed();
            }
        }
        
        // 如果已经获取到所有信息就退出
        if (!m_Vendor.isEmpty() && !m_Name.isEmpty()) {
            break;
        }
    }
}
  1. DeviceMonitor.cpp 中的修改:
    • 语法逻辑:正确
    • 代码质量:
      • 使用 Common::specialComType 的魔法数字,建议定义枚举常量
    • 性能:无明显问题
    • 安全:无明显问题

建议改进:

enum SpecialComputerType {
    NORMAL = 0,
    TYPE_2 = 2,  // 需要添加实际含义的注释
    TYPE_5 = 5   // 需要添加实际含义的注释
};

// 在使用时
if (Common::specialComType == SpecialComputerType::TYPE_2) {
    m_IsTomlSet = true;
}

if (Common::specialComType == SpecialComputerType::TYPE_5) {
    m_CurrentResolution = QString("%1").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info));
} else {
    m_CurrentResolution = QString("%1@%2").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)).arg(curRate);
}
  1. DeviceNetwork.cpp 中的修改:

    • 语法逻辑:正确
    • 代码质量:
      • 移除了重复的 USB 设备信息获取代码,提高了代码复用性
    • 性能:改进了代码结构,减少了重复操作
    • 安全:无明显问题
  2. CmdTool.cpp 中的修改:

    • 语法逻辑:正确
    • 代码质量:合理扩展了网络设备的识别范围
    • 性能:无明显影响
    • 安全:无明显问题
  3. DeviceGenerator.cpp 中的修改:

    • 语法逻辑:正确
    • 代码质量:增加了对空 logicalName 的检查
    • 性能:无明显影响
    • 安全:无明显问题

总体建议:

  1. 添加更多的错误处理和日志记录
  2. 避免使用魔法数字,使用有意义的枚举或常量
  3. 注意命令注入风险,使用参数列表而非字符串拼接
  4. 考虑添加单元测试覆盖新增的功能
  5. 对于性能敏感的操作,考虑缓存结果
  6. 添加必要的代码注释说明特殊处理的原因

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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 Nov 28, 2025

/merge

@deepin-bot deepin-bot bot merged commit f3f5477 into linuxdeepin:master Nov 28, 2025
17 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