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 "config.h"
21

            
22
#include "atkstreamablecontent.h"
23

            
24
/**
25
 * AtkStreamableContent:
26
 *
27
 * The ATK interface which provides access to streamable content.
28
 *
29
 * An interface whereby an object allows its backing content to be
30
 * streamed to clients.  Typical implementors would be images or
31
 * icons, HTML content, or multimedia display/rendering widgets.
32
 *
33
 * Negotiation of content type is allowed. Clients may examine the
34
 * backing data and transform, convert, or parse the content in order
35
 * to present it in an alternate form to end-users.
36
 *
37
 * The AtkStreamableContent interface is particularly useful for
38
 * saving, printing, or post-processing entire documents, or for
39
 * persisting alternate views of a document. If document content
40
 * itself is being serialized, stored, or converted, then use of the
41
 * AtkStreamableContent interface can help address performance
42
 * issues. Unlike most ATK interfaces, this interface is not strongly
43
 * tied to the current user-agent view of the a particular document,
44
 * but may in some cases give access to the underlying model data.
45
 */
46

            
47
GType
48
atk_streamable_content_get_type (void)
49
{
50
  static GType type = 0;
51

            
52
  if (!type)
53
    {
54
      GTypeInfo tinfo = {
55
        sizeof (AtkStreamableContentIface),
56
        (GBaseInitFunc) NULL,
57
        (GBaseFinalizeFunc) NULL,
58

            
59
      };
60

            
61
      type = g_type_register_static (G_TYPE_INTERFACE, "AtkStreamableContent", &tinfo, 0);
62
    }
63

            
64
  return type;
65
}
66

            
67
/**
68
 * atk_streamable_content_get_n_mime_types:
69
 * @streamable: a GObject instance that implements AtkStreamableContentIface
70
 *
71
 * Gets the number of mime types supported by this object.
72
 *
73
 * Returns: a gint which is the number of mime types supported by the object.
74
 **/
75
gint
76
atk_streamable_content_get_n_mime_types (AtkStreamableContent *streamable)
77
{
78
  AtkStreamableContentIface *iface;
79

            
80
  g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), 0);
81

            
82
  iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
83

            
84
  if (iface->get_n_mime_types)
85
    return (iface->get_n_mime_types) (streamable);
86
  else
87
    return 0;
88
}
89

            
90
/**
91
 * atk_streamable_content_get_mime_type:
92
 * @streamable: a GObject instance that implements AtkStreamableContent
93
 * @i: a gint representing the position of the mime type starting from 0
94
 *
95
 * Gets the character string of the specified mime type. The first mime
96
 * type is at position 0, the second at position 1, and so on.
97
 *
98
 * Returns: a gchar* representing the specified mime type; the caller
99
 * should not free the character string.
100
 **/
101
const gchar *
102
atk_streamable_content_get_mime_type (AtkStreamableContent *streamable,
103
                                      gint i)
104
{
105
  AtkStreamableContentIface *iface;
106

            
107
  g_return_val_if_fail (i >= 0, NULL);
108
  g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
109

            
110
  iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
111

            
112
  if (iface->get_mime_type)
113
    return (iface->get_mime_type) (streamable, i);
114
  else
115
    return NULL;
116
}
117

            
118
/**
119
 * atk_streamable_content_get_stream:
120
 * @streamable: a GObject instance that implements AtkStreamableContentIface
121
 * @mime_type: a gchar* representing the mime type
122
 *
123
 * Gets the content in the specified mime type.
124
 *
125
 * Returns: (transfer full): A #GIOChannel which contains the content in the
126
 * specified mime type.
127
 **/
128
GIOChannel *
129
atk_streamable_content_get_stream (AtkStreamableContent *streamable,
130
                                   const gchar *mime_type)
131
{
132
  AtkStreamableContentIface *iface;
133

            
134
  g_return_val_if_fail (mime_type != NULL, NULL);
135
  g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
136

            
137
  iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
138

            
139
  if (iface->get_stream)
140
    return (iface->get_stream) (streamable, mime_type);
141
  else
142
    return NULL;
143
}
144

            
145
/**
146
 * atk_streamable_content_get_uri:
147
 * @streamable: a GObject instance that implements AtkStreamableContentIface
148
 * @mime_type: a gchar* representing the mime type, or NULL to request a URI
149
 * for the default mime type.
150
 *
151
 * Get a string representing a URI in IETF standard format
152
 * (see http://www.ietf.org/rfc/rfc2396.txt) from which the object's content
153
 * may be streamed in the specified mime-type, if one is available.
154
 * If mime_type is NULL, the URI for the default (and possibly only) mime-type is
155
 * returned.
156
 *
157
 * Note that it is possible for get_uri to return NULL but for
158
 * get_stream to work nonetheless, since not all GIOChannels connect to URIs.
159
 *
160
 * Returns: (nullable): Returns a string representing a URI, or %NULL
161
 * if no corresponding URI can be constructed.
162
 *
163
 * Since: 1.12
164
 **/
165
const gchar *
166
atk_streamable_content_get_uri (AtkStreamableContent *streamable,
167
                                const gchar *mime_type)
168
{
169
  AtkStreamableContentIface *iface;
170

            
171
  g_return_val_if_fail (mime_type != NULL, NULL);
172
  g_return_val_if_fail (ATK_IS_STREAMABLE_CONTENT (streamable), NULL);
173

            
174
  iface = ATK_STREAMABLE_CONTENT_GET_IFACE (streamable);
175

            
176
  if (iface->get_uri)
177
    return (iface->get_uri) (streamable, mime_type);
178
  else
179
    return NULL;
180
}