Skip to content

Commit

Permalink
feat: Qt5 to Qt6 Migration
Browse files Browse the repository at this point in the history
1. Build System: Update CMake configs and dependencies for Qt6
2. API Updates: Replace deprecated APIs (e.g.: QRegExp QDesktopWidget)
3. DBus: Refactor async calls to use QVariant list
4. UI: Modernize widget layouts and color handling
5. Dependencies: Update to Qt6/DTK6 series packages

Log: Qt5 to Qt6 Migration
  • Loading branch information
rb-union committed Jan 13, 2025
1 parent 5ea0a6c commit e442181
Show file tree
Hide file tree
Showing 66 changed files with 543 additions and 501 deletions.
21 changes: 6 additions & 15 deletions 3rdparty/kcalendarcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,14 @@ project(kcalendarcore)

# Find the library
find_package(PkgConfig REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5 COMPONENTS
Core
DBus
REQUIRED)

#set(LibIcal_MIN_VERSION "3.0")
#find_package(ical ${LibIcal_MIN_VERSION})
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui DBus)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
pkg_check_modules(3rd_lib REQUIRED
libical
)
pkg_check_modules(3rd_lib REQUIRED libical)

#安全编译参数
# 安全编译参数
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -z noexecstack -pie -fPIC -z lazy")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${3rd_lib_INCLUDE_DIRS})
Expand All @@ -28,9 +19,9 @@ aux_source_directory(src CALENDARCORE_SRCS)
add_library(${PROJECT_NAME} STATIC ${CALENDARCORE_SRCS})

target_link_libraries(${PROJECT_NAME}
Qt5::Core
Qt5::DBus
Qt5::Gui
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Gui
${3rd_lib_LIBRARIES}
${Libical_LIBRARIES}
icalvcal
Expand Down
75 changes: 64 additions & 11 deletions 3rdparty/kcalendarcore/src/vcalformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,18 @@ Todo::Ptr VCalFormat::VTodoToEvent(VObject *vtodo)
recurrenceType = Recurrence::rWeekly;
} else if (tmpStrLen > 1) {
recurrenceTypeAbbrLen = 2;
if (tmpStr.leftRef(2) == QLatin1String("MP")) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto prefix = QStringView(tmpStr).left(2);
#else
auto prefix = tmpStr.leftRef(2);
#endif
if (prefix == QLatin1String("MP")) {
recurrenceType = Recurrence::rMonthlyPos;
} else if (tmpStr.leftRef(2) == QLatin1String("MD")) {
} else if (prefix == QLatin1String("MD")) {
recurrenceType = Recurrence::rMonthlyDay;
} else if (tmpStr.leftRef(2) == QLatin1String("YM")) {
} else if (prefix == QLatin1String("YM")) {
recurrenceType = Recurrence::rYearlyMonth;
} else if (tmpStr.leftRef(2) == QLatin1String("YD")) {
} else if (prefix == QLatin1String("YD")) {
recurrenceType = Recurrence::rYearlyDay;
}
}
Expand All @@ -350,7 +355,11 @@ Todo::Ptr VCalFormat::VTodoToEvent(VObject *vtodo)
// Immediately after the type is the frequency
int index = tmpStr.indexOf(QLatin1Char(' '));
int last = tmpStr.lastIndexOf(QLatin1Char(' ')) + 1; // find last entry
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
int rFreq = QStringView(tmpStr).mid(recurrenceTypeAbbrLen, (index - 1)).toInt();
#else
int rFreq = tmpStr.midRef(recurrenceTypeAbbrLen, (index - 1)).toInt();
#endif
++index; // advance to beginning of stuff after freq

// Read the type-specific settings
Expand Down Expand Up @@ -485,7 +494,11 @@ Todo::Ptr VCalFormat::VTodoToEvent(VObject *vtodo)
if (tmpStr.mid(index, 1) == QLatin1String("#")) {
// Nr of occurrences
index++;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
int rDuration = QStringView(tmpStr).mid(index, tmpStr.length() - index).toInt();
#else
int rDuration = tmpStr.midRef(index, tmpStr.length() - index).toInt();
#endif
if (rDuration > 0) {
anEvent->recurrence()->setDuration(rDuration);
}
Expand Down Expand Up @@ -769,13 +782,19 @@ Event::Ptr VCalFormat::VEventToEvent(VObject *vevent)
recurrenceType = Recurrence::rWeekly;
} else if (tmpStrLen > 1) {
recurrenceTypeAbbrLen = 2;
if (tmpStr.leftRef(2) == QLatin1String("MP")) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
auto prefix = QStringView(tmpStr).left(2);
#else
auto prefix = tmpStr.leftRef(2);
#endif

if (prefix == QLatin1String("MP")) {
recurrenceType = Recurrence::rMonthlyPos;
} else if (tmpStr.leftRef(2) == QLatin1String("MD")) {
} else if (prefix == QLatin1String("MD")) {
recurrenceType = Recurrence::rMonthlyDay;
} else if (tmpStr.leftRef(2) == QLatin1String("YM")) {
} else if (prefix == QLatin1String("YM")) {
recurrenceType = Recurrence::rYearlyMonth;
} else if (tmpStr.leftRef(2) == QLatin1String("YD")) {
} else if (prefix == QLatin1String("YD")) {
recurrenceType = Recurrence::rYearlyDay;
}
}
Expand All @@ -785,7 +804,11 @@ Event::Ptr VCalFormat::VEventToEvent(VObject *vevent)
// Immediately after the type is the frequency
int index = tmpStr.indexOf(QLatin1Char(' '));
int last = tmpStr.lastIndexOf(QLatin1Char(' ')) + 1; // find last entry
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
int rFreq = QStringView(tmpStr).mid(recurrenceTypeAbbrLen, (index - 1)).toInt();
#else
int rFreq = tmpStr.midRef(recurrenceTypeAbbrLen, (index - 1)).toInt();
#endif
++index; // advance to beginning of stuff after freq

