| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information ([email protected])
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtCore module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qtextcodecplugin.h"
|
|---|
| 43 | #include "qstringlist.h"
|
|---|
| 44 |
|
|---|
| 45 | #ifndef QT_NO_TEXTCODECPLUGIN
|
|---|
| 46 |
|
|---|
| 47 | QT_BEGIN_NAMESPACE
|
|---|
| 48 |
|
|---|
| 49 | /*!
|
|---|
| 50 | \class QTextCodecPlugin
|
|---|
| 51 | \brief The QTextCodecPlugin class provides an abstract base for custom QTextCodec plugins.
|
|---|
| 52 | \reentrant
|
|---|
| 53 | \ingroup plugins
|
|---|
| 54 |
|
|---|
| 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.
|
|---|
| 58 |
|
|---|
| 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.
|
|---|
| 64 |
|
|---|
| 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.
|
|---|
| 68 | */
|
|---|
| 69 |
|
|---|
| 70 | /*!
|
|---|
| 71 | \fn QStringList QTextCodecPlugin::names() const
|
|---|
| 72 |
|
|---|
| 73 | Returns the list of MIME names supported by this plugin.
|
|---|
| 74 |
|
|---|
| 75 | If a codec has several names, the extra names are returned by aliases().
|
|---|
| 76 |
|
|---|
| 77 | \sa createForName(), aliases()
|
|---|
| 78 | */
|
|---|
| 79 |
|
|---|
| 80 | /*!
|
|---|
| 81 | \fn QList<QByteArray> QTextCodecPlugin::aliases() const
|
|---|
| 82 |
|
|---|
| 83 | Returns the list of aliases supported by this plugin.
|
|---|
| 84 | */
|
|---|
| 85 |
|
|---|
| 86 | /*!
|
|---|
| 87 | \fn QTextCodec *QTextCodecPlugin::createForName(const QByteArray &name)
|
|---|
| 88 |
|
|---|
| 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.
|
|---|
| 92 |
|
|---|
| 93 | Example:
|
|---|
| 94 |
|
|---|
| 95 | \snippet doc/src/snippets/code/src_corelib_codecs_qtextcodecplugin.cpp 0
|
|---|
| 96 |
|
|---|
| 97 | \sa names()
|
|---|
| 98 | */
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | /*!
|
|---|
| 102 | \fn QList<int> QTextCodecPlugin::mibEnums() const
|
|---|
| 103 |
|
|---|
| 104 | Returns the list of mib enums supported by this plugin.
|
|---|
| 105 |
|
|---|
| 106 | \sa createForMib()
|
|---|
| 107 | */
|
|---|
| 108 |
|
|---|
| 109 | /*!
|
|---|
| 110 | \fn QTextCodec *QTextCodecPlugin::createForMib(int mib);
|
|---|
| 111 |
|
|---|
| 112 | Creates a QTextCodec object for the mib enum \a mib.
|
|---|
| 113 |
|
|---|
| 114 | See \l{http://www.iana.org/assignments/character-sets}{the
|
|---|
| 115 | IANA character-sets encoding file} for more information.
|
|---|
| 116 |
|
|---|
| 117 | \sa mibEnums()
|
|---|
| 118 | */
|
|---|
| 119 |
|
|---|
| 120 | /*!
|
|---|
| 121 | Constructs a text codec plugin with the given \a parent. This is
|
|---|
| 122 | invoked automatically by the Q_EXPORT_PLUGIN2() macro.
|
|---|
| 123 | */
|
|---|
| 124 | QTextCodecPlugin::QTextCodecPlugin(QObject *parent)
|
|---|
| 125 | : QObject(parent)
|
|---|
| 126 | {
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | /*!
|
|---|
| 130 | Destroys the text codec plugin.
|
|---|
| 131 |
|
|---|
| 132 | You never have to call this explicitly. Qt destroys a plugin
|
|---|
| 133 | automatically when it is no longer used.
|
|---|
| 134 | */
|
|---|
| 135 | QTextCodecPlugin::~QTextCodecPlugin()
|
|---|
| 136 | {
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | QStringList QTextCodecPlugin::keys() const
|
|---|
| 140 | {
|
|---|
| 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;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | QTextCodec *QTextCodecPlugin::create(const QString &name)
|
|---|
| 153 | {
|
|---|
| 154 | if (name.startsWith(QLatin1String("MIB: ")))
|
|---|
| 155 | return createForMib(name.mid(4).toInt());
|
|---|
| 156 | return createForName(name.toLatin1());
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | QT_END_NAMESPACE
|
|---|
| 160 |
|
|---|
| 161 | #endif // QT_NO_TEXTCODECPLUGIN
|
|---|