1 /* 2 * This file is part of KMail. 3 * SPDX-FileCopyrightText: 2009 Constantin Berzan <exit3219@gmail.com> 4 * 5 * Based on KMMsgBase code by: 6 * SPDX-FileCopyrightText: 1996-1998 Stefan Taferner <taferner@kde.org> 7 * 8 * SPDX-License-Identifier: GPL-2.0-or-later 9 */ 10 11 // Own 12 #include "codecmanager.h" 13 14 // KMail 15 #include "kmkernel.h" 16 17 // Qt 18 #include <QTextCodec> 19 20 // KDE libs 21 #include <MessageComposer/MessageComposerSettings> 22 CodecManager()23CodecManager::CodecManager() 24 { 25 updatePreferredCharsets(); 26 } 27 28 // static self()29CodecManager *CodecManager::self() 30 { 31 static CodecManager instance; 32 return &instance; 33 } 34 preferredCharsets() const35QVector<QByteArray> CodecManager::preferredCharsets() const 36 { 37 return mPreferredCharsets; 38 } 39 updatePreferredCharsets()40void CodecManager::updatePreferredCharsets() 41 { 42 const QStringList prefCharsets = MessageComposer::MessageComposerSettings::self()->preferredCharsets(); 43 mPreferredCharsets.clear(); 44 for (const QString &str : prefCharsets) { 45 QByteArray charset = str.toLatin1().toLower(); 46 47 if (charset == "locale") { 48 charset = QTextCodec::codecForLocale()->name(); 49 50 // Special case for Japanese: 51 // (Introduction to i18n, 6.6 Limit of Locale technology): 52 // EUC-JP is the de-facto standard for UNIX systems, ISO 2022-JP 53 // is the standard for Internet, and Shift-JIS is the encoding 54 // for Windows and Macintosh. 55 if (charset == "jisx0208.1983-0" || charset == "eucjp" || charset == "shift-jis") { 56 charset = "iso-2022-jp"; 57 // TODO wtf is "jis7"? 58 } 59 60 // Special case for Korean: 61 if (charset == "ksc5601.1987-0") { 62 charset = "euc-kr"; 63 } 64 } 65 mPreferredCharsets << charset; 66 } 67 } 68