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