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.
21 #include "codecaction.h"
24 #include "codecmanager.h"
33 class CodecAction::Private
36 Private( CodecAction::Mode mod
, CodecAction
*qq
)
42 const CodecAction::Mode mode
;
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();
57 addAction( oldActions
.takeFirst() ); // 'Default'
58 addAction( i18nc( "Encodings menu", "us-ascii" ) );
59 foreach( QAction
*a
, oldActions
) {
62 } else if( mode
== ReaderMode
) {
67 setIcon( KIcon( "accessories-character-map" ) );
68 setText( i18nc( "Menu item", "Encoding" ) );
71 CodecAction::~CodecAction()
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.
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();
95 #include "codecaction.moc"