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 return bonobo_persist_generate_content_types(2, "application/mathml+xml", "text/mathml");
40 gtk_math_view_persist_stream_class_init(GtkMathViewPersistStreamClass *klass)
42 GObjectClass *object_class = G_OBJECT_CLASS(klass);
43 BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass);
44 POA_Bonobo_PersistStream__epv *epv = &klass->epv;
47 printf("persist stream class init\n");
49 gtk_math_view_persist_stream_parent_class = g_type_class_peek_parent(klass);
51 epv->load = load_implementation;
52 epv->save = save_implementation;
54 object_class->finalize = finalize;
55 persist_class->get_content_types = get_content_types;
59 gtk_math_view_persist_stream_get_type(void)
61 static GType type = 0;
63 printf("persist stream get type\n");
67 sizeof(GtkMathViewPersistStreamClass),
69 (GBaseFinalizeFunc) NULL,
70 (GClassInitFunc) gtk_math_view_persist_stream_class_init,
71 NULL, /*class finalize */
73 sizeof(GtkMathViewPersistStream),
75 (GInstanceInitFunc) NULL
78 type = bonobo_type_unique(
80 POA_Bonobo_PersistStream__init,POA_Bonobo_PersistStream__fini,
81 G_STRUCT_OFFSET(GtkMathViewPersistStreamClass,epv),
82 &info,"GtkMathViewPersistStream");
88 gtk_math_view_persist_stream_new(GtkMathView *math_view)
93 printf("persist stream new\n");
95 stream = g_object_new(gtk_math_view_persist_stream_get_type(),NULL);
96 bonobo_persist_construct(BONOBO_PERSIST(stream),CONTROL_FACTORY_ID);
98 g_object_ref(math_view);
99 GTK_MATH_VIEW_PERSIST_STREAM(stream)->math_view = math_view;
105 create_tmp_file(GtkMathViewPersistStream *persist)
110 persist->tmp_path_name = g_strconcat(g_get_tmp_dir(), "/gmvXXXXXX", NULL);
111 if((fd = mkstemp(persist->tmp_path_name)) < 0) {
112 g_free(persist->tmp_path_name),
113 persist->tmp_path_name = NULL;
116 printf("salvo nel file %s\n", persist->tmp_path_name);
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 printf("type = %s\n", type);
145 if (strcmp (type, "application/mathml+xml") != 0) {
146 CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
147 ex_Bonobo_Persist_WrongDataType, NULL);
151 tmpfile = create_tmp_file(persist);
153 Bonobo_Stream_read (stream, 4096, &buffer, ev);
155 if (ev->_major != CORBA_NO_EXCEPTION) {
156 printf("*** eccezione 1\n");
160 len_read = buffer->_length;
161 printf("letti %d bytes\n", len_read);
163 if (buffer->_buffer && len_read)
164 if(fwrite(buffer->_buffer, 1, len_read, tmpfile) != len_read) {
166 printf("*** eccezione 2\n");
171 } while (len_read > 0);
174 result = gtk_math_view_load_uri(persist->math_view,persist->tmp_path_name);
177 CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL);
187 save_implementation(PortableServer_Servant servant,const Bonobo_Stream stream,const CORBA_char *type,CORBA_Environment *ev)
189 bonobo_exception_set(ev,"save_exception");
190 bonobo_exception_add_handler_str("save_exception",
191 "Save option is not valid");