Sun Java Solaris Communities My SDN Account Join SDN

Article

Integrating Applications Into the GNOME 2.0 Desktop

 
By Stephen Browne, Calum Benson, and Gary Little, October 2002  

Overview


GNOME 2.0 Desktop is now available for the Solaris Operating System. Developed by the open source, free software community, which includes Sun itself, GNOME is considered very easy to use and very easy to configure. This makes it a compelling choice for end users who are perhaps growing a bit weary of the Common Desktop Environment they've been using for the past few years.

Sun is scheduled to provide GNOME 2.0 for the Solaris 8 OE or later versions, as well as for the recently announced Sun Linux. Plans are to offer it initially as a free download, and later provide it rolled into Solaris OE media kits and preinstalled on Sun workstations. You can download GNOME 2.0 for the Solaris OE from sun.com:
http://www.sun.com/gnome/.

This article provides practical advice to application developers on how to make their software fit seamlessly into the GNOME desktop environment. This is not difficult to do and does not require changing an application's source code -- in fact, one of the major benefits of GNOME is that it runs existing CDE/Motif and Java technology-based applications. All that is required is the creation of a handful of data files that an installer can move to certain specific locations in the file system hierarchy. Once you've done this, a launcher for an application will appear in GNOME's Applications menu, the Nautilus file manager will use the appropriate icons for the application and the documents it creates, and double-clicking an application's document icon will launch the application.

Note that this document assumes that GNOME 2.0 is installed in the / (root) directory. If it is installed elsewhere, change all directory references to the actual installation directory. A quick way to determine the actual GNOME directory, assuming GNOME is currently running, is to do a "which gnome-session", then take the result and parse the prefix for the bin/ directory in which gnome-session is located.

How Do I Integrate My Application Within the GNOME 2.0 Desktop?


There are three things you need to do to have GNOME recognize your application:

  1. Add a menu entry for launching your application.
  2. Add a MIME type sniffer/file name association for any new MIME types and provide human-readable names for your MIME types.
  3. Add a MIME type binding between your application and the MIME type(s) it handles.

1) Adding a New Menu Entry for Your Application


To have your application appear in the GNOME Applications menu (located at the top left of the top panel), you need to write an application-specific '.desktop' file; and install it in the correct location.

The full format of this file is defined as the Desktop Entry Standard on the freedesktop.org web site:
http://freedesktop.org/Standards/desktop-entry-spec/desktop-entry- spec-0.9.4.html

The most basic information you need to specify in your application's .desktop file are the following fields:

Name=<this is the name you wish to appear in the menu for the c locale>
Comment=<this is the text you wish to appear in the menu entry tooltip>
Exec=<this is the executable name for your application, with optional arguments>
TryExec=<this is the executable used to tell whether your application is installed>
Terminal=<true|false - this defines if your application needs to be run in a terminal>
Type=<this is the .desktop file type - you should use application>
Icon=<name of application icon file>
Categories=<this is a semi-colon ';' separated list of categories used to define the submenu(s) that the menu entry appears in>

The Name and Comment field should have translated entries associated with the locale.

Name[ca]=<this is the translated name for the ca locale>
Name[es]=<this is the translated name for the es locale>
Comment[ca]=<this is the translated tooltip for the ca locale>
(and so on)

The icon referred to in the Icon field must be stored in the /usr/share/pixmaps/ directory. The recommended size is 48x48 pixels. (For user installations -- that is, not root installations -- the icon should be placed in the ~/.icons/gnome/<size>/apps/ directory, where <size> represents the dimensions of the icon, for example, 48x48.)

GNOME also supports several icon themes for users with special visual needs; application icons crafted for these themes should be placed in the following directories:

