Skip to content

Commit

Permalink
chore: support Qt6 (#385)
Browse files Browse the repository at this point in the history
- Update CMakeLists.txt to support both Qt5 and Qt6
- Replace DApplicationHelper with DGuiApplicationHelper for Qt6
- Update debian/control and debian/rules for Qt6 compatibility
- Fix Qt6 compatibility issues in various widgets and utilities
- Update unit tests for Qt6 support

Log: support Qt6
  • Loading branch information
wyu71 authored Jan 16, 2025
1 parent 123c5af commit 93da939
Show file tree
Hide file tree
Showing 114 changed files with 1,586 additions and 355 deletions.
21 changes: 16 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ else()
SET(IS_LOONGARCH_TYPE 0)
endif()

if (NOT DEFINED QT_VERSION_MAJOR)
set(QT_VERSION_MAJOR 6)
endif()
if (QT_VERSION_MAJOR EQUAL 6)
set(DTK_VERSION_MAJOR 6)
else()
set(DTK_VERSION_MAJOR)
endif()
set(QT_NS Qt${QT_VERSION_MAJOR})
set(DTK_NS Dtk${DTK_VERSION_MAJOR})

#系统监视器主应用
ADD_SUBDIRECTORY(deepin-system-monitor-main)
#系统监视器插件
Expand Down Expand Up @@ -73,11 +84,11 @@ set(system_monitor_plugin_popup assets/configs/org.deepin.system-monitor.plugin.
set(system_monitor_plugin_server assets/configs/org.deepin.system-monitor.server.json)

if (DEFINED DSG_DATA_DIR)
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_main})
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_daemon})
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_plugin})
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_plugin_popup})
dconfig_meta_files(APPID ${APPID} FILES ${system_monitor_plugin_server})
dtk_add_config_meta_files(APPID ${APPID} FILES ${system_monitor_main})
dtk_add_config_meta_files(APPID ${APPID} FILES ${system_monitor_daemon})
dtk_add_config_meta_files(APPID ${APPID} FILES ${system_monitor_plugin})
dtk_add_config_meta_files(APPID ${APPID} FILES ${system_monitor_plugin_popup})
dtk_add_config_meta_files(APPID ${APPID} FILES ${system_monitor_plugin_server})
message("-- DConfig is supported by DTK")
else()
install(FILES ${system_monitor_main} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/dsg/configs/${APPID}/)
Expand Down
27 changes: 12 additions & 15 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,35 @@ Build-Depends:
debhelper (>= 11),
cmake,
pkg-config,
qtbase5-dev,
qttools5-dev,
libdtkwidget-dev,
qt6-base-dev | qtbase5-dev,
qt6-svg-dev | libqt5svg5-dev,
qt6-tools-dev | qttools5-dev,
libdtk6core-dev | libdtkcore-dev,
libdtk6gui-dev | libdtkgui-dev,
libdtk6widget-dev | libdtkwidget-dev,
libxcb1-dev,
libqt5x11extras5-dev,
libxext-dev,
libpcap-dev,
qttools5-dev-tools,
qt6-tools-dev-tools | qttools5-dev-tools,
libicu-dev,
deepin-gettext-tools,
libxcb-util0-dev,
libxcb-icccm4-dev,
libnl-3-dev,
libnl-route-3-dev,
libudev-dev,
libgsettings-qt-dev,
dde-dock-dev,
libgtest-dev,
libgmock-dev,
libdwayland-dev | libkf5wayland-dev,
libwayland-dev,
libpolkit-qt5-1-dev
dde-tray-loader-dev | dde-dock-dev,
libgtest-dev,
libgmock-dev,
libpolkit-qt6-1-dev | libpolkit-qt5-1-dev
Standards-Version: 3.9.8
Homepage: https://github.com/linuxdeepin/deepin-system-monitor

