File indexing completed on 2024-05-19 11:41:33
0001 /* 0002 SPDX-FileCopyrightText: 2019 Christoph Feck <cfeck@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef LEGACY_CODEC_H 0008 #define LEGACY_CODEC_H 0009 0010 #include <QTextCodec> 0011 0012 class LegacyCodec : public QTextCodec 0013 { 0014 public: 0015 LegacyCodec() 0016 { 0017 if (codecForLocale()->mibEnum() == 106) { 0018 setCodecForLocale(this); 0019 } 0020 } 0021 0022 ~LegacyCodec() override 0023 { 0024 setCodecForLocale(nullptr); 0025 } 0026 0027 QList<QByteArray> aliases() const override 0028 { 0029 return QList<QByteArray>(); 0030 } 0031 0032 int mibEnum() const override 0033 { 0034 return 106; 0035 } 0036 0037 QByteArray name() const override 0038 { 0039 return QByteArray("UTF-8"); 0040 } 0041 0042 protected: 0043 QByteArray convertFromUnicode(const QChar *input, int number, QTextCodec::ConverterState *state) const override 0044 { 0045 Q_UNUSED(state); 0046 return encodeFileNameUTF8(QString::fromRawData(input, number)); 0047 } 0048 0049 QString convertToUnicode(const char *chars, int len, QTextCodec::ConverterState *state) const override 0050 { 0051 Q_UNUSED(state); 0052 return decodeFileNameUTF8(QByteArray::fromRawData(chars, len)); 0053 } 0054 0055 private: 0056 static QByteArray encodeFileNameUTF8(const QString &fileName); 0057 static QString decodeFileNameUTF8(const QByteArray &localFileName); 0058 }; 0059 0060 #endif // define LEGACY_CODEC_H