// Read the type-specific settings
Expand Down Expand Up @@ -920,7 +943,11 @@ Event::Ptr VCalFormat::VEventToEvent(VObject *vevent)
if (tmpStr.mid(index, 1) == QLatin1String("#")) {
// Nr of occurrences
index++;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
int rDuration = QStringView(tmpStr).mid(index, tmpStr.length() - index).toInt();
#else
int rDuration = tmpStr.midRef(index, tmpStr.length() - index).toInt();
#endif
if (rDuration > 0) {
anEvent->recurrence()->setDuration(rDuration);
}
Expand Down Expand Up @@ -1210,16 +1237,26 @@ QDateTime VCalFormat::ISOToQDateTime(const QString &dtStr)
{
QDate tmpDate;
QTime tmpTime;
QString tmpStr;
int year, month, day, hour, minute, second;

tmpStr = dtStr;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QStringView tmpStr{dtStr};
year = tmpStr.left(4).toInt();
month = tmpStr.mid(4, 2).toInt();
day = tmpStr.mid(6, 2).toInt();
hour = tmpStr.mid(9, 2).toInt();
minute = tmpStr.mid(11, 2).toInt();
second = tmpStr.mid(13, 2).toInt();
#else
QString tmpStr = dtStr;
year = tmpStr.leftRef(4).toInt();
month = tmpStr.midRef(4, 2).toInt();
day = tmpStr.midRef(6, 2).toInt();
hour = tmpStr.midRef(9, 2).toInt();
minute = tmpStr.midRef(11, 2).toInt();
second = tmpStr.midRef(13, 2).toInt();
#endif

tmpDate.setDate(year, month, day);
tmpTime.setHMS(hour, minute, second);

Expand All @@ -1239,9 +1276,16 @@ QDate VCalFormat::ISOToQDate(const QString &dateStr)
{
int year, month, day;

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QStringView tmpStr{dateStr};
year = tmpStr.left(4).toInt();
month = tmpStr.mid(4, 2).toInt();
day = tmpStr.mid(6, 2).toInt();
#else
year = dateStr.leftRef(4).toInt();
month = dateStr.midRef(4, 2).toInt();
day = dateStr.midRef(6, 2).toInt();
#endif

return QDate(year, month, day);
}
Expand Down Expand Up @@ -1280,8 +1324,12 @@ bool VCalFormat::parseTZOffsetISO8601(const QString &s, int &result)
if (str.size() < (ofs + 2)) {
return false;
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QStringView tmpStr{str};
v = tmpStr.mid(ofs, 2).toInt(&ok) * 60;
#else
v = str.midRef(ofs, 2).toInt(&ok) * 60;
#endif
if (!ok) {
return false;
}
Expand All @@ -1295,7 +1343,12 @@ bool VCalFormat::parseTZOffsetISO8601(const QString &s, int &result)
if (str.size() < (ofs + 2)) {
return false;
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
v += tmpStr.mid(ofs, 2).toInt(&ok);
#else
v += str.midRef(ofs, 2).toInt(&ok);
#endif
if (!ok) {
return false;
}
Expand Down
107 changes: 66 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
cmake_minimum_required(VERSION 3.7)
project(dde-calendar)

if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr)
endif ()
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX /usr)
endif()

include(GNUInstallDirs)

#compile flags
if (CMAKE_BUILD_TYPE MATCHES Debug)
# check Qt version, support Qt5 default
find_package(Qt6 QUIET)

if(Qt6_FOUND)
set(SUPPORT_QT6 TRUE)
set(QT_VERSION_MAJOR 6)
set(DTK_VERSION_MAJOR 6)
else()
set(QT_VERSION_MAJOR 5)
endif()

message(STATUS "--- Enable Qt6: ${ENABLE_Qt6} Current use Qt Version: ${QT_VERSION_MAJOR}")

# compile flags
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra")
# Enable Qt builtin debug mode

# Enable Qt builtin debug mode
add_definitions("-DQT_MESSAGELOGCONTEXT")
else()
# -Wl, -O2 Enable linker optimizations
Expand All @@ -20,68 +35,78 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O2 -Wl,--gc-sections")
endif()

#代码覆盖率开关
# 代码覆盖率开关
if(CMAKE_COVERAGE_ARG STREQUAL "CMAKE_COVERAGE_ARG_ON")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -fprofile-arcs -ftest-coverage")
endif()

macro(SUBDIRLIST result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
LIST(APPEND dirlist ${child})
endif()
endforeach()
set(${result} ${dirlist})
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")

foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
LIST(APPEND dirlist ${child})
endif()
endforeach()

set(${result} ${dirlist})
endmacro()

ADD_SUBDIRECTORY(3rdparty/kcalendarcore)
ADD_SUBDIRECTORY(calendar-common)
ADD_SUBDIRECTORY(calendar-client)
ADD_SUBDIRECTORY(calendar-service)
ADD_SUBDIRECTORY(schedule-plugin)
#ADD_SUBDIRECTORY(tests)

#前后端都有翻译所以将翻译放到更高层级
find_package(Qt5LinguistTools REQUIRED)
#lupdate start
#此处其实只有当没有自动翻译需要手动翻译.ts文件才有意义可以创建不同语言名称的ts文件,下同
set(TS_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/translations/${PROJECT_NAME}_en_US.ts"
)

# FIXME: Unit tests have not been maintained for a long time
# ADD_SUBDIRECTORY(tests)

# ##### Translation #####
# There are translations on both the front and back ends, so take the translations to a higher level
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS LinguistTools)

# In fact, it only makes sense to manually translate .ts files without automatic translation,
# and you can create TS files with different language names, the same below
find_program(LUPDATE_EXECUTABLE lupdate)
find_program(LRELEASE_EXECUTABLE lrelease)
set(TS_FILES "${CMAKE_CURRENT_SOURCE_DIR}/translations/${PROJECT_NAME}_en_US.ts")
set(TS_SERVICEFILES "${CMAKE_CURRENT_SOURCE_DIR}/translations/${PROJECT_NAME}-service_en_US.ts")

foreach(_ts_file ${TS_FILES})
execute_process(
COMMAND ${LUPDATE_EXECUTABLE} -recursive ${CMAKE_CURRENT_SOURCE_DIR}/calendar-client -ts ${_ts_file})
execute_process(
COMMAND ${LUPDATE_EXECUTABLE} -recursive ${CMAKE_CURRENT_SOURCE_DIR}/calendar-client -ts ${_ts_file})
endforeach()

set(TS_SERVICEFILES
"${CMAKE_CURRENT_SOURCE_DIR}/translations/${PROJECT_NAME}-service_en_US.ts"
)
foreach(_ts_file ${TS_SERVICEFILES})
execute_process(
COMMAND ${LUPDATE_EXECUTABLE} -recursive ${CMAKE_CURRENT_SOURCE_DIR}/calendar-service -ts ${_ts_file})
execute_process(
COMMAND ${LUPDATE_EXECUTABLE} -recursive ${CMAKE_CURRENT_SOURCE_DIR}/calendar-service -ts ${_ts_file})
endforeach()
#lupdate end

file (GLOB DTNG_TS_FILES translations/*.ts)
file(GLOB DTNG_TS_FILES translations/*.ts)

#lrelease start
#发布qm文件
find_program(LRELEASE_EXECUTABLE lrelease)
foreach(_ts_file ${DTNG_TS_FILES})
execute_process(COMMAND ${LRELEASE_EXECUTABLE} ${_ts_file})
execute_process(COMMAND ${LRELEASE_EXECUTABLE} ${_ts_file})
endforeach()
#lrelease end

qt5_create_translation(DTNG_QM_FILES
# lrelease end
if(SUPPORT_QT6)
qt_create_translation(DTNG_QM_FILES
${DTNG_TS_FILES}
${DTNG_QM_FILES}
)

)
else()
qt5_create_translation(DTNG_QM_FILES
${DTNG_TS_FILES}
${DTNG_QM_FILES}
)
endif()

file(GLOB APP_QM_FILES "translations/*.qm")
install(FILES ${APP_QM_FILES} DESTINATION ${CMAKE_INSTALL_DATADIR}/dde-calendar/translations)

# ##### Translation end #####

# 安装日志搜集工具的配置
install(FILES "org.deepin.calendar.json" DESTINATION ${CMAKE_INSTALL_DATADIR}/deepin-log-viewer/deepin-log.conf.d/)
7 changes: 2 additions & 5 deletions DDav/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ project(kdav)

# Find the library
find_package(PkgConfig REQUIRED)
find_package(Qt5 COMPONENTS
Core
DBus
REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core DBus)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
Expand All @@ -17,7 +14,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector-strong -z noexecstack

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
aux_source_directory(src KDAV_SRCS)
link_libraries(${Qt5CORE_LIBRARIES} ${Qt5DBus_LIBRARIES})
link_libraries(Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::DBus)
add_library(${PROJECT_NAME} STATIC ${KDAV_SRCS})


Loading

0 comments on commit e442181

Please sign in to comment.