From: pmasoudi Date: Wed, 16 Jul 2003 12:48:25 +0000 (+0000) Subject: added persit-file-implementation. X-Git-Tag: LucaOK~75 X-Git-Url: http://matita.cs.unibo.it/gitweb/?p=helm.git;a=commitdiff_plain;h=70f855932359e26ca89deb11c22f9c9d26154827 added persit-file-implementation. --- diff --git a/helm/gtkmathview-bonobo/src/persist-file.c b/helm/gtkmathview-bonobo/src/persist-file.c new file mode 100644 index 000000000..eceb4e77a --- /dev/null +++ b/helm/gtkmathview-bonobo/src/persist-file.c @@ -0,0 +1,152 @@ +#include +#include +#include + + +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 finalize(GObject *object) +{ + GtkMathViewPersistFile *file = GTK_MATH_VIEW_PERSIST_FILE(object); + + if(file->math_view){ + g_object_unref(file->html); + file->math_view = NULL; + } + + G_OBJECT_CLASS(gtk_math_view_persist_file_parent_class)->finalize (object); +} + +static Bonobo_Persist_ContentTypeList * +get_content_types(BonoboPersist *persist,CORBA_Environment *ev) +{ + return bonobo_persist_generate_content_types(); +} + +static void +gtk_math_view_persist_file_class_init(GtkMathViewFileClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass); + POA_Bonobo_PersistFile__epv *epv = &klass->epv; + + gtk_math_view_persist_file_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_file_get_type(void) +{ + static GType type = 0; + if(!type){ + GTypeInfo info = { + sizeof(GtkMathViewPresistFileClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gtk_math_view_persist_file_class_init, + NULL, /* class finalize */ + NULL, /* class_data */ + sizeof(GtkMathViewPresistFile), + 0, /* n_preallocs */ + (GInstanceInitFunc) NULL + }; + + type = bonobo_type_unique( + BONOBO_TYPE_PERSIST, + POA_Bonobo_PersistFile__init,POA_Bonobo_PersistFile__fini, + G_STRUCT_OFFSET(GtkMathViewPresistFileClass, epv), + &info,"GtkMathViewPresistFile"); + } + return type; +} + +BonoboObject * +gtk_math_view_persist_file_new(GtkMathView *math_view) +{ + BonoboObject *file; + + file = g_object_new(gtk_math_view_persist_file_get_type(),NULL); + bonobo_persist_construct(BONOBO_PRESIST(file), CONTROL_FACTORY_ID); + + g_object_ref(math_view); + GTK_MATH_VIEW_PRESIST_FILE (file) = 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) +{ + 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) + { + bonobo_object_unref(BONOBO_OBJECT (data_file)); + return NULL; + } + + bonobo_object_add_interface(BONOBO_OBJECT(data_file), + BONOBO_OBJECT(file)); + return data_file; +} + + +} + + +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) +{ + return 1; //return 1 on success +} + + diff --git a/helm/gtkmathview-bonobo/src/persist-file.h b/helm/gtkmathview-bonobo/src/persist-file.h new file mode 100644 index 000000000..feef4598b --- /dev/null +++ b/helm/gtkmathview-bonobo/src/persist-file.h @@ -0,0 +1,42 @@ +#ifdef _GTK_MATH_VIEW_PERSIST_FILE_H_ +#define _GTK_MATH_VIEW_PERSIST_FILE_H_ + +#include +#include + +G_BEGIN_DECLS + +struct _GtkMathViewPersistFile; +typedef struct _GtkMathViewPersistFile GtkMathViewPersistFile; +typedef struct _GtkMathViewPersistFilePrivate GtkMathViewPersistFilePrivate; + +#define GTK_MATH_VIEW_TYPE_PERSIST_FILE (gtk_math_view_persist_file_get_type()) + +#define GTK_MATH_VIEW_PERSIST_FILE(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GTK_MATH_VIEW_TYPE_PERSIST_FILE, \ + GtkMathViewPersistFile)) + +#define GTK_HTML_IS_PERSIST_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k),\ + GTK_MATH_VIEW_TYPE_PERSIST_FILE,\ + GtkMathViewPersistFileClass)) +#define GTK_MATH_VIEW_IS_PERSIST_FILE(o) (G_TYPE_CHECK_INSTANCE_TYPE((o),\ + GTK_MATH_VIEW_TYPE_PERSIST_FILE)) +#define GTK_MATH_VIEW_IS_PERSIST_FILE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k),\ + GTK_MATH_VIEW_TYPE_PERSIST_FILE)) + +struct _GtkMathViewPersistFile{ + BonoboPersist parent; + GtkMathView *math_view; +}; + +typedef struct { + BonoboPersistClass parent_class; + + POA_Bonobo_PersistFile__epv epv; +}GtkMathViewPersistFileClass; + +GType gtk_math_view_persist_file_get_type(void); +BonoboObject *gtk_math_view_persist_file_new(GtkMathView *math_view); + +G_END_DECLS + +#endif