1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qmime.cpp:179 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QMimeSourceFactory Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QMimeSourceFactory Class Reference</h1>
|
---|
33 |
|
---|
34 | <p>The QMimeSourceFactory class is an extensible provider of mime-typed data.
|
---|
35 | <a href="#details">More...</a>
|
---|
36 | <p><tt>#include <<a href="qmime-h.html">qmime.h</a>></tt>
|
---|
37 | <p><a href="qmimesourcefactory-members.html">List of all member functions.</a>
|
---|
38 | <h2>Public Members</h2>
|
---|
39 | <ul>
|
---|
40 | <li class=fn><a href="#QMimeSourceFactory"><b>QMimeSourceFactory</b></a> ()</li>
|
---|
41 | <li class=fn>virtual <a href="#~QMimeSourceFactory"><b>~QMimeSourceFactory</b></a> ()</li>
|
---|
42 | <li class=fn>virtual const QMimeSource * <a href="#data"><b>data</b></a> ( const QString & abs_name ) const</li>
|
---|
43 | <li class=fn>virtual QString <a href="#makeAbsolute"><b>makeAbsolute</b></a> ( const QString & abs_or_rel_name, const QString & context ) const</li>
|
---|
44 | <li class=fn>const QMimeSource * <a href="#data-2"><b>data</b></a> ( const QString & abs_or_rel_name, const QString & context ) const</li>
|
---|
45 | <li class=fn>virtual void <a href="#setText"><b>setText</b></a> ( const QString & abs_name, const QString & text )</li>
|
---|
46 | <li class=fn>virtual void <a href="#setImage"><b>setImage</b></a> ( const QString & abs_name, const QImage & image )</li>
|
---|
47 | <li class=fn>virtual void <a href="#setPixmap"><b>setPixmap</b></a> ( const QString & abs_name, const QPixmap & pixmap )</li>
|
---|
48 | <li class=fn>virtual void <a href="#setData"><b>setData</b></a> ( const QString & abs_name, QMimeSource * data )</li>
|
---|
49 | <li class=fn>virtual void <a href="#setFilePath"><b>setFilePath</b></a> ( const QStringList & path )</li>
|
---|
50 | <li class=fn>virtual QStringList <a href="#filePath"><b>filePath</b></a> () const</li>
|
---|
51 | <li class=fn>void <a href="#addFilePath"><b>addFilePath</b></a> ( const QString & p )</li>
|
---|
52 | <li class=fn>virtual void <a href="#setExtensionType"><b>setExtensionType</b></a> ( const QString & ext, const char * mimetype )</li>
|
---|
53 | </ul>
|
---|
54 | <h2>Static Public Members</h2>
|
---|
55 | <ul>
|
---|
56 | <li class=fn>QMimeSourceFactory * <a href="#defaultFactory"><b>defaultFactory</b></a> ()</li>
|
---|
57 | <li class=fn>void <a href="#setDefaultFactory"><b>setDefaultFactory</b></a> ( QMimeSourceFactory * factory )</li>
|
---|
58 | <li class=fn>QMimeSourceFactory * <a href="#takeDefaultFactory"><b>takeDefaultFactory</b></a> ()</li>
|
---|
59 | <li class=fn>void <a href="#addFactory"><b>addFactory</b></a> ( QMimeSourceFactory * f )</li>
|
---|
60 | <li class=fn>void <a href="#removeFactory"><b>removeFactory</b></a> ( QMimeSourceFactory * f )</li>
|
---|
61 | </ul>
|
---|
62 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
63 |
|
---|
64 |
|
---|
65 | The QMimeSourceFactory class is an extensible provider of mime-typed data.
|
---|
66 | <p>
|
---|
67 |
|
---|
68 | <p> A QMimeSourceFactory provides an abstract interface to a
|
---|
69 | collection of information. Each piece of information is
|
---|
70 | represented by a <a href="qmimesource.html">QMimeSource</a> object which can be examined and
|
---|
71 | converted to concrete data types by functions such as
|
---|
72 | <a href="qimagedrag.html#canDecode">QImageDrag::canDecode</a>() and <a href="qimagedrag.html#decode">QImageDrag::decode</a>().
|
---|
73 | <p> The base QMimeSourceFactory can be used in two ways: as an
|
---|
74 | abstraction of a collection of files or as specifically stored
|
---|
75 | data. For it to access files, call <a href="#setFilePath">setFilePath</a>() before accessing
|
---|
76 | data. For stored data, call <a href="#setData">setData</a>() for each item (there are
|
---|
77 | also convenience functions, e.g. <a href="#setText">setText</a>(), <a href="#setImage">setImage</a>() and
|
---|
78 | <a href="#setPixmap">setPixmap</a>(), that simply call setData() with appropriate
|
---|
79 | parameters).
|
---|
80 | <p> The rich text widgets, <a href="qtextedit.html">QTextEdit</a> and <a href="qtextbrowser.html">QTextBrowser</a>, use
|
---|
81 | QMimeSourceFactory to resolve references such as images or links
|
---|
82 | within rich text documents. They either access the default factory
|
---|
83 | (see <a href="#defaultFactory">defaultFactory</a>()) or their own (see
|
---|
84 | <a href="qtextedit.html#setMimeSourceFactory">QTextEdit::setMimeSourceFactory</a>()). Other classes that are
|
---|
85 | capable of displaying rich text (such as <a href="qlabel.html">QLabel</a>, <a href="qwhatsthis.html">QWhatsThis</a> or
|
---|
86 | <a href="qmessagebox.html">QMessageBox</a>) always use the default factory.
|
---|
87 | <p> A factory can also be used as a container to store data associated
|
---|
88 | with a name. This technique is useful whenever rich text contains
|
---|
89 | images that are stored in the program itself, not loaded from the
|
---|
90 | hard disk. Your program may, for example, define some image data
|
---|
91 | as:
|
---|
92 | <pre>
|
---|
93 | static const char* myimage_data[]={
|
---|
94 | "...",
|
---|
95 | ...
|
---|
96 | "..."};
|
---|
97 | </pre>
|
---|
98 |
|
---|
99 | <p> To be able to use this image within some rich text, for example
|
---|
100 | inside a QLabel, you must create a <a href="qimage.html">QImage</a> from the raw data and
|
---|
101 | insert it into the factory with a unique name:
|
---|
102 | <pre>
|
---|
103 | QMimeSourceFactory::<a href="#defaultFactory">defaultFactory</a>()->setImage( "myimage", QImage(myimage_data) );
|
---|
104 | </pre>
|
---|
105 |
|
---|
106 | <p> Now you can create a rich text QLabel with
|
---|
107 | <p> <pre>
|
---|
108 | <a href="qlabel.html">QLabel</a>* label = new <a href="qlabel.html">QLabel</a>(
|
---|
109 | "Rich text with embedded image:<img source=\"myimage\">"
|
---|
110 | "Isn't that <em>cute</em>?" );
|
---|
111 | </pre>
|
---|
112 |
|
---|
113 | <p> When no longer needed, you can clear the data from the factory:
|
---|
114 | <p> <pre>
|
---|
115 | delete label;
|
---|
116 | QMimeSourceFactory::<a href="#defaultFactory">defaultFactory</a>()->setData( "myimage", 0 );
|
---|
117 | </pre>
|
---|
118 |
|
---|
119 | <p>See also <a href="environment.html">Environment Classes</a> and <a href="io.html">Input/Output and Networking</a>.
|
---|
120 |
|
---|
121 | <hr><h2>Member Function Documentation</h2>
|
---|
122 | <h3 class=fn><a name="QMimeSourceFactory"></a>QMimeSourceFactory::QMimeSourceFactory ()
|
---|
123 | </h3>
|
---|
124 | Constructs a QMimeSourceFactory that has no file path and no
|
---|
125 | stored content.
|
---|
126 |
|
---|
127 | <h3 class=fn><a name="~QMimeSourceFactory"></a>QMimeSourceFactory::~QMimeSourceFactory ()<tt> [virtual]</tt>
|
---|
128 | </h3>
|
---|
129 | Destroys the QMimeSourceFactory, deleting all stored content.
|
---|
130 |
|
---|
131 | <h3 class=fn>void <a name="addFactory"></a>QMimeSourceFactory::addFactory ( <a href="qmimesourcefactory.html">QMimeSourceFactory</a> * f )<tt> [static]</tt>
|
---|
132 | </h3>
|
---|
133 | Adds the QMimeSourceFactory <em>f</em> to the list of available
|
---|
134 | mimesource factories. If the <a href="#defaultFactory">defaultFactory</a>() can't resolve a
|
---|
135 | <a href="#data">data</a>() it iterates over the list of installed mimesource factories
|
---|
136 | until the data can be resolved.
|
---|
137 | <p> <p>See also <a href="#removeFactory">removeFactory</a>().
|
---|
138 |
|
---|
139 | <h3 class=fn>void <a name="addFilePath"></a>QMimeSourceFactory::addFilePath ( const <a href="qstring.html">QString</a> & p )
|
---|
140 | </h3>
|
---|
141 | Adds another search path, <em>p</em> to the existing search paths.
|
---|
142 | <p> <p>See also <a href="#setFilePath">setFilePath</a>().
|
---|
143 |
|
---|
144 | <h3 class=fn>const <a href="qmimesource.html">QMimeSource</a> * <a name="data"></a>QMimeSourceFactory::data ( const <a href="qstring.html">QString</a> & abs_name ) const<tt> [virtual]</tt>
|
---|
145 | </h3>
|
---|
146 | Returns a reference to the data associated with <em>abs_name</em>. The
|
---|
147 | return value remains valid only until the next <a href="#data">data</a>() or <a href="#setData">setData</a>()
|
---|
148 | call, so you should immediately decode the result.
|
---|
149 | <p> If there is no data associated with <em>abs_name</em> in the factory's
|
---|
150 | store, the factory tries to access the local filesystem. If <em>abs_name</em> isn't an absolute file name, the factory will search for
|
---|
151 | it in all defined paths (see <a href="#setFilePath">setFilePath</a>()).
|
---|
152 | <p> The factory understands all the image formats supported by
|
---|
153 | <a href="qimageio.html">QImageIO</a>. Any other mime types are determined by the file name
|
---|
154 | extension. The default settings are
|
---|
155 | <pre>
|
---|
156 | <a href="#setExtensionType">setExtensionType</a>("html", "text/html;charset=iso8859-1");
|
---|
157 | <a href="#setExtensionType">setExtensionType</a>("htm", "text/html;charset=iso8859-1");
|
---|
158 | <a href="#setExtensionType">setExtensionType</a>("txt", "text/plain");
|
---|
159 | <a href="#setExtensionType">setExtensionType</a>("xml", "text/xml;charset=UTF-8");
|
---|
160 | </pre>
|
---|
161 |
|
---|
162 | The effect of these is that file names ending in "txt" will be
|
---|
163 | treated as text encoded in the local encoding; those ending in
|
---|
164 | "xml" will be treated as text encoded in Unicode UTF-8 encoding.
|
---|
165 | The text/html type is treated specially, since the encoding can be
|
---|
166 | specified in the html file itself. "html" or "htm" will be treated
|
---|
167 | as text encoded in the encoding specified by the html meta tag, if
|
---|
168 | none could be found, the charset of the mime type will be used.
|
---|
169 | The text subtype ("html", "plain", or "xml") does not affect the
|
---|
170 | factory, but users of the factory may behave differently. We
|
---|
171 | recommend creating "xml" files where practical. These files can be
|
---|
172 | viewed regardless of the runtime encoding and can encode any
|
---|
173 | Unicode characters without resorting to encoding definitions
|
---|
174 | inside the file.
|
---|
175 | <p> Any file data that is not recognized will be retrieved as a
|
---|
176 | <a href="qmimesource.html">QMimeSource</a> providing the "application/octet-stream" mime type,
|
---|
177 | meaning uninterpreted binary data.
|
---|
178 | <p> You can add further extensions or change existing ones with
|
---|
179 | subsequent calls to <a href="#setExtensionType">setExtensionType</a>(). If the extension mechanism
|
---|
180 | is not sufficient for your problem domain, you can inherit
|
---|
181 | QMimeSourceFactory and reimplement this function to perform some
|
---|
182 | more specialized mime-type detection. The same applies if you want
|
---|
183 | to use the mime source factory to access URL referenced data over
|
---|
184 | a network.
|
---|
185 |
|
---|
186 | <h3 class=fn>const <a href="qmimesource.html">QMimeSource</a> * <a name="data-2"></a>QMimeSourceFactory::data ( const <a href="qstring.html">QString</a> & abs_or_rel_name, const <a href="qstring.html">QString</a> & context ) const
|
---|
187 | </h3>
|
---|
188 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
189 | <p> A convenience function. See <a href="#data">data</a>(const <a href="qstring.html">QString</a>& abs_name). The
|
---|
190 | file name is given in <em>abs_or_rel_name</em> and the path is in <em>context</em>.
|
---|
191 |
|
---|
192 | <h3 class=fn><a href="qmimesourcefactory.html">QMimeSourceFactory</a> * <a name="defaultFactory"></a>QMimeSourceFactory::defaultFactory ()<tt> [static]</tt>
|
---|
193 | </h3>
|
---|
194 | Returns the application-wide default mime source factory. This
|
---|
195 | factory is used by rich text rendering classes such as
|
---|
196 | <a href="qsimplerichtext.html">QSimpleRichText</a>, <a href="qwhatsthis.html">QWhatsThis</a> and <a href="qmessagebox.html">QMessageBox</a> to resolve named
|
---|
197 | references within rich text documents. It serves also as the
|
---|
198 | initial factory for the more complex render widgets, <a href="qtextedit.html">QTextEdit</a> and
|
---|
199 | <a href="qtextbrowser.html">QTextBrowser</a>.
|
---|
200 | <p> <p>See also <a href="#setDefaultFactory">setDefaultFactory</a>().
|
---|
201 |
|
---|
202 | <p>Examples: <a href="qaction-application-example.html#x1140">action/application.cpp</a> and <a href="simple-application-example.html#x1558">application/application.cpp</a>.
|
---|
203 | <h3 class=fn><a href="qstringlist.html">QStringList</a> <a name="filePath"></a>QMimeSourceFactory::filePath () const<tt> [virtual]</tt>
|
---|
204 | </h3>
|
---|
205 | Returns the currently set search paths.
|
---|
206 |
|
---|
207 | <h3 class=fn><a href="qstring.html">QString</a> <a name="makeAbsolute"></a>QMimeSourceFactory::makeAbsolute ( const <a href="qstring.html">QString</a> & abs_or_rel_name, const <a href="qstring.html">QString</a> & context ) const<tt> [virtual]</tt>
|
---|
208 | </h3>
|
---|
209 | Converts the absolute or relative data item name <em>abs_or_rel_name</em> to an absolute name, interpreted within the
|
---|
210 | context (path) of the data item named <em>context</em> (this must be an
|
---|
211 | absolute name).
|
---|
212 |
|
---|
213 | <h3 class=fn>void <a name="removeFactory"></a>QMimeSourceFactory::removeFactory ( <a href="qmimesourcefactory.html">QMimeSourceFactory</a> * f )<tt> [static]</tt>
|
---|
214 | </h3>
|
---|
215 | Removes the mimesource factory <em>f</em> from the list of available
|
---|
216 | mimesource factories.
|
---|
217 | <p> <p>See also <a href="#addFactory">addFactory</a>().
|
---|
218 |
|
---|
219 | <h3 class=fn>void <a name="setData"></a>QMimeSourceFactory::setData ( const <a href="qstring.html">QString</a> & abs_name, <a href="qmimesource.html">QMimeSource</a> * data )<tt> [virtual]</tt>
|
---|
220 | </h3>
|
---|
221 | Sets <em>data</em> to be the data item associated with
|
---|
222 | the absolute name <em>abs_name</em>. Note that the ownership of <em>data</em> is
|
---|
223 | transferred to the factory: do not delete or access the pointer after
|
---|
224 | passing it to this function.
|
---|
225 | <p> Passing 0 for data removes previously stored data.
|
---|
226 |
|
---|
227 | <h3 class=fn>void <a name="setDefaultFactory"></a>QMimeSourceFactory::setDefaultFactory ( <a href="qmimesourcefactory.html">QMimeSourceFactory</a> * factory )<tt> [static]</tt>
|
---|
228 | </h3>
|
---|
229 | Sets the default <em>factory</em>, destroying any previously set mime
|
---|
230 | source provider. The ownership of the factory is transferred to
|
---|
231 | Qt.
|
---|
232 | <p> <p>See also <a href="#defaultFactory">defaultFactory</a>().
|
---|
233 |
|
---|
234 | <h3 class=fn>void <a name="setExtensionType"></a>QMimeSourceFactory::setExtensionType ( const <a href="qstring.html">QString</a> & ext, const char * mimetype )<tt> [virtual]</tt>
|
---|
235 | </h3>
|
---|
236 | Sets the mime-type to be associated with the file name extension,
|
---|
237 | <em>ext</em> to <em>mimetype</em>. This determines the mime-type for files
|
---|
238 | found via the paths set by <a href="#setFilePath">setFilePath</a>().
|
---|
239 |
|
---|
240 | <h3 class=fn>void <a name="setFilePath"></a>QMimeSourceFactory::setFilePath ( const <a href="qstringlist.html">QStringList</a> & path )<tt> [virtual]</tt>
|
---|
241 | </h3>
|
---|
242 | Sets the list of directories that will be searched when named data
|
---|
243 | is requested to the those given in the string list <em>path</em>.
|
---|
244 | <p> <p>See also <a href="#filePath">filePath</a>().
|
---|
245 |
|
---|
246 | <h3 class=fn>void <a name="setImage"></a>QMimeSourceFactory::setImage ( const <a href="qstring.html">QString</a> & abs_name, const <a href="qimage.html">QImage</a> & image )<tt> [virtual]</tt>
|
---|
247 | </h3>
|
---|
248 | Sets <em>image</em> to be the data item associated with the absolute
|
---|
249 | name <em>abs_name</em>.
|
---|
250 | <p> Equivalent to <a href="#setData">setData</a>(abs_name, new <a href="qimagedrag.html">QImageDrag</a>(image)).
|
---|
251 |
|
---|
252 | <h3 class=fn>void <a name="setPixmap"></a>QMimeSourceFactory::setPixmap ( const <a href="qstring.html">QString</a> & abs_name, const <a href="qpixmap.html">QPixmap</a> & pixmap )<tt> [virtual]</tt>
|
---|
253 | </h3>
|
---|
254 | Sets <em>pixmap</em> to be the data item associated with the absolute
|
---|
255 | name <em>abs_name</em>.
|
---|
256 |
|
---|
257 | <h3 class=fn>void <a name="setText"></a>QMimeSourceFactory::setText ( const <a href="qstring.html">QString</a> & abs_name, const <a href="qstring.html">QString</a> & text )<tt> [virtual]</tt>
|
---|
258 | </h3>
|
---|
259 | Sets <em>text</em> to be the data item associated with the absolute name
|
---|
260 | <em>abs_name</em>.
|
---|
261 | <p> Equivalent to <a href="#setData">setData</a>(abs_name, new <a href="qtextdrag.html">QTextDrag</a>(text)).
|
---|
262 |
|
---|
263 | <h3 class=fn><a href="qmimesourcefactory.html">QMimeSourceFactory</a> * <a name="takeDefaultFactory"></a>QMimeSourceFactory::takeDefaultFactory ()<tt> [static]</tt>
|
---|
264 | </h3>
|
---|
265 | Sets the <a href="#defaultFactory">defaultFactory</a>() to 0 and returns the previous one.
|
---|
266 |
|
---|
267 | <!-- eof -->
|
---|
268 | <hr><p>
|
---|
269 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
270 | Copyright © 1995-2007
|
---|
271 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
272 | <table width=100% cellspacing=0 border=0><tr>
|
---|
273 | <td>Copyright © 2007
|
---|
274 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
275 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
276 | </table></div></address></body>
|
---|
277 | </html>
|
---|