source: trunk/third/gnome-vfs2/test/test-mime-handlers.c @ 20794

Revision 20794, 6.1 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20793, which included commits to RCS files with non-trunk default branches.
Line 
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
4
5   Copyright (C) 2000 Eazel
6
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.
11
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.
16
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.
21
22   Author: Maciej Stachowiak <mjs@eazel.com>
23*/
24
25#include <config.h>
26
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>
31#include <stdio.h>
32#include <string.h>
33
34static void
35append_comma_and_scheme (gpointer scheme,
36                         gpointer user_data)
37{
38        char **string;
39
40        string = (char **) user_data;
41        if (*string != NULL) {
42                char *tmp;             
43                tmp = g_strconcat (*string, ", ", scheme, NULL);
44                g_free (*string);
45                *string = tmp;
46        } else {
47                *string = g_strdup (scheme);
48        }
49}
50
51
52static char *
53format_supported_uri_schemes_for_display (GList *supported_uri_schemes)
54{
55        char *string;
56
57        string = NULL;
58        g_list_foreach (supported_uri_schemes,
59                        append_comma_and_scheme,
60                        &string);
61        return string;
62}
63
64static const char *
65format_mime_application_argument_type_for_display (GnomeVFSMimeApplicationArgumentType argument_type)
66{
67        switch (argument_type) {
68        case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS:
69                return "Always";
70                break;
71        case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_PATHS:
72                return "No";
73        case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS_FOR_NON_FILES:
74                return "For non-files";
75        default:
76                g_assert_not_reached ();
77        }
78        return NULL;
79}
80
81static void
82print_application (GnomeVFSMimeApplication *application)
83{
84        if (application == NULL) {
85                puts ("(none)");
86        } else {
87                gchar *uri_schemes;
88
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),
94                        uri_schemes,
95                        (application->requires_terminal ? "TRUE" : "FALSE"));
96                g_free (uri_schemes);
97        }
98}
99
100static void
101print_component (Bonobo_ServerInfo *component)
102{
103        if (component == NULL) {
104                puts ("(none)");
105        } else {
106                printf ("iid: %s\n", component->iid);
107        }
108}
109
110static void
111print_action (GnomeVFSMimeAction *action)
112{
113        if (action == NULL) {
114                puts ("(none)");
115        } else {
116          if (action->action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION) {
117                puts ("type: application");
118                print_application (action->action.application);
119          } else {
120                puts ("type: component");
121                print_component (action->action.component);
122          }
123        }
124}
125
126
127static void
128print_component_list (GList *components)
129{
130       GList *p;
131       if (components == NULL) {
132         puts ("(none)");
133       } else {
134         for (p = components; p != NULL; p = p->next) {
135           print_component (p->data);
136           puts ("------");
137         }
138         
139       }
140}
141
142static void
143print_application_list (GList *applications)
144{
145       GList *p;
146       if (applications == NULL) {
147         puts ("(none)");
148       } else {
149         for (p = applications; p != NULL; p = p->next) {
150           print_application (p->data);
151           puts ("------");
152         }
153         
154       }
155}
156
157
158int
159main (int argc, char **argv)
160{
161        char *type; 
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;
170
171        gnome_vfs_init ();
172        if (argc != 2) {
173               fprintf (stderr, "Usage: %s mime_type\n", *argv);
174               return 1;
175        }
176
177        type = argv[1];
178
179        if (!gnome_vfs_mime_type_is_known (type)) {
180                fprintf (stderr, "Unknown mime type: %s\n", type);
181                return 1;
182        }
183       
184        description = gnome_vfs_mime_get_description (type);
185        printf ("Description: %s\n", description);
186
187        default_action = gnome_vfs_mime_get_default_action (type);
188        puts ("Default Action");
189        print_action (default_action);
190        puts ("");
191        gnome_vfs_mime_action_free (default_action);
192
193        default_application = gnome_vfs_mime_get_default_application (type);
194        puts("Default Application");
195        print_application (default_application);
196        puts ("");
197        gnome_vfs_mime_application_free (default_application);
198               
199        default_component = gnome_vfs_mime_get_default_component (type);
200        puts("Default Component");
201        print_component (default_component);
202        puts ("");
203        CORBA_free (default_component);
204
205        short_list_applications = gnome_vfs_mime_get_short_list_applications (type);
206        puts("Short List Applications");
207        print_application_list (short_list_applications);
208        puts ("");
209        gnome_vfs_mime_application_list_free (short_list_applications);
210
211        short_list_components = gnome_vfs_mime_get_short_list_components (type);
212        puts("Short List Components");
213        print_component_list (short_list_components);
214        puts ("");
215        gnome_vfs_mime_component_list_free (short_list_components);
216
217        all_applications = gnome_vfs_mime_get_all_applications (type);
218        puts("All Applications");
219        print_application_list (all_applications);
220        puts ("");
221        gnome_vfs_mime_application_list_free (all_applications);
222
223        all_components = gnome_vfs_mime_get_all_components (type);
224        puts("All Components");
225        print_component_list (all_components);
226        puts ("");
227        gnome_vfs_mime_component_list_free (all_components);
228
229        gnome_vfs_shutdown ();
230        return 0;
231}
232
233
Note: See TracBrowser for help on using the repository browser.