Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
[qt-netbsd.git] / src / corelib / codecs / qtextcodecplugin.cpp
blob90b64f4423c6bf8c33044708bf2511a1a1f2ae0e
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtCore module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #include "qtextcodecplugin.h"
43 #include "qstringlist.h"
45 #ifndef QT_NO_TEXTCODECPLUGIN
47 QT_BEGIN_NAMESPACE
49 /*!
50 \class QTextCodecPlugin
51 \brief The QTextCodecPlugin class provides an abstract base for custom QTextCodec plugins.
52 \reentrant
53 \ingroup plugins
55 The text codec plugin is a simple plugin interface that makes it
56 easy to create custom text codecs that can be loaded dynamically
57 into applications.
59 Writing a text codec plugin is achieved by subclassing this base
60 class, reimplementing the pure virtual functions names(),
61 aliases(), createForName(), mibEnums() and createForMib(), and
62 exporting the class with the Q_EXPORT_PLUGIN2() macro. See \l{How
63 to Create Qt Plugins} for details.
65 See the \l{http://www.iana.org/assignments/character-sets}{IANA
66 character-sets encoding file} for more information on mime
67 names and mib enums.
70 /*!
71 \fn QStringList QTextCodecPlugin::names() const
73 Returns the list of MIME names supported by this plugin.
75 If a codec has several names, the extra names are returned by aliases().
77 \sa createForName(), aliases()
80 /*!
81 \fn QList<QByteArray> QTextCodecPlugin::aliases() const
83 Returns the list of aliases supported by this plugin.
86 /*!
87 \fn QTextCodec *QTextCodecPlugin::createForName(const QByteArray &name)
89 Creates a QTextCodec object for the codec called \a name. The \a name
90 must come from the list of encodings returned by names(). Encoding
91 names are case sensitive.
93 Example:
95 \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp 0
97 \sa names()
102 \fn QList<int> QTextCodecPlugin::mibEnums() const
104 Returns the list of mib enums supported by this plugin.
106 \sa createForMib()
110 \fn QTextCodec *QTextCodecPlugin::createForMib(int mib);
112 Creates a QTextCodec object for the mib enum \a mib.
114 See \l{http://www.iana.org/assignments/character-sets}{the
115 IANA character-sets encoding file} for more information.
117 \sa mibEnums()
121 Constructs a text codec plugin with the given \a parent. This is
122 invoked automatically by the Q_EXPORT_PLUGIN2() macro.
124 QTextCodecPlugin::QTextCodecPlugin(QObject *parent)
125 : QObject(parent)
130 Destroys the text codec plugin.
132 You never have to call this explicitly. Qt destroys a plugin
133 automatically when it is no longer used.
135 QTextCodecPlugin::~QTextCodecPlugin()
139 QStringList QTextCodecPlugin::keys() const
141 QStringList keys;
142 QList<QByteArray> list = names();
143 list += aliases();
144 for (int i = 0; i < list.size(); ++i)
145 keys += QString::fromLatin1(list.at(i));
146 QList<int> mibs = mibEnums();
147 for (int i = 0; i < mibs.count(); ++i)
148 keys += QLatin1String("MIB: ") + QString::number(mibs.at(i));
149 return keys;
152 QTextCodec *QTextCodecPlugin::create(const QString &name)
154 if (name.startsWith(QLatin1String("MIB: ")))
155 return createForMib(name.mid(4).toInt());
156 return createForName(name.toLatin1());
159 QT_END_NAMESPACE
161 #endif // QT_NO_TEXTCODECPLUGIN