1 | /****************************************************************************
|
---|
2 | ** $Id: qtextcodecplugin.cpp 2 2005-11-16 15:49:26Z dmik $
|
---|
3 | **
|
---|
4 | ** Implementation of QTextCodecPlugin class
|
---|
5 | **
|
---|
6 | ** Created : 010920
|
---|
7 | **
|
---|
8 | ** Copyright (C) 2001-2002 Trolltech AS. All rights reserved.
|
---|
9 | **
|
---|
10 | ** This file is part of the tools module of the Qt GUI Toolkit.
|
---|
11 | **
|
---|
12 | ** This file may be distributed under the terms of the Q Public License
|
---|
13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
15 | **
|
---|
16 | ** This file may be distributed and/or modified under the terms of the
|
---|
17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
19 | ** packaging of this file.
|
---|
20 | **
|
---|
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
22 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
23 | ** Agreement provided with the Software.
|
---|
24 | **
|
---|
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
27 | **
|
---|
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
29 | ** information about Qt Commercial License Agreements.
|
---|
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
32 | **
|
---|
33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
34 | ** not clear to you.
|
---|
35 | **
|
---|
36 | **********************************************************************/
|
---|
37 |
|
---|
38 | #include "qtextcodecplugin.h"
|
---|
39 | #ifndef QT_NO_TEXTCODECPLUGIN
|
---|
40 | #include "qtextcodecinterface_p.h"
|
---|
41 |
|
---|
42 | /*!
|
---|
43 | \class QTextCodecPlugin qtextcodecplugin.h
|
---|
44 | \brief The QTextCodecPlugin class provides an abstract base for custom QTextCodec plugins.
|
---|
45 | \reentrant
|
---|
46 | \ingroup plugins
|
---|
47 |
|
---|
48 | The text codec plugin is a simple plugin interface that makes it
|
---|
49 | easy to create custom text codecs that can be loaded dynamically
|
---|
50 | into applications.
|
---|
51 |
|
---|
52 | Writing a text codec plugin is achieved by subclassing this base
|
---|
53 | class, reimplementing the pure virtual functions names(),
|
---|
54 | createForName(), mibEnums() and createForMib(), and exporting the
|
---|
55 | class with the \c Q_EXPORT_PLUGIN macro. See the \link
|
---|
56 | plugins-howto.html Qt Plugins documentation \endlink for details.
|
---|
57 |
|
---|
58 | See the \link http://www.iana.org/assignments/character-sets IANA
|
---|
59 | character-sets encoding file\endlink for more information on mime
|
---|
60 | names and mib enums.
|
---|
61 | */
|
---|
62 |
|
---|
63 | /*!
|
---|
64 | \fn QStringList QTextCodecPlugin::names() const
|
---|
65 |
|
---|
66 | Returns the list of mime names supported by this plugin.
|
---|
67 |
|
---|
68 | \sa createForName()
|
---|
69 | */
|
---|
70 |
|
---|
71 | /*!
|
---|
72 | \fn QTextCodec *QTextCodecPlugin::createForName( const QString &name );
|
---|
73 |
|
---|
74 | Creates a QTextCodec object for the codec called \a name.
|
---|
75 |
|
---|
76 | \sa names()
|
---|
77 | */
|
---|
78 |
|
---|
79 |
|
---|
80 | /*!
|
---|
81 | \fn QValueList<int> QTextCodecPlugin::mibEnums() const
|
---|
82 |
|
---|
83 | Returns the list of mib enums supported by this plugin.
|
---|
84 |
|
---|
85 | \sa createForMib()
|
---|
86 | */
|
---|
87 |
|
---|
88 | /*!
|
---|
89 | \fn QTextCodec *QTextCodecPlugin::createForMib( int mib );
|
---|
90 |
|
---|
91 | Creates a QTextCodec object for the mib enum \a mib.
|
---|
92 |
|
---|
93 | (See \link
|
---|
94 | ftp://ftp.isi.edu/in-notes/iana/assignments/character-sets the
|
---|
95 | IANA character-sets encoding file\endlink for more information)
|
---|
96 |
|
---|
97 | \sa mibEnums()
|
---|
98 | */
|
---|
99 |
|
---|
100 |
|
---|
101 |
|
---|
102 | class QTextCodecPluginPrivate : public QTextCodecFactoryInterface
|
---|
103 | {
|
---|
104 | public:
|
---|
105 | QTextCodecPluginPrivate( QTextCodecPlugin *p )
|
---|
106 | : plugin( p )
|
---|
107 | {
|
---|
108 | }
|
---|
109 | virtual ~QTextCodecPluginPrivate();
|
---|
110 |
|
---|
111 | QRESULT queryInterface( const QUuid &iid, QUnknownInterface **iface );
|
---|
112 | Q_REFCOUNT;
|
---|
113 |
|
---|
114 | QStringList featureList() const;
|
---|
115 | QTextCodec *createForMib( int mib );
|
---|
116 | QTextCodec *createForName( const QString &name );
|
---|
117 |
|
---|
118 | private:
|
---|
119 | QTextCodecPlugin *plugin;
|
---|
120 | };
|
---|
121 |
|
---|
122 | QTextCodecPluginPrivate::~QTextCodecPluginPrivate()
|
---|
123 | {
|
---|
124 | delete plugin;
|
---|
125 | }
|
---|
126 |
|
---|
127 | QRESULT QTextCodecPluginPrivate::queryInterface( const QUuid &iid, QUnknownInterface **iface )
|
---|
128 | {
|
---|
129 | *iface = 0;
|
---|
130 |
|
---|
131 | if ( iid == IID_QUnknown )
|
---|
132 | *iface = this;
|
---|
133 | else if ( iid == IID_QFeatureList )
|
---|
134 | *iface = this;
|
---|
135 | else if ( iid == IID_QTextCodecFactory )
|
---|
136 | *iface = this;
|
---|
137 | else
|
---|
138 | return QE_NOINTERFACE;
|
---|
139 |
|
---|
140 | (*iface)->addRef();
|
---|
141 | return QS_OK;
|
---|
142 | }
|
---|
143 |
|
---|
144 | QStringList QTextCodecPluginPrivate::featureList() const
|
---|
145 | {
|
---|
146 | QStringList keys = plugin->names();
|
---|
147 | QValueList<int> mibs = plugin->mibEnums();
|
---|
148 | for ( QValueList<int>::Iterator it = mibs.begin(); it != mibs.end(); ++it )
|
---|
149 | keys += QString("MIB-%1").arg( *it );
|
---|
150 | return keys;
|
---|
151 | }
|
---|
152 |
|
---|
153 | QTextCodec *QTextCodecPluginPrivate::createForMib( int mib )
|
---|
154 | {
|
---|
155 | return plugin->createForMib( mib );
|
---|
156 | }
|
---|
157 |
|
---|
158 | QTextCodec *QTextCodecPluginPrivate::createForName( const QString &name )
|
---|
159 | {
|
---|
160 | return plugin->createForName( name );
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | /*!
|
---|
165 | Constructs a text codec plugin. This is invoked automatically by
|
---|
166 | the \c Q_EXPORT_PLUGIN macro.
|
---|
167 | */
|
---|
168 | QTextCodecPlugin::QTextCodecPlugin()
|
---|
169 | : QGPlugin( d = new QTextCodecPluginPrivate( this ) )
|
---|
170 | {
|
---|
171 | }
|
---|
172 |
|
---|
173 | /*!
|
---|
174 | Destroys the text codec plugin.
|
---|
175 |
|
---|
176 | You never have to call this explicitly. Qt destroys a plugin
|
---|
177 | automatically when it is no longer used.
|
---|
178 | */
|
---|
179 | QTextCodecPlugin::~QTextCodecPlugin()
|
---|
180 | {
|
---|
181 | }
|
---|
182 |
|
---|
183 | #endif // QT_NO_TEXTCODECPLUGIN
|
---|