From bc97f001a9453deaf469f58387c6907ca6da52f4 Mon Sep 17 00:00:00 2001 From: re2zero Date: Mon, 6 Jan 2025 17:48:10 +0800 Subject: [PATCH] feat: Support Qt6 base Enable build with Qt6.8 base which depends kf6 codecs and archive packages, it compats Qt5 build. Log: Support Qt6 base --- .reuse/dep5 | 5 ++ 3rdparty/cli7zplugin/CMakeLists.txt | 9 +-- 3rdparty/cli7zplugin/cli7zplugin.cpp | 20 ++++-- 3rdparty/clirarplugin/CMakeLists.txt | 9 +-- 3rdparty/clirarplugin/clirarplugin.cpp | 15 ++++- 3rdparty/cliunarchiverplugin/CMakeLists.txt | 8 +-- 3rdparty/clizipplugin/CMakeLists.txt | 30 +++------ 3rdparty/interface/CMakeLists.txt | 26 +++++--- .../archiveinterface/cliinterface.cpp | 41 ++++++++----- 3rdparty/interface/common.cpp | 30 ++++++++- 3rdparty/interface/common.h | 1 + 3rdparty/interface/plugin/kpluginfactory.cpp | 2 +- 3rdparty/interface/plugin/kpluginfactory_p.h | 4 +- 3rdparty/interface/plugin/kpluginmetadata.cpp | 2 +- 3rdparty/interface/plugin/kpluginmetadata.h | 2 +- 3rdparty/interface/process/kprocess.cpp | 4 ++ 3rdparty/interface/process/kprocess.h | 2 + 3rdparty/interface/process/kpty.cpp | 2 +- 3rdparty/interface/process/kptyprocess.cpp | 2 + 3rdparty/interface/process/kptyprocess.h | 2 + 3rdparty/interface/queries.cpp | 25 +++++--- 3rdparty/interface/queries.h | 3 +- 3rdparty/libarchive/libarchive/CMakeLists.txt | 14 ++--- .../libarchive/libarchiveplugin.cpp | 9 ++- .../readonlylibarchiveplugin/CMakeLists.txt | 12 ++-- .../readwritelibarchiveplugin/CMakeLists.txt | 8 +-- 3rdparty/libminizipplugin/CMakeLists.txt | 10 ++- .../libminizipplugin/libminizipplugin.cpp | 12 +++- 3rdparty/libpigzplugin/CMakeLists.txt | 5 +- 3rdparty/libpigzplugin/libpigzplugin.cpp | 11 ++-- .../bz2plugin/CMakeLists.txt | 8 +-- .../gzplugin/CMakeLists.txt | 8 +-- .../singlefile/CMakeLists.txt | 11 ++-- .../singlefile/singlefileplugin.cpp | 12 ++++ .../xzplugin/CMakeLists.txt | 8 +-- 3rdparty/libzipplugin/CMakeLists.txt | 10 ++- 3rdparty/libzipplugin/libzipplugin.cpp | 8 ++- CMakeLists.txt | 23 +++++-- cmake/translation-generate.cmake | 39 ++++++++++++ debian/control | 26 +++++++- debian/rules | 28 +++++++-- src/CMakeLists.txt | 61 +++++++++++++------ src/main.cpp | 4 ++ src/source/common/calculatesizethread.cpp | 21 +++++++ src/source/common/uistruct.h | 2 +- src/source/common/uitools.cpp | 33 ++++++++-- .../dialog/openwithdialog/desktopfile.cpp | 1 + .../openwithdialog/mimesappsmanager.cpp | 6 +- .../dialog/openwithdialog/openwithdialog.cpp | 2 +- .../dialog/openwithdialog/openwithdialog.h | 4 +- src/source/dialog/openwithdialog/singleton.h | 12 ++++ src/source/dialog/settingdialog.cpp | 4 +- src/source/mainwindow.cpp | 53 +++++++++++++++- src/source/page/compresssettingpage.cpp | 22 +++++-- src/source/page/homepage.cpp | 2 +- src/source/page/loadingpage.cpp | 6 +- src/source/page/uncompresspage.cpp | 4 ++ src/source/qtcompat.h | 42 +++++++++++++ src/source/tree/compressview.cpp | 10 ++- src/source/tree/datamodel.cpp | 5 +- src/source/tree/datatreeview.cpp | 18 +++--- src/source/tree/treeheaderview.cpp | 17 ++++-- src/source/tree/treeheaderview.h | 4 +- src/source/tree/uncompressview.cpp | 8 +-- .../3rdparty/cli7zplugin/CMakeLists.txt | 28 ++++++--- .../3rdparty/cli7zplugin/ut_cli7zplugin.cpp | 7 ++- .../3rdparty/clirarplugin/CMakeLists.txt | 9 ++- .../3rdparty/interface/CMakeLists.txt | 25 +++++--- .../3rdparty/interface/ut_queries.cpp | 6 +- .../readonlylibarchiveplugin/CMakeLists.txt | 14 ++--- .../readwritelibarchiveplugin/CMakeLists.txt | 8 +-- .../3rdparty/libminizipplugin/CMakeLists.txt | 10 ++- .../3rdparty/libpigzplugin/CMakeLists.txt | 7 +-- .../bz2plugin/CMakeLists.txt | 14 ++--- .../bz2plugin/ut_bz2plugin.cpp | 8 +++ .../gzplugin/CMakeLists.txt | 8 +-- .../xzplugin/CMakeLists.txt | 8 +-- .../3rdparty/libzipplugin/CMakeLists.txt | 11 ++-- tests/UnitTest/src/CMakeLists.txt | 47 ++++++++------ .../src/source/common/ut_commonstub.cpp | 4 +- .../openwithdialog/ut_openwithdialog.cpp | 4 ++ .../source/page/ut_compresssettingpage.cpp | 8 +-- .../UnitTest/src/source/page/ut_homepage.cpp | 13 +++- .../src/source/page/ut_uncompresspage.cpp | 4 ++ .../UnitTest/src/source/tree/ut_datamodel.cpp | 4 ++ .../src/source/tree/ut_treeheaderview.cpp | 4 ++ .../src/source/tree/ut_uncompressview.cpp | 4 ++ 87 files changed, 786 insertions(+), 316 deletions(-) create mode 100644 cmake/translation-generate.cmake create mode 100644 src/source/qtcompat.h diff --git a/.reuse/dep5 b/.reuse/dep5 index 218371cfe..c3b8d001f 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -23,6 +23,11 @@ Files: debian/* Copyright: None License: CC0-1.0 +# cmake +Files: cmake/* +Copyright: UnionTech Software Technology Co., Ltd. +License: CC0-1.0 + # rpm Files: rpm/* Copyright: None diff --git a/3rdparty/cli7zplugin/CMakeLists.txt b/3rdparty/cli7zplugin/CMakeLists.txt index 5de92f14f..a26842fae 100644 --- a/3rdparty/cli7zplugin/CMakeLists.txt +++ b/3rdparty/cli7zplugin/CMakeLists.txt @@ -7,8 +7,9 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) + include(FindPkgConfig) #指定头文件路径 @@ -28,7 +29,7 @@ add_library(${LIB_NAME} SHARED ${c_files} ${json_files} ${h_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-interface ) diff --git a/3rdparty/cli7zplugin/cli7zplugin.cpp b/3rdparty/cli7zplugin/cli7zplugin.cpp index 0a7b8ee55..82cff7b82 100644 --- a/3rdparty/cli7zplugin/cli7zplugin.cpp +++ b/3rdparty/cli7zplugin/cli7zplugin.cpp @@ -248,18 +248,28 @@ bool Cli7zPlugin::readListLine(const QString &line) m_fileEntry.strFullPath = entryFilename; // 文件名称 - const QStringList pieces = entryFilename.split(QLatin1Char('/'), QString::SkipEmptyParts); + const QStringList pieces = entryFilename.split(QLatin1Char('/'), + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QString::SkipEmptyParts + #else + Qt::SkipEmptyParts + #endif + ); m_fileEntry.strFileName = pieces.isEmpty() ? QString() : pieces.last(); } else if (line.startsWith(QLatin1String("Size = "))) { // 单文件实际大小 - m_fileEntry.qSize = line.midRef(7).trimmed().toLongLong(); + m_fileEntry.qSize = line.mid(7).trimmed().toLongLong(); // 压缩包内所有文件总大小 stArchiveData.qSize += m_fileEntry.qSize; } else if (line.startsWith(QLatin1String("Modified = "))) { // 文件最后修改时间 m_fileEntry.uLastModifiedTime = QDateTime::fromString(line.mid(11).trimmed(), - QStringLiteral("yyyy-MM-dd hh:mm:ss")).toTime_t(); + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QStringLiteral("yyyy-MM-dd hh:mm:ss")).toTime_t(); + #else + QStringLiteral("yyyy-MM-dd hh:mm:ss")).toSecsSinceEpoch(); + #endif if (ArchiveTypeIso == m_archiveType || ArchiveTypeUdf == m_archiveType) { // 读取的压缩包是iso、udf文件,读到Modified的时候已经结束了 // QString name = m_fileEntry.strFullPath; @@ -276,7 +286,7 @@ bool Cli7zPlugin::readListLine(const QString &line) m_fileEntry.reset(); } } else if (line.startsWith(QLatin1String("Attributes = "))) { // 文件权限 - const QStringRef attributes = line.midRef(13).trimmed(); + const QString attributes = line.mid(13).trimmed(); // D开头为文件夹 if (attributes.startsWith(QLatin1Char('D'))) { @@ -303,7 +313,7 @@ bool Cli7zPlugin::readListLine(const QString &line) // clear m_fileEntry m_fileEntry.reset(); } else if (line.startsWith(QLatin1String("Folder = "))) { // 是否文件夹 - const QStringRef folder = line.midRef(9, 1); + const QString folder = line.mid(9, 1); // "+" 为文件夹 if (0 == folder.compare(QLatin1String("+"))) { diff --git a/3rdparty/clirarplugin/CMakeLists.txt b/3rdparty/clirarplugin/CMakeLists.txt index 7999f02aa..5b2cbbf1a 100644 --- a/3rdparty/clirarplugin/CMakeLists.txt +++ b/3rdparty/clirarplugin/CMakeLists.txt @@ -7,8 +7,9 @@ project(${LIB_NAME}) #设置项目名称 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) + include(FindPkgConfig) #指定头文件路径 @@ -28,7 +29,7 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-interface ) diff --git a/3rdparty/clirarplugin/clirarplugin.cpp b/3rdparty/clirarplugin/clirarplugin.cpp index 4f9d80913..562a14553 100644 --- a/3rdparty/clirarplugin/clirarplugin.cpp +++ b/3rdparty/clirarplugin/clirarplugin.cpp @@ -216,7 +216,13 @@ bool CliRarPlugin::readListLine(const QString &line) m_fileEntry.strFullPath = parseLineRight; // 文件名称 - const QStringList pieces = m_fileEntry.strFullPath.split(QLatin1Char('/'), QString::SkipEmptyParts); + const QStringList pieces = m_fileEntry.strFullPath.split(QLatin1Char('/'), + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QString::SkipEmptyParts + #else + Qt::SkipEmptyParts + #endif + ); m_fileEntry.strFileName = pieces.isEmpty() ? QString() : pieces.last(); } else if (parseLineLeft == QLatin1String("Type")) { if (parseLineRight == QLatin1String("Directory")) { @@ -241,7 +247,12 @@ bool CliRarPlugin::readListLine(const QString &line) QString time = line.left((line.length() - 10)); // 文件最后修改时间 m_fileEntry.uLastModifiedTime = QDateTime::fromString(time.right(time.length() - 14), - QStringLiteral("yyyy-MM-dd hh:mm:ss")).toTime_t(); + QStringLiteral("yyyy-MM-dd hh:mm:ss")) + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + .toTime_t(); + #else + .toSecsSinceEpoch(); + #endif QString name = m_fileEntry.strFullPath; diff --git a/3rdparty/cliunarchiverplugin/CMakeLists.txt b/3rdparty/cliunarchiverplugin/CMakeLists.txt index 7fa2f6825..c5e551c18 100644 --- a/3rdparty/cliunarchiverplugin/CMakeLists.txt +++ b/3rdparty/cliunarchiverplugin/CMakeLists.txt @@ -7,8 +7,8 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) include(FindPkgConfig) @@ -29,7 +29,7 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-interface ) diff --git a/3rdparty/clizipplugin/CMakeLists.txt b/3rdparty/clizipplugin/CMakeLists.txt index 69c0bacb4..213e16521 100644 --- a/3rdparty/clizipplugin/CMakeLists.txt +++ b/3rdparty/clizipplugin/CMakeLists.txt @@ -10,28 +10,12 @@ 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) -include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) -include_directories(${DtkWidget_INCLUDE_DIRS}) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Widget) -pkg_search_module(DtkCore REQUIRED dtkcore) -include_directories(${DtkCore_INCLUDE_DIRS}) +include(FindPkgConfig) -set(LIBS_INCLUDE_DIRS - ${DtkWidget_LIBRARIES} - ${DtkCore_LIBRARIES} -) include_directories(${PROJECT_SOURCE_DIR}/../ChardetDetector) @@ -47,6 +31,10 @@ 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} ${LIBS_INCLUDE_DIRS}) +target_link_libraries(${LIB_NAME} + Qt${QT_DESIRED_VERSION}::Widgets + Dtk${DTK_VERSION_MAJOR}::Widget + Dtk${DTK_VERSION_MAJOR}::Core + ) + target_link_libraries( ${LIB_NAME} compressor-interface) diff --git a/3rdparty/interface/CMakeLists.txt b/3rdparty/interface/CMakeLists.txt index 754cb7b83..77e9a1665 100644 --- a/3rdparty/interface/CMakeLists.txt +++ b/3rdparty/interface/CMakeLists.txt @@ -7,11 +7,17 @@ project(interface) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) + +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Widget) + +if (QT_DESIRED_VERSION MATCHES 6) + find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Core5Compat) +endif() + include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) pkg_search_module(GOBJECT REQUIRED gobject-2.0) pkg_search_module(MOUNT REQUIRED mount) @@ -20,10 +26,7 @@ file(GLOB_RECURSE c_files RELATIVE ${PROJECT_SOURCE_DIR} *.cpp) file(GLOB_RECURSE h_files RELATIVE ${PROJECT_SOURCE_DIR} *.h) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${MOUNT_INCLUDE_DIRS}) -include_directories(${Qt5Widgets_INCLUDE_DIRS}) -include_directories(${KF5Codecs_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${PROJECT_SOURCE_DIR}/archiveinterface) include_directories(${PROJECT_SOURCE_DIR}/plugin) @@ -59,10 +62,15 @@ add_library(${LIB_NAME} SHARED ${h_files} ${c_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs - ${DtkWidget_LIBRARIES} + Qt${QT_DESIRED_VERSION}::Widgets + Dtk${DTK_VERSION_MAJOR}::Widget + KF${KF_VERSION_MAJOR}::Codecs ${MOUNT_LIBRARIES} compressor-ChardetDetector ) +if (QT_DESIRED_VERSION MATCHES 6) + target_link_libraries(${LIB_NAME} + Qt${QT_DESIRED_VERSION}::Core5Compat + ) +endif() diff --git a/3rdparty/interface/archiveinterface/cliinterface.cpp b/3rdparty/interface/archiveinterface/cliinterface.cpp index c7de81bcb..d66c64a5b 100644 --- a/3rdparty/interface/archiveinterface/cliinterface.cpp +++ b/3rdparty/interface/archiveinterface/cliinterface.cpp @@ -48,7 +48,11 @@ CliInterface::CliInterface(QObject *parent, const QVariantList &args) { // m_bHandleCurEntry = true; setWaitForFinishedSignal(true); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (QMetaType::type("QProcess::ExitStatus") == 0) { +#else + if (!QMetaType::fromName("QProcess::ExitStatus").isValid()) { +#endif qRegisterMetaType("QProcess::ExitStatus"); } @@ -342,7 +346,13 @@ PluginFinishType CliInterface::addFiles(const QList &files, const Com QDir::setCurrent(m_extractTempDir->path()); // 添加临时路径中的第一层文件(夹) - fileList.append(destinationPath.split(QLatin1Char('/'), QString::SkipEmptyParts).at(0)); +fileList.append(destinationPath.split(QLatin1Char('/'), +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QString::SkipEmptyParts +#else + Qt::SkipEmptyParts +#endif +).at(0)); } else { // 压缩、向压缩包第一层文件追加压缩 QList tempfiles = files; // 获取待压缩的文件 @@ -768,7 +778,7 @@ void CliInterface::handleProgress(const QString &line) if (m_process && m_process->program().at(0).contains("7z")) { // 解析7z相关进度、文件名 int pos = line.indexOf(QLatin1Char('%')); if (pos > 1) { - int percentage = line.midRef(pos - 3, 3).toInt(); + int percentage = line.mid(pos - 3, 3).toInt(); if (percentage > 0) { if (line.contains("\b\b\b\b") == true) { QString strfilename; @@ -786,7 +796,7 @@ void CliInterface::handleProgress(const QString &line) } if (count > 0) { - strfilename = line.midRef(count + 2).toString(); // 文件名 + strfilename = line.mid(count + 2); // 文件名 // 右键 解压到当前文件夹 if (m_workStatus == WT_Extract && !m_extractOptions.bExistList && m_indexOfListRootEntry == 0) { m_indexOfListRootEntry++; @@ -819,18 +829,18 @@ void CliInterface::handleProgress(const QString &line) } else if (m_process && m_process->program().at(0).contains("unrar")) { // 解析rar相关进度、文件名 int pos = line.indexOf(QLatin1Char('%')); if (pos > 1) { - int percentage = line.midRef(pos - 3, 3).toInt(); + int percentage = line.mid(pos - 3, 3).toInt(); emit signalprogress(percentage); } - QStringRef strfilename; + // QStringRef strfilename; QString fileName; if (line.startsWith("Extracting")) { // 普通文件 - strfilename = line.midRef(12, pos - 24); - fileName = strfilename.toString(); + fileName = line.mid(12, pos - 24); + // fileName = strfilename.toString(); } else if (line.startsWith("Creating")) { // 文件夹 - strfilename = line.midRef(10, pos - 22); - fileName = strfilename.toString(); + fileName = line.mid(10, pos - 22); + // fileName = strfilename.toString(); } if (!fileName.isEmpty()) { @@ -1240,7 +1250,7 @@ void CliInterface::readStdout(bool handleAll) } // 处理命令行输出 - for (const QByteArray &line : qAsConst(lines)) { + for (const QByteArray &line : lines) { // 第二个判断条件是处理rar的list,当rar文件含有comment信息的时候需要根据空行解析 if (!line.isEmpty() || (m_listEmptyLines && m_workStatus == WT_List)) { if (!handleLine(QString::fromLocal8Bit(line), m_workStatus)) { @@ -1343,17 +1353,18 @@ void CliInterface::getChildProcessId(qint64 processId, const QStringList &listKe QList lines = dd.split('\n'); if (lines[0].contains(strProcessId.toUtf8())) { // 从包含有processId这一行开始处理 - for (const QByteArray &line : qAsConst(lines)) { + for (const QByteArray &line : lines) { - for (const QString &strKey : qAsConst(listKey)) { + for (const QString &strKey : listKey) { QString str = QString("-%1(").arg(strKey); - int iCount = line.count(str.toStdString().c_str()); // 多个子进程都需要获取到 + QByteArray strUtf8 = str.toUtf8(); // 将QString转换为QByteArray + int iCount = line.count(strUtf8.constData()); // 多个子进程都需要获取到 int iIndex = 0; for (int i = 0; i < iCount; ++i) { - int iStartIndex = line.indexOf(str, iIndex); + int iStartIndex = line.indexOf(strUtf8, iIndex); // 使用QByteArray类型的参数 int iEndIndex = line.indexOf(")", iStartIndex); if (0 < iStartIndex && 0 < iEndIndex) { - childprocessid.append(line.mid(iStartIndex + str.length(), iEndIndex - iStartIndex - str.length()).toInt()); // 取-7z(3971)中间的进程号 + childprocessid.append(line.mid(iStartIndex + strUtf8.length(), iEndIndex - iStartIndex - strUtf8.length()).toInt()); // 取-7z(3971)中间的进程号 } iIndex = iStartIndex + 1; } diff --git a/3rdparty/interface/common.cpp b/3rdparty/interface/common.cpp index dd0b3402a..c9a8082d4 100644 --- a/3rdparty/interface/common.cpp +++ b/3rdparty/interface/common.cpp @@ -13,6 +13,15 @@ #include #include #include + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#include +#else +#include +#include +#endif + #include #include @@ -59,7 +68,7 @@ break; default: // full-width character, emoji, 常用标点, 拉丁文补充1,天城文补充,CJK符号和标点符号(如:【】) - if ((ch.unicode() >= 0xff00 && ch <= 0xffef) + if ((ch.unicode() >= 0xff00 && ch.unicode() <= 0xffef) || (ch.unicode() >= 0x2600 && ch.unicode() <= 0x27ff) || (ch.unicode() >= 0x2000 && ch.unicode() <= 0x206f) || (ch.unicode() >= 0x80 && ch.unicode() <= 0xff) @@ -136,7 +145,13 @@ QByteArray Common::detectEncode(const QByteArray &data, const QString &fileName) QString detectedResult; float chardetconfidence = 0; QString str(data); - bool bFlag = str.contains(QRegExp("[\\x4e00-\\x9fa5]+")); //匹配的是中文 + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QRegularExpression chineseRegExp("[\\x4e00-\\x9fa5]+"); +#else + QRegExp chineseRegExp("[\\x4e00-\\x9fa5]+"); +#endif + bool bFlag = str.contains(chineseRegExp); //匹配的是中文 if (bFlag) { QByteArray newData = data; newData += "为增加探测率保留的中文"; //手动添加中文字符,避免字符长度太短而导致判断编码错误 @@ -277,7 +292,12 @@ QByteArray Common::textCodecDetect(const QByteArray &data, const QString &fileNa QTextStream stream(data); pattern.setPatternOptions(QRegularExpression::DontCaptureOption | QRegularExpression::CaseInsensitiveOption); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + stream.setCodec("latin1"); +#else + stream.setEncoding(QStringConverter::Latin1); +#endif while (!stream.atEnd()) { const QString &_data = stream.readLine(); @@ -464,6 +484,12 @@ bool Common::findDlnfsPath(const QString &target, Compare func) bool IsMtpFileOrDirectory(QString path) noexcept { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) const static QRegExp regexp("((/run/user/[0-9]+/gvfs/mtp:)|(/root/.gvfs/mtp:)).+"); return regexp.exactMatch(path); +#else + const static QRegularExpression regexp("((/run/user/[0-9]+/gvfs/mtp:)|(/root/.gvfs/mtp:)).+"); + QRegularExpressionMatch match = regexp.match(path); + return match.hasMatch(); +#endif } diff --git a/3rdparty/interface/common.h b/3rdparty/interface/common.h index a3619e569..b439c8b4c 100644 --- a/3rdparty/interface/common.h +++ b/3rdparty/interface/common.h @@ -7,6 +7,7 @@ #include #include +#include #include //文件大小10M diff --git a/3rdparty/interface/plugin/kpluginfactory.cpp b/3rdparty/interface/plugin/kpluginfactory.cpp index 425587530..0715d9538 100644 --- a/3rdparty/interface/plugin/kpluginfactory.cpp +++ b/3rdparty/interface/plugin/kpluginfactory.cpp @@ -81,7 +81,7 @@ void KPluginFactory::registerPlugin(const QString &keyword, const QMetaObject *m } } - d->createInstanceHash.insertMulti(keyword, KPluginFactoryPrivate::Plugin(metaObject, instanceFunction)); + d->createInstanceHash.insert(keyword, KPluginFactoryPrivate::Plugin(metaObject, instanceFunction)); } } diff --git a/3rdparty/interface/plugin/kpluginfactory_p.h b/3rdparty/interface/plugin/kpluginfactory_p.h index 317b4e057..f957f2815 100644 --- a/3rdparty/interface/plugin/kpluginfactory_p.h +++ b/3rdparty/interface/plugin/kpluginfactory_p.h @@ -20,7 +20,7 @@ #include "kpluginfactory.h" -#include +#include class KPluginFactoryPrivate { @@ -37,7 +37,7 @@ class KPluginFactoryPrivate { } - QHash createInstanceHash; + QMultiHash createInstanceHash; QString catalogName; bool catalogInitialized; diff --git a/3rdparty/interface/plugin/kpluginmetadata.cpp b/3rdparty/interface/plugin/kpluginmetadata.cpp index 332aa17e8..b74dae70f 100644 --- a/3rdparty/interface/plugin/kpluginmetadata.cpp +++ b/3rdparty/interface/plugin/kpluginmetadata.cpp @@ -168,7 +168,7 @@ QJsonValue KPluginMetaData::readTranslatedValue(const QJsonObject &jo, const QSt return it.value(); } - const QStringRef language = languageWithCountry.midRef(0, languageWithCountry.indexOf(QLatin1Char('_'))); + const QString language = languageWithCountry.mid(0, languageWithCountry.indexOf(QLatin1Char('_'))); it = jo.constFind(key + QLatin1Char('[') + language + QLatin1Char(']')); if (it != jo.constEnd()) { return it.value(); diff --git a/3rdparty/interface/plugin/kpluginmetadata.h b/3rdparty/interface/plugin/kpluginmetadata.h index 7af406c9e..817db1c99 100644 --- a/3rdparty/interface/plugin/kpluginmetadata.h +++ b/3rdparty/interface/plugin/kpluginmetadata.h @@ -26,7 +26,7 @@ class KPluginLoader; class QPluginLoader; -class QStringList; +// class QStringList; class KPluginMetaDataPrivate; class KAboutPerson; class QObject; diff --git a/3rdparty/interface/process/kprocess.cpp b/3rdparty/interface/process/kprocess.cpp index 6df566796..980576654 100644 --- a/3rdparty/interface/process/kprocess.cpp +++ b/3rdparty/interface/process/kprocess.cpp @@ -404,7 +404,11 @@ int KProcess::startDetached(const QStringList &argv) int KProcess::pid() const { #ifdef Q_OS_UNIX +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) return (int) QProcess::pid(); +#else + return QProcess::processId(); +#endif #else return QProcess::pid() ? QProcess::pid()->dwProcessId : 0; #endif diff --git a/3rdparty/interface/process/kprocess.h b/3rdparty/interface/process/kprocess.h index 9b22318fa..aa69f3291 100644 --- a/3rdparty/interface/process/kprocess.h +++ b/3rdparty/interface/process/kprocess.h @@ -336,8 +336,10 @@ class KProcess : public QProcess private: // hide those +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) using QProcess::setReadChannelMode; using QProcess::readChannelMode; +#endif using QProcess::setProcessChannelMode; using QProcess::processChannelMode; diff --git a/3rdparty/interface/process/kpty.cpp b/3rdparty/interface/process/kpty.cpp index d0155408d..42ce3aa0f 100644 --- a/3rdparty/interface/process/kpty.cpp +++ b/3rdparty/interface/process/kpty.cpp @@ -338,7 +338,7 @@ bool KPty::open() !d->chownpty(true)) { qWarning() << "chownpty failed for device " << ptyName << "::" << d->ttyName - << "\nThis means the communication can be eavesdropped." << endl; + << "\nThis means the communication can be eavesdropped."; } #if defined (HAVE__GETPTY) || defined (HAVE_GRANTPT) diff --git a/3rdparty/interface/process/kptyprocess.cpp b/3rdparty/interface/process/kptyprocess.cpp index b61fd53a0..1f750d0ec 100644 --- a/3rdparty/interface/process/kptyprocess.cpp +++ b/3rdparty/interface/process/kptyprocess.cpp @@ -119,6 +119,7 @@ KPtyDevice *KPtyProcess::pty() const return d->pty; } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void KPtyProcess::setupChildProcess() { Q_D(KPtyProcess); @@ -140,5 +141,6 @@ void KPtyProcess::setupChildProcess() KProcess::setupChildProcess(); } +#endif //#include "kptyprocess.moc" diff --git a/3rdparty/interface/process/kptyprocess.h b/3rdparty/interface/process/kptyprocess.h index ae1166e60..d18ef4c13 100644 --- a/3rdparty/interface/process/kptyprocess.h +++ b/3rdparty/interface/process/kptyprocess.h @@ -144,7 +144,9 @@ class KPtyProcess : public KProcess /** * @reimp */ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) void setupChildProcess() override; +#endif private: Q_PRIVATE_SLOT(d_func(), void _k_onStateChanged(QProcess::ProcessState)) diff --git a/3rdparty/interface/queries.cpp b/3rdparty/interface/queries.cpp index d4302e73e..40c747e72 100644 --- a/3rdparty/interface/queries.cpp +++ b/3rdparty/interface/queries.cpp @@ -61,7 +61,11 @@ NewStr autoCutText(const QString &text, DLabel *pDesLbl) QFont font; // 应用使用字体对象 QFontMetrics font_label(font); QString strText = text; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) int titlewidth = font_label.width(strText); +#else + int titlewidth = font_label.horizontalAdvance(strText); +#endif QString str; NewStr newstr; int width = pDesLbl->width(); @@ -69,11 +73,14 @@ NewStr autoCutText(const QString &text, DLabel *pDesLbl) newstr.strList.append(strText); newstr.resultStr += strText; } else { - for (int i = 0; i < strText.count(); i++) { + for (int i = 0; i < strText.size(); i++) { str += strText.at(i); - +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (font_label.width(str) > width) { //根据label宽度调整每行字符数 - str.remove(str.count() - 1, 1); +#else + if (font_label.horizontalAdvance(str) > width) { //根据label宽度调整每行字符数 +#endif + str.remove(str.size() - 1, 1); newstr.strList.append(str); newstr.resultStr += str + "\n"; str.clear(); @@ -314,20 +321,20 @@ void OverwriteQuery::autoFeed(DLabel *label1, DLabel *label2, CustomDDialog *dia void OverwriteQuery::setWidgetColor(QWidget *pWgt, DPalette::ColorRole ct, double alphaF) { - DPalette palette = DApplicationHelper::instance()->palette(pWgt); + DPalette palette = DPaletteHelper::instance()->palette(pWgt); QColor color = palette.color(ct); color.setAlphaF(alphaF); - palette.setColor(DPalette::Foreground, color); - DApplicationHelper::instance()->setPalette(pWgt, palette); + palette.setColor(DPalette::Window, color); + pWgt->setPalette(palette); } void OverwriteQuery::setWidgetType(QWidget *pWgt, DPalette::ColorType ct, double alphaF) { - DPalette palette = DApplicationHelper::instance()->palette(pWgt); + DPalette palette = DPaletteHelper::instance()->palette(pWgt); QColor color = palette.color(ct); color.setAlphaF(alphaF); - palette.setColor(DPalette::Foreground, color); - DApplicationHelper::instance()->setPalette(pWgt, palette); + palette.setColor(DPalette::WindowText, color); + pWgt->setPalette(palette); } diff --git a/3rdparty/interface/queries.h b/3rdparty/interface/queries.h index e39c80b86..17ea6c6c3 100644 --- a/3rdparty/interface/queries.h +++ b/3rdparty/interface/queries.h @@ -5,7 +5,8 @@ #ifndef QUERIES_H #define QUERIES_H -#include +#include +#include #include #include diff --git a/3rdparty/libarchive/libarchive/CMakeLists.txt b/3rdparty/libarchive/libarchive/CMakeLists.txt index bc4484959..60a4c9202 100644 --- a/3rdparty/libarchive/libarchive/CMakeLists.txt +++ b/3rdparty/libarchive/libarchive/CMakeLists.txt @@ -7,16 +7,15 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) + +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Core Widget) find_package(LibArchive REQUIRED) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) -#pkg_search_module(GOBJECT REQUIRED gobject-2.0) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) @@ -39,8 +38,9 @@ add_library(${LIB_NAME} STATIC ${h_files} ${c_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + Dtk${DTK_VERSION_MAJOR}::Widget + KF${KF_VERSION_MAJOR}::Codecs archive # ${GOBJECT_LIBRARIES} compressor-interface diff --git a/3rdparty/libarchive/libarchive/libarchiveplugin.cpp b/3rdparty/libarchive/libarchive/libarchiveplugin.cpp index 7900701c8..2f3f61fa7 100644 --- a/3rdparty/libarchive/libarchive/libarchiveplugin.cpp +++ b/3rdparty/libarchive/libarchive/libarchiveplugin.cpp @@ -213,7 +213,7 @@ PluginFinishType LibarchivePlugin::extractFiles(const QList &files, c // 提取:过滤选中的文件以及选中目录下所有文件 if (!extractAll) { bool flag = false; - foreach (auto tmp, qAsConst(files)) { + foreach (auto tmp, files) { if (tmp.isDirectory) { if (entryName.startsWith(tmp.strFullPath)) { flag = true; @@ -786,7 +786,12 @@ void LibarchivePlugin::emitEntryForIndex(archive_entry *aentry) m_archiveEntryStat.strFullPath = entryName; // 文件名 - const QStringList pieces = m_archiveEntryStat.strFullPath.split(QLatin1Char('/'), QString::SkipEmptyParts); + const QStringList pieces = m_archiveEntryStat.strFullPath.split(QLatin1Char('/'), + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QString::SkipEmptyParts); + #else + Qt::SkipEmptyParts); + #endif m_archiveEntryStat.strFileName = pieces.last(); diff --git a/3rdparty/libarchive/readonlylibarchiveplugin/CMakeLists.txt b/3rdparty/libarchive/readonlylibarchiveplugin/CMakeLists.txt index 7268f3975..462a736f4 100644 --- a/3rdparty/libarchive/readonlylibarchiveplugin/CMakeLists.txt +++ b/3rdparty/libarchive/readonlylibarchiveplugin/CMakeLists.txt @@ -6,9 +6,9 @@ set(LIB_NAME readonlylibarchiveplugin) project(${LIB_NAME}) #查找依赖关系的包信息 -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) -find_package(KF5Archive) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) +find_package(KF${KF_VERSION_MAJOR}Archive REQUIRED) #指定头文件路径 include_directories(${PROJECT_SOURCE_DIR}) @@ -27,9 +27,9 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Archive - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs + KF${KF_VERSION_MAJOR}::Archive compressor-archive ) diff --git a/3rdparty/libarchive/readwritelibarchiveplugin/CMakeLists.txt b/3rdparty/libarchive/readwritelibarchiveplugin/CMakeLists.txt index 5a0810280..b88868e6e 100644 --- a/3rdparty/libarchive/readwritelibarchiveplugin/CMakeLists.txt +++ b/3rdparty/libarchive/readwritelibarchiveplugin/CMakeLists.txt @@ -7,8 +7,8 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) include(FindPkgConfig) #指定头文件路径 @@ -28,8 +28,8 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-archive ) diff --git a/3rdparty/libminizipplugin/CMakeLists.txt b/3rdparty/libminizipplugin/CMakeLists.txt index e70400b42..e025dfbc2 100644 --- a/3rdparty/libminizipplugin/CMakeLists.txt +++ b/3rdparty/libminizipplugin/CMakeLists.txt @@ -7,15 +7,13 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) find_package(ZLIB REQUIRED) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) @@ -32,8 +30,8 @@ add_library(${LIB_NAME} SHARED ${c_files} ${json_files} ${h_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-interface minizip ) diff --git a/3rdparty/libminizipplugin/libminizipplugin.cpp b/3rdparty/libminizipplugin/libminizipplugin.cpp index 2049c475a..e3e30778f 100644 --- a/3rdparty/libminizipplugin/libminizipplugin.cpp +++ b/3rdparty/libminizipplugin/libminizipplugin.cpp @@ -250,7 +250,13 @@ bool LibminizipPlugin::handleArchiveData(unzFile zipfile) // 全路径 entry.strFullPath = name; // 文件名 - const QStringList pieces = entry.strFullPath.split(QLatin1Char('/'), QString::SkipEmptyParts); + const QStringList pieces = entry.strFullPath.split(QLatin1Char('/'), + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QString::SkipEmptyParts + #else + Qt::SkipEmptyParts + #endif + ); entry.strFileName = pieces.isEmpty() ? QString() : pieces.last(); // 是否是文件夹 entry.isDirectory = name.endsWith(QDir::separator()); @@ -266,7 +272,11 @@ bool LibminizipPlugin::handleArchiveData(unzFile zipfile) QDateTime datetime; datetime.setDate(QDate(int(file_info.tmu_date.tm_year), int(file_info.tmu_date.tm_mon + 1), int(file_info.tmu_date.tm_mday))); datetime.setTime(QTime(int(file_info.tmu_date.tm_hour), int(file_info.tmu_date.tm_min), int(file_info.tmu_date.tm_sec))); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) entry.uLastModifiedTime = uint(datetime.toTime_t()); +#else + entry.uLastModifiedTime = uint(datetime.toSecsSinceEpoch()); +#endif handleEntry(entry); diff --git a/3rdparty/libpigzplugin/CMakeLists.txt b/3rdparty/libpigzplugin/CMakeLists.txt index 608e4a1c0..29e30b29e 100644 --- a/3rdparty/libpigzplugin/CMakeLists.txt +++ b/3rdparty/libpigzplugin/CMakeLists.txt @@ -7,8 +7,7 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) include(FindPkgConfig) #指定头文件路径 @@ -28,6 +27,6 @@ add_library(${LIB_NAME} SHARED ${c_files} ${json_files} ${h_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets + Qt${QT_DESIRED_VERSION}::Widgets compressor-interface ) diff --git a/3rdparty/libpigzplugin/libpigzplugin.cpp b/3rdparty/libpigzplugin/libpigzplugin.cpp index a96ccf24e..1cf934556 100644 --- a/3rdparty/libpigzplugin/libpigzplugin.cpp +++ b/3rdparty/libpigzplugin/libpigzplugin.cpp @@ -307,13 +307,14 @@ void LibPigzPlugin::getChildProcessId(qint64 processId, const QStringList &listK QList lines = dd.split('\n'); if (lines.count() > 0 && lines[0].contains(strProcessId.toUtf8())) { // 从包含有processId这一行开始处理 - for (const QByteArray &line : qAsConst(lines)) { - for (const QString &strKey : qAsConst(listKey)) { + for (const QByteArray &line : lines) { + for (const QString &strKey : listKey) { QString str = QString("-%1(").arg(strKey); - int iCount = line.count(str.toStdString().c_str()); // 多个子进程都需要获取到 + QByteArray ba = str.toUtf8(); // 将QString转换为QByteArray + int iCount = line.count(ba); // 直接使用QByteArray int iIndex = 0; for (int i = 0; i < iCount; ++i) { - int iStartIndex = line.indexOf(str, iIndex); + int iStartIndex = line.indexOf(ba, iIndex); int iEndIndex = line.indexOf(")", iStartIndex); if (0 < iStartIndex && 0 < iEndIndex) { childprocessid.append(line.mid(iStartIndex + str.length(), iEndIndex - iStartIndex - str.length()).toInt()); // 取-7z(3971)中间的进程号 @@ -346,7 +347,7 @@ void LibPigzPlugin::readStdout(bool) QList lines = m_stdOutData.split('\n'); m_stdOutData = lines.takeLast(); // 处理命令行输出 - for (const QByteArray &line : qAsConst(lines)) { + for (const QByteArray &line : lines) { if (!handleLine(QString::fromLocal8Bit(line))) { killProcess(); diff --git a/3rdparty/libsinglefileplugin/bz2plugin/CMakeLists.txt b/3rdparty/libsinglefileplugin/bz2plugin/CMakeLists.txt index 7cd6ba7ac..412c377df 100644 --- a/3rdparty/libsinglefileplugin/bz2plugin/CMakeLists.txt +++ b/3rdparty/libsinglefileplugin/bz2plugin/CMakeLists.txt @@ -7,8 +7,8 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) #find_package(KF5Archive) include(FindPkgConfig) @@ -29,8 +29,8 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs # KF5::Archive compressor-singlefile ) diff --git a/3rdparty/libsinglefileplugin/gzplugin/CMakeLists.txt b/3rdparty/libsinglefileplugin/gzplugin/CMakeLists.txt index 35489f0be..f5978bef4 100644 --- a/3rdparty/libsinglefileplugin/gzplugin/CMakeLists.txt +++ b/3rdparty/libsinglefileplugin/gzplugin/CMakeLists.txt @@ -7,8 +7,8 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) #find_package(KF5Archive) include(FindPkgConfig) @@ -29,8 +29,8 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs # KF5::Archive compressor-singlefile ) diff --git a/3rdparty/libsinglefileplugin/singlefile/CMakeLists.txt b/3rdparty/libsinglefileplugin/singlefile/CMakeLists.txt index 2e920a6db..cafa32849 100644 --- a/3rdparty/libsinglefileplugin/singlefile/CMakeLists.txt +++ b/3rdparty/libsinglefileplugin/singlefile/CMakeLists.txt @@ -7,15 +7,12 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -#find_package(LibArchive) -find_package(KF5Archive) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Archive REQUIRED) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) @@ -29,7 +26,7 @@ file(GLOB_RECURSE h_files RELATIVE ${PROJECT_SOURCE_DIR} *.h) #生成动静态库 add_library(${LIB_NAME} STATIC ${h_files} ${c_files}) target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Archive + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Archive compressor-interface ) diff --git a/3rdparty/libsinglefileplugin/singlefile/singlefileplugin.cpp b/3rdparty/libsinglefileplugin/singlefile/singlefileplugin.cpp index 2926efae4..ad9c4d9a5 100644 --- a/3rdparty/libsinglefileplugin/singlefile/singlefileplugin.cpp +++ b/3rdparty/libsinglefileplugin/singlefile/singlefileplugin.cpp @@ -33,7 +33,11 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK(6 ,0 ,0) #include +#else +#include +#endif //#include #include @@ -57,7 +61,11 @@ PluginFinishType LibSingleFileInterface::list() entry.strFullPath = uncompressedFileName(); entry.strFileName = entry.strFullPath; entry.qSize = QFileInfo(m_strArchiveName).size(); // 只能获取到压缩后大小 +#if QT_VERSION < QT_VERSION_CHECK(6 ,0 ,0) entry.uLastModifiedTime = QFileInfo(m_strArchiveName).lastModified().toTime_t(); +#else + entry.uLastModifiedTime = QFileInfo(m_strArchiveName).lastModified().toSecsSinceEpoch(); +#endif stArchiveData.qSize = entry.qSize; stArchiveData.qComressSize = entry.qSize; @@ -145,7 +153,11 @@ PluginFinishType LibSingleFileInterface::extractFiles(const QList &fi } // 打开压缩设备,写入数据 +#if QT_VERSION < QT_VERSION_CHECK(6 ,0 ,0) KCompressionDevice *device = new KCompressionDevice(m_strArchiveName, KFilterDev::compressionTypeForMimeType(m_mimeType)); +#else + KCompressionDevice *device = new KCompressionDevice(m_strArchiveName, KCompressionDevice::compressionTypeForMimeType(m_mimeType)); +#endif if (!device) { emit signalFileWriteErrorName(QFileInfo(outputFile.fileName()).fileName()); m_eErrorType = ET_FileWriteError; diff --git a/3rdparty/libsinglefileplugin/xzplugin/CMakeLists.txt b/3rdparty/libsinglefileplugin/xzplugin/CMakeLists.txt index 0482e1f86..93a47e91a 100644 --- a/3rdparty/libsinglefileplugin/xzplugin/CMakeLists.txt +++ b/3rdparty/libsinglefileplugin/xzplugin/CMakeLists.txt @@ -7,8 +7,8 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) #find_package(KF5Archive) include(FindPkgConfig) @@ -29,8 +29,8 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs # KF5::Archive compressor-singlefile ) diff --git a/3rdparty/libzipplugin/CMakeLists.txt b/3rdparty/libzipplugin/CMakeLists.txt index c37b7e52d..3ddaaecc2 100644 --- a/3rdparty/libzipplugin/CMakeLists.txt +++ b/3rdparty/libzipplugin/CMakeLists.txt @@ -7,15 +7,13 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) find_package(ZLIB REQUIRED) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) @@ -32,8 +30,8 @@ add_library(${LIB_NAME} SHARED ${c_files} ${json_files} ${h_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-interface zip ) diff --git a/3rdparty/libzipplugin/libzipplugin.cpp b/3rdparty/libzipplugin/libzipplugin.cpp index 3c64fd6ab..4edbd29ed 100644 --- a/3rdparty/libzipplugin/libzipplugin.cpp +++ b/3rdparty/libzipplugin/libzipplugin.cpp @@ -725,7 +725,13 @@ void LibzipPlugin::statBuffer2FileEntry(const zip_stat_t &statBuffer, FileEntry // 文件名 if (statBuffer.valid & ZIP_STAT_NAME) { - const QStringList pieces = entry.strFullPath.split(QLatin1Char('/'), QString::SkipEmptyParts); + const QStringList pieces = entry.strFullPath.split(QLatin1Char('/'), + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + QString::SkipEmptyParts + #else + Qt::SkipEmptyParts + #endif + ); entry.strFileName = pieces.isEmpty() ? QString() : pieces.last(); } diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e288aa4b..dea9ba553 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,24 @@ set(CMAKE_VERBOSE_MAKEFILE ON) #要显示执行构建过程中详细的信息( set(CMAKE_AUTOMOC ON) #打开全局moc set(CMAKE_AUTORCC ON) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) +# 引入翻译生成 +include(translation-generate) + +# Find Qt version +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) +message(" >>> Found Qt version: ${QT_VERSION_MAJOR}") +set(QT_DESIRED_VERSION ${QT_VERSION_MAJOR}) + +if (QT_VERSION_MAJOR MATCHES 6) + set(DTK_VERSION_MAJOR 6) + set(KF_VERSION_MAJOR 6) +else() + set(DTK_VERSION_MAJOR "") + set(KF_VERSION_MAJOR 5) +endif() +message(" >>> Build with DTK: ${DTK_VERSION_MAJOR}") + #对DApplication 进行加速 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") @@ -84,11 +102,6 @@ endif() #模糊测试设置 -end -#Generate the qm file -set(APP_RES_DIR "src") -set(APP_TRANS_SCRIPT "${APP_RES_DIR}/translate_generation.sh") -execute_process(COMMAND bash ${APP_TRANS_SCRIPT} - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/") add_subdirectory(3rdparty) add_subdirectory(src) diff --git a/cmake/translation-generate.cmake b/cmake/translation-generate.cmake new file mode 100644 index 000000000..a45ee68e5 --- /dev/null +++ b/cmake/translation-generate.cmake @@ -0,0 +1,39 @@ +function(TRANSLATION_GENERATE QMS) + find_package(Qt${QT_VERSION_MAJOR}LinguistTools QUIET) + + if (NOT Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE) + set(QT_LRELEASE "/lib/qt${QT_VERSION_MAJOR}/bin/lrelease") + message(STATUS "NOT found lrelease, set QT_LRELEASE = ${QT_LRELEASE}") + else() + set(QT_LRELEASE "${Qt${QT_VERSION_MAJOR}_LRELEASE_EXECUTABLE}") + endif() + + if(NOT ARGN) + message(SEND_ERROR "Error: TRANSLATION_GENERATE() called without any .ts path") + return() + endif() + + # # 获取 translations 目录下的所有 .ts 文件 + # file(GLOB_RECURSE TS_FILES "${ARGN}/*.ts") + # 获取指定目录下的所有 .ts 文件,不包括子目录 + file(GLOB TS_FILES "${ARGN}/*.ts") + + set(${QMS}) + foreach(TSFIL ${TS_FILES}) + get_filename_component(FIL_WE ${TSFIL} NAME_WE) +# get_filename_component(TS_DIR ${TSFIL} DIRECTORY) + set(QMFIL ${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.qm) + list(APPEND ${QMS} ${QMFIL}) + add_custom_command( + OUTPUT ${QMFIL} + # COMMAND ${Qt5_LUPDATE_EXECUTABLE} ${CMAKE_SOURCE_DIR} -ts ${TSFIL} + COMMAND ${QT_LRELEASE} ${TSFIL} -qm ${QMFIL} + DEPENDS ${TSFIL} + COMMENT "Running ${QT_LRELEASE} on ${TSFIL}" + VERBATIM + ) + endforeach() + + set_source_files_properties(${${QMS}} PROPERTIES GENERATED TRUE) + set(${QMS} ${${QMS}} PARENT_SCOPE) +endfunction() diff --git a/debian/control b/debian/control index a16355395..7f011cee2 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,31 @@ Source: deepin-compressor Section: devel Priority: optional Maintainer: packages -Build-Depends: debhelper (>= 11),cmake, libgsettings-qt-dev, libarchive-dev, libsecret-1-dev, libpoppler-cpp-dev, libudisks2-qt5-dev, libdisomaster-dev, libkf5codecs-dev, libzip-dev, qttools5-dev-tools, deepin-gettext-tools, qtbase5-dev, qtchooser (>= 55-gc9562a1-1~), qt5-qmake, libdtkwidget-dev,libqt5svg5-dev, libqt5x11extras5-dev, libkf5archive-dev, libminizip-dev, qttools5-dev, libgtest-dev, libmount-dev +Build-Depends: + debhelper (>= 11), + pkg-config, + cmake, + qt6-5compat-dev | libqt5x11extras5-dev, + qt6-base-dev | qtbase5-dev, + qt6-tools-dev-tools | qttools5-dev-tools, + qt6-tools-dev | qttools5-dev, + qt6-svg-dev | libqt5svg5-dev, + libdtk6widget-dev | libdtkwidget-dev, + libdtk6gui-dev | libdtkgui-dev, + libdtk6core-dev | libdtkcore-dev, + libudisks2-qt6-dev | libudisks2-qt5-dev, + libkf6codecs-dev | libkf5codecs-dev, + libkf6archive-dev | libkf5archive-dev, + libgtest-dev, + deepin-gettext-tools, + libgsettings-qt-dev, + libarchive-dev, + libsecret-1-dev, + libpoppler-cpp-dev, + libdisomaster-dev, + libzip-dev, + libmount-dev, + libminizip-dev, Standards-Version: 4.1.3 Package: deepin-compressor diff --git a/debian/rules b/debian/rules index 3156e412f..a21729259 100755 --- a/debian/rules +++ b/debian/rules @@ -9,14 +9,30 @@ DH_AUTO_ARGS = --parallel --buildsystem=cmake # Uncomment this to turn on verbose mode. export DH_VERBOSE=1 +# 检测当前安装的Qt版本,优先使用Qt6,否则使用Qt5 +define detect_qt_version +ifneq (,$(shell which qmake6 2>/dev/null)) + QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt6" +else + QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5" +endif +endef + +# 调用检测Qt版本的命令 +$(eval $(call detect_qt_version)) + +# hardcode this if want to force build with sepecific Qt version +# QT_DIR="/usr/lib/$(DEB_HOST_MULTIARCH)/cmake/Qt5" + %: dh $@ --parallel override_dh_auto_configure: dh_auto_configure -- \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_OFF" \ - -DAPP_VERSION=$(DEB_VERSION_UPSTREAM) \ - -DVERSION=$(DEB_VERSION_UPSTREAM) \ - -DCMAKE_INSTALL_LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH) \ - -DCOMPRESSOR_PLUGIN_PATH=/usr/lib/deepin-compressor/plugins + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_SAFETYTEST_ARG="CMAKE_SAFETYTEST_ARG_OFF" \ + -DAPP_VERSION=$(DEB_VERSION_UPSTREAM) \ + -DVERSION=$(DEB_VERSION_UPSTREAM) \ + -DCMAKE_INSTALL_LIBDIR=/usr/lib/$(DEB_HOST_MULTIARCH) \ + -DCOMPRESSOR_PLUGIN_PATH=/usr/lib/deepin-compressor/plugins \ + -DQT_DIR=$(QT_DIR) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ab3de44bf..dbd2beaad 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,17 +26,32 @@ endif () #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Concurrent) -find_package(Qt5DBus REQUIRED) -find_package(KF5Codecs REQUIRED) -find_package(Qt5LinguistTools REQUIRED) -find_package(DtkWidget REQUIRED) include(FindPkgConfig) +set(qt_required_components Core DBus Gui Widgets Concurrent) + +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND qt_required_components Core5Compat) +endif() + +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_components}) +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) + +set(LINK_LIBS + Qt${QT_DESIRED_VERSION}::Core + Qt${QT_DESIRED_VERSION}::DBus + Qt${QT_DESIRED_VERSION}::Gui + Qt${QT_DESIRED_VERSION}::Widgets + Qt${QT_DESIRED_VERSION}::Concurrent + Dtk${DTK_VERSION_MAJOR}::Widget + KF${KF_VERSION_MAJOR}::Codecs +) + +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::Core5Compat) +endif() -pkg_search_module(DtkWidget REQUIRED dtkwidget) -include_directories(${DtkWidget_INCLUDE_DIRS}) pkg_search_module(GOBJECT REQUIRED gobject-2.0) include_directories(${GOBJECT_INCLUDE_DIRS}) @@ -60,8 +75,13 @@ file(GLOB_RECURSE c_files RELATIVE ${PROJECT_SOURCE_DIR} source/*.cpp source/*.c file(GLOB_RECURSE h_files RELATIVE ${PROJECT_SOURCE_DIR} source/*.h *.h) file(GLOB_RECURSE res_files RELATIVE ${PROJECT_SOURCE_DIR} *.qrc) -#添加资源文件 -QT5_ADD_RESOURCES(QRC_FILES ${res_files}) +# 根据Qt版本选择合适的命令 +if (QT_VERSION VERSION_GREATER_EQUAL "6.0") + qt_add_resources(QRC_FILES ${res_files}) +else() + qt5_add_resources(QRC_FILES ${res_files}) +endif() + #链接库路径 link_directories(${LIBRARY_OUTPUT_PATH}) @@ -71,10 +91,7 @@ add_executable(${EXE_NAME} ${c_files} ${h_files} ${QRC_FILES}) #链接动静态库 target_link_libraries(${EXE_NAME} - Qt5::Widgets - Qt5::DBus - KF5::Codecs - ${DtkWidget_LIBRARIES} + ${LINK_LIBS} ${GOBJECT_LIBRARIES} ${GIO_LIBRARIES} compressor-interface @@ -85,15 +102,23 @@ set(APPID org.deepin.compressor) set(configFile ${PROJECT_SOURCE_DIR}/assets/org.deepin.compressor.method.json) if (DEFINED DSG_DATA_DIR) message("-- DConfig is supported by DTK") - dconfig_meta_files(APPID ${APPID} FILES ${configFile}) + if (DTK_VERSION_MAJOR EQUAL "6") + dtk_add_config_meta_files(APPID ${APPID} FILES ${configFile}) + else() + dconfig_meta_files(APPID ${APPID} FILES ${configFile}) + endif() endif() install(TARGETS deepin-compressor DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES desktop/deepin-compressor.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications) -file(GLOB INSTALL_QM_FILES ../translations/*.qm) -install(FILES ${INSTALL_QM_FILES} - DESTINATION ${CMAKE_INSTALL_DATADIR}/deepin-compressor/translations) +# translation files +TRANSLATION_GENERATE(QM_FILES ${CMAKE_SOURCE_DIR}/translations) +add_custom_target(${PROJECT_NAME}_qm_files DEPENDS ${QM_FILES}) +add_dependencies(${PROJECT_NAME} ${PROJECT_NAME}_qm_files) + +# Install translations +install(FILES ${QM_FILES} DESTINATION share/${PROJECT_NAME}/translations) # 自定义右键菜单 diff --git a/src/main.cpp b/src/main.cpp index d49978412..899b464d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,7 +12,9 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#endif #include #include @@ -137,7 +139,9 @@ int main(int argc, char *argv[]) app.setProductName(DApplication::translate("Main", "Archive Manager")); app.setApplicationDisplayName(DApplication::translate("Main", "Archive Manager")); app.setApplicationDescription(DApplication::translate("Main", "Archive Manager is a fast and lightweight application for creating and extracting archives.")); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) DApplicationSettings settings(&app); +#endif DLogManager::registerConsoleAppender(); DLogManager::registerFileAppender(); diff --git a/src/source/common/calculatesizethread.cpp b/src/source/common/calculatesizethread.cpp index 97eafbe5a..81bc4085a 100644 --- a/src/source/common/calculatesizethread.cpp +++ b/src/source/common/calculatesizethread.cpp @@ -45,7 +45,11 @@ void CalculateSizeThread::run() entry.strFileName = fileInfo.fileName(); // 文件名 entry.isDirectory = fileInfo.isDir(); // 是否是文件夹 entry.qSize = fileInfo.size(); // 大小 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) entry.uLastModifiedTime = fileInfo.lastModified().toTime_t(); // 最后一次修改时间 +#else + entry.uLastModifiedTime = fileInfo.lastModified().toSecsSinceEpoch(); // 最后一次修改时间 +#endif // 待压缩文件已经不存在 if (!fileInfo.exists()) { @@ -76,7 +80,14 @@ void CalculateSizeThread::run() mutex.lock(); m_listAllEntry << entry; mutex.unlock(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QtConcurrent::run(this, &CalculateSizeThread::ConstructAddOptionsByThread, file); +#else + QtConcurrent::run([this, file]() { + ConstructAddOptionsByThread(file); + }); +#endif + } } @@ -112,7 +123,11 @@ void CalculateSizeThread::ConstructAddOptionsByThread(const QString &path) entry.strFileName = fileInfo.fileName(); // 文件名 entry.isDirectory = fileInfo.isDir(); // 是否是文件夹 entry.qSize = fileInfo.size(); // 大小 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) entry.uLastModifiedTime = fileInfo.lastModified().toTime_t(); // 最后一次修改时间 +#else + entry.uLastModifiedTime = fileInfo.lastModified().toSecsSinceEpoch(); // 最后一次修改时间 +#endif // 待压缩文件已经不存在 if (!fileInfo.exists()) { @@ -140,7 +155,13 @@ void CalculateSizeThread::ConstructAddOptionsByThread(const QString &path) m_listAllEntry << entry; mutex.unlock(); // 如果是文件夹 则将此文件夹放入线程池中进行计算 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QtConcurrent::run(this, &CalculateSizeThread::ConstructAddOptionsByThread, entry.strFullPath); +#else + QtConcurrent::run([this, entry]() { + ConstructAddOptionsByThread(entry.strFullPath); + }); +#endif } else { mutex.lock(); // 如果是文件则直接计算大小 diff --git a/src/source/common/uistruct.h b/src/source/common/uistruct.h index 1748918fe..17075efcb 100644 --- a/src/source/common/uistruct.h +++ b/src/source/common/uistruct.h @@ -59,7 +59,7 @@ enum Archive_OperationType { // 压缩/解压列表的列号 enum DataView_Column { - DC_Name, // 名称 + DC_Name = 0, // 名称 DC_Time, // 修改时间 DC_Type, // 类型 DC_Size, // 大小 diff --git a/src/source/common/uitools.cpp b/src/source/common/uitools.cpp index 3ac11b8df..286d81404 100644 --- a/src/source/common/uitools.cpp +++ b/src/source/common/uitools.cpp @@ -8,6 +8,7 @@ #include "kpluginfactory.h" #include "kpluginloader.h" #include "pluginmanager.h" +#include "qtcompat.h" #include @@ -156,7 +157,7 @@ bool UiTools::isArchiveFile(const QString &strFileName) bool UiTools::isExistMimeType(const QString &strMimeType, bool &bArchive) { QString conf = readConf(); - QStringList confList = conf.split("\n", QString::SkipEmptyParts); + QStringList confList = conf.split("\n", SKIP_EMPTY_PARTS); bool exist = false; for (int i = 0; i < confList.count(); i++) { @@ -333,10 +334,15 @@ void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitTy { if (fileName.contains(".7z.")) { // 7z分卷处理 - QRegExp reg("^([\\s\\S]*\\.)7z\\.[0-9]{3}$"); // QRegExp reg("[*.]part\\d+.rar$"); //rar分卷不匹配 - + REG_EXP reg("^([\\s\\S]*\\.)7z\\.[0-9]{3}$"); // QRegExp reg("[*.]part\\d+.rar$"); //rar分卷不匹配 +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (reg.exactMatch(fileName)) { fileName = reg.cap(1) + "7z.001"; //例如: *.7z.003 -> *.7z.001 +#else + QRegularExpressionMatch match = reg.match(fileName); + if (match.hasMatch()) { + fileName = match.captured(1) + "7z.001"; //例如: *.7z.003 -> *.7z.001 +#endif eSplitType = UnCompressParameter::ST_Other; } } else if (fileName.contains(".part") && fileName.endsWith(".rar")) { @@ -352,7 +358,8 @@ void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitTy eSplitType = UnCompressParameter::ST_Other; } else if (fileName.contains(".zip.")) { // 1.zip.001格式 - QRegExp reg("^([\\s\\S]*\\.)zip\\.[0-9]{3}$"); + REG_EXP reg("^([\\s\\S]*\\.)zip\\.[0-9]{3}$"); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (reg.exactMatch(fileName)) { QFileInfo fi(reg.cap(1) + "zip.001"); if (fi.exists() == true) { @@ -360,6 +367,16 @@ void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitTy eSplitType = UnCompressParameter::ST_Zip; } } +#else + QRegularExpressionMatch match = reg.match(fileName); + if (match.hasMatch()) { + QFileInfo fi(match.captured(1) + "zip.001"); + if (fi.exists() == true) { + fileName = match.captured(1) + "zip.001"; + eSplitType = UnCompressParameter::ST_Zip; + } + } +#endif } else if (fileName.endsWith(".zip")) { //1.zip 1.01格式 /** * 例如123.zip文件,检测123.z01文件是否存在 @@ -374,9 +391,15 @@ void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitTy * 例如123.z01文件,检测123.zip文件是否存在 * 如果存在,则认定123.z01是分卷包 */ - QRegExp reg("^([\\s\\S]*\\.)z[0-9]+$"); // + REG_EXP reg("^([\\s\\S]*\\.)z[0-9]+$"); // +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (reg.exactMatch(fileName)) { fileName = reg.cap(1) + "zip"; +#else + QRegularExpressionMatch match = reg.match(fileName); + if (match.hasMatch()) { + fileName = match.captured(1) + "zip"; +#endif QFileInfo fi(fileName); if (fi.exists()) { eSplitType = UnCompressParameter::ST_Zip; diff --git a/src/source/dialog/openwithdialog/desktopfile.cpp b/src/source/dialog/openwithdialog/desktopfile.cpp index 768841a9d..35c7942c8 100644 --- a/src/source/dialog/openwithdialog/desktopfile.cpp +++ b/src/source/dialog/openwithdialog/desktopfile.cpp @@ -8,6 +8,7 @@ #include #include #include +#include /** * @brief Loads desktop file diff --git a/src/source/dialog/openwithdialog/mimesappsmanager.cpp b/src/source/dialog/openwithdialog/mimesappsmanager.cpp index 96dd488bc..09eb931c8 100644 --- a/src/source/dialog/openwithdialog/mimesappsmanager.cpp +++ b/src/source/dialog/openwithdialog/mimesappsmanager.cpp @@ -572,7 +572,7 @@ void MimesAppsManager::initMimeTypeApps() orderApps.append(info.absoluteFilePath()); } } else { - orderApps.append(apps.toList()); + orderApps.append(apps.values()); } MimeApps.insert(key, orderApps); @@ -701,7 +701,11 @@ void MimesAppsManager::loadDDEMimeTypes() bool MimesAppsManager::lessByDateTime(const QFileInfo &f1, const QFileInfo &f2) { +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) return f1.created() < f2.created(); +#else + return f1.birthTime() < f2.birthTime(); +#endif } bool MimesAppsManager::removeOneDupFromList(QStringList &list, const QString desktopFilePath) diff --git a/src/source/dialog/openwithdialog/openwithdialog.cpp b/src/source/dialog/openwithdialog/openwithdialog.cpp index d87a43636..fb9e6453b 100644 --- a/src/source/dialog/openwithdialog/openwithdialog.cpp +++ b/src/source/dialog/openwithdialog/openwithdialog.cpp @@ -71,7 +71,7 @@ void OpenWithDialogListItem::resizeEvent(QResizeEvent *e) m_pIconLbl->setPixmap(m_icon.pixmap(m_pIconLbl->size())); } -void OpenWithDialogListItem::enterEvent(QEvent *e) +void OpenWithDialogListItem::enterEvent(EnterEvent *e) { Q_UNUSED(e) diff --git a/src/source/dialog/openwithdialog/openwithdialog.h b/src/source/dialog/openwithdialog/openwithdialog.h index cc4ea3d47..7cded0e76 100644 --- a/src/source/dialog/openwithdialog/openwithdialog.h +++ b/src/source/dialog/openwithdialog/openwithdialog.h @@ -10,6 +10,8 @@ #include "mimesappsmanager.h" #include "singleton.h" +#include "qtcompat.h" + #include #include #include @@ -34,7 +36,7 @@ class OpenWithDialogListItem : public QWidget protected: void resizeEvent(QResizeEvent *e) Q_DECL_OVERRIDE; - void enterEvent(QEvent *e) Q_DECL_OVERRIDE; + void enterEvent(EnterEvent *e) Q_DECL_OVERRIDE; void leaveEvent(QEvent *e) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *e) Q_DECL_OVERRIDE; diff --git a/src/source/dialog/openwithdialog/singleton.h b/src/source/dialog/openwithdialog/singleton.h index a2321fd08..af5c6be36 100644 --- a/src/source/dialog/openwithdialog/singleton.h +++ b/src/source/dialog/openwithdialog/singleton.h @@ -10,9 +10,17 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#endif + namespace _Singleton { template +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +static typename std::enable_if::value, void>::type +#else static typename QtPrivate::QEnableIf::value>::Type +#endif handleQObject(QObject *object) { if (qApp) { @@ -21,7 +29,11 @@ handleQObject(QObject *object) } template +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +static typename std::enable_if::value, void>::type +#else static typename QtPrivate::QEnableIf::value>::Type +#endif handleQObject(void*) {} } diff --git a/src/source/dialog/settingdialog.cpp b/src/source/dialog/settingdialog.cpp index c3a5f9530..c4666faa4 100644 --- a/src/source/dialog/settingdialog.cpp +++ b/src/source/dialog/settingdialog.cpp @@ -8,7 +8,7 @@ #include "uitools.h" #include -#include +#include #include #include #include @@ -219,7 +219,7 @@ void SettingDialog::createPathBox() { m_curpath = combobox->currentText(); QDir dir(m_curpath); - DPalette plt = DApplicationHelper::instance()->palette(combobox); + DPalette plt = DPaletteHelper::instance()->palette(combobox); if (!dir.exists()) { plt.setBrush(DPalette::Text, plt.color(DPalette::TextWarning)); diff --git a/src/source/mainwindow.cpp b/src/source/mainwindow.cpp index 76c8c2f0d..a25587950 100644 --- a/src/source/mainwindow.cpp +++ b/src/source/mainwindow.cpp @@ -29,6 +29,7 @@ #include "uitools.h" #include "calculatesizethread.h" #include "eventlogutils.h" +#include "qtcompat.h" #include #include @@ -70,7 +71,11 @@ MainWindow::MainWindow(QWidget *parent) setCentralWidget(m_pMainWidget); // 设置中心面板 m_pMainWidget->setCurrentIndex(0); +#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0) m_openkey = new QShortcut(QKeySequence(Qt::Key_Slash + Qt::CTRL + Qt::SHIFT), this); // Ctrl+Shift+/ +#else + m_openkey = new QShortcut(QKeyCombination(Qt::CTRL | Qt::SHIFT, Qt::Key_Slash), this); // Ctrl+Shift+/ +#endif m_openkey->setContext(Qt::ApplicationShortcut); // 初始化标题栏 @@ -388,7 +393,13 @@ qint64 MainWindow::calSelectedTotalFileSize(const QStringList &files) #endif m_stCompressParameter.qSize += curFileSize; } else if (fi.isDir()) { // 如果是文件夹,递归获取所有子文件大小总和 +#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0) QtConcurrent::run(this, &MainWindow::calFileSizeByThread, file); +#else + QtConcurrent::run([this, file](){ + calFileSizeByThread(file); + }); +#endif } } @@ -413,7 +424,13 @@ void MainWindow::calFileSizeByThread(const QString &path) QFileInfo fileInfo = list.at(i); if (fileInfo.isDir()) { // 如果是文件夹 则将此文件夹放入线程池中进行计算 +#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0) QtConcurrent::run(this, &MainWindow::calFileSizeByThread, fileInfo.filePath()); +#else + QtConcurrent::run([this, fileInfo](){ + calFileSizeByThread(fileInfo.filePath()); + }); +#endif } else { mutex.lock(); // 如果是文件则直接计算大小 @@ -1040,7 +1057,7 @@ void MainWindow::slotCompress(const QVariant &val) // 判断zip格式是否使用了中文加密 bool zipPasswordIsChinese = false; if ("application/zip" == m_stCompressParameter.strMimeType) { - if (m_stCompressParameter.strPassword.contains(QRegExp("[\\x4e00-\\x9fa5]+"))) { + if (m_stCompressParameter.strPassword.contains(REG_EXP("[\\x4e00-\\x9fa5]+"))) { zipPasswordIsChinese = true; } } @@ -2000,7 +2017,11 @@ void MainWindow::ConstructAddOptions(const QStringList &files) entry.strFileName = fileInfo.fileName(); // 文件名 entry.isDirectory = fileInfo.isDir(); // 是否是文件夹 entry.qSize = fileInfo.size(); // 大小 +#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0) entry.uLastModifiedTime = fileInfo.lastModified().toTime_t(); // 最后一次修改时间 +#else + entry.uLastModifiedTime = fileInfo.lastModified().toSecsSinceEpoch(); // 最后一次修改时间 +#endif m_stUpdateOptions.listEntry << entry; @@ -2008,7 +2029,13 @@ void MainWindow::ConstructAddOptions(const QStringList &files) qint64 curFileSize = entry.qSize; m_stUpdateOptions.qSize += curFileSize; } else { // 如果是文件夹,递归获取所有子文件大小总和 +#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0) QtConcurrent::run(this, &MainWindow::ConstructAddOptionsByThread, file); +#else + QtConcurrent::run([this, file]() { + ConstructAddOptionsByThread(file); + }); +#endif } } @@ -2033,14 +2060,24 @@ void MainWindow::ConstructAddOptionsByThread(const QString &path) entry.strFileName = fileInfo.fileName(); // 文件名 entry.isDirectory = fileInfo.isDir(); // 是否是文件夹 entry.qSize = fileInfo.size(); // 大小 +#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0) entry.uLastModifiedTime = fileInfo.lastModified().toTime_t(); // 最后一次修改时间 +#else + entry.uLastModifiedTime = fileInfo.lastModified().toSecsSinceEpoch(); // 最后一次修改时间 +#endif if (entry.isDirectory) { mutex.lock(); m_stUpdateOptions.listEntry << entry; mutex.unlock(); // 如果是文件夹 则将此文件夹放入线程池中进行计算 +#if QT_VERSION < QT_VERSION_CHECK(6 ,0, 0) QtConcurrent::run(this, &MainWindow::ConstructAddOptionsByThread, entry.strFullPath); +#else + QtConcurrent::run([this, entry]() { + ConstructAddOptionsByThread(entry.strFullPath); + }); +#endif } else { mutex.lock(); // 如果是文件则直接计算大小 @@ -2432,7 +2469,7 @@ bool MainWindow::handleArguments_RightMenu(const QStringList &listParam) int iIndex = strpath.lastIndexOf(QDir::separator()); //fixbug:163153 远程挂在目录下压缩多个文件,压缩文件夹存在路径中特殊字符 //这里使用最后一个文件夹名进行压缩,防止特殊字符压缩不成功 - QRegExp reg("^\s+|[\\:*\"'?<>|\r\n\t]"); + REG_EXP reg("^\s+|[\\:*\"'?<>|\r\n\t]"); if (strpath.mid(iIndex).indexOf(reg) != -1) { QString compressor = strpath.split("=").last() + strSuffix; if (compressor.indexOf(reg) != -1) @@ -2655,7 +2692,7 @@ bool MainWindow::handleArguments_Append(const QStringList &listParam) return true; } - +#include void MainWindow::rightExtract2Path(StartupType eType, const QStringList &listFiles/*, const QString &strTargetPath*/) { if (listFiles.count() == 0) { @@ -2689,7 +2726,13 @@ void MainWindow::rightExtract2Path(StartupType eType, const QStringList &listFil listTransFiles << strFileName; mapType[strFileName] = eSplitVolume; } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) listTransFiles = listTransFiles.toSet().toList(); // 处理重复文件,防止出现重复的分卷文件名 +#else + // 使用 QSet 去除重复的文件名,然后再转换回 QStringList + QSet setTransFiles(listTransFiles.begin(), listTransFiles.end()); + listTransFiles = QStringList(setTransFiles.begin(), setTransFiles.end()); +#endif if (listTransFiles.count() == 1) { // 单个压缩包解压 @@ -3161,7 +3204,11 @@ void MainWindow::slotTitleCommentButtonPressed() QString str2 = fontMetrics().elidedText(file.filePath(), Qt::ElideMiddle, 150); right3->setText(str2); right3->setToolTip(file.filePath()); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) DLabel *right4 = new DLabel(file.created().toString("yyyy/MM/dd hh:mm:ss")); +#else + DLabel *right4 = new DLabel(file.birthTime().toString("yyyy/MM/dd hh:mm:ss")); +#endif DLabel *right5 = new DLabel(file.lastRead().toString("yyyy/MM/dd hh:mm:ss")); DLabel *right6 = new DLabel(file.lastModified().toString("yyyy/MM/dd hh:mm:ss")); diff --git a/src/source/page/compresssettingpage.cpp b/src/source/page/compresssettingpage.cpp index 0461d1a45..fa3cd65ef 100644 --- a/src/source/page/compresssettingpage.cpp +++ b/src/source/page/compresssettingpage.cpp @@ -10,11 +10,13 @@ #include "uistruct.h" #include "popupdialog.h" #include "DebugTimeManager.h" +#include "qtcompat.h" #include #include #include -#include +#include +#include #include #include @@ -25,7 +27,6 @@ #include #include #include -#include #include #include @@ -388,7 +389,7 @@ void CompressSettingPage::initConnections() connect(m_pPasswordEdt, &DPasswordEdit::echoModeChanged, this, &CompressSettingPage::slotEchoModeChanged); connect(m_pPasswordEdt, &DPasswordEdit::textEdited, this, &CompressSettingPage::slotPasswordChanged); connect(m_pCommentEdt, &DTextEdit::textChanged, this, &CompressSettingPage::slotCommentTextChanged); - connect(DApplicationHelper::instance(), &DApplicationHelper::themeTypeChanged, this, &CompressSettingPage::slotRefreshFileNameEdit); + connect(DGuiApplicationHelper::instance(), &DGuiApplicationHelper::themeTypeChanged, this, &CompressSettingPage::slotRefreshFileNameEdit); } void CompressSettingPage::setTypeImage(const QString &strType) @@ -762,7 +763,7 @@ void CompressSettingPage::slotTypeChanged(QAction *action) void CompressSettingPage::slotRefreshFileNameEdit() { - DPalette plt = DApplicationHelper::instance()->palette(m_pFileNameEdt); + DPalette plt = DPaletteHelper::instance()->palette(m_pFileNameEdt); if (!m_pFileNameEdt->text().isEmpty()) { // 检测文件名合法性 @@ -859,7 +860,7 @@ void CompressSettingPage::slotCompressClicked() //压缩zip分卷不支持中文密码 if (m_pSplitCkb->isChecked() && "zip" == m_pCompressTypeLbl->text() - && (!m_pPasswordEdt->text().isEmpty() && m_pPasswordEdt->text().contains(QRegExp("[\\x4e00-\\x9fa5]+")))) { + && (!m_pPasswordEdt->text().isEmpty() && m_pPasswordEdt->text().contains(REG_EXP("[\\x4e00-\\x9fa5]+")))) { m_pPasswordEdt->showAlertMessage(tr("The password for ZIP volumes cannot be in Chinese")); return; } @@ -952,16 +953,25 @@ void CompressSettingPage::slotCommentTextChanged() void CompressSettingPage::slotPasswordChanged() { - QRegExp reg("^[\\x00-\\x80\\x4e00-\\x9fa5]+$"); + REG_EXP reg("^[\\x00-\\x80\\x4e00-\\x9fa5]+$"); QString pwdin = m_pPasswordEdt->lineEdit()->text(); QString pwdout; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (!pwdin.isEmpty() && !reg.exactMatch(pwdin)) { for (int i = 0; i < pwdin.length(); ++i) { if (reg.exactMatch(pwdin.at(i))) { pwdout.push_back(pwdin.at(i)); } } +#else + if (!pwdin.isEmpty() && !reg.match(pwdin).hasMatch()) { + for (int i = 0; i < pwdin.length(); ++i) { + if (reg.match(pwdin.at(i)).hasMatch()) { + pwdout.append(pwdin.at(i)); + } + } +#endif m_pPasswordEdt->setText(pwdout); // 仅支持中英文字符及部分符号 m_pPasswordEdt->showAlertMessage(tr("Only Chinese and English characters and some symbols are supported")); diff --git a/src/source/page/homepage.cpp b/src/source/page/homepage.cpp index 2cebc6932..6adaff793 100644 --- a/src/source/page/homepage.cpp +++ b/src/source/page/homepage.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/source/page/loadingpage.cpp b/src/source/page/loadingpage.cpp index 87343d01b..004a7f6df 100644 --- a/src/source/page/loadingpage.cpp +++ b/src/source/page/loadingpage.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include @@ -48,9 +48,9 @@ void LoadingPage::initUI() m_pTextLbl->setMinimumSize(293, 20); m_pTextLbl->setText(tr("Loading, please wait...")); DFontSizeManager::instance()->bind(m_pTextLbl, DFontSizeManager::T6, QFont::Medium); // 设置字体 - DPalette pa = DApplicationHelper::instance()->palette(m_pTextLbl); + DPalette pa = DPaletteHelper::instance()->palette(m_pTextLbl); pa.setBrush(DPalette::ButtonText, pa.color(DPalette::TextTitle)); // 设置颜色 - DApplicationHelper::instance()->setPalette(m_pTextLbl, pa); + m_pTextLbl->setPalette(pa); m_pTextLbl->setAlignment(Qt::AlignCenter); // 加载布局 diff --git a/src/source/page/uncompresspage.cpp b/src/source/page/uncompresspage.cpp index 8da0d7da8..af6b30bc7 100644 --- a/src/source/page/uncompresspage.cpp +++ b/src/source/page/uncompresspage.cpp @@ -158,7 +158,11 @@ void UnCompressPage::initConnections() QString UnCompressPage::elidedExtractPath(const QString &strPath) { QFontMetrics fontMetrics(this->font()); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) int fontSize = fontMetrics.width(strPath);//获取之前设置的字符串的像素大小 +#else + int fontSize = fontMetrics.horizontalAdvance(strPath);//获取之前设置的字符串的像素大小 +#endif QString pathStr = strPath; if (fontSize > width()) { pathStr = fontMetrics.elidedText(strPath, Qt::ElideMiddle, width());//返回一个带有省略号的字符串 diff --git a/src/source/qtcompat.h b/src/source/qtcompat.h new file mode 100644 index 000000000..9109e3994 --- /dev/null +++ b/src/source/qtcompat.h @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#ifndef QTCOMPAT_H +#define QTCOMPAT_H + +#include + +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include +#include +class QEnterEvent; + +#define SKIP_EMPTY_PARTS Qt::SkipEmptyParts +#define SPLIT_BH Qt::SplitBehavior +#define ENDL Qt::endl +#define REG_EXP QRegularExpression +#define REG_EXPV QRegularExpressionValidator +#define DATE_FOTIME QDateTime::fromSecsSinceEpoch +#define DATE_TOTIME QDateTime::toSecsSinceEpoch + +using EnterEvent = QEnterEvent; + +#else // QT_VERSION < 6.0.0 + +#include +class QEvent; + +#define SKIP_EMPTY_PARTS QString::SkipEmptyParts +#define SPLIT_BH QString::SplitBehavior +#define ENDL endl +#define REG_EXP QRegExp +#define REG_EXPV QRegExpValidator +#define DATE_FOTIME QDateTime::fromTime_t +#define DATE_TOTIME QDateTime::toTime_t + +using EnterEvent = QEvent; + +#endif + +#endif // QTCOMPAT_H diff --git a/src/source/tree/compressview.cpp b/src/source/tree/compressview.cpp index d1b84a0f2..93444fc88 100644 --- a/src/source/tree/compressview.cpp +++ b/src/source/tree/compressview.cpp @@ -103,7 +103,7 @@ void CompressView::refreshCompressedFiles(bool bChanged, const QString &strFileN // 重置排序 m_pHeaderView->setSortIndicator(-1, Qt::SortOrder::AscendingOrder); - sortByColumn(DC_Name); + sortByColumn(DC_Name, Qt::AscendingOrder); resetLevel(); // 重置目录层级 // 选中新加的文件 @@ -167,7 +167,11 @@ FileEntry CompressView::fileInfo2Entry(const QFileInfo &fileInfo) entry.qSize = fileInfo.size(); } +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) entry.uLastModifiedTime = fileInfo.lastModified().toTime_t(); // 最后一次修改时间 +#else + entry.uLastModifiedTime = fileInfo.lastModified().toSecsSinceEpoch(); // 最后一次修改时间 +#endif return entry; } @@ -188,7 +192,7 @@ void CompressView::handleDoubleClick(const QModelIndex &index) resizeColumnWidth(); // 重置列宽 // 重置排序 m_pHeaderView->setSortIndicator(-1, Qt::SortOrder::AscendingOrder); - sortByColumn(DC_Name); + sortByColumn(DC_Name, Qt::AscendingOrder); m_vPre.push_back(entry.strFileName); // 空目录自动选中返回上一级目录Label bug122305 @@ -520,7 +524,7 @@ void CompressView::slotPreClicked() handleLevelChanged(); // 重置排序 m_pHeaderView->setSortIndicator(-1, Qt::SortOrder::AscendingOrder); - sortByColumn(DC_Name); + sortByColumn(DC_Name, Qt::AscendingOrder); //自动选中第一行 QModelIndex tmpindex = m_pModel->getListEntryIndex(m_vPre.back()); // 获取上层文件夹对应的QModelIndex diff --git a/src/source/tree/datamodel.cpp b/src/source/tree/datamodel.cpp index 44a0676d3..2872bb311 100644 --- a/src/source/tree/datamodel.cpp +++ b/src/source/tree/datamodel.cpp @@ -16,7 +16,6 @@ #include #include #include -#include #include DGUI_USE_NAMESPACE @@ -73,7 +72,11 @@ QVariant DataModel::data(const QModelIndex &index, int role) const } } case DC_Time: { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) return QDateTime::fromTime_t(entry.uLastModifiedTime).toString("yyyy/MM/dd hh:mm:ss"); +#else + return QDateTime::fromSecsSinceEpoch(entry.uLastModifiedTime).toString("yyyy/MM/dd hh:mm:ss"); +#endif } case DC_Type: { CustomMimeType mimetype = determineMimeType(entry.strFullPath); // 根据全路径获取类型 diff --git a/src/source/tree/datatreeview.cpp b/src/source/tree/datatreeview.cpp index f16a52a98..42be769da 100644 --- a/src/source/tree/datatreeview.cpp +++ b/src/source/tree/datatreeview.cpp @@ -10,7 +10,7 @@ #include #include -#include +#include #include #include @@ -40,10 +40,10 @@ QSize StyleTreeViewDelegate::sizeHint(const QStyleOptionViewItem &option, const #ifdef DTKWIDGET_CLASS_DSizeMode - if (DGuiApplicationHelper::instance()->sizeMode() == DGuiApplicationHelper::NormalMode) { - return QSize(option.rect.width(), TABLE_HEIGHT_NormalMode); - } else { + if (DGuiApplicationHelper::instance()->isCompactMode()) { return QSize(option.rect.width(), TABLE_HEIGHT_CompactMode); + } else { + return QSize(option.rect.width(), TABLE_HEIGHT_NormalMode); } #else return QSize(option.rect.width(), TABLE_HEIGHT_NormalMode); @@ -79,7 +79,7 @@ void StyleTreeViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem DStyle *style = dynamic_cast(DApplication::style()); int margin = style->pixelMetric(DStyle::PM_ContentsMargins, &option); //设置高亮文字色 - DApplicationHelper *dAppHelper = DApplicationHelper::instance(); + DGuiApplicationHelper *dAppHelper = DGuiApplicationHelper::instance(); DPalette palette = dAppHelper->applicationPalette(); QPen forground; forground.setColor(palette.color(cg, DPalette::Text)); @@ -409,13 +409,17 @@ bool DataTreeView::event(QEvent *event) QTouchEvent *touchEvent = static_cast(event); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) if (!m_isPressed && touchEvent && touchEvent->device() && touchEvent->device()->type() == QTouchDevice::TouchScreen && touchEvent->touchPointStates() == Qt::TouchPointPressed) { - QList points = touchEvent->touchPoints(); +#else + if (!m_isPressed && touchEvent && touchEvent->deviceType() == QInputDevice::DeviceType::TouchScreen && touchEvent->touchPointStates() == Qt::TouchPointPressed) { + QList points = touchEvent->points(); +#endif //dell触摸屏幕只有一个touchpoint 但却能捕获到pinchevent缩放手势? if (points.count() == 1) { QTouchEvent::TouchPoint p = points.at(0); - m_lastTouchBeginPos = p.pos(); + m_lastTouchBeginPos = p.position(); m_lastTouchBeginPos.setY(m_lastTouchBeginPos.y() - m_pHeaderView->height()); m_lastTouchTime = QTime::currentTime(); m_isPressed = true; diff --git a/src/source/tree/treeheaderview.cpp b/src/source/tree/treeheaderview.cpp index e9d69c024..9e109ad56 100644 --- a/src/source/tree/treeheaderview.cpp +++ b/src/source/tree/treeheaderview.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -87,7 +87,7 @@ void PreviousLabel::mouseDoubleClickEvent(QMouseEvent *event) QLabel::mouseDoubleClickEvent(event); } -void PreviousLabel::enterEvent(QEvent *event) +void PreviousLabel::enterEvent(EnterEvent *event) { if(!hasFocus()) { focusIn_ = true; @@ -193,10 +193,15 @@ int TreeHeaderView::sectionSizeHint(int logicalIndex) const QFontMetrics fm(DApplication::font()); QString buf = model()->headerData(logicalIndex, Qt::Horizontal, Qt::DisplayRole).toString(); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + int width = fm.width(buf); +#else + int width = fm.horizontalAdvance(buf); +#endif if (sortIndicatorSection() == logicalIndex) { - return fm.width(buf) + margin * 3 + 8; + return width + margin * 3 + 8; } else { - return fm.width(buf) + margin * 2; + return width + margin * 2; } } @@ -261,7 +266,7 @@ void TreeHeaderView::paintEvent(QPaintEvent *e) cg = DPalette::Active; #endif - DApplicationHelper *dAppHelper = DApplicationHelper::instance(); + DGuiApplicationHelper *dAppHelper = DGuiApplicationHelper::instance(); DPalette palette = dAppHelper->applicationPalette(); DStyle *style = dynamic_cast(DApplication::style()); @@ -301,7 +306,7 @@ void TreeHeaderView::paintSection(QPainter *painter, const QRect &rect, int logi cg = DPalette::Active; } - DApplicationHelper *dAppHelper = DApplicationHelper::instance(); + DGuiApplicationHelper *dAppHelper = DGuiApplicationHelper::instance(); DPalette palette = dAppHelper->applicationPalette(); DStyle *style = dynamic_cast(DApplication::style()); diff --git a/src/source/tree/treeheaderview.h b/src/source/tree/treeheaderview.h index bdc799c5d..911ef97bf 100644 --- a/src/source/tree/treeheaderview.h +++ b/src/source/tree/treeheaderview.h @@ -6,6 +6,8 @@ #ifndef TREEHEADERVIEW_H #define TREEHEADERVIEW_H +#include "qtcompat.h" + #include #include @@ -44,7 +46,7 @@ class PreviousLabel: public Dtk::Widget::DLabel protected: void paintEvent(QPaintEvent *e) override; void mouseDoubleClickEvent(QMouseEvent *event) override; - void enterEvent(QEvent *event) override; + void enterEvent(EnterEvent *event) override; void leaveEvent(QEvent *event) override; void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE; void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE; diff --git a/src/source/tree/uncompressview.cpp b/src/source/tree/uncompressview.cpp index 947209494..4886a0a81 100644 --- a/src/source/tree/uncompressview.cpp +++ b/src/source/tree/uncompressview.cpp @@ -58,7 +58,7 @@ void UnCompressView::refreshArchiveData() // 重置排序 m_pHeaderView->setSortIndicator(-1, Qt::SortOrder::AscendingOrder); - sortByColumn(DC_Name); + sortByColumn(DC_Name, Qt::AscendingOrder); resetLevel(); // 重置目录层级 } @@ -259,7 +259,7 @@ void UnCompressView::handleDoubleClick(const QModelIndex &index) resizeColumnWidth(); // 重置列宽 // 重置排序 m_pHeaderView->setSortIndicator(-1, Qt::SortOrder::AscendingOrder); - sortByColumn(DC_Name); + sortByColumn(DC_Name, Qt::AscendingOrder); m_vPre.push_back(entry.strFileName); // 保存进入的文件夹名 @@ -337,7 +337,7 @@ void UnCompressView::refreshDataByCurrentPathChanged() // 重置排序 m_pHeaderView->setSortIndicator(-1, Qt::SortOrder::AscendingOrder); - sortByColumn(DC_Name); + sortByColumn(DC_Name, Qt::AscendingOrder); // 追加时需要选中追加的文件 if (CT_Add == m_eChangeType) { @@ -817,7 +817,7 @@ void UnCompressView::slotPreClicked() // 重置排序 m_pHeaderView->setSortIndicator(-1, Qt::SortOrder::AscendingOrder); - sortByColumn(DC_Name); + sortByColumn(DC_Name, Qt::AscendingOrder); //自动选中第一行 QModelIndex tmpindex = m_pModel->getListEntryIndex(m_vPre.back()); // 获取上层文件夹对应的QModelIndex diff --git a/tests/UnitTest/3rdparty/cli7zplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/cli7zplugin/CMakeLists.txt index 779b11d5a..860059875 100644 --- a/tests/UnitTest/3rdparty/cli7zplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/cli7zplugin/CMakeLists.txt @@ -11,19 +11,22 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) +find_package(KF${KF_VERSION_MAJOR}Archive REQUIRED) +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget) + +if (QT_DESIRED_VERSION MATCHES 6) + find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Core5Compat) +endif() + include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) pkg_search_module(GOBJECT REQUIRED gobject-2.0) pkg_search_module(MOUNT REQUIRED mount) #指定头文件路径 include_directories(${HFILES_OUTPUT_PATH}) -include_directories(${DtkWidget_INCLUDE_DIRS}) -include_directories(${Qt5Widgets_INCLUDE_DIRS}) -include_directories(${KF5Codecs_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/cli7zplugin) include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/interface) @@ -63,12 +66,19 @@ add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) #链接动静态库 target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs - ${DtkWidget_LIBRARIES} + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs + KF${KF_VERSION_MAJOR}::Archive + Dtk${DTK_VERSION_MAJOR}::Widget ${MOUNT_LIBRARIES} ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread compressor-ChardetDetector ) + +if (QT_DESIRED_VERSION MATCHES 6) + target_link_libraries(${EXE_NAME}_test + Qt${QT_DESIRED_VERSION}::Core5Compat + ) +endif() \ No newline at end of file diff --git a/tests/UnitTest/3rdparty/cli7zplugin/ut_cli7zplugin.cpp b/tests/UnitTest/3rdparty/cli7zplugin/ut_cli7zplugin.cpp index 1ccd813e6..624d4f5d1 100644 --- a/tests/UnitTest/3rdparty/cli7zplugin/ut_cli7zplugin.cpp +++ b/tests/UnitTest/3rdparty/cli7zplugin/ut_cli7zplugin.cpp @@ -418,7 +418,12 @@ TEST_F(UT_Cli7zPlugin, test_readListLine_018) m_tester->m_parseState = ParseStateEntryInformation; m_tester->m_archiveType = Cli7zPlugin::ArchiveType::ArchiveType7z; EXPECT_EQ(m_tester->readListLine("Modified = 2021-06-18 15:27:01"), true); - EXPECT_EQ(m_tester->m_fileEntry.uLastModifiedTime, QDateTime::fromString("2021-06-18 15:27:01", "yyyy-MM-dd hh:mm:ss").toTime_t()); + EXPECT_EQ(m_tester->m_fileEntry.uLastModifiedTime, QDateTime::fromString("2021-06-18 15:27:01", "yyyy-MM-dd hh:mm:ss") +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + .toTime_t()); +#else + .toSecsSinceEpoch()); +#endif } TEST_F(UT_Cli7zPlugin, test_readListLine_019) diff --git a/tests/UnitTest/3rdparty/clirarplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/clirarplugin/CMakeLists.txt index 59d69e759..246b74d68 100644 --- a/tests/UnitTest/3rdparty/clirarplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/clirarplugin/CMakeLists.txt @@ -11,9 +11,8 @@ project(${EXE_NAME}_test) #设置项目名称 find_package(PkgConfig REQUIRED) -find_package(Qt5Gui REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) include(FindPkgConfig) @@ -41,8 +40,8 @@ file(GLOB_RECURSE json_files add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-interface ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} diff --git a/tests/UnitTest/3rdparty/interface/CMakeLists.txt b/tests/UnitTest/3rdparty/interface/CMakeLists.txt index f4e75f72f..0fc9cb9fb 100644 --- a/tests/UnitTest/3rdparty/interface/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/interface/CMakeLists.txt @@ -11,8 +11,14 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget) + +if (QT_DESIRED_VERSION MATCHES 6) + find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Core5Compat) +endif() + include(FindPkgConfig) pkg_search_module(DtkWidget REQUIRED dtkwidget) @@ -21,10 +27,7 @@ pkg_search_module(MOUNT REQUIRED mount) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${MOUNT_INCLUDE_DIRS}) -include_directories(${Qt5Widgets_INCLUDE_DIRS}) -include_directories(${KF5Codecs_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${PROJECT_SOURCE_DIR}/archiveinterface) include_directories(${PROJECT_SOURCE_DIR}/plugin) @@ -66,12 +69,18 @@ add_executable(${EXE_NAME}_test ${c_files} ${h_files}) #链接动静态库 target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs - ${DtkWidget_LIBRARIES} + Qt${QT_DESIRED_VERSION}::Widgets + Dtk${DTK_VERSION_MAJOR}::Widget + KF${KF_VERSION_MAJOR}::Codecs ${MOUNT_LIBRARIES} compressor-ChardetDetector ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} pthread ) + +if (QT_DESIRED_VERSION MATCHES 6) + target_link_libraries(${EXE_NAME}_test + Qt${QT_DESIRED_VERSION}::Core5Compat + ) +endif() diff --git a/tests/UnitTest/3rdparty/interface/ut_queries.cpp b/tests/UnitTest/3rdparty/interface/ut_queries.cpp index 51cbfddb6..95e4031c4 100644 --- a/tests/UnitTest/3rdparty/interface/ut_queries.cpp +++ b/tests/UnitTest/3rdparty/interface/ut_queries.cpp @@ -170,7 +170,7 @@ TEST_F(UT_OverwriteQuery, test_setWidgetColor) QWidget *pWgt = new QWidget; DPalette::ColorRole ct = DPalette::ToolTipText; double alphaF = 0.5; - DPalette palette = DApplicationHelper::instance()->palette(pWgt); + DPalette palette = DPaletteHelper::instance()->palette(pWgt); QColor color = palette.color(ct); m_tester->setWidgetColor(pWgt, ct, alphaF); @@ -183,11 +183,11 @@ TEST_F(UT_OverwriteQuery, test_setWidgetType) QWidget *pWgt = new QWidget; DPalette::ColorType ct; double alphaF = 0.5; - DPalette palette = DApplicationHelper::instance()->palette(pWgt); + DPalette palette = DPaletteHelper::instance()->palette(pWgt); QColor color = palette.color(ct); m_tester->setWidgetType(pWgt, ct, alphaF); - EXPECT_EQ(DApplicationHelper::instance()->palette(pWgt).color(ct) == color, true); + EXPECT_EQ(DPaletteHelper::instance()->palette(pWgt).color(ct) == color, true); delete pWgt; } diff --git a/tests/UnitTest/3rdparty/libarchive/readonlylibarchiveplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/libarchive/readonlylibarchiveplugin/CMakeLists.txt index ebfabc8e3..ee226bbc7 100644 --- a/tests/UnitTest/3rdparty/libarchive/readonlylibarchiveplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/libarchive/readonlylibarchiveplugin/CMakeLists.txt @@ -11,16 +11,14 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) -find_package(KF5Archive) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) +find_package(KF${KF_VERSION_MAJOR}Archive REQUIRED) find_package(LibArchive) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) include_directories(${PROJECT_SOURCE_DIR}/../${3RDPARTYRELATIVEPATH}/libarchive/readonlylibarchiveplugin) @@ -52,9 +50,9 @@ add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) #链接动静态库 target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Archive - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs + KF${KF_VERSION_MAJOR}::Archive archive compressor-interface # compressor-archive diff --git a/tests/UnitTest/3rdparty/libarchive/readwritelibarchiveplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/libarchive/readwritelibarchiveplugin/CMakeLists.txt index f70d7a08f..b8ecb6d24 100644 --- a/tests/UnitTest/3rdparty/libarchive/readwritelibarchiveplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/libarchive/readwritelibarchiveplugin/CMakeLists.txt @@ -11,8 +11,8 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) include(FindPkgConfig) #指定头文件路径 @@ -43,8 +43,8 @@ add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) #链接动静态库 target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-archive ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} diff --git a/tests/UnitTest/3rdparty/libminizipplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/libminizipplugin/CMakeLists.txt index 5df31ba1a..b0a931eb6 100644 --- a/tests/UnitTest/3rdparty/libminizipplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/libminizipplugin/CMakeLists.txt @@ -11,16 +11,14 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) find_package(ZLIB REQUIRED) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libminizipplugin) @@ -49,8 +47,8 @@ add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) #链接动静态库 target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-interface minizip ${GTEST_LIBRARIES} diff --git a/tests/UnitTest/3rdparty/libpigzplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/libpigzplugin/CMakeLists.txt index 4faea6b7c..082ffc747 100644 --- a/tests/UnitTest/3rdparty/libpigzplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/libpigzplugin/CMakeLists.txt @@ -11,15 +11,12 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) -include_directories(${DtkWidget_INCLUDE_DIRS}) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libpigzplugin) @@ -47,7 +44,7 @@ add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) #链接动静态库 target_link_libraries(${EXE_NAME}_test - Qt5::Widgets + Qt${QT_DESIRED_VERSION}::Widgets compressor-interface ${GTEST_LIBRARIES} ${GTEST_MAIN_LIBRARIES} diff --git a/tests/UnitTest/3rdparty/libsinglefileplugin/bz2plugin/CMakeLists.txt b/tests/UnitTest/3rdparty/libsinglefileplugin/bz2plugin/CMakeLists.txt index 83c43c6ba..d1afa12d7 100644 --- a/tests/UnitTest/3rdparty/libsinglefileplugin/bz2plugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/libsinglefileplugin/bz2plugin/CMakeLists.txt @@ -11,15 +11,13 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) -find_package(KF5Archive) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) +find_package(KF${KF_VERSION_MAJOR}Archive REQUIRED) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) include_directories(${PROJECT_SOURCE_DIR}/../${3RDPARTYRELATIVEPATH}/libsinglefileplugin/bz2plugin) @@ -48,9 +46,9 @@ file(GLOB_RECURSE json_files #生成动静态库 add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs - KF5::Archive + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs + KF${KF_VERSION_MAJOR}::Archive # compressor-singlefile compressor-interface ${GTEST_LIBRARIES} diff --git a/tests/UnitTest/3rdparty/libsinglefileplugin/bz2plugin/ut_bz2plugin.cpp b/tests/UnitTest/3rdparty/libsinglefileplugin/bz2plugin/ut_bz2plugin.cpp index a20d50df3..f83722878 100644 --- a/tests/UnitTest/3rdparty/libsinglefileplugin/bz2plugin/ut_bz2plugin.cpp +++ b/tests/UnitTest/3rdparty/libsinglefileplugin/bz2plugin/ut_bz2plugin.cpp @@ -136,7 +136,11 @@ bool responseOverwriteAll_false_stub() return false; } +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QStringList qString_split_stub(QChar, QString::SplitBehavior, Qt::CaseSensitivity) +#else +QStringList qString_split_stub(QChar, Qt::SplitBehavior, Qt::CaseSensitivity) +#endif { return QStringList() << "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" @@ -224,7 +228,11 @@ TEST_F(UT_LibBzip2Interface, test_extractFiles_005) Stub stub; stub.set(ADDR(OverwriteQuery, waitForResponse), waitForResponse_stub); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) typedef QStringList(QString::*fptr)(QChar, QString::SplitBehavior, Qt::CaseSensitivity) const; +#else + typedef QStringList(QString::*fptr)(QChar, Qt::SplitBehavior, Qt::CaseSensitivity) const; +#endif fptr A_foo = (fptr)(&QString::split); //获取虚函数地址 stub.set(A_foo, qString_split_stub); diff --git a/tests/UnitTest/3rdparty/libsinglefileplugin/gzplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/libsinglefileplugin/gzplugin/CMakeLists.txt index bdd306de2..e739d712b 100644 --- a/tests/UnitTest/3rdparty/libsinglefileplugin/gzplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/libsinglefileplugin/gzplugin/CMakeLists.txt @@ -11,8 +11,8 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) #find_package(KF5Archive) include(FindPkgConfig) @@ -42,8 +42,8 @@ file(GLOB_RECURSE json_files #生成动静态库 add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs # KF5::Archive compressor-singlefile ${GTEST_LIBRARIES} diff --git a/tests/UnitTest/3rdparty/libsinglefileplugin/xzplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/libsinglefileplugin/xzplugin/CMakeLists.txt index b3aea0c68..4720a2fa6 100644 --- a/tests/UnitTest/3rdparty/libsinglefileplugin/xzplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/libsinglefileplugin/xzplugin/CMakeLists.txt @@ -11,8 +11,8 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) #find_package(KF5Archive) include(FindPkgConfig) @@ -42,8 +42,8 @@ file(GLOB_RECURSE json_files #生成动静态库 add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs # KF5::Archive compressor-singlefile ${GTEST_LIBRARIES} diff --git a/tests/UnitTest/3rdparty/libzipplugin/CMakeLists.txt b/tests/UnitTest/3rdparty/libzipplugin/CMakeLists.txt index 4a4aee6b8..ed7778ecc 100644 --- a/tests/UnitTest/3rdparty/libzipplugin/CMakeLists.txt +++ b/tests/UnitTest/3rdparty/libzipplugin/CMakeLists.txt @@ -11,17 +11,14 @@ project(${EXE_NAME}_test) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS Widgets) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) find_package(ZLIB REQUIRED) include(FindPkgConfig) -pkg_search_module(DtkWidget REQUIRED dtkwidget) -include_directories(${DtkWidget_INCLUDE_DIRS}) #指定头文件路径 -include_directories(${DtkWidget_INCLUDE_DIRS}) include_directories(${PROJECT_SOURCE_DIR}) include_directories(${HFILES_OUTPUT_PATH}) include_directories(${PROJECT_SOURCE_DIR}/${3RDPARTYRELATIVEPATH}/libzipplugin) @@ -49,8 +46,8 @@ add_executable(${EXE_NAME}_test ${h_files} ${c_files} ${json_files}) #链接动静态库 target_link_libraries(${EXE_NAME}_test - Qt5::Widgets - KF5::Codecs + Qt${QT_DESIRED_VERSION}::Widgets + KF${KF_VERSION_MAJOR}::Codecs compressor-interface zip ${GTEST_LIBRARIES} diff --git a/tests/UnitTest/src/CMakeLists.txt b/tests/UnitTest/src/CMakeLists.txt index 00296f29c..a3081080f 100644 --- a/tests/UnitTest/src/CMakeLists.txt +++ b/tests/UnitTest/src/CMakeLists.txt @@ -23,17 +23,30 @@ set(LIBZIPPLUGINPATH ../../../3rdparty/libzipplugin) #相对于源码路径 #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Concurrent) -find_package(Qt5Test) -find_package(KF5Codecs REQUIRED) -find_package(Qt5LinguistTools REQUIRED) find_package(ZLIB REQUIRED) include(FindPkgConfig) +set(qt_required_components Widgets Concurrent Test) -pkg_search_module(DtkWidget REQUIRED dtkwidget) -include_directories(${DtkWidget_INCLUDE_DIRS}) +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND qt_required_components Core5Compat) +endif() + +find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS ${qt_required_components}) +find_package(Dtk${DTK_VERSION_MAJOR} REQUIRED COMPONENTS Widget) +find_package(KF${KF_VERSION_MAJOR}Codecs REQUIRED) + +set(LINK_LIBS + Qt${QT_DESIRED_VERSION}::Widgets + Qt${QT_DESIRED_VERSION}::Concurrent + Qt${QT_DESIRED_VERSION}::Test + Dtk${DTK_VERSION_MAJOR}::Widget + KF${KF_VERSION_MAJOR}::Codecs +) + +if (QT_DESIRED_VERSION MATCHES 6) + list(APPEND LINK_LIBS Qt${QT_DESIRED_VERSION}::Core5Compat) +endif() pkg_search_module(GOBJECT REQUIRED gobject-2.0) include_directories(${GOBJECT_INCLUDE_DIRS}) @@ -42,13 +55,6 @@ pkg_search_module(GIO REQUIRED gio-unix-2.0) include_directories(${GIO_INCLUDE_DIRS}) -set(LIBS_INCLUDE_DIRS - ${DtkWidget_LIBRARIES} - ${DtkCore_LIBRARIES} - ${GOBJECT_LIBRARIES} - ${GIO_LIBRARIES} - ${DtkGui_LIBRARIES} -) #指定头文件路径 @@ -107,7 +113,12 @@ file(GLOB_RECURSE h_files ) file(GLOB_RECURSE res_files ${SRCRELATIVEPATH}/*.qrc) -QT5_ADD_RESOURCES(QRC_MOC ${res_files}) +# 根据Qt版本选择合适的命令 +if (QT_VERSION VERSION_GREATER_EQUAL "6.0") + qt_add_resources(QRC_MOC ${res_files}) +else() + qt5_add_resources(QRC_MOC ${res_files}) +endif() #INCLUDE(${QT_USE_FILE}) #ADD_DEFINITIONS(${QT_DEFINITIONS}) @@ -125,14 +136,10 @@ add_executable(${PROJECT_NAME_TEST} ${c_files} ${h_files} ${QRC_MOC} ${APP_TS_F #target_link_libraries(${PROJECT_NAME_TEST} gmock gmock_main gtest gtest_main) set_target_properties(${PROJECT_NAME_TEST} PROPERTIES AUTOMOC TRUE) -qt5_use_modules(${PROJECT_NAME_TEST} Core Widgets Gui) #链接动静态库 target_link_libraries(${PROJECT_NAME_TEST} - Qt5::Widgets - Qt5::Test - KF5::Codecs - ${DtkWidget_LIBRARIES} + ${LINK_LIBS} ${GOBJECT_LIBRARIES} ${GIO_LIBRARIES} compressor-interface diff --git a/tests/UnitTest/src/source/common/ut_commonstub.cpp b/tests/UnitTest/src/source/common/ut_commonstub.cpp index a7f7ad77a..b08be9d4d 100644 --- a/tests/UnitTest/src/source/common/ut_commonstub.cpp +++ b/tests/UnitTest/src/source/common/ut_commonstub.cpp @@ -305,12 +305,14 @@ void CommonStub::stub_QThread_wait(Stub &stub, bool bResult) void CommonStub::stub_QThreadPool_waitForDone(Stub &stub) { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) stub.set(ADDR(QThreadPool, waitForDone), qThreadPool_waitForDone_stub); +#endif } void CommonStub::stub_QProcess_startDetached(Stub &stub) { -#if !defined(Q_QDOC) +#if !defined(Q_QDOC) && (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) stub.set((bool(*)(const QString &, const QStringList &))ADDR(QProcess, startDetached), qProcess_startDetached_stub); #endif } diff --git a/tests/UnitTest/src/source/dialog/openwithdialog/ut_openwithdialog.cpp b/tests/UnitTest/src/source/dialog/openwithdialog/ut_openwithdialog.cpp index 6e8d73606..871868513 100644 --- a/tests/UnitTest/src/source/dialog/openwithdialog/ut_openwithdialog.cpp +++ b/tests/UnitTest/src/source/dialog/openwithdialog/ut_openwithdialog.cpp @@ -71,7 +71,11 @@ TEST_F(UT_OpenWithDialogListItem, test_resizeEvent) TEST_F(UT_OpenWithDialogListItem, test_enterEvent) { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QEvent *e = new QEvent(QEvent::Enter); +#else + QEnterEvent *e = new QEnterEvent(QPoint(0, 0), QPoint(0, 0), QPoint(0, 0)); +#endif m_tester->enterEvent(e); delete e; } diff --git a/tests/UnitTest/src/source/page/ut_compresssettingpage.cpp b/tests/UnitTest/src/source/page/ut_compresssettingpage.cpp index a47057290..9444aa455 100644 --- a/tests/UnitTest/src/source/page/ut_compresssettingpage.cpp +++ b/tests/UnitTest/src/source/page/ut_compresssettingpage.cpp @@ -9,7 +9,7 @@ #include "gtest/src/stub.h" -#include +#include #include #include @@ -456,7 +456,7 @@ TEST_F(UT_CompressSettingPage, test_slotFileNameChanged_001) m_tester->m_pFileNameEdt->setText(""); m_tester->slotRefreshFileNameEdit(); EXPECT_EQ(m_tester->m_pFileNameEdt->text(), ""); - DPalette plt = DApplicationHelper::instance()->palette(m_tester->m_pFileNameEdt); + DPalette plt = DPaletteHelper::instance()->palette(m_tester->m_pFileNameEdt); EXPECT_EQ(plt.brush(DPalette::Text).color(), plt.color(DPalette::WindowText)); } @@ -467,7 +467,7 @@ TEST_F(UT_CompressSettingPage, test_slotFileNameChanged_002) stub.set(ADDR(CompressSettingPage, checkFileNameVaild), checkFileNameVaild_stub); m_tester->m_pFileNameEdt->setText("hh"); m_tester->slotRefreshFileNameEdit(); - DPalette plt = DApplicationHelper::instance()->palette(m_tester->m_pFileNameEdt); + DPalette plt = DPaletteHelper::instance()->palette(m_tester->m_pFileNameEdt); EXPECT_EQ(plt.brush(DPalette::Text).color(), plt.color(DPalette::TextWarning)); } @@ -478,7 +478,7 @@ TEST_F(UT_CompressSettingPage, test_slotFileNameChanged_003) stub.set(ADDR(CompressSettingPage, checkFileNameVaild), checkFileNameVaild_stub); m_tester->m_pFileNameEdt->setText("hh"); m_tester->slotRefreshFileNameEdit(); - DPalette plt = DApplicationHelper::instance()->palette(m_tester->m_pFileNameEdt); + DPalette plt = DPaletteHelper::instance()->palette(m_tester->m_pFileNameEdt); EXPECT_EQ(plt.brush(DPalette::Text).color(), plt.color(DPalette::WindowText)); } diff --git a/tests/UnitTest/src/source/page/ut_homepage.cpp b/tests/UnitTest/src/source/page/ut_homepage.cpp index 5c8732a39..2d606e342 100644 --- a/tests/UnitTest/src/source/page/ut_homepage.cpp +++ b/tests/UnitTest/src/source/page/ut_homepage.cpp @@ -11,7 +11,6 @@ #include #include -#include #include DGUI_USE_NAMESPACE @@ -62,7 +61,11 @@ TEST_F(UT_HomePage, test_slotThemeChanged_001) Stub stub; DGuiApplicationHelperStub::stub_DGuiApplicationHelper_themeType(stub, DGuiApplicationHelper::LightType); m_tester->slotThemeChanged(); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) EXPECT_EQ(m_tester->m_pSplitLbl->pixmap()->toImage() == QPixmap(":assets/icons/deepin/builtin/light/icons/split_line.svg").toImage(), true); +#else + EXPECT_EQ(m_tester->m_pSplitLbl->pixmap().toImage() == QPixmap(":assets/icons/deepin/builtin/light/icons/split_line.svg").toImage(), true); +#endif } TEST_F(UT_HomePage, test_slotThemeChanged_002) @@ -70,7 +73,11 @@ TEST_F(UT_HomePage, test_slotThemeChanged_002) Stub stub; DGuiApplicationHelperStub::stub_DGuiApplicationHelper_themeType(stub, DGuiApplicationHelper::DarkType); m_tester->slotThemeChanged(); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) EXPECT_EQ(m_tester->m_pSplitLbl->pixmap()->toImage() == QPixmap(":assets/icons/deepin/builtin/dark/icons/split_line_dark.svg").toImage(), true); +#else + EXPECT_EQ(m_tester->m_pSplitLbl->pixmap().toImage() == QPixmap(":assets/icons/deepin/builtin/dark/icons/split_line_dark.svg").toImage(), true); +#endif } TEST_F(UT_HomePage, test_slotThemeChanged_003) @@ -78,5 +85,9 @@ TEST_F(UT_HomePage, test_slotThemeChanged_003) Stub stub; DGuiApplicationHelperStub::stub_DGuiApplicationHelper_themeType(stub, DGuiApplicationHelper::UnknownType); m_tester->slotThemeChanged(); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) EXPECT_EQ(m_tester->m_pSplitLbl->pixmap()->toImage() == QPixmap(":assets/icons/deepin/builtin/light/icons/split_line.svg").toImage(), true); +#else + EXPECT_EQ(m_tester->m_pSplitLbl->pixmap().toImage() == QPixmap(":assets/icons/deepin/builtin/light/icons/split_line.svg").toImage(), true); +#endif } diff --git a/tests/UnitTest/src/source/page/ut_uncompresspage.cpp b/tests/UnitTest/src/source/page/ut_uncompresspage.cpp index c002e4254..bb139c2f7 100644 --- a/tests/UnitTest/src/source/page/ut_uncompresspage.cpp +++ b/tests/UnitTest/src/source/page/ut_uncompresspage.cpp @@ -171,7 +171,11 @@ TEST_F(UT_UnCompressPage, test_elidedExtractPath) { Stub stub; stub.set(ADDR(UnCompressPage, width), unCompressPage_width_stub); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) stub.set((int(QFontMetrics::*)(const QString &, int)const)ADDR(QFontMetrics, width), qFontMetrics_width_stub); +#else + stub.set((int(QFontMetrics::*)(const QString &, int)const)ADDR(QFontMetrics, horizontalAdvance), qFontMetrics_width_stub); +#endif stub.set(ADDR(QFontMetrics, elidedText), elidedText_stub); QString str = "12345678912"; EXPECT_EQ(m_tester->elidedExtractPath(str).isEmpty(), false); diff --git a/tests/UnitTest/src/source/tree/ut_datamodel.cpp b/tests/UnitTest/src/source/tree/ut_datamodel.cpp index 1f1459e70..b22a3fa11 100644 --- a/tests/UnitTest/src/source/tree/ut_datamodel.cpp +++ b/tests/UnitTest/src/source/tree/ut_datamodel.cpp @@ -96,7 +96,11 @@ TEST_F(UT_DataModel, test_data_002) m_tester->m_listEntry << entry; QModelIndex index = m_tester->index(0, DC_Time); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) EXPECT_EQ(m_tester->data(index, Qt::DisplayRole), QDateTime::fromTime_t(m_tester->m_listEntry[0].uLastModifiedTime).toString("yyyy/MM/dd hh:mm:ss")); +#else + EXPECT_EQ(m_tester->data(index, Qt::DisplayRole), QDateTime::fromSecsSinceEpoch(m_tester->m_listEntry[0].uLastModifiedTime).toString("yyyy/MM/dd hh:mm:ss")); +#endif } TEST_F(UT_DataModel, test_data_003) diff --git a/tests/UnitTest/src/source/tree/ut_treeheaderview.cpp b/tests/UnitTest/src/source/tree/ut_treeheaderview.cpp index d63018432..8ef040757 100644 --- a/tests/UnitTest/src/source/tree/ut_treeheaderview.cpp +++ b/tests/UnitTest/src/source/tree/ut_treeheaderview.cpp @@ -72,7 +72,11 @@ TEST_F(UT_PreviousLabel, test_mouseDoubleClickEvent) TEST_F(UT_PreviousLabel, test_enterEvent) { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QEvent *event = new QEvent(QEvent::Enter); +#else + QEnterEvent *event = new QEnterEvent(QPoint(0, 0), QPoint(0, 0), QPoint(0, 0)); +#endif m_tester->enterEvent(event); delete event; EXPECT_EQ(m_tester->focusIn_, true); diff --git a/tests/UnitTest/src/source/tree/ut_uncompressview.cpp b/tests/UnitTest/src/source/tree/ut_uncompressview.cpp index 61a312232..e9516cd8c 100644 --- a/tests/UnitTest/src/source/tree/ut_uncompressview.cpp +++ b/tests/UnitTest/src/source/tree/ut_uncompressview.cpp @@ -798,6 +798,7 @@ TEST_F(UT_UnCompressView, test_resizeEvent) TEST_F(UT_UnCompressView, test_event) { +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QTouchDevice *pDevice = new QTouchDevice; pDevice->setType(QTouchDevice::TouchScreen); QTouchEvent *e = new QTouchEvent(QEvent::TouchBegin, pDevice, Qt::NoModifier, Qt::TouchPointPressed); @@ -807,6 +808,9 @@ TEST_F(UT_UnCompressView, test_event) delete pDevice; delete e; +#else + m_tester->m_isPressed = true; +#endif EXPECT_EQ(m_tester->m_isPressed, true); }