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 | |
---|
34 | |
---|
35 | static void |
---|
36 | print_application (GnomeVFSMimeApplication *application) |
---|
37 | { |
---|
38 | if (application == NULL) { |
---|
39 | puts ("(none)"); |
---|
40 | } else { |
---|
41 | printf ("name: %s\ncommand: %s\ncan_open_multiple_files: %s\ncan_open_uris: %s\nrequires_terminal: %s\n", |
---|
42 | application->name, application->command, |
---|
43 | (application->can_open_multiple_files ? "TRUE" : "FALSE"), |
---|
44 | (application->can_open_uris ? "TRUE" : "FALSE"), |
---|
45 | (application->requires_terminal ? "TRUE" : "FALSE")); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | static void |
---|
50 | print_component (OAF_ServerInfo *component) |
---|
51 | { |
---|
52 | if (component == NULL) { |
---|
53 | puts ("(none)"); |
---|
54 | } else { |
---|
55 | printf ("iid: %s\n", component->iid); |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | static void |
---|
60 | print_action (GnomeVFSMimeAction *action) |
---|
61 | { |
---|
62 | if (action == NULL) { |
---|
63 | puts ("(none)"); |
---|
64 | } else { |
---|
65 | if (action->action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION) { |
---|
66 | puts ("type: application"); |
---|
67 | print_application (action->action.application); |
---|
68 | } else { |
---|
69 | puts ("type: component"); |
---|
70 | print_component (action->action.component); |
---|
71 | } |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | |
---|
76 | static void |
---|
77 | print_component_list (GList *components) |
---|
78 | { |
---|
79 | GList *p; |
---|
80 | if (components == NULL) { |
---|
81 | puts ("(none)"); |
---|
82 | } else { |
---|
83 | for (p = components; p != NULL; p = p->next) { |
---|
84 | print_component (p->data); |
---|
85 | puts ("------"); |
---|
86 | } |
---|
87 | |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | static void |
---|
92 | print_application_list (GList *applications) |
---|
93 | { |
---|
94 | GList *p; |
---|
95 | if (applications == NULL) { |
---|
96 | puts ("(none)"); |
---|
97 | } else { |
---|
98 | for (p = applications; p != NULL; p = p->next) { |
---|
99 | print_application (p->data); |
---|
100 | puts ("------"); |
---|
101 | } |
---|
102 | |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | int |
---|
108 | main (int argc, char **argv) |
---|
109 | { |
---|
110 | const char *type; |
---|
111 | GnomeVFSMimeApplication *default_application; |
---|
112 | OAF_ServerInfo *default_component; |
---|
113 | GnomeVFSMimeAction *default_action; |
---|
114 | GList *all_components; |
---|
115 | GList *all_applications; |
---|
116 | GList *short_list_components; |
---|
117 | GList *short_list_applications; |
---|
118 | |
---|
119 | oaf_init (argc, argv); |
---|
120 | gnome_vfs_init (); |
---|
121 | |
---|
122 | if (argc != 2) { |
---|
123 | fprintf (stderr, "Usage: %s mime_type\n", *argv); |
---|
124 | return 1; |
---|
125 | } |
---|
126 | |
---|
127 | type = argv[1]; |
---|
128 | |
---|
129 | default_action = gnome_vfs_mime_get_default_action (type); |
---|
130 | puts ("Default Action"); |
---|
131 | print_action (default_action); |
---|
132 | puts (""); |
---|
133 | |
---|
134 | default_application = gnome_vfs_mime_get_default_application (type); |
---|
135 | puts("Default Application"); |
---|
136 | print_application (default_application); |
---|
137 | puts (""); |
---|
138 | |
---|
139 | default_component = gnome_vfs_mime_get_default_component (type); |
---|
140 | puts("Default Component"); |
---|
141 | print_component (default_component); |
---|
142 | puts (""); |
---|
143 | |
---|
144 | short_list_applications = gnome_vfs_mime_get_short_list_applications (type); |
---|
145 | puts("Short List Applications"); |
---|
146 | print_application_list (short_list_applications); |
---|
147 | puts (""); |
---|
148 | |
---|
149 | short_list_components = gnome_vfs_mime_get_short_list_components (type); |
---|
150 | puts("Short List Components"); |
---|
151 | print_component_list (short_list_components); |
---|
152 | puts (""); |
---|
153 | |
---|
154 | all_applications = gnome_vfs_mime_get_all_applications (type); |
---|
155 | puts("All Applications"); |
---|
156 | print_application_list (all_applications); |
---|
157 | puts (""); |
---|
158 | |
---|
159 | all_components = gnome_vfs_mime_get_all_components (type); |
---|
160 | puts("All Components"); |
---|
161 | print_component_list (all_components); |
---|
162 | puts (""); |
---|
163 | |
---|
164 | return 0; |
---|
165 | } |
---|
166 | |
---|
167 | |
---|