From e5453ce7147d04f46c7a71492f56dcf2bce1f0eb Mon Sep 17 00:00:00 2001 From: gongheng Date: Tue, 29 Jul 2025 15:13:14 +0800 Subject: [PATCH 1/5] Perf: [cppcheck] parameter should be passed by const reference. -- Local variable "items" shadows outer variable. -- Function parameter should be passed by const reference. pick from: https://github.com/linuxdeepin/deepin-devicemanager/commit/52f69718bf951763e2ab39930f8de534f6147b81 --- .../src/DeviceManager/DeviceGpu.cpp | 13 +++++-------- .../src/DeviceManager/DeviceManager.cpp | 2 +- .../src/DeviceManager/DeviceManager.h | 2 +- .../src/DeviceManager/DeviceNetwork.cpp | 2 +- .../src/DeviceManager/DeviceNetwork.h | 2 +- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp b/deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp index e44ec2fbf..e8c92145d 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceGpu.cpp @@ -4,6 +4,7 @@ // 项目自身文件 #include "DeviceGpu.h" +#include "commondefine.h" #include "commonfunction.h" #include "DDLog.h" @@ -198,18 +199,14 @@ bool DeviceGpu::setHwinfoInfo(const QMap &mapInfo) // qCDebug(appLog) << "Skipping empty item in gpu-info."; continue; } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QStringList items = allStr.split(":", QString::SkipEmptyParts); -#else - QStringList items = allStr.split(":", Qt::SkipEmptyParts); -#endif - if (items.size() != 2) { + QStringList tmpItems = allStr.split(":", QT_SKIP_EMPTY_PARTS); + if (tmpItems.size() != 2) { // qCDebug(appLog) << "Skipping item with incorrect size in gpu-info: " << item; continue; } - if (items.first().trimmed() == "VRAM total size") { + if (tmpItems.first().trimmed() == "VRAM total size") { bool ok; - quint64 vramSize = items.last().trimmed().toULong(&ok, 16); + quint64 vramSize = tmpItems.last().trimmed().toULong(&ok, 16); if (ok && vramSize >= 1048576) { // qCDebug(appLog) << "VRAM total size found and valid, converting."; vramSize /= 1048576; diff --git a/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp b/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp index c1a000ffe..d01a68754 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp @@ -1432,7 +1432,7 @@ DeviceBaseInfo *DeviceManager::getNetworkDevice(const QString &unique_id) return nullptr; } -void DeviceManager::correctNetworkLinkStatus(QString linkStatus, QString networkDriver) +void DeviceManager::correctNetworkLinkStatus(const QString &linkStatus, const QString &networkDriver) { qCDebug(appLog) << "Correcting network link status"; if (m_ListDeviceNetwork.size() == 0) { diff --git a/deepin-devicemanager/src/DeviceManager/DeviceManager.h b/deepin-devicemanager/src/DeviceManager/DeviceManager.h index c58503b94..61ee5438d 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceManager.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceManager.h @@ -385,7 +385,7 @@ class DeviceManager : public QObject * @brief correctNetworkLinkStatus:校正网络连接状态 * @param linkStatus:连接状态 */ - void correctNetworkLinkStatus(QString linkStatus, QString networkDriver); + void correctNetworkLinkStatus(const QString &linkStatus, const QString &networkDriver); /** * @brief networkDriver:获取所有网络驱动 diff --git a/deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp b/deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp index 4163e072f..e04ea1835 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp @@ -255,7 +255,7 @@ bool DeviceNetwork::enable() return m_Enable; } -void DeviceNetwork::correctCurrentLinkStatus(QString linkStatus) +void DeviceNetwork::correctCurrentLinkStatus(const QString &linkStatus) { // qCDebug(appLog) << "DeviceNetwork::correctCurrentLinkStatus"; if (m_Link != linkStatus) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceNetwork.h b/deepin-devicemanager/src/DeviceManager/DeviceNetwork.h index 6b050289a..1bbda454d 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceNetwork.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceNetwork.h @@ -92,7 +92,7 @@ class DeviceNetwork : public DeviceBaseInfo * @brief correctCurrentLinkStatus * @param linkStatus */ - void correctCurrentLinkStatus(QString linkStatus); + void correctCurrentLinkStatus(const QString &linkStatus); /** * @brief logicalName: 获取网卡逻辑名称 From c2ddd14537bef9e6529e56eaf80d33cd99da9450 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Tue, 29 Jul 2025 11:20:42 +0800 Subject: [PATCH 2/5] fix: Update input device Bus interface display Corrected I2C protocol touchpad showing as PS/2 interface in Device Manager, and updated input device interface detection rules. pick from: https://github.com/linuxdeepin/deepin-devicemanager/commit/6e5ecd717ab12febf479e58f561eeb79dee7e078 Log: Fix incorrect Bus interface display for I2C devices Bug: https://pms.uniontech.com/bug-view-326531.html Task: https://pms.uniontech.com/task-view-379781.html Change-Id: Id30e6e792ce8757de50a53e68fec6af69d490644 --- .../src/DeviceManager/DeviceInput.cpp | 101 +++++++++++++++++- .../src/DeviceManager/DeviceInput.h | 23 ++++ 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInput.cpp b/deepin-devicemanager/src/DeviceManager/DeviceInput.cpp index 08d9e1b91..9218396ea 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInput.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceInput.cpp @@ -9,6 +9,7 @@ #include "DBusTouchPad.h" #include "DBusWakeupInterface.h" #include "DDLog.h" +#include "commondefine.h" // Qt库文件 #include @@ -67,6 +68,7 @@ bool DeviceInput::setInfoFromlshw(const QMap &mapInfo) qCDebug(appLog) << "Driver is empty and interface is PS/2, setting m_CanUninstall to false."; m_CanUninstall = false; } + getMouseInfoFromBusDevice(); // 获取其他设备信息 getOtherMapInfo(mapInfo); @@ -177,6 +179,7 @@ void DeviceInput::setInfoFromHwinfo(const QMap &mapInfo) setInfoFromBluetoothctl(); qCDebug(appLog) << "Info set from Bluetoothctl."; + getMouseInfoFromBusDevice(); // 获取其他设备信息 getOtherMapInfo(mapInfo); qCDebug(appLog) << "Exiting setInfoFromHwinfo."; @@ -361,6 +364,102 @@ QString DeviceInput::eventStrFromDeviceFiles(const QString &dfs) return ""; } +InputDeviceBusInfo DeviceInput::getDetailBusInfo(const QString &busId) +{ + InputDeviceBusInfo info; + info.busId = busId; + + // 根据 Bus ID 查找对应的接口类型信息-只会使用 interfaceType,其他内容预留维护参考 + static QMap busInfoMap = { + {"0000", {"0000", "UINPUT", "虚拟设备", "用于软件模拟输入"}}, + {"0001", {"0001", "PCI", "特殊输入卡", "通过 PCI/PCIe 总线连接的设备"}}, + {"0002", {"0002", "ISA", "古老 ISA 设备", "已淘汰的 ISA 接口设备"}}, + {"0003", {"0003", "USB", "USB鼠标/键盘/手柄", "最常见的外设接口,设备路径含 usb"}}, + {"0004", {"0004", "HIL", "HP-HIL终端设备", "历史遗留系统 (HP-HIL)"}}, + {"0005", {"0005", "BLUETOOTH", "蓝牙鼠标/键盘", "设备名称含 bluetooth,需 rfkill 管理"}}, + {"0006", {"0006", "VIRTUAL", "VMware/QEMU虚拟输入", "虚拟机中的输入设备"}}, + {"0007", {"0007", "SERIAL)", "串口鼠标", "设备节点为 /dev/ttyS*"}}, + {"0008", {"0008", "HOST", "内置键盘/触摸板", "通过主板直接连接的设备"}}, + {"0009", {"0009", "Game Port", "游戏手柄", "15针 D-Sub 接口"}}, + {"0010", {"0010", "PARALLEL", "老式输入设备", "/dev/parport*"}}, + {"0011", {"0011", "PS/2", "PS/2鼠标/键盘", "圆形 6-pin 接口,设备节点为 /dev/psaux"}}, + {"0012", {"0012", "RADIO", "无线接收器", "专用 2.4G 设备 (如罗技 Unifying)"}}, + {"0013", {"0013", "J1939", "车载工业设备", "CAN 总线扩展"}}, + {"0018", {"0018", "I2C", "高端触摸板/触控笔", "设备名称含 i2c,需 i2c-tools 调试"}}, + {"0019", {"0019", "SPI", "嵌入式触控屏", "通过 SPI 总线通信"}}, + {"001a", {"001A", "ILLUMINANCE", "环境光传感器", "部分笔记本的自动亮度调节"}}, + {"001b", {"001B", "GDIX", "Surface Dial", "微软 Surface Dial 特殊旋转输入设备"}}, + {"001c", {"001C", "WACOM", "数位板/绘图屏", "设备名含 wacom"}}, + {"001d", {"001D", "UCSI", "USB Type-C输入", "新式笔记本的 USB-C 扩展设备"}} + }; + + // 查找匹配的 Bus ID (不区分大小写) + QString lowerBusId = busId.toLower(); + if (busInfoMap.contains(lowerBusId)) { + return busInfoMap.value(lowerBusId); + } + + // 如果没有找到匹配的,返回未知类型 + info.interfaceType = "Unknown"; + info.typicalDevices = "UnKnown Device"; + info.description = QString("Unrecognized Bus ID: %1").arg(busId); + + return info; +} + +void DeviceInput::getMouseInfoFromBusDevice() +{ + QProcess process; + process.start("cat", QStringList() << "/proc/bus/input/devices"); + process.waitForFinished(10000); + QString rawContent = process.readAllStandardOutput(); + + QMap nameToBusMap; + + if (rawContent.isEmpty()) { + return ; + } + + QStringList deviceBlocks = rawContent.split("\n\n", QT_SKIP_EMPTY_PARTS); + + for (const QString &block : deviceBlocks) { + QString bus, name; + QStringList lines = block.split("\n", QT_SKIP_EMPTY_PARTS); + + for (const QString &line : lines) { + QString trimmedLine = line.trimmed(); + + // 提取 Bus 信息 (I: Bus=0019 ...) + if (trimmedLine.startsWith("I:") && trimmedLine.contains("Bus=")) { + QRegularExpression busRegex("Bus=([0-9a-fA-F]+)"); + QRegularExpressionMatch match = busRegex.match(trimmedLine); + if (match.hasMatch()) { + bus = match.captured(1); + } + } + + // 提取 Name 信息 (N: Name="Sleep Button") + if (trimmedLine.startsWith("N:") && trimmedLine.contains("Name=")) { + QRegularExpression nameRegex("Name=\"([^\"]+)\""); + QRegularExpressionMatch match = nameRegex.match(trimmedLine); + if (match.hasMatch()) { + name = match.captured(1); + } + } + } + + // 如果同时找到了 name 和 bus,则添加到映射中 + if (!name.isEmpty() && !bus.isEmpty()) { + nameToBusMap.insert(name, bus); + } + } + + if (nameToBusMap.contains(m_Name)) { + QString busID = nameToBusMap.value(m_Name); + m_Interface = getDetailBusInfo(busID).interfaceType; + } +} + QString DeviceInput::getBusInfo() const { return m_SysPath; @@ -397,7 +496,7 @@ bool DeviceInput::available() // qCDebug(appLog) << "driver is empty"; m_Available = false; } - if ("PS/2" == m_Interface || "Bluetooth" == m_Interface) { + if ("PS/2" == m_Interface || "Bluetooth" == m_Interface || "I2C" == m_Interface) { // qCDebug(appLog) << "interface is PS/2 or Bluetooth"; m_Available = true; } diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInput.h b/deepin-devicemanager/src/DeviceManager/DeviceInput.h index 2320df7c0..35e776f9c 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInput.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceInput.h @@ -8,6 +8,17 @@ #include "DeviceInfo.h" +/** + * @brief The InputDeviceBusInfo class + * 描述InputDevice设备的Bus信息 + */ +struct InputDeviceBusInfo { + QString busId; + QString interfaceType; + QString typicalDevices; + QString description; +}; + /** * @brief The DeviceInput class * 用来描述输入设备的类 @@ -171,6 +182,18 @@ class DeviceInput : public DeviceBaseInfo */ QString eventStrFromDeviceFiles(const QString &dfs); + /** + * @brief getDetailBusInfo + * @param busId Bus ID类别号 + * @return + */ + InputDeviceBusInfo getDetailBusInfo(const QString &busId); + + /** + * @brief getMouseInfoFromBusDevice + * 实时从/proc/bus/input/devices获取设备接口信息 + */ + void getMouseInfoFromBusDevice(); private: QString m_Model; // Date: Tue, 29 Jul 2025 19:31:33 +0800 Subject: [PATCH 3/5] Feat: [Monitor] The monitor name show error. -- parse the edid ,and show the right monitor name. pick from: https://github.com/linuxdeepin/deepin-devicemanager/commit/662a9122edcedb85a2392a155dfe9d2a5358e320 Log: add feature for Monitor. Task: https://pms.uniontech.com/task-view-379819.html --- .../src/DeviceManager/DeviceMonitor.cpp | 11 +++ .../src/DeviceManager/DeviceMonitor.h | 4 +- .../src/GenerateDevice/CustomGenerator.cpp | 2 +- .../src/GenerateDevice/HWGenerator.cpp | 2 +- deepin-devicemanager/src/Tool/EDIDParser.cpp | 68 +++++++++++++++- deepin-devicemanager/src/Tool/EDIDParser.h | 12 +++ deepin-devicemanager/src/Tool/commontools.cpp | 81 ++++++++++++++----- deepin-devicemanager/src/Tool/commontools.h | 2 +- 8 files changed, 156 insertions(+), 26 deletions(-) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp index d8da22f55..94ac1631e 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp @@ -227,6 +227,17 @@ void DeviceMonitor::setInfoFromEdid(const QMap &mapInfo) qCDebug(appLog) << "Finished setting monitor info from EDID"; } +void DeviceMonitor::setInfoFromEdidForCustom(const QMap &mapInfo) +{ + setAttribute(mapInfo, "Size", m_ScreenSize); + setAttribute(mapInfo, "Vendor", m_Vendor); + setAttribute(mapInfo, "Date", m_ProductionWeek); + setAttribute(mapInfo, "Display Input", m_DisplayInput); + setAttribute(mapInfo, "Model", m_Model); + m_Name = m_Model; + getOtherMapInfo(mapInfo); +} + void DeviceMonitor::setInfoFromDbus(const QMap &mapInfo) { qCDebug(appLog) << "Setting monitor info from D-Bus data"; diff --git a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.h b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.h index 49409eeb3..3a6ac781e 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.h @@ -67,7 +67,9 @@ class DeviceMonitor : public DeviceBaseInfo */ void setInfoFromEdid(const QMap &mapInfo); - /**@brief:PanGuV项目里面的显示屏信息是从dbus里面获取的*/ + void setInfoFromEdidForCustom(const QMap &mapInfo); + + /**@brief:华为PanGuV项目里面的显示屏信息是从dbus里面获取的*/ /** * @brief setInfoFromDbus:设置PanGuV项目里面的显示屏信息 * @param mapInfo:获取的信息map diff --git a/deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp b/deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp index 046250a8b..f7f661ce0 100644 --- a/deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp +++ b/deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp @@ -86,7 +86,7 @@ void CustomGenerator::generatorMonitorDevice() QStringList allEDIDS_all; allEDIDS_all.append(fileInfo.filePath() + "/" + "edid"); QString interface = fileInfo.fileName().remove("card0-").remove("card1-").remove("card2-"); - CommonTools::parseEDID(allEDIDS_all, interface); + CommonTools::parseEDID(allEDIDS_all, interface, false); } } } diff --git a/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp b/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp index 2d4f514e4..cf8171991 100644 --- a/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp +++ b/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp @@ -476,7 +476,7 @@ void HWGenerator::generatorMonitorDevice() QStringList allEDIDS_all; allEDIDS_all.append(fileInfo.filePath() + "/" + "edid"); QString interface = fileInfo.fileName().remove("card0-").remove("card1-").remove("card2-"); - CommonTools::parseEDID(allEDIDS_all,interface); + CommonTools::parseEDID(allEDIDS_all, interface, true); } } } diff --git a/deepin-devicemanager/src/Tool/EDIDParser.cpp b/deepin-devicemanager/src/Tool/EDIDParser.cpp index 1a8b26c26..5a1023786 100644 --- a/deepin-devicemanager/src/Tool/EDIDParser.cpp +++ b/deepin-devicemanager/src/Tool/EDIDParser.cpp @@ -89,7 +89,8 @@ bool EDIDParser::setEdid(const QString &edid, QString &errorMsg, const QString & // 解析屏幕尺寸 qCDebug(appLog) << "Parsing screen size"; parseScreenSize(); - + // 解析监视器名称 + parseMonitorName(); return true; } @@ -118,6 +119,11 @@ const QString &EDIDParser::screenSize()const return m_ScreenSize; } +const QString &EDIDParser::monitorName() const +{ + return m_MonitorName; +} + int EDIDParser::width() { // qCDebug(appLog) << "Getting width"; @@ -239,6 +245,66 @@ void EDIDParser::parseScreenSize() qCDebug(appLog) << "Screen size parsed:" << m_ScreenSize << "Width:" << m_Width << "Height:" << m_Height; } +void EDIDParser::parseMonitorName() +{ + // EDID中从字节54开始有4个18字节的Descriptor Block + // 每个Descriptor Block可能包含显示器名称信息 + // 显示器名称的标识符是0xFC(Display Product Name) 注意:部分机型有一些特殊,标识符为0xFE + + // 4个Descriptor Block的起始字节位置 + int descriptorStarts[4] = {54, 72, 90, 108}; + + for (int i = 0; i < 4; i++) { + int startByte = descriptorStarts[i]; + + // 计算行号和字节位置(每行16字节) + int line = startByte / 16; + int byteInLine = startByte % 16; + + // 获取Descriptor Block的关键字节 + QString byte0 = getBytes(line, byteInLine); // 第0字节 + QString byte1 = getBytes(line, byteInLine + 1); // 第1字节 + QString byte3 = getBytes(line, byteInLine + 3); // 第3字节(类型标识) + + // 检查是否为Display Descriptor (字节0-1为0x0000) 且类型为Display Product Name (字节3为0xFC) + if (byte0.toUpper() == "00" && byte1.toUpper() == "00" && (byte3.toUpper() == "FC" || byte3.toUpper() == "FE")) { + + // 找到显示器名称描述符,提取ASCII字符串(字节5-17) + QString monitorName; + + for (int j = 5; j <= 17; j++) { + int currentByte = startByte + j; + int currentLine = currentByte / 16; + int currentByteInLine = currentByte % 16; + + QString charByte = getBytes(currentLine, currentByteInLine); + + if (!charByte.isEmpty()) { + int asciiValue = hexToDec(charByte).toInt(); + + // ASCII可打印字符范围:32-126,0x0A为换行符,0x00为结束符 + if (asciiValue == 0x00 || asciiValue == 0x0A) { + break; // 遇到结束符或换行符,停止解析 + } else if (asciiValue >= 32 && asciiValue <= 126) { + monitorName.append(QChar(asciiValue)); + } + } + } + + // 去除首尾空白字符 + m_MonitorName = monitorName.trimmed(); + + // 如果找到有效的监视器名称,记录日志并返回 + if (!m_MonitorName.isEmpty()) + return; + } + } + + // 如果没有找到有效的监视器名称,设置默认值 + if (m_MonitorName.isEmpty()) + m_MonitorName = "Unknown Monitor"; +} + QString EDIDParser::binToDec(QString strBin) //二进制转十进制 { // qCDebug(appLog) << "Converting binary to decimal"; diff --git a/deepin-devicemanager/src/Tool/EDIDParser.h b/deepin-devicemanager/src/Tool/EDIDParser.h index cdee3cee3..32aa98209 100644 --- a/deepin-devicemanager/src/Tool/EDIDParser.h +++ b/deepin-devicemanager/src/Tool/EDIDParser.h @@ -52,6 +52,12 @@ class EDIDParser */ const QString &screenSize()const; + /** + * @brief screenSize:获取监视器名称 + * @return 监视器名称 + */ + const QString &monitorName()const; + /** * @brief width : get screen width * @return @@ -81,6 +87,11 @@ class EDIDParser */ void parseScreenSize(); + /** + * @brief parseScreenSize:从edid中获取监视器名称 + */ + void parseMonitorName(); + /** * @brief binToDec:将二进制转换成十进制 * @param strBin:二进制字符串 @@ -140,6 +151,7 @@ class EDIDParser QString m_Model; // 显示屏的型号信息 QString m_ReleaseDate; // 显示屏的生产日期 QString m_ScreenSize; // 屏幕大小 + QString m_MonitorName; // 监视器名称 bool m_LittleEndianMode; // 小端模式 int m_Width; // width int m_Height; // heigth diff --git a/deepin-devicemanager/src/Tool/commontools.cpp b/deepin-devicemanager/src/Tool/commontools.cpp index cceca1ab0..e0ace08de 100644 --- a/deepin-devicemanager/src/Tool/commontools.cpp +++ b/deepin-devicemanager/src/Tool/commontools.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "commontools.h" +#include "commondefine.h" #include "DDLog.h" #include "EDIDParser.h" #include "DeviceMonitor.h" @@ -183,45 +184,83 @@ QString CommonTools::getBackupPath() return "/var/lib/deepin-devicemanager/"; } -void CommonTools::parseEDID(const QStringList &allEDIDS, const QString &input) +void CommonTools::parseEDID(const QStringList &allEDIDS, const QString &input, bool isHW) { for (auto edid:allEDIDS) { - QProcess process; - process.start(QString("hexdump %1").arg(edid)); - process.waitForFinished(-1); + QString edidStr; + if (isHW) { + QProcess process; + process.start(QString("hexdump %1").arg(edid)); + process.waitForFinished(-1); - QString deviceInfo = process.readAllStandardOutput(); - if (deviceInfo.isEmpty()) - continue; + QString deviceInfo = process.readAllStandardOutput(); + if (deviceInfo.isEmpty()) + continue; - QString edidStr; - QStringList lines = deviceInfo.split("\n"); - for (auto line:lines) { - QStringList words = line.trimmed().split(" "); - if (words.size() != 9) + QStringList lines = deviceInfo.split("\n"); + for (auto line:lines) { + QStringList words = line.trimmed().split(" "); + if (words.size() != 9) + continue; + + words.removeAt(0); + QString l = words.join(""); + l.append("\n"); + edidStr.append(l); + } + } else { + QProcess process; + process.start(QString("hexdump -C %1").arg(edid)); + process.waitForFinished(-1); + QString deviceInfo = process.readAllStandardOutput(); + if (deviceInfo.isEmpty()) continue; - words.removeAt(0); - QString l = words.join(""); - l.append("\n"); - edidStr.append(l); + QStringList lines = deviceInfo.split("\n"); + for (auto line: lines) { + if (line.trimmed().isEmpty()) + continue; + int firstSpace = line.indexOf(" "); + int lastPipe = line.indexOf("|"); + + if (firstSpace == -1 || lastPipe == -1 || firstSpace >= lastPipe) + continue; + + QString hexPart = line.mid(firstSpace + 2, lastPipe - firstSpace -3).trimmed(); + + QStringList hexBytes = hexPart.split(QRegularExpression("\\s+")); + + QString lineData; + for (const QString &hexByte : hexBytes) { + if (hexByte.length() == 2 && hexByte != "") + lineData.append(hexByte); + } + + if (lineData.length() == 32) + edidStr.append(lineData + "\n"); + } } - lines = edidStr.split("\n"); + QStringList lines = edidStr.split("\n"); if (lines.size() > 3){ EDIDParser edidParser; QString errorMsg; - edidParser.setEdid(edidStr,errorMsg,"\n", false); + edidParser.setEdid(edidStr,errorMsg,"\n", isHW ? false : true); QMap mapInfo; mapInfo.insert("Vendor",edidParser.vendor()); - mapInfo.insert("Model",edidParser.model()); - //mapInfo.insert("Date",edidParser.releaseDate()); + if (isHW) + mapInfo.insert("Model",edidParser.model()); + else + mapInfo.insert("Model",edidParser.monitorName()); mapInfo.insert("Size",edidParser.screenSize()); mapInfo.insert("Display Input",input); DeviceMonitor *device = new DeviceMonitor(); - device->setInfoFromEdid(mapInfo); + if (isHW) + device->setInfoFromEdid(mapInfo); + else + device->setInfoFromEdidForCustom(mapInfo); DeviceManager::instance()->addMonitor(device); } } diff --git a/deepin-devicemanager/src/Tool/commontools.h b/deepin-devicemanager/src/Tool/commontools.h index 71b2bc890..96ec149a5 100644 --- a/deepin-devicemanager/src/Tool/commontools.h +++ b/deepin-devicemanager/src/Tool/commontools.h @@ -78,7 +78,7 @@ class CommonTools : public QObject */ static QString getBackupPath(); - static void parseEDID(const QStringList &allEDIDS, const QString &input); + static void parseEDID(const QStringList &allEDIDS, const QString &input, bool isHW = true); static QString getGpuInfoCommandFromDConfig(); signals: From 6d28f05b9b483cd423bc9ca29d604309e9fa342f Mon Sep 17 00:00:00 2001 From: gongheng Date: Wed, 30 Jul 2025 13:09:48 +0800 Subject: [PATCH 4/5] fix: [cppcheck] Remove the useless code. -- The "ret" is not use, so remvoe it. pick from: https://github.com/linuxdeepin/deepin-devicemanager/commit/dabc018f6903ae6e97e11ba844946ac473d36283 --- .../src/DeviceManager/DeviceAudio.cpp | 12 +++++----- .../src/DeviceManager/DeviceBios.cpp | 4 ++-- .../src/DeviceManager/DeviceBluetooth.cpp | 23 ++++++++++--------- .../src/DeviceManager/DeviceCdrom.cpp | 8 +++---- .../src/DeviceManager/DeviceInfo.cpp | 4 ++-- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceAudio.cpp b/deepin-devicemanager/src/DeviceManager/DeviceAudio.cpp index b88cae03b..a777e45e8 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceAudio.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceAudio.cpp @@ -140,14 +140,14 @@ TomlFixMethod DeviceAudio::setInfoFromTomlOneByOne(const QMap { qCDebug(appLog) << "DeviceAudio::setInfoFromTomlOneByOne started."; TomlFixMethod ret = TOML_None; -// must cover the loadOtherDeviceInfo + // must cover the loadOtherDeviceInfo // 添加基本信息 - ret = setTomlAttribute(mapInfo, "SysFS_Path", m_SysPath); - ret = setTomlAttribute(mapInfo, "KernelModeDriver", m_Driver); + setTomlAttribute(mapInfo, "SysFS_Path", m_SysPath); + setTomlAttribute(mapInfo, "KernelModeDriver", m_Driver); // 添加其他信息,成员变量 - ret = setTomlAttribute(mapInfo, "Chip", m_Chip); - ret = setTomlAttribute(mapInfo, "Capabilities", m_Capabilities); - ret = setTomlAttribute(mapInfo, "Memory Address", m_Memory); + setTomlAttribute(mapInfo, "Chip", m_Chip); + setTomlAttribute(mapInfo, "Capabilities", m_Capabilities); + setTomlAttribute(mapInfo, "Memory Address", m_Memory); ret = setTomlAttribute(mapInfo, "IRQ", m_Irq); //3. 获取设备的其它信息 getOtherMapInfo(mapInfo); diff --git a/deepin-devicemanager/src/DeviceManager/DeviceBios.cpp b/deepin-devicemanager/src/DeviceManager/DeviceBios.cpp index a1b99f13f..db08bf7f8 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceBios.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceBios.cpp @@ -28,8 +28,8 @@ TomlFixMethod DeviceBios::setInfoFromTomlOneByOne(const QMap & TomlFixMethod ret = TOML_None; ret = setTomlAttribute(mapInfo, "Version", m_Version, true); - ret = setTomlAttribute(mapInfo, "Product Name", m_ProductName, true); - ret = setTomlAttribute(mapInfo, "Chipset", m_ChipsetFamily, true); + setTomlAttribute(mapInfo, "Product Name", m_ProductName, true); + setTomlAttribute(mapInfo, "Chipset", m_ChipsetFamily, true); // ret = setTomlAttribute(mapInfo, "Vendor", m_Vendor,true); // m_IsBoard = true; qCDebug(appLog) << "Toml attributes set for Version, Product Name, Chipset."; diff --git a/deepin-devicemanager/src/DeviceManager/DeviceBluetooth.cpp b/deepin-devicemanager/src/DeviceManager/DeviceBluetooth.cpp index 86b97aa7c..3daa08c87 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceBluetooth.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceBluetooth.cpp @@ -140,22 +140,23 @@ TomlFixMethod DeviceBluetooth::setInfoFromTomlOneByOne(const QMap { qCDebug(appLog) << "DeviceCdrom::setInfoFromTomlOneByOne started."; TomlFixMethod ret = TOML_None; - ret = setTomlAttribute(mapInfo, "Model", m_Type); - ret = setTomlAttribute(mapInfo, "Bus Info", m_BusInfo); - ret = setTomlAttribute(mapInfo, "Capabilities", m_Capabilities); - ret = setTomlAttribute(mapInfo, "Maximum Power", m_MaxPower); + setTomlAttribute(mapInfo, "Model", m_Type); + setTomlAttribute(mapInfo, "Bus Info", m_BusInfo); + setTomlAttribute(mapInfo, "Capabilities", m_Capabilities); + setTomlAttribute(mapInfo, "Maximum Power", m_MaxPower); ret = setTomlAttribute(mapInfo, "Speed", m_Speed); qCDebug(appLog) << "Toml attributes set."; //3. 获取设备的其它信息 diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp b/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp index 41b747655..5a77a96bc 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp @@ -630,8 +630,8 @@ TomlFixMethod DeviceBaseInfo::setInfoFromTomlBase(const QMap & return TOML_Del; } - ret2 = setTomlAttribute(mapInfo, "Revision", m_Version); - ret2 = setTomlAttribute(mapInfo, "Description", m_Description); + setTomlAttribute(mapInfo, "Revision", m_Version); + setTomlAttribute(mapInfo, "Description", m_Description); m_VID = m_VID.toLower(); m_PID = m_PID.toLower(); m_VID_PID = m_VID + m_PID.remove("0x"); From 0b351be84149485a89296c3b7d041e0d8a27cf5c Mon Sep 17 00:00:00 2001 From: gongheng Date: Wed, 30 Jul 2025 13:33:09 +0800 Subject: [PATCH 5/5] Perf: [cppcheck] Improve program execution efficiency. -- Enhance application runtime performance -- Clean up dead/unused code pick from: https://github.com/linuxdeepin/deepin-devicemanager/commit/04d5c66a8f4fc4de8d05df32843b633a75af5763 --- .../src/DeviceManager/DeviceManager.cpp | 51 ++++++++++--------- .../src/DeviceManager/DeviceMonitor.cpp | 3 +- .../src/DeviceManager/DeviceStorage.cpp | 2 +- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp b/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp index d01a68754..774155c03 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceManager.cpp @@ -39,7 +39,7 @@ using namespace DDLog; DeviceManager *DeviceManager::sInstance = nullptr; int DeviceManager::m_CurrentXlsRow = 1; -QMutex addCmdMutex; +static QMutex addCmdMutex; DeviceManager::DeviceManager() : m_CpuNum(1) @@ -398,12 +398,14 @@ QList DeviceManager::convertDeviceList(DeviceType deviceType) if (deviceType == DT_Print) {return m_ListDevicePrint;} if (deviceType == DT_Image) {return m_ListDeviceImage;} if (deviceType == DT_Others) {return m_ListDeviceOthers;} + + return QList(); } DeviceBaseInfo *DeviceManager::createDevice(DeviceType deviceType) { qCDebug(appLog) << "Creating device for deviceType:" << deviceType; - DeviceBaseInfo *vTemp; + DeviceBaseInfo *vTemp { nullptr }; if (deviceType == DT_Computer) {vTemp = new DeviceComputer(); return vTemp;} if (deviceType == DT_Cpu) {vTemp = new DeviceCpu(); return vTemp;} if (deviceType == DT_Bios) {vTemp = new DeviceBios(); return vTemp;} @@ -508,7 +510,6 @@ TomlFixMethod DeviceManager::tomlDeviceMapSet(DeviceType deviceType, DeviceBase DevicePower *tomldevice = dynamic_cast(device); (TOML_Del == tomldevice->setInfoFromTomlBase(mapInfo)) ? ret = TOML_Del : ret = tomldevice->setInfoFromTomlOneByOne(mapInfo); } break; - default: { } break; } return ret; } @@ -518,83 +519,81 @@ QString DeviceManager::tomlDeviceReadKeyValue(DeviceType deviceType, DeviceBaseI if (!device) return QString(""); - TomlFixMethod ret = TOML_None; switch (deviceType) { case DT_Null: break; case DT_Computer: { DeviceComputer *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Cpu: { DeviceCpu *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Bios: { DeviceBios *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Memory: { DeviceMemory *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; - case DT_Storage: { + }; + case DT_Storage: { DeviceStorage *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Gpu: { DeviceGpu *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Monitor: { DeviceMonitor *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Network: { DeviceNetwork *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Audio: { DeviceAudio *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Bluetoorh: { DeviceBluetooth *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Keyboard: { DeviceInput *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Mouse: { DeviceInput *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Print: { DevicePrint *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Image: { DeviceImage *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Cdrom: { DeviceCdrom *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Others: { DeviceOthers *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_OtherPCI: { DeviceOtherPCI *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; + }; case DT_Power: { DevicePower *tomldevice = dynamic_cast(device); return tomldevice->readDeviceInfoKeyValue(key); - } break; - default: { } break; + }; } return QString(""); } @@ -602,6 +601,8 @@ QString DeviceManager::tomlDeviceReadKeyValue(DeviceType deviceType, DeviceBaseI bool DeviceManager::tomlSetBytomlmatchkey(DeviceType deviceType, DeviceBaseInfo *device, const QString &tomltomlmatchkey, const QString &tomltomlconfigdemanding) { Q_UNUSED(deviceType) + Q_UNUSED(tomltomlconfigdemanding) + QMap itemMap; QStringList keyValues = tomltomlmatchkey.split(","); foreach (const QString &keyValue, keyValues) { @@ -739,10 +740,12 @@ void DeviceManager::tomlDeviceAdd(DeviceType deviceType, DeviceBaseInfo *const d bool DeviceManager::findByModalias(DeviceType deviceType, DeviceBaseInfo *device, const QString &modalias) { qCDebug(appLog) << "Finding by Modalias for deviceType:" << deviceType; + if (modalias.isEmpty()) { qCDebug(appLog) << "Modalias is empty"; return false; } + { if (!device) { qCDebug(appLog) << "Device is null"; diff --git a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp index 94ac1631e..22040726b 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp @@ -386,8 +386,7 @@ const QString DeviceMonitor::getOverviewInfo() qCDebug(appLog) << "Getting monitor overview information"; QString ov; - ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize); - if (Common::specialComType == 6) { + if (Common::specialComType == 6 || Common::specialComType == 7) { ov = QString("(%1)").arg(m_ScreenSize); } else { ov = QString("%1(%2)").arg(m_Name).arg(m_ScreenSize); diff --git a/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp b/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp index 2eba86b37..9891abac5 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp @@ -629,7 +629,7 @@ QString DeviceStorage::subTitle() const QString DeviceStorage::getOverviewInfo() { // qCDebug(appLog) << "DeviceStorage::getOverviewInfo"; - QString overViewInfo = QString("%1 (%2)").arg(m_Name).arg(m_Size); + QString overViewInfo; if (m_Interface.contains("UFS", Qt::CaseInsensitive)) { overViewInfo = QString("%1 %2").arg(m_Size).arg("UFS");