/* * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "platform.h" #include #include #include #include #ifdef Q_OS_WIN #include #else #include #endif CharsetInfoManager* pCharsetInfoManager; QByteArray CharsetInfoManager::getDefaultSystemEncoding() { #ifdef Q_OS_WIN DWORD acp = GetACP(); PCharsetInfo info = findCharsetByCodepage(acp); if (info) { return info->name; } return "unknown"; #else return QByteArray(nl_langinfo(CODESET)); #endif } PCharsetInfo CharsetInfoManager::findCharsetByCodepage(int codepage) { foreach (const PCharsetInfo& info, mCodePages) { if (info->codepage == codepage) return info; } return PCharsetInfo(); } QStringList CharsetInfoManager::languageNames() { QSet languages; foreach (const PCharsetInfo& info, mCodePages) { if (info->enabled) languages.insert(info->language); } QStringList lst; foreach (const QString& s, languages) lst.append(s); lst.sort(Qt::CaseInsensitive); return lst; } QList CharsetInfoManager::findCharsetsByLanguageName(const QString &languageName) { QList result; foreach (const PCharsetInfo& info, mCodePages) { if (info->language == languageName && info->enabled) result.append(info); } std::sort(result.begin(),result.end(),[](const PCharsetInfo& info1,const PCharsetInfo& info2){ return (info1->name < info2->name); }); return result; } CharsetInfoManager::CharsetInfoManager():QObject() { mCodePages.append(std::make_shared(37,"IBM037","",false)); mCodePages.append(std::make_shared(437,"IBM437","",false)); mCodePages.append(std::make_shared(500,"IBM500","",false)); mCodePages.append(std::make_shared(708,"ASMO-708","",false)); mCodePages.append(std::make_shared(709,"","",false)); mCodePages.append(std::make_shared(710,"","",false)); mCodePages.append(std::make_shared(720,"DOS-720",tr("Arabic"),false)); mCodePages.append(std::make_shared(737,"ibm737",tr("Greek"),false)); mCodePages.append(std::make_shared(775,"ibm775",tr("Baltic"),false)); mCodePages.append(std::make_shared(850,"ibm850",tr("Western Europe"),false)); mCodePages.append(std::make_shared(852,"ibm852",tr("Central Europe"),false)); mCodePages.append(std::make_shared(855,"IBM855",tr("Cyrillic"),false)); mCodePages.append(std::make_shared(857,"ibm857",tr("Turkish"),false)); mCodePages.append(std::make_shared(858,"ibm858",tr("Western Europe"),false)); mCodePages.append(std::make_shared(860,"IBM860",tr("Western Europe"),false)); mCodePages.append(std::make_shared(861,"ibm861",tr("Northern Europe"),false)); mCodePages.append(std::make_shared(862,"DOS-862",tr("Hebrew"),false)); mCodePages.append(std::make_shared(863,"IBM863",tr("Western Europe"),false)); mCodePages.append(std::make_shared(864,"IBM864","",false)); mCodePages.append(std::make_shared(865,"IBM865",tr("Northern Europe"),false)); mCodePages.append(std::make_shared(866,"cp866",tr("Cyrillic"),false)); mCodePages.append(std::make_shared(869,"ibm869",tr("Greek"),false)); mCodePages.append(std::make_shared(870,"IBM870","",false)); mCodePages.append(std::make_shared(874,"tis-620",tr("Thai"),true)); mCodePages.append(std::make_shared(875,"cp875","",false)); mCodePages.append(std::make_shared(932,"shift_jis",tr("Japanese"),true)); mCodePages.append(std::make_shared(936,"gbk",tr("Chinese"),true)); mCodePages.append(std::make_shared(949,"windows-949",tr("Korean"),true)); mCodePages.append(std::make_shared(950,"big5",tr("Chinese"),true)); mCodePages.append(std::make_shared(1026,"IBM1026","",false)); mCodePages.append(std::make_shared(1047,"IBM01047","",false)); mCodePages.append(std::make_shared(1140,"IBM01140","",false)); mCodePages.append(std::make_shared(1141,"IBM01141","",false)); mCodePages.append(std::make_shared(1142,"IBM01142","",false)); mCodePages.append(std::make_shared(1143,"IBM01143","",false)); mCodePages.append(std::make_shared(1144,"IBM01144","",false)); mCodePages.append(std::make_shared(1145,"IBM01145","",false)); mCodePages.append(std::make_shared(1146,"IBM01146","",false)); mCodePages.append(std::make_shared(1147,"IBM01147","",false)); mCodePages.append(std::make_shared(1148,"IBM01148","",false)); mCodePages.append(std::make_shared(1149,"IBM01149","",false)); mCodePages.append(std::make_shared(1200,"utf-16","",false)); mCodePages.append(std::make_shared(1201,"unicodeFFFE","",false)); mCodePages.append(std::make_shared(1250,"windows-1250",tr("Central Europe"),true)); mCodePages.append(std::make_shared(1251,"windows-1251",tr("Cyrillic"),true)); mCodePages.append(std::make_shared(1252,"windows-1252",tr("Western Europe"),true)); mCodePages.append(std::make_shared(1253,"windows-1253",tr("Greek"),true)); mCodePages.append(std::make_shared(1254,"windows-1254",tr("Turkish"),true)); mCodePages.append(std::make_shared(1255,"windows-1255",tr("Hebrew"),true)); mCodePages.append(std::make_shared(1256,"windows-1256",tr("Arabic"),true)); mCodePages.append(std::make_shared(1257,"windows-1257",tr("Baltic"),true)); mCodePages.append(std::make_shared(1258,"windows-1258",tr("Vietnamese"),true)); mCodePages.append(std::make_shared(1361,"Johab","",false)); mCodePages.append(std::make_shared(10000,"macintosh",tr("Cyrillic"),true)); mCodePages.append(std::make_shared(10001,"x-mac-japanese","",false)); mCodePages.append(std::make_shared(10002,"x-mac-chinesetrad","",false)); mCodePages.append(std::make_shared(10003,"x-mac-korean","",false)); mCodePages.append(std::make_shared(10004,"x-mac-arabic","",false)); mCodePages.append(std::make_shared(10005,"x-mac-hebrew","",false)); mCodePages.append(std::make_shared(10006,"x-mac-greek","",false)); mCodePages.append(std::make_shared(10007,"x-mac-cyrillic","",false)); mCodePages.append(std::make_shared(10008,"x-mac-chinesesimp","",false)); mCodePages.append(std::make_shared(10010,"x-mac-romanian","",false)); mCodePages.append(std::make_shared(10017,"x-mac-ukrainian","",false)); mCodePages.append(std::make_shared(10021,"x-mac-thai","",false)); mCodePages.append(std::make_shared(10029,"x-mac-ce","",false)); mCodePages.append(std::make_shared(10079,"x-mac-icelandic","",false)); mCodePages.append(std::make_shared(10081,"x-mac-turkish","",false)); mCodePages.append(std::make_shared(10082,"x-mac-croatian","",false)); mCodePages.append(std::make_shared(12000,"utf-32","",false)); mCodePages.append(std::make_shared(12001,"utf-32BE","",false)); mCodePages.append(std::make_shared(20000,"x-Chinese_CNS","",false)); mCodePages.append(std::make_shared(20001,"x-cp20001","",false)); mCodePages.append(std::make_shared(20002,"x_Chinese-Eten","",false)); mCodePages.append(std::make_shared(20003,"x-cp20003","",false)); mCodePages.append(std::make_shared(20004,"x-cp20004","",false)); mCodePages.append(std::make_shared(20005,"x-cp20005","",false)); mCodePages.append(std::make_shared(20105,"x-IA5","",false)); mCodePages.append(std::make_shared(20106,"x-IA5-German","",false)); mCodePages.append(std::make_shared(20107,"x-IA5-Swedish","",false)); mCodePages.append(std::make_shared(20108,"x-IA5-Norwegian","",false)); mCodePages.append(std::make_shared(20127,"us-ascii","",false)); mCodePages.append(std::make_shared(20261,"x-cp20261","",false)); mCodePages.append(std::make_shared(20269,"x-cp20269","",false)); mCodePages.append(std::make_shared(20273,"IBM273","",false)); mCodePages.append(std::make_shared(20277,"IBM277","",false)); mCodePages.append(std::make_shared(20278,"IBM278","",false)); mCodePages.append(std::make_shared(20280,"IBM280","",false)); mCodePages.append(std::make_shared(20284,"IBM284","",false)); mCodePages.append(std::make_shared(20285,"IBM285","",false)); mCodePages.append(std::make_shared(20290,"IBM290","",false)); mCodePages.append(std::make_shared(20297,"IBM297","",false)); mCodePages.append(std::make_shared(20420,"IBM420","",false)); mCodePages.append(std::make_shared(20423,"IBM423","",false)); mCodePages.append(std::make_shared(20424,"IBM424","",false)); mCodePages.append(std::make_shared(20833,"x-EBCDIC-KoreanExtended","",false)); mCodePages.append(std::make_shared(20838,"IBM-Thai","",false)); mCodePages.append(std::make_shared(20866,"koi8-r",tr("Cyrillic"),true)); mCodePages.append(std::make_shared(20871,"IBM871","",false)); mCodePages.append(std::make_shared(20880,"IBM880","",false)); mCodePages.append(std::make_shared(20905,"IBM905","",false)); mCodePages.append(std::make_shared(20924,"IBM00924","",false)); mCodePages.append(std::make_shared(20932,"EUC-JP","",false)); mCodePages.append(std::make_shared(20936,"x-cp20936","",false)); mCodePages.append(std::make_shared(20949,"x-cp20949","",false)); mCodePages.append(std::make_shared(21025,"cp1025","",false)); mCodePages.append(std::make_shared(21027,"","",false)); mCodePages.append(std::make_shared(21866,"koi8-u",tr("Cyrillic"),true)); mCodePages.append(std::make_shared(28591,"iso-8859-1",tr("Western Europe"),true)); mCodePages.append(std::make_shared(28592,"iso-8859-2",tr("Eastern Europe"),true)); mCodePages.append(std::make_shared(28593,"iso-8859-3",tr("Turkish"),true)); mCodePages.append(std::make_shared(28594,"iso-8859-4",tr("Baltic"),true)); mCodePages.append(std::make_shared(28595,"iso-8859-5",tr("Cyrillic"),true)); mCodePages.append(std::make_shared(28596,"iso-8859-6",tr("Arabic"),true)); mCodePages.append(std::make_shared(28597,"iso-8859-7",tr("Greek"),true)); mCodePages.append(std::make_shared(28598,"iso-8859-8",tr("Hebrew"),true)); mCodePages.append(std::make_shared(28599,"iso-8859-9",tr("Turkish"),true)); mCodePages.append(std::make_shared(28603,"iso-8859-13",tr("Baltic"),true)); mCodePages.append(std::make_shared(-1,"iso-8859-14",tr("Celtic"),true)); mCodePages.append(std::make_shared(28605,"iso-8859-15",tr("Western Europe"),true)); mCodePages.append(std::make_shared(29001,"x-Europa","",false)); mCodePages.append(std::make_shared(38598,"iso-8859-8-i","",false)); mCodePages.append(std::make_shared(50220,"iso-2022-jp","",false)); mCodePages.append(std::make_shared(50221,"csISO2022JP","",false)); mCodePages.append(std::make_shared(50222,"iso-2022-jp","",false)); mCodePages.append(std::make_shared(50225,"iso-2022-kr","",false)); mCodePages.append(std::make_shared(50227,"x-cp50227","",false)); mCodePages.append(std::make_shared(50229,"","",false)); mCodePages.append(std::make_shared(50930,"","",false)); mCodePages.append(std::make_shared(50931,"","",false)); mCodePages.append(std::make_shared(50933,"","",false)); mCodePages.append(std::make_shared(50935,"","",false)); mCodePages.append(std::make_shared(50936,"","",false)); mCodePages.append(std::make_shared(50937,"","",false)); mCodePages.append(std::make_shared(50939,"","",false)); mCodePages.append(std::make_shared(51932,"euc-jp",tr("Japanese"),true)); mCodePages.append(std::make_shared(51936,"euc-cn","",false)); mCodePages.append(std::make_shared(51949,"euc-kr",tr("Korean"),true)); mCodePages.append(std::make_shared(51950,"","",false)); mCodePages.append(std::make_shared(52936,"hz-gb-2312","",false)); mCodePages.append(std::make_shared(54936,"gb18030",tr("Chinese"),true)); mCodePages.append(std::make_shared(57002,"x-iscii-de","",false)); mCodePages.append(std::make_shared(57003,"x-iscii-be","",false)); mCodePages.append(std::make_shared(57004,"x-iscii-ta","",false)); mCodePages.append(std::make_shared(57005,"x-iscii-te","",false)); mCodePages.append(std::make_shared(57006,"x-iscii-as","",false)); mCodePages.append(std::make_shared(57007,"x-iscii-or","",false)); mCodePages.append(std::make_shared(57008,"x-iscii-ka","",false)); mCodePages.append(std::make_shared(57009,"x-iscii-ma","",false)); mCodePages.append(std::make_shared(57010,"x-iscii-gu","",false)); mCodePages.append(std::make_shared(57011,"x-iscii-pa","",false)); mCodePages.append(std::make_shared(65000,"utf-7","",false)); mCodePages.append(std::make_shared(65001,"utf-8","",false)); } CharsetInfo::CharsetInfo(int codepage, const QByteArray &name, const QString &language, bool enabled) { this->codepage = codepage; this->name = name; this->language = language; this->enabled = enabled; }