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
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDISABLE_POLKIT)
endif()

# 设置 QT_VERSION 变量
set(QT_VERSION_MAJOR 6)
# 自动检测系统中的Qt版本
if(NOT DEFINED QT_VERSION_MAJOR)
# 首先尝试查找Qt6
find_package(Qt6 QUIET)
if(Qt6_FOUND)
set(QT_VERSION_MAJOR 6)
message("Found Qt6, using Qt version 6")
else()
set(QT_VERSION_MAJOR 5)
message("Found Qt5, using Qt version 5")
endif()
else()
message("Using manually specified QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}")
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-z,relro -Wl,-z,now")

Expand All @@ -28,4 +40,4 @@ add_subdirectory(${CMAKE_SOURCE_DIR}/deepin-devicemanager-server)
if(CMAKE_COVERAGE_ARG STREQUAL "CMAKE_COVERAGE_ARG_ON")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage")
endif()
endif()
9 changes: 4 additions & 5 deletions deepin-devicemanager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,18 @@ SET_QT_VERSION()

if(${QT_VERSION_MAJOR} EQUAL 6)
find_package(QApt-qt6 REQUIRED)
include_directories(${QApt-qt6_INCLUDE_DIRS})
include_directories(${QApt-qt6_INCLUDE_DIRS})
include_directories(${Qt6Gui_PRIVATE_INCLUDE_DIRS})
set(QAPT_LIB QApt-qt6)
elseif(${QT_VERSION_MAJOR} EQUAL 5)
find_package(QApt REQUIRED)
include_directories(${QApt_INCLUDE_DIRS})
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
set(QAPT_LIB QApt)
else()
message(FATAL_ERROR "Unsupported QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}")
endif()

#include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
include_directories(${Qt6Gui_PRIVATE_INCLUDE_DIRS})

# Tell CMake to create the executable
add_executable(${PROJECT_NAME} ${SRC_CPP} ${SRC_H} ${APP_QRC})
target_include_directories(${APP_BIN_NAME} PUBLIC ${DtkWidget_INCLUDE_DIRS} ${OBJECT_BINARY_DIR})
Expand Down Expand Up @@ -222,4 +221,4 @@ endif()
# Test--------deepin-devicemanager
if (CMAKE_COVERAGE_ARG STREQUAL "CMAKE_COVERAGE_ARG_ON")
add_subdirectory(./tests)
endif()
endif()
22 changes: 1 addition & 21 deletions deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,8 @@
return QString("");
}

