PDA

View Full Version : How-To: Mime Types and file associations with FC3 - Gnome 2.8



Pegasus
14th November 2004, 11:46 AM
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"?>

ominae
12th April 2005, 09:28 PM
How would you make .m3u automatically load to xmms when you double click on the file. Mine aways default to xine. thanks

BandC
13th April 2005, 04:01 PM
Just curious... Did they fix this in Gnome 2.10 so we don't have to do all this?

Schika
25th April 2005, 12:49 AM
How can I add/edit instead of MIME-TYPE the protocols? For example I would like to add the protocol callto:// and assign it to Skype. Thanks in advance.

TheCat
14th July 2005, 02:43 PM
No, it hasn't been fixed in Gnome 2.10. I'm guessing this is a conscious decision on the part of the Gnome developers, but it sure seems weird to me. At any rate, there's a very helpful tutorial I found for Gnome 2.1 on FC4.

Gnome
http://www.ces.clemson.edu/linux/fc4_desktop.shtml#gmime

KDE
http://www.ces.clemson.edu/linux/fc4_desktop.shtml#kmime

BandC
14th July 2005, 04:40 PM
No, it hasn't been fixed in Gnome 2.10. I'm guessing this is a conscious decision on the part of the Gnome developers, but it sure seems weird to me. At any rate, there's a very helpful tutorial I found for Gnome 2.1 on FC4.

Gnome
http://www.ces.clemson.edu/linux/fc4_desktop.shtml#gmime

KDE
http://www.ces.clemson.edu/linux/fc4_desktop.shtml#kmime

These tutorials look really nice. Thanks for the links.

marinaccio
13th August 2006, 07:50 AM
Pegasus,

Thanks for the info, pointed me in the right direction.

marinaccio

salgur
11th September 2010, 04:07 PM
Thank you very much. You're one more nice person who makes my life easier. Thanks again.
Sal