Skip to content

Commit

Permalink
chore: Adapt to qt6
Browse files Browse the repository at this point in the history
  Adapt to qt6.

Issue: linuxdeepin/dtk#86
  • Loading branch information
18202781743 committed Jun 9, 2023
1 parent 0280dc6 commit 87f1146
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 39 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ cmake_minimum_required(VERSION 3.7)

set(VERSION 4.0)

set(DTK_VERSION "5" CACHE STRING "Dtk Version")

if (DTK_VERSION STREQUAL "5")
set(QT_VERSION_MAJOR "5")
set(DTK_VERSION_MAJOR "")
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)

add_subdirectory("dconfig-center")
10 changes: 5 additions & 5 deletions dconfig-center/dde-dconfig-daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})
Expand Down
12 changes: 12 additions & 0 deletions dconfig-center/dde-dconfig-daemon/src.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@

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)

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)

Expand Down
30 changes: 20 additions & 10 deletions dconfig-center/dde-dconfig-editor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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}
)

Expand Down
12 changes: 9 additions & 3 deletions dconfig-center/dde-dconfig-editor/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <QApplication>
#include <QClipboard>
#include <QMessageBox>
#include <QActionGroup>

MainWindow::MainWindow(QWidget *parent) :
DMainWindow(parent)
Expand Down Expand Up @@ -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"));

Expand Down Expand Up @@ -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);
Expand All @@ -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<double>::min(), std::numeric_limits<double>::max());
widget->setValue(v.toDouble());
Expand Down
25 changes: 17 additions & 8 deletions dconfig-center/dde-dconfig/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -38,17 +48,16 @@ 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})

target_include_directories(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}
${DtkCore_INCLUDE_DIRS}
../common
)

Expand Down
6 changes: 3 additions & 3 deletions dconfig-center/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 6 additions & 8 deletions dconfig-center/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}
Expand Down
3 changes: 1 addition & 2 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 87f1146

Please sign in to comment.