/usr/share/icons/HighContrast/<size>/apps/
/usr/share/icons/HighContrastInverse/<size>/apps/
/usr/share/icons/HighContrastLargePrint/<size>/apps/
/usr/share/icons/HighContrastLargePrintInverse/<size>/apps/
/usr/share/icons/LargePrint/<size>/apps/
/usr/share/icons/LowContrast/<size>/apps/
/usr/share/icons/LowContrastLargePrint/<size>/apps/

In this case, <size> represents the dimensions of the icon. It is recommended that you supply 16x16 and 48x48 icons for these themes. (For user installations, the icons should be placed in the subdirectories of ~/.icons/gnome/ rather than /usr/share/icons/.)

Use the Categories section to define where you want the menu entry to go. For example, use Categories=Application;System; for system utilities, or use Categories=Application;Game; for games.

See the file /etc/gnome/gnome-vfs-2.0/vfolders/applications-all-users.vfolder-info for the system definition of the menu structure and how it uses these category keywords.

Once you have defined this simple file, you need to install it to:

/usr/share/applications/

This is the default location for application .desktop files. (For user installations, put the file in the ~/.gnome2/vfolders/applications/ directory.)

Here is an example of the Eye of GNOME application .desktop file. The translated names and comments have been stripped out. Notice the %U argument on the Exec line; it means that the application will accept one or more URLs passed to it. Another common argument is %F, which means one or more files. Specifying these arguments allows a user to open documents by dragging and dropping them on a launcher that was created by dragging the item in the Applications menu hierarchy corresponding to your .desktop file to a panel or to the desktop.

------eog.desktop---------------------------
[Desktop Entry]
Name=Eye of Gnome Image Viewer
Comment=View many different types of images
Exec=eog %U
TryExec=eog
Icon=gnome-eog.png
Terminal=false
Type=Application
Categories=GNOME;Application;Graphics;RasterGraphics;Viewer;
-------------------------------------------

2) Add a MIME Type Sniffer/File Name Association for Any New MIME Types


It is important that the GNOME MIME type registry knows about your application and the MIME types it can handle. This is so that the Nautilus file manager can detect the file types, display a descriptive string for it, use an appropriate icon to represent it in a folder view, and offer the user a default and extra list of applications to launch to edit/view this file type.

There are two ways you can specify new file-to-MIME-type associations in GNOME.

a) Provide a file content sniffer to identify the MIME type:

Take a look at the file /etc/gnome/gnome-vfs-mime-magic.

This file contains the default file content sniffers for identifying MIME types. Some good documentation of the file format is available in the header of the file, but here is a simple breakdown of the fields in each single line record:

  • The first column is the offset into the file that the sniffer should 'sniff' from.
  • The second column is the pattern type (currently, only string is supported).
  • The third column is the actual pattern the sniffer should look for.
  • The fourth column is the pattern mask (same length as the pattern).
  • And the final column is the name of the valid MIME type that should be associated with sniffed files that match this entry.

Here is an example of the GIF image file format sniffer:

0       string          GIF8               image/gif

So the sniffer looks for a pattern match of the string 'GIF8' right at the start of the file. There is no pattern mask, and the associated MIME type is image/gif.

b) Provide a file name pattern/extension detection of the MIME type:

If a file's MIME type is not identified by one of the sniffers described above, GNOME will then start looking at the following files to see if it can match the file name to a MIME type:

