comparison src/paranormal/pn/pnbooleanoption.c @ 12:3da1b8942b8b trunk

[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author nenolod
date Mon, 18 Sep 2006 03:14:20 -0700
parents src/Visualization/paranormal/pn/pnbooleanoption.c@13389e613d67
children
comparison
equal deleted inserted replaced
11:cff1d04026ae 12:3da1b8942b8b
1 /* Paranormal - A highly customizable audio visualization library
2 * Copyright (C) 2001 Jamie Gennis <jgennis@mindspring.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <config.h>
20
21 #include <ctype.h>
22 #include <glib.h>
23 #include "pnbooleanoption.h"
24 #include "pnxml.h"
25 #include "pnerror.h"
26
27 static void pn_boolean_option_class_init (PnBooleanOptionClass *class);
28
29 /* PnUserObject methods */
30 static void pn_boolean_option_save_thyself (PnUserObject *user_object,
31 xmlNodePtr node);
32 static void pn_boolean_option_load_thyself (PnUserObject *user_object,
33 xmlNodePtr node);
34
35 static PnUserObjectClass *parent_class = NULL;
36
37 GType
38 pn_boolean_option_get_type (void)
39 {
40 static GType boolean_option_type = 0;
41
42 if (! boolean_option_type)
43 {
44 static const GTypeInfo boolean_option_info =
45 {
46 sizeof (PnBooleanOptionClass),
47 NULL, /* base_init */
48 NULL, /* base_finalize */
49 (GClassInitFunc) pn_boolean_option_class_init,
50 NULL, /* class_finalize */
51 NULL, /* class_data */
52 sizeof (PnBooleanOption),
53 0, /* n_preallocs */
54 NULL /* instance_init */
55 };
56
57 /* FIXME: should this be dynamic? */
58 boolean_option_type = g_type_register_static (PN_TYPE_OPTION,
59 "PnBooleanOption",
60 &boolean_option_info,
61 0);
62 }
63 return boolean_option_type;
64 }
65
66 static void
67 pn_boolean_option_class_init (PnBooleanOptionClass *class)
68 {
69 PnObjectClass *object_class;
70 PnUserObjectClass *user_object_class;
71 PnOptionClass *option_class;
72
73 parent_class = g_type_class_peek_parent (class);
74
75 object_class = (PnObjectClass *) class;
76 user_object_class = (PnUserObjectClass *) class;
77 option_class = (PnOptionClass *) class;
78
79 /* PnUserObject methods */
80 user_object_class->save_thyself = pn_boolean_option_save_thyself;
81 user_object_class->load_thyself = pn_boolean_option_load_thyself;
82
83 /* PnOption methods */
84 /* FIXME: this needs to be uncommented when the widget is done */
85 /* option_class->widget_type = PN_TYPE_BOOLEAN_OPTION_WIDGET; */
86 }
87
88 static void
89 pn_boolean_option_save_thyself (PnUserObject *user_object, xmlNodePtr node)
90 {
91 PnBooleanOption *boolean_option;
92 xmlNodePtr value_node;
93
94 g_return_if_fail (user_object != NULL);
95 g_return_if_fail (PN_IS_BOOLEAN_OPTION (user_object));
96 g_return_if_fail (node != NULL);
97
98 boolean_option = (PnBooleanOption *) user_object;
99
100 value_node = xmlNewChild (node, NULL, (xmlChar *) "Value", NULL);
101
102 if (boolean_option->value)
103 xmlNodeSetContent (value_node, (xmlChar *) "True");
104 else
105 xmlNodeSetContent (value_node, (xmlChar *) "False");
106
107 if (parent_class->save_thyself)
108 parent_class->save_thyself (user_object, node);
109 }
110
111 static void
112 pn_boolean_option_load_thyself (PnUserObject *user_object, const xmlNodePtr node)
113 {
114 PnBooleanOption *boolean_option;
115 xmlNodePtr boolean_option_node;
116 gchar *val_str;
117
118 g_return_if_fail (user_object != NULL);
119 g_return_if_fail (PN_IS_BOOLEAN_OPTION (user_object));
120 g_return_if_fail (node != NULL);
121
122 boolean_option = (PnBooleanOption *) user_object;
123
124 /* find the node for this class */
125 for (boolean_option_node = node->xmlChildrenNode;
126 boolean_option_node;
127 boolean_option_node = boolean_option_node->next)
128 if (g_strcasecmp ((gchar *) boolean_option_node->name, "Value") == 0)
129 break;
130 if (! boolean_option_node)
131 {
132 pn_error ("unable to load a PnBooleanOption from xml node \"%s\"", node->name);
133 return;
134 }
135
136 val_str = (gchar *)xmlNodeGetContent (boolean_option_node);
137 if (! val_str)
138 goto done;
139
140 while (isspace ((int) *val_str))
141 val_str++;
142
143 if (g_strncasecmp (val_str, "True", 4) == 0)
144 boolean_option->value = TRUE;
145 else if (g_strncasecmp (val_str, "False", 5) == 0)
146 boolean_option->value = FALSE;
147 else
148 {
149 pn_error ("invalid boolean option value encountered at xml node \"%s\"", node->name);
150 return;
151 }
152
153 done:
154 if (parent_class->load_thyself)
155 parent_class->load_thyself (user_object, node);
156 }
157
158 PnBooleanOption*
159 pn_boolean_option_new (const gchar *name, const gchar *desc)
160 {
161 PnBooleanOption *boolean_option;
162
163 g_return_val_if_fail (name != NULL, NULL);
164 g_return_val_if_fail (desc != NULL, NULL);
165
166 boolean_option = (PnBooleanOption *) g_object_new (PN_TYPE_BOOLEAN_OPTION, NULL);
167
168 pn_user_object_set_name (PN_USER_OBJECT (boolean_option), name);
169 pn_user_object_set_description (PN_USER_OBJECT (boolean_option), desc);
170
171 return boolean_option;
172 }
173
174 void
175 pn_boolean_option_set_value (PnBooleanOption *boolean_option, gboolean value)
176 {
177 g_return_if_fail (boolean_option != NULL);
178 g_return_if_fail (PN_IS_BOOLEAN_OPTION (boolean_option));
179
180 boolean_option->value = value;
181 }
182
183 gboolean
184 pn_boolean_option_get_value (PnBooleanOption *boolean_option)
185 {
186 g_return_val_if_fail (boolean_option != NULL, FALSE);
187 g_return_val_if_fail (PN_IS_BOOLEAN_OPTION (boolean_option), FALSE);
188
189 return boolean_option->value;
190 }