f2a53632e0b77e16be1f3cfdc118dab642fc7fdf
[platform/upstream/atk.git] / atk / atkstreamablecontent.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2001 Sun Microsystems Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "atkstreamablecontent.h"
19
20 /**
21  * SECTION:atkstreamablecontent
22  * @Short_description: The ATK interface which provides access to
23  *  streamable content.
24  * @Title:AtkStreamableContent
25  *
26  * An interface whereby an object allows its backing content to be
27  * streamed to clients.  Typical implementors would be images or
28  * icons, HTML content, or multimedia display/rendering widgets.
29  *
30  * Negotiation of content type is allowed. Clients may examine the
31  * backing data and transform, convert, or parse the content in order
32  * to present it in an alternate form to end-users.
33  *
34  * The AtkStreamableContent interface is particularly useful for
35  * saving, printing, or post-processing entire documents, or for
36  * persisting alternate views of a document. If document content
37  * itself is being serialized, stored, or converted, then use of the
38  * AtkStreamableContent interface can help address performance
39  * issues. Unlike most ATK interfaces, this interface is not strongly
40  * tied to the current user-agent view of the a particular document,
41  * but may in some cases give access to the underlying model data.
42  */
43
44 GType
45 atk_streamable_content_get_type (void)
46 {
47   static GType type = 0;
48
49   if (!type) {
50     GTypeInfo tinfo =
51     {
52       sizeof (AtkStreamableContentIface),
53       (GBaseInitFunc) NULL,
54       (GBaseFinalizeFunc) NULL,
55
56     };
57
58     type = g_type_register_static (G_TYPE_INTERFACE, "AtkStreamableContent", &tinfo, 0);
59   }
60
61   return type;
62 }
63
64 /**
65  * atk_streamable_content_get_n_mime_types:
66  * @streamable: a GObject instance that implements AtkStreamableContentIface
67  *
68  * Gets the number of mime types supported by this object.
69  *
70  * Returns: a gint which is the number of mime types supported by the object.
71  **/
72 gint
73 atk_streamable_content_get_n_mime_types (AtkStreamableContent *streamable)
74 {
75   AtkStreamableContentIface *iface;
76
77   g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), 0);
78
79   iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
80
81   if (iface->get_n_mime_types)
82     return (iface->get_n_mime_types) (streamable);
83   else
84     return 0;
85 }
86
87 /**
88  * atk_streamable_content_get_mime_type:
89  * @streamable: a GObject instance that implements AtkStreamableContent
90  * @i: a gint representing the position of the mime type starting from 0
91  *
92  * Gets the character string of the specified mime type. The first mime
93  * type is at position 0, the second at position 1, and so on.
94  *
95  * Returns: a gchar* representing the specified mime type; the caller
96  * should not free the character string.
97  **/
98 const gchar*
99 atk_streamable_content_get_mime_type (AtkStreamableContent *streamable,
100                                       gint                 i)
101 {
102   AtkStreamableContentIface *iface;
103
104   g_return_val_if_fail (i >= 0, NULL);
105   g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
106
107   iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
108
109   if (iface->get_mime_type)
110     return (iface->get_mime_type) (streamable, i);
111   else
112     return NULL;
113 }
114
115 /**
116  * atk_streamable_content_get_stream:
117  * @streamable: a GObject instance that implements AtkStreamableContentIface
118  * @mime_type: a gchar* representing the mime type
119  *
120  * Gets the content in the specified mime type.
121  *
122  * Returns: (transfer full): A #GIOChannel which contains the content in the
123  * specified mime type.
124  **/
125 GIOChannel*
126 atk_streamable_content_get_stream (AtkStreamableContent *streamable,
127                                    const gchar          *mime_type)
128 {
129   AtkStreamableContentIface *iface;
130
131   g_return_val_if_fail (mime_type != NULL, NULL);
132   g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
133
134   iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
135
136   if (iface->get_stream)
137     return (iface->get_stream) (streamable, mime_type);
138   else
139     return NULL;
140 }
141
142 /**
143  * atk_streamable_content_get_uri:
144  * @streamable: a GObject instance that implements AtkStreamableContentIface
145  * @mime_type: a gchar* representing the mime type, or NULL to request a URI 
146  * for the default mime type.
147  *
148  * Get a string representing a URI in IETF standard format
149  * (see http://www.ietf.org/rfc/rfc2396.txt) from which the object's content
150  * may be streamed in the specified mime-type, if one is available.
151  * If mime_type is NULL, the URI for the default (and possibly only) mime-type is
152  * returned. 
153  *
154  * Note that it is possible for get_uri to return NULL but for
155  * get_stream to work nonetheless, since not all GIOChannels connect to URIs.
156  *
157  * Returns:  Returns a string representing a URI, or NULL if no corresponding URI
158  * can be constructed.
159  *
160  * Since: 1.12
161  **/
162 const gchar*
163 atk_streamable_content_get_uri (AtkStreamableContent *streamable,
164                                 const gchar          *mime_type)
165 {
166   AtkStreamableContentIface *iface;
167
168   g_return_val_if_fail (mime_type != NULL, NULL);
169   g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
170
171   iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
172
173   if (iface->get_uri)
174     return (iface->get_uri) (streamable, mime_type);
175   else
176     return NULL;
177 }