<?xml version="1.0" encoding="utf-8"?>
<page xmlns="http://projectmallard.org/1.0/" type="topic" style="task" id="mime-types-custom-user" xml:lang="fr">

  <info>
    <link type="guide" xref="software#management"/>
    <link type="seealso" xref="mime-types"/>
    <revision pkgversion="3.12" date="2014-06-17" status="review"/>

    <credit type="author copyright">
      <name>Petr Kovar</name>
      <email>pknbe@volny.cz</email>
      <years>2014</years>
    </credit>

    <include xmlns="http://www.w3.org/2001/XInclude" href="legal.xml"/>

    <desc>Créer la spécification d’un type MIME pour un utilisateur et l’associer à une application par défaut.</desc>
  
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
      <mal:name>Thibault Leclair</mal:name>
      <mal:email>thibaultleclair@yahoo.com</mal:email>
      <mal:years>2021</mal:years>
    </mal:credit>
  
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
      <mal:name>Mathieu Bousquet</mal:name>
      <mal:email>mathieu.bousquet2@gmail.com</mal:email>
      <mal:years>2022</mal:years>
    </mal:credit>
  
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
      <mal:name>Guillaume Bernard</mal:name>
      <mal:email>associations@guillaume-bernard.fr</mal:email>
      <mal:years>2023</mal:years>
    </mal:credit>
  
    <mal:credit xmlns:mal="http://projectmallard.org/1.0/" type="translator copyright">
      <mal:name>Irénée Thirion</mal:name>
      <mal:email>irenee.thirion@e.email</mal:email>
      <mal:years>2023-2024</mal:years>
    </mal:credit>
  </info>

    <title>Ajouter un type MIME personnalisé à un utilisateur</title>
    <p>Pour ajouter un type MIME personnalisé à un utilisateur et l’associer à une application par défaut, vous devez créer un nouveau fichier de spécification de type MIME dans le répertoire <file>~/.local/share/mime/packages/</file> ainsi qu’un fichier <file>.desktop</file> dans le répertoire <file>~/.local/share/applications/</file>.</p>
    <steps>
      <title>Ajouter un type MIME <code>application/x-newtype</code> personnalisé pour un utilisateur</title>
      <item>
        <p>Créez le fichier <file>~/.local/share/mime/packages/application-x-newtype.xml</file> :</p>
        <code mime="application/xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info"&gt;
  &lt;mime-type type="application/x-newtype"&gt;
    &lt;comment&gt;new mime type&lt;/commentaire&gt;
    &lt;glob pattern="*.xyz"/&gt;
  &lt;/mime-type&gt;
&lt;/mime-info&gt;</code>
      <p>L’exemple <file>application-x-newtype.xml</file> ci-dessus définit un nouveau type MIME <sys>application/x-newtype</sys> auquel sont assignés les fichiers avec l’extension <file>.xyz</file>.</p>
      </item>
      <item>
        <p>Créez un nouveau fichier <file>.desktop</file>, par exemple, <file>monapplication1.desktop</file>, et placez-le dans le répertoire <file>~/.local/share/applications/</file> :</p>
        <code>[Desktop Entry]
Type=Application
MimeType=application/x-newtype
Name=<var>Mon application n°1</var>
Exec=<var>monapplication1</var></code>
      <p>L’exemple <file>monapplication1.desktop</file> ci-dessus associe le type MIME <code>application/x-newtype</code> à l’application <app>Mon application n°1</app>, exécutée par la commande <cmd>monapplication1</cmd>.</p>
      </item>
      <item>
        <p>Actualisez la base de données MIME pour que vos modifications soient effectives :</p>
        <screen><output>$ </output><input>update-mime-database ~/.local/share/mime</input>
        </screen>
      </item>
      <item>
        <p>Actualisez la base de données des applications :</p>
        <screen><output>$ </output><input>update-desktop-database ~/.local/share/applications</input>
        </screen>
      </item>
      <item>
        <p>Pour vérifier l’association des fichiers <file>*.xyz</file> au type MIME <sys>application/x-newtype</sys>, créez préalablement un fichier vide, par exemple <file>test.xyz</file> :</p>
        <screen><output>$ </output><input>touch test.xyz</input></screen>
        <p>Exécutez ensuite la commande <cmd>gio info</cmd> :</p>
        <screen><output>$ </output><input>gio info test.xyz | grep "standard::content-type"</input>
  standard::content-type: application/x-newtype</screen>
        </item>
        <item>
          <p>Pour vérifier que <file>monapplication1.desktop</file> a été correctement définie comme application par défaut pour le type MIME <sys>application/x-newtype</sys>, exécutez la commande <cmd>gio mime</cmd> :</p>
        <screen><output>$ </output><input>gio mime application/x-newtype</input>
Application par défaut pour « application/x-newtype » : monapplication1.desktop
Applications inscrites :
	monapplication1.desktop
Applications recommandées :
	monapplication1.desktop</screen>
      </item>
    </steps>
</page>