foreach (QString out, outInfo.split("\n")) {

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

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'out' is used to iterate by value. It could be declared as a const reference which is usually faster and recommended in C++.
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList item = out.split(":", QString::SkipEmptyParts);
#else
QStringList item = out.split(":", Qt::SkipEmptyParts);
#endif
QStringList item = out.split(":", QT_SKIP_EMPTY_PARTS);
if (!item.isEmpty() && "version" == item[0].trimmed()) {
// qCDebug(appLog) << "Found driver version: " << item[1].trimmed();
return item[1].trimmed();
Expand Down Expand Up @@ -1077,7 +1073,6 @@
<< "o" << "p" << "q" << "r" << "s" << "t"
<< "u" << "v" << "w" << "x" << "y" << "z";

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QRegularExpression reg("([0-9a-zA-Z]+)-([0-9a-zA-Z]+)\\.([0-9a-zA-Z]+)");
QRegularExpressionMatch match = reg.match(words[0]);
if (match.hasMatch()) {
Expand All @@ -1086,27 +1081,12 @@
int third = match.captured(3).toInt();
m_HwinfoToLshw = QString("usb@%1:%2.%3").arg(nums.at(first)).arg(nums.at(second)).arg(nums.at(third));
qCDebug(appLog) << "DeviceBaseInfo::setHwinfoLshwKey match";
} else {
int first = chs[0].toInt();
int second = chs[1].toInt();
m_HwinfoToLshw = QString("usb@%1:%2").arg(nums.at(first)).arg(nums.at(second));
qCDebug(appLog) << "DeviceBaseInfo::setHwinfoLshwKey not match";
}
#else
QRegExp reg("([0-9a-zA-Z]+)-([0-9a-zA-Z]+)\\.([0-9a-zA-Z]+)");
if (reg.exactMatch(words[0])) {
int first = reg.cap(1).toInt();
int second = reg.cap(2).toInt();
int third = reg.cap(3).toInt();
m_HwinfoToLshw = QString("usb@%1:%2.%3").arg(nums.at(first)).arg(nums.at(second)).arg(nums.at(third));
qCDebug(appLog) << "DeviceBaseInfo::setHwinfoLshwKey match";
} else {
int first = chs[0].toInt();
int second = chs[1].toInt();
m_HwinfoToLshw = QString("usb@%1:%2").arg(nums.at(first)).arg(nums.at(second));
qCDebug(appLog) << "DeviceBaseInfo::setHwinfoLshwKey no match";
}
#endif
}

bool DeviceBaseInfo::matchToLshw(const QMap<QString, QString> &mapInfo)
Expand Down
38 changes: 0 additions & 38 deletions deepin-devicemanager/src/DeviceManager/DeviceInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,35 +233,17 @@ bool DeviceInput::getPS2Syspath(const QString &dfs)
// qCDebug(appLog) << "Found sysfs line: " << sysfs;
continue;
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRegExp reg("H: Handlers=.*(event[0-9]{1,2}).*");
if (reg.exactMatch(line)) {
event = reg.cap(1);
// qCDebug(appLog) << "Matched event using QRegExp: " << event;
}
#else
QRegularExpression reg("H: Handlers=.*(event[0-9]{1,2}).*");
QRegularExpressionMatch match = reg.match(line);
if (match.hasMatch()) {
event = match.captured(1);
// qCDebug(appLog) << "Matched event using QRegularExpression: " << event;
}
#endif
}

if (!event.isEmpty() && !sysfs.isEmpty()) {
// qCDebug(appLog) << "Event and sysfs are not empty. Checking for match.";
if (event == eventdfs) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRegExp regfs;
if (sysfs.contains("i2c_designware"))
regfs = QRegExp("S: Sysfs=(.*)/input/input[0-9]{1,2}");
else
regfs = QRegExp("S: Sysfs=(.*)/input[0-9]{1,2}");
if (regfs.exactMatch(sysfs)) {
m_SysPath = regfs.cap(1);
}
#else
QRegularExpression regfs;
if (sysfs.contains("i2c_designware"))
regfs = QRegularExpression("S: Sysfs=(.*)/input/input[0-9]{1,2}");
Expand All @@ -271,7 +253,6 @@ bool DeviceInput::getPS2Syspath(const QString &dfs)
if (match.hasMatch()) {
m_SysPath = match.captured(1);
}
#endif
}
}
}
Expand Down Expand Up @@ -307,31 +288,18 @@ bool DeviceInput::isBluetoothDevice(const QString &dfs)
Uniq = line;
continue;
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRegExp reg("H: Handlers=.*(event[0-9]{1,2}).*");
if (reg.exactMatch(line)) {
event = reg.cap(1);
}
#else
QRegularExpression reg("H: Handlers=.*(event[0-9]{1,2}).*");
QRegularExpressionMatch match = reg.match(line);
if (match.hasMatch()) {
event = match.captured(1);
}
#endif
}

