]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/persist-file.c
added persit-file-implementation.
[helm.git] / helm / gtkmathview-bonobo / src / persist-file.c
1 #include <bonobo.h>
2 #include <gtk_math_view.h>
3 #include <glib.h>
4
5
6 static BonoboObjectClass *gtk_math_view_persist_file_parent_class;
7
8 static void load_implementation(PortableServer_Servant servant,const CORBA_char *path,Corba_Environment *ev); 
9
10 static void finalize(GObject *object)
11 {
12         GtkMathViewPersistFile *file = GTK_MATH_VIEW_PERSIST_FILE(object);
13
14         if(file->math_view){
15                 g_object_unref(file->html);
16                 file->math_view = NULL;
17         }
18
19         G_OBJECT_CLASS(gtk_math_view_persist_file_parent_class)->finalize (object);
20 }
21
22 static Bonobo_Persist_ContentTypeList *
23 get_content_types(BonoboPersist *persist,CORBA_Environment *ev)
24 {
25         return bonobo_persist_generate_content_types();
26 }
27
28 static void 
29 gtk_math_view_persist_file_class_init(GtkMathViewFileClass *klass)
30 {
31         GObjectClass *object_class = G_OBJECT_CLASS(klass);
32         BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass);
33         POA_Bonobo_PersistFile__epv *epv = &klass->epv;
34
35         gtk_math_view_persist_file_parent_class = g_type_class_peek_parent(klass);
36
37         epv->load = load_implementation;
38         epv->save = save_implementation;
39
40         object_class->finalize = finalize;
41         persist_class->get_content_types = get_content_types;
42 }
43
44 GType 
45 gtk_math_view_persist_file_get_type(void)
46 {
47         static GType type = 0;
48         if(!type){
49                 GTypeInfo info = {
50                         sizeof(GtkMathViewPresistFileClass),
51                         (GBaseInitFunc) NULL,
52                         (GBaseFinalizeFunc) NULL,
53                         (GClassInitFunc) gtk_math_view_persist_file_class_init,
54                         NULL,  /* class finalize */
55                         NULL,  /* class_data */
56                         sizeof(GtkMathViewPresistFile),
57                         0,   /* n_preallocs */
58                         (GInstanceInitFunc) NULL
59                 };
60
61                 type = bonobo_type_unique(
62                                 BONOBO_TYPE_PERSIST,
63                                 POA_Bonobo_PersistFile__init,POA_Bonobo_PersistFile__fini,
64                                 G_STRUCT_OFFSET(GtkMathViewPresistFileClass, epv),
65                                 &info,"GtkMathViewPresistFile");
66         }
67         return type;
68 }
69
70 BonoboObject *
71 gtk_math_view_persist_file_new(GtkMathView *math_view)
72 {
73         BonoboObject *file;
74
75         file = g_object_new(gtk_math_view_persist_file_get_type(),NULL);
76         bonobo_persist_construct(BONOBO_PRESIST(file), CONTROL_FACTORY_ID);
77
78         g_object_ref(math_view);
79         GTK_MATH_VIEW_PRESIST_FILE (file) = math_view;
80
81         return file;
82 }
83
84 static void
85 load_implementation(PortableServer_Servant servant,const CORBA_char *path,CORBA_Environment *ev)
86 {
87         GtkMathViewPersistFile *file = GTK_MATH_VIEW_
88 }
89
90 Dom::Document *
91 gtk_math_view_bonobo_data_construct(Dom::Document *data_file)
92 {
93         BonoboObject *retval;
94         BonoboPersistFile *file;
95
96         file = bonobo_persist_file_new(gtk_math_view_load_from_file,
97                         gtk_math_view_save_to_file,
98                         "OAFIID:GNOME_MATH_VIEW_FILE_Control",
99                         data_file);
100
101         if(file == NULL)
102         {
103                 bonobo_object_unref(BONOBO_OBJECT (data_file));
104                 return NULL;
105         }
106
107         bonobo_object_add_interface(BONOBO_OBJECT(data_file),
108                                         BONOBO_OBJECT(file));
109         return data_file;
110 }
111
112
113 }
114
115
116 static gint
117 gtk_math_view_bonobo_load_from_file(BonoboPresistFile   *pf,
118                 const CORBA_char        *filename,
119                 CORBA_Environment       *ev,
120                 void                    *closure)
121 {
122         Bonobo_PersistStream ps = closure;
123         BonoboStream *stream;
124
125         g_return_val_if_fail (data != NULL, -1);
126         //FIXME: controllo del tipo di dato in input
127         
128         stram = bonobo_stream_open(
129                         BONOBO_IO_DRIVER_FS,
130                         filename,Bonobo_STORAGE_READ,
131                         0);
132         if(!stream)
133                 return 0;
134
135         //FIXME:I have to extract content type from file
136                 
137         
138         Bonobo_PersistStream_load(ps, type, ev);
139         
140         return 1;  //return 1 on success
141 }
142
143 static gint 
144 gtk_math_view_bonobo_save_to_file(BonoboPresistFile             *pf,
145                 const CORBA_char        *filename,
146                 CORBA_Environment       *ev,
147                 void                    *closure)
148 {
149         return 1;   //return 1 on success
150 }
151
152