]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/persist-file.c
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / gtkmathview-bonobo / src / persist-file.c
1 #include <bonobo.h>
2 #include <gtkmathview.h>
3 #include <glib.h>
4 #include "persist-file.h"
5 #include "control-factory.h"
6
7 static BonoboObjectClass *gtk_math_view_persist_file_parent_class;
8
9 static void load_implementation(PortableServer_Servant servant,const gchar *path,
10                 CORBA_Environment *ev); 
11
12 static void save_implementation(PortableServer_Servant servant,const gchar *path,
13                 CORBA_Environment *ev);
14
15 static void finalize(GObject *object)
16 {
17         GtkMathViewPersistFile *file = GTK_MATH_VIEW_PERSIST_FILE(object);
18
19         if(file->math_view){
20                 g_object_unref(file->math_view);
21                 file->math_view = NULL;
22         }
23
24         G_OBJECT_CLASS(gtk_math_view_persist_file_parent_class)->finalize (object);
25 }
26
27 static Bonobo_Persist_ContentTypeList *
28 get_content_types(BonoboPersist *persist,CORBA_Environment *ev)
29 {
30         //FIXME: il tipo di dato non e` noto
31         return bonobo_persist_generate_content_types(0);
32 }
33
34
35 static void 
36 gtk_math_view_persist_file_class_init(GtkMathViewPersistFileClass *klass)
37 {
38         GObjectClass *object_class = G_OBJECT_CLASS(klass);
39         BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass);
40         POA_Bonobo_PersistFile__epv *epv = &klass->epv;
41
42         printf("persist file class init\n");
43         gtk_math_view_persist_file_parent_class = g_type_class_peek_parent(klass);
44
45         epv->load = load_implementation;
46         epv->save = save_implementation;
47
48         object_class->finalize = finalize;
49         persist_class->get_content_types = get_content_types;
50 }
51
52 GType 
53 gtk_math_view_persist_file_get_type(void)
54 {
55         static GType type = 0;
56         printf("persist file get type\n");
57         if(!type){
58                 GTypeInfo info = {
59                         sizeof(GtkMathViewPersistFileClass),
60                         (GBaseInitFunc) NULL,
61                         (GBaseFinalizeFunc) NULL,
62                         (GClassInitFunc) gtk_math_view_persist_file_class_init,
63                         NULL,  /* class finalize */
64                         NULL,  /* class_data */
65                         sizeof(GtkMathViewPersistFile),
66                         0,   /* n_preallocs */
67                         (GInstanceInitFunc) NULL
68                 };
69
70                 type = bonobo_type_unique(
71                                 BONOBO_TYPE_PERSIST,
72                                 POA_Bonobo_PersistFile__init,POA_Bonobo_PersistFile__fini,
73                                 G_STRUCT_OFFSET(GtkMathViewPersistFileClass, epv),
74                                 &info,"GtkMathViewPresistFile");
75         }
76         return type;
77 }
78
79 BonoboObject *
80 gtk_math_view_persist_file_new(GtkMathView *math_view)
81 {
82         BonoboObject *file;
83
84         printf("persist file new\n");
85         file = g_object_new(gtk_math_view_persist_file_get_type(),NULL);
86         bonobo_persist_construct(BONOBO_PERSIST(file),CONTROL_FACTORY_ID);
87
88         g_object_ref(math_view);
89         GTK_MATH_VIEW_PERSIST_FILE(file)->math_view = math_view;
90
91         return file;
92 }
93
94 static void
95 load_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Environment *ev)
96 {
97         gboolean result;
98         GtkMathViewPersistFile* file = GTK_MATH_VIEW_PERSIST_FILE(bonobo_object_from_servant(servant));
99         //fd = open(path, O_RDONLY);
100                 
101         result = gtk_math_view_load_uri(file->math_view,path);
102         if(!result)
103         {
104                 CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL);
105         }
106         return ;
107 }
108
109 static void
110 save_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Environment *ev)
111 {
112         bonobo_exception_set(ev,"save_exception");
113         bonobo_exception_add_handler_str("save_exception",
114                                           "Save option is not valid");
115         return;
116 }