Skip to content

Commit 00db5e4

Browse files
committed
feat: migrate QML plugins to Qt6 resource system
This commit transitions the control center from file-based QML plugin loading to Qt6's resource system for better performance and deployment. Key changes include: 1. Replaced manual file copying with qt_add_qml_module for proper QML module management 2. Added plugin-system and plugin-device as proper subdirectories 3. Updated plugin loading logic to support both resource-based and file- based plugins 4. Modified DCI icon theme search paths to use resource paths 5. Fixed local file paths in QML by converting them to proper file:// URLs 6. Enhanced plugin discovery with multiple path resolution strategies The migration improves plugin loading performance, simplifies deployment, and provides better integration with Qt6's QML module system. It also maintains backward compatibility with existing file- based plugins. Log: Improved QML plugin loading performance and deployment Influence: 1. Test control center startup and plugin loading 2. Verify all plugin modules load correctly (system, device, accounts, etc.) 3. Check icon display in various modules 4. Test plugin navigation and functionality 5. Verify resource paths work in different deployment scenarios 6. Test backward compatibility with existing plugin configurations feat: 迁移 QML 插件到 Qt6 资源系统 本次提交将控制中心从基于文件的 QML 插件加载迁移到 Qt6 资源系统,以获得更 好的性能和部署体验。主要变更包括: 1. 使用 qt_add_qml_module 替代手动文件复制,实现更好的 QML 模块管理 2. 添加 plugin-system 和 plugin-device 作为正式子目录 3. 更新插件加载逻辑以支持基于资源和基于文件的插件 4. 修改 DCI 图标主题搜索路径以使用资源路径 5. 通过转换为 file:// URL 修复 QML 中的本地文件路径问题 6. 增强插件发现功能,支持多种路径解析策略 此次迁移提高了插件加载性能,简化了部署流程,并提供了与 Qt6 QML 模块系统 的更好集成。同时保持了对现有基于文件的插件的向后兼容性。 Log: 提升 QML 插件加载性能和部署体验 Influence: 1. 测试控制中心启动和插件加载 2. 验证所有插件模块正确加载(系统、设备、账户等) 3. 检查各模块中的图标显示 4. 测试插件导航和功能 5. 验证资源路径在不同部署场景下的工作 6. 测试与现有插件配置的向后兼容性
1 parent 04dbc56 commit 00db5e4

27 files changed

+179
-52
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ add_subdirectory(src/dde-control-center)
205205
#-----------------------shared-utils------------------------
206206
add_subdirectory(src/shared-utils)
207207
#--------------------------plugins--------------------------
208+
add_subdirectory(src/plugin-system)
209+
add_subdirectory(src/plugin-device)
208210
add_subdirectory(src/plugin-accounts)
209211
if (NOT DISABLE_AUTHENTICATION)
210212
add_subdirectory(src/plugin-authentication)

misc/DdeControlCenterPluginMacros.cmake

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,48 @@ include(CMakeParseArguments)
22

