|
发表于 2005-8-7 09:54:17
|
显示全部楼层
楼上的说的比较全了,其实官方faq上面就有的:
How do I add new MIME types to GNOME?
Since GNOME 2.10, MIME types are stored in the new FreeDesktop shared-mime-info database. However, gnome-control-center has not been updated to allow one to easily add MIME types to this database. Therefore, if applications such as Nautilus complain that there is no MIME type associated with a particular file, using the Open With tab under Properties not work.
New MIME types can be added in one of two places. They can either be added system-wide for all users, or added locally on a per-user basis. System-wide MIME types must be added to either ${LOCALBASE}/share/mime or ${X11BASE}/share/mime, where as local MIME types must be added to ~/.local/share/mime. In both cases, the procedure is the same.
To define a new MIME type, you must create an application and a packages file to describe it. The application file will be named for the MIME type, and contain its name and a brief comment describing it. The packages file will list all the extensions associated with this MIME type as well as any special file magic that can be used to identify files without an extension.
For example, if we wanted to add a new local MIME type for Windows HTML Help files (i.e. .chm files) called application/x-chm, we would do the following. First, we would create the directories ~/.local/share/mime/application and ~/.local/share/mime/packages if they did not already exist. Then, we create an application file called x-chm.xml that we will place in ~/.local/share/mime/application. The file looks like:
<xml version="1.0" encoding="UTF-8"?>
<mime-type
xmlns="http://www.freedesktop.org/standards/shared-mime-info"
type="application/x-chm">
<comment>Windows HTML Help file</comment>
</mime-type>
Next, we create a packages file called chm.xml that we will place in ~/.local/share/mime/packages. The file looks like:
<xml version="1.0" encoding="UTF-8"?>
<mime-info
xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/x-chm">
<comment>Windows HTML Help file</comment>
<glob pattern="*.chm" />
</mime-type>
</mime-info>
Once the files have been created, the MIME database must be updated. To do that, run the command:
% update-mime-database ~/.local/share/mime
Finally (and unfortunately), you must logout and log back in to GNOME for the changes to fully take effect. Nautilus' Properties->Open With interface can now be used to associate an application to this MIME type. Hopefully all of this will be made much easier in a future GNOME release. |
|