| Version: 3.3.1

Public Member Functions | Static Public Member Functions | List of all members
wxMimeTypesManager Class Reference
Class List by Category » Application and System configuration

`#include <wx/mimetype.h>`

## Detailed Description

This class allows the application to retrieve information about all known MIME types from a system-specific location and the filename extensions to the MIME types and vice versa.

MIME stands for "Multipurpose Internet Mail Extensions" and was originally used in mail protocols. It's standardized by several RFCs.

Under Windows, the MIME type information is queried from registry. Under Linux and Unix, it is queried from the XDG data directories.

Currently, wxMimeTypesManager is limited to reading MIME type information.

The application should not construct its own manager: it should use the object pointer wxTheMimeTypesManager. The functions GetFileTypeFromMimeType() and GetFileTypeFromExtension() return a wxFileType object which may be further queried for file description, icon and other attributes.

# Helper functions

All of these functions are static (i.e. don't need a wxMimeTypesManager object to call them) and provide some useful operations for string representations of MIME types. Their usage is recommended instead of directly working with MIME types using wxString functions.

- wxMimeTypesManager::IsOfType()

# Query database

These functions are the heart of this class: they allow to find a file type object from either file extension or MIME type. If the function is successful, it returns a pointer to the wxFileType object which must be deleted by the caller, otherwise nullptr will be returned.

- wxMimeTypesManager::GetFileTypeFromMimeType()
- wxMimeTypesManager::GetFileTypeFromExtension()

##

Library: wxBase
Category: Application and System configuration

See also
  wxFileType

## Public Member Functions
| wxMimeTypesManager ()
| Constructor puts the object in the "working" state. More...
| ~wxMimeTypesManager ()
| Destructor is not virtual, so this class should not be derived from. More...
void | AddFallbacks (const wxFileTypeInfo *fallbacks)
| This function may be used to provide hard-wired fallbacks for the MIME types and extensions that might not be present in the system MIME database. More...
wxFileType * | GetFileTypeFromExtension (const wxString &extension)
| Gather information about the files with given extension and return the corresponding wxFileType object or nullptr if the extension is unknown. More...
wxFileType * | GetFileTypeFromMimeType (const wxString &mimeType)
| Gather information about the files with given MIME type and return the corresponding wxFileType object or nullptr if the MIME type is unknown. More...
wxFileType * | Associate (const wxFileTypeInfo &ftInfo)
| Create a new association using the fields of wxFileTypeInfo (at least the MIME type and the extension should be set). More...
bool | Unassociate (wxFileType *ft)
| Undo Associate(). More...
size_t | EnumAllFileTypes (wxArrayString &mimetypes)
| Enumerate all known file types. More...

## Static Public Member Functions
static bool | IsOfType (const wxString &mimeType, const wxString &wildcard)
| This function returns true if either the given mimeType is exactly the same as wildcard or if it has the same category and the subtype of wildcard is '*'. More...

## Constructor & Destructor Documentation

## ◆ wxMimeTypesManager()

wxMimeTypesManager::wxMimeTypesManager | ( |  | ) |

Constructor puts the object in the "working" state.

## ◆ ~wxMimeTypesManager()

wxMimeTypesManager::~wxMimeTypesManager | ( |  | ) |

Destructor is not virtual, so this class should not be derived from.

## Member Function Documentation

## ◆ AddFallbacks()

void wxMimeTypesManager::AddFallbacks | ( | const wxFileTypeInfo * | fallbacks | ) |

This function may be used to provide hard-wired fallbacks for the MIME types and extensions that might not be present in the system MIME database.

Please see the typetest sample for an example of using it.

## ◆ Associate()

wxFileType* wxMimeTypesManager::Associate | ( | const wxFileTypeInfo & | ftInfo | ) |

Create a new association using the fields of wxFileTypeInfo (at least the MIME type and the extension should be set).

## ◆ EnumAllFileTypes()

size_t wxMimeTypesManager::EnumAllFileTypes | ( | wxArrayString & | mimetypes | ) |

Enumerate all known file types.

Returns the number of retrieved items.

## ◆ GetFileTypeFromExtension()

wxFileType* wxMimeTypesManager::GetFileTypeFromExtension | ( | const wxString & | extension | ) |

Gather information about the files with given extension and return the corresponding wxFileType object or nullptr if the extension is unknown.

The extension parameter may have, or not, the leading dot, if it has it, it is stripped automatically. It must not however be empty.

## ◆ GetFileTypeFromMimeType()

wxFileType* wxMimeTypesManager::GetFileTypeFromMimeType | ( | const wxString & | mimeType | ) |

Gather information about the files with given MIME type and return the corresponding wxFileType object or nullptr if the MIME type is unknown.

## ◆ IsOfType()

static bool wxMimeTypesManager::IsOfType | ( | const wxString & | mimeType,
|  | const wxString & | wildcard
| ) |  |
| static

This function returns true if either the given mimeType is exactly the same as wildcard or if it has the same category and the subtype of wildcard is '*'.

Note that the '*' wildcard is not allowed in mimeType itself.

The comparison done by this function is case insensitive so it is not necessary to convert the strings to the same case before calling it.

## ◆ Unassociate()

bool wxMimeTypesManager::Unassociate | ( | wxFileType * | ft | ) |

Undo Associate().