gnome-mime

Name

gnome-mime — Routines to find out the mime type of a file.

Synopsis


#include <gnome.h>


const char* gnome_mime_type                 (const gchar *filename);
const char* gnome_mime_type_or_default      (const gchar *filename,
                                             const gchar *defaultv);
const char* gnome_mime_type_of_file         (const char *existing_filename);
const char* gnome_mime_type_or_default_of_file
                                            (const char *existing_filename,
                                             const gchar *defaultv);
const char* gnome_mime_type_from_magic      (const gchar *filename);
GList*      gnome_uri_list_extract_filenames
                                            (const gchar *uri_list);
GList*      gnome_uri_list_extract_uris     (const gchar *uri_list);
void        gnome_uri_list_free_strings     (GList *list);

Description

The routines in gnome-mime provide a way to find the MIME type of a file and some utility functions.

There are two different methods for finding out the MIME type of a file: those where only the file name is used to find the MIME type: in this case the name is matched against a database of known extensions and regular expressions; and a routine that will try to guess the MIME type of the file by peeking at the contents of the file. The former routines only do in-memory operations, while the later need to perform a possible time expensive operation to figure out the information.

The routines that classify a file by its name, use the contents of all of the files with the extension .mime from the $gnome_prefix/share/mime-info directory and the ~/.gnome/mime-info to build the database for filename matching. The latter is supported to enable users to provide their mime types to extend the system defaults.

Application that wish to install their own MIME types only need to install a file in this directory.

The file $gnome/share/mime-info/gnome.mime is special, as it contains the defaults for gnome, and is read first. In addition, the file ~/.gnome/mime-info/user.mime is read last. This will guarantee that there is a way to set system defaults, and there is a way for the user to override them. There is currently no way to tell anything about the order of the other files in those directories, nor is there anyway to override system defaults yet.

The gnome_mime_type_from_magic Uses the contents of the file $gnome_prefix/etc/mime-magic to determine the contents of a file (this database is usually kept in a fast machine-preprocessed format in the $gnome_prefix/etc/mime-magic.dat file).

Details

gnome_mime_type ()

const char* gnome_mime_type                 (const gchar *filename);

Determined the mime type for filename.

filename : A filename (the file does not necesarily exist).
Returns :the mime-type for this filename.


gnome_mime_type_or_default ()

const char* gnome_mime_type_or_default      (const gchar *filename,
                                             const gchar *defaultv);

This routine tries to determine the mime-type of the filename only by looking at the filename from the GNOME database of mime-types.

filename : A filename (the file does not necesarily exist).
defaultv : A default value to be returned if no match is found
Returns :the mime-type of the filename. If no value could not be determined, it will return defaultv.


gnome_mime_type_of_file ()

const char* gnome_mime_type_of_file         (const char *existing_filename);

Determined the mime type for existing_filename. It will try to figure this out by looking at the contents of the file, if this fails it will use the filename to figure out a name.

existing_filename : A filename pointing to an existing file.
Returns :the mime-type for this filename.


gnome_mime_type_or_default_of_file ()

const char* gnome_mime_type_or_default_of_file
                                            (const char *existing_filename,
                                             const gchar *defaultv);

This routine tries to determine the mime-type of the filename by trying to guess the content of the file. If this fails, it will return the mime-type based only on the filename.

existing_filename : A filename that points to an existing filename.
defaultv : A default value to be returned if no match is found
Returns :the mime-type of the existing_filename. If no value could not be determined, it will return defaultv.


gnome_mime_type_from_magic ()

const char* gnome_mime_type_from_magic      (const gchar *filename);

This routine uses a magic database as described in magic(5) that maps files into their mime-type (so our modified magic database contains mime-types rather than textual descriptions of the files).

filename : an existing file name for which we want to guess the mime-type
Returns :a pointer to an internal copy of the mime-type for filename.


gnome_uri_list_extract_filenames ()

GList*      gnome_uri_list_extract_filenames
                                            (const gchar *uri_list);

uri_list : an uri-list in the standard format
Returns :a GList containing strings allocated with g_malloc that contain the filenames in the uri-list. Note that unlike gnome_uri_list_extract_uris() function, this will discard any non-file uri from the result value.


gnome_uri_list_extract_uris ()

GList*      gnome_uri_list_extract_uris     (const gchar *uri_list);

uri_list : an uri-list in the standard format.
Returns :a GList containing strings allocated with g_malloc that have been splitted from uri-list.


gnome_uri_list_free_strings ()

void        gnome_uri_list_free_strings     (GList *list);

Releases all of the resources allocated by list.