diff --git a/CMakeLists.txt b/CMakeLists.txt index ea6c20d22..e34c16872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -421,7 +421,7 @@ set(CMAKE_STATUS_QX11INFO_SUPPORT "Not available") include_directories(${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS}) list(APPEND qt_kvirc_modules Qt::Widgets) -# Qt6 Compat module for Qt5; Needed by QRegExp +# Qt6 Compat module for Qt5; Needed by QTextCodec if(${QT_VERSION_MAJOR} EQUAL 6) find_package(Qt6 REQUIRED COMPONENTS Core5Compat) if(Qt6Core5Compat_FOUND) diff --git a/src/kvilib/ext/KviStringConversion.cpp b/src/kvilib/ext/KviStringConversion.cpp index 8b8e557ea..b12a1ef84 100644 --- a/src/kvilib/ext/KviStringConversion.cpp +++ b/src/kvilib/ext/KviStringConversion.cpp @@ -226,7 +226,13 @@ namespace KviStringConversion void toString(const QFont & font, QString & szBuffer) { QString szFamily(font.family()); - szBuffer = QString::asprintf("%s,%d,%d,%d", szFamily.toUtf8().data(), font.pointSize(), font.styleHint(), font.weight()); + szBuffer = QString::asprintf("%s,%d,%d,%d", szFamily.toUtf8().data(), font.pointSize(), font.styleHint(), +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + font.weight() +#else + font.legacyWeight() +#endif + ); QString szOptions; if(font.bold()) szOptions.append('b'); @@ -266,8 +272,11 @@ namespace KviStringConversion buffer.setStyleHint((QFont::StyleHint)i); i = weight.toInt(&bOk); if(bOk && (i >= 0)) +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) buffer.setWeight(i); - +#else + buffer.setLegacyWeight(i); +#endif buffer.setBold(str.contains("b")); buffer.setItalic(str.contains("i")); buffer.setUnderline(str.contains("u")); diff --git a/src/kvilib/file/KviFileUtils.cpp b/src/kvilib/file/KviFileUtils.cpp index 283bdc501..755557912 100644 --- a/src/kvilib/file/KviFileUtils.cpp +++ b/src/kvilib/file/KviFileUtils.cpp @@ -34,7 +34,11 @@ #include #include #include +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #include +#else +#include +#endif #include namespace KviFileUtils @@ -263,7 +267,13 @@ namespace KviFileUtils KviFile f(szPath); if(!f.open(QFile::WriteOnly | (bAppend ? QFile::Append : QFile::Truncate))) return false; +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) QByteArray szTmp = QTextCodec::codecForLocale()->fromUnicode(szData); +#else + QStringEncoder enc = QStringEncoder(QStringConverter::Latin1); + QByteArray szTmp = enc.encode(szData); +#endif + if(f.write(szTmp.data(), szTmp.length()) != ((unsigned int)(szTmp.length()))) return false; return true; @@ -326,14 +336,16 @@ namespace KviFileUtils bool readLine(QFile * pFile, QString & szBuffer, bool bUtf8) { QTextStream stream(pFile); - // By default, QTextCodec::codecForLocale() is used, and automatic unicode detection is enabled. - if(bUtf8) - stream.setCodec(QTextCodec::codecForMib(106)); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) /* * Name: UTF-8 * MIBenum: 106 * from: http://www.iana.org/assignments/character-sets */ + stream.setCodec(bUtf8 ? QTextCodec::codecForMib(106) : QTextCodec::codecForLocale()); +#else + stream.setEncoding(bUtf8 ? QStringConverter::Utf8 : QStringConverter::Latin1); +#endif szBuffer = stream.readLine(); return !szBuffer.isNull(); } @@ -341,9 +353,12 @@ namespace KviFileUtils bool readLines(QFile * pFile, QStringList & buffer, int iStartLine, int iCount, bool bUtf8) { QTextStream stream(pFile); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) //please read comments in the readLine(...) method - if(bUtf8) - stream.setCodec(QTextCodec::codecForMib(106)); + stream.setCodec(bUtf8 ? QTextCodec::codecForMib(106) : QTextCodec::codecForLocale()); +#else + stream.setEncoding(bUtf8 ? QStringConverter::Utf8 : QStringConverter::Latin1); +#endif for(int i = 0; i < iStartLine; i++) stream.readLine(); diff --git a/src/modules/file/libkvifile.cpp b/src/modules/file/libkvifile.cpp index b57cd7f26..ac527f720 100644 --- a/src/modules/file/libkvifile.cpp +++ b/src/modules/file/libkvifile.cpp @@ -35,7 +35,11 @@ #include #include #include +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #include +#else +#include +#endif #include #include @@ -1081,8 +1085,11 @@ static bool file_kvs_fnc_readLines(KviKvsModuleFunctionCall * c) QTextStream stream(&f); - if(!bLocal8Bit) - stream.setCodec(QTextCodec::codecForMib(106)); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + stream.setCodec(bLocal8Bit ? QTextCodec::codecForLocale() : QTextCodec::codecForMib(106)); +#else + stream.setEncoding(bLocal8Bit ? QStringConverter::Latin1 : QStringConverter::Utf8); +#endif for(int i = 0; i < iStartLine; i++) stream.readLine(); diff --git a/src/modules/help/HelpIndex.cpp b/src/modules/help/HelpIndex.cpp index 4ce07616f..33c42781a 100644 --- a/src/modules/help/HelpIndex.cpp +++ b/src/modules/help/HelpIndex.cpp @@ -44,7 +44,11 @@ #include #include #include +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) #include +#else +#include +#endif #include #include #include @@ -200,7 +204,11 @@ void HelpIndex::parseDocument(const QString & filename, int docNum) } QTextStream s(&file); - s.setCodec(QTextCodec::codecForMib(106)); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + s.setCodec(QTextCodec::codecForMib(106)); +#else + s.setEncoding(QStringConverter::Utf8); +#endif QString text = s.readAll(); if(text.isNull()) return; diff --git a/src/modules/logview/LogFile.cpp b/src/modules/logview/LogFile.cpp index 471099b73..200a2cb0c 100644 --- a/src/modules/logview/LogFile.cpp +++ b/src/modules/logview/LogFile.cpp @@ -40,6 +40,11 @@ #include #include #include +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) +#include +#else +#include +#endif #ifdef COMPILE_ZLIB_SUPPORT #include @@ -431,7 +436,11 @@ void LogFile::createLog(ExportType exportType, QString szLog, QString * pszFile) // Ensure we're writing in UTF-8 QTextStream output(&log); - output.setCodec("UTF-8"); +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) + output.setCodec(QTextCodec::codecForMib(106)); +#else + output.setEncoding(QStringConverter::Utf8); +#endif output << szOutputBuffer; // Close file descriptors