1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Implementation of QTextCodecFactory class
|
---|
4 | **
|
---|
5 | ** Created : 010130
|
---|
6 | **
|
---|
7 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
|
---|
8 | **
|
---|
9 | ** This file is part of the tools module of the Qt GUI Toolkit.
|
---|
10 | **
|
---|
11 | ** This file may be distributed under the terms of the Q Public License
|
---|
12 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
13 | ** LICENSE.QPL included in the packaging of this file.
|
---|
14 | **
|
---|
15 | ** This file may be distributed and/or modified under the terms of the
|
---|
16 | ** GNU General Public License version 2 as published by the Free Software
|
---|
17 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
18 | ** packaging of this file.
|
---|
19 | **
|
---|
20 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
---|
21 | ** file in accordance with the Qt Commercial License Agreement provided
|
---|
22 | ** with the Software.
|
---|
23 | **
|
---|
24 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
25 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
26 | **
|
---|
27 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
28 | ** information about Qt Commercial License Agreements.
|
---|
29 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
30 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
31 | **
|
---|
32 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
33 | ** not clear to you.
|
---|
34 | **
|
---|
35 | **********************************************************************/
|
---|
36 |
|
---|
37 | #include "qtextcodecfactory.h"
|
---|
38 |
|
---|
39 | #ifndef QT_NO_TEXTCODEC
|
---|
40 |
|
---|
41 | #ifndef QT_NO_COMPONENT
|
---|
42 | #include "qapplication.h"
|
---|
43 | #include "qcleanuphandler.h"
|
---|
44 | #include <private/qpluginmanager_p.h>
|
---|
45 | #include "qtextcodecinterface_p.h"
|
---|
46 |
|
---|
47 | #ifdef QT_THREAD_SUPPORT
|
---|
48 | # include <private/qmutexpool_p.h>
|
---|
49 | #endif // QT_THREAD_SUPPORT
|
---|
50 |
|
---|
51 | #include <stdlib.h>
|
---|
52 |
|
---|
53 |
|
---|
54 | static QPluginManager<QTextCodecFactoryInterface> *manager = 0;
|
---|
55 | static QSingleCleanupHandler< QPluginManager<QTextCodecFactoryInterface> > cleanup_manager;
|
---|
56 |
|
---|
57 | static void create_manager()
|
---|
58 | {
|
---|
59 | if ( manager ) // already created
|
---|
60 | return;
|
---|
61 |
|
---|
62 | #ifdef QT_THREAD_SUPPORT
|
---|
63 | // protect manager creation
|
---|
64 | QMutexLocker locker( qt_global_mutexpool ?
|
---|
65 | qt_global_mutexpool->get( &manager ) : 0);
|
---|
66 |
|
---|
67 | // we check the manager pointer again to make sure that another thread
|
---|
68 | // has not created the manager before us.
|
---|
69 |
|
---|
70 | if ( manager ) // already created
|
---|
71 | return;
|
---|
72 | #endif
|
---|
73 |
|
---|
74 | manager =
|
---|
75 | new QPluginManager<QTextCodecFactoryInterface>(IID_QTextCodecFactory,
|
---|
76 | QApplication::libraryPaths(), "/codecs",
|
---|
77 | FALSE);
|
---|
78 | Q_CHECK_PTR( manager );
|
---|
79 | cleanup_manager.set( &manager );
|
---|
80 | }
|
---|
81 |
|
---|
82 | #endif // QT_NO_COMPONENT
|
---|
83 |
|
---|
84 |
|
---|
85 | QTextCodec *QTextCodecFactory::createForName(const QString &name)
|
---|
86 | {
|
---|
87 | QTextCodec *codec = 0;
|
---|
88 |
|
---|
89 | #ifndef QT_NO_COMPONENT
|
---|
90 |
|
---|
91 | // make sure the manager is created
|
---|
92 | create_manager();
|
---|
93 |
|
---|
94 | QInterfacePtr<QTextCodecFactoryInterface> iface;
|
---|
95 | manager->queryInterface(name, &iface );
|
---|
96 |
|
---|
97 | if (iface)
|
---|
98 | codec = iface->createForName(name);
|
---|
99 |
|
---|
100 | #endif // QT_NO_COMPONENT
|
---|
101 |
|
---|
102 | return codec;
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | QTextCodec *QTextCodecFactory::createForMib(int mib)
|
---|
107 | {
|
---|
108 | QTextCodec *codec = 0;
|
---|
109 |
|
---|
110 | #ifndef QT_NO_COMPONENT
|
---|
111 |
|
---|
112 | // make sure the manager is created
|
---|
113 | create_manager();
|
---|
114 |
|
---|
115 | QInterfacePtr<QTextCodecFactoryInterface> iface;
|
---|
116 | manager->queryInterface("MIB-" + QString::number(mib), &iface );
|
---|
117 |
|
---|
118 | if (iface)
|
---|
119 | codec = iface->createForMib(mib);
|
---|
120 |
|
---|
121 | #endif // QT_NO_COMPONENT
|
---|
122 |
|
---|
123 | return codec;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 | #endif // QT_NO_TEXTCODEC
|
---|