source: trunk/third/gnome-vfs/test/test-mime-handlers.c @ 15858

Revision 15858, 5.4 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15857, which included commits to RCS files with non-trunk default branches.
RevLine 
[15496]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#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include "gnome-vfs.h"
29#include "gnome-vfs-mime-handlers.h"
30
31#include <stdio.h>
32#include <string.h>
33
[15857]34static void
35append_comma_and_scheme (gpointer scheme,
36                         gpointer user_data)
37{
38        char **string;
[15496]39
[15857]40        string = (char **) user_data;
41        if (strlen (*string) > 0) {
42                *string = g_strconcat (*string, ", ", scheme, NULL);
43        }
44        else {
45                *string = g_strdup (scheme);
46        }
47}
48
49
50static char *
51format_supported_uri_schemes_for_display (GList *supported_uri_schemes)
52{
53        char *string;
54
55        string = g_strdup ("");
56        g_list_foreach (supported_uri_schemes,
57                        append_comma_and_scheme,
58                        &string);
59        return string;
60}
61
62static const char *
63format_mime_application_argument_type_for_display (GnomeVFSMimeApplicationArgumentType argument_type)
64{
65        switch (argument_type) {
66        case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS:
67                return "Always";
68                break;
69        case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_PATHS:
70                return "No";
71        case GNOME_VFS_MIME_APPLICATION_ARGUMENT_TYPE_URIS_FOR_NON_FILES:
72                return "For non-files";
73        default:
74                g_assert_not_reached ();
75        }
76        return NULL;
77}
78
[15496]79static void
80print_application (GnomeVFSMimeApplication *application)
81{
82        if (application == NULL) {
83                puts ("(none)");
84        } else {
[15857]85                printf ("name: %s\ncommand: %s\ncan_open_multiple_files: %s\nexpects_uris: %s\nsupported_uri_schemes: %s\nrequires_terminal: %s\n",
[15496]86                        application->name, application->command,
87                        (application->can_open_multiple_files ? "TRUE" : "FALSE"),
[15857]88                        format_mime_application_argument_type_for_display (application->expects_uris),
89                        format_supported_uri_schemes_for_display (application->supported_uri_schemes),
[15496]90                        (application->requires_terminal ? "TRUE" : "FALSE"));
91        }
92}
93
94static void
95print_component (OAF_ServerInfo *component)
96{
97        if (component == NULL) {
98                puts ("(none)");
99        } else {
100                printf ("iid: %s\n", component->iid);
101        }
102}
103
104static void
105print_action (GnomeVFSMimeAction *action)
106{
107        if (action == NULL) {
108                puts ("(none)");
109        } else {
110          if (action->action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION) {
111                puts ("type: application");
112                print_application (action->action.application);
113          } else {
114                puts ("type: component");
115                print_component (action->action.component);
116          }
117        }
118}
119
120
121static void
122print_component_list (GList *components)
123{
124       GList *p;
125       if (components == NULL) {
126         puts ("(none)");
127       } else {
128         for (p = components; p != NULL; p = p->next) {
129           print_component (p->data);
130           puts ("------");
131         }
132         
133       }
134}
135
136static void
137print_application_list (GList *applications)
138{
139       GList *p;
140       if (applications == NULL) {
141         puts ("(none)");
142       } else {
143         for (p = applications; p != NULL; p = p->next) {
144           print_application (p->data);
145           puts ("------");
146         }
147         
148       }
149}
150
151
152int
153main (int argc, char **argv)
154{
155        const char *type; 
156        GnomeVFSMimeApplication *default_application;
157        OAF_ServerInfo *default_component;
158        GnomeVFSMimeAction *default_action;
[15857]159        const char *description;
[15496]160        GList *all_components;
161        GList *all_applications;
162        GList *short_list_components;
163        GList *short_list_applications;
164
165        oaf_init (argc, argv);
166        gnome_vfs_init ();
167
168        if (argc != 2) {
169                fprintf (stderr, "Usage: %s mime_type\n", *argv);
170                return 1;
171        }
172
173        type = argv[1];
174       
[15857]175        description = gnome_vfs_mime_get_description (type);
176        printf ("Description: %s\n", description);
177
178
[15496]179        default_action = gnome_vfs_mime_get_default_action (type);
180        puts ("Default Action");
181        print_action (default_action);
182        puts ("");
183
184        default_application = gnome_vfs_mime_get_default_application (type);
185        puts("Default Application");
186        print_application (default_application);
187        puts ("");
188               
189        default_component = gnome_vfs_mime_get_default_component (type);
190        puts("Default Component");
191        print_component (default_component);
192        puts ("");
193
194        short_list_applications = gnome_vfs_mime_get_short_list_applications (type);
195        puts("Short List Applications");
196        print_application_list (short_list_applications);
197        puts ("");
198
199        short_list_components = gnome_vfs_mime_get_short_list_components (type);
200        puts("Short List Components");
201        print_component_list (short_list_components);
202        puts ("");
203
204        all_applications = gnome_vfs_mime_get_all_applications (type);
205        puts("All Applications");
206        print_application_list (all_applications);
207        puts ("");
208
209        all_components = gnome_vfs_mime_get_all_components (type);
210        puts("All Components");
211        print_component_list (all_components);
212        puts ("");
213
214        return 0;
215}
216
217
Note: See TracBrowser for help on using the repository browser.