/usr/share/gnome/mime-info/*.mime

Again, there is some good documentation of the .mime file format at the top of the /usr/share/gnome/mime-info/gnome-vfs.mime file, but here is a short description:

mime-type
        ext:    list of extensions for this mime-type
        regex:  a regular expression that matches the filename

And here's an example:

audio/x-mp3
        ext: mp3

You must specify the ext or regex field (or both). Each can have multiple entries separated by space characters.

audio/x-real-audio
        ext: rm ra ram

New applications that handle new MIME types (that is, those not already defined) normally would create a new file '.mime' with the MIME type matcher and put it into the /usr/share/gnome/mime-info/ directory. For user installations, put the file in the ~/.gnome/mime-info/ directory. New applications don't generally add new file sniffers.

Just a note now on the priority of MIME type matching. The sniffers take priority over the file name/pattern matchers. The sniffer priority is determined by the order in which they appear in the file. The file name/pattern matchers are prioritized with an extra ,<prio> suffix to the ext or regex fields. See /usr/share/gnome/mime-info/gnome-vfs.mime for more information.

Once you have defined any new MIME types you handle and given GNOME some idea of how to detect them, you now need to provide human-readable names and an icon that should be associated with them. To do this, you need to create a '<myapp.keys>' file in the same /usr/share/gnome/mime-info/ directory. (For user installations, put the file in the ~/.gnome/mime-info/ directory.)

The file format is similar to the .mime file with a mime-type and then a list of tab-indented key-value pairs.

For example:

application/x-myapp-file:
        description=Myapp data file
        icon_filename=i-myappdata.png
        default_action_type=application
        short_list_application_ids_for_novice_user_level=myapp
        category=Documents/Diagram

This entry defines an association between the mime type application/x-myapp-file and a human-readable description, an icon, the default application to use when the icon is double clicked in the file manager, and a MIME type category.

The icon referred to in the icon_filename field must be stored in the /usr/share/pixmaps/document-icons/ directory. The recommended size is 48x48 pixels. (For user installations, put the icon file in the ~/.icons/gnome/<size>/mimetypes/ directory, where <size> represents the dimensions of the icon, for example, 48x48.)

GNOME also supports several icon themes for users with special visual needs; MIME type icons crafted for these themes should be placed in the following directories:

 
  /usr/share/icons/HighContrast/<size>/mimetypes/
  /usr/share/icons/HighContrastInverse/<size>/mimetypes/
  /usr/share/icons/HighContrastLargePrint/<size>/mimetypes/
  /usr/share/icons/HighContrastLargePrintInverse/<size>/mimetypes/
  /usr/share/icons/LargePrint/<size>/mimetypes/
  /usr/share/icons/LowContrast/<size>/mimetypes/
  /usr/share/icons/LowContrastLargePrint/<size>/mimetypes/

In this case, <size> represents the dimensions of the icon. It is recommended that you supply 16x16 and 48x48 icons for these themes. (For user installations, the icons should be placed in the subdirectories of ~/.icons/gnome/ rather than /usr/share/icons/.)

The other values for default_action_type should be ignored unless you are writing Bonobo or Nautilus view components.

The short_list_application entry defines an application name that appears in the application registry, so you now need to create an entry for your application there as well.

The category entry allows the MIME type to be organized conveniently in the Files Types and Programs preferences panel. See this panel for the standard category names. Subcategory names can also be specified, separated from their parent category by a "/" character, as in the preceding example.

3) Add a MIME Type Binding Between Your Application and the MIME Types It Handles


Create a file called '.applications' and install it to /usr/share/gnome/application-registry. (For user installations, put the file in ~/.gnome/application-info/.)

Take a look at /usr/share/gnome/application-registry/gnome-vfs.applications for an example of the format of this file.

Here is the example for the eog (Eye of GNOME) image viewer application:

eog
        command=eog
        name=Eye of Gnome
        can_open_multiple_files=true
        expects_uris=false
        requires_terminal=false
        mime_types=image/bmp,image/gif,image/jpeg,image/png,
		image/tiff,im= age/x-xpixmap,image/x-bmp,image/x-png,image/
		x-portable-anymap,
image/x-porta=
ble-bitmap,image/x-portable-graymap,image/x-portable-pixmap

The first line is the application id in the registry (which is matched by short_list_application* entries in the .keys files).

The command field is the command line that should be used to invoke the application; here you may specify particular options that are required for opening files passed to the command line, and so on.

The name field is the human-readable name for the application that will appear in the Open With context menu in Nautilus.

The expects_uris field lets Nautilus know if your application can accept uris. For example, Netscape can accept http: ftp: etc uris to open at the command line. If expects_uris is true, then you should have a supported_uri_schemes entry to list the uri schemes your application supports.

The requires_terminal field is normally set to false although something like vi would need a terminal and would set this field to true.

The mime_types field lists the MIME-type names of all the file formats that the application can handle.

Summary and Example


This summary offers a really simple example for everyone who just got confused about all of the above.

And here are the steps to follow to integrate the application "Steve Viewer", which handles the MIME type "image/steve", with GNOME (assuming a root installation):

1) Install .desktop file

------steve-viewer.desktop----------
[Desktop Entry]
Name=Steve Viewer
Comment=View Steve image files
Exec=steve-viewer
TryExec=steve-viewer
Icon=steve-viewer.png
Terminal=false
Type=Application
Categories=Application;Graphics;
-----------------------------------

This file should be installed to /usr/share/applications/. Remember it is the Categories that you define that determine where in the menu structure your menu entry will appear.

This file alone will give GNOME users access to your application by means of the GNOME menu. If you do not install any new MIME types or need to tell GNOME about any MIME types you can handle, then you can stop here.

2) Install application icon

steve-viewer.png (mentioned in the .desktop file) should be installed to /usr/share/pixmaps/ and should be 48x48 pixels in size. As noted, you should also install other icons to support users with special visual needs.

3) Install .mime file

-------steve-viewer.mime------------
image/steve
        ext: steve stephen stv
------------------------------------

This file should be installed to /usr/share/gnome/mime-info/.

This file just defines the new MIME-type image/steve and makes an association to all files named *.steve, *.stephen, and *.stv.

4) Install .keys file


-------steve-viewer.keys------------
image/steve
        description=Steve Image file
        icon_filename=i-steve.png
        default_action=application
        short_list_application_ids_for_novice_user_level=steve-viewer
        category=Images
-----------------------------------

This file should be installed to /usr/share/gnome/mime-info/.

Here we now have some more human-consumable information about the new MIME-type, which Nautilus can use to display in its folder views.

5) Install file type icon


i-steve.png should be 48x48 pixels and installed to /usr/share/pixmaps/document-icons/. Icons crafted for themes designed for users with special visual needs should also be installed in the following locations:

  
  /usr/share/icons/HighContrast/<size>/mimetypes/
  /usr/share/icons/HighContrastInverse/<size>/mimetypes/
  /usr/share/icons/HighContrastLargePrint/<size>/mimetypes/
  /usr/share/icons/HighContrastLargePrintInverse/<size>/mimetypes/
  /usr/share/icons/LargePrint/<size>/mimetypes/
  /usr/share/icons/LowContrast/<size>/mimetypes/
  /usr/share/icons/LowContrastLargePrint/<size>/mimetypes/

As with application icons, file type icons for these themes should be provided in two sizes, 16x16 and 48x48.

6) Install .applications file


----steve-viewer.applications------
steve-viewer
        command=steve-viewer -f
        name=Steve Viewer
        expects_uris=false
        requires_terminal=false
        mime_types=image/steve
-----------------------------------

This file should be installed to /usr/share/gnome/application-registry/.

Now Nautilus will know all it needs to know to offer Steve Viewer as an application in the Open With menu, and combined with the preceding .keys file, it will know to use steve-viewer as the default application for the image/steve MIME-type.

Conclusion


And that's all there is to it! By supplying and installing the files described here, GNOME 2.0 Desktop users should be able to use applications much more effectively and productively. Although the integration process is fairly straightforward, we hope to provide a tool in the future that simplifies the creation and integration of all the necessary pieces.

About the Authors


Gary Little is a Product Line Manager for the GNOME 2.0 Desktop at Sun Microsystems. Calum Benson, a User Interface Designer, and Stephen Browne are on Sun's GNOME engineering team in Dublin, Ireland.

October 2002

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.