Skip to content

Commit

Permalink
refacotr: Adaptation for Qt6
Browse files Browse the repository at this point in the history
Adaptation for Qt6

Log: Adaptation for Qt6
  • Loading branch information
Johnson-zs authored and deepin-bot[bot] committed Jul 31, 2023
1 parent e39c507 commit 090d084
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 90 deletions.
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ endif ()

set(CMAKE_CXX_FLAGS Release CACHE STRING "define CXXFLAGS")

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(BUILD_TESTING ON)
set(BUILD_EXAMPLES ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif ()
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
message("Using Qt version: ${QT_VERSION_MAJOR}")

if(QT_VERSION_MAJOR EQUAL "5")
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(BUILD_TESTING ON)
set(BUILD_EXAMPLES ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif()
endif()

find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core DBus)
find_package(DtkCore REQUIRED)

add_compile_definitions(QT_NO_SIGNALS_SLOTS_KEYWORDS)

# src
Expand Down
1 change: 0 additions & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Build-Depends:
libsecret-1-dev,
libpoppler-cpp-dev,
libudisks2-qt5-dev,
libdisomaster-dev,
libkf5codecs-dev,
libzip-dev,
libkf5archive-dev,
Expand Down
2 changes: 1 addition & 1 deletion examples/dtkburn/burn_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(Dtk COMPONENTS Core REQUIRED)
#find_package(dtkburn REQUIRED)

Expand Down
4 changes: 2 additions & 2 deletions examples/dtkcompressor/dtkcompressor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set(CMAKE_AUTOUIC ON)
PROJECT(testcompressor)


find_package(Qt5Widgets)
find_package(Qt${QT_VERSION_MAJOR}Widgets)
find_package(PkgConfig REQUIRED)
find_package(DtkCore REQUIRED)
find_package(KF5Codecs REQUIRED)
Expand All @@ -33,7 +33,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::DBus)

