## ThunarVfsMimeDatabase

ThunarVfsMimeDatabase — Provides access to the MIME database.

## Synopsis

    #include <thunar-vfs/thunar-vfs.h>

                        ThunarVfsMimeDatabase;
    ThunarVfsMimeDatabase* thunar_vfs_mime_database_get_default
                                                            (void);
    ThunarVfsMimeInfo*  thunar_vfs_mime_database_get_info   (ThunarVfsMimeDatabase *database,
                                                             const gchar *mime_type);
    ThunarVfsMimeInfo*  thunar_vfs_mime_database_get_info_for_data
                                                            (ThunarVfsMimeDatabase *database,
                                                             gconstpointer data,
                                                             gsize length);
    ThunarVfsMimeInfo*  thunar_vfs_mime_database_get_info_for_name
                                                            (ThunarVfsMimeDatabase *database,
                                                             const gchar *name);
    ThunarVfsMimeInfo*  thunar_vfs_mime_database_get_info_for_file
                                                            (ThunarVfsMimeDatabase *database,
                                                             const gchar *path,
                                                             const gchar *name);
    GList*              thunar_vfs_mime_database_get_infos_for_info
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info);
    GList*              thunar_vfs_mime_database_get_applications
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info);
    ThunarVfsMimeApplication* thunar_vfs_mime_database_get_default_application
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info);
    gboolean            thunar_vfs_mime_database_set_default_application
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info,
                                                             ThunarVfsMimeApplication *application,
                                                             GError **error);
    ThunarVfsMimeApplication* thunar_vfs_mime_database_add_application
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info,
                                                             const gchar *name,
                                                             const gchar *exec,
                                                             GError **error);
    gboolean            thunar_vfs_mime_database_remove_application
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeApplication *application,
                                                             GError **error);

## Object Hierarchy

      GObject
       +----ThunarVfsMimeDatabase

## Description

## Details

### ThunarVfsMimeDatabase

    typedef struct _ThunarVfsMimeDatabase ThunarVfsMimeDatabase;

The ThunarVfsMimeDatabase contains private data only, and should be accessed using the functions below.

### thunar_vfs_mime_database_get_default ()

    ThunarVfsMimeDatabase* thunar_vfs_mime_database_get_default
                                                            (void);

Returns a reference on the shared ThunarVfsMimeDatabase instance. The caller is responsible to call `g_object_unref()` on the returned object when no longer needed.

Returns : | the shared ThunarVfsMimeDatabase.

### thunar_vfs_mime_database_get_info ()

    ThunarVfsMimeInfo*  thunar_vfs_mime_database_get_info   (ThunarVfsMimeDatabase *database,
                                                             const gchar *mime_type);

Determines the ThunarVfsMimeInfo which corresponds to `mime_type` in database. The caller is responsible to call `thunar_vfs_mime_info_unref()` on the returned instance.

`database` : | a ThunarVfsMimeDatabase.
`mime_type` : | the string representation of the mime type.
Returns : | the ThunarVfsMimeInfo corresponding to `mime_type` in `database`.

### thunar_vfs_mime_database_get_info_for_data ()

    ThunarVfsMimeInfo*  thunar_vfs_mime_database_get_info_for_data
                                                            (ThunarVfsMimeDatabase *database,
                                                             gconstpointer data,
                                                             gsize length);

Determines the ThunarVfsMimeInfo for `data` in `database`. The caller is responsible to call `thunar_vfs_mime_info_unref()` on the returned instance.

`database` : | a ThunarVfsMimeDatabase.
`data` : | the data to check.
`length` : | the length of `data` in bytes.
Returns : | the ThunarVfsMimeInfo determined for `data`.

### thunar_vfs_mime_database_get_info_for_name ()

    ThunarVfsMimeInfo*  thunar_vfs_mime_database_get_info_for_name
                                                            (ThunarVfsMimeDatabase *database,
                                                             const gchar *name);

Determines the ThunarVfsMimeInfo for the filename given in `name` from `database`. The caller is responsible to call `thunar_vfs_mime_info_unref()` on the returned instance.

The `name` must be a valid filename in UTF-8 encoding and it may not contained any slashes!

`database` : | a ThunarVfsMimeDatabase.
`name` : | a filename (must be valid UTF-8!).
Returns : | the ThunarVfsMimeInfo for `name` in `database`.

### thunar_vfs_mime_database_get_info_for_file ()

    ThunarVfsMimeInfo*  thunar_vfs_mime_database_get_info_for_file
                                                            (ThunarVfsMimeDatabase *database,
                                                             const gchar *path,
                                                             const gchar *name);

