Mercurial > pidgin
annotate src/pluginpref.c @ 13399:18d5d4018604
[gaim-migrate @ 15773]
Dereferencing the pointer-pointer to check if it's NULL. Oops, my bad.
Resolves CID 11
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 06 Mar 2006 17:01:32 +0000 |
parents | 16f6d6f8afc7 |
children | 8bda65b88e49 |
rev | line source |
---|---|
8713 | 1 /** |
2 * gaim | |
3 * | |
4 * Gaim is the legal property of its developers, whose names are too numerous | |
5 * to list here. Please refer to the COPYRIGHT file distributed with this | |
6 * source distribution. | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #ifdef HAVE_CONFIG_H | |
23 # include <config.h> | |
24 #endif | |
25 | |
26 #include <glib.h> | |
27 | |
28 #include "debug.h" | |
29 #include "internal.h" | |
30 #include "pluginpref.h" | |
31 #include "prefs.h" | |
32 | |
33 struct _GaimPluginPrefFrame { | |
34 GList *prefs; | |
35 }; | |
36 | |
37 struct _GaimPluginPref { | |
38 char *name; | |
39 char *label; | |
40 | |
41 GaimPluginPrefType type; | |
42 | |
43 int min; | |
44 int max; | |
45 GList *choices; | |
46 unsigned int max_length; | |
9841 | 47 gboolean masked; |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
48 GaimStringFormatType format; |
8713 | 49 }; |
50 | |
51 GaimPluginPrefFrame * | |
52 gaim_plugin_pref_frame_new() { | |
53 GaimPluginPrefFrame *frame; | |
54 | |
55 frame = g_new0(GaimPluginPrefFrame, 1); | |
56 | |
57 return frame; | |
58 } | |
59 | |
60 void | |
61 gaim_plugin_pref_frame_destroy(GaimPluginPrefFrame *frame) { | |
62 GaimPluginPref *pref; | |
8745 | 63 GList *l; |
8713 | 64 |
65 g_return_if_fail(frame); | |
66 | |
8745 | 67 for(l = frame->prefs; l != NULL; l = l->next) { |
8713 | 68 pref = (GaimPluginPref *)l->data; |
69 gaim_plugin_pref_destroy(pref); | |
70 } | |
71 | |
8745 | 72 g_list_free(frame->prefs); |
73 frame->prefs = NULL; | |
74 | |
75 g_free(frame); | |
8713 | 76 frame = NULL; |
77 } | |
78 | |
79 void | |
80 gaim_plugin_pref_frame_add(GaimPluginPrefFrame *frame, GaimPluginPref *pref) { | |
81 g_return_if_fail(frame); | |
82 g_return_if_fail(pref); | |
83 | |
8745 | 84 frame->prefs = g_list_append(frame->prefs, pref); |
8713 | 85 } |
86 | |
87 GList * | |
88 gaim_plugin_pref_frame_get_prefs(GaimPluginPrefFrame *frame) { | |
8745 | 89 g_return_val_if_fail(frame, NULL); |
90 g_return_val_if_fail(frame->prefs, NULL); | |
91 | |
8713 | 92 return frame->prefs; |
93 } | |
94 | |
95 GaimPluginPref * | |
96 gaim_plugin_pref_new() { | |
97 GaimPluginPref *pref; | |
98 | |
99 pref = g_new0(GaimPluginPref, 1); | |
100 | |
101 return pref; | |
102 } | |
103 | |
104 GaimPluginPref * | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
105 gaim_plugin_pref_new_with_name(const char *name) { |
8713 | 106 GaimPluginPref *pref; |
107 | |
108 g_return_val_if_fail(name, NULL); | |
109 | |
110 pref = g_new0(GaimPluginPref, 1); | |
111 pref->name = g_strdup(name); | |
112 | |
113 return pref; | |
114 } | |
115 | |
116 GaimPluginPref * | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
117 gaim_plugin_pref_new_with_label(const char *label) { |
8713 | 118 GaimPluginPref *pref; |
119 | |
120 g_return_val_if_fail(label, NULL); | |
121 | |
122 pref = g_new0(GaimPluginPref, 1); | |
123 pref->label = g_strdup(label); | |
124 | |
125 return pref; | |
126 } | |
127 | |
128 GaimPluginPref * | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
129 gaim_plugin_pref_new_with_name_and_label(const char *name, const char *label) { |
8713 | 130 GaimPluginPref *pref; |
131 | |
132 g_return_val_if_fail(name, NULL); | |
133 g_return_val_if_fail(label, NULL); | |
134 | |
135 pref = g_new0(GaimPluginPref, 1); | |
136 pref->name = g_strdup(name); | |
137 pref->label = g_strdup(label); | |
138 | |
139 return pref; | |
140 } | |
141 | |
142 void | |
143 gaim_plugin_pref_destroy(GaimPluginPref *pref) { | |
144 g_return_if_fail(pref); | |
145 | |
8745 | 146 if(pref->name) { |
8713 | 147 g_free(pref->name); |
8745 | 148 pref->name = NULL; |
149 } | |
8713 | 150 |
8745 | 151 if(pref->label) { |
152 g_free(pref->label); | |
153 pref->label = NULL; | |
154 } | |
8713 | 155 |
8745 | 156 if(pref->choices) { |
157 g_list_free(pref->choices); | |
158 pref->choices = NULL; | |
8713 | 159 } |
160 | |
161 g_free(pref); | |
162 } | |
163 | |
164 void | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
165 gaim_plugin_pref_set_name(GaimPluginPref *pref, const char *name) { |
8713 | 166 g_return_if_fail(pref); |
167 g_return_if_fail(name); | |
168 | |
169 if(pref->name) | |
170 g_free(pref->name); | |
171 | |
172 pref->name = g_strdup(name); | |
173 } | |
174 | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
175 const char * |
8713 | 176 gaim_plugin_pref_get_name(GaimPluginPref *pref) { |
177 g_return_val_if_fail(pref, NULL); | |
178 | |
179 return pref->name; | |
180 } | |
181 | |
182 void | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
183 gaim_plugin_pref_set_label(GaimPluginPref *pref, const char *label) { |
8713 | 184 g_return_if_fail(pref); |
185 g_return_if_fail(label); | |
186 | |
187 if(pref->label) | |
188 g_free(pref->label); | |
189 | |
190 pref->label = g_strdup(label); | |
191 } | |
192 | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
193 const char * |
8713 | 194 gaim_plugin_pref_get_label(GaimPluginPref *pref) { |
195 g_return_val_if_fail(pref, NULL); | |
196 | |
197 return pref->label; | |
198 } | |
199 | |
200 void | |
201 gaim_plugin_pref_set_bounds(GaimPluginPref *pref, int min, int max) { | |
202 int tmp; | |
203 | |
204 g_return_if_fail(pref); | |
205 g_return_if_fail(pref->name); | |
206 | |
207 if(gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) { | |
208 gaim_debug(GAIM_DEBUG_INFO, "pluginpref", | |
209 "gaim_plugin_pref_set_bounds: %s is not an integer pref\n", | |
210 pref->name); | |
211 return; | |
212 } | |
10414 | 213 |
8713 | 214 if(min > max) { |
215 tmp = min; | |
216 min = max; | |
217 max = tmp; | |
218 } | |
219 | |
220 pref->min = min; | |
221 pref->max = max; | |
222 } | |
223 | |
224 void gaim_plugin_pref_get_bounds(GaimPluginPref *pref, int *min, int *max) { | |
225 g_return_if_fail(pref); | |
226 g_return_if_fail(pref->name); | |
227 | |
228 if(gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) { | |
229 gaim_debug(GAIM_DEBUG_INFO, "pluginpref", | |
230 "gaim_plugin_pref_get_bounds: %s is not an integer pref\n", | |
231 pref->name); | |
232 return; | |
233 } | |
234 | |
235 *min = pref->min; | |
236 *max = pref->max; | |
237 } | |
238 | |
239 void | |
240 gaim_plugin_pref_set_type(GaimPluginPref *pref, GaimPluginPrefType type) { | |
241 g_return_if_fail(pref); | |
242 | |
243 pref->type = type; | |
244 } | |
245 | |
246 GaimPluginPrefType | |
247 gaim_plugin_pref_get_type(GaimPluginPref *pref) { | |
248 g_return_val_if_fail(pref, GAIM_PLUGIN_PREF_NONE); | |
249 | |
250 return pref->type; | |
251 } | |
252 | |
253 void | |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
254 gaim_plugin_pref_add_choice(GaimPluginPref *pref, const char *label, gpointer choice) { |
8713 | 255 g_return_if_fail(pref); |
256 g_return_if_fail(label); | |
13268
16f6d6f8afc7
[gaim-migrate @ 15634]
Richard Laager <rlaager@wiktel.com>
parents:
13106
diff
changeset
|
257 g_return_if_fail(choice || gaim_prefs_get_type(pref->name) == GAIM_PREF_INT); |
8713 | 258 |
13106
a0a4b44239e8
[gaim-migrate @ 15468]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
259 pref->choices = g_list_append(pref->choices, (gpointer)label); |
8713 | 260 pref->choices = g_list_append(pref->choices, choice); |
261 } | |
262 | |
263 GList * | |
264 gaim_plugin_pref_get_choices(GaimPluginPref *pref) { | |
265 g_return_val_if_fail(pref, NULL); | |
266 | |
267 return pref->choices; | |
268 } | |
269 | |
270 void | |
271 gaim_plugin_pref_set_max_length(GaimPluginPref *pref, unsigned int max_length) { | |
272 g_return_if_fail(pref); | |
273 | |
274 pref->max_length = max_length; | |
275 } | |
276 | |
277 unsigned int | |
278 gaim_plugin_pref_get_max_length(GaimPluginPref *pref) { | |
279 g_return_val_if_fail(pref, 0); | |
280 | |
281 return pref->max_length; | |
282 } | |
9841 | 283 |
284 void | |
285 gaim_plugin_pref_set_masked(GaimPluginPref *pref, gboolean masked) { | |
286 g_return_if_fail(pref); | |
287 | |
288 pref->masked = masked; | |
289 } | |
290 | |
291 gboolean | |
292 gaim_plugin_pref_get_masked(GaimPluginPref *pref) { | |
293 g_return_val_if_fail(pref, FALSE); | |
294 | |
295 return pref->masked; | |
296 } | |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
297 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
298 void |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
299 gaim_plugin_pref_set_format_type(GaimPluginPref *pref, GaimStringFormatType format) |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
300 { |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
301 g_return_if_fail(pref); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
302 g_return_if_fail(pref->type == GAIM_PLUGIN_PREF_STRING_FORMAT); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
303 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
304 pref->format = format; |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
305 } |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
306 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
307 GaimStringFormatType |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
308 gaim_plugin_pref_get_format_type(GaimPluginPref *pref) |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
309 { |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
310 g_return_val_if_fail(pref, 0); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
311 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
312 if (pref->type != GAIM_PLUGIN_PREF_STRING_FORMAT) |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
313 return GAIM_STRING_FORMAT_TYPE_NONE; |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
314 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
315 return pref->format; |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
316 } |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
10414
diff
changeset
|
317 |