if (event == eventdfs) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRegExp regUniq(".*([0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}).*");
if (regUniq.exactMatch(Uniq)) {
QString id = regUniq.cap(1);
#else
QRegularExpression regUniq(".*([0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}:[0-9A-Z]{2}).*");
QRegularExpressionMatch match = regUniq.match(Uniq);
if (match.hasMatch()) {
QString id = match.captured(1);
#endif
QProcess process;
process.start("hcitool con");
process.waitForFinished(-1);
Expand All @@ -352,16 +320,10 @@ bool DeviceInput::isBluetoothDevice(const QString &dfs)
QString DeviceInput::eventStrFromDeviceFiles(const QString &dfs)
{
qCDebug(appLog) << "eventStrFromDeviceFiles";
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QRegularExpression regdfs(".*(event[0-9]{1,2}).*");
QRegularExpressionMatch match = regdfs.match(dfs);
if (match.hasMatch())
return match.captured(1);
#else
QRegExp regdfs(".*(event[0-9]{1,2}).*");
if (regdfs.exactMatch(dfs))
return regdfs.cap(1);
#endif
qCDebug(appLog) << "eventStrFromDeviceFiles end";
return "";
}
Expand Down
4 changes: 0 additions & 4 deletions deepin-devicemanager/src/DeviceManager/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,14 +1361,10 @@
{
qCDebug(appLog) << "Getting audio device with path:" << path;
for (QList<DeviceBaseInfo *>::iterator it = m_ListDeviceAudio.begin(); it != m_ListDeviceAudio.end(); ++it) {
DeviceAudio *audio = dynamic_cast<DeviceAudio *>(*it);

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

View workflow job for this annotation

GitHub Actions / cppcheck

Variable 'audio' can be declared as pointer to const
QString tpath = audio->uniqueID();
// 判断该设备是否已经存在,1.1:1.1 -> 1.1:1.0
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (audio && path == tpath.replace(QRegExp("[1-9]$"), "0")) {
#else
if (audio && path == tpath.replace(QRegularExpression("[1-9]$"), "0")) {

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

View workflow job for this annotation

GitHub Actions / cppcheck

Either the condition 'audio' is redundant or there is possible null pointer dereference: audio.
#endif
return *it;
}
QString syspath = audio->sysPath(); //remove dumplicate syspath
Expand Down
54 changes: 7 additions & 47 deletions deepin-devicemanager/src/DeviceManager/DeviceMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,48 +56,16 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double &
// 根据不同的正则表达式解析屏幕大小字符串
QString res = sizeDescription;

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRegExp re("^([\\d]*)x([\\d]*) mm$");
if (re.exactMatch(sizeDescription)) {
qCDebug(appLog) << "Matched size description with format: ^([\\d]*)x([\\d]*) mm$";
// 获取屏幕宽高 int
m_Width = re.cap(1).toInt();
m_Height = re.cap(2).toInt();
retSize = QSize(m_Width, m_Height);

// 获取屏幕尺寸大小 inch
double width = m_Width / 2.54;
double height = m_Height / 2.54;
inch = std::sqrt(width * width + height * height) / 10.0;
res = QString::number(inch, 10, 1) + " " + translateStr("inch") + " (";
res += sizeDescription;
res += ")";
}

re.setPattern("([0-9]\\d*)mm x ([0-9]\\d*)mm");
if (re.exactMatch(sizeDescription)) {
qCDebug(appLog) << "Matched size description with format: ([0-9]\\d*)mm x ([0-9]\\d*)mm";
// 获取屏幕宽高 int
m_Width = re.cap(1).toInt();
m_Height = re.cap(2).toInt();
retSize = QSize(m_Width, m_Height);

double width = m_Width / 2.54;
double height = m_Height / 2.54;
inch = std::sqrt(width * width + height * height) / 10.0;
res = QString::number(inch, 10, 1) + " " + translateStr("inch") + " (";
res += sizeDescription;
res += ")";
}
#else
QRegularExpression re("^([\\d]*)x([\\d]*) mm$");
QRegularExpressionMatch match = re.match(sizeDescription);
if (match.hasMatch()) {
qCDebug(appLog) << "Matched size description with format: ^([\\d]*)x([\\d]*) mm$";
// 获取屏幕宽高 int
m_Width = match.captured(1).toInt();
m_Height = match.captured(2).toInt();
retSize = QSize(m_Width, m_Height);

// 获取屏幕尺寸大小 inch
double width = m_Width / 2.54;
double height = m_Height / 2.54;
inch = std::sqrt(width * width + height * height) / 10.0;
Expand All @@ -110,6 +78,7 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double &
match = re.match(sizeDescription);
if (match.hasMatch()) {
qCDebug(appLog) << "Matched size description with format: ([0-9]\\d*)mm x ([0-9]\\d*)mm";
// 获取屏幕宽高 int
m_Width = match.captured(1).toInt();
m_Height = match.captured(2).toInt();
retSize = QSize(m_Width, m_Height);
Expand All @@ -121,7 +90,6 @@ QString DeviceMonitor::parseMonitorSize(const QString &sizeDescription, double &
res += sizeDescription;
res += ")";
}
#endif

qCDebug(appLog) << "Finished parsing monitor size. Result:" << res;
return res;
Expand Down Expand Up @@ -164,11 +132,7 @@ void DeviceMonitor::setInfoFromHwinfo(const QMap<QString, QString> &mapInfo)
caculateScreenRatio();

if (Common::isHwPlatform()){
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_SupportResolution.replace(QRegExp(", $"), "");
#else
m_SupportResolution.replace(QRegularExpression(", $"), "");
#endif
}
qCDebug(appLog) << "Supported resolutions processed:" << m_SupportResolution;

Expand Down Expand Up @@ -288,7 +252,7 @@ bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, c
// 设置当前分辨率
if (m_CurrentResolution.isEmpty()) {
qCDebug(appLog) << "Current resolution is empty, extracting from main string";
QRegularExpression reScreenSize(".*([0-9]{1,5}x[0-9]{1,5}).*");
QRegularExpression reScreenSize(".*connected.*\\s([0-9]{1,5}x[0-9]{1,5})\\+.*");
QRegularExpressionMatch match = reScreenSize.match(main);
if (match.hasMatch()) {
qCDebug(appLog) << "Matched screen size from main string:" << match.captured(1);
Expand Down Expand Up @@ -320,11 +284,7 @@ bool DeviceMonitor::setInfoFromXradr(const QString &main, const QString &edid, c
m_SupportResolution.append(", ");
}
}
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_SupportResolution.remove(QRegExp(", $"));
#else
m_SupportResolution.remove(QRegularExpression(", $"));
#endif
}
}
qCDebug(appLog) << "Interface already processed, returning false";
Expand Down Expand Up @@ -494,7 +454,7 @@ bool DeviceMonitor::setMainInfoFromXrandr(const QString &info, const QString &ra
}

// 设置当前分辨率
QRegularExpression reScreenSize(".*([0-9]{1,5}x[0-9]{1,5}).*");
QRegularExpression reScreenSize(".*connected.*\\s([0-9]{1,5}x[0-9]{1,5})\\+.*");
match = reScreenSize.match(info);
if (match.hasMatch()) {
qCDebug(appLog) << "Found screen size in xrandr info:" << match.captured(1);
Expand All @@ -516,9 +476,9 @@ bool DeviceMonitor::setMainInfoFromXrandr(const QString &info, const QString &ra
m_RefreshRate = QString("%1").arg(curRate);
}
if (Common::specialComType == 5 || Common::specialComType == 6) {
m_CurrentResolution = QString("%1").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)).replace("x", "×", Qt::CaseInsensitive);
m_CurrentResolution = QString("%1").arg(match.captured(1)).replace("x", "×", Qt::CaseInsensitive);
} else {
m_CurrentResolution = QString("%1 @%2").arg(QT_REGEXP_CAPTURE(reScreenSize, 1, info)).arg(curRate).replace("x", "×", Qt::CaseInsensitive);
m_CurrentResolution = QString("%1 @%2").arg(match.captured(1)).arg(curRate).replace("x", "×", Qt::CaseInsensitive);
}
} else {
qCDebug(appLog) << "Rate is empty, setting current resolution without rate";
Expand Down
Loading