Mercurial > audlegacy
comparison Plugins/Visualization/paranormal/pn/pnstringoption.c @ 1507:0c5fdcf3f947 trunk
[svn] - incomplete stuff
author | nenolod |
---|---|
date | Sun, 06 Aug 2006 01:53:29 -0700 |
parents | |
children | 02841f72b897 |
comparison
equal
deleted
inserted
replaced
1506:2a8e193c07a6 | 1507:0c5fdcf3f947 |
---|---|
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 "pnstringoption.h" | |
24 #include "pnxml.h" | |
25 #include "pnerror.h" | |
26 | |
27 static void pn_string_option_class_init (PnStringOptionClass *class); | |
28 static void pn_string_option_init (PnStringOption *string_option, | |
29 PnStringOptionClass *class); | |
30 | |
31 /* PnUserObject methods */ | |
32 static void pn_string_option_save_thyself (PnUserObject *user_object, | |
33 xmlNodePtr node); | |
34 static void pn_string_option_load_thyself (PnUserObject *user_object, | |
35 xmlNodePtr node); | |
36 | |
37 static PnUserObjectClass *parent_class = NULL; | |
38 static gchar * const empty_string = ""; | |
39 | |
40 GType | |
41 pn_string_option_get_type (void) | |
42 { | |
43 static GType string_option_type = 0; | |
44 | |
45 if (! string_option_type) | |
46 { | |
47 static const GTypeInfo string_option_info = | |
48 { | |
49 sizeof (PnStringOptionClass), | |
50 NULL, /* base_init */ | |
51 NULL, /* base_finalize */ | |
52 (GClassInitFunc) pn_string_option_class_init, | |
53 NULL, /* class_finalize */ | |
54 NULL, /* class_data */ | |
55 sizeof (PnStringOption), | |
56 0, /* n_preallocs */ | |
57 (GInstanceInitFunc) pn_string_option_init | |
58 }; | |
59 | |
60 /* FIXME: should this be dynamic? */ | |
61 string_option_type = g_type_register_static (PN_TYPE_OPTION, | |
62 "PnStringOption", | |
63 &string_option_info, | |
64 0); | |
65 } | |
66 return string_option_type; | |
67 } | |
68 | |
69 static void | |
70 pn_string_option_class_init (PnStringOptionClass *class) | |
71 { | |
72 PnObjectClass *object_class; | |
73 PnUserObjectClass *user_object_class; | |
74 PnOptionClass *option_class; | |
75 | |
76 parent_class = g_type_class_peek_parent (class); | |
77 | |
78 object_class = (PnObjectClass *) class; | |
79 user_object_class = (PnUserObjectClass *) class; | |
80 option_class = (PnOptionClass *) class; | |
81 | |
82 /* PnUserObject methods */ | |
83 user_object_class->save_thyself = pn_string_option_save_thyself; | |
84 user_object_class->load_thyself = pn_string_option_load_thyself; | |
85 | |
86 /* PnOption methods */ | |
87 /* FIXME: this needs to be uncommented when the widget is done */ | |
88 /* option_class->widget_type = PN_TYPE_STRING_OPTION_WIDGET; */ | |
89 } | |
90 | |
91 static void | |
92 pn_string_option_init (PnStringOption *string_option, PnStringOptionClass *class) | |
93 { | |
94 string_option->value = empty_string; | |
95 } | |
96 | |
97 static void | |
98 pn_string_option_save_thyself (PnUserObject *user_object, xmlNodePtr node) | |
99 { | |
100 PnStringOption *string_option; | |
101 xmlNodePtr value_node; | |
102 | |
103 g_return_if_fail (user_object != NULL); | |
104 g_return_if_fail (PN_IS_STRING_OPTION (user_object)); | |
105 g_return_if_fail (node != NULL); | |
106 | |
107 string_option = (PnStringOption *) user_object; | |
108 value_node = xmlNewChild (node, NULL, "Value", NULL); | |
109 xmlNodeSetContent (value_node, string_option->value); | |
110 | |
111 if (parent_class->save_thyself) | |
112 parent_class->save_thyself (user_object, node); | |
113 } | |
114 | |
115 static void | |
116 pn_string_option_load_thyself (PnUserObject *user_object, const xmlNodePtr node) | |
117 { | |
118 PnStringOption *string_option; | |
119 xmlNodePtr string_option_node; | |
120 gchar *val_str; | |
121 | |
122 g_return_if_fail (user_object != NULL); | |
123 g_return_if_fail (PN_IS_STRING_OPTION (user_object)); | |
124 g_return_if_fail (node != NULL); | |
125 | |
126 string_option = (PnStringOption *) user_object; | |
127 | |
128 for (string_option_node = node->xmlChildrenNode; | |
129 string_option_node; | |
130 string_option_node = string_option_node->next) | |
131 if (g_strcasecmp (string_option_node->name, "Value") == 0) | |
132 break; | |
133 if (! string_option_node) | |
134 { | |
135 pn_error ("unable to load a PnStringOption from xml node \"%s\"", node->name); | |
136 return; | |
137 } | |
138 | |
139 val_str = xmlNodeGetContent (string_option_node); | |
140 if (val_str) | |
141 pn_string_option_set_value (string_option, val_str); | |
142 else | |
143 pn_string_option_set_value (string_option, empty_string); | |
144 | |
145 if (parent_class->load_thyself) | |
146 parent_class->load_thyself (user_object, node); | |
147 } | |
148 | |
149 PnStringOption* | |
150 pn_string_option_new (const gchar *name, const gchar *desc) | |
151 { | |
152 PnStringOption *string_option; | |
153 | |
154 g_return_val_if_fail (name != NULL, NULL); | |
155 g_return_val_if_fail (desc != NULL, NULL); | |
156 | |
157 string_option = (PnStringOption *) g_object_new (PN_TYPE_STRING_OPTION, NULL); | |
158 | |
159 pn_user_object_set_name (PN_USER_OBJECT (string_option), name); | |
160 pn_user_object_set_description (PN_USER_OBJECT (string_option), desc); | |
161 | |
162 return string_option; | |
163 } | |
164 | |
165 void | |
166 pn_string_option_set_value (PnStringOption *string_option, const gchar *value) | |
167 { | |
168 g_return_if_fail (string_option != NULL); | |
169 g_return_if_fail (PN_IS_STRING_OPTION (string_option)); | |
170 g_return_if_fail (value != NULL); | |
171 | |
172 if (string_option->value && string_option->value != empty_string) | |
173 g_free (string_option->value); | |
174 | |
175 string_option->value = g_strdup (value); | |
176 } | |
177 | |
178 gchar* | |
179 pn_string_option_get_value (PnStringOption *string_option) | |
180 { | |
181 g_return_val_if_fail (string_option != NULL, FALSE); | |
182 g_return_val_if_fail (PN_IS_STRING_OPTION (string_option), FALSE); | |
183 | |
184 return string_option->value; | |
185 } |