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