Skip to content

Commit

Permalink
Changes that will need to be reworked.
Browse files Browse the repository at this point in the history
QFont changed the weight scale in Qt6, in order to use them we'd need to fix all configuration files in all themes.
QStreamConverter only supports Utf8/16/32 and Latin1 before Qt6.5. Stick to qt5compat's QTextCodec by now
  • Loading branch information
ctrlaltca committed Oct 18, 2023
1 parent b62b83e commit 2d1bc24
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions src/kvilib/ext/KviStringConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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"));
Expand Down
25 changes: 20 additions & 5 deletions src/kvilib/file/KviFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@
#include <QString>
#include <QStringList>
#include <QtGlobal>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <QTextCodec>
#else
#include <QStringConverter>
#endif
#include <QTextStream>

namespace KviFileUtils
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -326,24 +336,29 @@ 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();
}

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();
Expand Down
11 changes: 9 additions & 2 deletions src/modules/file/libkvifile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
#include <QFileInfo>
#include <QDir>
#include <QTextStream>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <QTextCodec>
#else
#include <QStringConverter>
#endif
#include <QByteArray>
#include <QDateTime>

Expand Down Expand Up @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion src/modules/help/HelpIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
#include <QByteArray>
#include <QTextStream>
#include <QUrl>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <QTextCodec>
#else
#include <QStringConverter>
#endif
#include <cctype>
#include <QTextDocument>
#include <QTimer>
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion src/modules/logview/LogFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
#include <QDir>
#include <QTextStream>
#include <QLocale>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <QTextCodec>
#else
#include <QStringConverter>
#endif

#ifdef COMPILE_ZLIB_SUPPORT
#include <zlib.h>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2d1bc24

Please sign in to comment.