add: try supporting Qt6

This commit is contained in:
QxQ 2020-09-17 20:38:29 +08:00
parent 72204d5096
commit f1da8f1159
11 changed files with 95 additions and 31 deletions

View File

@ -135,6 +135,37 @@ elseif(QV2RAY_USE_QWIDGET)
QVLOG(QV2RAY_QNODEEDITOR_PROVIDER) QVLOG(QV2RAY_QNODEEDITOR_PROVIDER)
endif() 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 # Default Core/Assets Path
# ================================================================================== # ==================================================================================
@ -210,8 +241,8 @@ include(cmake/backend.cmake)
# Qv2ray Base, Qt Libraries, Qv2ray GUI Libraries, libThreads # Qv2ray Base, Qt Libraries, Qv2ray GUI Libraries, libThreads
# ================================================================================== # ==================================================================================
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
find_package(Qt5 5.11 COMPONENTS Core Network REQUIRED) find_package(${QV_QT_LIBNAME} ${QV_QT_MAJOR_VERSION}.${QV_QT_MINOR_VERSION} COMPONENTS Core Network REQUIRED)
list(APPEND QV2RAY_QT_LIBS Qt5::Core Qt5::Network) list(APPEND QV2RAY_QT_LIBS ${QV_QT_LIBNAME}::Core ${QV_QT_LIBNAME}::Network)
cmake_policy(SET CMP0071 NEW) cmake_policy(SET CMP0071 NEW)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
@ -219,12 +250,21 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOUIC ON)
if(QV2RAY_USE_QML) if(QV2RAY_USE_QML)
find_package(Qt5 5.11 COMPONENTS Qml Quick Widgets Svg QuickControls2 Gui REQUIRED) 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 Qt5::Quick Qt5::Qml Qt5::Widgets Qt5::Svg Qt5::QuickControls2 Qt5::Gui) 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) set(_QV2RAY_HAS_GUI_INTERNAL_ ON)
elseif(QV2RAY_USE_QWIDGET) elseif(QV2RAY_USE_QWIDGET)
find_package(Qt5 5.11 COMPONENTS Widgets Svg Gui REQUIRED) find_package(${QV_QT_LIBNAME} ${QV_QT_MAJOR_VERSION}.${QV_QT_MINOR_VERSION} COMPONENTS Widgets Svg Gui REQUIRED)
list(APPEND QV2RAY_QT_LIBS Qt5::Widgets Qt5::Svg Qt5::Gui) list(APPEND QV2RAY_QT_LIBS
${QV_QT_LIBNAME}::Widgets
${QV_QT_LIBNAME}::Svg
${QV_QT_LIBNAME}::Gui)
set(_QV2RAY_HAS_GUI_INTERNAL_ ON) set(_QV2RAY_HAS_GUI_INTERNAL_ ON)
else() else()
endif() endif()

View File

