QMimeSourceFactory(3qt)

NAME
QMimeSourceFactory - An extensible supply of MIME-typed data

#include <qmime.h>

  Public Members
QMimeSourceFactory ()
virtual ~QMimeSourceFactory ()
virtual const QMimeSource* data ( const QString & abs_name ) const
virtual QString makeAbsolute ( const QString & abs_or_rel_name, const QString & context ) const
const QMimeSource* data ( const QString & abs_or_rel_name, const QString & context ) const
virtual void setText ( const QString & abs_name, const QString & text )
virtual void setImage ( const QString & abs_name, const QImage & im )
virtual void setPixmap ( const QString & abs_name, const QPixmap & pm )
virtual void setData ( const QString & abs_name, QMimeSource * data )
virtual void setFilePath ( const QStringList & )
virtual QStringList filePath () const
void addFilePath ( const QString & )
virtual void setExtensionType ( const QString & ext, const char * mimetype )

  Static Public Members
QMimeSourceFactory* defaultFactory ()
void setDefaultFactory ( QMimeSourceFactory * )

DESCRIPTION
An extensible supply of MIME-typed data.

A QMimeSourceFactory provides an abstract interface to a collection of information. Each piece of information is represented by a QMimeSource object, which can be examined and converted to concrete data types by functions like QImageDrag::canDecode() and QImageDrag::decode().

The base QMimeSourceFactory 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 setText(), setImage(), and setPixmap() that simply call setData() with massaged parameters).

The rich text widgets QTextView and QTextBrowser use QMimeSourceFactory to resolve references such as images or links within rich text documents. They either access the default factory ( see defaultFactory() ) or their own ( see QTextView::setMimeSourceFactory() ). Other classes that are capable of displaying rich text like QLabel, QWhatsThis or QMessageBox always use the default factory.

As mentioned earlier, a factory can also be used as 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

  static const char* myimage_xpm[]={
  "...",
  ...
  "..."};

To be able to use this image within some rich text, for example inside a QLabel, you have to create a QImage from the raw data and insert it into the factory with a unique name:

  QMimeSourceFactory::defaultFactory()->setImage( "myimage", QImage(myimage_data) );

Now you can create a rich text QLabel with

  QLabel* label = new QLabel(
      "Rich text with embedded image:<img source=\"myimage\">"
      "Isn't that <em>cute</em>?" );

MEMBER FUNCTION DOCUMENTATION

QMimeSourceFactory::QMimeSourceFactory ()
Constructs a QMimeSourceFactory which has no file path and no stored content.

QMimeSourceFactory::~QMimeSourceFactory () [virtual]
Destructs the QMimeSourceFactory, deleting all stored content.

void QMimeSourceFactory::addFilePath ( const QString & p )
Adds another search path.

See also setFilePath().

const QMimeSource* QMimeSourceFactory::data ( const QString & abs_name ) const [virtual]
Returns a reference to the data associated with abs_name. The return value only remains valid until a subsequent call to this function for the same object, and only if setData() is not called to modify the data, so you should immediately decode the result.

If there is no data associated with abs_name in the factory's store, the factory tries to access the local filesystem. If abs_name isn't an absolute filename, the factory will search for it on all defined paths ( see setFilePath() ).

The factory understands all image formats supported by QImageIO. Any other mime types are determined by the filename extension. The default settings are

  setExtensionType("html", "text/html;charset=iso8859-1");
  setExtensionType("htm", "text/html;charset=iso8859-1");
  setExtensionType("txt", "text/plain");
  setExtensionType("xml", "text/xml;charset=UTF-8");

The effect of these is that filenames ending in "html" or "htm" will be treated as text encoded in the iso8859-1 encoding, those ending in "txt" will be treated as text encoded in the local encoding; those ending in "xml" will be treated as text encoded in UTF8 encoding. 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 as such files can be viewed regardless of the run-time encoding, and can encode any Unicode characters without resorting to encoding definitions inside the file.

Any file data that is not recognized will be retrieved as a QMimeSource providing the "application/octet-stream" MIME type, which is just uninterpreted binary data. You can add further extensions or change existing ones with subsequent calls to setExtensionType(). If the extension mechanism is not sufficient for you problem domain, you may inherit QMimeSourceFactory and reimplement this function to perform some more clever mime type detection. The same applies if you want to use the mime source factory for accessing URL referenced data over a network.

const QMimeSource* QMimeSourceFactory::data ( const QString & abs_or_rel_name, const QString & context ) const
A convenience function. See data(const QString& abs_name).

QMimeSourceFactory* QMimeSourceFactory::defaultFactory () [static]
Returns the application-wide default mime source factory. This factory is used by rich text rendering classes such as QSimpleRichText, QWhatsThis and also QMessageBox to resolve named references within rich text documents. It serves also as initial factory for the more complex render widgets QTextView and QTextBrowser.

See also setDefaultFactory().

QStringList QMimeSourceFactory::filePath () const [virtual]
Returns the currently set search paths.

QString QMimeSourceFactory::makeAbsolute ( const QString & abs_or_rel_name, const QString & context ) const [virtual]
Converts the absolute or relative data item name abs_or_rel_name to an absolute name, interpreted within the context of the data item named context (this must be an absolute name).

void QMimeSourceFactory::setData ( const QString & abs_name, QMimeSource * data ) [virtual]
Sets data to be the data item associated with the absolute name abs_name. Note that the ownership of data is transferred to the factory - do not delete or access the pointer after passing it to this function.

void QMimeSourceFactory::setDefaultFactory ( QMimeSourceFactory * factory ) [static]
Sets the default factory, destroying any previously set mime source provider. The ownership of the factory is transferred.

See also defaultFactory().

void QMimeSourceFactory::setExtensionType ( const QString & ext, const char * mimetype ) [virtual]
Sets the MIME-type to be associated with a filename extension. This determines the MIME-type for files found via a path set by setFilePath().

void QMimeSourceFactory::setFilePath ( const QStringList & path ) [virtual]
Sets a list of directories which will be searched when named data is requested.

See also filePath().

void QMimeSourceFactory::setImage ( const QString & abs_name, const QImage & image ) [virtual]
Sets image to be the data item associated with the absolute name abs_name.

Equivalent to setData(abs_name, new QImageDrag(image)).

void QMimeSourceFactory::setPixmap ( const QString & abs_name, const QPixmap & pixmap ) [virtual]
Sets pixmap to be the data item associated with the absolute name abs_name.

void QMimeSourceFactory::setText ( const QString & abs_name, const QString & text ) [virtual]
Sets text to be the data item associated with the absolute name abs_name.

Equivalent to setData(abs_name, new QTextDrag(text)).

SEE ALSO
http://doc.trolltech.com/qmimesourcefactory.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports make our job much simpler. Thank you.

In case of content or formattting problems with this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qmimesourcefactory.3qt) and the Qt version (2.3.5).