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
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ if(BUILD_DOCS)
add_subdirectory(docs)
endif()

set(DCC_TRANSLATION_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/translations/v1.0" CACHE STRING "Install dir for dde-control-center translate files")
set(DCC_PLUGINS_VERSION 1.1)
set(DCC_TRANSLATION_INSTALL_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/translations/v${DCC_PLUGINS_VERSION}" CACHE STRING "Install dir for dde-control-center translate files")

# 输出目录
set(DCC_LIBDIR ${PROJECT_BINARY_DIR}/lib)
# 插件目录
set(DCC_PLUGINS_DIR plugins_v1.0)
set(DCC_PLUGINS_DIR plugins_v${DCC_PLUGINS_VERSION})
# 安装目录
set(DCC_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/dde-control-center)
set(DCC_DEBUG_LIBDIR ${DCC_INSTALL_DIR})
Expand Down Expand Up @@ -205,6 +206,8 @@ add_subdirectory(src/dde-control-center)
#-----------------------shared-utils------------------------
add_subdirectory(src/shared-utils)
#--------------------------plugins--------------------------
add_subdirectory(src/plugin-system)
add_subdirectory(src/plugin-device)
add_subdirectory(src/plugin-accounts)
if (NOT DISABLE_AUTHENTICATION)
add_subdirectory(src/plugin-authentication)
Expand Down
1 change: 1 addition & 0 deletions misc/DdeControlCenterConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
include(${CMAKE_CURRENT_LIST_DIR}/DdeControlCenterTargets.cmake)
set(DDE_CONTROL_CENTER_PLUGIN_VERSION @DCC_PLUGINS_VERSION@)
set(DDE_CONTROL_CENTER_PLUGIN_DIR @DCC_PLUGINS_DIR@)
set(DDE_CONTROL_CENTER_PLUGIN_INSTALL_DIR @CMAKE_INSTALL_PREFIX@/@DCC_PLUGINS_INSTALL_DIR@)
set(DDE_CONTROL_CENTER_TRANSLATION_INSTALL_DIR @CMAKE_INSTALL_PREFIX@/@DCC_TRANSLATION_INSTALL_DIR@)
Expand Down
81 changes: 72 additions & 9 deletions misc/DdeControlCenterPluginMacros.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,84 @@
include(CMakeParseArguments)

function(dcc_to_capitalized_string input_string output_variable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这种我们要导出去么?如果只是控制中心内部使用的话,尽量不对外,

if(NOT input_string STREQUAL "")
string(SUBSTRING ${input_string} 0 1 first_char)
string(SUBSTRING ${input_string} 1 -1 rest_chars)
string(TOUPPER ${first_char} capitalized_first_char)
set(result "${capitalized_first_char}${rest_chars}")
else()
set(result "")
endif()
set(${output_variable} ${result} PARENT_SCOPE)
endfunction()


macro(dcc_build_plugin)
set(oneValueArgs NAME TARGET QML_ROOT_DIR)
set(qml_root_dir ${CMAKE_CURRENT_SOURCE_DIR}/qml)
set(multiValueArgs QML_FILES RESOURCE_FILES)
set(QML_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/qml)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QML_ROOT_DIR 这个不暴露出去吧,我们只处理默认的,不然下面跟QML_FILES一起组合使用很容易出问题,
如果不设置QML_FILES,我们就默认去处理,否则就让调用方去处理ALIAS,

find_package(Qt6 COMPONENTS Qml)
cmake_parse_arguments(_config "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(NOT "${_config_NAME}" MATCHES "^[A-Za-z0-9]+$")
message(FATAL_ERROR "Error: The name '${_config_NAME}' contains invalid characters. Only alphanumeric characters are allowed.")
endif()

if (DEFINED _config_QML_ROOT_DIR)
set(qml_root_dir ${_config_QML_ROOT_DIR})
set(QML_ROOT_DIR ${_config_QML_ROOT_DIR})
endif()
file(GLOB_RECURSE qml_files ${qml_root_dir}/*)
add_custom_target(${_config_NAME}_qml ALL
SOURCES ${qml_files}
)


if(NOT _config_QML_FILES)
file(GLOB_RECURSE _config_QML_FILES ${QML_ROOT_DIR}/*.qml ${QML_ROOT_DIR}/*.js)
endif()

if(NOT _config_RESOURCE_FILES)
file(GLOB_RECURSE _config_RESOURCE_FILES ${QML_ROOT_DIR}/*.dci ${QML_ROOT_DIR}/*.svg ${QML_ROOT_DIR}/*.png ${QML_ROOT_DIR}/*.jpg ${QML_ROOT_DIR}/*.webp)
endif()

set(plugin_dirs ${PROJECT_BINARY_DIR}/lib/${DDE_CONTROL_CENTER_PLUGIN_DIR}/${_config_NAME}/)
add_custom_command(TARGET ${_config_NAME}_qml POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${qml_root_dir} ${plugin_dirs}
foreach(FILE_PATH ${_config_QML_FILES})
file(RELATIVE_PATH FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR} ${FILE_PATH})
list(APPEND QML_PATHS ${FILE_NAME})

file(RELATIVE_PATH F_NAME ${QML_ROOT_DIR} ${FILE_PATH})

if(${F_NAME} STREQUAL "main.qml")
dcc_to_capitalized_string(${_config_NAME} UPPERNAME)
message(FATAL_ERROR "Error: The filename '${F_NAME}' is deprecated. Please rename it to ${UPPERNAME}Main.qml. path:${FILE_PATH}")
endif()
if(NOT "${F_NAME}" MATCHES "^[A-Z]")
dcc_to_capitalized_string(${F_NAME} UPPERNAME)
message(FATAL_ERROR "Error: The filename '${F_NAME}' must start with an uppercase letter. Please rename it to ${UPPERNAME}. path:${FILE_PATH}")
endif()

set_source_files_properties(${FILE_NAME} PROPERTIES
QT_RESOURCE_ALIAS ${F_NAME}
)
endforeach(FILE_PATH)

foreach(FILE_PATH ${_config_RESOURCE_FILES})
file(RELATIVE_PATH FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR} ${FILE_PATH})
list(APPEND RESOURCE_PATHS ${FILE_NAME})

file(RELATIVE_PATH F_NAME ${QML_ROOT_DIR} ${FILE_PATH})
set_source_files_properties(${FILE_NAME} PROPERTIES
QT_RESOURCE_ALIAS ${F_NAME}
)
endforeach(FILE_PATH)
qt_policy(SET QTP0001 NEW)
qt_policy(SET QTP0004 NEW)
qt_add_qml_module(${_config_NAME}_qml
PLUGIN_TARGET ${_config_NAME}_qml
URI ${_config_NAME}
VERSION 1.0
QML_FILES ${QML_PATHS}
RESOURCES ${RESOURCE_PATHS}
OUTPUT_DIRECTORY ${plugin_dirs}
)
install(TARGETS ${_config_NAME}_qml DESTINATION ${DDE_CONTROL_CENTER_PLUGIN_INSTALL_DIR}/${_config_NAME})
install(FILES ${plugin_dirs}/qmldir DESTINATION ${DDE_CONTROL_CENTER_PLUGIN_INSTALL_DIR}/${_config_NAME})

if (DEFINED _config_TARGET)
set_target_properties(${_config_TARGET} PROPERTIES
Expand All @@ -33,7 +97,6 @@ function(dcc_install_plugin)
install(TARGETS ${_config_TARGET} DESTINATION ${DDE_CONTROL_CENTER_PLUGIN_INSTALL_DIR}/${_config_NAME})
endif()

install(DIRECTORY ${plugin_dirs} DESTINATION ${DDE_CONTROL_CENTER_PLUGIN_INSTALL_DIR}/${_config_NAME})
endfunction()

function(dcc_handle_plugin_translation)
Expand Down
33 changes: 6 additions & 27 deletions src/dde-control-center/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,18 @@ cmake_minimum_required(VERSION 3.18)

#--------------------------frame--------------------------
set(DCCFrame_Name ${DCC_FRAME_Library})
file(GLOB DCCFrame_SRCS
"${DCC_PROJECT_ROOT_DIR}/include/*.h"
"frame/*.cpp"
"frame/*.h"
)

add_library(${DCCFrame_Name} SHARED
${DCCFrame_SRCS}
"${DCC_PROJECT_ROOT_DIR}/include/dccfactory.h"
)

find_package(${QT_NS} COMPONENTS QmlModels REQUIRED)
if(${QT_NS}_VERSION VERSION_GREATER_EQUAL 6.10)
find_package(${QT_NS} COMPONENTS QmlModelsPrivate QuickPrivate REQUIRED)
endif()

set(DCCFrame_Libraries
${DTK_NS}::Gui
${QT_NS}::Gui
${QT_NS}::Quick
${QT_NS}::QuickPrivate
${QT_NS}::QmlModelsPrivate
)

target_link_libraries(${DCCFrame_Name} PRIVATE
${DCCFrame_Libraries}
${QT_NS}::Core
)

set_target_properties(${DCCFrame_Name} PROPERTIES
Expand All @@ -48,7 +35,7 @@ install(EXPORT DdeControlCenterTargets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/DdeControlCenter
)
#--------------------------qml-plugin--------------------------
add_subdirectory(frame/plugin)
add_subdirectory(plugin)
#--------------------------dde-control-center--------------------------
set(Control_Center_Name dde-control-center)
file(GLOB Control_Center_SRCS
Expand All @@ -64,8 +51,8 @@ add_executable(${Control_Center_Name}
target_compile_definitions(${Control_Center_Name} PRIVATE CVERSION="${CMAKE_PROJECT_VERSION}")

target_include_directories(${Control_Center_Name} PRIVATE
include/interface
frame
include
plugin
)

set(Control_Center_Libraries
Expand All @@ -75,26 +62,18 @@ set(Control_Center_Libraries
${QT_NS}::DBus
${QT_NS}::Concurrent
${QT_NS}::Quick
dde-control-center-lib
)

target_link_libraries(${Control_Center_Name} PRIVATE
${Control_Center_Libraries}
)

file(GLOB_RECURSE qmlFiles "${DCC_PROJECT_ROOT_DIR}/qml/*.*")
add_custom_target(${Control_Center_Name}_qml ALL
SOURCES ${qmlFiles}
)
add_custom_command(TARGET ${Control_Center_Name}_qml POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory "${DCC_PROJECT_ROOT_DIR}/qml" ${DCC_LIBDIR}
)

file(GLOB_RECURSE DCC_Translation_QML_FILES ${DCC_PROJECT_ROOT_DIR}/qml/*.qml ${DCC_PROJECT_ROOT_DIR}/src/*.qml)
file(GLOB_RECURSE DCC_Translation_SOURCE_FILES ${DCC_PROJECT_ROOT_DIR}/src/*.cpp ${DCC_PROJECT_ROOT_DIR}/src/*.h)
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})
# bin
install(TARGETS ${Control_Center_Name} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY "${DCC_PROJECT_ROOT_DIR}/qml/" DESTINATION ${DCC_INSTALL_DIR})
#----------------------------install config------------------------------
#desktop
install(FILES ${DCC_PROJECT_ROOT_DIR}/misc/org.deepin.dde.control-center.desktop DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/applications)
Expand Down
35 changes: 9 additions & 26 deletions src/dde-control-center/dccmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
#include <DIconTheme>

#include <QCoreApplication>
#include <QDBusConnection>

Check warning on line 17 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 18 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 19 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 20 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 21 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 22 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 23 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLoggingCategory>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickWindow>
#include <QTimer>

Check warning on line 28 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 29 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 30 in src/dde-control-center/dccmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

DCORE_USE_NAMESPACE

Expand Down Expand Up @@ -82,40 +82,23 @@

bool DccManager::installTranslator(const QString &name)
{
QTranslator *translator = new QTranslator(qApp);
if (translator->load(QLocale(), name, "_", TRANSLATE_READ_DIR)) {
qApp->installTranslator(translator);
#if 1 // 兼容旧版位置
} else if (translator->load(QLocale(), name, "_", TRANSLATE_READ_DIR "/..")) {
qApp->installTranslator(translator);
#endif
} else {
delete translator;
qCWarning(dccLog()) << "install translator fail:" << name << ", dir:" << TRANSLATE_READ_DIR;
return false;
}
return true;
const QStringList translateDirs = { TRANSLATE_READ_DIR,
TRANSLATE_READ_DIR "/../v1.0", // 兼容旧版位置
TRANSLATE_READ_DIR "/.." };
return Dtk::Gui::DGuiApplicationHelper::loadTranslator(name, translateDirs, { QLocale() });
}

void DccManager::init()
{
if (m_engine)
return;

QQmlEngine::setObjectOwnership(dccV25::DccApp::instance(), QQmlEngine::CppOwnership);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个可以直接在c++中用qtquick方式注册,

qmlRegisterSingletonInstance("org.deepin.dcc", 1, 0, "DccApp", dccV25::DccApp::instance());

m_engine = new QQmlApplicationEngine(this);
auto paths = m_engine->importPathList();
paths.prepend(DefaultModuleDirectory);
const auto runtimePluginDir = QCoreApplication::applicationDirPath() + "/../lib/";
if (QFileInfo::exists(runtimePluginDir)) {
paths.prepend(runtimePluginDir);
}
qCInfo(dccLog()) << "Import paths:" << paths;
m_engine->setImportPathList(paths);
m_imageProvider = new DccImageProvider();
m_engine->addImageProvider("DccImage", m_imageProvider);
QStringList dciPaths = Dtk::Gui::DIconTheme::dciThemeSearchPaths();
dciPaths << QStringLiteral(DefaultModuleDirectory);
Dtk::Gui::DIconTheme::setDciThemeSearchPaths(dciPaths);
}

QQmlApplicationEngine *DccManager::engine()
Expand All @@ -134,7 +117,7 @@
void DccManager::loadModules(bool async, const QStringList &dirs)
{
// onAddModule(m_rootModule);
m_plugins->loadModules(m_root, async, dirs);
m_plugins->loadModules(m_root, async, dirs, m_engine);
// showModule(m_rootModule);
}

Expand Down
43 changes: 0 additions & 43 deletions src/dde-control-center/frame/CMakeLists.txt

This file was deleted.

56 changes: 0 additions & 56 deletions src/dde-control-center/frame/plugin/CMakeLists.txt

This file was deleted.

Loading