backport 1145339: no error box spam
[kdepim.git] / kmail / codecaction.cpp
blob19246f10c8be7e7e418bcf8182e3506dcceb805e
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
28 // KDE libs
29 #include <KDebug>
30 #include <KLocale>
32 class CodecAction::Private
34 public:
35 Private( CodecAction::Mode mod, CodecAction *qq )
36 : mode( mod )
37 , q( qq )
41 const CodecAction::Mode mode;
42 CodecAction *const q;
47 CodecAction::CodecAction( Mode mode, QObject *parent )
48 : KCodecAction( parent, mode == ReaderMode )
49 , d( new Private( mode, this ) )
51 if( mode == ComposerMode ) {
52 // Add 'us-ascii' entry. We want it at the top, so remove then re-add everything.
53 // FIXME is there a better way?
54 QList<QAction*> oldActions = actions();
55 removeAllActions();
56 addAction( oldActions.takeFirst() ); // 'Default'
57 addAction( i18nc( "Encodings menu", "us-ascii" ) );
58 foreach( QAction *a, oldActions ) {
59 addAction( a );
61 } else if( mode == ReaderMode ) {
62 // Nothing to do.
65 // Eye candy.
66 setIcon( KIcon( "accessories-character-map" ) );
67 setText( i18nc( "Menu item", "Encoding" ) );
70 CodecAction::~CodecAction()
72 delete d;
75 QList<QByteArray> CodecAction::mimeCharsets() const
77 QList<QByteArray> ret;
78 kDebug() << "current item" << currentItem() << currentText();
79 if( currentItem() == 0 ) {
80 // 'Default' selected: return the preferred charsets.
81 ret = CodecManager::self()->preferredCharsets();
82 } else if( currentItem() == 1 ) {
83 // 'us-ascii' selected.
84 ret << "us-ascii";
85 } else {
86 // Specific codec selected.
87 // ret << currentCodecName().toLatin1().toLower(); // FIXME in kdelibs: returns e.g. '&koi8-r'
88 ret << currentCodec()->name();
89 kDebug() << "current codec name" << ret.first();
91 return ret;
94 #include "codecaction.moc"