ROX-CLib: mime.c File Reference

- Main Page
- Data Structures
- Files
- Related Pages

- File List
- Globals

# mime.c File Reference

Shared MIME database functions for ROX-CLib. More...

`#include "rox-clib.h"`
`#include <stdlib.h>`
`#include <time.h>`
`#include <string.h>`
`#include <sys/param.h>`
`#include <fnmatch.h>`
`#include <sys/types.h>`
`#include <sys/stat.h>`
`#include <gtk/gtk.h>`
`#include <libxml/parser.h>`
`#include "rox.h"`
`#include "basedir.h"`
`#include "mime.h"`

## Data Structures
struct | pattern
## Defines
#define | TYPE_NS "http://www.freedesktop.org/standards/shared-mime-info"
#define | UNKNOWN text_plain
## Typedefs
typedef pattern | Pattern
## Functions
void | rox_mime_init (void)
ROXMIMEType * | rox_mime_get_type (const char *name, gboolean can_create)
void | mime_init (void)
ROXMIMEType * | rox_mime_lookup (const char *path)
ROXMIMEType * | mime_lookup (const char *path)
ROXMIMEType * | rox_mime_lookup_by_name (const char *name)
ROXMIMEType * | mime_lookup_by_name (const char *name)
char * | rox_mime_type_name (const ROXMIMEType *type)
char * | mime_type_name (const ROXMIMEType *type)
const char * | rox_mime_type_comment (ROXMIMEType *type)
const char * | mime_type_comment (ROXMIMEType *type)
void | rox_mime_set_ignore_exec_bit (int ignore)
void | mime_set_ignore_exec_bit (int ignore)
int | rox_mime_get_ignore_exec_bit (void)
int | mime_get_ignore_exec_bit (void)
void | rox_mime_set_by_content (int content)
void | mime_set_by_content (int content)
int | rox_mime_get_by_content (void)
int | mime_get_by_content (void)
GdkPixbuf * | rox_mime_get_icon (const ROXMIMEType *type, int msize)
## Variables
MIMEType_export ROXMIMEType * | text_plain
MIMEType_export ROXMIMEType * | application_executable
MIMEType_export ROXMIMEType * | application_octet_stream
MIMEType_export ROXMIMEType * | inode_directory
MIMEType_export ROXMIMEType * | inode_mountpoint
MIMEType_export ROXMIMEType * | inode_pipe
MIMEType_export ROXMIMEType * | inode_socket
MIMEType_export ROXMIMEType * | inode_block
MIMEType_export ROXMIMEType * | inode_char
MIMEType_export ROXMIMEType * | inode_door
MIMEType_export ROXMIMEType * | inode_unknown

## Detailed Description

Shared MIME database functions for ROX-CLib.

Author:
  Thomas Leonard, Stephen Watson

Version:
  Id
    mime.c,v 1.9 2006/10/03 20:45:58 stephen Exp

## Define Documentation

#define TYPE_NS "http://www.freedesktop.org/standards/shared-mime-info"

XML name space of the MIME definitions.

#define UNKNOWN text_plain

Normal files of undefined type default to text/plain

## Typedef Documentation

typedef struct pattern Pattern

The first pattern in the list which matches is used

## Function Documentation

int mime_get_by_content | ( | void |  | ) |

Return how the MIME system deals with the content of files, see mime_set_by_content().

Deprecated:
  Use rox_mime_get_by_content()

int mime_get_ignore_exec_bit | ( | void |  | ) |

Return how the MIME system treats executable files, see mime_set_ignore_exec_bit().

Deprecated:
  Use rox_mime_get_ignore_exec_bit().

void mime_init | ( | void |  | ) |

Initialize the MIME type system.

Deprecated:
  Use rox_mime_init() instead.

ROXMIMEType* mime_lookup | ( | const char * | path | ) |

Return the MIME type of the named object.

Deprecated:
  Use rox_mime_lookup().

ROXMIMEType* mime_lookup_by_name | ( | const char * | name | ) |

Return the type of a file based purely on the name. The file need not exist or be readable.

Deprecated:
  use rox_mime_lookup_by_name()

void mime_set_by_content | ( | int | content | ) |

Set how the MIME system deals with the content of files. If content is `FALSE` then the content of the files will never be read to identify the type.

Deprecated:
  Use rox_mime_set_by_content()

void mime_set_ignore_exec_bit | ( | int | ignore | ) |

Set how the MIME system treats executable files. If ignore is `FALSE` then all executable files will be identified as application/executable

Deprecated:
  Use rox_mime_set_ignore_exec_bit().

const char* mime_type_comment | ( | ROXMIMEType * | type | ) |

Return the comment of a MIME type (the long form of a name, e.g. " Text document")

Deprecated:
  use rox_mime_type_comment().

