The K Desktop Environment

3.2. How to install new data types

3.2.1. What are data types

A file contains only bits and bytes. One must know how to interprete them to give them a meaning. A usual method to archive this is to look at the filename. If it ends with .gif for example, you assume that it is a GIF image. That's what most desktop environments (further on called DE) do. KFM does this, too, since it is very fast, but not convenient. If the extension is not available one does not know of which data type the file is and that means in turn that KFM does not know which appliaction can deal with the data. So if KFM can not figure out the data type by extension it will have a look in the first bytes of the file and lookup some stuff in its magic file. This is called automatic-mime-type-detection-magic and works quite nice. So if the datatype has an entry in the magic file $KDEDIR/share/mimelnk/magic, then KFM would know that the file MyGirlFriend contains an image.

You must register data types in KFM. This poor little helper of yours must know common extensions of this data type, an icon, some descriptive text, perhaps a default application ( we will learn more about this later ) and the mime type.

3.2.2. What is a Mime Type

Mime types are an internet standard. This standard is a naming scheme for data types. A data types name is devided in two sections. The first one tells about the general kind of data ( image, video, audio, text ... ) and since there are different kinds of text ( C-sources, english text, ... ) and different formats for saving images and so on, the second part tells abou the special format. A good example is image/gif. The first part tell, its an image and the second one tells, it is saved in GIF format.

If you are not shure about the correct mime type, then have a look at the magic file, many many mime types are already registered there.

Usually this chapter is only of interest for system maintainers and application developers. A proper installed KDE should come with all this stuff already done, but some people always want to know how stuff works, so here we go.

The directory $KDEDIR/share/mimelnk contains many subdirectories which correspond to the first section of the mime type names. For example our example image/gif is represented by a file named $KDEDIR/share/mimelnk/image/gif.kdelnk. Every KFM config file has the .kdelnk extension. Sometimes KFM hides this extension, since it does not look very nice.

You will find out sooner or later that the directory structure in your global KDE directory is the same as the one in your ˜/.kde directory. As sysadmin on your local Linux box, you may usually want to edit the global configuration, while a user at the universities UNIX cluster may only edit his personal configuration. Everything we say about the $KDEDIR directory here, applies to the ˜/.kde directory, too. To edit the global config files in $KDEDIR you need a super users password, for the personal stuff of course not.

3.2.3. Installing new mime types step by step

This chapter could be named installing mime types for dummies since it comes with many nice pictures :-).

In the following we want to see how I installed the image/gif mime type. You dont need to reproduce these steps, since this mime type is already installed. After reading this chapter and after having a look at all the images you should know how to install new ones.

The black numbers on yellow circels in the images correspond to the numbered list under the image.

3.2.3.1. Open a KFM super user window

On your desktop you will find icons like these:

Now click on this icon to open a new KFM window. Usually this is the correct method, but in some cases we need a super users KFM window. If you want to edit the global config files which are usually only writeable for the super user, you need super user access. If you dont now the super user password, then you are not allowed to change the global configuration anyway, but you can of course edit your user specific configuration without being super user. There are different methods leading to a super user kfm window. You can log out, and log in as root. That is the Windows NT way, so we want to do it better. You could open a kvt window, switch to superuser with su and start kfm -ws now, but it is much easier to hit Alt+F2. Now enter kfmsu. A terminal window pops up, asking you for super users password. Enter it and a KFM window will popup up. Once you have done the following stuff, dont forget to close the KFM super user window again. At this time the terminal will desappear, too. the kfmsu script will allow the super user to access the display and will disallow it afterwards automatically for you.

To start, click once with the left mouse button on Templates folder ( or open a super user KFM window as described above ). Have a look at the files in this directory, you will remember them later in this chapter.

Now open the menu Edit and choose Mime Types ( or Global Mime Types if you want to edit the global configuration ). Now you will see something like this:

  • This is the magic file we talked about before. You should have a look at it later, but dont worry, no need to understand it.

  • The folder containing the image/gif mime type file. Click on this folder with the left mouse button to open it.

3.2.3.2. Creating a new mime type file

Open the menu File and select New. You may have notice by now that the names in this popup menu correspond to the names in the tamplates folder. This menu gives you quick access to the templates. You can have the same effect by opening the templates folder and doing drag and drop. Now select Mime Type. A window like this one will popup:

  • Enter the name of the file here. Please dont delete the .kdelnk extension. You should notice here that the name of the file is only the second part of the mime types name. The first part is coverd by the directory you move the file in. The name of the file and the subdirectory you put it in does not really matter, it just needs to be in $KDEDIR/share/mimelnk.

  • Now press the OK button and the new icon will appear in the KFM window.

3.2.3.3. Opening the properties dialog

Now press the right mouse button over the new icon and select Properties from the popup menu. A dialog appears:

  • Select the tab called Binding.

  • Enter some patterns that usually match files of this data type. If you have multiple patterns, then you must separate them with a ;

  • Enter a descriptive text here. If your language is supported, you will notice that the description is in your native language. KFM can store multiple descriptions, one for each language. If you enter something here then it will be stored under your language. Application developers should make shure that at least a english description is available. How to do this was discussed one chapter before in the hackers section.

  • Enter the full name of the mime type.

  • You can select a default application here. This is of interest if multiple applications regsitered for the same mime type. If you click on such a data type file KFM makes a guess which app to use. By choosing a default app you can keep KFM away from guessing.

  • Select a icon. All icons are stored in $KDEDIR/share/icons. For every icon in this directory there exists a icon of the same name but half size in $KDEDIR/share/icons/mini. Usual icons have the size 32x32 and the mini icons 16x16.

  • Press the OK button.

Now KFM rescans all opened directories because the icons and stuff could have changed. You can force KFM manually to do so by choosing Rescan Bindings in the View menu. Your mime type is now registered and KFM should know about it.

Congratulations, you survived this lesson. Time for a break now :-)

3.2.4. Internals

The config files are very simple and of course human readable. You can have a look at it here:

 # KDE Config File
 [KDE Desktop Entry]
 Type=MimeType
 MimeType=image/gif
 Icon=image.xpm
 Patterns=*.gif;*.GIF;
 Comment=Gif images
 Comment[de]=GIF Dokument
 Comment[nl]=Gif afbeelding

You dont need to understand what this means, since KFM provides a GUI for you, that makes things much easier. Hackers never the less want to know and hack everything, so here is a brief description.

The first line is the header of every KDE config file. The Typeline is included in every KFM config file to distinguish the purpose of the config file. This is followed by the mime types name, the icon, a ; separated list of patterns and comments in english, german, ...

Now the hackers may leave this lesson.