Fix some functions descriptions
[pidgin-git.git] / libpurple / pluginpref.c
blob3fda42397e0e2fc17a7e800083220f465e33a736
1 /**
2 * purple
4 * Purple 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.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifdef HAVE_CONFIG_H
23 # include <config.h>
24 #endif
26 #include <glib.h>
28 #include "debug.h"
29 #include "internal.h"
30 #include "pluginpref.h"
31 #include "prefs.h"
33 struct _PurplePluginPrefFrame
35 GList *prefs;
38 struct _PurplePluginPref
40 char *name;
41 char *label;
43 PurplePluginPrefType type;
45 int min;
46 int max;
47 GList *choices;
48 unsigned int max_length;
49 gboolean masked;
50 PurpleStringFormatType format;
53 PurplePluginPrefFrame *
54 purple_plugin_pref_frame_new()
56 PurplePluginPrefFrame *frame;
58 frame = g_new0(PurplePluginPrefFrame, 1);
60 return frame;
63 void
64 purple_plugin_pref_frame_destroy(PurplePluginPrefFrame *frame)
66 g_return_if_fail(frame != NULL);
68 g_list_foreach(frame->prefs, (GFunc)purple_plugin_pref_destroy, NULL);
69 g_list_free(frame->prefs);
70 g_free(frame);
73 void
74 purple_plugin_pref_frame_add(PurplePluginPrefFrame *frame, PurplePluginPref *pref)
76 g_return_if_fail(frame != NULL);
77 g_return_if_fail(pref != NULL);
79 frame->prefs = g_list_append(frame->prefs, pref);
82 GList *
83 purple_plugin_pref_frame_get_prefs(PurplePluginPrefFrame *frame)
85 g_return_val_if_fail(frame != NULL, NULL);
86 g_return_val_if_fail(frame->prefs != NULL, NULL);
88 return frame->prefs;
91 PurplePluginPref *
92 purple_plugin_pref_new()
94 PurplePluginPref *pref;
96 pref = g_new0(PurplePluginPref, 1);
98 return pref;
101 PurplePluginPref *
102 purple_plugin_pref_new_with_name(const char *name)
104 PurplePluginPref *pref;
106 g_return_val_if_fail(name != NULL, NULL);
108 pref = g_new0(PurplePluginPref, 1);
109 pref->name = g_strdup(name);
111 return pref;
114 PurplePluginPref *
115 purple_plugin_pref_new_with_label(const char *label)
117 PurplePluginPref *pref;
119 g_return_val_if_fail(label != NULL, NULL);
121 pref = g_new0(PurplePluginPref, 1);
122 pref->label = g_strdup(label);
124 return pref;
127 PurplePluginPref *
128 purple_plugin_pref_new_with_name_and_label(const char *name, const char *label)
130 PurplePluginPref *pref;
132 g_return_val_if_fail(name != NULL, NULL);
133 g_return_val_if_fail(label != NULL, NULL);
135 pref = g_new0(PurplePluginPref, 1);
136 pref->name = g_strdup(name);
137 pref->label = g_strdup(label);
139 return pref;
142 void
143 purple_plugin_pref_destroy(PurplePluginPref *pref)
145 GList *tmp;
146 g_return_if_fail(pref != NULL);
148 g_free(pref->name);
149 g_free(pref->label);
150 tmp = pref->choices;
151 while(tmp) {
152 g_free(tmp->data);
153 /* Remove the string, and the data entries */
154 tmp = g_list_delete_link(tmp, tmp);
155 tmp = g_list_delete_link(tmp, tmp);
157 g_free(pref);
160 void
161 purple_plugin_pref_set_name(PurplePluginPref *pref, const char *name)
163 g_return_if_fail(pref != NULL);
164 g_return_if_fail(name != NULL);
166 g_free(pref->name);
167 pref->name = g_strdup(name);
170 const char *
171 purple_plugin_pref_get_name(PurplePluginPref *pref)
173 g_return_val_if_fail(pref != NULL, NULL);
175 return pref->name;
178 void
179 purple_plugin_pref_set_label(PurplePluginPref *pref, const char *label)
181 g_return_if_fail(pref != NULL);
182 g_return_if_fail(label != NULL);
184 g_free(pref->label);
185 pref->label = g_strdup(label);
188 const char *
189 purple_plugin_pref_get_label(PurplePluginPref *pref)
191 g_return_val_if_fail(pref != NULL, NULL);
193 return pref->label;
196 void
197 purple_plugin_pref_set_bounds(PurplePluginPref *pref, int min, int max)
199 int tmp;
201 g_return_if_fail(pref != NULL);
202 g_return_if_fail(pref->name != NULL);
204 if (purple_prefs_get_pref_type(pref->name) != PURPLE_PREF_INT)
206 purple_debug_warning("pluginpref",
207 "purple_plugin_pref_set_bounds: %s is not an integer pref\n",
208 pref->name);
209 return;
212 if (min > max)
214 tmp = min;
215 min = max;
216 max = tmp;
219 pref->min = min;
220 pref->max = max;
223 void purple_plugin_pref_get_bounds(PurplePluginPref *pref, int *min, int *max)
225 g_return_if_fail(pref != NULL);
226 g_return_if_fail(pref->name != NULL);
228 if (purple_prefs_get_pref_type(pref->name) != PURPLE_PREF_INT)
230 purple_debug_warning("pluginpref",
231 "purple_plugin_pref_get_bounds: %s is not an integer pref\n",
232 pref->name);
233 return;
236 *min = pref->min;
237 *max = pref->max;
240 void
241 purple_plugin_pref_set_pref_type(PurplePluginPref *pref, PurplePluginPrefType type)
243 g_return_if_fail(pref != NULL);
245 pref->type = type;
248 PurplePluginPrefType
249 purple_plugin_pref_get_pref_type(PurplePluginPref *pref)
251 g_return_val_if_fail(pref != NULL, PURPLE_PLUGIN_PREF_NONE);
253 return pref->type;
256 void
257 purple_plugin_pref_add_choice(PurplePluginPref *pref, const char *label, gpointer choice)
259 g_return_if_fail(pref != NULL);
260 g_return_if_fail(label != NULL);
261 g_return_if_fail(choice || purple_prefs_get_pref_type(pref->name) == PURPLE_PREF_INT);
263 pref->choices = g_list_append(pref->choices, g_strdup(label));
264 pref->choices = g_list_append(pref->choices, choice);
267 GList *
268 purple_plugin_pref_get_choices(PurplePluginPref *pref)
270 g_return_val_if_fail(pref != NULL, NULL);
272 return pref->choices;
275 void
276 purple_plugin_pref_set_max_length(PurplePluginPref *pref, unsigned int max_length)
278 g_return_if_fail(pref != NULL);
280 pref->max_length = max_length;
283 unsigned int
284 purple_plugin_pref_get_max_length(PurplePluginPref *pref)
286 g_return_val_if_fail(pref != NULL, 0);
288 return pref->max_length;
291 void
292 purple_plugin_pref_set_masked(PurplePluginPref *pref, gboolean masked)
294 g_return_if_fail(pref != NULL);
296 pref->masked = masked;
299 gboolean
300 purple_plugin_pref_get_masked(PurplePluginPref *pref)
302 g_return_val_if_fail(pref != NULL, FALSE);
304 return pref->masked;
307 void
308 purple_plugin_pref_set_format_type(PurplePluginPref *pref, PurpleStringFormatType format)
310 g_return_if_fail(pref != NULL);
311 g_return_if_fail(pref->type == PURPLE_PLUGIN_PREF_STRING_FORMAT);
313 pref->format = format;
316 PurpleStringFormatType
317 purple_plugin_pref_get_format_type(PurplePluginPref *pref)
319 g_return_val_if_fail(pref != NULL, 0);
321 if (pref->type != PURPLE_PLUGIN_PREF_STRING_FORMAT)
322 return PURPLE_STRING_FORMAT_TYPE_NONE;
324 return pref->format;