2 #include <gtkmathview.h>
4 #include "persist-stream.h"
5 #include "control-factory.h"
9 static BonoboObjectClass *gtk_math_view_persist_stream_parent_class;
11 static void load_implementation(PortableServer_Servant servant,
12 const Bonobo_Stream stream,
13 const CORBA_char *type,
14 CORBA_Environment *ev);
16 static void save_implementation(PortableServer_Servant servant,
17 const Bonobo_Stream stream,
18 const CORBA_char *type,
19 CORBA_Environment *ev);
21 static void finalize(GObject *object)
23 GtkMathViewPersistStream *stream = GTK_MATH_VIEW_PERSIST_STREAM(object);
25 if(stream->math_view){
26 g_object_unref(stream->math_view);
27 stream->math_view = NULL;
30 G_OBJECT_CLASS(gtk_math_view_persist_stream_parent_class)->finalize(object);
33 static Bonobo_Persist_ContentTypeList *
34 get_content_types(BonoboPersist *persist,CORBA_Environment *ev)
36 //FIXME:il tipo di dato non e` noto
37 return bonobo_persist_generate_content_types(0);
41 gtk_math_view_persist_stream_class_init(GtkMathViewPersistStreamClass *klass)
43 GObjectClass *object_class = G_OBJECT_CLASS(klass);
44 BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass);
45 POA_Bonobo_PersistStream__epv *epv = &klass->epv;
48 printf("persist stream class init\n");
50 gtk_math_view_persist_stream_parent_class = g_type_class_peek_parent(klass);
52 epv->load = load_implementation;
53 epv->save = save_implementation;
55 object_class->finalize = finalize;
56 persist_class->get_content_types = get_content_types;
60 gtk_math_view_persist_stream_get_type(void)
62 static GType type = 0;
64 printf("persist stream get type\n");
68 sizeof(GtkMathViewPersistStreamClass),
70 (GBaseFinalizeFunc) NULL,
71 (GClassInitFunc) gtk_math_view_persist_stream_class_init,
72 NULL, /*class finalize */
74 sizeof(GtkMathViewPersistStream),
76 (GInstanceInitFunc) NULL
79 type = bonobo_type_unique(
81 POA_Bonobo_PersistStream__init,POA_Bonobo_PersistStream__fini,
82 G_STRUCT_OFFSET(GtkMathViewPersistStreamClass,epv),
83 &info,"GtkMathViewPersistStream");
89 gtk_math_view_persist_stream_new(GtkMathView *math_view)
94 printf("persist stream new\n");
96 stream = g_object_new(gtk_math_view_persist_stream_get_type(),NULL);
97 bonobo_persist_construct(BONOBO_PERSIST(stream),CONTROL_FACTORY_ID);
99 g_object_ref(math_view);
100 GTK_MATH_VIEW_PERSIST_STREAM(stream)->math_view = math_view;
106 create_tmp_file(GtkMathViewPersistStream *persist)
111 persist->tmp_path_name = g_strconcat(g_get_tmp_dir(), "/ggvXXXXXX", NULL);
112 if((fd = mkstemp(persist->tmp_path_name)) < 0) {
113 g_free(persist->tmp_path_name),
114 persist->tmp_path_name = NULL;
117 tmpfile = fdopen(fd, "w");
127 load_implementation(PortableServer_Servant servant,
128 Bonobo_PersistStream stream,
129 const CORBA_char *type,
130 CORBA_Environment *ev)
132 GtkMathViewPersistStream *persist = GTK_MATH_VIEW_PERSIST_STREAM (bonobo_object_from_servant (servant));
133 Bonobo_Stream_iobuf *buffer;
134 GtkMathViewPersistStream *handle;
140 printf("persist stream loading\n");
143 if (strcmp (type, "application/mathml+xml") != 0) {
144 CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
145 ex_Bonobo_Persist_WrongDataType, NULL);
149 tmpfile = create_tmp_file(persist);
151 Bonobo_Stream_read (stream, 4096, &buffer, ev);
153 if (ev->_major != CORBA_NO_EXCEPTION || buffer->_length <= 0) {
158 len_read = buffer->_length;
159 if (buffer->_buffer && len_read)
160 if(fwrite(buffer->_buffer, 1, len_read, tmpfile) != len_read) {
169 result = gtk_math_view_load_uri(persist->math_view,persist->tmp_path_name);
172 CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL);
174 //FIXME non sono sicuro di questo
175 bonobo_object_unref(BONOBO_OBJECT(stream));
184 save_implementation(PortableServer_Servant servant,const Bonobo_Stream stream,const CORBA_char *type,CORBA_Environment *ev)
186 bonobo_exception_set(ev,"save_exception");
187 bonobo_exception_add_handler_str("save_exception",
188 "Save option is not valid");