Fix typos
[kdepim.git] / kmail / codecaction.cpp
blob328422c50eff7f8fa26010d247ca87a15cc03e10
1 /*
2 * This file is part of KMail.
3 * Copyright (c) 2009 Constantin Berzan <exit3219@gmail.com>
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 2 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 // Own
21 #include "codecaction.h"
23 // KMail
24 #include "codecmanager.h"
26 // Qt
27 #include <QTextCodec>
29 // KDE libs
30 #include <KDebug>
31 #include <KLocale>
33 class CodecAction::Private
35 public:
36 Private( CodecAction::Mode mod, CodecAction *qq )
37 : mode( mod )
38 , q( qq )
42 const CodecAction::Mode mode;
43 CodecAction *const q;
48 CodecAction::CodecAction( Mode mode, QObject *parent )
49 : KCodecAction( parent, mode == ReaderMode )
50 , d( new Private( mode, this ) )
52 if( mode == ComposerMode ) {
53 // Add 'us-ascii' entry. We want it at the top, so remove then re-add everything.
54 // FIXME is there a better way?
55 QList<QAction*> oldActions = actions();
56 removeAllActions();
57 addAction( oldActions.takeFirst() ); // 'Default'
58 addAction( i18nc( "Encodings menu", "us-ascii" ) );
59 foreach( QAction *a, oldActions ) {
60 addAction( a );
62 } else if( mode == ReaderMode ) {
63 // Nothing to do.
66 // Eye candy.
67 setIcon( KIcon( "accessories-character-map" ) );
68 setText( i18nc( "Menu item", "Encoding" ) );
71 CodecAction::~CodecAction()
73 delete d;
76 QList<QByteArray> CodecAction::mimeCharsets() const
78 QList<QByteArray> ret;
79 kDebug() << "current item" << currentItem() << currentText();
80 if( currentItem() == 0 ) {
81 // 'Default' selected: return the preferred charsets.
82 ret = CodecManager::self()->preferredCharsets();
83 } else if( currentItem() == 1 ) {
84 // 'us-ascii' selected.
85 ret << "us-ascii";
86 } else {
87 // Specific codec selected.
88 // ret << currentCodecName().toLatin1().toLower(); // FIXME in kdelibs: returns e.g. '&koi8-r'
89 ret << currentCodec()->name();
90 kDebug() << "current codec name" << ret.first();
92 return ret;
95 #include "codecaction.moc"