diff --git a/CMakeLists.txt b/CMakeLists.txt index b8f9d107..6ac577f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,6 +135,37 @@ elseif(QV2RAY_USE_QWIDGET) QVLOG(QV2RAY_QNODEEDITOR_PROVIDER) endif() +option(QV2RAY_QT6 "Use Qt6 for Debugging") +QVLOG(QV2RAY_QT6) +if(QV2RAY_QT6) + cmake_policy(SET CMP0072 NEW) + set(QV_QT_MAJOR_VERSION 6) + set(QV_QT_MINOR_VERSION 0) + set(QV_QT_LIBNAME Qt6) + #From: https://github.com/KDE/kwin/blob/master/cmake/modules/FindXKB.cmake#L35 + find_package(PkgConfig) + pkg_check_modules(PKG_XKB QUIET xkbcommon) + set(XKB_DEFINITIONS ${PKG_XKB_CFLAGS_OTHER}) + find_path(XKB_INCLUDE_DIR NAMES xkbcommon/xkbcommon.h HINTS ${PKG_XKB_INCLUDE_DIRS}) + find_library(XKB_LIBRARY NAMES xkbcommon HINTS ${PKG_XKB_LIBRARY_DIRS}) + set(XKB_LIBRARIES ${XKB_LIBRARY}) + set(XKB_INCLUDE_DIRS ${XKB_INCLUDE_DIR}) + set(XKB_VERSION ${PKG_XKB_VERSION}) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(XKB FOUND_VAR XKB_FOUND REQUIRED_VARS XKB_LIBRARY XKB_INCLUDE_DIR VERSION_VAR XKB_VERSION) + add_library(XKB::XKB UNKNOWN IMPORTED) + set_target_properties(XKB::XKB PROPERTIES + IMPORTED_LOCATION "${XKB_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${XKB_DEFINITIONS}" + INTERFACE_INCLUDE_DIRECTORIES "${XKB_INCLUDE_DIR}" + ) +else() + set(QV_QT_MAJOR_VERSION 5) + set(QV_QT_MINOR_VERSION 11) + set(QV_QT_LIBNAME Qt5) +endif() + + # ================================================================================== # Default Core/Assets Path # ================================================================================== @@ -210,8 +241,8 @@ include(cmake/backend.cmake) # Qv2ray Base, Qt Libraries, Qv2ray GUI Libraries, libThreads # ================================================================================== find_package(Threads REQUIRED) -find_package(Qt5 5.11 COMPONENTS Core Network REQUIRED) -list(APPEND QV2RAY_QT_LIBS Qt5::Core Qt5::Network) +find_package(${QV_QT_LIBNAME} ${QV_QT_MAJOR_VERSION}.${QV_QT_MINOR_VERSION} COMPONENTS Core Network REQUIRED) +list(APPEND QV2RAY_QT_LIBS ${QV_QT_LIBNAME}::Core ${QV_QT_LIBNAME}::Network) cmake_policy(SET CMP0071 NEW) set(CMAKE_AUTOMOC ON) @@ -219,12 +250,21 @@ set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) if(QV2RAY_USE_QML) - find_package(Qt5 5.11 COMPONENTS Qml Quick Widgets Svg QuickControls2 Gui REQUIRED) - list(APPEND QV2RAY_QT_LIBS Qt5::Quick Qt5::Qml Qt5::Widgets Qt5::Svg Qt5::QuickControls2 Qt5::Gui) + find_package(${QV_QT_LIBNAME} ${QV_QT_MAJOR_VERSION}.${QV_QT_MINOR_VERSION} COMPONENTS Qml Quick Widgets Svg QuickControls2 Gui REQUIRED) + list(APPEND QV2RAY_QT_LIBS + ${QV_QT_LIBNAME}::Quick + ${QV_QT_LIBNAME}::Qml + ${QV_QT_LIBNAME}::Widgets + ${QV_QT_LIBNAME}::Svg + ${QV_QT_LIBNAME}::QuickControls2 + ${QV_QT_LIBNAME}::Gui) set(_QV2RAY_HAS_GUI_INTERNAL_ ON) elseif(QV2RAY_USE_QWIDGET) - find_package(Qt5 5.11 COMPONENTS Widgets Svg Gui REQUIRED) - list(APPEND QV2RAY_QT_LIBS Qt5::Widgets Qt5::Svg Qt5::Gui) + find_package(${QV_QT_LIBNAME} ${QV_QT_MAJOR_VERSION}.${QV_QT_MINOR_VERSION} COMPONENTS Widgets Svg Gui REQUIRED) + list(APPEND QV2RAY_QT_LIBS + ${QV_QT_LIBNAME}::Widgets + ${QV_QT_LIBNAME}::Svg + ${QV_QT_LIBNAME}::Gui) set(_QV2RAY_HAS_GUI_INTERNAL_ ON) else() endif() diff --git a/cmake/components/qv2ray-platform.cmake b/cmake/components/qv2ray-platform.cmake index 34f07082..7c94f004 100644 --- a/cmake/components/qv2ray-platform.cmake +++ b/cmake/components/qv2ray-platform.cmake @@ -1,8 +1,8 @@ if(ANDROID) - find_package(Qt5 COMPONENTS AndroidExtras REQUIRED) + find_package(${QV_QT_LIBNAME} COMPONENTS AndroidExtras REQUIRED) list(APPEND QV2RAY_PLATFORM_SOURCES ${CMAKE_SOURCE_DIR}/src/platforms/android/QvVPNService.hpp ${CMAKE_SOURCE_DIR}/src/platforms/android/QvVPNService.cpp ) - list(APPEND QV2RAY_PLATFORM_LIBS Qt5::AndroidExtras -llog -landroid) + list(APPEND QV2RAY_PLATFORM_LIBS ${QV_QT_LIBNAME}::AndroidExtras -llog -landroid) endif() diff --git a/cmake/qnodeeditor.cmake b/cmake/qnodeeditor.cmake index a4550f9d..f2b2a23c 100644 --- a/cmake/qnodeeditor.cmake +++ b/cmake/qnodeeditor.cmake @@ -74,9 +74,9 @@ if(QV2RAY_QNODEEDITOR_PROVIDER STREQUAL "module") ${QNODEEDITOR_INCLUDE_PATH} ) target_link_libraries(${QNODEEDITOR_LIBRARY} - Qt5::Core - Qt5::Widgets - Qt5::Gui + ${QV_QT_LIBNAME}::Core + ${QV_QT_LIBNAME}::Widgets + ${QV_QT_LIBNAME}::Gui ) set(QNODEEDITOR_QRC_RESOURCES ${QNODEEDITOR_DIR}/resources/resources.qrc) elseif(QV2RAY_QNODEEDITOR_PROVIDER STREQUAL "package") diff --git a/cmake/translations.cmake b/cmake/translations.cmake index 006e70d3..67e106ca 100644 --- a/cmake/translations.cmake +++ b/cmake/translations.cmake @@ -1,4 +1,6 @@ -find_package(Qt5 COMPONENTS LinguistTools) +find_package(${QV_QT_LIBNAME} COMPONENTS LinguistTools) set(TRANSLATIONS_DIR ${CMAKE_SOURCE_DIR}/translations) file(GLOB TRANSLATIONS_TS ${TRANSLATIONS_DIR}/**.ts) -qt5_add_translation(QV2RAY_QM_FILES ${TRANSLATIONS_TS}) +if(NOT QV2RAY_QT6) + qt5_add_translation(QV2RAY_QM_FILES ${TRANSLATIONS_TS}) +endif() diff --git a/src/plugin-interface b/src/plugin-interface index 15c68565..7340650c 160000 --- a/src/plugin-interface +++ b/src/plugin-interface @@ -1 +1 @@ -Subproject commit 15c68565a7c18027cc7694ec7c4e5cd8aefd4ee4 +Subproject commit 7340650c79b9ff5c20784295e7274743dbbd6249 diff --git a/src/plugins/protocols/QvPlugin-BuiltinProtocolSupport.cmake b/src/plugins/protocols/QvPlugin-BuiltinProtocolSupport.cmake index eef7b85b..71bffeb2 100644 --- a/src/plugins/protocols/QvPlugin-BuiltinProtocolSupport.cmake +++ b/src/plugins/protocols/QvPlugin-BuiltinProtocolSupport.cmake @@ -68,4 +68,4 @@ else() message(FATAL_ERROR "?") endif() -target_link_libraries(${BUILT_IN_PROTOCOL_PLUGIN_TARGET} Qt5::Core Qt5::Gui Qt5::Widgets) +target_link_libraries(${BUILT_IN_PROTOCOL_PLUGIN_TARGET} ${QV_QT_LIBNAME}::Core ${QV_QT_LIBNAME}::Gui ${QV_QT_LIBNAME}::Widgets) diff --git a/src/ui/common/autolaunch/QvAutoLaunch.cpp b/src/ui/common/autolaunch/QvAutoLaunch.cpp index 01d3f62c..e0e1534e 100644 --- a/src/ui/common/autolaunch/QvAutoLaunch.cpp +++ b/src/ui/common/autolaunch/QvAutoLaunch.cpp @@ -165,7 +165,7 @@ namespace Qv2ray::components::autolaunch QString appName = QCoreApplication::applicationName(); QString userAutoStartPath = getUserAutostartDir_private(); QString desktopFileLocation = userAutoStartPath + appName + QLatin1String(".desktop"); - QStringList appCmdList = QCoreApplication::arguments(); + QStringList appCmdList = QCoreApplication::arguments(); appCmdList.replace(0, binPath); if (enable) @@ -187,16 +187,18 @@ namespace Qv2ray::components::autolaunch } QTextStream ts(&iniFile); + #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) ts.setCodec("UTF-8"); - ts << QLatin1String("[Desktop Entry]") << NEWLINE // - << QLatin1String("Name=") << appName << NEWLINE // - << QLatin1String("GenericName=") << QLatin1String("V2Ray Frontend") << NEWLINE // - << QLatin1String("Exec=") << appCmdList.join(" ") << NEWLINE // - << QLatin1String("Terminal=") << "false" << NEWLINE // - << QLatin1String("Icon=") << "qv2ray" << NEWLINE // - << QLatin1String("Categories=") << "Network" << NEWLINE // - << QLatin1String("Type=") << "Application" << NEWLINE // - << QLatin1String("StartupNotify=") << "false" << NEWLINE // + #endif + ts << QLatin1String("[Desktop Entry]") << NEWLINE // + << QLatin1String("Name=") << appName << NEWLINE // + << QLatin1String("GenericName=") << QLatin1String("V2Ray Frontend") << NEWLINE // + << QLatin1String("Exec=") << appCmdList.join(" ") << NEWLINE // + << QLatin1String("Terminal=") << "false" << NEWLINE // + << QLatin1String("Icon=") << "qv2ray" << NEWLINE // + << QLatin1String("Categories=") << "Network" << NEWLINE // + << QLatin1String("Type=") << "Application" << NEWLINE // + << QLatin1String("StartupNotify=") << "false" << NEWLINE // << QLatin1String("X-GNOME-Autostart-enabled=") << "true" << NEWLINE; ts.flush(); iniFile.close(); diff --git a/src/ui/widgets/editors/w_InboundEditor.cpp b/src/ui/widgets/editors/w_InboundEditor.cpp index 0162e2f3..dfe49ad0 100644 --- a/src/ui/widgets/editors/w_InboundEditor.cpp +++ b/src/ui/widgets/editors/w_InboundEditor.cpp @@ -24,7 +24,11 @@ InboundEditor::InboundEditor(INBOUND source, QWidget *parent) : QDialog(parent), auto l = new QGridLayout(); l->setHorizontalSpacing(0); l->setVerticalSpacing(0); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + l->setContentsMargins(0, 0, 0, 0); +#else l->setMargin(0); +#endif transportFrame->setLayout(l); } transportFrame->layout()->addWidget(streamSettingsWidget); diff --git a/src/ui/widgets/windows/w_MainWindow.cpp b/src/ui/widgets/windows/w_MainWindow.cpp index 25d90c7b..cf534262 100644 --- a/src/ui/widgets/windows/w_MainWindow.cpp +++ b/src/ui/widgets/windows/w_MainWindow.cpp @@ -93,7 +93,7 @@ void MainWindow::SortConnectionList(MW_ITEM_COL byCol, bool asending) void MainWindow::ReloadRecentConnectionList() { QList newRecentConnections; - const auto iterateRange = std::min(GlobalConfig.uiConfig.maxJumpListCount, GlobalConfig.uiConfig.recentConnections.count()); + const auto iterateRange = std::min(GlobalConfig.uiConfig.maxJumpListCount, (int) GlobalConfig.uiConfig.recentConnections.count()); for (auto i = 0; i < iterateRange; i++) { const auto &item = GlobalConfig.uiConfig.recentConnections.at(i); @@ -1213,7 +1213,7 @@ void MainWindow::Action_CopyRecentLogs() if (!accepted) return; const auto totalLinesCount = lines.count(); - const auto linesToCopy = std::min(totalLinesCount, line); + const auto linesToCopy = std::min((int) totalLinesCount, line); QStringList result; for (auto i = totalLinesCount - linesToCopy; i < totalLinesCount; i++) { diff --git a/src/ui/widgets/windows/w_MainWindow_extra.cpp b/src/ui/widgets/windows/w_MainWindow_extra.cpp index e020ef9f..4dee368d 100644 --- a/src/ui/widgets/windows/w_MainWindow_extra.cpp +++ b/src/ui/widgets/windows/w_MainWindow_extra.cpp @@ -83,12 +83,12 @@ void MainWindow::CheckSubscriptionsUpdate() if (info.subscriptionOption.updateInterval == 0) continue; // - const auto lastRenewDate = QDateTime::fromTime_t(info.lastUpdatedDate); + const auto lastRenewDate = QDateTime::fromSecsSinceEpoch(info.lastUpdatedDate); const auto renewTime = lastRenewDate.addSecs(info.subscriptionOption.updateInterval * 86400); if (renewTime <= QDateTime::currentDateTime()) { - updateList << QPair{ info.displayName, entry }; + updateList << QPair{ info.displayName, entry }; updateNamesList << info.displayName; LOG(MODULE_SUBSCRIPTION, QString("Subscription update \"%1\": L=%2 R=%3 I=%4") .arg(info.displayName) diff --git a/src/utils/QvHelpers.cpp b/src/utils/QvHelpers.cpp index fa98a419..6f6ffe09 100644 --- a/src/utils/QvHelpers.cpp +++ b/src/utils/QvHelpers.cpp @@ -3,6 +3,10 @@ #include "3rdparty/puresource/src/PureJson.hpp" #include "base/Qv2rayBase.hpp" +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + #include +#endif + namespace Qv2ray::common { const QString GenerateRandomString(int len) @@ -35,7 +39,16 @@ namespace Qv2ray::common auto byteArray = source.readAll(); if (!wasOpened) source.close(); - // +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + for (const auto &encoding : { QStringDecoder::Utf8, QStringDecoder::Utf16, QStringDecoder::System }) + { + auto converter = QStringDecoder(encoding, QStringConverter::Flag::ConvertInvalidToNull); + const auto data = converter(byteArray).data; + if (!data.contains("\0")) + return data; + } + Q_ASSERT_X(false, Q_FUNC_INFO, "Unsupported File Encoding"); +#else QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QTextCodec::ConverterState state; const QString text = codec->toUnicode(byteArray.constData(), byteArray.size(), &state); @@ -44,6 +57,7 @@ namespace Qv2ray::common LOG(MODULE_FILEIO, "Not a valid UTF-8 sequence: " + source.fileName()) } return state.invalidChars > 0 ? byteArray : text; +#endif } bool StringToFile(const QString &text, const QString &targetpath) @@ -142,7 +156,9 @@ namespace Qv2ray::common QStringList SplitLines(const QString &_string) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + return _string.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts); +#elif QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) return _string.split(QRegExp("[\r\n]"), Qt::SkipEmptyParts); #else return _string.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);