1 | /* |
2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
3 | * |
4 | * This program is free software: you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation, either version 3 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | */ |
17 | #ifndef QT_UTILS_CHARSETINFO_H |
18 | #define QT_UTILS_CHARSETINFO_H |
19 | #include <QByteArray> |
20 | #include <QString> |
21 | #include <memory> |
22 | #include <QObject> |
23 | |
24 | struct CharsetInfo{ |
25 | int codepage; |
26 | QByteArray name; |
27 | QString language; |
28 | QString localeName; |
29 | bool enabled; |
30 | explicit CharsetInfo(int codepage, |
31 | const QByteArray& name, |
32 | const QString& language, |
33 | const QString& locale, |
34 | bool enabled); |
35 | }; |
36 | |
37 | using PCharsetInfo = std::shared_ptr<CharsetInfo>; |
38 | |
39 | class CharsetInfoManager: public QObject { |
40 | Q_OBJECT |
41 | public: |
42 | explicit CharsetInfoManager(const QString& localeName); |
43 | QByteArray getDefaultSystemEncoding(); |
44 | PCharsetInfo findCharsetByCodepage(int codepage); |
45 | QStringList languageNames(); |
46 | QList<PCharsetInfo> findCharsetsByLanguageName(const QString& languageName); |
47 | QList<PCharsetInfo> findCharsetByLocale(const QString& localeName); |
48 | QString findLanguageByCharsetName(const QString& encodingName); |
49 | const QString &localeName() const; |
50 | |
51 | private: |
52 | QList<PCharsetInfo> mCodePages; |
53 | QString mLocaleName; |
54 | }; |
55 | |
56 | using PCharsetInfoManager = std::shared_ptr<CharsetInfo>; |
57 | |
58 | extern CharsetInfoManager* pCharsetInfoManager; |
59 | |
60 | #endif // PLATFORM_H |
61 | |