source: trunk/src/corelib/codecs/qtextcodecplugin.cpp@ 807

Last change on this file since 807 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 4.9 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
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.
23**
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.
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 have questions regarding the use of this file, please contact
37** Nokia 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
47QT_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*/
124QTextCodecPlugin::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*/
135QTextCodecPlugin::~QTextCodecPlugin()
136{
137}
138
139QStringList 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
152QTextCodec *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
159QT_END_NAMESPACE
160
161#endif // QT_NO_TEXTCODECPLUGIN
Note: See TracBrowser for help on using the repository browser.