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
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
// SPDX-FileCopyrightText: 2019 ~ 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "deviceinterface.h"
#include "deviceinfomanager.h"
#include "mainjob.h"

Check warning on line 6 in deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QDBusConnection>
#include <QDBusMessage>

Check warning on line 10 in deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 11 in deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 13 in deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 14 in deepin-devicemanager-server/deepin-deviceinfo/src/loadinfo/deviceinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <polkit-qt5-1/PolkitQt1/Authority>
#else
#include <polkit-qt6-1/PolkitQt1/Authority>
#endif

using namespace DDLog;
constexpr char kGraphicsMemory[] { "Graphics Memory" };

using namespace PolkitQt1;
bool DeviceInterface::getUserAuthorPasswd()
{
Expand All @@ -30,6 +34,52 @@
return result == Authority::Yes;
}

bool DeviceInterface::getGpuMemInfoForFTDTM(QMap<QString, QString> &mapInfo)
{
const QString filePath = "/sys/kernel/debug/gc/total_mem";
QString totalValue;

QFile file(filePath);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qCritical() << "Error opening /sys/kernel/debug/gc/total_mem:" << file.errorString();
return false;
}

QString content = QString::fromUtf8(file.readAll());
file.close();

if (content.isEmpty()) {
qCritical() << "Error: /sys/kernel/debug/gc/total_mem File is empty!";
return false;
}

QRegularExpression regex(R"((\d+(?:\.\d+)?)\s*\(?(MB|GB|KB|B)\)?)",
QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch memInfoMatch = regex.match(content);

if (!memInfoMatch.hasMatch()) {
qCritical() << "Error: Failed to find memory info";
return false;
}

double value = memInfoMatch.captured(1).toDouble();
QString unit = memInfoMatch.captured(2).toUpper();

if (unit == "MB") {
totalValue = QString("%1GB").arg(value / 1024.0, 0, 'f', 2);
} else if (unit == "GB") {
totalValue = QString("%1GB").arg(value, 0, 'f', 2);
} else if (unit == "KB") {
totalValue = QString("%1GB").arg(value / (1024.0 * 1024.0), 0, 'f', 2);
} else if (unit == "B") {
totalValue = QString("%1GB").arg(value / (1024.0 * 1024.0 * 1024.0), 0, 'f', 2);
}

mapInfo.insert(kGraphicsMemory, totalValue);

return true;
}

DeviceInterface::DeviceInterface(const char *name, QObject *parent)
: QObject(parent)
{
Expand Down Expand Up @@ -91,24 +141,17 @@
}
}

QString DeviceInterface::getGpuInfoByCustom(const QString &cmd, const QStringList &arguments)
QString DeviceInterface::getGpuInfoForFTDTM()
{
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;
static QString gpuMemInfo { "" };
if (gpuMemInfo.isEmpty()) {
QMap<QString, QString> mapInfo;
if (getGpuMemInfoForFTDTM(mapInfo)) {
for (auto it = mapInfo.begin(); it != mapInfo.end(); ++it) {
QString tmpInfo = it.key() + ": " + it.value() + "\n";
gpuMemInfo.append(tmpInfo);
}
}
}

if (process.exitCode() == 0)
gpuinfo = QString::fromLocal8Bit(process.readAllStandardOutput());

return gpuinfo;
return gpuMemInfo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ public slots:
*/
Q_SCRIPTABLE void setMonitorDeviceFlag(bool flag);

Q_SCRIPTABLE QString getGpuInfoByCustom(const QString &cmd, const QStringList &arguments);
Q_SCRIPTABLE QString getGpuInfoForFTDTM();

private:
bool getUserAuthorPasswd();
bool getGpuMemInfoForFTDTM(QMap<QString, QString> &mapInfo);
};

#endif // DEVICEINTERFACE_H
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/DeviceManager/DeviceCpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void DeviceCpu::setInfoFromDmidecode(const QMap<QString, QString> &mapInfo)
setAttribute(mapInfo, "product", m_Name);
}

