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
24 changes: 23 additions & 1 deletion deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,29 @@
return vendor.trimmed();
}

void DeviceBaseInfo::setVendorNameBylsusbLspci(const QString &vidpid, const QString &modalias)
{
if (!vidpid.isEmpty() && modalias.contains("usb")) {
QProcess process;
QString vendorId = vidpid.toLower().remove("0x").trimmed().left(4);
QString deviceId = vidpid.toLower().remove("0x").trimmed().right(4);
process.start("lsusb -v -d " + vendorId + ":" + deviceId);
process.waitForFinished(-1);

QString output = process.readAllStandardOutput();

foreach (QString out, output.split("\n")) {
// 从USB设备获取制造商和设备名称
if (out.contains("idVendor", Qt::CaseSensitive)) {
m_Vendor = out.remove(0, out.indexOf(vendorId) + 4).trimmed();
} else if (out.contains("idProduct", Qt::CaseSensitive)) {
m_Name = out.remove(0, out.indexOf(deviceId) + 4).trimmed();
}
}
}
}

const QString DeviceBaseInfo::getDriverVersion()

Check warning on line 810 in deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getDriverVersion' is never used.
{
qCDebug(appLog) << "DeviceBaseInfo::getDriverVersion called.";
QString outInfo = Common::executeClientCmd("modinfo", QStringList() << driver(), QString(), -1);
Expand Down Expand Up @@ -1464,4 +1486,4 @@
<< tr("Type") \
<< tr("Vendor") \
<< tr("Processor");
}
}
8 changes: 8 additions & 0 deletions deepin-devicemanager/src/DeviceManager/DeviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ class DeviceBaseInfo : public QObject
*/
const QString getVendorOrModelId(const QString &sysPath, bool flag = true);

/**
* @brief setVendorNameBylsusbLspci:获取Vendor 和 Name
* @param vidpid 属性vidpid
* @param modalias
* @return
*/
void setVendorNameBylsusbLspci(const QString &vidpid, const QString &modalias);

