1 /*
2  * Replacement fot QT Bindings that were removed from QT5
3  * Copyright (C) 2020  Pedro de Carvalho Gomes <pedrogomes81@gmail.com>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef CORETEXTCODEC_H
20 #define CORETEXTCODEC_H
21 
22 #include "QtBinding.h"
23 #include "CoreByteArray.h"
24 
25 #include <QObject>
26 #include <QTextCodec>
27 
28 class QJSEngine;
29 
30 namespace QtBindings
31 {
32     namespace Core
33     {
34         class TextCodec : public QObject, public QtBindings::Base<TextCodec>
35         {
36         Q_OBJECT
37         public:
38             Q_INVOKABLE TextCodec();
39             Q_INVOKABLE TextCodec(const QTextCodec* coded);
40             Q_INVOKABLE TextCodec(const TextCodec& codec);
41             Q_INVOKABLE ~TextCodec();
42             Q_INVOKABLE static QList<QByteArray> availableCodecs();
43             Q_INVOKABLE static QList<int> availableMibs();
44             Q_INVOKABLE static TextCodec codecForHtml(const ByteArray &ba, QTextCodec *defaultCodec);
45             Q_INVOKABLE static TextCodec codecForHtml(const ByteArray &ba);
46             Q_INVOKABLE static TextCodec codecForLocale();
47             Q_INVOKABLE static TextCodec codecForMib(int mib);
48             Q_INVOKABLE static TextCodec codecForName(const ByteArray &name);
49             Q_INVOKABLE static TextCodec codecForName(const char *name);
50             Q_INVOKABLE static TextCodec codecForUtfText(const ByteArray &ba, QTextCodec *defaultCodec);
51             Q_INVOKABLE static TextCodec codecForUtfText(const ByteArray &ba);
52             Q_INVOKABLE static void setCodecForLocale(QTextCodec *c);
53             TextCodec &operator=(const TextCodec &other);
54         public slots:
55             virtual QList<QByteArray> aliases() const;
56             bool canEncode(QChar ch) const;
57             bool canEncode(const QString &s) const;
58             ByteArray fromUnicode(const QString &str) const;
59             ByteArray fromUnicode(const QChar *input, int number, QTextCodec::ConverterState *state = Q_NULLPTR) const;
60             /*
61             QTextDecoder *makeDecoder(ConversionFlags flags = DefaultConversion) const;
62             QTextEncoder *makeEncoder(ConversionFlags flags = DefaultConversion) const;
63              */
64             virtual int	mibEnum();
65             virtual ByteArray name();
66             QString toUnicode(const ByteArray &a) const;
67             QString toUnicode(const char *chars) const;
68             QString toUnicode(const char *input, int size, QTextCodec::ConverterState *state = Q_NULLPTR) const;
69         private:
70             const QTextCodec *internal;
71         };
72     }
73 }
74 Q_DECLARE_METATYPE(QtBindings::Core::TextCodec)
75 #endif //CORETEXTCODEC_H
76