# kio Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# KMimeMagic Class Reference

This class or method is obsolete, it is provided for compatibility only. Use KMimeType::findByContent() instead May be removed in KDE 4.0 Determine auto-magically the type of file, not only by using its extension, but also by reading its contents. More...

`#include <kmimemagic.h>`

Collaboration diagram for KMimeMagic:

[legend]
List of all members.

## Public Member Functions

| KMimeMagic ()
| Create a parser and initialize it with the KDE-global data: the "magic" config file as well as the snippets from share/config/magic.
| KMimeMagic (const QString &configFile)
| Create a parser and initialize it with the given config file.
| ~KMimeMagic ()
| Destroy the parser.
bool | mergeConfig (const QString &configFile)
| Merge an existing parse table with the data from the given file.
bool | mergeBufConfig (char *)
| Merge an existing parse table with the data from the given buffer.
void | setFollowLinks (bool _enable)
| Enable/Disable follow-links.
KMimeMagicResult * | findFileType (const QString &_filename)
| Try to find a MimeType for the given file.
KMimeMagicResult * | findBufferType (const QByteArray &p)
| Same functionality as above, except data is not read from a file.
KMimeMagicResult * | findBufferFileType (const QByteArray &, const QString &filename)
| Same functionality as findBufferType() but with additional capability of distinguishing between C-headers and C-Source.

## Static Public Member Functions

KMimeMagic * | self ()
| Returns a pointer to the unique KMimeMagic instance in this process.

## Static Protected Member Functions

void | initStatic ()

## Protected Attributes

KMimeMagicResult * | magicResult
| The result type.

## Static Protected Attributes

KMimeMagic * | s_pSelf = 0L

## Detailed Description

This class or method is obsolete, it is provided for compatibility only. Use KMimeType::findByContent() instead May be removed in KDE 4.0 Determine auto-magically the type of file, not only by using its extension, but also by reading its contents.

Unless specified otherwise, KMimeMagic uses $KDEDIR/share/mimelnk/magic for this purpose.

To make KMimeMagic restore the 'atime' of a file after it opened it, add its directory in kmimemagicrc like: [Settings] atimeDirs=/tmp,/var/tmp,/home/dfaure/tmp This isn't done by default because it changes the 'ctime'. See kmimemagic.cpp for a full discussion on this issue.

The basic usage of KMimeMagic is :

- Get a pointer to it, using KMimeMagic::self().
- Use it for any file or buffer you want, using one of the three `find`...Type() methods.

The result is contained in the class KMimeMagicResult.

Definition at line 100 of file kmimemagic.h.

## Constructor & Destructor Documentation

KMimeMagic::KMimeMagic | ( |  | ) |

Create a parser and initialize it with the KDE-global data: the "magic" config file as well as the snippets from share/config/magic.

Since:
  3.1

Definition at line 2045 of file kmimemagic.cpp.

References KGlobal::dirs(), KStandardDirs::findAllResources(), locate(), and mergeConfig().

KMimeMagic::KMimeMagic | ( | const QString & | configFile | ) |

| Create a parser and initialize it with the given config file. Definition at line 2057 of file kmimemagic.cpp.

KMimeMagic::~KMimeMagic | ( |  | ) |

| Destroy the parser. Definition at line 2086 of file kmimemagic.cpp. References magicResult.

## Member Function Documentation

bool KMimeMagic::mergeConfig | ( | const QString & | configFile | ) |

Merge an existing parse table with the data from the given file.

Returns:
  `true` on success.

Definition at line 2103 of file kmimemagic.cpp.

References QString::isEmpty().

Referenced by KMimeMagic().

bool KMimeMagic::mergeBufConfig | ( | char * |  | ) |

Merge an existing parse table with the data from the given buffer.

Returns:
  `true` on success.

Definition at line 2121 of file kmimemagic.cpp.

void KMimeMagic::setFollowLinks | ( | bool | _enable | ) |

| Enable/Disable follow-links. (Default is disabled.) Definition at line 2138 of file kmimemagic.cpp.

KMimeMagicResult * KMimeMagic::findFileType | ( | const QString & | _filename | ) |

Try to find a MimeType for the given file.

If no special MimeType is found, the default MimeType is returned. This function looks at the content of the file.

Returns:
  A pointer to the result object. Do not delete the result object. After another call to KMimeMagic the returned result object changes its value since it is reused by KMimeMagic.

Definition at line 2201 of file kmimemagic.cpp.

References magicResult, KMimeMagicResult::setAccuracy(), KMimeMagicResult::setInvalid(), KMimeMagicResult::setMimeType(), and QString::stripWhiteSpace().

Referenced by KMimeType::findByFileContent(), and KMimeType::findByURL().

KMimeMagicResult * KMimeMagic::findBufferType | ( | const QByteArray & | p | ) |

Same functionality as above, except data is not read from a file.

Instead a buffer can be supplied which is examined.

Returns:
  A pointer to the result object. Do not delete the result object. After another call to KMimeMagic the returned result object changes its value since it is reused by KMimeMagic.

Definition at line 2144 of file kmimemagic.cpp.

References magicResult, KMimeMagicResult::setAccuracy(), KMimeMagicResult::setInvalid(), KMimeMagicResult::setMimeType(), and QString::stripWhiteSpace().

Referenced by findBufferFileType(), and KMimeType::findByContent().

KMimeMagicResult * KMimeMagic::findBufferFileType | ( | const QByteArray & | ,
|  | const QString & | filename
| ) |

Same functionality as findBufferType() but with additional capability of distinguishing between C-headers and C-Source.

For this purpose this function looks at the extension of the filename. This means that 'filename' can be a filename on some FTP server, too.

Returns:
  A pointer to the result object. Do not delete the result object. After another call to KMimeMagic the returned result object changes its value since it is reused by KMimeMagic.

Definition at line 2190 of file kmimemagic.cpp.

References findBufferType().

KMimeMagic * KMimeMagic::self | ( |  | ) | `[static]`

| Returns a pointer to the unique KMimeMagic instance in this process. Definition at line 30 of file kmimemagic.cpp. Referenced by KMimeType::findByContent(), KMimeType::findByFileContent(), and KMimeType::findByURL().

## Member Data Documentation

KMimeMagicResult* KMimeMagic::magicResult `[protected]`

| The result type. Definition at line 196 of file kmimemagic.h. Referenced by findBufferType(), findFileType(), and ~KMimeMagic().

The documentation for this class was generated from the following files:

- kmimemagic.h
- kmimemagic.cpp

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:19:08 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001