1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-mime.c - Test for the mime handler detection features of the GNOME
3 Virtual File System Library
5 Copyright (C) 2000 Eazel
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Author: Maciej Stachowiak <mjs@eazel.com>
27 #include <bonobo-activation/bonobo-activation.h>
28 #include <libgnomevfs/gnome-vfs-init.h>
29 #include <libgnomevfs/gnome-vfs-mime-handlers.h>
30 #include <libgnomevfs/gnome-vfs-mime-info.h>
35 append_comma_and_scheme (gpointer scheme,
40 string = (char **) user_data;
41 if (*string != NULL) {
43 tmp = g_strconcat (*string, ", ", scheme, NULL);
47 *string = g_strdup (scheme);
53 format_supported_uri_schemes_for_display (GList *supported_uri_schemes)
58 g_list_foreach (supported_uri_schemes,
59 append_comma_and_scheme,
65 format_mime_application_argument_type_for_display (GnomeVFSMimeApplicationArgumentType argument_type)
67 switch (argument_type) {
68 case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS:
71 case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_PATHS:
73 case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS_FOR_NON_FILES:
74 return "For non-files";
76 g_assert_not_reached ();
82 print_application (GnomeVFSMimeApplication *application)
84 if (application == NULL) {
89 uri_schemes = format_supported_uri_schemes_for_display (application->supported_uri_schemes),
90 printf ("name: %s\ncommand: %s\ncan_open_multiple_files: %s\nexpects_uris: %s\nsupported_uri_schemes: %s\nrequires_terminal: %s\n",
91 application->name, application->command,
92 (application->can_open_multiple_files ? "TRUE" : "FALSE"),
93 format_mime_application_argument_type_for_display (application->expects_uris),
95 (application->requires_terminal ? "TRUE" : "FALSE"));
101 print_component (Bonobo_ServerInfo *component)
103 if (component == NULL) {
106 printf ("iid: %s\n", component->iid);
111 print_action (GnomeVFSMimeAction *action)
113 if (action == NULL) {
116 if (action->action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION) {
117 puts ("type: application");
118 print_application (action->action.application);
120 puts ("type: component");
121 print_component (action->action.component);
128 print_component_list (GList *components)
131 if (components == NULL) {
134 for (p = components; p != NULL; p = p->next) {
135 print_component (p->data);
143 print_application_list (GList *applications)
146 if (applications == NULL) {
149 for (p = applications; p != NULL; p = p->next) {
150 print_application (p->data);
159 main (int argc, char **argv)
162 GnomeVFSMimeApplication *default_application;
163 Bonobo_ServerInfo *default_component;
164 GnomeVFSMimeAction *default_action;
165 const char *description;
166 GList *all_components;
167 GList *all_applications;
168 GList *short_list_components;
169 GList *short_list_applications;
173 fprintf (stderr, "Usage: %s mime_type\n", *argv);
179 if (!gnome_vfs_mime_type_is_known (type)) {
180 fprintf (stderr, "Unknown mime type: %s\n", type);
184 description = gnome_vfs_mime_get_description (type);
185 printf ("Description: %s\n", description);
187 default_action = gnome_vfs_mime_get_default_action (type);
188 puts ("Default Action");
189 print_action (default_action);
191 gnome_vfs_mime_action_free (default_action);
193 default_application = gnome_vfs_mime_get_default_application (type);
194 puts("Default Application");
195 print_application (default_application);
197 gnome_vfs_mime_application_free (default_application);
199 default_component = gnome_vfs_mime_get_default_component (type);
200 puts("Default Component");
201 print_component (default_component);
203 CORBA_free (default_component);
205 short_list_applications = gnome_vfs_mime_get_short_list_applications (type);
206 puts("Short List Applications");
207 print_application_list (short_list_applications);
209 gnome_vfs_mime_application_list_free (short_list_applications);
211 short_list_components = gnome_vfs_mime_get_short_list_components (type);
212 puts("Short List Components");
213 print_component_list (short_list_components);
215 gnome_vfs_mime_component_list_free (short_list_components);
217 all_applications = gnome_vfs_mime_get_all_applications (type);
218 puts("All Applications");
219 print_application_list (all_applications);
221 gnome_vfs_mime_application_list_free (all_applications);
223 all_components = gnome_vfs_mime_get_all_components (type);
224 puts("All Components");
225 print_component_list (all_components);
227 gnome_vfs_mime_component_list_free (all_components);
229 gnome_vfs_shutdown ();