if (Common::specialComType > 0) {
if (Common::isHwPlatform()) {
if (mapInfo.contains("Version")) {
setAttribute(mapInfo, "Version", m_Name);
}
Expand Down
11 changes: 5 additions & 6 deletions deepin-devicemanager/src/DeviceManager/DeviceInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,12 @@
}
if(e){
//鼠标启用时,唤醒能力打开
DBusWakeupInterface::getInstance()->setWakeupMachine(wakeupID(), sysPath(), true, name());
DBusWakeupInterface::getInstance()->setWakeupMachine(wakeupID(), sysPath(), true, name(), m_HardwareClass);
m_wakeupChanged = true;

} else if (m_wakeupChanged) { //鼠标禁用时,唤醒能力关闭
m_wakeupChanged = false;
DBusWakeupInterface::getInstance()->setWakeupMachine(wakeupID(), sysPath(), false, name());
DBusWakeupInterface::getInstance()->setWakeupMachine(wakeupID(), sysPath(), false, name(), m_HardwareClass);
}
bool res = DBusEnableInterface::getInstance()->enable(m_HardwareClass, m_Name, m_SysPath, m_UniqueID, e, m_Driver);
if (res) {
Expand All @@ -584,13 +584,12 @@
return m_Enable;
}

bool DeviceInput::canWakeupMachine()

Check warning on line 587 in deepin-devicemanager/src/DeviceManager/DeviceInput.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'canWakeupMachine' is never used.
{
qCDebug(appLog) << "canWakeupMachine";
if (m_WakeupID.isEmpty() || (m_HardwareClass == "keyboard" && "PS/2" == m_Interface)) {
qCDebug(appLog) << "canWakeupMachine return false";
if (m_WakeupID.isEmpty())
return false;
}

QFile file(wakeupPath());
if (!file.open(QIODevice::ReadOnly)) {
qCDebug(appLog) << "canWakeupMachine open file failed";
Expand Down Expand Up @@ -618,7 +617,7 @@
// }
qCDebug(appLog) << "return ps2 wakeup";
// /proc/acpi/wakeup文件中状态未刷新,ps2设备通过dbus获取状态
return DBusWakeupInterface::getInstance()->isInputWakeupMachine(m_SysPath, m_Name);
return DBusWakeupInterface::getInstance()->isInputWakeupMachine(m_SysPath, m_Name, m_HardwareClass, m_Interface);

} else {
if (info.contains("disabled")) {
Expand Down
8 changes: 4 additions & 4 deletions deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void DeviceMonitor::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
setAttribute(mapInfo, "", m_DisplayInput);
setAttribute(mapInfo, "Size", m_ScreenSize);
setAttribute(mapInfo, "", m_MainScreen);
if (Common::specialComType > 0){
if (Common::isHwPlatform()){
setAttribute(mapInfo, "Resolution", m_SupportResolution);
}
qCDebug(appLog) << "Basic monitor attributes set - Name:" << m_Name << "Vendor:" << m_Vendor << "Model:" << m_Model;
Expand All @@ -149,7 +149,7 @@ void DeviceMonitor::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
qCDebug(appLog) << "Screen size parsed:" << m_ScreenSize << "Width:" << size.width() << "Height:" << size.height();

// 获取当前分辨率 和 当前支持分辨率
if (Common::specialComType > 0){
if (Common::isHwPlatform()){
QStringList listResolution = m_SupportResolution.split(" ");
m_SupportResolution = "";
foreach (const QString &word, listResolution) {
Expand All @@ -163,7 +163,7 @@ void DeviceMonitor::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
// 计算显示比例
caculateScreenRatio();

if (Common::specialComType > 0){
if (Common::isHwPlatform()){
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_SupportResolution.replace(QRegExp(", $"), "");
#else
Expand Down Expand Up @@ -386,7 +386,7 @@ bool DeviceMonitor::available()
QString DeviceMonitor::subTitle()
{
// qCDebug(appLog) << "Getting monitor subtitle";
if (Common::specialComType >= 1) {
if (Common::isHwPlatform()) {
m_Name.clear();
}
return m_Name;
Expand Down
8 changes: 8 additions & 0 deletions deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@
return m_MACAddress;
}

bool DeviceNetwork::canDisable()

Check warning on line 286 in deepin-devicemanager/src/DeviceManager/DeviceNetwork.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'canDisable' is never used.
{
if (m_SysPath.isEmpty()) {
return false;
}
return true;
}

void DeviceNetwork::initFilterKey()
{
qCDebug(appLog) << "DeviceNetwork::initFilterKey";
Expand Down
2 changes: 2 additions & 0 deletions deepin-devicemanager/src/DeviceManager/DeviceNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class DeviceNetwork : public DeviceBaseInfo
*/
QString hwAddress();

bool canDisable();

protected:

/**
Expand Down
8 changes: 1 addition & 7 deletions deepin-devicemanager/src/GenerateDevice/CustomGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ CustomGenerator::CustomGenerator(QObject *parent)

void CustomGenerator::generatorGpuDevice()
{
QString cmd = CommonTools::getGpuInfoCommandFromDConfig();
if (cmd.isEmpty()) {
DeviceGenerator::generatorGpuDevice();
return;
}

QString tmpGpuInfo = CommonTools::preGenerateGpuInfo();
if (tmpGpuInfo.isEmpty()) {
qCritical() << "Failed to get gpu info by commad " << cmd;
qCritical() << "Error: Failed to get gpu info!";
return;
}

Expand Down
12 changes: 0 additions & 12 deletions deepin-devicemanager/src/GenerateDevice/DBusInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ void DBusInterface::refreshInfo()
mp_Iface->asyncCall("refreshInfo");
}

bool DBusInterface::getGpuInfoByCustom(const QString &cmd, const QStringList &arguments, QString &gpuInfo)
{
QDBusReply<QString> replyList = mp_Iface->call("getGpuInfoByCustom", cmd, arguments);
if (replyList.isValid()) {
gpuInfo = replyList.value();
return true;
} else {
qCritical() << "Error: failed to call dbus to get gpu memery info! ";
return false;
}
}

void DBusInterface::init()
{
qCDebug(appLog) << "DBusInterface::init start";
Expand Down
2 changes: 0 additions & 2 deletions deepin-devicemanager/src/GenerateDevice/DBusInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ class DBusInterface
*/
void refreshInfo();

bool getGpuInfoByCustom(const QString &cmd, const QStringList &arguments, QString &gpuInfo);

protected:
DBusInterface();

Expand Down
13 changes: 0 additions & 13 deletions deepin-devicemanager/src/Page/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,19 +477,6 @@ void MainWindow::initWindowTitle()
}
});
titlebar()->addWidget(mp_ButtonBox);
#ifdef DTKCORE_CLASS_DConfigFile
//需要查询是否支持特殊机型静音恢复,例如hw机型
DConfig *dconfig = DConfig::create("org.deepin.devicemanager","org.deepin.devicemanager");
//需要判断Dconfig文件是否合法
if(dconfig && dconfig->isValid() && dconfig->keyList().contains("specialComType")){
Common::specialComType = dconfig->value("specialComType").toInt();
}
qCInfo(appLog) << "Common::specialComType value is:" << Common::specialComType;
if (dconfig && dconfig->isValid() && dconfig->keyList().contains("TomlFilesName")) {
QString tomlFilesName = dconfig->value("TomlFilesName").toString();
Common::tomlFilesNameSet(tomlFilesName);
}
#endif
// 特殊处理
if (!Common::boardVendorType().isEmpty())
mp_ButtonBox->hide();
Expand Down
17 changes: 10 additions & 7 deletions deepin-devicemanager/src/Page/PageMultiInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void PageMultiInfo::updateInfo(const QList<DeviceBaseInfo *> &lst)
mp_Table->setVisible(true);
mp_Table->setFixedHeight(TABLE_HEIGHT);
mp_Table->updateTable(m_deviceList, m_menuControlList);
if (Common::specialComType >= 1) {
if (Common::isHwPlatform()) {
if (mp_Label->text() == tr("Storage") || mp_Label->text() == tr("Memory") || mp_Label->text() == tr("Monitor")) {
mp_Table->setVisible(false);
mp_Table->setFixedHeight(0);
Expand Down Expand Up @@ -148,20 +148,20 @@ void PageMultiInfo::resizeEvent(QResizeEvent *e)
if (curHeight < LEAST_PAGE_HEIGHT) {
qCDebug(appLog) << "Height too small, resize table";
// 获取多个设备界面表格信息
if (Common::specialComType <= 0) {
mp_Table->updateTable(m_deviceList, m_menuControlList, true, (LEAST_PAGE_HEIGHT - curHeight) / TREE_ROW_HEIGHT + 1);
} else {
if (Common::isHwPlatform()) {
if (mp_Label->text() != tr("Storage") && mp_Label->text() != tr("Memory") && mp_Label->text() != tr("Monitor"))
mp_Table->updateTable(m_deviceList, m_menuControlList, true, (LEAST_PAGE_HEIGHT - curHeight) / TREE_ROW_HEIGHT + 1);
} else {
mp_Table->updateTable(m_deviceList, m_menuControlList, true, (LEAST_PAGE_HEIGHT - curHeight) / TREE_ROW_HEIGHT + 1);
}
} else {
qCDebug(appLog) << "Height is enough, resize table";
// 获取多个设备界面表格信息
if (Common::specialComType <= 0) {
mp_Table->updateTable(m_deviceList, m_menuControlList, true, 0);
} else {
if (Common::isHwPlatform()) {
if (mp_Label->text() != tr("Storage") && mp_Label->text() != tr("Memory") && mp_Label->text() != tr("Monitor"))
mp_Table->updateTable(m_deviceList, m_menuControlList, true, 0);
} else {
mp_Table->updateTable(m_deviceList, m_menuControlList, true, 0);
}
}

Expand Down Expand Up @@ -322,12 +322,15 @@ void PageMultiInfo::getTableListInfo(const QList<DeviceBaseInfo *> &lst, QList<Q
if (info->name().contains("PS/2")) {
menuControl.append(input->getBusInfo());
menuControl.append(input->name());
menuControl.append(input->hardwareClass());
menuControl.append(input->getInterface());
}
}

DeviceNetwork *network = dynamic_cast<DeviceNetwork *>(info);
if (network) {
menuControl.append(network->logicalName());
menuControl.append(network->canDisable() ? "true" : "false");
}

menuControlList.append(menuControl);
Expand Down
7 changes: 6 additions & 1 deletion deepin-devicemanager/src/Page/PageSingleInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,10 @@ void PageSingleInfo::slotShowMenu(const QPoint &)
qCDebug(appLog) << "Device is disabled, disabling wakeup action.";
}
mp_Menu->addAction(mp_WakeupMachine);

// 根据网卡情况判断是否支持禁用
if (!network->canDisable())
mp_Menu->removeAction(mp_Enable);
}

mp_Menu->exec(QCursor::pos());
Expand Down Expand Up @@ -412,7 +416,8 @@ void PageSingleInfo::slotWakeupMachine()
DBusWakeupInterface::getInstance()->setWakeupMachine(input->wakeupID(),
input->sysPath(),
mp_WakeupMachine->isChecked(),
input->getInterface());
input->getInterface(),
input->hardwareClass());
}

// 网卡的远程唤醒
Expand Down
9 changes: 8 additions & 1 deletion deepin-devicemanager/src/Tool/EDIDParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

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

Check warning on line 7 in deepin-devicemanager/src/Tool/EDIDParser.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 8 in deepin-devicemanager/src/Tool/EDIDParser.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "commonfunction.h" not found.

// Qt库文件
#include<QLoggingCategory>
Expand Down Expand Up @@ -241,8 +242,14 @@
}
}

if (Common::specialComType == Common::kSpecialType7){ // sepcial task:378963
m_Width = 296;
m_Height = 197;
}
double inch = sqrt((m_Width / 2.54) * (m_Width / 2.54) + (m_Height / 2.54) * (m_Height / 2.54))/10;
m_ScreenSize = QString("%1 %2(%3mm×%4mm)").arg(QString::number(inch, '0', 1)).arg(QObject::tr("inch")).arg(m_Width).arg(m_Height);
m_ScreenSize = QString("%1 %2(%3mm×%4mm)")
.arg(QString::number(inch, '0', Common::specialComType == Common::kSpecialType7 ? 0 : 1))
.arg(QObject::tr("inch")).arg(m_Width).arg(m_Height);
qCDebug(appLog) << "Screen size parsed:" << m_ScreenSize << "Width:" << m_Width << "Height:" << m_Height;
}

Expand Down
Loading