]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/gtkmathview-bonobo/src/persist-file.c
Persist file completed.
[helm.git] / helm / gtkmathview-bonobo / src / persist-file.c
index eceb4e77a31cbb5bb6a88e3b544113eefddec4f5..68914ded4133fe07d42ab3c4f7c2f470a8a4a195 100644 (file)
@@ -1,18 +1,23 @@
 #include <bonobo.h>
-#include <gtk_math_view.h>
+#include <gtkmathview.h>
 #include <glib.h>
-
+#include "persist-file.h"
+#include "control-factory.h"
 
 static BonoboObjectClass *gtk_math_view_persist_file_parent_class;
 
-static void load_implementation(PortableServer_Servant servant,const CORBA_char *path,Corba_Environment *ev); 
+static void load_implementation(PortableServer_Servant servant,const gchar *path,
+               CORBA_Environment *ev); 
+
+static void save_implementation(PortableServer_Servant servant,const gchar *path,
+               CORBA_Environment *ev);
 
 static void finalize(GObject *object)
 {
        GtkMathViewPersistFile *file = GTK_MATH_VIEW_PERSIST_FILE(object);
 
        if(file->math_view){
-               g_object_unref(file->html);
+               g_object_unref(file->math_view);
                file->math_view = NULL;
        }
 
@@ -22,16 +27,19 @@ static void finalize(GObject *object)
 static Bonobo_Persist_ContentTypeList *
 get_content_types(BonoboPersist *persist,CORBA_Environment *ev)
 {
-       return bonobo_persist_generate_content_types();
+       //FIXME: il tipo di dato non e` noto
+       return bonobo_persist_generate_content_types(0);
 }
 
+
 static void 
-gtk_math_view_persist_file_class_init(GtkMathViewFileClass *klass)
+gtk_math_view_persist_file_class_init(GtkMathViewPersistFileClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS(klass);
        BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass);
        POA_Bonobo_PersistFile__epv *epv = &klass->epv;
 
+       printf("persist file class init\n");
        gtk_math_view_persist_file_parent_class = g_type_class_peek_parent(klass);
 
        epv->load = load_implementation;
@@ -45,15 +53,16 @@ GType
 gtk_math_view_persist_file_get_type(void)
 {
        static GType type = 0;
+       printf("persist file get type\n");
        if(!type){
                GTypeInfo info = {
-                       sizeof(GtkMathViewPresistFileClass),
+                       sizeof(GtkMathViewPersistFileClass),
                        (GBaseInitFunc) NULL,
                        (GBaseFinalizeFunc) NULL,
                        (GClassInitFunc) gtk_math_view_persist_file_class_init,
                        NULL,  /* class finalize */
                        NULL,  /* class_data */
-                       sizeof(GtkMathViewPresistFile),
+                       sizeof(GtkMathViewPersistFile),
                        0,   /* n_preallocs */
                        (GInstanceInitFunc) NULL
                };
@@ -61,7 +70,7 @@ gtk_math_view_persist_file_get_type(void)
                type = bonobo_type_unique(
                                BONOBO_TYPE_PERSIST,
                                POA_Bonobo_PersistFile__init,POA_Bonobo_PersistFile__fini,
-                               G_STRUCT_OFFSET(GtkMathViewPresistFileClass, epv),
+                               G_STRUCT_OFFSET(GtkMathViewPersistFileClass, epv),
                                &info,"GtkMathViewPresistFile");
        }
        return type;
@@ -72,81 +81,36 @@ gtk_math_view_persist_file_new(GtkMathView *math_view)
 {
        BonoboObject *file;
 
+       printf("persist file new\n");
        file = g_object_new(gtk_math_view_persist_file_get_type(),NULL);
-       bonobo_persist_construct(BONOBO_PRESIST(file), CONTROL_FACTORY_ID);
+       bonobo_persist_construct(BONOBO_PERSIST(file),CONTROL_FACTORY_ID);
 
        g_object_ref(math_view);
-       GTK_MATH_VIEW_PRESIST_FILE (file) = math_view;
+       GTK_MATH_VIEW_PERSIST_FILE(file)->math_view = math_view;
 
        return file;
 }
 
 static void
-load_implementation(PortableServer_Servant servant,const CORBA_char *path,CORBA_Environment *ev)
-{
-       GtkMathViewPersistFile *file = GTK_MATH_VIEW_
-}
-
-Dom::Document *
-gtk_math_view_bonobo_data_construct(Dom::Document *data_file)
+load_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Environment *ev)
 {
-       BonoboObject *retval;
-       BonoboPersistFile *file;
-
-       file = bonobo_persist_file_new(gtk_math_view_load_from_file,
-                       gtk_math_view_save_to_file,
-                       "OAFIID:GNOME_MATH_VIEW_FILE_Control",
-                       data_file);
-
-       if(file == NULL)
+       gboolean result;
+       GtkMathViewPersistFile* file = GTK_MATH_VIEW_PERSIST_FILE(bonobo_object_from_servant(servant));
+       //fd = open(path, O_RDONLY);
+               
+       result = gtk_math_view_load_uri(file->math_view,path);
+       if(!result)
        {
-               bonobo_object_unref(BONOBO_OBJECT (data_file));
-               return NULL;
+               CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL);
        }
-
-       bonobo_object_add_interface(BONOBO_OBJECT(data_file),
-                                       BONOBO_OBJECT(file));
-       return data_file;
+       return ;
 }
 
-
-}
-
-
-static gint
-gtk_math_view_bonobo_load_from_file(BonoboPresistFile  *pf,
-               const CORBA_char        *filename,
-               CORBA_Environment       *ev,
-               void                    *closure)
-{
-       Bonobo_PersistStream ps = closure;
-       BonoboStream *stream;
-
-       g_return_val_if_fail (data != NULL, -1);
-       //FIXME: controllo del tipo di dato in input
-       
-       stram = bonobo_stream_open(
-                       BONOBO_IO_DRIVER_FS,
-                       filename,Bonobo_STORAGE_READ,
-                       0);
-       if(!stream)
-               return 0;
-
-       //FIXME:I have to extract content type from file
-               
-       
-       Bonobo_PersistStream_load(ps, type, ev);
-       
-       return 1;  //return 1 on success
-}
-
-static gint 
-gtk_math_view_bonobo_save_to_file(BonoboPresistFile            *pf,
-               const CORBA_char        *filename,
-               CORBA_Environment       *ev,
-               void                    *closure)
+static void
+save_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Environment *ev)
 {
-       return 1;   //return 1 on success
+       bonobo_exception_set(ev,"save_exception");
+       bonobo_exception_add_handler_str("save_exception",
+                                         "Save option is not valid");
+       return;
 }
-
-