Determines the ThunarVfsMimeInfo for `path` in `database`. The caller is responsible to free the returned instance using `thunar_vfs_mime_info_unref()`.

The `name` parameter is optional. If the caller already knows the basename of `path` in UTF-8 encoding, it should be specified here to speed up the lookup process.

`database` : | a ThunarVfsMimeDatabase.
`path` : | the path to a file in the local filesystem (in the filesystem encoding).
`name` : | the basename of `path` in UTF-8 encoding or `NULL`.
Returns : | the ThunarVfsMimeInfo for `path` in `database`.

### thunar_vfs_mime_database_get_infos_for_info ()

    GList*              thunar_vfs_mime_database_get_infos_for_info
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info);

Returns a list of all ThunarVfsMimeInfos, that are related to `info` in `database`. Currently this is the list of parent MIME-types for `info`, as defined in the Shared Mime Database.

Note that the returned list will also include a reference `info` itself. In addition, this method also handles details specified by the Shared Mime Database Specification like the fact that every "text/xxxx" MIME-type is a subclass of "text/plain" and every MIME-type is a subclass of "application/octet-stream".

The caller is responsible to free the returned list using #`thunar_vfs_mime_info_list_free()` when done with it.

`database` : | a ThunarVfsMimeDatabase.
`info` : | a ThunarVfsMimeInfo.
Returns : | the list of ThunarVfsMimeInfos related to `info`.

### thunar_vfs_mime_database_get_applications ()

    GList*              thunar_vfs_mime_database_get_applications
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info);

Looks up all ThunarVfsMimeApplications in `database`, which claim to be able to open files whose MIME-type is represented by `info`.

The caller is responsible to free the returned list using something like:

    g_list_foreach (list, (GFunc) g_object_unref, NULL);
    g_list_free (list);

`database` : | a ThunarVfsMimeDatabase.
`info` : | a ThunarVfsMimeInfo.
Returns : | the list of ThunarVfsMimeApplications, that can handle `info`.

### thunar_vfs_mime_database_get_default_application ()

    ThunarVfsMimeApplication* thunar_vfs_mime_database_get_default_application
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info);

Returns the default ThunarVfsMimeApplication to handle files of type `info` or `NULL` if no default application is set for `info`.

The caller is responsible to free the returned instance using `g_object_unref()` when no longer needed.

`database` : | a ThunarVfsMimeDatabase.
`info` : | a ThunarVfsMimeInfo.
Returns : | the default ThunarVfsMimeApplication for `info` or `NULL`.

### thunar_vfs_mime_database_set_default_application ()

    gboolean            thunar_vfs_mime_database_set_default_application
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info,
                                                             ThunarVfsMimeApplication *application,
                                                             GError **error);

Sets `application` to be the default ThunarVfsMimeApplication to open files of type `info` in `database`.

`database` : | a ThunarVfsMimeDatabase.
`info` : | a valid ThunarVfsMimeInfo for `database`.
`application` : | a ThunarVfsMimeApplication.
`error` : | return location for errors or `NULL`.
Returns : | `TRUE` if the operation was successfull, else `FALSE`.

### thunar_vfs_mime_database_add_application ()

    ThunarVfsMimeApplication* thunar_vfs_mime_database_add_application
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeInfo *info,
                                                             const gchar *name,
                                                             const gchar *exec,
                                                             GError **error);

Adds a new ThunarVfsMimeApplication to the `database`, whose name is `name` and command is `exec`, and which can be used to open files of type `info`.

The caller is responsible to free the returned object using `g_object_unref()` when no longer needed.

`database` : | a ThunarVfsMimeDatabase.
`info` : | a ThunarVfsMimeInfo.
`name` : | the name for the application.
`exec` : | the command for the application.
`error` : | return location for errors or `NULL`.
Returns : | the newly created ThunarVfsMimeApplication or `NULL` on error.

### thunar_vfs_mime_database_remove_application ()

    gboolean            thunar_vfs_mime_database_remove_application
                                                            (ThunarVfsMimeDatabase *database,
                                                             ThunarVfsMimeApplication *application,
                                                             GError **error);

Undoes the effect of `thunar_vfs_mime_database_add_application()` by removing the user created `application` from the `database`. The `application` must be user created, and the removal will fail if its not (for example if its a system-wide installed application launcher). See the documentation for `thunar_vfs_mime_application_is_usercreated()` for details.

`database` : | a ThunarVfsMimeDatabase.
`application` : | a ThunarVfsMimeApplication.
`error` : | return location for errors or `NULL`.
Returns : | `TRUE` if the removal was successfull, `FALSE` otherwise and `error` will be set.

## See Also

ThunarVfsMimeApplication, ThunarVfsMimeInfo