/**
* @brief get_string:读取文件内信息
* @param path:文件绝对路径+名称
Expand Down
10 changes: 8 additions & 2 deletions deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

// 项目自身文件
#include "DeviceMonitor.h"
#include "EDIDParser.h"

Check warning on line 7 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "EDIDParser.h" not found.
#include "commonfunction.h"

Check warning on line 8 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "commonfunction.h" not found.
#include "commondefine.h"

Check warning on line 9 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "commondefine.h" not found.
#include "DDLog.h"

Check warning on line 10 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "DDLog.h" not found.

#include <DApplication>

Check warning on line 12 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// Qt库文件
#include <QLoggingCategory>
Expand Down Expand Up @@ -175,10 +176,11 @@
TomlFixMethod DeviceMonitor::setInfoFromTomlOneByOne(const QMap<QString, QString> &mapInfo)
{
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.

m_IsTomlSet = true;
TomlFixMethod ret = TOML_None;
// 添加基本信息
ret = setTomlAttribute(mapInfo, "Type", m_Model);

Check warning on line 183 in deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'ret' is reassigned a value before the old one has been used.
ret = setTomlAttribute(mapInfo, "Display Input", m_DisplayInput);
ret = setTomlAttribute(mapInfo, "Interface Type", m_Interface);
qCDebug(appLog) << "Basic monitor attributes set from TOML - Model:" << m_Model << "Input:" << m_DisplayInput << "Interface:" << m_Interface;
Expand Down Expand Up @@ -427,7 +429,11 @@
qCDebug(appLog) << "Adjusting rate for board vendor type";
curRate = QString::number(ceil(curRate.left(pos).toDouble())) + curRate.right(curRate.size() - pos);
}
m_CurrentResolution = QString("%1@%2").arg(match.captured(1)).arg(curRate);
if (Common::specialComType == 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);
}
} else {
qCDebug(appLog) << "Rate is empty, setting current resolution without rate";
m_CurrentResolution = QString("%1").arg(match.captured(1));
Expand Down
33 changes: 7 additions & 26 deletions deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,9 @@ void DeviceNetwork::setInfoFromLshw(const QMap<QString, QString> &mapInfo)
setAttribute(mapInfo, "description", m_Model);
setAttribute(mapInfo, "product", m_Name);
setAttribute(mapInfo, "vendor", m_Vendor);
if (m_SysPath.contains("usb")) {
qCDebug(appLog) << "DeviceNetwork::setInfoFromLshw, sysPath contains usb";
QProcess process;
QString vendorId = getVendorOrModelId(m_SysPath, true).trimmed();
QString deviceId = getVendorOrModelId(m_SysPath, false).trimmed();
process.start("lsusb -v -d " + vendorId + ":" + deviceId);
process.waitForFinished(-1);

QString output = process.readAllStandardOutput();

foreach (QString out, output.split("\n")) {
if (!m_Vendor.isEmpty() && !m_Name.isEmpty())
break;
// 从USB设备获取制造商和设备名称
if (m_Vendor.isEmpty() && out.contains("idVendor", Qt::CaseSensitive)) {
m_Vendor = out.remove(0, out.indexOf(vendorId) + 4).trimmed();
} else if (m_Name.isEmpty() && out.contains("idProduct", Qt::CaseSensitive)) {
m_Name = out.remove(0, out.indexOf(deviceId) + 4).trimmed();
}
}
} else {
qCDebug(appLog) << "DeviceNetwork::setInfoFromLshw, sysPath not contains usb";
setAttribute(mapInfo, "description", m_Name, false);
}
if (m_Name.isEmpty())
setAttribute(mapInfo, "description", m_Name);

setAttribute(mapInfo, "version", m_Version);
setAttribute(mapInfo, "bus info", m_BusInfo);
setAttribute(mapInfo, "logical name", m_LogicalName);
Expand Down Expand Up @@ -169,6 +148,7 @@ bool DeviceNetwork::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
}
qCDebug(appLog) << "DeviceNetwork::setInfoFromHwinfo, mapInfo not contains path";
setAttribute(mapInfo, "Device", m_Name);
setAttribute(mapInfo, "Vendor", m_Vendor);
setAttribute(mapInfo, "Device File", m_LogicalName);
setAttribute(mapInfo, "HW Address", m_MACAddress);
setAttribute(mapInfo, "Permanent HW Address", m_UniqueID);
Expand All @@ -178,6 +158,9 @@ bool DeviceNetwork::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
setAttribute(mapInfo, "Module Alias", m_Modalias);
setAttribute(mapInfo, "VID_PID", m_VID_PID);
m_PhysID = m_VID_PID;
if (!m_VID_PID.isEmpty() && m_Modalias.contains("usb")) {
setVendorNameBylsusbLspci(m_VID_PID, m_Modalias);
}

if (driverIsKernelIn(m_DriverModules) || driverIsKernelIn(m_Driver)) {
qCDebug(appLog) << "DeviceNetwork::setInfoFromHwinfo, driver is kernel in";
Expand All @@ -193,8 +176,6 @@ bool DeviceNetwork::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
// 判断是否是无线网卡
setIsWireless(mapInfo["SysFS ID"]);

setHwinfoLshwKey(mapInfo);

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/GenerateDevice/CmdTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ void CmdTool::loadLshwInfo(const QString &debugFile)
qCDebug(appLog) << "Parsing lshw multimedia info.";
getMapInfoFromLshw(item, mapInfo);
addMapInfo("lshw_multimedia", mapInfo);
} else if (item.startsWith("network")) { // 网卡信息
} else if (item.startsWith("network") || item.startsWith("communication")) { // 网卡信息
qCDebug(appLog) << "Parsing lshw network info.";
getMapInfoFromLshw(item, mapInfo);
addMapInfo("lshw_network", mapInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void DeviceGenerator::generatorMonitorDevice()

bool isValidLogicalName(const QString& logicalName)
{
if (logicalName.contains("p2p", Qt::CaseInsensitive))
if (logicalName.contains("p2p", Qt::CaseInsensitive) || logicalName.isEmpty())
return false;

QString addressFilePath = "/sys/class/net/" + logicalName;
Expand Down