2 * This file is part of KMail.
3 * Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
5 * Based on KMMsgBase code by:
6 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include "codecmanager.h"
32 #include <kcodecaction.h>
37 #include <messagecomposersettings.h>
39 class CodecManagerPrivate
42 CodecManagerPrivate();
43 ~CodecManagerPrivate();
45 CodecManager
*instance
;
46 QList
<QByteArray
> preferredCharsets
;
50 K_GLOBAL_STATIC( CodecManagerPrivate
, sInstance
)
52 CodecManagerPrivate::CodecManagerPrivate()
53 : instance( new CodecManager( this ) )
55 instance
->updatePreferredCharsets();
58 CodecManagerPrivate::~CodecManagerPrivate()
65 CodecManager::CodecManager( CodecManagerPrivate
*dd
)
66 : QObject() // TODO does it need to be a QObject?
72 CodecManager
* CodecManager::self()
74 return sInstance
->instance
;
77 QList
<QByteArray
> CodecManager::preferredCharsets() const
79 return d
->preferredCharsets
;
82 void CodecManager::updatePreferredCharsets()
84 const QStringList prefCharsets
= MessageComposer::MessageComposerSettings::self()->preferredCharsets();
85 d
->preferredCharsets
.clear();
86 foreach( const QString
&str
, prefCharsets
) {
87 QByteArray charset
= str
.toLatin1().toLower();
89 if( charset
== "locale" ) {
90 charset
= KGlobal::locale()->encoding().toLower();
92 // Special case for Japanese:
93 // (Introduction to i18n, 6.6 Limit of Locale technology):
94 // EUC-JP is the de-facto standard for UNIX systems, ISO 2022-JP
95 // is the standard for Internet, and Shift-JIS is the encoding
96 // for Windows and Macintosh.
97 if( charset
== "jisx0208.1983-0" ||
99 charset
== "shift-jis" ) {
100 charset
= "iso-2022-jp";
101 // TODO wtf is "jis7"?
104 // Special case for Korean:
105 if( charset
== "ksc5601.1987-0" ) {
109 d
->preferredCharsets
<< charset
;
113 #include "codecmanager.moc"