<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
               "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
<!ENTITY version SYSTEM "version.xml">
]>
<refentry id="gio-GContentType">
<refmeta>
<refentrytitle role="top_of_page" id="gio-GContentType.top_of_page">GContentType</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GIO Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>GContentType</refname>
<refpurpose>Platform-specific content typing</refpurpose>
</refnamediv>

<refsynopsisdiv id="gio-GContentType.synopsis" role="synopsis">
<title role="synopsis.title">Synopsis</title>

<synopsis>

#include &lt;gio/gio.h&gt;

<link linkend="gboolean">gboolean</link>            <link linkend="g-content-type-equals">g_content_type_equals</link>               (const <link linkend="char">char</link> *type1,
                                                         const <link linkend="char">char</link> *type2);
<link linkend="gboolean">gboolean</link>            <link linkend="g-content-type-is-a">g_content_type_is_a</link>                 (const <link linkend="char">char</link> *type,
                                                         const <link linkend="char">char</link> *supertype);
<link linkend="gboolean">gboolean</link>            <link linkend="g-content-type-is-unknown">g_content_type_is_unknown</link>           (const <link linkend="char">char</link> *type);
<link linkend="char">char</link> *              <link linkend="g-content-type-get-description">g_content_type_get_description</link>      (const <link linkend="char">char</link> *type);
<link linkend="char">char</link> *              <link linkend="g-content-type-get-mime-type">g_content_type_get_mime_type</link>        (const <link linkend="char">char</link> *type);
<link linkend="GIcon">GIcon</link> *             <link linkend="g-content-type-get-icon">g_content_type_get_icon</link>             (const <link linkend="char">char</link> *type);
<link linkend="gboolean">gboolean</link>            <link linkend="g-content-type-can-be-executable">g_content_type_can_be_executable</link>    (const <link linkend="char">char</link> *type);
<link linkend="char">char</link> *              <link linkend="g-content-type-from-mime-type">g_content_type_from_mime_type</link>       (const <link linkend="char">char</link> *mime_type);
<link linkend="char">char</link> *              <link linkend="g-content-type-guess">g_content_type_guess</link>                (const <link linkend="char">char</link> *filename,
                                                         const <link linkend="guchar">guchar</link> *data,
                                                         <link linkend="gsize">gsize</link> data_size,
                                                         <link linkend="gboolean">gboolean</link> *result_uncertain);
<link linkend="char">char</link> **             <link linkend="g-content-type-guess-for-tree">g_content_type_guess_for_tree</link>       (<link linkend="GFile">GFile</link> *root);
<link linkend="GList">GList</link> *             <link linkend="g-content-types-get-registered">g_content_types_get_registered</link>      (void);
</synopsis>
</refsynopsisdiv>









<refsect1 id="gio-GContentType.description" role="desc">
<title role="desc.title">Description</title>
<para>
A content type is a platform specific string that defines the type
of a file. On unix it is a mime type, on win32 it is an extension string
like ".doc", ".txt" or a percieved string like "audio". Such strings
can be looked up in the registry at HKEY_CLASSES_ROOT.</para>
<para>
</para>
</refsect1>

<refsect1 id="gio-GContentType.details" role="details">
<title role="details.title">Details</title>
<refsect2 id="g-content-type-equals" role="function">
<title>g_content_type_equals ()</title>
<indexterm zone="g-content-type-equals"><primary sortas="content_type_equals">g_content_type_equals</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_content_type_equals               (const <link linkend="char">char</link> *type1,
                                                         const <link linkend="char">char</link> *type2);</programlisting>
<para>
Compares two content types for equality.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type1</parameter>&#160;:</term>
<listitem><simpara> a content type string.
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>type2</parameter>&#160;:</term>
<listitem><simpara> a content type string.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if the two strings are identical or equivalent,
<link linkend="FALSE--CAPS"><literal>FALSE</literal></link> otherwise.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-content-type-is-a" role="function">
<title>g_content_type_is_a ()</title>
<indexterm zone="g-content-type-is-a"><primary sortas="content_type_is_a">g_content_type_is_a</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_content_type_is_a                 (const <link linkend="char">char</link> *type,
                                                         const <link linkend="char">char</link> *supertype);</programlisting>
