File indexing completed on 2025-01-05 04:26:48

0001 /*
0002  * Replacement fot QT Bindings that were removed from QT5
0003  * Copyright (C) 2020  Pedro de Carvalho Gomes <pedrogomes81@gmail.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 #ifndef CORETEXTCODEC_H
0020 #define CORETEXTCODEC_H
0021 
0022 #include "QtBinding.h"
0023 #include "CoreByteArray.h"
0024 
0025 #include <QObject>
0026 #include <QTextCodec>
0027 
0028 class QJSEngine;
0029 
0030 namespace QtBindings
0031 {
0032     namespace Core
0033     {
0034         class TextCodec : public QObject, public QtBindings::Base<TextCodec>
0035         {
0036         Q_OBJECT
0037         public:
0038             Q_INVOKABLE TextCodec();
0039             Q_INVOKABLE TextCodec(const QTextCodec* coded);
0040             Q_INVOKABLE TextCodec(const TextCodec& codec);
0041             Q_INVOKABLE ~TextCodec();
0042             Q_INVOKABLE static QList<QByteArray> availableCodecs();
0043             Q_INVOKABLE static QList<int> availableMibs();
0044             Q_INVOKABLE static TextCodec codecForHtml(const ByteArray &ba, QTextCodec *defaultCodec);
0045             Q_INVOKABLE static TextCodec codecForHtml(const ByteArray &ba);
0046             Q_INVOKABLE static TextCodec codecForLocale();
0047             Q_INVOKABLE static TextCodec codecForMib(int mib);
0048             Q_INVOKABLE static TextCodec codecForName(const ByteArray &name);
0049             Q_INVOKABLE static TextCodec codecForName(const char *name);
0050             Q_INVOKABLE static TextCodec codecForUtfText(const ByteArray &ba, QTextCodec *defaultCodec);
0051             Q_INVOKABLE static TextCodec codecForUtfText(const ByteArray &ba);
0052             Q_INVOKABLE static void setCodecForLocale(QTextCodec *c);
0053             TextCodec &operator=(const TextCodec &other);
0054         public slots:
0055             virtual QList<QByteArray> aliases() const;
0056             bool canEncode(QChar ch) const;
0057             bool canEncode(const QString &s) const;
0058             ByteArray fromUnicode(const QString &str) const;
0059             ByteArray fromUnicode(const QChar *input, int number, QTextCodec::ConverterState *state = Q_NULLPTR) const;
0060             /*
0061             QTextDecoder *makeDecoder(ConversionFlags flags = DefaultConversion) const;
0062             QTextEncoder *makeEncoder(ConversionFlags flags = DefaultConversion) const;
0063              */
0064             virtual int mibEnum();
0065             virtual ByteArray name();
0066             QString toUnicode(const ByteArray &a) const;
0067             QString toUnicode(const char *chars) const;
0068             QString toUnicode(const char *input, int size, QTextCodec::ConverterState *state = Q_NULLPTR) const;
0069         private:
0070             const QTextCodec *internal;
0071         };
0072     }
0073 }
0074 Q_DECLARE_METATYPE(QtBindings::Core::TextCodec)
0075 #endif //CORETEXTCODEC_H