class KMimeType

Represent a mime type, like "text/plain". More...

Definition#include <kmimetype.h>
InheritsKServiceType [public ]
Inherited byKDEDesktopMimeType, KExecMimeType, KFolderType
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

Public Types

Public Methods

Public Static Methods

Protected Methods

Protected Static Methods

Protected Members


Detailed Description

Represent a mime type, like "text/plain".

The starting point you need is often the static methods. See also KServiceType.

typedef KSharedPtr<KMimeType> Ptr

Ptr

typedef QValueList List

List

 KMimeType ( const QString & _fullpath, const QString& _type, const QString& _icon, const QString& _comment, const QStringList& _patterns )

KMimeType

Constructor.

You may pass in arguments to create a mimetype with specific properties.

 KMimeType ( const QString & _fullpath )

KMimeType

Construct a mimetype and take all information from a config file.

 KMimeType ( KDesktopFile *config )

KMimeType

Construct a mimetype and take all information from a desktop file.

 KMimeType ( QDataStream& _str, int offset )

KMimeType

The stream must already be positionned at the correct offset

 ~KMimeType ()

~KMimeType

[virtual]

QString  icon ( const QString& , bool )

icon

[const virtual]

Return the filename of the icon associated with the mimetype.

The arguments are unused, but provided so that KMimeType-derived classes can use them (e.g. KFolderType uses the URL to return one out of 2 icons)

Returns: The path to the icon associated with this MIME type.

Reimplemented from KServiceType.

QString  icon ( const KURL& , bool )

icon

[const virtual]

This function differs from the above only in that a KURL may be provided instead of a QString for convenience.

Reimplemented from KServiceType.

QPixmap  pixmap ( KIcon::Group _group, int _force_size = 0, int _state = 0, QString * _path = 0L )

pixmap

[const virtual]

Use this function only if you don't have a special URL for which you search a pixmap.

This function is useful to find out, which icon is usually chosen for a certain mime type. Since no URL is passed, it is impossible to obey icon hints in desktop entries for example.

Parameters:
_groupThe icon group where the icon is going to be used.
_force_sizeOverride globallly configured icon size.
_stateThe icon state, one of: KIcon::DefaultState, KIcon::ActiveState or KIcon::DisabledState.
_pathOutput parameter to get the full path. Seldom needed.

QPixmap  pixmap ( const KURL& _url, KIcon::Group _group, int _force_size = 0, int _state = 0, QString * _path = 0L )

pixmap

[const virtual]

Find the pixmap for a given file of this mimetype.

Convenience method that uses icon(), but also locates and load the pixmap.

Parameters:
_urlURL for the file.
_groupThe icon group where the icon is going to be used.
_force_sizeOverride globallly configured icon size.
_stateThe icon state, one of: KIcon::DefaultState, KIcon::ActiveState or KIcon::DisabledState.
_pathOutput parameter to get the full path. Seldom needed.

QPixmap  pixmapForURL ( const KURL & _url, mode_t _mode = 0, KIcon::Group _group = KIcon::Desktop, int _force_size = 0, int _state = 0, QString * _path = 0L )

pixmapForURL

[static]

Convenience method to find the pixmap for a URL

Call this one when you don't know the mimetype.

Parameters:
_urlURL for the file.
_groupThe icon group where the icon is going to be used.
_force_sizeOverride globally configured icon size.
_stateThe icon state, one of: KIcon::DefaultState, KIcon::ActiveState or KIcon::DisabledState.
_pathOutput parameter to get the full path. Seldom needed.

QString  iconForURL ( const KURL & _url, mode_t _mode = 0 )

iconForURL

[static]

The same functionality as pixmapForURL, but this method returns the name of the icon to load. You'll have to use KIconLoader to load the pixmap for it. The advantage of this method is that you can store the result, and then use it later on for any kind of size.

QString  favIconForURL ( const KURL& url )

favIconForURL

[static]

If unavailable, returns QString::null.