33
macro(dcc_build_plugin)
44
set(oneValueArgs NAME TARGET QML_ROOT_DIR)
5-
set(qml_root_dir ${CMAKE_CURRENT_SOURCE_DIR}/qml)
5+
set(multiValueArgs QML_FILES RESOURCE_FILES)
6+
set(QML_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml)
7+
find_package(Qt6 COMPONENTS Qml)
8+
69
cmake_parse_arguments(_config "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
710
if (DEFINED _config_QML_ROOT_DIR)
8-
set(qml_root_dir ${_config_QML_ROOT_DIR})
11+
set(QML_ROOT_DIR ${_config_QML_ROOT_DIR})
912
endif()
10-
file(GLOB_RECURSE qml_files ${qml_root_dir}/*)
11-
add_custom_target(${_config_NAME}_qml ALL
12-
SOURCES ${qml_files}
13-
)
13+
14+
15+
if(NOT _config_QML_FILES)
16+
file(GLOB_RECURSE _config_QML_FILES ${QML_ROOT_DIR}/*.qml ${QML_ROOT_DIR}/*.js)
17+
endif()
18+
19+
if(NOT _config_RESOURCE_FILES)
20+
file(GLOB_RECURSE _config_RESOURCE_FILES ${QML_ROOT_DIR}/*.dci ${QML_ROOT_DIR}/*.svg ${QML_ROOT_DIR}/*.png ${QML_ROOT_DIR}/*.jpg)
21+
endif()
22+
1423
set(plugin_dirs ${PROJECT_BINARY_DIR}/lib/${DDE_CONTROL_CENTER_PLUGIN_DIR}/${_config_NAME}/)
15-
add_custom_command(TARGET ${_config_NAME}_qml POST_BUILD
16-
COMMAND ${CMAKE_COMMAND} -E copy_directory ${qml_root_dir} ${plugin_dirs}
24+
foreach(FILE_PATH ${_config_QML_FILES})
25+
file(RELATIVE_PATH FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR} ${FILE_PATH})
26+
list(APPEND QML_PATHS ${FILE_NAME})
27+
endforeach(FILE_PATH)
28+
29+
foreach(FILE_PATH ${_config_RESOURCE_FILES})
30+
file(RELATIVE_PATH FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR} ${FILE_PATH})
31+
list(APPEND RESOURCE_PATHS ${FILE_NAME})
32+
endforeach(FILE_PATH)
33+
qt_policy(SET QTP0001 NEW)
34+
qt_policy(SET QTP0004 NEW)
35+
qt_add_qml_module(${_config_NAME}_qml
36+
URI "org.deepin.dcc.${_config_NAME}"
37+
QML_FILES ${QML_PATHS}
38+
RESOURCES ${RESOURCE_PATHS}
39+
NO_PLUGIN
40+
RESOURCE_PREFIX "/"
41+
OUTPUT_DIRECTORY "org/deepin/dcc/${_config_NAME}"
42+
)
43+
set_target_properties(${_config_NAME}_qml PROPERTIES
44+
LIBRARY_OUTPUT_DIRECTORY ${plugin_dirs}
1745
)
46+
install(TARGETS ${_config_NAME}_qml DESTINATION ${DDE_CONTROL_CENTER_PLUGIN_INSTALL_DIR}/${_config_NAME})
1847

1948
if (DEFINED _config_TARGET)
2049
set_target_properties(${_config_TARGET} PROPERTIES

src/dde-control-center/CMakeLists.txt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,11 @@ target_link_libraries(${Control_Center_Name} PRIVATE
8181
${Control_Center_Libraries}
8282
)
8383

84-
file(GLOB_RECURSE qmlFiles "${DCC_PROJECT_ROOT_DIR}/qml/*.*")
85-
add_custom_target(${Control_Center_Name}_qml ALL
86-
SOURCES ${qmlFiles}
87-
)
88-
add_custom_command(TARGET ${Control_Center_Name}_qml POST_BUILD
89-
COMMAND ${CMAKE_COMMAND} -E copy_directory "${DCC_PROJECT_ROOT_DIR}/qml" ${DCC_LIBDIR}
90-
)
91-
9284
file(GLOB_RECURSE DCC_Translation_QML_FILES ${DCC_PROJECT_ROOT_DIR}/qml/*.qml ${DCC_PROJECT_ROOT_DIR}/src/*.qml)
9385
file(GLOB_RECURSE DCC_Translation_SOURCE_FILES ${DCC_PROJECT_ROOT_DIR}/src/*.cpp ${DCC_PROJECT_ROOT_DIR}/src/*.h)
9486
dcc_handle_plugin_translation(NAME ${Control_Center_Name} SOURCE_DIR ${DCC_PROJECT_ROOT_DIR} QML_FILES ${DCC_Translation_QML_FILES} SOURCE_FILES ${DCC_Translation_SOURCE_FILES})
9587
# bin
9688
install(TARGETS ${Control_Center_Name} DESTINATION ${CMAKE_INSTALL_BINDIR})
97-
install(DIRECTORY "${DCC_PROJECT_ROOT_DIR}/qml/" DESTINATION ${DCC_INSTALL_DIR})
9889
#----------------------------install config------------------------------
9990
#desktop
10091
install(FILES ${DCC_PROJECT_ROOT_DIR}/misc/org.deepin.dde.control-center.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)

src/dde-control-center/dccmanager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QDBusConnection>
1818
#include <QDBusPendingCall>
1919
#include <QElapsedTimer>
20+
#include <QFileInfo>
2021
#include <QJsonArray>
2122
#include <QJsonDocument>
2223
#include <QJsonObject>
@@ -27,7 +28,6 @@
2728
#include <QTimer>
2829
#include <QTranslator>
2930
#include <QWindow>
30-
#include <QFileInfo>
3131

3232
DCORE_USE_NAMESPACE
3333

@@ -114,7 +114,7 @@ void DccManager::init()
114114
m_imageProvider = new DccImageProvider();
115115
m_engine->addImageProvider("DccImage", m_imageProvider);
116116
QStringList dciPaths = Dtk::Gui::DIconTheme::dciThemeSearchPaths();
117-
dciPaths << QStringLiteral(DefaultModuleDirectory);
117+
dciPaths << ":/org/deepin/dcc";
118118
Dtk::Gui::DIconTheme::setDciThemeSearchPaths(dciPaths);
119119
}
120120

src/dde-control-center/frame/plugin/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,32 @@ foreach(FILE_PATH ${QML_PATHS})
1919
list(APPEND DCCQmlPlugin_CONTROLS ${FILE_NAME})
2020
endforeach(FILE_PATH)
2121

22+
file(GLOB RES_PATHS
23+
"*.dci"
24+
"*.svg"
25+
"*.png"
26+
"*.jpg"
27+
)
28+
29+
foreach(FILE_PATH ${RES_PATHS})
30+
string(REGEX REPLACE ".+/(.+)" "\\1" FILE_NAME ${FILE_PATH})
31+
list(APPEND DCCQmlPlugin_RES ${FILE_NAME})
32+
endforeach(FILE_PATH)
33+
qt_policy(SET QTP0001 NEW)
2234
qt_add_qml_module(${DCCQmlPlugin_Name}
2335
PLUGIN_TARGET ${DCCQmlPlugin_Name}
2436
URI ${URI}
2537
VERSION "1.0"
2638
SHARED
2739
NO_GENERATE_PLUGIN_SOURCE
2840
NO_PLUGIN_OPTIONAL
41+
RESOURCE_PREFIX "/"
2942
QML_FILES
3043
${DCCQmlPlugin_CONTROLS}
3144
SOURCES
3245
${DCCQmlPlugin_SRCS}
46+
RESOURCES
47+
${DCCQmlPlugin_RES}
3348
OUTPUT_DIRECTORY
3449
"${PROJECT_BINARY_DIR}/lib/${URI_PATH}"
3550
)

qml/Crumb.qml renamed to src/dde-control-center/frame/plugin/Crumb.qml

File renamed without changes.

src/dde-control-center/frame/plugin/DccUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
.pragma library
12
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
23
// SPDX-License-Identifier: GPL-3.0-or-later
3-
.pragma library
44

55
function copyFont(srcFont, propertys) {
66
return Qt.font({

qml/DccWindow.qml renamed to src/dde-control-center/frame/plugin/DccWindow.qml

File renamed without changes.

qml/HomePage.qml renamed to src/dde-control-center/frame/plugin/HomePage.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Control {
153153
id: description
154154
Layout.maximumWidth: 160
155155
visible: text !== ""
156-
font: DTK.fontManager.t10
156+
font: D.DTK.fontManager.t10
157157
text: updateDescription()
158158
color: palette.brightText
159159
opacity: 0.5

qml/SecondPage.qml renamed to src/dde-control-center/frame/plugin/SecondPage.qml

File renamed without changes.

0 commit comments

Comments
 (0)