source: trunk/doc/html/qmimesourcefactory.html@ 208

Last change on this file since 208 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 16.8 KB
Line 
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"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { 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&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;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&nbsp;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 &lt;<a href="qmime-h.html">qmime.h</a>&gt;</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&nbsp;QString&nbsp;&amp;&nbsp;abs_name ) const</li>
43<li class=fn>virtual QString <a href="#makeAbsolute"><b>makeAbsolute</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;abs_or_rel_name, const&nbsp;QString&nbsp;&amp;&nbsp;context ) const</li>
44<li class=fn>const QMimeSource * <a href="#data-2"><b>data</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;abs_or_rel_name, const&nbsp;QString&nbsp;&amp;&nbsp;context ) const</li>
45<li class=fn>virtual void <a href="#setText"><b>setText</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;abs_name, const&nbsp;QString&nbsp;&amp;&nbsp;text )</li>
46<li class=fn>virtual void <a href="#setImage"><b>setImage</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;abs_name, const&nbsp;QImage&nbsp;&amp;&nbsp;image )</li>
47<li class=fn>virtual void <a href="#setPixmap"><b>setPixmap</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;abs_name, const&nbsp;QPixmap&nbsp;&amp;&nbsp;pixmap )</li>
48<li class=fn>virtual void <a href="#setData"><b>setData</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;abs_name, QMimeSource&nbsp;*&nbsp;data )</li>
49<li class=fn>virtual void <a href="#setFilePath"><b>setFilePath</b></a> ( const&nbsp;QStringList&nbsp;&amp;&nbsp;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&nbsp;QString&nbsp;&amp;&nbsp;p )</li>
52<li class=fn>virtual void <a href="#setExtensionType"><b>setExtensionType</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;ext, const&nbsp;char&nbsp;*&nbsp;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&nbsp;*&nbsp;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&nbsp;*&nbsp;f )</li>
60<li class=fn>void <a href="#removeFactory"><b>removeFactory</b></a> ( QMimeSourceFactory&nbsp;*&nbsp;f )</li>
61</ul>
62<hr><a name="details"></a><h2>Detailed Description</h2>
63
64
65The QMimeSourceFactory class is an extensible provider of mime-typed data.
66<p>
67
68<p> A QMimeSourceFactory provides an abstract interface to a
69collection of information. Each piece of information is
70represented by a <a href="qmimesource.html">QMimeSource</a> object which can be examined and
71converted 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
74abstraction of a collection of files or as specifically stored
75data. For it to access files, call <a href="#setFilePath">setFilePath</a>() before accessing
76data. For stored data, call <a href="#setData">setData</a>() for each item (there are
77also 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
79parameters).
80<p> The rich text widgets, <a href="qtextedit.html">QTextEdit</a> and <a href="qtextbrowser.html">QTextBrowser</a>, use
81QMimeSourceFactory to resolve references such as images or links
82within 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
85capable 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
88with a name. This technique is useful whenever rich text contains
89images that are stored in the program itself, not loaded from the
90hard disk. Your program may, for example, define some image data
91as:
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
100inside a QLabel, you must create a <a href="qimage.html">QImage</a> from the raw data and
101insert it into the factory with a unique name:
102<pre>
103 QMimeSourceFactory::<a href="#defaultFactory">defaultFactory</a>()-&gt;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:&lt;img source=\"myimage\"&gt;"
110 "Isn't that &lt;em&gt;cute&lt;/em&gt;?" );
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>()-&gt;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>
124Constructs a QMimeSourceFactory that has no file path and no
125stored content.
126
127<h3 class=fn><a name="~QMimeSourceFactory"></a>QMimeSourceFactory::~QMimeSourceFactory ()<tt> [virtual]</tt>
128</h3>
129Destroys the QMimeSourceFactory, deleting all stored content.
130
131<h3 class=fn>void <a name="addFactory"></a>QMimeSourceFactory::addFactory ( <a href="qmimesourcefactory.html">QMimeSourceFactory</a>&nbsp;*&nbsp;f )<tt> [static]</tt>
132</h3>
133Adds the QMimeSourceFactory <em>f</em> to the list of available
134mimesource 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
136until 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&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;p )
140</h3>
141Adds 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&nbsp;<a href="qmimesource.html">QMimeSource</a>&nbsp;* <a name="data"></a>QMimeSourceFactory::data ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;abs_name ) const<tt> [virtual]</tt>
145</h3>
146Returns a reference to the data associated with <em>abs_name</em>. The
147return value remains valid only until the next <a href="#data">data</a>() or <a href="#setData">setData</a>()
148call, so you should immediately decode the result.
149<p> If there is no data associated with <em>abs_name</em> in the factory's
150store, the factory tries to access the local filesystem. If <em>abs_name</em> isn't an absolute file name, the factory will search for
151it 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
154extension. 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
162The effect of these is that file names ending in "txt" will be
163treated as text encoded in the local encoding; those ending in
164"xml" will be treated as text encoded in Unicode UTF-8 encoding.
165The text/html type is treated specially, since the encoding can be
166specified in the html file itself. "html" or "htm" will be treated
167as text encoded in the encoding specified by the html meta tag, if
168none could be found, the charset of the mime type will be used.
169The text subtype ("html", "plain", or "xml") does not affect the
170factory, but users of the factory may behave differently. We
171recommend creating "xml" files where practical. These files can be
172viewed regardless of the runtime encoding and can encode any
173Unicode characters without resorting to encoding definitions
174inside 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,
177meaning uninterpreted binary data.
178<p> You can add further extensions or change existing ones with
179subsequent calls to <a href="#setExtensionType">setExtensionType</a>(). If the extension mechanism
180is not sufficient for your problem domain, you can inherit
181QMimeSourceFactory and reimplement this function to perform some
182more specialized mime-type detection. The same applies if you want
183to use the mime source factory to access URL referenced data over
184a network.
185
186<h3 class=fn>const&nbsp;<a href="qmimesource.html">QMimeSource</a>&nbsp;* <a name="data-2"></a>QMimeSourceFactory::data ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;abs_or_rel_name, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;context ) const
187</h3>
188This 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
190file 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>&nbsp;* <a name="defaultFactory"></a>QMimeSourceFactory::defaultFactory ()<tt> [static]</tt>
193</h3>
194Returns the application-wide default mime source factory. This
195factory 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
197references within rich text documents. It serves also as the
198initial 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>
205Returns the currently set search paths.
206
207<h3 class=fn><a href="qstring.html">QString</a> <a name="makeAbsolute"></a>QMimeSourceFactory::makeAbsolute ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;abs_or_rel_name, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;context ) const<tt> [virtual]</tt>
208</h3>
209Converts the absolute or relative data item name <em>abs_or_rel_name</em> to an absolute name, interpreted within the
210context (path) of the data item named <em>context</em> (this must be an
211absolute name).
212
213<h3 class=fn>void <a name="removeFactory"></a>QMimeSourceFactory::removeFactory ( <a href="qmimesourcefactory.html">QMimeSourceFactory</a>&nbsp;*&nbsp;f )<tt> [static]</tt>
214</h3>
215Removes the mimesource factory <em>f</em> from the list of available
216mimesource factories.
217<p> <p>See also <a href="#addFactory">addFactory</a>().
218
219<h3 class=fn>void <a name="setData"></a>QMimeSourceFactory::setData ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;abs_name, <a href="qmimesource.html">QMimeSource</a>&nbsp;*&nbsp;data )<tt> [virtual]</tt>
220</h3>
221Sets <em>data</em> to be the data item associated with
222the absolute name <em>abs_name</em>. Note that the ownership of <em>data</em> is
223transferred to the factory: do not delete or access the pointer after
224passing 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>&nbsp;*&nbsp;factory )<tt> [static]</tt>
228</h3>
229Sets the default <em>factory</em>, destroying any previously set mime
230source provider. The ownership of the factory is transferred to
231Qt.
232<p> <p>See also <a href="#defaultFactory">defaultFactory</a>().
233
234<h3 class=fn>void <a name="setExtensionType"></a>QMimeSourceFactory::setExtensionType ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;ext, const&nbsp;char&nbsp;*&nbsp;mimetype )<tt> [virtual]</tt>
235</h3>
236Sets 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
238found via the paths set by <a href="#setFilePath">setFilePath</a>().
239
240<h3 class=fn>void <a name="setFilePath"></a>QMimeSourceFactory::setFilePath ( const&nbsp;<a href="qstringlist.html">QStringList</a>&nbsp;&amp;&nbsp;path )<tt> [virtual]</tt>
241</h3>
242Sets the list of directories that will be searched when named data
243is 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&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;abs_name, const&nbsp;<a href="qimage.html">QImage</a>&nbsp;&amp;&nbsp;image )<tt> [virtual]</tt>
247</h3>
248Sets <em>image</em> to be the data item associated with the absolute
249name <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&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;abs_name, const&nbsp;<a href="qpixmap.html">QPixmap</a>&nbsp;&amp;&nbsp;pixmap )<tt> [virtual]</tt>
253</h3>
254Sets <em>pixmap</em> to be the data item associated with the absolute
255name <em>abs_name</em>.
256
257<h3 class=fn>void <a name="setText"></a>QMimeSourceFactory::setText ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;abs_name, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;text )<tt> [virtual]</tt>
258</h3>
259Sets <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>&nbsp;* <a name="takeDefaultFactory"></a>QMimeSourceFactory::takeDefaultFactory ()<tt> [static]</tt>
264</h3>
265Sets the <a href="#defaultFactory">defaultFactory</a>() to 0 and returns the previous one.
266
267<!-- eof -->
268<hr><p>
269This file is part of the <a href="index.html">Qt toolkit</a>.
270Copyright &copy; 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 &copy; 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>
Note: See TracBrowser for help on using the repository browser.