diff --git a/deepin-devicemanager-server/customgpuinfo/main.cpp b/deepin-devicemanager-server/customgpuinfo/main.cpp index 72502513..b20d40d5 100644 --- a/deepin-devicemanager-server/customgpuinfo/main.cpp +++ b/deepin-devicemanager-server/customgpuinfo/main.cpp @@ -98,8 +98,7 @@ bool getGpuMemInfoForFTDTM(QMap &mapInfo) int main(int argc, char *argv[]) { QMap mapInfo; - if (getGpuBaseInfo(mapInfo)) { - getGpuMemInfoForFTDTM(mapInfo); + if (getGpuMemInfoForFTDTM(mapInfo)) { for (auto it = mapInfo.begin(); it != mapInfo.end(); ++it) std::cout << it.key().toStdString() << ": " << it.value().toStdString() << std::endl; return 0; diff --git a/deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp b/deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp index f46caa6d..8411d60f 100644 --- a/deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp +++ b/deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp @@ -93,27 +93,22 @@ void DeviceInterface::setMonitorDeviceFlag(bool flag) QString DeviceInterface::getGpuInfoByCustom(const QString &cmd, const QStringList &arguments) { - static bool firstFlag = true; - static QString gpuinfo; - if (firstFlag) { - firstFlag = false; - - QProcess process; - QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - if (arguments.size() > 1) { - env.insert("DISPLAY", arguments[0]); - env.insert("XAUTHORITY", arguments[1]); - } - process.setProcessEnvironment(env); - process.start(cmd, arguments); - if (!process.waitForFinished(4000)) { - qCritical() << QString("Error executing %1 :").arg(cmd) << process.errorString(); - return gpuinfo; - } - - if (process.exitCode() == 0) - gpuinfo = QString::fromLocal8Bit(process.readAllStandardOutput()); + QString gpuinfo; + QProcess process; + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + if (arguments.size() > 1) { + env.insert("DISPLAY", arguments[0]); + env.insert("XAUTHORITY", arguments[1]); } + process.setProcessEnvironment(env); + process.start(cmd, arguments); + if (!process.waitForFinished()) { + qCritical() << QString("Error executing %1 :").arg(cmd) << process.errorString(); + return gpuinfo; + } + + if (process.exitCode() == 0) + gpuinfo = QString::fromLocal8Bit(process.readAllStandardOutput()); return gpuinfo; } diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp b/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp index 5a77a96b..5d47713b 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp @@ -688,7 +688,7 @@ bool DeviceBaseInfo::driverIsKernelIn(const QString &driver) return isKernelIn; } -void DeviceBaseInfo::setCanEnale(bool can) +void DeviceBaseInfo::setCanEnable(bool can) { // qCDebug(appLog) << "DeviceBaseInfo::setCanEnale called with can: " << can; m_CanEnable = can; diff --git a/deepin-devicemanager/src/DeviceManager/DeviceInfo.h b/deepin-devicemanager/src/DeviceManager/DeviceInfo.h index e3d6c875..c0988081 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceInfo.h +++ b/deepin-devicemanager/src/DeviceManager/DeviceInfo.h @@ -164,10 +164,10 @@ class DeviceBaseInfo : public QObject virtual bool driverIsKernelIn(const QString &driver); /** - * @brief setCanEnale : set can enable or not + * @brief setCanEnable : set can enable or not * @param can */ - void setCanEnale(bool can); + void setCanEnable(bool can); /** * @brief canEnable : 该设备是否可以禁用 diff --git a/deepin-devicemanager/src/DeviceManager/DeviceOthers.cpp b/deepin-devicemanager/src/DeviceManager/DeviceOthers.cpp index f1c5cab4..7b195f4e 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceOthers.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceOthers.cpp @@ -48,7 +48,7 @@ void DeviceOthers::setInfoFromLshw(const QMap &mapInfo) if(m_Driver.isEmpty() && !m_Avail.compare("yes", Qt::CaseInsensitive)){ qCDebug(appLog) << "DeviceOthers::setInfoFromLshw, driver is empty and avail is yes"; setForcedDisplay(true); - setCanEnale(false); + setCanEnable(false); if(!(tmp_Name.contains("fingerprint", Qt::CaseInsensitive) || tmp_Name. contains("MOH", Qt::CaseInsensitive))) setCanUninstall(false); } diff --git a/deepin-devicemanager/src/DeviceManager/DevicePower.cpp b/deepin-devicemanager/src/DeviceManager/DevicePower.cpp index 1fb90680..9b2580b4 100644 --- a/deepin-devicemanager/src/DeviceManager/DevicePower.cpp +++ b/deepin-devicemanager/src/DeviceManager/DevicePower.cpp @@ -8,11 +8,16 @@ #include "DDLog.h" // Qt库文件 -#include +#include +#include // Dtk头文件 #include +constexpr const char* kPowerService = "com.deepin.system.Power"; +constexpr const char* kPowerPath = "/com/deepin/system/Power"; +constexpr const char* kPowerInterface = "com.deepin.system.Power"; + DWIDGET_USE_NAMESPACE using namespace DDLog; @@ -107,7 +112,19 @@ bool DevicePower::setInfoFromUpower(const QMap &mapInfo) m_Temp = QString("%1 degrees C").arg(temp); }*/ - getOtherMapInfo(mapInfo); + // 当前电池容量修改成通过DDE接口获得,目的是与状态栏的当前电池容量保持一致(bug#333825) + QMap tmpMapInfo = mapInfo; + if (tmpMapInfo.contains("percentage")) { + QDBusInterface interface(kPowerService, kPowerPath, kPowerInterface, QDBusConnection::systemBus()); + if (interface.isValid()) { + double tmpValue = interface.property("BatteryPercentage").toDouble(); + tmpMapInfo["percentage"] = QString("%1%").arg(static_cast(tmpValue)); + } else { + qCritical() << QString("Dbus %1 is not valid!").arg(kPowerService); + } + } + + getOtherMapInfo(tmpMapInfo); return true; } diff --git a/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp b/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp index 9891abac..dd6fb2fc 100644 --- a/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp +++ b/deepin-devicemanager/src/DeviceManager/DeviceStorage.cpp @@ -252,11 +252,9 @@ bool DeviceStorage::setHwinfoInfo(const QMap &mapInfo) QFile file(Path); if (file.open(QIODevice::ReadOnly)) { qCDebug(appLog) << "DeviceStorage::setHwinfoInfo, open spec_version success"; - QString output2 = file.readAll(); - if (output2.contains("310", Qt::CaseInsensitive)) { - m_Interface = "UFS 3.1"; - } else if (output2.contains("300", Qt::CaseInsensitive)) { - m_Interface = "UFS 3.0"; + QString output = file.readAll(); + if (!output.isEmpty()) { + m_Interface = "UFS"; } file.close(); } diff --git a/deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp b/deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp index f7f661ce..d3ab7ade 100644 --- a/deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp +++ b/deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp @@ -26,18 +26,7 @@ void CustomGenerator::generatorGpuDevice() return; } - QStringList arguments; - QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - QString display = env.value("DISPLAY"); - QString xauthority = env.value("XAUTHORITY"); - if (display.isEmpty() || xauthority.isEmpty()) { - qWarning() << "DISPLAY or XAUTHORITY is not set!"; - } else { - arguments << display << xauthority; - } - - QString tmpGpuInfo; - DBusInterface::getInstance()->getGpuInfoByCustom(cmd, arguments, tmpGpuInfo); + QString tmpGpuInfo = CommonTools::preGenerateGpuInfo(); if (tmpGpuInfo.isEmpty()) { qCritical() << "Failed to get gpu info by commad " << cmd; return; diff --git a/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp b/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp index cf2640d4..36518168 100644 --- a/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp +++ b/deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp @@ -1097,7 +1097,7 @@ void DeviceGenerator::getKeyboardInfoFromHwinfo() DeviceInput *device = new DeviceInput(); device->setInfoFromHwinfo(*it); device->setHardwareClass("keyboard"); - device->setCanEnale(false); + device->setCanEnable(false); DeviceManager::instance()->addKeyboardDevice(device); addBusIDFromHwinfo((*it)["SysFS BusID"]); } diff --git a/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp b/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp index cf817199..2df5fa20 100644 --- a/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp +++ b/deepin-devicemanager/src/GenerateDevice/HWGenerator.cpp @@ -311,7 +311,7 @@ void HWGenerator::generatorDiskDevice() tempMap["Name"] = "nouse"; if (Common::specialComType == 2) { - tempMap["Interface"] = "UFS 3.1"; + tempMap["Interface"] = "UFS"; } // 读取interface版本 @@ -327,10 +327,10 @@ void HWGenerator::generatorDiskDevice() exitCode = process.exitCode(); if (exitCode != 127 && exitCode != 126) { deviceInfo = process.readAllStandardOutput(); - if (deviceInfo.trimmed() == "310") { - tempMap["interface"] = "UFS 3.1"; - } else if (deviceInfo.trimmed() == "300") - tempMap["interface"] = "UFS 3.0"; + + if (!deviceInfo.trimmed().isEmpty()) { + tempMap["interface"] = "UFS"; + } } } } @@ -366,7 +366,7 @@ void HWGenerator::getAudioInfoFromCatAudio() } DeviceAudio *device = new DeviceAudio(); - device->setCanEnale(false); + device->setCanEnable(false); device->setCanUninstall(false); device->setForcedDisplay(true); device->setInfoFromCatAudio(tempMap); @@ -387,7 +387,7 @@ void HWGenerator::getBluetoothInfoFromHciconfig() continue; } DeviceBluetooth *device = new DeviceBluetooth(); - device->setCanEnale(false); + device->setCanEnable(false); device->setForcedDisplay(true); device->setInfoFromHciconfig(*it); DeviceManager::instance()->addBluetoothDevice(device); diff --git a/deepin-devicemanager/src/Tool/EDIDParser.cpp b/deepin-devicemanager/src/Tool/EDIDParser.cpp index 5a102378..f209bffb 100644 --- a/deepin-devicemanager/src/Tool/EDIDParser.cpp +++ b/deepin-devicemanager/src/Tool/EDIDParser.cpp @@ -82,7 +82,8 @@ bool EDIDParser::setEdid(const QString &edid, QString &errorMsg, const QString & // 解析厂商信息 qCDebug(appLog) << "Parsing vendor info"; - parserVendor(); + parseVendor(); + // 解析发布日期 qCDebug(appLog) << "Parsing release date"; parseReleaseDate(); @@ -136,7 +137,7 @@ int EDIDParser::height() return m_Height; } -void EDIDParser::parserVendor() +void EDIDParser::parseVendor() { qCDebug(appLog) << "Parsing vendor info from EDID"; diff --git a/deepin-devicemanager/src/Tool/EDIDParser.h b/deepin-devicemanager/src/Tool/EDIDParser.h index 2287fdbf..2d1b810c 100644 --- a/deepin-devicemanager/src/Tool/EDIDParser.h +++ b/deepin-devicemanager/src/Tool/EDIDParser.h @@ -66,16 +66,16 @@ class EDIDParser /** * @brief height : get screen height - * @return + * @return screen height */ int height(); private: /** - * @brief parserVendor:从edid中获取厂商信息 + * @brief parseVendor:从edid中获取厂商信息 */ - void parserVendor(); + void parseVendor(); /** * @brief parseReleaseDate:从edid中获取发布日期 @@ -154,7 +154,7 @@ class EDIDParser QString m_MonitorName; // 监视器名称 bool m_LittleEndianMode; // 小端模式 int m_Width; // width - int m_Height; // heigth + int m_Height; // height QStringList m_ListEdid; // edid数据 QMap m_MapCh; // 二进制字符串映射到字母A-Z diff --git a/deepin-devicemanager/src/Tool/commontools.cpp b/deepin-devicemanager/src/Tool/commontools.cpp index e0ace08d..90ca0476 100644 --- a/deepin-devicemanager/src/Tool/commontools.cpp +++ b/deepin-devicemanager/src/Tool/commontools.cpp @@ -22,6 +22,14 @@ using namespace DDLog; #define ICON_SIZE_WIDTH 36 #define ICON_SIZE_HEIGHT 36 +// 名称("Name") 厂商("Vendor") 型号("Model") 版本(Version) 显存("Graphics Memory") + +constexpr char kName[] { "Name" }; +constexpr char kVendor[] { "Vendor" }; +constexpr char kModel[] { "Model" }; +constexpr char kVersion[] { "Version" }; +constexpr char kGraphicsMemory[] { "Graphics Memory" }; + QMap CommonTools::m_MapDriverIcon = { {DR_Bluetooth, QString(":/icons/deepin/builtin/icons/bluetooth.svg")} , {DR_Camera, QString(":/icons/deepin/builtin/icons/image.svg")} @@ -274,3 +282,74 @@ QString CommonTools::getGpuInfoCommandFromDConfig() cmd = dconfig->value("CommandToGetGPUInfo").toString(); return cmd; } + +QString CommonTools::preGenerateGpuInfo() +{ + static QString gpuInfo { "" }; + + if (gpuInfo.isEmpty()) { + QStringList arguments; + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + QString display = env.value("DISPLAY"); + QString xauthority = env.value("XAUTHORITY"); + if (display.isEmpty() || xauthority.isEmpty()) { + qCritical() << "DISPLAY or XAUTHORITY is not set!"; + } else { + arguments << display << xauthority; + } + + QDBusInterface iface("org.deepin.DeviceInfo", + "/org/deepin/DeviceInfo", + "org.deepin.DeviceInfo", + QDBusConnection::systemBus()); + if (iface.isValid()) { + QDBusReply replyList = iface.call("getGpuInfoByCustom", arguments, gpuInfo); + if (replyList.isValid()) { + gpuInfo = replyList.value(); + } else { + qCritical() << "Error: failed to call dbus to get gpu memery info! "; + } + } + + QMap mapInfo; + if (getGpuBaseInfo(mapInfo)) { + for (auto it = mapInfo.begin(); it != mapInfo.end(); ++it) { + QString tmpInfo = it.key() + ": " + it.value() + "\n"; + gpuInfo.append(tmpInfo); + } + } + } + + return gpuInfo; +} + +bool CommonTools::getGpuBaseInfo(QMap &mapInfo) +{ + QProcess process; + QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); + process.setProcessEnvironment(env); + process.start("/usr/bin/glxinfo", QStringList() << "-B"); + if (!process.waitForFinished()) { + qCritical() << "Error executing glxinfo:" << process.errorString(); + return false; + } + + QString output = QString::fromLocal8Bit(process.readAllStandardOutput()); + QStringList lines = output.split('\n'); + QRegularExpression regex("^([^:]+):\\s*(.+)$"); + for (const QString &line : lines) { + QRegularExpressionMatch match = regex.match(line); + if (match.hasMatch()) { + QString key = match.captured(1).trimmed(); + QString value = match.captured(2).trimmed(); + if (key == "OpenGL renderer string") { + mapInfo.insert(kName, value); + mapInfo.insert(kModel, value); + } else if (key == "OpenGL vendor string") { + mapInfo.insert(kVendor, value); + } + } + } + + return true; +} diff --git a/deepin-devicemanager/src/Tool/commontools.h b/deepin-devicemanager/src/Tool/commontools.h index c92a905d..915d5f99 100644 --- a/deepin-devicemanager/src/Tool/commontools.h +++ b/deepin-devicemanager/src/Tool/commontools.h @@ -80,6 +80,10 @@ class CommonTools : public QObject static void parseEDID(const QStringList &allEDIDS, const QString &input, bool isHW = true); static QString getGpuInfoCommandFromDConfig(); + static QString preGenerateGpuInfo(); + +private: + static bool getGpuBaseInfo(QMap &mapInfo); signals: diff --git a/deepin-devicemanager/src/main.cpp b/deepin-devicemanager/src/main.cpp index 80d28f1e..5435be93 100644 --- a/deepin-devicemanager/src/main.cpp +++ b/deepin-devicemanager/src/main.cpp @@ -13,6 +13,8 @@ #include "DebugTimeManager.h" #include "SingleDeviceManager.h" #include "DDLog.h" +#include "commontools.h" + #include #include #include @@ -133,6 +135,12 @@ int main(int argc, char *argv[]) qCDebug(appLog) << "DBus service registered successfully"; dbus.registerObject("/com/deepin/DeviceManagerNotify", &app, QDBusConnection::ExportScriptableSlots); app.parseCmdLine(); + + QString cmd = CommonTools::getGpuInfoCommandFromDConfig(); + if (!cmd.isEmpty()) { + CommonTools::preGenerateGpuInfo(); + } + app.activateWindow(); return app.exec(); } else {