]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/persist-file.c
* added first version of persist stream implementation (not yet working)
[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 #ifdef DEBUG
43         printf("persist file class init\n");
44 #endif
45         gtk_math_view_persist_file_parent_class = g_type_class_peek_parent(klass);
46
47         epv->load = load_implementation;
48         epv->save = save_implementation;
49
50         object_class->finalize = finalize;
51         persist_class->get_content_types = get_content_types;
52 }
53
54 GType 
55 gtk_math_view_persist_file_get_type(void)
56 {
57         static GType type = 0;
58 #ifdef DEBUG
59         printf("persist file get type\n");
60 #endif
61         if(!type){
62                 GTypeInfo info = {
63                         sizeof(GtkMathViewPersistFileClass),
64                         (GBaseInitFunc) NULL,
65                         (GBaseFinalizeFunc) NULL,
66                         (GClassInitFunc) gtk_math_view_persist_file_class_init,
67                         NULL,  /* class finalize */
68                         NULL,  /* class_data */
69                         sizeof(GtkMathViewPersistFile),
70                         0,   /* n_preallocs */
71                         (GInstanceInitFunc) NULL
72                 };
73
74                 type = bonobo_type_unique(
75                                 BONOBO_TYPE_PERSIST,
76                                 POA_Bonobo_PersistFile__init,POA_Bonobo_PersistFile__fini,
77                                 G_STRUCT_OFFSET(GtkMathViewPersistFileClass, epv),
78                                 &info,"GtkMathViewPresistFile");
79         }
80         return type;
81 }
82
83 BonoboObject *
84 gtk_math_view_persist_file_new(GtkMathView *math_view)
85 {
86         BonoboObject *file;
87
88         printf("persist file new\n");
89         file = g_object_new(gtk_math_view_persist_file_get_type(),NULL);
90         bonobo_persist_construct(BONOBO_PERSIST(file),CONTROL_FACTORY_ID);
91
92         g_object_ref(math_view);
93         GTK_MATH_VIEW_PERSIST_FILE(file)->math_view = math_view;
94
95         return file;
96 }
97
98 static void
99 load_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Environment *ev)
100 {
101         gboolean result;
102         GtkMathViewPersistFile* file = GTK_MATH_VIEW_PERSIST_FILE(bonobo_object_from_servant(servant));
103         //fd = open(path, O_RDONLY);
104                 
105         result = gtk_math_view_load_uri(file->math_view,path);
106         if(!result)
107         {
108                 CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL);
109         }
110     bonobo_object_unref(BONOBO_OBJECT(file));
111         return ;
112 }
113
114 static void
115 save_implementation(PortableServer_Servant servant,
116                     const gchar *path,
117                     CORBA_Environment *ev)
118 {
119         bonobo_exception_set(ev,"save_exception");
120         bonobo_exception_add_handler_str("save_exception",
121                                           "Save option is not valid");
122         return;
123 }