2008-05-28 Mark Doffman <mark.doffman@codethink.co.uk>
[platform/core/uifw/at-spi2-atk.git] / tests / dummyatk / my-atk-streamable-content.c
1 #include <atk/atk.h>
2
3 #include "my-atk-streamable-content.h"
4
5 //*************************implementation***********************
6 //implementation of virtual functions
7 //*****************get_n_mime_types************
8 static gint my_atk_streamable_content_get_n_mime_types(
9     AtkStreamableContent *streamable)
10 {
11     g_return_val_if_fail(MY_IS_ATK_STREAMABLE_CONTENT(streamable), 0);
12     
13     return sizeof(mime_types) / sizeof(mime_types[0]);
14 }
15 //*****************get_mime_type****************
16 static const gchar* my_atk_streamable_content_get_mime_type(
17     AtkStreamableContent *streamable,
18     gint i)
19 {
20     g_return_val_if_fail(MY_IS_ATK_STREAMABLE_CONTENT(streamable), NULL);
21     
22     if((i < 0) || (i >= sizeof(mime_types) / sizeof(mime_types[0])))
23     {
24         return NULL;
25     }
26     return mime_types[i];
27 }
28 //**********************get_stream*******************
29 static GIOChannel* my_atk_streamable_content_get_stream(
30     AtkStreamableContent *streamable,
31     const gchar* mime_type)
32 {
33     gint i;
34     g_return_val_if_fail(MY_IS_ATK_STREAMABLE_CONTENT(streamable), NULL);
35     
36     for(i = 0; i < sizeof(mime_types) / sizeof(mime_types[0]); i++)
37     {
38         if(strcmp(mime_type, mime_types[i]) == 0)
39         {
40             GError *error = NULL;
41             gchar* full_filename = T2C_GET_DATA_PATH(file_names[i]);
42             GIOChannel* channel = g_io_channel_new_file(full_filename, "r", &error);
43             if(error != NULL)
44             {
45                 TRACE("Cannot open file '%s' for read: %s", full_filename,
46                     error->message);
47                 g_error_free(error);
48             }
49             g_free(full_filename);
50             return channel;
51         }
52     }
53     return NULL;
54 }
55 //others functions
56 static void my_atk_streamable_content_interface_init(gpointer g_iface, gpointer iface_data)
57 {
58     AtkStreamableContentIface *klass = (AtkStreamableContentIface*)g_iface;
59     
60     klass->get_n_mime_types = my_atk_streamable_content_get_n_mime_types;
61     klass->get_mime_type = my_atk_streamable_content_get_mime_type;
62     klass->get_stream = my_atk_streamable_content_get_stream;
63 }
64
65 GType my_atk_streamable_content_get_type()
66 {
67     static GType type = 0;
68     if(type == 0)
69     {
70         static const GTypeInfo typeInfo = 
71         {
72             sizeof(MyAtkStreamableContentClass),
73             NULL, //base_init
74             NULL, //base_finalize
75             NULL, //class_init
76             NULL, //class_finalize
77             NULL, //class_data
78             sizeof(MyAtkStreamableContent),
79             0, //n_preallocs
80             NULL //instance_init
81         };
82
83         static const GInterfaceInfo iface_info = 
84         {
85             my_atk_streamable_content_interface_init,    /* interface_init*/
86             NULL,                               /* interface_finalize*/
87             NULL                                /* interface_data */
88         };
89         type = g_type_register_static(G_TYPE_OBJECT, "MyAtkStreamableContent", &typeInfo, 0);
90         g_type_add_interface_static(type,
91             ATK_TYPE_STREAMABLE_CONTENT,
92             &iface_info);
93     }
94     return type;    
95 }