wxRuby Documentation Home

Wx::MimeTypesManager

This class allows the application to retrieve the information about all known
MIME types from a system-specific location and the filename extensions to the
MIME types and vice versa. After initialization the functions
MimeTypesManager#get_file_type_from_mime_type
and MimeTypesManager#get_file_type_from_extension
may be called: they will return a FileType object which
may be further queried for file description, icon and other attributes.

Windows: MIME type information is stored in the registry and no additional
initialization is needed.

Unix: MIME type information is stored in the files mailcap and mime.types
(system-wide) and .mailcap and .mime.types in the current user’s home directory:
all of these files can be searched for and loaded (disabled by default). However,

Additional Functions

MimeTypesManager#read_mailcap and
MimeTypesManager#read_mime_types are
provided to load additional files.

If GNOME or KDE desktop environment is installed, then MimeTypesManager
gathers MIME information from respective files (e.g. .kdelnk files under KDE).

NB: Currently, MimeTypesManager is limited to reading MIME type information
but it will support modifying it as well in future versions.

Global objects

Global instance of MimeTypesManager is always available. It is defined
as follows:

MimeTypesManager *TheMimeTypesManager;

It is recommended to use this instance instead of creating your own because
gathering MIME information may take quite a long time on Unix systems.

Derived from

No base class.

See also

FileType

Function groups

Helper functions

All of these functions are static (i.e. don’t need a MimeTypesManager 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 String functions.

is_of_type

Constructor and destructor

NB: You won’t normally need to use more than one MimeTypesManager object in a
program.

MimeTypesManager

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 FileType object
which must be deleted by the caller, otherwise NULL will be returned.

get_file_type_from_mime_type
get_file_type_from_extension

Initialization functions

Unix: These functions may be used to load additional files (except for the
default ones which are loaded automatically) containing MIME
information in either mailcap(5) or mime.types(5) format.

read_mailcap
read_mime_types
add_fallbacks

MimeTypesManager#add_fallbacks

add_fallbacks(%(arg-type)FileTypeInfo% 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.

MimeTypesManager#get_file_type_from_extension

FileType get_file_type_from_extension(%(arg-type)String% extension)

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

MimeTypesManager#get_file_type_from_mime_type

FileType get_file_type_from_mime_type(%(arg-type)String% mimeType)

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

MimeTypesManager#is_of_type

Boolean is_of_type(%(arg-type)String% mimeType, String 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 ‘*’. Note that the ‘*’ wildcard is not allowed in
mimeType itself.

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

MimeTypesManager#read_mailcap

Boolean read_mailcap(%(arg-type)String% filename, Boolean fallback = false)

Load additional file containing information about MIME types and associated
information in mailcap format. See metamail(1) and mailcap(5) for more
information.

fallback parameter may be used to load additional mailcap files without
overriding the settings found in the standard files: normally, entries from
files loaded with ReadMailcap will override the entries from files loaded
previously (and the standard ones are loaded in the very beginning), but this
will not happen if this parameter is set to true (default is false).

The return value is true if there were no errors in the file or false
otherwise.

MimeTypesManager#read_mime_types

Boolean read_mime_types(%(arg-type)String% filename)

Load additional file containing information about MIME types and associated
information in mime.types file format. See metamail(1) and mailcap(5) for more
information.

The return value is true if there were no errors in the file or false
otherwise.

[This page automatically generated from the Textile source at 2023-06-03 08:07:31 +0000]