Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ void DeviceNetwork::setInfoFromLshw(const QMap<QString, QString> &mapInfo)
setAttribute(mapInfo, "ip", m_Ip);
setAttribute(mapInfo, "size", m_Speed);
setAttribute(mapInfo, "capacity", m_Capacity);
if (Common::isHwPlatform()) {
m_Speed = Common::formatNetworkSpeed(m_Speed);
m_Capacity = Common::formatNetworkSpeed(m_Capacity);
}
setAttribute(mapInfo, "Latency", m_Latency);
setAttribute(mapInfo, "multicast", m_Multicast);
if (driverIsKernelIn(m_DriverModules) || driverIsKernelIn(m_Driver)) {
Expand Down Expand Up @@ -100,6 +104,10 @@ TomlFixMethod DeviceNetwork::setInfoFromTomlOneByOne(const QMap<QString, QString
// 添加其他信息,成员变量
setTomlAttribute(mapInfo, "Maximum Rate", m_Capacity);
setTomlAttribute(mapInfo, "Negotiation Rate", m_Speed);
if (Common::isHwPlatform()) {
m_Capacity = Common::formatNetworkSpeed(m_Capacity);
m_Speed = Common::formatNetworkSpeed(m_Speed);
}
setTomlAttribute(mapInfo, "Port", m_Port);
setTomlAttribute(mapInfo, "Multicast", m_Multicast);
setTomlAttribute(mapInfo, "Link", m_Link);
Expand Down
4 changes: 2 additions & 2 deletions deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -214,7 +214,7 @@ bool DeviceStorage::setHwinfoInfo(const QMap<QString, QString> &mapInfo)
if (file.open(QIODevice::ReadOnly)) {
QString output = file.readAll();
if (!output.isEmpty()) {
m_Interface = "UFS";
m_Interface = "";
}
file.close();
}
Expand Down
6 changes: 3 additions & 3 deletions deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022-2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -281,7 +281,7 @@ void HWGenerator::generatorDiskDevice()
tempMap["Name"] = "nouse";

if (Common::specialComType == Common::kSpecialType2) {
tempMap["Interface"] = "UFS";
tempMap["Interface"] = "";
}

// 读取interface版本
Expand All @@ -299,7 +299,7 @@ void HWGenerator::generatorDiskDevice()
deviceInfo = process.readAllStandardOutput();

if (!deviceInfo.trimmed().isEmpty()) {
tempMap["interface"] = "UFS";
tempMap["interface"] = "";
}
}
}
Expand Down
48 changes: 47 additions & 1 deletion deepin-devicemanager/src/commonfunction.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 ~ 2026 Uniontech Software Technology Co.,Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
Expand Down Expand Up @@ -347,3 +347,49 @@ int Common::parseSharedCpuCount(const QString &sharedCpuList)
}
return count;
}

QString Common::formatNetworkSpeed(const QString& speed)
{
// 1. Trim whitespace; return original if empty
QString s = speed.trimmed();
if (s.isEmpty())
return speed;

// 2. Convert "Gbit/s" -> "Mbps" (1Gbit/s = 1000Mbps), case-sensitive
const QString gbitSuffix = "Gbit/s";
if (s.endsWith(gbitSuffix, Qt::CaseSensitive)) {
QString numStr = s.left(s.length() - gbitSuffix.length()).trimmed();
bool ok = false;
double num = numStr.toDouble(&ok);
if (ok) {
double mbps = num * 1000.0;
// Format: integer values get no decimal point, otherwise keep one decimal
double intPart;
if (std::abs(std::modf(mbps, &intPart)) < 1e-6) {
return QString::number(static_cast<long long>(mbps)) + "Mbps";
} else {
return QString::number(mbps, 'f', 1) + "Mbps";
}
}
}

// 3. Normalize "Mbit/s" -> "Mbps" (value unchanged, case-sensitive)
const QString mbitSuffix = "Mbit/s";
if (s.endsWith(mbitSuffix, Qt::CaseSensitive)) {
QString numStr = s.left(s.length() - mbitSuffix.length()).trimmed();
bool ok = false;
double num = numStr.toDouble(&ok);
if (ok) {
// Format: integer values get no decimal point, otherwise keep one decimal
double intPart;
if (std::abs(std::modf(num, &intPart)) < 1e-6) {
return QString::number(static_cast<long long>(num)) + "Mbps";
} else {
return QString::number(num, 'f', 1) + "Mbps";
}
}
}

// 4. Return original string if no known suffix matches
return speed;
}
11 changes: 10 additions & 1 deletion deepin-devicemanager/src/commonfunction.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 ~ 2026 Uniontech Software Technology Co.,Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
Expand Down Expand Up @@ -60,5 +60,14 @@ class Common
static QString formatTotalCache(const QString& perThreadCache, int coreCount);

static int parseSharedCpuCount(const QString &sharedCpuList);

/**
* @brief formatNetworkSpeed: Convert network speed units to Mbps
* @param speed: Original speed string (e.g., "1Gbit/s", "100Mbit/s")
* @return Converted speed string in Mbps format (e.g., "1000Mbps", "100Mbps")
* Returns the original string if no conversion is needed.
* Note: Case-sensitive - "Gbit/s" -> "Mbps", "Mbit/s" -> "Mbps"
*/
static QString formatNetworkSpeed(const QString& speed);
};
#endif // COMMONFUNCTION_H
Loading