set(TARGET_LIBS
Qt5::Widgets
Qt${QT_VERSION_MAJOR}::Widgets
${DtkCore_LIBRARIES}
KF5::Codecs
Qt${QT_VERSION_MAJOR}::DBus
Expand Down
2 changes: 1 addition & 1 deletion examples/dtkio/io_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

find_package(Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(Dtk COMPONENTS Core REQUIRED)
#find_package(dtkio REQUIRED)

Expand Down
26 changes: 17 additions & 9 deletions examples/dtkmount/device_monitor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

find_package(Qt5 COMPONENTS Widgets Core Gui DBus LinguistTools REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Core Gui DBus LinguistTools REQUIRED)
find_package(Dtk COMPONENTS Widget Core Gui REQUIRED)
#find_package(dtkmount REQUIRED)

file(GLOB TS_FILES CONFIGURE_DEPENDS translations/*.ts)
file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS src/*.cpp include/*.h ${TS_FILES})

qt5_create_translation(
QM_FILES
${PROJECT_SOURCES}
${TS_FILES}
)
if(QT_VERSION_MAJOR EQUAL "6")
qt_create_translation(
QM_FILES
${PROJECT_SOURCES}
${TS_FILES}
)
else()
qt5_create_translation(
QM_FILES
${PROJECT_SOURCES}
${TS_FILES}
)
endif()

add_executable(
${PROJECT_NAME}
Expand All @@ -35,7 +43,7 @@ target_link_libraries(
${DtkWidget_LIBRARIES}
${DtkCore_LIBRARIES}
dtkmount
Qt5::Widgets
Qt5::Core
Qt5::DBus
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
)
6 changes: 3 additions & 3 deletions examples/dtksearch/search_client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})

find_package(Qt5 COMPONENTS Widgets Core Gui REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Core Gui REQUIRED)
find_package(Dtk COMPONENTS Widget Core Gui REQUIRED)

file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS ./*.cpp ./*.h)
Expand All @@ -25,7 +25,7 @@ target_link_libraries(
${DtkWidget_LIBRARIES}
${DtkCore_LIBRARIES}
dtksearch
Qt5::Widgets
Qt5::Core
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Core
)

4 changes: 2 additions & 2 deletions src/dtkcompressor/3rdparty/cliunarchiverplugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ project(${LIB_NAME})

#查找依赖关系的包信息
find_package(PkgConfig REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
find_package(KF5Codecs REQUIRED)
include(FindPkgConfig)

Expand All @@ -29,7 +29,7 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files})

#链接动静态库
target_link_libraries(${LIB_NAME}
Qt5::Widgets
Qt{QT_VERSION_MAJOR}::Widgets
KF5::Codecs
compressor-interface
)
13 changes: 2 additions & 11 deletions src/dtkcompressor/3rdparty/clizipplugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

find_package(PkgConfig REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5DBus REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5 REQUIRED Widgets)
find_package(Qt5Concurrent)
find_package(Qt5Xml)
find_package(Qt5Svg REQUIRED SvgWidgets)
find_package(KF5Codecs REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Widgets Network Concurrent Xml Svg)
include(FindPkgConfig)

pkg_search_module(DtkWidget REQUIRED dtkwidget)
Expand Down Expand Up @@ -47,6 +38,6 @@ file(GLOB_RECURSE json_files *.json)
include_directories(${PROJECT_SOURCE_DIR})

add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files})
target_link_libraries(${LIB_NAME} Qt5::Widgets)
target_link_libraries(${LIB_NAME} Qt${QT_VERSION_MAJOR}::Widgets)
target_link_libraries(${LIB_NAME} ${LIBS_INCLUDE_DIRS})
target_link_libraries( ${LIB_NAME} compressor-interface)
1 change: 1 addition & 0 deletions src/dtkcompressor/3rdparty/interface/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <QString>
#include <QLocale>
#include <QTextCodec>

class Common: public QObject
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

class KPluginLoader;
class QPluginLoader;
class QStringList;
class KPluginMetaDataPrivate;
class KAboutPerson;
class QObject;
Expand Down
2 changes: 2 additions & 0 deletions src/dtkcompressor/3rdparty/interface/process/kprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,13 @@ class KProcess : public QProcess
KProcessPrivate *const d_ptr;

private:
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// hide those
using QProcess::setReadChannelMode;
using QProcess::readChannelMode;
using QProcess::setProcessChannelMode;
using QProcess::processChannelMode;
#endif

Q_PRIVATE_SLOT(d_func(), void _k_forwardStdout())
Q_PRIVATE_SLOT(d_func(), void _k_forwardStderr())
Expand Down
1 change: 0 additions & 1 deletion src/dtkcompressor/3rdparty/libzipplugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ add_library(${LIB_NAME} SHARED ${c_files} ${json_files} ${h_files})

#链接动静态库
target_link_libraries(${LIB_NAME}
# Qt5::Core
KF5::Codecs
interfacecompressor
zip
Expand Down
30 changes: 21 additions & 9 deletions src/dtkcompressor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ if(NOT DEFINED HFILES_OUTPUT_PATH)
set(HFILES_OUTPUT_PATH ${CMAKE_BINARY_DIR}/include)
endif()
add_subdirectory(3rdparty)

find_package(KF5Codecs REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(DtkCore REQUIRED)
if(QT_VERSION_MAJOR EQUAL "6")
find_package(Qt6Core5Compat REQUIRED)
endif()

target_include_directories(${BIN_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include/${BIN_NAME}/)
target_include_directories(${BIN_NAME} PUBLIC ${KF5Codecs_INCLUDE_DIRS})
Expand All @@ -34,18 +36,28 @@ set_target_properties(${BIN_NAME} PROPERTIES

target_compile_definitions(${BIN_NAME} PRIVATE VERSION="${CMAKE_PROJECT_VERSION}")

if(QT_VERSION_MAJOR EQUAL "6")
target_link_libraries(${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
Qt6::Core5Compat
${DtkCore_LIBRARIES}
interfacecompressor
KF5::Codecs
)
else()
target_link_libraries(${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
${DtkCore_LIBRARIES}
interfacecompressor
KF5::Codecs
)
endif()


target_include_directories(${BIN_NAME} PUBLIC
Qt${QT_VERSION_MAJOR}::Core
${HFILES_OUTPUT_PATH}
)

target_link_libraries(${BIN_NAME} PRIVATE
Qt${QT_VERSION_MAJOR}::Core
${DtkCore_LIBRARIES}
interfacecompressor
KF5::Codecs
)

install(FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${BIN_NAME})
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})

Expand Down
3 changes: 3 additions & 0 deletions src/dtkcompressor/archivemanager/processopenthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "processopenthread.h"
#include "kprocess.h"

#include <QProcess>

DCOMPRESSOR_USE_NAMESPACE
ProcessOpenThread::ProcessOpenThread(QObject *parent)
: QThread(parent)
Expand Down
2 changes: 2 additions & 0 deletions src/dtkcompressor/archivemanager/processopenthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "plugin.h"

#include <QThread>
#include <QTextCodec>

#include "dcompressornamespace.h"
DCOMPRESSOR_BEGIN_NAMESPACE

Expand Down
2 changes: 2 additions & 0 deletions src/dtkcompressor/archivemanager/singlejob.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "commonstruct.h"
#include "queries.h"
#include "dcompressornamespace.h"

#include <QTextCodec>
#include <QThread>
#include <QElapsedTimer>

Expand Down
28 changes: 17 additions & 11 deletions src/dtkcompressor/archivemanager/uitools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ bool UiTools::isArchiveFile(const QString &strFileName)
bool UiTools::isExistMimeType(const QString &strMimeType, bool &bArchive)
{
QString conf = readConf();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QStringList confList = conf.split("\n", Qt::SkipEmptyParts);
#else
QStringList confList = conf.split("\n", QString::SkipEmptyParts);
#endif

bool exist = false;
for (int i = 0; i < confList.count(); i++) {
Expand Down Expand Up @@ -291,10 +295,10 @@ ReadOnlyArchiveInterface *UiTools::createInterface(const QString &fileName, cons
void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitType &eSplitType)
{
if (fileName.contains(".7z.")) {
QRegExp reg("^([\\s\\S]*\\.)7z\\.[0-9]{3}$");

if (reg.exactMatch(fileName)) {
fileName = reg.cap(1) + "7z.001";
QRegularExpression reg("^([\\s\\S]*\\.)7z\\.[0-9]{3}$");
QRegularExpressionMatch match = reg.match(fileName);
if (match.hasMatch()) {
fileName = match.captured(1) + "7z.001";
eSplitType = UnCompressParameter::ST_Other;
}
} else if (fileName.contains(".part") && fileName.endsWith(".rar")) {
Expand All @@ -309,11 +313,12 @@ void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitTy

eSplitType = UnCompressParameter::ST_Other;
} else if (fileName.contains(".zip.")) {
QRegExp reg("^([\\s\\S]*\\.)zip\\.[0-9]{3}$");
if (reg.exactMatch(fileName)) {
QFileInfo fi(reg.cap(1) + "zip.001");
QRegularExpression reg("^([\\s\\S]*\\.)zip\\.[0-9]{3}$");
QRegularExpressionMatch match = reg.match(fileName);
if (match.hasMatch()) {
QFileInfo fi(match.captured(1) + "zip.001");
if (fi.exists() == true) {
fileName = reg.cap(1) + "zip.001";
fileName = match.captured(1) + "zip.001";
eSplitType = UnCompressParameter::ST_Zip;
}
}
Expand All @@ -323,9 +328,10 @@ void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitTy
eSplitType = UnCompressParameter::ST_Zip;
}
} else if (fileName.contains(".z")) {
QRegExp reg("^([\\s\\S]*\\.)z[0-9]+$"); //
if (reg.exactMatch(fileName)) {
fileName = reg.cap(1) + "zip";
QRegularExpression reg("^([\\s\\S]*\\.)z[0-9]+$"); //
QRegularExpressionMatch match = reg.match(fileName);
if (match.hasMatch()) {
fileName = match.captured(1) + "zip";
QFileInfo fi(fileName);
if (fi.exists()) {
eSplitType = UnCompressParameter::ST_Zip;
Expand Down
8 changes: 7 additions & 1 deletion src/dtkio/dfilehelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,13 @@ QSet<QString> hideListFromUrl(const QUrl &url)
if (succ) {
if (contents && len > 0) {
QString dataStr(contents);
return QSet<QString>::fromList(dataStr.split('\n', QString::SkipEmptyParts));
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QStringList strs { dataStr.split('\n', Qt::SkipEmptyParts) };
return QSet<QString> { strs.begin(), strs.end() };
#else
const QStringList strs { dataStr.split('\n', QString::SkipEmptyParts) };
return QSet<QString>::fromList(strs);
#endif
}
} else {
qWarning() << "load .hidden fail, url: " << url << " error: " << error->code << " " << QString::fromLocal8Bit(error->message);
Expand Down
9 changes: 7 additions & 2 deletions src/dtkmount/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ set_source_files_properties(
${UDISKS2_XML}
PROPERTIES NO_NAMESPACE true INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/dbus/udisks2_dbus_common.h
)
qt5_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface)
qt5_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface)
if(QT_VERSION_MAJOR EQUAL "6")
qt_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface)
qt_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface)
else()
qt5_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface)
qt5_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface)
endif()

add_library(${BIN_NAME} SHARED
${INCLUDE_FILES}
Expand Down
6 changes: 5 additions & 1 deletion src/dtkmount/dbus/udisks2_dbus_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ OrgFreedesktopDBusObjectManagerInterface *objectManager()
qDBusRegisterMetaType<QPair<QString, QVariantMap>>();
qDBusRegisterMetaType<QMap<QDBusObjectPath, QMap<QString, QVariantMap>>>();

QMetaType::registerDebugStreamOperator<QList<QPair<QString, QVariantMap>>>();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// TODO
#else
QMetaType::registerDebugStreamOperator<QList<QPair<QString, QVariantMap>>>();
#endif
}

return omGlobal;
Expand Down
Loading

0 comments on commit 090d084

Please sign in to comment.