Package: deepin-system-monitor
Architecture: any
Depends: ${shlibs:Depends},
${misc:Depends},
libcap2-bin,
libdwaylandclient5 | libkf5waylandclient5,
libdwaylandserver5 | libkf5waylandserver5,
libcap2-bin,
deepin-service-manager
Recommends: uos-reporter, deepin-event-log
Replaces: deepin-system-monitor-plugin
Expand Down
20 changes: 9 additions & 11 deletions deepin-system-monitor-daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,25 @@ endforeach()
file(GLOB_RECURSE SRC_CPP ${CMAKE_CURRENT_LIST_DIR}/src/*.cpp)
file(GLOB_RECURSE SRC_H ${CMAKE_CURRENT_LIST_DIR}/src/*.h)

find_package(Qt5 COMPONENTS Core DBus REQUIRED)
find_package(DtkCore CONFIG REQUIRED)
find_package(${QT_NS} COMPONENTS Core DBus REQUIRED)
find_package(${DTK_NS} REQUIRED COMPONENTS Core)

if (QT_VERSION_MAJOR LESS 6)
qt5_add_resources(RESOURCES_FILE assets/${BIN_NAME}.qrc)
else()
qt6_add_resources(RESOURCES_FILE assets/${BIN_NAME}.qrc)
endif()

add_library(${BIN_NAME} MODULE
${SRC_CPP}
${SRC_H}
${RESOURCES_FILE}
)

target_include_directories(${BIN_NAME} PUBLIC
Qt5::Core
Qt5::DBus
${DtkCore_INCLUDE_DIRS}
)

target_link_libraries(${BIN_NAME} PRIVATE
Qt5::Core
Qt5::DBus
${DtkCore_LIBRARIES}
${QT_NS}::Core
${QT_NS}::DBus
${DTK_NS}::Core
)

#安全测试加固编译参数
Expand Down
4 changes: 4 additions & 0 deletions deepin-system-monitor-daemon/src/cpuprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ double CpuProfile::updateSystemCpuUsage()
// |user|nice|sys|idle|iowait|hardqirq|softirq|steal|guest|guest_nice|

// 分割行数据
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList cpuStatus = QString(lineData).split(" ", QString::SkipEmptyParts);
#else
QStringList cpuStatus = QString(lineData).split(" ", Qt::SkipEmptyParts);
#endif

// CPU状态应包含10个数据片段,有效数据 1-10,位置0不使用
if (cpuStatus.size() < 11) {
Expand Down
6 changes: 6 additions & 0 deletions deepin-system-monitor-daemon/src/memoryprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ double MemoryProfile::updateSystemMemoryUsage()
}

// 数据提取
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList list1 = QString(lineData1).split(" ", QString::SkipEmptyParts);
QStringList list2 = QString(lineData2).split(" ", QString::SkipEmptyParts);
QStringList list3 = QString(lineData3).split(" ", QString::SkipEmptyParts);
#else
QStringList list1 = QString(lineData1).split(" ", Qt::SkipEmptyParts);
QStringList list2 = QString(lineData2).split(" ", Qt::SkipEmptyParts);
QStringList list3 = QString(lineData3).split(" ", Qt::SkipEmptyParts);
#endif

if (list1.size() < 3 || list2.size() < 3 || list3.size() < 3) {
qCWarning(app) << QString(" parse %1 file fail !").arg(PROC_MEM_INFOI_PATH) << list1 << list2 << list3;
Expand Down
66 changes: 19 additions & 47 deletions deepin-system-monitor-main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set(APP_RESOURCES ${APP_RES_ROOT}/${PROJECT_NAME}.qrc)
set(DESKTOP_FILE ${PROJECT_NAME}.desktop)
set(POLICY_FILE com.deepin.pkexec.${PROJECT_NAME}.policy)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wl,--as-need -fPIE")
Expand All @@ -25,7 +25,7 @@ endif ()
if (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions("-DQT_NO_DEBUG_OUTPUT")
endif()
if (USE_DEEPIN_WAYLAND)
if (USE_DEEPIN_WAYLAND AND QT_VERSION LESS 6)
add_definitions("-DUSE_DEEPIN_WAYLAND")
endif()

Expand All @@ -37,29 +37,10 @@ include(CheckSymbolExists)
check_symbol_exists(syscall "unistd.h" HAVE_SYS_CALL)
check_symbol_exists(SYS_getrandom "sys/syscall.h" HAVE_SYS_GETRANDOM)
include(FindPkgConfig)
if (USE_DEEPIN_WAYLAND)
find_package(DWayland)
find_package(KF5Wayland)
if (DWayland_FOUND)
message("DWayland founded.")
add_definitions(-DDWAYLAND)
elseif(KF5Wayland_FOUND)
message("KF5Wayland founded.")
add_definitions(-DKF5WAYLAND)
endif()
endif()

find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt5 COMPONENTS Widgets REQUIRED)
find_package(Qt5 COMPONENTS Gui REQUIRED)
find_package(Qt5 COMPONENTS X11Extras REQUIRED)
find_package(Qt5 COMPONENTS DBus REQUIRED)
find_package(Qt5 COMPONENTS Concurrent REQUIRED)
find_package(Qt5 COMPONENTS LinguistTools REQUIRED)

find_package(DtkCore REQUIRED)
find_package(DtkGui REQUIRED)
find_package(DtkWidget REQUIRED)
find_package(${QT_NS} COMPONENTS Core Widgets Gui DBus Concurrent LinguistTools REQUIRED)
find_package(${DTK_NS} COMPONENTS Core Gui Widget REQUIRED)

find_library(LIB_PCAP NAMES pcap REQUIRED)
find_library(LIB_XCB NAMES xcb REQUIRED)
find_library(LIB_XEXT NAMES Xext REQUIRED)
Expand All @@ -70,9 +51,6 @@ find_package(ICU COMPONENTS i18n uc REQUIRED)
pkg_search_module(LIB_NL3 REQUIRED libnl-3.0)
pkg_search_module(LIB_NL3_ROUTE REQUIRED libnl-route-3.0)
pkg_search_module(LIB_UDEV REQUIRED libudev)
include_directories(${DtkCore_INCLUDE_DIRS})
include_directories(${DtkGui_INCLUDE_DIRS})
include_directories(${DtkWidget_INCLUDE_DIRS})

include_directories(${LIB_NL3_INCLUDE_DIRS})
include_directories(${LIB_NL3_ROUTE_INCLUDE_DIRS})
Expand Down Expand Up @@ -588,15 +566,14 @@ set(APP_CPP
${DMIDECODE}
)
set(LIBS
Qt5::Core
Qt5::Widgets
Qt5::Gui
Qt5::DBus
Qt5::Concurrent
Qt5::X11Extras
dtkcore
dtkwidget
dtkgui
${QT_NS}::Core
${QT_NS}::Widgets
${QT_NS}::Gui
${QT_NS}::DBus
${QT_NS}::Concurrent
${DTK_NS}::Core
${DTK_NS}::Widget
${DTK_NS}::Gui
${LIB_PCAP}
ICU::i18n
ICU::uc
Expand All @@ -607,19 +584,14 @@ set(LIBS
${LIB_NL3_ROUTE_LIBRARIES}
${LIB_UDEV_LIBRARIES}
# ${DFrameworkDBus_LIBRARIES} # chinalife
Dtk::Core
)

if (USE_DEEPIN_WAYLAND)
if (DWayland_FOUND)
list(APPEND LIBS DWaylandClient DWaylandServer)
else()
list(APPEND LIBS KF5::WaylandClient KF5::WaylandServer)
endif()
endif()

file(GLOB APP_TS_FILES LIST_DIRECTORIES false translations/*.ts)
qt5_add_translation(APP_QM_FILES ${APP_TS_FILES})
if (QT_VERSION_MAJOR LESS 6)
qt5_add_translation(APP_QM_FILES ${APP_TS_FILES})
else()
qt6_add_translation(APP_QM_FILES ${APP_TS_FILES})
endif()
add_custom_target(QMFILES ALL DEPENDS ${APP_QM_FILES})

find_program(POLICY_TS_CONV deepin-policy-ts-convert REQUIRED)
Expand Down Expand Up @@ -657,5 +629,5 @@ message("-- DConfig is supported by DTK ${PROJECT_SOURCE_DIR}")
set(configFile ${PROJECT_SOURCE_DIR}/assets/org.deepin.system-monitor.main.json)
if (DEFINED DSG_DATA_DIR)
message("-- DConfig is supported by DTK")
dconfig_meta_files(APPID ${APPID} FILES ${configFile})
dtk_add_config_meta_files(APPID ${APPID} FILES ${configFile})
endif()
2 changes: 1 addition & 1 deletion deepin-system-monitor-main/common/error_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ ErrorContext::~ErrorContext() {}
bool ErrorContext::operator==(const ErrorContext &other) const
{
return (data->m_code == other.getCode() && data->m_subCode == other.getSubCode() &&
data->m_errName == other.getSubCode() && data->m_errMessage == getErrorMessage());
data->m_errName == other.getErrorName() && data->m_errMessage == getErrorMessage());
}

// get error code
Expand Down
21 changes: 21 additions & 0 deletions deepin-system-monitor-main/compact_cpu_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
#include "gui/base/base_commandlink_button.h"

#include <DApplication>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <DApplicationHelper>
#else
#include <DGuiApplicationHelper>
#endif
#include <DPalette>
#include <DStyleHelper>
#include <DFontSizeManager>
Expand Down Expand Up @@ -173,7 +177,11 @@ void CompactCpuMonitor::resizeEvent(QResizeEvent *event)

void CompactCpuMonitor::resizeItemRect()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
m_detailButton->setFixedSize(m_detailButton->fontMetrics().width(m_detailButton->text()) + 12, m_detailButton->fontMetrics().height() + 4);
#else
m_detailButton->setFixedSize(m_detailButton->fontMetrics().horizontalAdvance(m_detailButton->text()) + 12, m_detailButton->fontMetrics().height() + 4);
#endif
const QSize &detailtextSize = m_detailButton->size();
m_detailButton->setGeometry(this->width() - detailtextSize.width() + additionCPUPosX, additionCPUPoxY, detailtextSize.width(), detailtextSize.height());
}
Expand All @@ -183,7 +191,11 @@ void CompactCpuMonitor::paintEvent(QPaintEvent *)
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto *dAppHelper = DApplicationHelper::instance();
#else
auto *dAppHelper = DGuiApplicationHelper::instance();
#endif

// init colors
auto palette = dAppHelper->applicationPalette();
Expand All @@ -208,11 +220,20 @@ void CompactCpuMonitor::paintEvent(QPaintEvent *)
QString cpuText = DApplication::translate("Process.Graph.View", "CPU");
QString cpuStatText = QString::number(totalCpuPercent, 'f', 1).append('%');

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRect cpuRect(pointerRadius * 2 + spacing - 2, 0, fm.width(cpuText), fm.height() + 4);
#else
QRect cpuRect(pointerRadius * 2 + spacing - 2, 0, fm.horizontalAdvance(cpuText), fm.height() + 4);
#endif
QRect sectionRect(0, cpuRect.y() + qCeil((cpuRect.height() - pointerRadius) / 2.),
pointerRadius, pointerRadius);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRect statRect(cpuRect.x() + cpuRect.width() + spacing, cpuRect.y(), fmStat.width(cpuStatText),
fmStat.height() + 4);
#else
QRect statRect(cpuRect.x() + cpuRect.width() + spacing, cpuRect.y(), fmStat.horizontalAdvance(cpuStatText),
fmStat.height() + 4);
#endif

m_detailButton->setText(m_detailButton->fontMetrics().elidedText(m_detailText, Qt::ElideRight, this->width() - statRect.right() - 2 * spacing));
resizeItemRect();
Expand Down
9 changes: 9 additions & 0 deletions deepin-system-monitor-main/compact_disk_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#include "system/diskio_info.h"

#include <DApplication>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <DApplicationHelper>
#else
#include <DGuiApplicationHelper>
#endif
#include <DPalette>

#include <QDebug>
Expand All @@ -21,6 +25,7 @@
#include <QMouseEvent>

DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE
using namespace core::system;
using namespace common;
using namespace common::format;
Expand Down Expand Up @@ -117,7 +122,11 @@ void CompactDiskMonitor::paintEvent(QPaintEvent *)
int margin = 10;

// init colors
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
auto *dAppHelper = DApplicationHelper::instance();
#else
auto *dAppHelper = DGuiApplicationHelper::instance();
#endif
auto palette = dAppHelper->applicationPalette();
#ifndef THEME_FALLBACK_COLOR
QColor tagColor = palette.color(DPalette::TextTitle);
Expand Down
Loading

0 comments on commit 93da939

Please sign in to comment.