<para>
Determines if <parameter>type</parameter> is a subset of <parameter>supertype</parameter>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> a content type string. 
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>supertype</parameter>&#160;:</term>
<listitem><simpara> a string.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if <parameter>type</parameter> is a kind of <parameter>supertype</parameter>,
<link linkend="FALSE--CAPS"><literal>FALSE</literal></link> otherwise. 
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-content-type-is-unknown" role="function">
<title>g_content_type_is_unknown ()</title>
<indexterm zone="g-content-type-is-unknown"><primary sortas="content_type_is_unknown">g_content_type_is_unknown</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_content_type_is_unknown           (const <link linkend="char">char</link> *type);</programlisting>
<para>
Checks if the content type is the generic "unknown" type.
On unix this is the "application/octet-stream" mimetype,
while on win32 it is "*".</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> a content type string. 
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if the type is the unknown type.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-content-type-get-description" role="function">
<title>g_content_type_get_description ()</title>
<indexterm zone="g-content-type-get-description"><primary sortas="content_type_get_description">g_content_type_get_description</primary></indexterm><programlisting><link linkend="char">char</link> *              g_content_type_get_description      (const <link linkend="char">char</link> *type);</programlisting>
<para>
Gets the human readable description of the content type.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> a content type string. 
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a short description of the content type <parameter>type</parameter>. 
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-content-type-get-mime-type" role="function">
<title>g_content_type_get_mime_type ()</title>
<indexterm zone="g-content-type-get-mime-type"><primary sortas="content_type_get_mime_type">g_content_type_get_mime_type</primary></indexterm><programlisting><link linkend="char">char</link> *              g_content_type_get_mime_type        (const <link linkend="char">char</link> *type);</programlisting>
<para>
Gets the mime-type for the content type. If one is registered</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> a content type string. 
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> the registered mime-type for the given <parameter>type</parameter>, or NULL if unknown.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-content-type-get-icon" role="function">
<title>g_content_type_get_icon ()</title>
<indexterm zone="g-content-type-get-icon"><primary sortas="content_type_get_icon">g_content_type_get_icon</primary></indexterm><programlisting><link linkend="GIcon">GIcon</link> *             g_content_type_get_icon             (const <link linkend="char">char</link> *type);</programlisting>
<para>
Gets the icon for a content type.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> a content type string.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="GIcon"><type>GIcon</type></link> corresponding to the content type.
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-content-type-can-be-executable" role="function">
<title>g_content_type_can_be_executable ()</title>
<indexterm zone="g-content-type-can-be-executable"><primary sortas="content_type_can_be_executable">g_content_type_can_be_executable</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link>            g_content_type_can_be_executable    (const <link linkend="char">char</link> *type);</programlisting>
<para>
Checks if a content type can be executable. Note that for instance
things like text files can be executables (i.e. scripts and batch files).</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>type</parameter>&#160;:</term>
<listitem><simpara> a content type string.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if the file type corresponds to a type that
can be executable, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> otherwise. 
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-content-type-from-mime-type" role="function" condition="since:2.18">
<title>g_content_type_from_mime_type ()</title>
<indexterm zone="g-content-type-from-mime-type" role="2.18"><primary sortas="content_type_from_mime_type">g_content_type_from_mime_type</primary></indexterm><programlisting><link linkend="char">char</link> *              g_content_type_from_mime_type       (const <link linkend="char">char</link> *mime_type);</programlisting>
<para>
Tries to find a content type based on the mime type name.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>mime_type</parameter>&#160;:</term>
<listitem><simpara> a mime type string.
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> Newly allocated string with content type or NULL when does not know.

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.18</para></refsect2>
<refsect2 id="g-content-type-guess" role="function">
<title>g_content_type_guess ()</title>
<indexterm zone="g-content-type-guess"><primary sortas="content_type_guess">g_content_type_guess</primary></indexterm><programlisting><link linkend="char">char</link> *              g_content_type_guess                (const <link linkend="char">char</link> *filename,
                                                         const <link linkend="guchar">guchar</link> *data,
                                                         <link linkend="gsize">gsize</link> data_size,
                                                         <link linkend="gboolean">gboolean</link> *result_uncertain);</programlisting>
