From 090d084fad5fda1aabed7d469ef84e93453625cb Mon Sep 17 00:00:00 2001 From: Zhang Sheng Date: Thu, 27 Jul 2023 13:13:20 +0800 Subject: [PATCH] refacotr: Adaptation for Qt6 Adaptation for Qt6 Log: Adaptation for Qt6 --- CMakeLists.txt | 17 ++++++---- debian/control | 1 - examples/dtkburn/burn_client/CMakeLists.txt | 2 +- .../dtkcompressor/CMakeLists.txt | 4 +-- examples/dtkio/io_client/CMakeLists.txt | 2 +- .../dtkmount/device_monitor/CMakeLists.txt | 26 +++++++++----- .../dtksearch/search_client/CMakeLists.txt | 6 ++-- .../cliunarchiverplugin/CMakeLists.txt | 4 +-- .../3rdparty/clizipplugin/CMakeLists.txt | 13 ++----- src/dtkcompressor/3rdparty/interface/common.h | 1 + .../interface/plugin/kpluginmetadata.h | 1 - .../3rdparty/interface/process/kprocess.h | 2 ++ .../3rdparty/libzipplugin/CMakeLists.txt | 1 - src/dtkcompressor/CMakeLists.txt | 30 +++++++++++----- .../archivemanager/processopenthread.cpp | 3 ++ .../archivemanager/processopenthread.h | 2 ++ src/dtkcompressor/archivemanager/singlejob.h | 2 ++ src/dtkcompressor/archivemanager/uitools.cpp | 28 +++++++++------ src/dtkio/dfilehelper.cpp | 8 ++++- src/dtkmount/CMakeLists.txt | 9 +++-- src/dtkmount/dbus/udisks2_dbus_common.cpp | 6 +++- src/dtkmount/dprotocoldevice.cpp | 6 ++++ src/dtksearch/CMakeLists.txt | 6 +++- .../searcher/anything/anythingsearcher.h | 4 +-- .../searcher/fulltext/fulltextsearcher.cpp | 34 +++++++++++-------- .../searcher/fulltext/fulltextsearcher.h | 4 +-- .../searcher/iterator/iteratorsearcher.cpp | 4 +-- .../searcher/iterator/iteratorsearcher.h | 4 +-- tests/dtkmount/CMakeLists.txt | 10 ++++-- 29 files changed, 150 insertions(+), 90 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d17c6d..3492c16 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,16 +31,19 @@ endif () set(CMAKE_CXX_FLAGS Release CACHE STRING "define CXXFLAGS") -if (CMAKE_BUILD_TYPE STREQUAL "Debug") - set(BUILD_TESTING ON) - set(BUILD_EXAMPLES ON) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") -endif () +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) +message("Using Qt version: ${QT_VERSION_MAJOR}") + +if(QT_VERSION_MAJOR EQUAL "5") + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + set(BUILD_TESTING ON) + set(BUILD_EXAMPLES ON) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") + endif() +endif() -find_package(QT NAMES Qt5 REQUIRED COMPONENTS Core) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core DBus) find_package(DtkCore REQUIRED) - add_compile_definitions(QT_NO_SIGNALS_SLOTS_KEYWORDS) # src diff --git a/debian/control b/debian/control index 3378dcb..8656307 100644 --- a/debian/control +++ b/debian/control @@ -19,7 +19,6 @@ Build-Depends: libsecret-1-dev, libpoppler-cpp-dev, libudisks2-qt5-dev, - libdisomaster-dev, libkf5codecs-dev, libzip-dev, libkf5archive-dev, diff --git a/examples/dtkburn/burn_client/CMakeLists.txt b/examples/dtkburn/burn_client/CMakeLists.txt index 115ce20..59c9b60 100644 --- a/examples/dtkburn/burn_client/CMakeLists.txt +++ b/examples/dtkburn/burn_client/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) -find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) find_package(Dtk COMPONENTS Core REQUIRED) #find_package(dtkburn REQUIRED) diff --git a/examples/dtkcompressor/dtkcompressor/CMakeLists.txt b/examples/dtkcompressor/dtkcompressor/CMakeLists.txt index 1073134..91357dd 100644 --- a/examples/dtkcompressor/dtkcompressor/CMakeLists.txt +++ b/examples/dtkcompressor/dtkcompressor/CMakeLists.txt @@ -12,7 +12,7 @@ set(CMAKE_AUTOUIC ON) PROJECT(testcompressor) -find_package(Qt5Widgets) +find_package(Qt${QT_VERSION_MAJOR}Widgets) find_package(PkgConfig REQUIRED) find_package(DtkCore REQUIRED) find_package(KF5Codecs REQUIRED) @@ -33,7 +33,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::DBus) set(TARGET_LIBS - Qt5::Widgets + Qt${QT_VERSION_MAJOR}::Widgets ${DtkCore_LIBRARIES} KF5::Codecs Qt${QT_VERSION_MAJOR}::DBus diff --git a/examples/dtkio/io_client/CMakeLists.txt b/examples/dtkio/io_client/CMakeLists.txt index 671cb34..82a681c 100644 --- a/examples/dtkio/io_client/CMakeLists.txt +++ b/examples/dtkio/io_client/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) -find_package(Qt5 COMPONENTS Core REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) find_package(Dtk COMPONENTS Core REQUIRED) #find_package(dtkio REQUIRED) diff --git a/examples/dtkmount/device_monitor/CMakeLists.txt b/examples/dtkmount/device_monitor/CMakeLists.txt index 0895fc2..c930f2b 100755 --- a/examples/dtkmount/device_monitor/CMakeLists.txt +++ b/examples/dtkmount/device_monitor/CMakeLists.txt @@ -9,18 +9,26 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) -find_package(Qt5 COMPONENTS Widgets Core Gui DBus LinguistTools REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Core Gui DBus LinguistTools REQUIRED) find_package(Dtk COMPONENTS Widget Core Gui REQUIRED) #find_package(dtkmount REQUIRED) file(GLOB TS_FILES CONFIGURE_DEPENDS translations/*.ts) file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS src/*.cpp include/*.h ${TS_FILES}) -qt5_create_translation( - QM_FILES - ${PROJECT_SOURCES} - ${TS_FILES} -) +if(QT_VERSION_MAJOR EQUAL "6") + qt_create_translation( + QM_FILES + ${PROJECT_SOURCES} + ${TS_FILES} + ) +else() + qt5_create_translation( + QM_FILES + ${PROJECT_SOURCES} + ${TS_FILES} + ) +endif() add_executable( ${PROJECT_NAME} @@ -35,7 +43,7 @@ target_link_libraries( ${DtkWidget_LIBRARIES} ${DtkCore_LIBRARIES} dtkmount - Qt5::Widgets - Qt5::Core - Qt5::DBus + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::DBus ) diff --git a/examples/dtksearch/search_client/CMakeLists.txt b/examples/dtksearch/search_client/CMakeLists.txt index 5a9edf2..bc2630f 100644 --- a/examples/dtksearch/search_client/CMakeLists.txt +++ b/examples/dtksearch/search_client/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) -find_package(Qt5 COMPONENTS Widgets Core Gui REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Core Gui REQUIRED) find_package(Dtk COMPONENTS Widget Core Gui REQUIRED) file(GLOB PROJECT_SOURCES CONFIGURE_DEPENDS ./*.cpp ./*.h) @@ -25,7 +25,7 @@ target_link_libraries( ${DtkWidget_LIBRARIES} ${DtkCore_LIBRARIES} dtksearch - Qt5::Widgets - Qt5::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Core ) diff --git a/src/dtkcompressor/3rdparty/cliunarchiverplugin/CMakeLists.txt b/src/dtkcompressor/3rdparty/cliunarchiverplugin/CMakeLists.txt index 7fa2f68..d302af4 100644 --- a/src/dtkcompressor/3rdparty/cliunarchiverplugin/CMakeLists.txt +++ b/src/dtkcompressor/3rdparty/cliunarchiverplugin/CMakeLists.txt @@ -7,7 +7,7 @@ project(${LIB_NAME}) #查找依赖关系的包信息 find_package(PkgConfig REQUIRED) -find_package(Qt5Widgets REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) find_package(KF5Codecs REQUIRED) include(FindPkgConfig) @@ -29,7 +29,7 @@ add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) #链接动静态库 target_link_libraries(${LIB_NAME} - Qt5::Widgets + Qt{QT_VERSION_MAJOR}::Widgets KF5::Codecs compressor-interface ) diff --git a/src/dtkcompressor/3rdparty/clizipplugin/CMakeLists.txt b/src/dtkcompressor/3rdparty/clizipplugin/CMakeLists.txt index 69c0bac..b76dad1 100644 --- a/src/dtkcompressor/3rdparty/clizipplugin/CMakeLists.txt +++ b/src/dtkcompressor/3rdparty/clizipplugin/CMakeLists.txt @@ -10,16 +10,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) find_package(PkgConfig REQUIRED) -find_package(Qt5Core REQUIRED) -find_package(Qt5DBus REQUIRED) -find_package(Qt5Gui REQUIRED) -find_package(Qt5Widgets REQUIRED) -find_package(Qt5Network REQUIRED) -find_package(Qt5 REQUIRED Widgets) -find_package(Qt5Concurrent) -find_package(Qt5Xml) -find_package(Qt5Svg REQUIRED SvgWidgets) -find_package(KF5Codecs REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Widgets Network Concurrent Xml Svg) include(FindPkgConfig) pkg_search_module(DtkWidget REQUIRED dtkwidget) @@ -47,6 +38,6 @@ file(GLOB_RECURSE json_files *.json) include_directories(${PROJECT_SOURCE_DIR}) add_library(${LIB_NAME} SHARED ${c_files} ${h_files} ${json_files}) -target_link_libraries(${LIB_NAME} Qt5::Widgets) +target_link_libraries(${LIB_NAME} Qt${QT_VERSION_MAJOR}::Widgets) target_link_libraries(${LIB_NAME} ${LIBS_INCLUDE_DIRS}) target_link_libraries( ${LIB_NAME} compressor-interface) diff --git a/src/dtkcompressor/3rdparty/interface/common.h b/src/dtkcompressor/3rdparty/interface/common.h index 6b0719e..f7b9f39 100644 --- a/src/dtkcompressor/3rdparty/interface/common.h +++ b/src/dtkcompressor/3rdparty/interface/common.h @@ -7,6 +7,7 @@ #include #include +#include class Common: public QObject { diff --git a/src/dtkcompressor/3rdparty/interface/plugin/kpluginmetadata.h b/src/dtkcompressor/3rdparty/interface/plugin/kpluginmetadata.h index 7af406c..cc82b06 100644 --- a/src/dtkcompressor/3rdparty/interface/plugin/kpluginmetadata.h +++ b/src/dtkcompressor/3rdparty/interface/plugin/kpluginmetadata.h @@ -26,7 +26,6 @@ class KPluginLoader; class QPluginLoader; -class QStringList; class KPluginMetaDataPrivate; class KAboutPerson; class QObject; diff --git a/src/dtkcompressor/3rdparty/interface/process/kprocess.h b/src/dtkcompressor/3rdparty/interface/process/kprocess.h index 9b22318..0933467 100644 --- a/src/dtkcompressor/3rdparty/interface/process/kprocess.h +++ b/src/dtkcompressor/3rdparty/interface/process/kprocess.h @@ -335,11 +335,13 @@ class KProcess : public QProcess KProcessPrivate *const d_ptr; private: +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) // hide those using QProcess::setReadChannelMode; using QProcess::readChannelMode; using QProcess::setProcessChannelMode; using QProcess::processChannelMode; +#endif Q_PRIVATE_SLOT(d_func(), void _k_forwardStdout()) Q_PRIVATE_SLOT(d_func(), void _k_forwardStderr()) diff --git a/src/dtkcompressor/3rdparty/libzipplugin/CMakeLists.txt b/src/dtkcompressor/3rdparty/libzipplugin/CMakeLists.txt index 40fa3e9..14141e2 100644 --- a/src/dtkcompressor/3rdparty/libzipplugin/CMakeLists.txt +++ b/src/dtkcompressor/3rdparty/libzipplugin/CMakeLists.txt @@ -28,7 +28,6 @@ add_library(${LIB_NAME} SHARED ${c_files} ${json_files} ${h_files}) #链接动静态库 target_link_libraries(${LIB_NAME} -# Qt5::Core KF5::Codecs interfacecompressor zip diff --git a/src/dtkcompressor/CMakeLists.txt b/src/dtkcompressor/CMakeLists.txt index 1967ce2..497bdfb 100644 --- a/src/dtkcompressor/CMakeLists.txt +++ b/src/dtkcompressor/CMakeLists.txt @@ -20,10 +20,12 @@ if(NOT DEFINED HFILES_OUTPUT_PATH) set(HFILES_OUTPUT_PATH ${CMAKE_BINARY_DIR}/include) endif() add_subdirectory(3rdparty) - find_package(KF5Codecs REQUIRED) find_package(PkgConfig REQUIRED) find_package(DtkCore REQUIRED) +if(QT_VERSION_MAJOR EQUAL "6") + find_package(Qt6Core5Compat REQUIRED) +endif() target_include_directories(${BIN_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include/${BIN_NAME}/) target_include_directories(${BIN_NAME} PUBLIC ${KF5Codecs_INCLUDE_DIRS}) @@ -34,18 +36,28 @@ set_target_properties(${BIN_NAME} PROPERTIES target_compile_definitions(${BIN_NAME} PRIVATE VERSION="${CMAKE_PROJECT_VERSION}") +if(QT_VERSION_MAJOR EQUAL "6") + target_link_libraries(${BIN_NAME} PRIVATE + Qt${QT_VERSION_MAJOR}::Core + Qt6::Core5Compat + ${DtkCore_LIBRARIES} + interfacecompressor + KF5::Codecs + ) +else() + target_link_libraries(${BIN_NAME} PRIVATE + Qt${QT_VERSION_MAJOR}::Core + ${DtkCore_LIBRARIES} + interfacecompressor + KF5::Codecs + ) +endif() + + target_include_directories(${BIN_NAME} PUBLIC - Qt${QT_VERSION_MAJOR}::Core ${HFILES_OUTPUT_PATH} ) -target_link_libraries(${BIN_NAME} PRIVATE - Qt${QT_VERSION_MAJOR}::Core - ${DtkCore_LIBRARIES} - interfacecompressor - KF5::Codecs -) - install(FILES ${INCLUDE_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${BIN_NAME}) install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR}) diff --git a/src/dtkcompressor/archivemanager/processopenthread.cpp b/src/dtkcompressor/archivemanager/processopenthread.cpp index 609e3d6..ecf8df8 100644 --- a/src/dtkcompressor/archivemanager/processopenthread.cpp +++ b/src/dtkcompressor/archivemanager/processopenthread.cpp @@ -4,6 +4,9 @@ #include "processopenthread.h" #include "kprocess.h" + +#include + DCOMPRESSOR_USE_NAMESPACE ProcessOpenThread::ProcessOpenThread(QObject *parent) : QThread(parent) diff --git a/src/dtkcompressor/archivemanager/processopenthread.h b/src/dtkcompressor/archivemanager/processopenthread.h index 4594b8c..5af3e07 100644 --- a/src/dtkcompressor/archivemanager/processopenthread.h +++ b/src/dtkcompressor/archivemanager/processopenthread.h @@ -9,6 +9,8 @@ #include "plugin.h" #include +#include + #include "dcompressornamespace.h" DCOMPRESSOR_BEGIN_NAMESPACE diff --git a/src/dtkcompressor/archivemanager/singlejob.h b/src/dtkcompressor/archivemanager/singlejob.h index 68c3851..09d4add 100644 --- a/src/dtkcompressor/archivemanager/singlejob.h +++ b/src/dtkcompressor/archivemanager/singlejob.h @@ -10,6 +10,8 @@ #include "commonstruct.h" #include "queries.h" #include "dcompressornamespace.h" + +#include #include #include diff --git a/src/dtkcompressor/archivemanager/uitools.cpp b/src/dtkcompressor/archivemanager/uitools.cpp index 180ea58..a8d716d 100644 --- a/src/dtkcompressor/archivemanager/uitools.cpp +++ b/src/dtkcompressor/archivemanager/uitools.cpp @@ -140,7 +140,11 @@ bool UiTools::isArchiveFile(const QString &strFileName) bool UiTools::isExistMimeType(const QString &strMimeType, bool &bArchive) { QString conf = readConf(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QStringList confList = conf.split("\n", Qt::SkipEmptyParts); +#else QStringList confList = conf.split("\n", QString::SkipEmptyParts); +#endif bool exist = false; for (int i = 0; i < confList.count(); i++) { @@ -291,10 +295,10 @@ ReadOnlyArchiveInterface *UiTools::createInterface(const QString &fileName, cons void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitType &eSplitType) { if (fileName.contains(".7z.")) { - QRegExp reg("^([\\s\\S]*\\.)7z\\.[0-9]{3}$"); - - if (reg.exactMatch(fileName)) { - fileName = reg.cap(1) + "7z.001"; + QRegularExpression reg("^([\\s\\S]*\\.)7z\\.[0-9]{3}$"); + QRegularExpressionMatch match = reg.match(fileName); + if (match.hasMatch()) { + fileName = match.captured(1) + "7z.001"; eSplitType = UnCompressParameter::ST_Other; } } else if (fileName.contains(".part") && fileName.endsWith(".rar")) { @@ -309,11 +313,12 @@ void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitTy eSplitType = UnCompressParameter::ST_Other; } else if (fileName.contains(".zip.")) { - QRegExp reg("^([\\s\\S]*\\.)zip\\.[0-9]{3}$"); - if (reg.exactMatch(fileName)) { - QFileInfo fi(reg.cap(1) + "zip.001"); + QRegularExpression reg("^([\\s\\S]*\\.)zip\\.[0-9]{3}$"); + QRegularExpressionMatch match = reg.match(fileName); + if (match.hasMatch()) { + QFileInfo fi(match.captured(1) + "zip.001"); if (fi.exists() == true) { - fileName = reg.cap(1) + "zip.001"; + fileName = match.captured(1) + "zip.001"; eSplitType = UnCompressParameter::ST_Zip; } } @@ -323,9 +328,10 @@ void UiTools::transSplitFileName(QString &fileName, UnCompressParameter::SplitTy eSplitType = UnCompressParameter::ST_Zip; } } else if (fileName.contains(".z")) { - QRegExp reg("^([\\s\\S]*\\.)z[0-9]+$"); // - if (reg.exactMatch(fileName)) { - fileName = reg.cap(1) + "zip"; + QRegularExpression reg("^([\\s\\S]*\\.)z[0-9]+$"); // + QRegularExpressionMatch match = reg.match(fileName); + if (match.hasMatch()) { + fileName = match.captured(1) + "zip"; QFileInfo fi(fileName); if (fi.exists()) { eSplitType = UnCompressParameter::ST_Zip; diff --git a/src/dtkio/dfilehelper.cpp b/src/dtkio/dfilehelper.cpp index 751a292..84c5545 100644 --- a/src/dtkio/dfilehelper.cpp +++ b/src/dtkio/dfilehelper.cpp @@ -412,7 +412,13 @@ QSet hideListFromUrl(const QUrl &url) if (succ) { if (contents && len > 0) { QString dataStr(contents); - return QSet::fromList(dataStr.split('\n', QString::SkipEmptyParts)); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + const QStringList strs { dataStr.split('\n', Qt::SkipEmptyParts) }; + return QSet { strs.begin(), strs.end() }; +#else + const QStringList strs { dataStr.split('\n', QString::SkipEmptyParts) }; + return QSet::fromList(strs); +#endif } } else { qWarning() << "load .hidden fail, url: " << url << " error: " << error->code << " " << QString::fromLocal8Bit(error->message); diff --git a/src/dtkmount/CMakeLists.txt b/src/dtkmount/CMakeLists.txt index 6944aea..f6a5967 100644 --- a/src/dtkmount/CMakeLists.txt +++ b/src/dtkmount/CMakeLists.txt @@ -17,8 +17,13 @@ set_source_files_properties( ${UDISKS2_XML} PROPERTIES NO_NAMESPACE true INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/dbus/udisks2_dbus_common.h ) -qt5_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface) -qt5_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface) +if(QT_VERSION_MAJOR EQUAL "6") + qt_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface) + qt_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface) +else() + qt5_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface) + qt5_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface) +endif() add_library(${BIN_NAME} SHARED ${INCLUDE_FILES} diff --git a/src/dtkmount/dbus/udisks2_dbus_common.cpp b/src/dtkmount/dbus/udisks2_dbus_common.cpp index 1e925ab..f757800 100644 --- a/src/dtkmount/dbus/udisks2_dbus_common.cpp +++ b/src/dtkmount/dbus/udisks2_dbus_common.cpp @@ -51,7 +51,11 @@ OrgFreedesktopDBusObjectManagerInterface *objectManager() qDBusRegisterMetaType>(); qDBusRegisterMetaType>>(); - QMetaType::registerDebugStreamOperator>>(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + // TODO +#else + QMetaType::registerDebugStreamOperator>>(); +#endif } return omGlobal; diff --git a/src/dtkmount/dprotocoldevice.cpp b/src/dtkmount/dprotocoldevice.cpp index 04b49cb..ef4b998 100644 --- a/src/dtkmount/dprotocoldevice.cpp +++ b/src/dtkmount/dprotocoldevice.cpp @@ -202,8 +202,14 @@ QStringList DProtocolDevice::iconNames() const return {}; g_autofree char *names = g_icon_to_string(icon); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + if (names) + d->icons = QString(names).remove(". GThemedIcon").split(" ", Qt::SkipEmptyParts); +#else if (names) d->icons = QString(names).remove(". GThemedIcon").split(" ", QString::SkipEmptyParts); +#endif + return d->icons; } diff --git a/src/dtksearch/CMakeLists.txt b/src/dtksearch/CMakeLists.txt index d93f949..41cbba3 100644 --- a/src/dtksearch/CMakeLists.txt +++ b/src/dtksearch/CMakeLists.txt @@ -11,7 +11,11 @@ file(GLOB_RECURSE SRCS ) set(QRC_FILE qrc/resources.qrc) -qt5_add_resources(QRC_RESOURCES ${QRC_FILE}) +if(QT_VERSION_MAJOR EQUAL "6") + qt_add_resources(QRC_RESOURCES ${QRC_FILE}) +else() + qt5_add_resources(QRC_RESOURCES ${QRC_FILE}) +endif() add_library(${BIN_NAME} SHARED ${INCLUDE_FILES} diff --git a/src/dtksearch/searcher/anything/anythingsearcher.h b/src/dtksearch/searcher/anything/anythingsearcher.h index 8524617..ea0f2d8 100644 --- a/src/dtksearch/searcher/anything/anythingsearcher.h +++ b/src/dtksearch/searcher/anything/anythingsearcher.h @@ -6,7 +6,7 @@ #define ANYTHINGSEARCHER_H #include -#include +#include #include "dtksearch_global.h" #include "searcher/abstractsearcher.h" @@ -33,7 +33,7 @@ class AnythingSearcher : public AbstractSearcher QStringList allResults; mutable QMutex mutex; - QTime notifyTimer; + QElapsedTimer notifyTimer; int lastEmit = 0; }; diff --git a/src/dtksearch/searcher/fulltext/fulltextsearcher.cpp b/src/dtksearch/searcher/fulltext/fulltextsearcher.cpp index e93adc1..ec36165 100644 --- a/src/dtksearch/searcher/fulltext/fulltextsearcher.cpp +++ b/src/dtksearch/searcher/fulltext/fulltextsearcher.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include @@ -85,7 +87,7 @@ bool FullTextSearcher::createIndex(const QString &path) try { // record spending - QTime timer; + QElapsedTimer timer; timer.start(); IndexWriterPtr writer = newIndexWriter(true); qDebug() << "Indexing to directory: " << m_indexPath; @@ -161,7 +163,8 @@ DocumentPtr FullTextSearcher::fileDocument(const QString &file) // file last modified time QFileInfo info(file); - QString modifyTime = QString::number(info.lastModified().toTime_t()); + QDateTime lastModified = info.lastModified(); + QString modifyTime = QString::number(lastModified.toSecsSinceEpoch()); doc->add(newLucene(L"modified", modifyTime.toStdWString(), Field::STORE_YES, Field::INDEX_NOT_ANALYZED)); // file contents @@ -214,8 +217,8 @@ void FullTextSearcher::doSearch(const QString &path, const QString &keyword) indexDocuments(writer, info.absoluteFilePath(), DeleteIndex); continue; } - - const QString &modifyTime = QString::number(info.lastModified().toTime_t()); + QDateTime lastModified = info.lastModified(); + const QString &modifyTime = QString::number(lastModified.toSecsSinceEpoch()); const String &storeTime = doc->get(L"modified"); if (modifyTime.toStdWString() != storeTime) { continue; @@ -251,8 +254,8 @@ void FullTextSearcher::doIndexTask(const IndexReaderPtr &reader, const IndexWrit return; // filter some folders - static QRegExp reg(Utils::kNotSupportDirectories); - if (bindPathTable.contains(path) || (reg.exactMatch(path) && !path.startsWith("/run/user"))) + static QRegularExpression reg(Utils::kNotSupportDirectories); + if (bindPathTable.contains(path) || (reg.match(path).hasMatch() && !path.startsWith("/run/user"))) return; // limit file name length and level @@ -290,8 +293,8 @@ void FullTextSearcher::doIndexTask(const IndexReaderPtr &reader, const IndexWrit } else { QFileInfo info(fn); QString suffix = info.suffix(); - static QRegExp suffixRegExp(Utils::kSupportFiles); - if (suffixRegExp.exactMatch(suffix)) { + static QRegularExpression suffixRegExp(Utils::kSupportFiles); + if (suffixRegExp.match(suffix).hasMatch()) { switch (type) { case Create: indexDocuments(writer, fn, AddIndex); @@ -368,7 +371,8 @@ bool FullTextSearcher::checkUpdate(const IndexReaderPtr &reader, const QString & } else { DocumentPtr doc = searcher->doc(topDocs->scoreDocs[0]->doc); QFileInfo info(file); - const QString &modifyTime = QString::number(info.lastModified().toTime_t()); + QDateTime lastModified = info.lastModified(); + const QString &modifyTime = QString::number(lastModified.toSecsSinceEpoch()); const String &storeTime = doc->get(L"modified"); if (modifyTime.toStdWString() != storeTime) { @@ -389,18 +393,18 @@ bool FullTextSearcher::checkUpdate(const IndexReaderPtr &reader, const QString & QString FullTextSearcher::dealKeyword(const QString &keyword) { - static QRegExp cnReg("^[\u4e00-\u9fa5]"); - static QRegExp enReg("^[A-Za-z]+$"); - static QRegExp numReg("^[0-9]$"); + static QRegularExpression cnReg("^[\u4e00-\u9fa5]"); + static QRegularExpression enReg("^[A-Za-z]+$"); + static QRegularExpression numReg("^[0-9]$"); QString oldType = "cn", currType = "cn"; QString newStr; for (auto c : keyword) { - if (cnReg.exactMatch(c)) { + if (cnReg.match(c).hasMatch()) { currType = "cn"; - } else if (enReg.exactMatch(c)) { + } else if (enReg.match(c).hasMatch()) { currType = "en"; - } else if (numReg.exactMatch(c)) { + } else if (numReg.match(c).hasMatch()) { currType = "digit"; } else { newStr += ' '; diff --git a/src/dtksearch/searcher/fulltext/fulltextsearcher.h b/src/dtksearch/searcher/fulltext/fulltextsearcher.h index 7998db0..3b19cfb 100644 --- a/src/dtksearch/searcher/fulltext/fulltextsearcher.h +++ b/src/dtksearch/searcher/fulltext/fulltextsearcher.h @@ -7,7 +7,7 @@ #include -#include +#include #include #include "dtksearch_global.h" @@ -61,7 +61,7 @@ class FullTextSearcher : public AbstractSearcher QMap bindPathTable; QAtomicInt status = AbstractSearcher::Ready; - QTime notifyTimer; + QElapsedTimer notifyTimer; int lastEmit = 0; }; diff --git a/src/dtksearch/searcher/iterator/iteratorsearcher.cpp b/src/dtksearch/searcher/iterator/iteratorsearcher.cpp index 0ad7bc4..fbd8bbf 100644 --- a/src/dtksearch/searcher/iterator/iteratorsearcher.cpp +++ b/src/dtksearch/searcher/iterator/iteratorsearcher.cpp @@ -71,10 +71,10 @@ void IteratorSearcher::doSearch() return; const auto &path = searchPathList.takeAt(0); - QRegExp reg(Utils::kNotSupportDirectories); + QRegularExpression reg(Utils::kNotSupportDirectories); // The filter directory can be searched only when // searching in the filter directory - if (!reg.exactMatch(m_searchPath) && reg.exactMatch(path)) + if (!reg.match(m_searchPath).hasMatch() && reg.match(path).hasMatch()) continue; QDirIterator iterator(path, QDir::NoDotAndDotDot | QDir::Dirs | QDir::Files); diff --git a/src/dtksearch/searcher/iterator/iteratorsearcher.h b/src/dtksearch/searcher/iterator/iteratorsearcher.h index 2bb6120..4bcd556 100644 --- a/src/dtksearch/searcher/iterator/iteratorsearcher.h +++ b/src/dtksearch/searcher/iterator/iteratorsearcher.h @@ -5,7 +5,7 @@ #ifndef ITERATORSEARCHER_H #define ITERATORSEARCHER_H -#include +#include #include #include @@ -37,7 +37,7 @@ class IteratorSearcher : public AbstractSearcher QRegularExpression regex; quint32 resultCount = 0; - QTime notifyTimer; + QElapsedTimer notifyTimer; int lastEmit = 0; }; diff --git a/tests/dtkmount/CMakeLists.txt b/tests/dtkmount/CMakeLists.txt index 1648a56..f55d262 100644 --- a/tests/dtkmount/CMakeLists.txt +++ b/tests/dtkmount/CMakeLists.txt @@ -22,9 +22,13 @@ set_source_files_properties( ${UDISKS2_XML} PROPERTIES NO_NAMESPACE true INCLUDE ${PROJECT_SOURCE_DIR}/src/dtkmount/dbus/udisks2_dbus_common.h ) -qt5_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface) -qt5_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface) - +if(QT_VERSION_MAJOR EQUAL "6") + qt_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface) + qt_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface) +else() + qt5_add_dbus_interface(SRCS ${UDISKS2_OBJECT_XML} objectmanager_interface) + qt5_add_dbus_interface(SRCS ${UDISKS2_XML} udisks2_interface) +endif() include_directories( "${PROJECT_SOURCE_DIR}/include/dtkmount/"