Skip to content

Conversation

@add-uos
Copy link
Contributor

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

pick develop/eagle to master

GongHeng2017 and others added 5 commits November 28, 2025 17:13
-- When disenable wireless, it maybe connneted.

pick from: linuxdeepin@e85b470

Log: fix issue
Bug: https://pms.uniontech.com/bug-view-308649.html
fix wakeup ps/2 mouse

Log: fix wakeup ps/2 mouse.
Bug: https://pms.uniontech.com/bug-view-313055.html
Change-Id: I84480ecaec50faecd8f841c6f22ccdbee369b294
format the overview of memory display

pick from: linuxdeepin@7f7dc01

Log: format the overview of memory display
Bug: https://pms.uniontech.com/bug-view-320787.html
Fixed the formatted resolution display of graphics cards by removing
redundant spaces.

pick from: linuxdeepin@2608aae

Log: Improve resolution display formatting
Bug: https://pms.uniontech.com/bug-view-324363.html
Change-Id: I9c2ee6868354bc2c55c45ffec42ba6a34f3e961d
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.

Sorry @add-uos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码进行审查,主要从语法逻辑、代码质量、性能和安全几个方面进行分析:

  1. enableutils.cpp 中的修改:

语法逻辑:

  • 代码逻辑基本正确,新增的无线网卡处理逻辑合理
  • 使用了 rfkill 和 ifconfig 命令来控制无线网卡状态

代码质量:

  • 建议将长的 shell 命令拆分成多行,提高可读性
  • 可以考虑将命令字符串提取为常量
  • 错误处理可以更详细,比如检查 rfkill 是否存在

性能:

  • 使用 system() 调用会有一定开销,但考虑到这是管理操作,可以接受
  • 可以考虑缓存无线网卡的状态,避免重复查询

安全:

  • 直接使用 system() 执行命令存在安全风险,建议使用 QProcess
  • 命令中的参数应该进行适当的转义和验证

建议改进代码:

bool EnableUtils::ioctlOperateNetworkLogicalName(const QString &logicalName, bool enable)
{
    qCDebug(appLog) << "Performing ioctl operation on network interface:" << logicalName << "enable:" << enable;
    
    if (logicalName.startsWith("wlan") || logicalName.startsWith("wlp")) {
        // 使用QProcess替代system调用
        QProcess process;
        
        // RFKILL操作
        QString rfkillCmd = QString("rfkill %1 $(rfkill list | grep -A 2 \"phy$(iw dev %2 info 2>/dev/null | awk '/wiphy/{print $2}')\" | awk 'NR==1{print $1}' | tr -d ':')")
                .arg(enable ? "unblock" : "block")
                .arg(logicalName);
        process.start("/bin/sh", QStringList() << "-c" << rfkillCmd);
        process.waitForFinished();
        if (process.exitCode() != 0) {
            qCritical() << "Failed to block/unblock wifi: " << process.errorString();
            return false;
        }
        
        // IFCONFIG操作
        QString ifconfigCmd = QString("/sbin/ifconfig %1 %2")
                .arg(logicalName)
                .arg(enable ? "up" : "down");
        process.start("/bin/sh", QStringList() << "-c" << ifconfigCmd);
        process.waitForFinished();
        if (process.exitCode() != 0) {
            qCritical() << "Failed to up/down network: " << logicalName << enable << " error: " << process.errorString();
            return false;
        }
        return true;
    }
    
    // 原有的有线网卡处理逻辑...
    // ...
}
  1. DeviceInput.cpp 中的修改:

语法逻辑:

  • 新增的 getBusInfo() 和 getInterface() 方法实现正确
  • isWakeupMachine() 中的逻辑判断修改合理

代码质量:

  • 代码结构清晰,新增方法命名规范
  • 建议在 getBusInfo() 和 getInterface() 方法中添加注释说明返回值的含义
  1. DeviceMemory.cpp 中的修改:

语法逻辑:

  • 字符串格式化的修改逻辑正确
  • 添加了 trim() 操作,避免多余空格

代码质量:

  • 建议将格式化字符串提取为常量
  • 可以考虑使用 QString::asprintf() 或 QString::arg() 的链式调用提高可读性

建议改进代码:

const QString DeviceMemory::getOverviewInfo()
{
    static const QString format = "%1(%2%3 %4)";
    
    QString nameStr = m_Name;
    if (nameStr == "--") {
        qCDebug(appLog) << "Name string is '--', clearing it";
        nameStr.clear();
    }
    
    QString ov = format.arg(m_Size)
                     .arg(nameStr)
                     .arg(nameStr.isEmpty() ? "" : " ")
                     .arg(m_Type)
                     .arg(m_Speed);
                     
    ov = ov.trimmed();
    qCDebug(appLog) << "Memory overview info:" << ov;
    return ov;
}
  1. ThreadExecXrandr.cpp 中的修改:

语法逻辑:

  • 分辨率显示格式的修改逻辑正确
  • 将 "x" 替换为 "×" 符号更符合显示规范

代码质量:

  • 建议将替换操作封装为单独的函数
  • 可以使用正则表达式一次性完成所有替换

建议改进代码:

QString formatResolution(const QString& resolution) {
    return resolution.replace(" ", "")
                    .replace("x", "×", Qt::CaseInsensitive);
}

// 在使用处:
lstMap[lstMap.count() - 1].insert("curResolution", formatResolution(match.captured(2)));
  1. TableWidget.cpp 中的修改:

语法逻辑:

  • 唤醒状态判断逻辑修改正确
  • 新增了对不同唤醒路径的处理

代码质量:

  • 建议将唤醒状态检查逻辑提取为单独的方法
  • 可以使用更简洁的条件表达式

建议改进代码:

bool TableWidget::isWakeupEnabled(const QString& wakeupPath, const QString& busInfo, const QString& name) {
    if (wakeupPath.contains("/proc/acpi/wakeup")) {
        return DBusWakeupInterface::getInstance()->isInputWakeupMachine(busInfo, name);
    }
    
    QFile file(wakeupPath);
    if (!file.open(QIODevice::ReadOnly)) {
        return false;
    }
    
    return !file.readAll().contains("disabled");
}

总体建议:

  1. 安全性:
  • 避免直接使用 system() 执行 shell 命令
  • 对用户输入进行适当的验证和转义
  • 使用 QProcess 替代 system 调用
  1. 性能:
  • 考虑缓存频繁访问的状态信息
  • 使用异步操作处理耗时的系统调用
  1. 代码质量:
  • 添加更多的注释说明
  • 将复杂逻辑拆分为更小的函数
  • 使用常量替代魔法数字和字符串
  • 统一错误处理方式
  1. 可维护性:
  • 保持代码风格的一致性
  • 使用更描述性的变量名
  • 考虑添加单元测试

这些修改建议可以帮助提高代码的质量、安全性和可维护性。

@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 f00f977 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.

4 participants