Skip to content

feat: format network speed as Mbps and remove hard-coded UFS interface#684

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:develop/eagle
Jun 8, 2026
Merged

feat: format network speed as Mbps and remove hard-coded UFS interface#684
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/eaglefrom
add-uos:develop/eagle

Conversation

@add-uos
Copy link
Copy Markdown
Contributor

@add-uos add-uos commented Jun 8, 2026

  • Add Common::formatNetworkSpeed() to convert speed units: "Gbit/s" -> "Mbps" (x1000), "Mbit/s" -> "Mbps" (unit normalization)
  • Apply the conversion to network Speed and Capacity on HW platform in DeviceNetwork for both lshw and toml info sources
  • Remove hard-coded "UFS" storage interface in DeviceStorage and HWGenerator

Log: 网卡速率统一转换为Mbps显示,移除硬盘接口硬编码的UFS
Task: https://pms.uniontech.com/task-view-390747.html
Change-Id: If4834ad6080330e5ce0a350a37c7e1698d13f2c2

Summary by Sourcery

Normalize hardware network speed display to Mbps and remove hard-coded UFS storage interface values.

New Features:

  • Add a common utility to convert network speed strings to normalized Mbps values.

Enhancements:

  • Apply unified Mbps formatting for network speed and capacity on hardware platforms for both lshw and TOML data sources.
  • Clear storage interface fields instead of using a hard-coded UFS value for certain hardware configurations.
  • Update copyright headers to cover the 2019-2026 and 2022-2026 periods in touched files.

- Add Common::formatNetworkSpeed() to convert speed units:
  "Gbit/s" -> "Mbps" (x1000), "Mbit/s" -> "Mbps" (unit normalization)
- Apply the conversion to network Speed and Capacity on HW platform in
  DeviceNetwork for both lshw and toml info sources
- Remove hard-coded "UFS" storage interface in DeviceStorage and HWGenerator

Log: 网卡速率统一转换为Mbps显示,移除硬盘接口硬编码的UFS
Task: https://pms.uniontech.com/task-view-390747.html
Change-Id: If4834ad6080330e5ce0a350a37c7e1698d13f2c2
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 8, 2026

Reviewer's Guide

Adds a common helper to normalize network speed strings to Mbps on hardware platforms and applies it to DeviceNetwork (for both lshw and TOML sources), while removing hard-coded UFS storage interface values in HW generator and DeviceStorage; also updates several copyright headers.

Sequence diagram for formatting network speed to Mbps in DeviceNetwork

sequenceDiagram
    participant DeviceNetwork
    participant Common

    DeviceNetwork->>DeviceNetwork: setInfoFromLshw(mapInfo)
    DeviceNetwork->>DeviceNetwork: setAttribute("size", m_Speed)
    DeviceNetwork->>DeviceNetwork: setAttribute("capacity", m_Capacity)
    alt [Common::isHwPlatform()]
        DeviceNetwork->>Common: isHwPlatform()
        Common-->>DeviceNetwork: bool
        DeviceNetwork->>Common: formatNetworkSpeed(m_Speed)
        Common-->>DeviceNetwork: QString
        DeviceNetwork->>DeviceNetwork: m_Speed = result
        DeviceNetwork->>Common: formatNetworkSpeed(m_Capacity)
        Common-->>DeviceNetwork: QString
        DeviceNetwork->>DeviceNetwork: m_Capacity = result
    end

    DeviceNetwork->>DeviceNetwork: setInfoFromTomlOneByOne(mapInfo)
    DeviceNetwork->>DeviceNetwork: setTomlAttribute("Maximum Rate", m_Capacity)
    DeviceNetwork->>DeviceNetwork: setTomlAttribute("Negotiation Rate", m_Speed)
    alt [Common::isHwPlatform()]
        DeviceNetwork->>Common: isHwPlatform()
        Common-->>DeviceNetwork: bool
        DeviceNetwork->>Common: formatNetworkSpeed(m_Capacity)
        Common-->>DeviceNetwork: QString
        DeviceNetwork->>DeviceNetwork: m_Capacity = result
        DeviceNetwork->>Common: formatNetworkSpeed(m_Speed)
        Common-->>DeviceNetwork: QString
        DeviceNetwork->>DeviceNetwork: m_Speed = result
    end