<para>
Guesses the content type based on example data. If the function is 
uncertain, <parameter>result_uncertain</parameter> will be set to <link linkend="TRUE--CAPS"><literal>TRUE</literal></link>. Either <parameter>filename</parameter>
or <parameter>data</parameter> may be <link linkend="NULL--CAPS"><literal>NULL</literal></link>, in which case the guess will be based solely
on the other argument.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>filename</parameter>&#160;:</term>
<listitem><simpara> a string, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>data</parameter>&#160;:</term>
<listitem><simpara> a stream of data, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>data_size</parameter>&#160;:</term>
<listitem><simpara> the size of <parameter>data</parameter>
</simpara></listitem></varlistentry>
<varlistentry><term><parameter>result_uncertain</parameter>&#160;:</term>
<listitem><simpara> a flag indicating the certainty of the result
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> a string indicating a guessed content type for the 
given data. 
</simpara></listitem></varlistentry>
</variablelist></refsect2>
<refsect2 id="g-content-type-guess-for-tree" role="function" condition="since:2.18">
<title>g_content_type_guess_for_tree ()</title>
<indexterm zone="g-content-type-guess-for-tree" role="2.18"><primary sortas="content_type_guess_for_tree">g_content_type_guess_for_tree</primary></indexterm><programlisting><link linkend="char">char</link> **             g_content_type_guess_for_tree       (<link linkend="GFile">GFile</link> *root);</programlisting>
<para>
Tries to guess the type of the tree with root <parameter>root</parameter>, by
looking at the files it contains. The result is an array
of content types, with the best guess coming first.
</para>
<para>
The types returned all have the form x-content/foo, e.g.
x-content/audio-cdda (for audio CDs) or x-content/image-dcf 
(for a camera memory card). See the <ulink url="http://www.freedesktop.org/wiki/Specifications/shared-mime-info-spec">shared-mime-info</ulink>
specification for more on x-content types.
</para>
<para>
This function is useful in the implementation of <link linkend="g-mount-guess-content-type"><function>g_mount_guess_content_type()</function></link>.</para>
<para>
</para><variablelist role="params">
<varlistentry><term><parameter>root</parameter>&#160;:</term>
<listitem><simpara> the root of the tree to guess a type for
</simpara></listitem></varlistentry>
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> an <link linkend="NULL--CAPS"><literal>NULL</literal></link>-terminated array of zero or more content types, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>. 
   Free with <link linkend="g-strfreev"><function>g_strfreev()</function></link>

</simpara></listitem></varlistentry>
</variablelist><para role="since">Since 2.18</para></refsect2>
<refsect2 id="g-content-types-get-registered" role="function">
<title>g_content_types_get_registered ()</title>
<indexterm zone="g-content-types-get-registered"><primary sortas="content_types_get_registered">g_content_types_get_registered</primary></indexterm><programlisting><link linkend="GList">GList</link> *             g_content_types_get_registered      (void);</programlisting>
<para>
Gets a list of strings containing all the registered content types
known to the system. The list and its data should be freed using 
<parameter>g_list_foreach</parameter>(list, g_free, NULL) and <parameter>g_list_free</parameter>(list)</para>
<para>
</para><variablelist role="params">
<varlistentry><term><emphasis>Returns</emphasis>&#160;:</term><listitem><simpara> <link linkend="GList"><type>GList</type></link> of the registered content types.
</simpara></listitem></varlistentry>
</variablelist></refsect2>

</refsect1>




</refentry>
