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