After extracting a MIME type (for example, image/png ) from a URI or file, you can ask GNOME for more information about the type with these functions:
gboolean gnome_vfs_mime_type_is_known(const char * mime_type )
Returns TRUE if GNOME recognizes mime_type .
GnomeVFSMimeActionType gnome_vfs_mime_get_default_action_type(const char * mime_type )
Indicates how GNOME normally opens the type; the return value is one of the following:
GNOME_VFS_MIME_ACTION_TYPE_NONE : Undefined .
GNOME_VFS_MIME_ACTION_TYPE_APPLICATION : Opens the file with an application.
GNOME_VFS_MIME_ACTION_TYPE_COMPONENT : Opens the file with a component.
GnomeVFSMimeApplication *gnome_vfs_mime_get_default_application(const char * mime_type )
Returns a freshly allocated GnomeVFSMimeApplication structure containing the default application for mime_type . See the discussion that follows for more information on this structure.
GList *gnome_vfs_mime_get_short_list_applications(const char * mime_type )
Returns a list of GnomeVFSMimeApplication structures with the applications recommended for mime_type .
GList *gnome_vfs_mime_get_all_applications(const char * mime_type )
Returns a list of GnomeVFSMimeApplication structures with all applications that can handle mime_type .
const char *gnome_vfs_mime_get_icon(const char * mime_type )
Returns an icon name for mime_type . Do not attempt to deallocate or change the name.
Note | This is not a full path , just a name. If the icon is in several formats, the name does not include a suffix, and in that case, you should add your own, such as .png . The images are independent of your current Nautilus theme. |
const char *gnome_vfs_mime_get_description(const char * mime_type )
Returns a short description of mime_type . Do not attempt to deallocate or change the description string.
gboolean gnome_vfs_mime_can_be_executable(const char * mime_type )
Returns TRUE if you might be able to execute files of mime_type .
GnomeVFSMimeApplication structures fields include the following:
id ( char * ): The application identifier.
name ( char * ): The full application name.
command ( char * ): The application executable name.
can_open_multiple_files ( gboolean ): TRUE if the application can open more than one file at a time.
expects_uris ( GnomeVFSMimeApplicationArgumentType ): Indicates how the application expects command-line file parameters. Possible values include the following:
GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS
URIs only.
GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_PATHS
Local paths only.
GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS_FOR_NON_FILES
Local paths for local files; URIs for everything else.
supported_uri_schemes ( GList * ): The application's supported URI access modes ( http , ftp , and so on).
requires_terminal ( gboolean ): The application must run in a terminal window.
You can manage GnomeVFSMimeApplication with these utilities:
GnomeVFSMimeApplication *gnome_vfs_mime_application_copy(GnomeVFSMimeApplication * application )
Returns a copy of application .
void gnome_vfs_mime_application_free(GnomeVFSMimeApplication * application )
Deallocates the memory for application .
void gnome_vfs_mime_application_list_free(GList * app_list )
Deallocates the memory for app_list and all applications inside.
gboolean gnome_vfs_mime_id_in_application_list(const char * id , GList * app_list )
Returns TRUE if the application for id is in app_list .
For GNOME to realize that your application supports a certain MIME type, you must declare the type and then declare the application. To declare the type, create $(PREFIX)/share/mime- info /name.mime , where name is your application identifier or application suite. For example, if your MiracleText program is part of MiracleOffice; your miracleoffice.mime file might look like this:
application/x-miracletext ext: mtx application/x-miraclecalc ext: mcl application/x-miracleoffice-plugin regex,2: ^miracle-.*-plugin.so$
Declarations start with a MIME type and end with an empty line, and ext: directives map a fixed file extension to the type. However, regex: directives try to match an entire filename to a regular expression.
The ,2 after regex in the preceding example specifies the priority level. Higher numbers mean higher priority; the default is 1.
In addition, the example makes sure that GNOME recognizes MiracleOffice plug-ins. Without the third rule, GNOME would recognize MiracleOffice plugins using the dynamic library declaration for .so in $(PREFIX)/share/mime-info/gnome-vfs.mime that reads like this:
application/x-shared-library ext: so
After declaring the type as described in Section 8.7.1, you can tell GNOME what application goes with the type. Enter this information into another configuration file, $(PREFIX)/share/mime-info/name.keys ; miracleoffice.keys might look like this:
application/x-miracletext category=Documents/Word Processor [de]category=Dokumente/Textverarbeitung [es]category=Documentos/Procesador de textos description=MiracleText document [de]description=MiracleText-Dokument [es]description=Documento de MiracleText icon_filename=miracletext-appicon.png default_action_type=application short_list_application_ids=miracletext use_category_default=no application/x-miraclecalc category=Documents/Spreadsheet [de]category=Dokumente/Tabellenkalkulation [es]category=Documentos/Hoja de calculo description=MiracleCalc spreadsheet [de]description=MiracleCalc-Arbeitsblatt [es]description=Hoja de clculo de MiracleCalc icon_filename=miraclecalc-appicon.png default_action_type=application short_list_application_ids=miraclecalc use_category_default=no application/x-miracleoffice-plugin category=System [de]category=System [es]category=Sistema description=MiracleOffice plugin library [de]description=MiracleCalc-Plugin-Bibliothek [es]description=Librera compartida de MiracleCalc icon_filename=miracle-pluginicon.png
The keys are as follows:
category : A category identifier that people can read. GNOME can sort MIME types according to the category; look in $(PREFIX)/share/mime-info/gnome-vfs.keys to see if it contains any that you can use.
description : A short description of the type.
icon_filename : The icon filename; do not include an extension if there are several versions of the file in different formats.
default_action_type : How GNOME should open the file ( application or component ).
short_list_application_ids : A comma-separated list of programs that the user should run to view the type.
use_category_default : If this is yes , GNOME opens the file type with the default category application. If the application is the only program that can open files of this particular type in the category, set this to no (for example, your default word processor document application may be OpenOffice, but it may not be able to open .mtx documents).
You can specify keys for different locales by placing the locale identifier in square brackets just before the key (for example, [es]category ). If you want intltool to do the work for you, do the following:
Add a .in extension to your .keys file.
Place an underscore before each key to translate in your .keys.in file.
Add your .keys.in filename to po/POTFILES.in .
Add directives to your top-level Makefile.am :
keysdir = $(datadir)/mime-info keys_in_files = miracleoffice.keys.in keys_DATA = $(keys_in_files:.keys.in=.keys) @INTLTOOL_KEYS_RULE@
Generate your Makefiles; then regenerate your .pot file.
Add the appropriate lines to your .po files.