Revert "Merge remote-tracking branch 'origin/sandbox/mniesluchow/upstream_2_16' into...
[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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "atkstreamablecontent.h"
21
22 /**
23  * SECTION:atkstreamablecontent
24  * @Short_description: The ATK interface which provides access to
25  *  streamable content.
26  * @Title:AtkStreamableContent
27  *
28  * An interface whereby an object allows its backing content to be
29  * streamed to clients.  Typical implementors would be images or
30  * icons, HTML content, or multimedia display/rendering widgets.
31  *
32  * Negotiation of content type is allowed. Clients may examine the
33  * backing data and transform, convert, or parse the content in order
34  * to present it in an alternate form to end-users.
35  *
36  * The AtkStreamableContent interface is particularly useful for
37  * saving, printing, or post-processing entire documents, or for
38  * persisting alternate views of a document. If document content
39  * itself is being serialized, stored, or converted, then use of the
40  * AtkStreamableContent interface can help address performance
41  * issues. Unlike most ATK interfaces, this interface is not strongly
42  * tied to the current user-agent view of the a particular document,
43  * but may in some cases give access to the underlying model data.
44  */
45
46 GType
47 atk_streamable_content_get_type (void)
48 {
49   static GType type = 0;
50
51   if (!type) {
52     GTypeInfo tinfo =
53     {
54       sizeof (AtkStreamableContentIface),
55       (GBaseInitFunc) NULL,
56       (GBaseFinalizeFunc) NULL,
57
58     };
59
60     type = g_type_register_static (G_TYPE_INTERFACE, "AtkStreamableContent", &tinfo, 0);
61   }
62
63   return type;
64 }
65
66 /**
67  * atk_streamable_content_get_n_mime_types:
68  * @streamable: a GObject instance that implements AtkStreamableContentIface
69  *
70  * Gets the number of mime types supported by this object.
71  *
72  * Returns: a gint which is the number of mime types supported by the object.
73  **/
74 gint
75 atk_streamable_content_get_n_mime_types (AtkStreamableContent *streamable)
76 {
77   AtkStreamableContentIface *iface;
78
79   g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), 0);
80
81   iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
82
83   if (iface->get_n_mime_types)
84     return (iface->get_n_mime_types) (streamable);
85   else
86     return 0;
87 }
88
89 /**
90  * atk_streamable_content_get_mime_type:
91  * @streamable: a GObject instance that implements AtkStreamableContent
92  * @i: a gint representing the position of the mime type starting from 0
93  *
94  * Gets the character string of the specified mime type. The first mime
95  * type is at position 0, the second at position 1, and so on.
96  *
97  * Returns: a gchar* representing the specified mime type; the caller
98  * should not free the character string.
99  **/
100 const gchar*
101 atk_streamable_content_get_mime_type (AtkStreamableContent *streamable,
102                                       gint                 i)
103 {
104   AtkStreamableContentIface *iface;
105
106   g_return_val_if_fail (i >= 0, NULL);
107   g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
108
109   iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
110
111   if (iface->get_mime_type)
112     return (iface->get_mime_type) (streamable, i);
113   else
114     return NULL;
115 }
116
117 /**
118  * atk_streamable_content_get_stream:
119  * @streamable: a GObject instance that implements AtkStreamableContentIface
120  * @mime_type: a gchar* representing the mime type
121  *
122  * Gets the content in the specified mime type.
123  *
124  * Returns: (transfer full): A #GIOChannel which contains the content in the
125  * specified mime type.
126  **/
127 GIOChannel*
128 atk_streamable_content_get_stream (AtkStreamableContent *streamable,
129                                    const gchar          *mime_type)
130 {
131   AtkStreamableContentIface *iface;
132
133   g_return_val_if_fail (mime_type != NULL, NULL);
134   g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
135
136   iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
137
138   if (iface->get_stream)
139     return (iface->get_stream) (streamable, mime_type);
140   else
141     return NULL;
142 }
143
144 /**
145  * atk_streamable_content_get_uri:
146  * @streamable: a GObject instance that implements AtkStreamableContentIface
147  * @mime_type: a gchar* representing the mime type, or NULL to request a URI 
148  * for the default mime type.
149  *
150  * Get a string representing a URI in IETF standard format
151  * (see http://www.ietf.org/rfc/rfc2396.txt) from which the object's content
152  * may be streamed in the specified mime-type, if one is available.
153  * If mime_type is NULL, the URI for the default (and possibly only) mime-type is
154  * returned. 
155  *
156  * Note that it is possible for get_uri to return NULL but for
157  * get_stream to work nonetheless, since not all GIOChannels connect to URIs.
158  *
159  * Returns:  Returns a string representing a URI, or NULL if no corresponding URI
160  * can be constructed.
161  *
162  * Since: 1.12
163  **/
164 const gchar*
165 atk_streamable_content_get_uri (AtkStreamableContent *streamable,
166                                 const gchar          *mime_type)
167 {
168   AtkStreamableContentIface *iface;
169
170   g_return_val_if_fail (mime_type != NULL, NULL);
171   g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
172
173   iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
174
175   if (iface->get_uri)
176     return (iface->get_uri) (streamable, mime_type);
177   else
178     return NULL;
179 }