char* mime_type_name | ( | const ROXMIMEType * | type | ) |

Return the human readable name of the type, in the form media/sub-type

Deprecated:
  use rox_mime_type_name().

int rox_mime_get_by_content | ( | void |  | ) |

Return how the MIME system deals with the content of files, see mime_set_by_content().

Currently this flag has no effect as identifying files by content is not yet supported.

Returns:
  the value of the by_content flag.

GdkPixbuf* rox_mime_get_icon | ( | const ROXMIMEType * | type,
|  | int | msize |
| ) |  |  |

Return the icon for the specified MIME type, scaled appropriately. This function checks the override icons for media/subtype, then the ROX theme icon for the same type. If neither works it tries again for the generic media icon in the same places. If nothing works, `NULL` is returned.

In the future this will detect the icon theme in use, but until then only the ROX theme is checked.

Parameters:

  `[in]` | type | MIME type to look up
  `[in]` | msize | maximum size in pixels of the icon to return. If 0 or less the default size of 48 is used.

Returns:
  the icon, or `NULL` if not found.

int rox_mime_get_ignore_exec_bit | ( | void |  | ) |

Return how the MIME system treats executable files, see mime_set_ignore_exec_bit().

Returns:
  the value of the ignore_exec flag.

ROXMIMEType* rox_mime_get_type | ( | const char * | name,
|  | gboolean | can_create |
| ) |  |  |

Parse a MIME type name and return the corresponding ROXMIMEType data.

Parameters:

  `[in]` | name | name of the type, as media/sub-type
  `[in]` | can_create | if `TRUE` and name is not a currently known type then create a new one and return it, otherwise return `NULL`

Returns:
  the type, or `NULL` if is not known and can_create false, or if is malformed.

void rox_mime_init | ( | void |  | ) |

Initialize the MIME type system. This must be called before the other functions.

ROXMIMEType* rox_mime_lookup | ( | const char * | path | ) |

Return the MIME type of the named object.

If the object does not exist, or is in an unsearchable directory, then the type returned is based purely on the name.

If the object does exist then the type of file is checked. If it is a non-file object (such as a directory) then the appropriate inode/subtype type is returned. If it is a file and is executable and the mime_get_ignore_exec_bit() value is `FALSE` then application/executable is returned.

If mime_get_by_content() is not `FALSE` and content checking is implemented (it currently is not) and a type is identified it is returned.

If the type can be identified by the name then that is returned.

Finally if the execute bit is set application/executable is returned, otherwise UNKNOWN.

Parameters:

  `[in]` | path | path to object to check, or a name of a non-existant file

Returns:
  the identified type.

ROXMIMEType* rox_mime_lookup_by_name | ( | const char * | name | ) |

Return the type of a file based purely on the name. The file need not exist or be readable.

Parameters:

  `[in]` | name | name of file

Returns:
  the identified type.

void rox_mime_set_by_content | ( | int | content | ) |

Set how the MIME system deals with the content of files. If content is `FALSE` then the content of the files will never be read to identify the type.

Currently this flag has no effect as identifying files by content is not yet supported.

Parameters:

  `[in]` | content | the new value of the by_cotnent flag.

void rox_mime_set_ignore_exec_bit | ( | int | ignore | ) |

Set how the MIME system treats executable files. If ignore is `FALSE` then all executable files will be identified as application/executable

Parameters:

  `[in]` | ignore | the new value of the ignore_exec flag.

const char* rox_mime_type_comment | ( | ROXMIMEType * | type | ) |

Return the comment of a MIME type (the long form of a name, e.g. " Text document")

Parameters:

  `[in]` | type | the type

Returns:
  the comment

char* rox_mime_type_name | ( | const ROXMIMEType * | type | ) |

Return the human readable name of the type, in the form media/sub-type

Parameters:

  `[in]` | type | type to return name of.

Returns:
  the name, pass to g_free() when done.

## Variable Documentation

MIMEType_export ROXMIMEType* application_executable

Default for executable file

MIMEType_export ROXMIMEType* application_octet_stream

Default for binary file

MIMEType_export ROXMIMEType* inode_block

Block device file

MIMEType_export ROXMIMEType* inode_char

Character device file

MIMEType_export ROXMIMEType* inode_directory

A directory

MIMEType_export ROXMIMEType* inode_door

Door file, similar to sockets, not available on all operating systems

MIMEType_export ROXMIMEType* inode_mountpoint

A directory used as a mount point

MIMEType_export ROXMIMEType* inode_pipe

A named pipe

MIMEType_export ROXMIMEType* inode_socket

UNIX domain socket

MIMEType_export ROXMIMEType* inode_unknown

Unknown type, probably broken symbolic link

MIMEType_export ROXMIMEType* text_plain

Default for plain file