@ -1,8 +1,8 @@
if(ANDROID) if(ANDROID)
find_package(Qt5 COMPONENTS AndroidExtras REQUIRED) find_package(${QV_QT_LIBNAME} COMPONENTS AndroidExtras REQUIRED)
list(APPEND QV2RAY_PLATFORM_SOURCES list(APPEND QV2RAY_PLATFORM_SOURCES
${CMAKE_SOURCE_DIR}/src/platforms/android/QvVPNService.hpp ${CMAKE_SOURCE_DIR}/src/platforms/android/QvVPNService.hpp
${CMAKE_SOURCE_DIR}/src/platforms/android/QvVPNService.cpp ${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() endif()

View File

@ -74,9 +74,9 @@ if(QV2RAY_QNODEEDITOR_PROVIDER STREQUAL "module")
${QNODEEDITOR_INCLUDE_PATH} ${QNODEEDITOR_INCLUDE_PATH}
) )
target_link_libraries(${QNODEEDITOR_LIBRARY} target_link_libraries(${QNODEEDITOR_LIBRARY}
Qt5::Core ${QV_QT_LIBNAME}::Core
Qt5::Widgets ${QV_QT_LIBNAME}::Widgets
Qt5::Gui ${QV_QT_LIBNAME}::Gui
) )
set(QNODEEDITOR_QRC_RESOURCES ${QNODEEDITOR_DIR}/resources/resources.qrc) set(QNODEEDITOR_QRC_RESOURCES ${QNODEEDITOR_DIR}/resources/resources.qrc)
elseif(QV2RAY_QNODEEDITOR_PROVIDER STREQUAL "package") elseif(QV2RAY_QNODEEDITOR_PROVIDER STREQUAL "package")

View File

@ -1,4 +1,6 @@
find_package(Qt5 COMPONENTS LinguistTools) find_package(${QV_QT_LIBNAME} COMPONENTS LinguistTools)
set(TRANSLATIONS_DIR ${CMAKE_SOURCE_DIR}/translations) set(TRANSLATIONS_DIR ${CMAKE_SOURCE_DIR}/translations)
file(GLOB TRANSLATIONS_TS ${TRANSLATIONS_DIR}/**.ts) 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()

@ -1 +1 @@
Subproject commit 15c68565a7c18027cc7694ec7c4e5cd8aefd4ee4 Subproject commit 7340650c79b9ff5c20784295e7274743dbbd6249

View File

@ -68,4 +68,4 @@ else()
message(FATAL_ERROR "?") message(FATAL_ERROR "?")
endif() 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)

View File

@ -187,7 +187,9 @@ namespace Qv2ray::components::autolaunch
} }
QTextStream ts(&iniFile); QTextStream ts(&iniFile);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
ts.setCodec("UTF-8"); ts.setCodec("UTF-8");
#endif
ts << QLatin1String("[Desktop Entry]") << NEWLINE // ts << QLatin1String("[Desktop Entry]") << NEWLINE //
<< QLatin1String("Name=") << appName << NEWLINE // << QLatin1String("Name=") << appName << NEWLINE //
<< QLatin1String("GenericName=") << QLatin1String("V2Ray Frontend") << NEWLINE // << QLatin1String("GenericName=") << QLatin1String("V2Ray Frontend") << NEWLINE //

View File

@ -24,7 +24,11 @@ InboundEditor::InboundEditor(INBOUND source, QWidget *parent) : QDialog(parent),
auto l = new QGridLayout(); auto l = new QGridLayout();
l->setHorizontalSpacing(0); l->setHorizontalSpacing(0);
l->setVerticalSpacing(0); l->setVerticalSpacing(0);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
l->setContentsMargins(0, 0, 0, 0);
#else
l->setMargin(0); l->setMargin(0);
#endif
transportFrame->setLayout(l); transportFrame->setLayout(l);
} }
transportFrame->layout()->addWidget(streamSettingsWidget); transportFrame->layout()->addWidget(streamSettingsWidget);

View File

@ -93,7 +93,7 @@ void MainWindow::SortConnectionList(MW_ITEM_COL byCol, bool asending)
void MainWindow::ReloadRecentConnectionList() void MainWindow::ReloadRecentConnectionList()
{ {
QList<ConnectionGroupPair> newRecentConnections; QList<ConnectionGroupPair> 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++) for (auto i = 0; i < iterateRange; i++)
{ {
const auto &item = GlobalConfig.uiConfig.recentConnections.at(i); const auto &item = GlobalConfig.uiConfig.recentConnections.at(i);
@ -1213,7 +1213,7 @@ void MainWindow::Action_CopyRecentLogs()
if (!accepted) if (!accepted)
return; return;
const auto totalLinesCount = lines.count(); const auto totalLinesCount = lines.count();
const auto linesToCopy = std::min(totalLinesCount, line); const auto linesToCopy = std::min((int) totalLinesCount, line);
QStringList result; QStringList result;
for (auto i = totalLinesCount - linesToCopy; i < totalLinesCount; i++) for (auto i = totalLinesCount - linesToCopy; i < totalLinesCount; i++)
{ {

View File

@ -83,12 +83,12 @@ void MainWindow::CheckSubscriptionsUpdate()
if (info.subscriptionOption.updateInterval == 0) if (info.subscriptionOption.updateInterval == 0)
continue; 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); const auto renewTime = lastRenewDate.addSecs(info.subscriptionOption.updateInterval * 86400);
if (renewTime <= QDateTime::currentDateTime()) if (renewTime <= QDateTime::currentDateTime())
{ {
updateList << QPair{ info.displayName, entry }; updateList << QPair<QString, GroupId>{ info.displayName, entry };
updateNamesList << info.displayName; updateNamesList << info.displayName;
LOG(MODULE_SUBSCRIPTION, QString("Subscription update \"%1\": L=%2 R=%3 I=%4") LOG(MODULE_SUBSCRIPTION, QString("Subscription update \"%1\": L=%2 R=%3 I=%4")
.arg(info.displayName) .arg(info.displayName)

View File

@ -3,6 +3,10 @@
#include "3rdparty/puresource/src/PureJson.hpp" #include "3rdparty/puresource/src/PureJson.hpp"
#include "base/Qv2rayBase.hpp" #include "base/Qv2rayBase.hpp"
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QStringConverter>
#endif
namespace Qv2ray::common namespace Qv2ray::common
{ {
const QString GenerateRandomString(int len) const QString GenerateRandomString(int len)
@ -35,7 +39,16 @@ namespace Qv2ray::common
auto byteArray = source.readAll(); auto byteArray = source.readAll();
if (!wasOpened) if (!wasOpened)
source.close(); 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 *codec = QTextCodec::codecForName("UTF-8");
QTextCodec::ConverterState state; QTextCodec::ConverterState state;
const QString text = codec->toUnicode(byteArray.constData(), byteArray.size(), &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()) LOG(MODULE_FILEIO, "Not a valid UTF-8 sequence: " + source.fileName())
} }
return state.invalidChars > 0 ? byteArray : text; return state.invalidChars > 0 ? byteArray : text;
#endif
} }
bool StringToFile(const QString &text, const QString &targetpath) bool StringToFile(const QString &text, const QString &targetpath)
@ -142,7 +156,9 @@ namespace Qv2ray::common
QStringList SplitLines(const QString &_string) 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); return _string.split(QRegExp("[\r\n]"), Qt::SkipEmptyParts);
#else #else
return _string.split(QRegExp("[\r\n]"), QString::SkipEmptyParts); return _string.split(QRegExp("[\r\n]"), QString::SkipEmptyParts);