]> matita.cs.unibo.it Git - helm.git/blob - helm/gtkmathview-bonobo/src/persist-file.c
Bug fixed: when an axiom was asked, an exception was raised (since the
[helm.git] / helm / gtkmathview-bonobo / src / persist-file.c
1 /* This file is part of GtkMathView-Bonobo, a Bonobo wrapper for GtkMathView.
2  * Copyright (C) 2003 Luca Padovani <lpadovan@cs.unibo.it>
3  *                    Pouria Masoudi <pmasoudi@cs.unibo.it>
4  * 
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * 
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * For more information, please visit the project's home page
20  * http://helm.cs.unibo.it/gtkmathview-bonobo
21  * or send an email to <lpadovan@cs.unibo.it>
22  */
23
24 #include <config.h>
25
26 #include <bonobo.h>
27 #include <gtkmathview.h>
28 #include <glib.h>
29
30 #include "persist-file.h"
31 #include "control-factory.h"
32
33 static BonoboObjectClass *gtk_math_view_persist_file_parent_class;
34
35 static void load_implementation(PortableServer_Servant servant,const gchar *path,
36                                 CORBA_Environment *ev); 
37
38 static void save_implementation(PortableServer_Servant servant,const gchar *path,
39                                 CORBA_Environment *ev);
40
41 static void finalize(GObject *object)
42 {
43   GtkMathViewPersistFile *file = GTK_MATH_VIEW_PERSIST_FILE(object);
44
45   if (file->math_view)
46     {
47       g_object_unref(file->math_view);
48       file->math_view = NULL;
49     }
50
51   G_OBJECT_CLASS(gtk_math_view_persist_file_parent_class)->finalize (object);
52 }
53
54 static Bonobo_Persist_ContentTypeList *
55 get_content_types(BonoboPersist *persist,CORBA_Environment *ev)
56 {
57   return bonobo_persist_generate_content_types(3, "application/mathml+xml", "text/mathml", "text/plain");
58 }
59
60 static void 
61 gtk_math_view_persist_file_class_init(GtkMathViewPersistFileClass *klass)
62 {
63   GObjectClass *object_class = G_OBJECT_CLASS(klass);
64   BonoboPersistClass *persist_class = BONOBO_PERSIST_CLASS(klass);
65   POA_Bonobo_PersistFile__epv *epv = &klass->epv;
66
67   gtk_math_view_persist_file_parent_class = g_type_class_peek_parent(klass);
68
69   epv->load = load_implementation;
70   epv->save = save_implementation;
71
72   object_class->finalize = finalize;
73   persist_class->get_content_types = get_content_types;
74 }
75
76 GType 
77 gtk_math_view_persist_file_get_type(void)
78 {
79   static GType type = 0;
80
81   if (!type)
82     {
83       GTypeInfo info =
84         {
85           sizeof(GtkMathViewPersistFileClass),
86           (GBaseInitFunc) NULL,
87           (GBaseFinalizeFunc) NULL,
88           (GClassInitFunc) gtk_math_view_persist_file_class_init,
89           NULL,  /* class finalize */
90           NULL,  /* class_data */
91           sizeof(GtkMathViewPersistFile),
92           0,   /* n_preallocs */
93           (GInstanceInitFunc) NULL
94         };
95
96       type = bonobo_type_unique(BONOBO_TYPE_PERSIST,
97                                 POA_Bonobo_PersistFile__init,POA_Bonobo_PersistFile__fini,
98                                 G_STRUCT_OFFSET(GtkMathViewPersistFileClass, epv),
99                                 &info,"GtkMathViewPresistFile");
100     }
101
102   return type;
103 }
104
105 BonoboObject *
106 gtk_math_view_persist_file_new(GtkMathView *math_view)
107 {
108   BonoboObject *file;
109
110   file = g_object_new(gtk_math_view_persist_file_get_type(),NULL);
111   bonobo_persist_construct(BONOBO_PERSIST(file),CONTROL_FACTORY_ID);
112
113   g_object_ref(math_view);
114   GTK_MATH_VIEW_PERSIST_FILE(file)->math_view = math_view;
115
116   return file;
117 }
118
119 static void
120 load_implementation(PortableServer_Servant servant,const gchar *path,CORBA_Environment *ev)
121 {
122   gboolean result;
123   GtkMathViewPersistFile* file = GTK_MATH_VIEW_PERSIST_FILE(bonobo_object_from_servant(servant));
124   //fd = open(path, O_RDONLY);
125
126   result = gtk_math_view_load_uri(file->math_view,path);
127   if(!result)
128     CORBA_exception_set(ev,CORBA_USER_EXCEPTION,ex_Bonobo_Persist_WrongDataType,NULL);
129
130   bonobo_object_unref(BONOBO_OBJECT(file));
131 }
132
133 static void
134 save_implementation(PortableServer_Servant servant,
135                     const gchar *path,
136                     CORBA_Environment *ev)
137 {
138   bonobo_exception_set(ev,"save_exception");
139   bonobo_exception_add_handler_str("save_exception",
140                                    "Save option is not valid");
141 }