From 6ee0d83854a7d209864a0ec82cc7ab543e2dd283 Mon Sep 17 00:00:00 2001 From: YeShanShan Date: Tue, 30 May 2023 09:29:53 +0800 Subject: [PATCH] chore: Adapt to qt6 Adapt to qt6. Issue: https://github.com/linuxdeepin/dtk/issues/86 --- CMakeLists.txt | 18 ++++++++++- dconfig-center/CMakeLists.txt | 3 -- .../dde-dconfig-daemon/CMakeLists.txt | 10 +++---- dconfig-center/dde-dconfig-daemon/src.cmake | 12 ++++++++ .../dde-dconfig-editor/CMakeLists.txt | 30 ++++++++++++------- .../dde-dconfig-editor/mainwindow.cpp | 12 ++++++-- dconfig-center/dde-dconfig/CMakeLists.txt | 25 +++++++++++----- dconfig-center/example/CMakeLists.txt | 6 ++-- dconfig-center/tests/CMakeLists.txt | 14 ++++----- debian/rules | 3 +- 10 files changed, 90 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2dfcbd..072e8d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,23 @@ cmake_minimum_required(VERSION 3.7) -set(VERSION 4.0) +set(DVERSION "1.0.0" CACHE STRING "define project version") +add_definitions(-DVERSION="${DVERSION}") + +set(DTK_VERSION "5" CACHE STRING "Dtk Version") + +if (DTK_VERSION STREQUAL "5") + set(QT_VERSION_MAJOR "5") + set(EnableDtk5 on) + set(EnableDtk6 off) +elseif(DTK_VERSION STREQUAL "6") + set(QT_VERSION_MAJOR "6") + set(DTK_VERSION_MAJOR "6") + set(EnableDtk5 off) + set(EnableDtk6 on) +else() + message(FATAL_ERROR "Only support DTK_VERSION is 5 or 6") +endif() project(dde-app-services) diff --git a/dconfig-center/CMakeLists.txt b/dconfig-center/CMakeLists.txt index a8c99be..72854cd 100644 --- a/dconfig-center/CMakeLists.txt +++ b/dconfig-center/CMakeLists.txt @@ -10,9 +10,6 @@ set(CMAKE_CXX_STANDARD 14) set(CMAKE_INCLUDE_CURRENT_DIR ON) include(GNUInstallDirs) -set(DVERSION "1.0.0" CACHE STRING "define project version") -add_definitions(-DVERSION="${DVERSION}") - add_subdirectory("dde-dconfig-daemon") add_subdirectory("dde-dconfig-editor") add_subdirectory("dde-dconfig") diff --git a/dconfig-center/dde-dconfig-daemon/CMakeLists.txt b/dconfig-center/dde-dconfig-daemon/CMakeLists.txt index 8a273c9..3c05184 100644 --- a/dconfig-center/dde-dconfig-daemon/CMakeLists.txt +++ b/dconfig-center/dde-dconfig-daemon/CMakeLists.txt @@ -10,8 +10,8 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif () set(REQUIRED_QT_VERSION 5.11.3) -find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus) -find_package(DtkCore REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus) +find_package(Dtk${DTK_VERSION_MAJOR}Core REQUIRED) # generate moc_predefs.h set(CMAKE_AUTOMOC ON) @@ -22,9 +22,9 @@ include(src.cmake) ADD_EXECUTABLE(dde-dconfig-daemon main.cpp ${HEADERS} ${SOURCES} ${DCONFIG_DBUS_XML}) set(COMMON_LIBS - Qt5::Core - Qt5::DBus - ${DtkCore_LIBRARIES} + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::DBus + Dtk${DTK_VERSION_MAJOR}::Core ) target_link_libraries(dde-dconfig-daemon PUBLIC ${COMMON_LIBS}) diff --git a/dconfig-center/dde-dconfig-daemon/src.cmake b/dconfig-center/dde-dconfig-daemon/src.cmake index 623b194..708fa25 100644 --- a/dconfig-center/dde-dconfig-daemon/src.cmake +++ b/dconfig-center/dde-dconfig-daemon/src.cmake @@ -4,6 +4,7 @@ find_package(Qt5DBus REQUIRED) +if(EnableDtk5) qt5_add_dbus_adaptor(DCONFIG_DBUS_XML ../dde-dconfig-daemon/services/org.desktopspec.ConfigManager.xml dconfigserver.h DSGConfigServer configmanager_adaptor DSGConfigAdaptor) @@ -11,6 +12,17 @@ qt5_add_dbus_adaptor(DCONFIG_DBUS_XML ../dde-dconfig-daemon/services/org.desktop qt5_add_dbus_adaptor(DCONFIG_DBUS_XML ../dde-dconfig-daemon/services/org.desktopspec.ConfigManager.Manager.xml dconfigconn.h DSGConfigConn manager_adaptor DSGConfigManagerAdaptor) +endif() + +if(EnableDtk6) +qt_add_dbus_adaptor(DCONFIG_DBUS_XML ../dde-dconfig-daemon/services/org.desktopspec.ConfigManager.xml + dconfigserver.h DSGConfigServer + configmanager_adaptor DSGConfigAdaptor) + +qt_add_dbus_adaptor(DCONFIG_DBUS_XML ../dde-dconfig-daemon/services/org.desktopspec.ConfigManager.Manager.xml + dconfigconn.h DSGConfigConn + manager_adaptor DSGConfigManagerAdaptor) +endif() include_directories(../common) diff --git a/dconfig-center/dde-dconfig-editor/CMakeLists.txt b/dconfig-center/dde-dconfig-editor/CMakeLists.txt index de9a179..8a739e4 100644 --- a/dconfig-center/dde-dconfig-editor/CMakeLists.txt +++ b/dconfig-center/dde-dconfig-editor/CMakeLists.txt @@ -10,10 +10,10 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif () set(REQUIRED_QT_VERSION 5.11.3) -find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui Widgets DBus) -find_package(DtkCore REQUIRED) -find_package(DtkGui REQUIRED) -find_package(DtkWidget REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core Gui Widgets DBus) +find_package(Dtk${DTK_VERSION_MAJOR}Core REQUIRED) +find_package(Dtk${DTK_VERSION_MAJOR}Gui REQUIRED) +find_package(Dtk${DTK_VERSION_MAJOR}Widget REQUIRED) # generate moc_predefs.h set(CMAKE_AUTOMOC ON) @@ -22,11 +22,21 @@ set(AUTOMOC_COMPILER_PREDEFINES ON) set(DCONFIG_DBUS_XML_CONFIGMANAGER ../dde-dconfig-daemon/services/org.desktopspec.ConfigManager.xml) set_source_files_properties(${DCONFIG_DBUS_XML_CONFIGMANAGER} PROPERTIES CLASSNAME DSGConfig NO_NAMESPACE NO_NAMESPACE) -qt5_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_CONFIGMANAGER} manager_interface) +if(EnableDtk5) + qt5_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_CONFIGMANAGER} manager_interface) +endif() +if(EnableDtk6) + qt_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_CONFIGMANAGER} manager_interface) +endif() set(DCONFIG_DBUS_XML_MANAGER ../dde-dconfig-daemon/services/org.desktopspec.ConfigManager.Manager.xml) set_source_files_properties(${DCONFIG_DBUS_XML_MANAGER} PROPERTIES CLASSNAME DSGConfigManager NO_NAMESPACE NO_NAMESPACE) -qt5_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_MANAGER} configmanager_interface) +if(EnableDtk5) + qt5_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_MANAGER} configmanager_interface) +endif() +if(EnableDtk6) + qt_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_MANAGER} configmanager_interface) +endif() set(HEADERS mainwindow.h @@ -50,10 +60,10 @@ set(QRC dde-dconfig-editor.qrc) ADD_EXECUTABLE(dde-dconfig-editor ${HEADERS} ${SOURCES} ${QRC} ${DCONFIG_DBUS_XML}) set(COMMON_LIBS - Qt5::Core - Qt5::Gui - Qt5::Widgets - Qt5::DBus + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Gui + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::DBus ${DtkWidget_LIBRARIES} ) diff --git a/dconfig-center/dde-dconfig-editor/mainwindow.cpp b/dconfig-center/dde-dconfig-editor/mainwindow.cpp index b097cbb..6f6a4bc 100644 --- a/dconfig-center/dde-dconfig-editor/mainwindow.cpp +++ b/dconfig-center/dde-dconfig-editor/mainwindow.cpp @@ -31,6 +31,7 @@ #include #include #include +#include MainWindow::MainWindow(QWidget *parent) : DMainWindow(parent) @@ -83,7 +84,7 @@ MainWindow::MainWindow(QWidget *parent) : auto contentViewWraper = new QWidget(this); auto contentViewLayout = new QVBoxLayout(contentViewWraper); contentViewLayout->setSpacing(0); - contentViewLayout->setMargin(0); + contentViewLayout->setContentsMargins(0, 0, 0, 0); contentView = new Content(); contentView->setObjectName(QStringLiteral("contentView")); @@ -611,7 +612,12 @@ void KeyContent::setBaseInfo(ConfigGetter *getter, const QString &language) labelWidget->setToolTip(getter->description(m_key, language)); m_hLay->addWidget(labelWidget); QWidget *valueWidget = nullptr; - if (v.type() == QVariant::Bool) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + const auto valueType = v.type(); +#else + const auto valueType = v.typeId(); +#endif + if (valueType == QVariant::Bool) { auto widget = new DSwitchButton(this); widget->setChecked(v.toBool()); widget->setEnabled(canWrite); @@ -620,7 +626,7 @@ void KeyContent::setBaseInfo(ConfigGetter *getter, const QString &language) emit valueChanged(checked); }); valueWidget = widget; - } else if (v.type() == QVariant::Double) { + } else if (valueType == QVariant::Double) { auto widget = new DDoubleSpinBox(this); widget->setRange(std::numeric_limits::min(), std::numeric_limits::max()); widget->setValue(v.toDouble()); diff --git a/dconfig-center/dde-dconfig/CMakeLists.txt b/dconfig-center/dde-dconfig/CMakeLists.txt index 501dc13..3e43736 100644 --- a/dconfig-center/dde-dconfig/CMakeLists.txt +++ b/dconfig-center/dde-dconfig/CMakeLists.txt @@ -10,8 +10,8 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) endif () set(REQUIRED_QT_VERSION 5.11.3) -find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus) -find_package(DtkCore REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus) +find_package(Dtk${DTK_VERSION_MAJOR}Core REQUIRED) # generate moc_predefs.h set(CMAKE_AUTOMOC ON) @@ -20,11 +20,21 @@ set(AUTOMOC_COMPILER_PREDEFINES ON) set(DCONFIG_DBUS_XML_CONFIGMANAGER ../dde-dconfig-daemon/services/org.desktopspec.ConfigManager.xml) set_source_files_properties(${DCONFIG_DBUS_XML_CONFIGMANAGER} PROPERTIES CLASSNAME DSGConfig NO_NAMESPACE NO_NAMESPACE) -qt5_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_CONFIGMANAGER} manager_interface) +if(EnableDtk6) + qt_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_CONFIGMANAGER} manager_interface) +endif() +if(EnableDtk5) + qt5_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_CONFIGMANAGER} manager_interface) +endif() set(DCONFIG_DBUS_XML_MANAGER ../dde-dconfig-daemon/services/org.desktopspec.ConfigManager.Manager.xml) set_source_files_properties(${DCONFIG_DBUS_XML_MANAGER} PROPERTIES CLASSNAME DSGConfigManager NO_NAMESPACE NO_NAMESPACE) -qt5_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_MANAGER} configmanager_interface) +if(EnableDtk6) + qt_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_MANAGER} configmanager_interface) +endif() +if (EnableDtk5) + qt5_add_dbus_interface(DCONFIG_DBUS_XML ${DCONFIG_DBUS_XML_MANAGER} configmanager_interface) +endif() set(HEADERS ../common/helper.hpp @@ -38,9 +48,9 @@ set(SOURCES ADD_EXECUTABLE(dde-dconfig ${HEADERS} ${SOURCES} ${DCONFIG_DBUS_XML}) set(COMMON_LIBS - Qt5::Core - Qt5::DBus - ${DtkCore_LIBRARIES} + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::DBus + Dtk${DTK_VERSION_MAJOR}::Core ) target_link_libraries(${PROJECT_NAME} PUBLIC ${COMMON_LIBS}) @@ -48,7 +58,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC ${COMMON_LIBS}) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR} - ${DtkCore_INCLUDE_DIRS} ../common ) diff --git a/dconfig-center/example/CMakeLists.txt b/dconfig-center/example/CMakeLists.txt index 1540620..cd3286d 100644 --- a/dconfig-center/example/CMakeLists.txt +++ b/dconfig-center/example/CMakeLists.txt @@ -6,12 +6,12 @@ PROJECT(dconfig-example) CMAKE_MINIMUM_REQUIRED(VERSION 3.7) set(REQUIRED_QT_VERSION 5.11.3) -find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core) -find_package(Dtk REQUIRED Core) +find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core) +find_package(Dtk${DTK_VERSION_MAJOR}Core REQUIRED) ADD_EXECUTABLE(dconfig-example ./main.cpp) -target_link_libraries(${PROJECT_NAME} PUBLIC Qt5::Core ${DtkCore${DTK_VERSION_SUFFIX}_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::Core Dtk${DTK_VERSION_MAJOR}::Core) dconfig_meta_files(APPID dconfig-example BASE ./configs FILES ./configs/example.json ./configs/a/example.json) diff --git a/dconfig-center/tests/CMakeLists.txt b/dconfig-center/tests/CMakeLists.txt index 7c7207b..07d7b28 100644 --- a/dconfig-center/tests/CMakeLists.txt +++ b/dconfig-center/tests/CMakeLists.txt @@ -6,9 +6,8 @@ PROJECT(tests) CMAKE_MINIMUM_REQUIRED(VERSION 3.7) set(REQUIRED_QT_VERSION 5.11.3) -find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus) -find_package(DtkCore REQUIRED) -find_package(Qt5 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Test) +find_package(Qt${QT_VERSION_MAJOR} ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Core DBus Test) +find_package(Dtk${DTK_VERSION_MAJOR}Core REQUIRED) # generate moc_predefs.h set(CMAKE_AUTOMOC ON) @@ -35,14 +34,13 @@ ADD_EXECUTABLE(dconfigtest main.cpp ${HEADERS} ${SOURCES} ${DCONFIG_DBUS_XML} da target_include_directories(dconfigtest PUBLIC ../dde-dconfig-daemon ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_SOURCE_DIR} ) set(COMMON_LIBS - Qt5::Core - Qt5::DBus - Qt5::Test - ${DtkCore_LIBRARIES} + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::DBus + Qt${QT_VERSION_MAJOR}::Test + Dtk${DTK_VERSION_MAJOR}::Core ) target_link_libraries(dconfigtest PUBLIC ${COMMON_LIBS} diff --git a/debian/rules b/debian/rules index a173dac..c0fe32c 100755 --- a/debian/rules +++ b/debian/rules @@ -1,13 +1,12 @@ #!/usr/bin/make -f DPKG_EXPORT_BUILDFLAGS = 1 include /usr/share/dpkg/default.mk -export QT_SELECT = qt5 %: dh $@ --parallel override_dh_auto_configure: - dh_auto_configure -- -DDVERSION=$(DEB_VERSION_UPSTREAM) + dh_auto_configure -- -DDVERSION=$(DEB_VERSION_UPSTREAM) -DDTK_VERSION=5 override_dh_auto_install: