summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqmimesourcefactory.3qt
blob: c1f5db94c39bc87eeac9129bf9ffbe5097bc90af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
'\" t
.TH TQMimeSourceFactory 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
TQMimeSourceFactory \- Extensible provider of mime-typed data
.SH SYNOPSIS
\fC#include <tqmime.h>\fR
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBTQMimeSourceFactory\fR ()"
.br
.ti -1c
.BI "virtual \fB~TQMimeSourceFactory\fR ()"
.br
.ti -1c
.BI "virtual const TQMimeSource * \fBdata\fR ( const TQString & abs_name ) const"
.br
.ti -1c
.BI "virtual TQString \fBmakeAbsolute\fR ( const TQString & abs_or_rel_name, const TQString & context ) const"
.br
.ti -1c
.BI "const TQMimeSource * \fBdata\fR ( const TQString & abs_or_rel_name, const TQString & context ) const"
.br
.ti -1c
.BI "virtual void \fBsetText\fR ( const TQString & abs_name, const TQString & text )"
.br
.ti -1c
.BI "virtual void \fBsetImage\fR ( const TQString & abs_name, const TQImage & image )"
.br
.ti -1c
.BI "virtual void \fBsetPixmap\fR ( const TQString & abs_name, const TQPixmap & pixmap )"
.br
.ti -1c
.BI "virtual void \fBsetData\fR ( const TQString & abs_name, TQMimeSource * data )"
.br
.ti -1c
.BI "virtual void \fBsetFilePath\fR ( const TQStringList & path )"
.br
.ti -1c
.BI "virtual TQStringList \fBfilePath\fR () const"
.br
.ti -1c
.BI "void \fBaddFilePath\fR ( const TQString & p )"
.br
.ti -1c
.BI "virtual void \fBsetExtensionType\fR ( const TQString & ext, const char * mimetype )"
.br
.in -1c
.SS "Static Public Members"
.in +1c
.ti -1c
.BI "TQMimeSourceFactory * \fBdefaultFactory\fR ()"
.br
.ti -1c
.BI "void \fBsetDefaultFactory\fR ( TQMimeSourceFactory * factory )"
.br
.ti -1c
.BI "TQMimeSourceFactory * \fBtakeDefaultFactory\fR ()"
.br
.ti -1c
.BI "void \fBaddFactory\fR ( TQMimeSourceFactory * f )"
.br
.ti -1c
.BI "void \fBremoveFactory\fR ( TQMimeSourceFactory * f )"
.br
.in -1c
.SH DESCRIPTION
The TQMimeSourceFactory class is an extensible provider of mime-typed data.
.PP
A TQMimeSourceFactory provides an abstract interface to a collection of information. Each piece of information is represented by a TQMimeSource object which can be examined and converted to concrete data types by functions such as TQImageDrag::canDecode() and TQImageDrag::decode().
.PP
The base TQMimeSourceFactory can be used in two ways: as an abstraction of a collection of files or as specifically stored data. For it to access files, call setFilePath() before accessing data. For stored data, call setData() for each item (there are also convenience functions, e.g. setText(), setImage() and setPixmap(), that simply call setData() with appropriate parameters).
.PP
The rich text widgets, TQTextEdit and TQTextBrowser, use TQMimeSourceFactory to resolve references such as images or links within rich text documents. They either access the default factory (see defaultFactory()) or their own (see TQTextEdit::setMimeSourceFactory()). Other classes that are capable of displaying rich text (such as QLabel, QWhatsThis or QMessageBox) always use the default factory.
.PP
A factory can also be used as a container to store data associated with a name. This technique is useful whenever rich text contains images that are stored in the program itself, not loaded from the hard disk. Your program may, for example, define some image data as:
.PP
.nf
.br
    static const char* myimage_data[]={
.br
    "...",
.br
    ...
.br
    "..."};
.br
.fi
.PP
To be able to use this image within some rich text, for example inside a QLabel, you must create a TQImage from the raw data and insert it into the factory with a unique name:
.PP
.nf
.br
    TQMimeSourceFactory::defaultFactory()->setImage( "myimage", TQImage(myimage_data) );
.br
.fi
.PP
Now you can create a rich text QLabel with
.PP
.nf
.br
    QLabel* label = new QLabel(
.br
        "Rich text with embedded image:<img source=\\"myimage\\">"
.br
        "Isn't that <em>cute</em>?" );
.br
.fi
.PP
When no longer needed, you can clear the data from the factory:
.PP
.nf
.br
    delete label;
.br
    TQMimeSourceFactory::defaultFactory()->setData( "myimage", 0 );
.br
.fi
.PP
See also Environment Classes and Input/Output and Networking.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "TQMimeSourceFactory::TQMimeSourceFactory ()"
Constructs a TQMimeSourceFactory that has no file path and no stored content.
.SH "TQMimeSourceFactory::~TQMimeSourceFactory ()\fC [virtual]\fR"
Destroys the TQMimeSourceFactory, deleting all stored content.
.SH "void TQMimeSourceFactory::addFactory ( TQMimeSourceFactory * f )\fC [static]\fR"
Adds the TQMimeSourceFactory \fIf\fR to the list of available mimesource factories. If the defaultFactory() can't resolve a data() it iterates over the list of installed mimesource factories until the data can be resolved.
.PP
See also removeFactory().
.SH "void TQMimeSourceFactory::addFilePath ( const TQString & p )"
Adds another search path, \fIp\fR to the existing search paths.
.PP
See also setFilePath().
.SH "const TQMimeSource * TQMimeSourceFactory::data ( const TQString & abs_name ) const\fC [virtual]\fR"
Returns a reference to the data associated with \fIabs_name\fR. The return value remains valid only until the next data() or setData() call, so you should immediately decode the result.
.PP
If there is no data associated with \fIabs_name\fR in the factory's store, the factory tries to access the local filesystem. If \fIabs_name\fR isn't an absolute file name, the factory will search for it in all defined paths (see setFilePath()).
.PP
The factory understands all the image formats supported by TQImageIO. Any other mime types are determined by the file name extension. The default settings are
.PP
.nf
.br
    setExtensionType("html", "text/html;charset=iso8859-1");
.br
    setExtensionType("htm", "text/html;charset=iso8859-1");
.br
    setExtensionType("txt", "text/plain");
.br
    setExtensionType("xml", "text/xml;charset=UTF-8");
.br
.fi
The effect of these is that file names ending in "txt" will be treated as text encoded in the local encoding; those ending in" xml" will be treated as text encoded in Unicode UTF-8 encoding. The text/html type is treated specially, since the encoding can be specified in the html file itself. "html" or "htm" will be treated as text encoded in the encoding specified by the html meta tag, if none could be found, the charset of the mime type will be used. The text subtype ("html", "plain", or "xml") does not affect the factory, but users of the factory may behave differently. We recommend creating "xml" files where practical. These files can be viewed regardless of the runtime encoding and can encode any Unicode characters without resorting to encoding definitions inside the file.
.PP
Any file data that is not recognized will be retrieved as a TQMimeSource providing the "application/octet-stream" mime type, meaning uninterpreted binary data.
.PP
You can add further extensions or change existing ones with subsequent calls to setExtensionType(). If the extension mechanism is not sufficient for your problem domain, you can inherit TQMimeSourceFactory and reimplement this function to perform some more specialized mime-type detection. The same applies if you want to use the mime source factory to access URL referenced data over a network.
.SH "const TQMimeSource * TQMimeSourceFactory::data ( const TQString & abs_or_rel_name, const TQString & context ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
A convenience function. See data(const TQString& abs_name). The file name is given in \fIabs_or_rel_name\fR and the path is in \fIcontext\fR.
.SH "TQMimeSourceFactory * TQMimeSourceFactory::defaultFactory ()\fC [static]\fR"
Returns the application-wide default mime source factory. This factory is used by rich text rendering classes such as QSimpleRichText, QWhatsThis and QMessageBox to resolve named references within rich text documents. It serves also as the initial factory for the more complex render widgets, TQTextEdit and TQTextBrowser.
.PP
See also setDefaultFactory().
.PP
Examples:
.)l action/application.cpp and application/application.cpp.
.SH "TQStringList TQMimeSourceFactory::filePath () const\fC [virtual]\fR"
Returns the currently set search paths.
.SH "TQString TQMimeSourceFactory::makeAbsolute ( const TQString & abs_or_rel_name, const TQString & context ) const\fC [virtual]\fR"
Converts the absolute or relative data item name \fIabs_or_rel_name\fR to an absolute name, interpreted within the context (path) of the data item named \fIcontext\fR (this must be an absolute name).
.SH "void TQMimeSourceFactory::removeFactory ( TQMimeSourceFactory * f )\fC [static]\fR"
Removes the mimesource factory \fIf\fR from the list of available mimesource factories.
.PP
See also addFactory().
.SH "void TQMimeSourceFactory::setData ( const TQString & abs_name, TQMimeSource * data )\fC [virtual]\fR"
Sets \fIdata\fR to be the data item associated with the absolute name \fIabs_name\fR. Note that the ownership of \fIdata\fR is transferred to the factory: do not delete or access the pointer after passing it to this function.
.PP
Passing 0 for data removes previously stored data.
.SH "void TQMimeSourceFactory::setDefaultFactory ( TQMimeSourceFactory * factory )\fC [static]\fR"
Sets the default \fIfactory\fR, destroying any previously set mime source provider. The ownership of the factory is transferred to Qt.
.PP
See also defaultFactory().
.SH "void TQMimeSourceFactory::setExtensionType ( const TQString & ext, const char * mimetype )\fC [virtual]\fR"
Sets the mime-type to be associated with the file name extension, \fIext\fR to \fImimetype\fR. This determines the mime-type for files found via the paths set by setFilePath().
.SH "void TQMimeSourceFactory::setFilePath ( const TQStringList & path )\fC [virtual]\fR"
Sets the list of directories that will be searched when named data is requested to the those given in the string list \fIpath\fR.
.PP
See also filePath().
.SH "void TQMimeSourceFactory::setImage ( const TQString & abs_name, const TQImage & image )\fC [virtual]\fR"
Sets \fIimage\fR to be the data item associated with the absolute name \fIabs_name\fR.
.PP
Equivalent to setData(abs_name, new TQImageDrag(image)).
.SH "void TQMimeSourceFactory::setPixmap ( const TQString & abs_name, const TQPixmap & pixmap )\fC [virtual]\fR"
Sets \fIpixmap\fR to be the data item associated with the absolute name \fIabs_name\fR.
.SH "void TQMimeSourceFactory::setText ( const TQString & abs_name, const TQString & text )\fC [virtual]\fR"
Sets \fItext\fR to be the data item associated with the absolute name \fIabs_name\fR.
.PP
Equivalent to setData(abs_name, new TQTextDrag(text)).
.SH "TQMimeSourceFactory * TQMimeSourceFactory::takeDefaultFactory ()\fC [static]\fR"
Sets the defaultFactory() to 0 and returns the previous one.

.SH "SEE ALSO"
.BR http://doc.trolltech.com/tqmimesourcefactory.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqmimesourcefactory.3qt) and the Qt
version (3.3.8).