initCommon(); $template->displayHeader(); ?>

Chapter 7. Adding Applications to the Menus

If you want users to be able to find your application, you need to add it to the Main Menu. The Main Menu in GNOME and KDE are generated from the same desktop files so that they have the same menus. This feature is useful because only one desktop file needs to be installed. The desktop file must be installed in the /usr/share/applications/ directory, must have a specific format, and must be in UTF-8 format. For example:

[Desktop Entry]
Name=System Logs
Name[it]=Log di sistema
Comment=Examine system log files
Comment[it]=Esaminare i file di log di sistema
Categories=Application;System;X-Red-Hat-Base;
Icon=/usr/share/pixmaps/redhat-logviewer.png
Exec=/usr/bin/redhat-logviewer
Type=Application
Terminal=false
Encoding=UTF-8

This example does not show all translations of the name and comment, but you can see the format of the file and translations from it. The Categories field specifies which menu group the application should appear under. In this example, the entry is under System Tools.

The file should follow the specification outlined at http://www.freedesktop.org/standards/desktop-entry-spec/. The Categories field is used as described in the specification at http://www.freedesktop.org/standards/menu-spec/, though Fedora Core doesn't yet use the XML format described in that spec.

If you are not sure your desktop file is written correctly, install the desktop-file-utils package. This package contains the command desktop-file-validate. To use it, execute the command followed by the location of your desktop file. If the file contains all the required fields, the command will return nothing; otherwise, it will return an error message. For example, the following error message is displayed if the Encoding field is missing:

Error, file /tmp/redhat-logviewer.desktop does not contain the "Encoding"
key. This is a required field for all desktop files.

Save the file as application-name.desktop, such as redhat-logviewer.desktop, and the following to the spec file under the %files section:

%attr(0644,root,root) %{_datadir}/applications/%{name}.desktop

Also add the following line to the install section of the Makefile to to make sure it is installed in the correct place:

install ${PKGNAME}.desktop $(INSTROOT)/usr/share/applications/${PKGNAME}.desktop

If an upstream package already comes with a .desktop file that installs to /usr/share/applications/, you may not need to do anything (especially because Fedora Core uses mostly the same menu layout as upstream GNOME). However, if you need to modify the upstream .desktop file, the desktop-file-utils package contains a tool called desktop-file-install. This tool can be used in the %install section of an RPM to munge the upstream .desktop file in various ways. Here is an example from gnome-system-monitor:

      
        desktop-file-install --vendor gnome --delete-original       \
          --dir $RPM_BUILD_ROOT%{_datadir}/applications             \
          --add-category X-Red-Hat-Base                             \
          $RPM_BUILD_ROOT%{_datadir}/applications/*
       
     

In the above example, the following changes are made:

In addition to letting you add/remove categories and so forth, desktop-file-install will automatically validate the .desktop file.

7.1. Red Hat Categories

There are two special categories, X-Red-Hat-Base and X-Red-Hat-Extra. These distinguish between menu items that appear in the base menus, and those that appear in the "More Foo" menus. For example, the "Internet" and "More Internet Applications" menus. The rule is that only one application of a given class of application may have the X-Red-Hat-Base category. For example, one and only one web browser may be in "Internet", other web browsers must be in "More Internet Applications." As a secondary rule, "geeky" or obscure applications may always be in the X-Red-Hat-Extra category. Essentially, the X-Red-Hat-Base should be reserved for a nice set of default applications for nontechnical end users.

The best guideline: use X-Red-Hat-Extra by default, and if you want to use X-Red-Hat-Base, make your case on .

displayFooter('$Date: 2005/12/06 19:37:03 $'); ?>