X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;ds=sidebyside;f=helm%2Fgtkmathview-bonobo%2Fsrc%2Fpersist-stream.c;fp=helm%2Fgtkmathview-bonobo%2Fsrc%2Fpersist-stream.c;h=0000000000000000000000000000000000000000;hb=1696761e4b8576e8ed81caa905fd108717019226;hp=bef7d90cb6218bea4f7f953a955a2114137be7e2;hpb=5325734bc2e4927ed7ec146e35a6f0f2b49f50c1;p=helm.git diff --git a/helm/gtkmathview-bonobo/src/persist-stream.c b/helm/gtkmathview-bonobo/src/persist-stream.c deleted file mode 100644 index bef7d90cb..000000000 --- a/helm/gtkmathview-bonobo/src/persist-stream.c +++ /dev/null @@ -1,221 +0,0 @@ -/* This file is part of GtkMathView-Bonobo, a Bonobo wrapper for GtkMathView. - * Copyright (C) 2003 Luca Padovani - * Pouria Masoudi - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * For more information, please visit the project's home page - * http://helm.cs.unibo.it/gtkmathview-bonobo - * or send an email to - */ - -#include - -#include -#include - -#include "persist-stream.h" -#include "control-factory.h" - -#define DEBUG0 - -static BonoboObjectClass *gtk_math_view_persist_stream_parent_class; - -static void load_implementation(PortableServer_Servant servant, - const Bonobo_Stream stream, - const CORBA_char *type, - CORBA_Environment *ev); - -static void save_implementation(PortableServer_Servant servant, - const Bonobo_Stream stream, - const CORBA_char *type, - CORBA_Environment *ev); - -static void finalize(GObject *object) -{ - GtkMathViewPersistStream *stream = GTK_MATH_VIEW_PERSIST_STREAM(object); - - if (stream->math_view != NULL) - { - g_object_unref(stream->math_view); - stream->math_view = NULL; - } - - G_OBJECT_CLASS(gtk_math_view_persist_stream_parent_class)->finalize(object); -} - -static Bonobo_Persist_ContentTypeList * -get_content_types(BonoboPersist *persist,CORBA_Environment *ev) -{ - return bonobo_persist_generate_content_types(2, "application/mathml+xml", "text/mathml"); -} - -static void -gtk_math_view_persist_stream_class_init(GtkMathViewPersistStreamClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS(klass); - BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass); - POA_Bonobo_PersistStream__epv *epv = &klass->epv; - -#ifdef DEBUG - printf("persist stream class init\n"); -#endif - gtk_math_view_persist_stream_parent_class = g_type_class_peek_parent(klass); - - epv->load = load_implementation; - epv->save = save_implementation; - - object_class->finalize = finalize; - persist_class->get_content_types = get_content_types; -} - -GType -gtk_math_view_persist_stream_get_type(void) -{ - static GType type = 0; -#ifdef DEBUG - printf("persist stream get type\n"); -#endif - if (!type) - { - GTypeInfo info = - { - sizeof(GtkMathViewPersistStreamClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gtk_math_view_persist_stream_class_init, - NULL, /*class finalize */ - NULL, /*class data */ - sizeof(GtkMathViewPersistStream), - 0, /* n_preallocs */ - (GInstanceInitFunc) NULL - }; - - type = bonobo_type_unique(BONOBO_TYPE_PERSIST, - POA_Bonobo_PersistStream__init,POA_Bonobo_PersistStream__fini, - G_STRUCT_OFFSET(GtkMathViewPersistStreamClass,epv), - &info,"GtkMathViewPersistStream"); - } - - return type; -} - -BonoboObject * -gtk_math_view_persist_stream_new(GtkMathView *math_view) -{ - BonoboObject *stream; - -#ifdef DEBUG - printf("persist stream new\n"); -#endif - stream = g_object_new(gtk_math_view_persist_stream_get_type(),NULL); - bonobo_persist_construct(BONOBO_PERSIST(stream),CONTROL_FACTORY_ID); - - g_object_ref(math_view); - GTK_MATH_VIEW_PERSIST_STREAM(stream)->math_view = math_view; - - return stream; -} - -static FILE* -create_tmp_file(GtkMathViewPersistStream *persist) -{ - FILE *tmpfile; - int fd; - - persist->tmp_path_name = g_strconcat(g_get_tmp_dir(), "/gmvXXXXXX", NULL); - if ((fd = mkstemp(persist->tmp_path_name)) < 0) - { - g_free(persist->tmp_path_name), - persist->tmp_path_name = NULL; - return NULL; - } - - tmpfile = fdopen(fd, "w"); - if(!tmpfile) - { - close(fd); - return NULL; - } - - return tmpfile; -} - - -static void -load_implementation(PortableServer_Servant servant, - Bonobo_PersistStream stream, - const CORBA_char *type, - CORBA_Environment *ev) -{ - GtkMathViewPersistStream *persist = GTK_MATH_VIEW_PERSIST_STREAM (bonobo_object_from_servant (servant)); - Bonobo_Stream_iobuf *buffer; - GtkMathViewPersistStream *handle; - CORBA_long len_read; - gboolean result; - FILE *tmpfile; - -#ifdef DEBUG - printf("persist stream loading\n"); -#endif - - if (strcmp (type, "application/mathml+xml") != 0) - { - CORBA_exception_set (ev, CORBA_USER_EXCEPTION, - ex_Bonobo_Persist_WrongDataType, NULL); - return; - } - - tmpfile = create_tmp_file(persist); - do - { - Bonobo_Stream_read (stream, 4096, &buffer, ev); - if (ev->_major != CORBA_NO_EXCEPTION) - goto clean; - - len_read = buffer->_length; - - if (buffer->_buffer && len_read) - if (fwrite(buffer->_buffer, 1, len_read, tmpfile) != len_read) - { - CORBA_free (buffer); - goto clean; - } - - CORBA_free (buffer); - } while (len_read > 0); - - fclose(tmpfile); - - result = gtk_math_view_load_uri(persist->math_view,persist->tmp_path_name); - if(!result) - { - CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL); - } - return ; - - clean: - fclose (tmpfile); - return; -} - -static void -save_implementation(PortableServer_Servant servant,const Bonobo_Stream stream,const CORBA_char *type,CORBA_Environment *ev) -{ - bonobo_exception_set(ev,"save_exception"); - bonobo_exception_add_handler_str("save_exception", - "Save option is not valid"); - return; -}