Loading

File-Level Changes

Change Details Files
Introduce Common::formatNetworkSpeed to normalize network speed values to Mbps.
  • Add static Common::formatNetworkSpeed(const QString&) declaration with documentation in commonfunction.h.
  • Implement Common::formatNetworkSpeed in commonfunction.cpp to trim input, convert Gbit/s to Mbps by multiplying by 1000, normalize Mbit/s to Mbps, preserve integer vs fractional formatting, and fall back to the original string when parsing fails or suffix is unknown.
  • Use case-sensitive matching for "Gbit/s" and "Mbit/s" suffixes and rely on std::modf and std::abs to determine integer values.
  • Minor header comment tweak changing copyright year separator from "~" to "-".
deepin-devicemanager/src/commonfunction.cpp
deepin-devicemanager/src/commonfunction.h
Apply network speed formatting on hardware platforms for network devices populated from lshw and TOML sources.
  • After reading size and capacity from lshw, conditionally normalize m_Speed and m_Capacity via Common::formatNetworkSpeed when Common::isHwPlatform() is true.
  • After reading Maximum Rate and Negotiation Rate from TOML, conditionally normalize m_Capacity and m_Speed via Common::formatNetworkSpeed when Common::isHwPlatform() is true.
deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp
Remove hard-coded UFS storage interface strings for special hardware configurations and when hwinfo readout exists.
  • In HWGenerator::generatorDiskDevice, change the special-type-2 assignment of disk Interface/interface from "UFS" to an empty string so the interface is no longer forced to UFS.
  • In DeviceStorage::setHwinfoInfo, change the interface assignment on successful file read from "UFS" to an empty string.
  • Update SPDX-FileCopyrightText headers in HWGenerator.cpp and DeviceStorage.cpp to include the 2022-2026 year span.
deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp
deepin-devicemanager/src/DeviceManager/DeviceStorage.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
Copy Markdown

@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 - I've left some high level feedback:

  • In Common::formatNetworkSpeed, you trim the input into s but return the original speed in the empty/no-match paths, which will reintroduce leading/trailing spaces; consider consistently returning s (or the trimmed version) when no conversion is applied.
  • In DeviceNetwork::setInfoFromLshw and setInfoFromTomlOneByOne, the speed/capacity values are written via setAttribute/setTomlAttribute before being passed through formatNetworkSpeed, so the stored attributes remain unformatted; if the goal is to expose normalized Mbps values, apply the conversion before setting these attributes (or write back the converted values).
  • For the UFS interface handling in HWGenerator and DeviceStorage, you now assign an empty string where "UFS" was previously hard-coded; if an unknown or unset interface is intended, consider omitting the key or using a clearer sentinel value rather than an empty string to avoid ambiguity downstream.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In Common::formatNetworkSpeed, you trim the input into `s` but return the original `speed` in the empty/no-match paths, which will reintroduce leading/trailing spaces; consider consistently returning `s` (or the trimmed version) when no conversion is applied.
- In DeviceNetwork::setInfoFromLshw and setInfoFromTomlOneByOne, the speed/capacity values are written via setAttribute/setTomlAttribute before being passed through formatNetworkSpeed, so the stored attributes remain unformatted; if the goal is to expose normalized Mbps values, apply the conversion before setting these attributes (or write back the converted values).
- For the UFS interface handling in HWGenerator and DeviceStorage, you now assign an empty string where `"UFS"` was previously hard-coded; if an unknown or unset interface is intended, consider omitting the key or using a clearer sentinel value rather than an empty string to avoid ambiguity downstream.

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
Copy Markdown

[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
Copy Markdown
Contributor Author

add-uos commented Jun 8, 2026

/forcemerge

@deepin-bot
Copy link
Copy Markdown
Contributor

deepin-bot Bot commented Jun 8, 2026

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 965f869 into linuxdeepin:develop/eagle Jun 8, 2026
21 of 22 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