Mime Types and file associations

Related to: Fedora Core 3 (Heidelberg) with Gnome 2.8
Problem: After fresh install, "File types and programs" (gnome-file-types-properties) is not available any more. The given solution by gnome - right-click -> open with other application -> ... - is not acceptable. Goal is to define a default application and double-click the file!

Since GNOME 2.8, 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 Associate Application interface will 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.
This text is taken from website http://www.freebsd.org/gnome/docs/faq2.html#q22

This essay will describe the system-wide procedure, because the local one caused errors! Also the shown procedure of local define caused trouble in FC3.
At the end of this essay, you'll find some helpers to fix such created file associations...


MIME type handling in Gnome 2.8
Related Files:
This section will give you a small introduction which files need to be modified in order to change the system for your needs. Each of the shown files needs to be changed with root access.

-> /usr/share/applications/defaults.list
This file contains the applications which cause a double-click success. All Mime types will point to a desktop file.

-> /usr/share/applications/[application_name].desktop
This is the file where "defaults.list" will point to. One of the most important things inside this file is the entry "MimeType=".

-> /usr/share/applications/mimeinfo.cache
Contains information in similar form shown for file "defaults.list" in same directory. This file contains ALL associations given to a mime type. There is no need for a specified order of desktop files (see XMMS example lateron)

-> /usr/share/mime (Directory)
This directory contains several information. The sub-directories - excluding packages - contain information about given mime types. You'll see that many mime types already exist.
The packages directory contains the DATABASE calles freedesktop.org.xml!

-> /usr/share/mime/globs
This file contains the file extensions, associated to the mime-types.


Example: MPlayer should start WMV by Double-Click
I've uninstalled Xine and Totem, cause i only use MPlayer. After uninstalling them, i've seen the desaster: previously, Totem was the default player. And now there was ... nothing!
After two days of internet research, this essay was created ... so you havn't waste time as i have to do ;)

Creating the desktop file
If it is not already existing, create the file "/usr/share/applications/mplayer.desktop" like this:

[Desktop Entry]
Name=Movie Player
Comment=Play multimedia files and media
Icon=mplayer.xpm
Exec=gmplayer %f
Terminal=false
MimeType=video/mpeg;video/x-msvideo;video/quicktime;video/x-ms-asf;video/x-ms-wmv
Type=Application
Categories=Application;AudioVideo;
Encoding=UTF-8

The mime types for asf and wmv already exist and are stored in the mime type database (/usr/share/mime/packages/freedesktop.org.xml)

Modify defaults.list
This file will init our DEFAULT application. It ONLY contains ONE desktop file for EACH mime type:

video/x-ms-asf=mplayer.desktop
video/x-ms-wmv=mplayer.desktop


Modify mimeinfo.cache
To take effect as default application and init the double-click feature, we need to modify the mimeinfo.cache also:

video/x-ms-asf=mplayer.desktop
video/x-ms-wmv=mplayer.desktop

This file can use MORE then ONE desktop file. If you want to be able to handle - for example - WMV files with different players, a line like this is also acceptable:

video/x-ms-wmv=mplayer.desktop;realplay.desktop

This will change the right-click-menu and insert Helix-Player, while mplayer is still default (with double-click)

After modification, log out from gnome and log in again...


Example: XMMS should start MP3 by Double-Click
I've seen this question inside this forum, so it might be a little helper to toggle existing file associations to a needed row...
By default, the Helix player will open if we double-click a MP3-file. In defaults.list file we'll see:

...
audio/x-mp3=realplay.desktop
audio/x-mp3-playlist=realplay.desktop
...

... and in mimeinfo.cache we'll see entries like this:

...
audio/x-mp3=rythmbox.desktop;rythmbox.desktop;redhat-audio-player.desktop;realplay.desktop
...
audio/mp3=realplay.desktop
...

Now, what the heck is the correct player? It's "redhat-audio-player.desktop" (if you open this file, you'll see the line "Exec=xmms -e %F" :D

If we want XMMS to start MP3 files with a double-click, we need to change the defaults.list file:

...
audio/x-mp3=redhat-audio-player.desktop
audio/x-mp3-playlist=redhat-audio-player.desktop
...

... and this MP3 association in mimeinfo.cache:

...
audio/mp3=redhat-audio-player.desktop
...

Logout from Gnome and log in again ... the changes are ready to use ;)


Bug-Fixes and trouble shooter
As told in the beginning, local changes may cause trouble to install default applications. Here is an introduction on how to fix them. There is no need for root access, all files are stored in /home/[username]/.local. In case of that, the problems has to be fixed by each user itself, because root will not see directory ~/.local directory for other user ...

If you create an association by using "open with" or "open with other application", files are created in directory ~/.local/share/applications. DELETE THEM for applications modified for system-wide usage.

If you manualy create mime types inside the ~/.local folder (as shown in the quoted website in the beginning), please store them system-wide. I've tried this procedure (local) and was not able to double-click a file after rebooting, regardless of using the application "update-mime-database" or not.

If you get in trouble by using "update-mime-database" application by creating NEW mime-types and errors occur: -> there is a bug in the shown website!
WRONG: <xml version="1.0" encoding="UTF-8"?>
CORRECT:<?xml version="1.0" encoding="UTF-8"?>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

studious_cat

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值