Returns: the "favicon" (see http://www.favicon.com) for the given url, if available. Does NOT attempt to download the favicon, it only returns one that is already available.

QString  comment ()

comment

[const]

Returns: The desriptive comment associated with the MIME type.

Reimplemented from KServiceType.

QString  comment ( const QString&, bool )

comment

[const virtual]

The arguments are unused, but provided so that KMimeType derived classes can use them.

Returns: The descriptive comment associated with the MIME type, if any.

Reimplemented from KServiceType.

QString  comment ( const KURL&, bool )

comment

[const virtual]

This function differs from the above only in that a KURL may be provided instead of a QString for convenience.

Reimplemented from KServiceType.

const QStringList&  patterns ()

patterns

[const]

Retrieve the list of patterns associated with the MIME Type.

void  load ( QDataStream& )

load

[virtual]

Load the mimetype from a stream.

Reimplemented from KServiceType.

void  save ( QDataStream& )

save

[virtual]

Save the mimetype to a stream.

Reimplemented from KServiceType.

QVariant  property ( const QString& _name )

property

[const virtual]

Reimplemented from KServiceType.

QStringList  propertyNames ()

propertyNames

[const virtual]

Reimplemented from KServiceType.

Ptr  mimeType ( const QString& _name )

mimeType

[static]

Retrieve a pointer to the mime type _name or a pointer to the default mime type "application/octet-stream".

0L is never returned.

Very important: Don't store the result in a KMimeType* !

See also: serviceType

Ptr  findByURL ( const KURL& _url, mode_t _mode = 0, bool _is_local_file = false, bool _fast_mode = false )

findByURL

[static]

This function looks at mode_t first.

If that does not help it looks at the extension. This is fine for FTP, FILE, TAR and friends, but is not for HTTP ( cgi scripts! ). You should use KRun instead, but this function returns immediately while KRun is async. If no extension matches, then KMimeMagic is used if the URL a local file or "application/octet-stream" is returned otherwise.

Parameters:
_urlIs the right most URL with a filesystem protocol. It is up to you to find out about that if you have a nested URL. For example "http://localhost/mist.gz#gzip:/decompress" would have to pass the "http://..." URL part, while "file:/tmp/x.tar#tar:/src/test.gz#gzip:/decompress" would have to pass the "tar:/..." part of the URL, since gzip is a filter protocol and not a filesystem protocol.
_fast_modeIf set to true no disk access is allowed to find out the mimetype. The result may be suboptimal, but it is fast.

Returns: A pointer to the matching mimetype. 0L is never returned. Very Important: Don't store the result in a KMimeType* !

Ptr  findByPath ( const QString& path, mode_t mode = 0, bool fast_mode = false )

findByPath

[static]

Same as findByURL but for local files only - convenience method.

Equivalent to KURL u; u.setPath(path); return findByURL( u, mode, true, fast_mode );

Ptr  findByContent ( const QByteArray &data, int *accuracy=0 )

findByContent

[static]

Tries to find out the MIME type of a data chunk by looking for certain magic numbers and characteristic strings in it. Returns application/octet-stream of the type can not be found this way. If accuracy is not a null pointer, *accuracy is set to the accuracy of the match (which is in the range 0..100).

Ptr  findByFileContent ( const QString &fileName, int *accuracy=0 )

findByFileContent

[static]

Tries to find out the MIME type of a file by looking for certain magic numbers and characteristic strings in it. This function is similar to the previous one. Note that the file name is not used for determining the file type, it is just used for loading the file's contents. If accuracy is not a null pointer, *accuracy is set to the accuracy of the match (which is in the range 0..100).

List  allMimeTypes ()

allMimeTypes

[static]

Get all the mimetypes.

Useful for showing the list of available mimetypes. More memory consuming than the ones above, don't use unless really necessary.

const QString &  defaultMimeType ()

defaultMimeType

[static]

Returns: name of the default mimetype Always application/octet-stream, but this method exists for performance purposes.

void  loadInternal ( QDataStream& )

loadInternal

[protected]

void  init ( KDesktopFile * )

init

[protected]

Reimplemented from KServiceType.

void  errorMissingMimeType ( const QString& _type )

errorMissingMimeType

[protected static]

Signal a missing mime type

void  buildDefaultType ()

buildDefaultType

[protected static]

This function makes sure that the default mime type exists.

void  checkEssentialMimeTypes ()

checkEssentialMimeTypes

[protected static]

This function makes sure that vital mime types are installed.

static bool s_bChecked

s_bChecked

[protected]

QStringList m_lstPatterns

m_lstPatterns

[protected]

static Ptr s_pDefaultType

s_pDefaultType

[protected]

void  virtual_hook ( int id, void* data )

virtual_hook

[protected virtual]

Returns true if check for vital mime types has been done.

Reimplemented from KServiceType.


Generated by: dfaure on faure on Tue Apr 16 08:49:48 2002, using kdoc 2.0a53.