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
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
30 #include "pluginpref.h"
33 struct _PurplePluginPrefFrame
38 struct _PurplePluginPref
43 PurplePluginPrefType type
;
48 unsigned int max_length
;
50 PurpleStringFormatType format
;
53 PurplePluginPrefFrame
*
54 purple_plugin_pref_frame_new()
56 PurplePluginPrefFrame
*frame
;
58 frame
= g_new0(PurplePluginPrefFrame
, 1);
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
);
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
);
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
);
92 purple_plugin_pref_new()
94 PurplePluginPref
*pref
;
96 pref
= g_new0(PurplePluginPref
, 1);
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
);
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
);
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
);
143 purple_plugin_pref_destroy(PurplePluginPref
*pref
)
145 g_return_if_fail(pref
!= NULL
);
149 g_list_free(pref
->choices
);
154 purple_plugin_pref_set_name(PurplePluginPref
*pref
, const char *name
)
156 g_return_if_fail(pref
!= NULL
);
157 g_return_if_fail(name
!= NULL
);
160 pref
->name
= g_strdup(name
);
164 purple_plugin_pref_get_name(PurplePluginPref
*pref
)
166 g_return_val_if_fail(pref
!= NULL
, NULL
);
172 purple_plugin_pref_set_label(PurplePluginPref
*pref
, const char *label
)
174 g_return_if_fail(pref
!= NULL
);
175 g_return_if_fail(label
!= NULL
);
178 pref
->label
= g_strdup(label
);
182 purple_plugin_pref_get_label(PurplePluginPref
*pref
)
184 g_return_val_if_fail(pref
!= NULL
, NULL
);
190 purple_plugin_pref_set_bounds(PurplePluginPref
*pref
, int min
, int max
)
194 g_return_if_fail(pref
!= NULL
);
195 g_return_if_fail(pref
->name
!= NULL
);
197 if (purple_prefs_get_type(pref
->name
) != PURPLE_PREF_INT
)
199 purple_debug_warning("pluginpref",
200 "purple_plugin_pref_set_bounds: %s is not an integer pref\n",
216 void purple_plugin_pref_get_bounds(PurplePluginPref
*pref
, int *min
, int *max
)
218 g_return_if_fail(pref
!= NULL
);
219 g_return_if_fail(pref
->name
!= NULL
);
221 if (purple_prefs_get_type(pref
->name
) != PURPLE_PREF_INT
)
223 purple_debug_warning("pluginpref",
224 "purple_plugin_pref_get_bounds: %s is not an integer pref\n",
234 purple_plugin_pref_set_type(PurplePluginPref
*pref
, PurplePluginPrefType type
)
236 g_return_if_fail(pref
!= NULL
);
242 purple_plugin_pref_get_type(PurplePluginPref
*pref
)
244 g_return_val_if_fail(pref
!= NULL
, PURPLE_PLUGIN_PREF_NONE
);
250 purple_plugin_pref_add_choice(PurplePluginPref
*pref
, const char *label
, gpointer choice
)
252 g_return_if_fail(pref
!= NULL
);
253 g_return_if_fail(label
!= NULL
);
254 g_return_if_fail(choice
|| purple_prefs_get_type(pref
->name
) == PURPLE_PREF_INT
);
256 pref
->choices
= g_list_append(pref
->choices
, (gpointer
)label
);
257 pref
->choices
= g_list_append(pref
->choices
, choice
);
261 purple_plugin_pref_get_choices(PurplePluginPref
*pref
)
263 g_return_val_if_fail(pref
!= NULL
, NULL
);
265 return pref
->choices
;
269 purple_plugin_pref_set_max_length(PurplePluginPref
*pref
, unsigned int max_length
)
271 g_return_if_fail(pref
!= NULL
);
273 pref
->max_length
= max_length
;
277 purple_plugin_pref_get_max_length(PurplePluginPref
*pref
)
279 g_return_val_if_fail(pref
!= NULL
, 0);
281 return pref
->max_length
;
285 purple_plugin_pref_set_masked(PurplePluginPref
*pref
, gboolean masked
)
287 g_return_if_fail(pref
!= NULL
);
289 pref
->masked
= masked
;
293 purple_plugin_pref_get_masked(PurplePluginPref
*pref
)
295 g_return_val_if_fail(pref
!= NULL
, FALSE
);
301 purple_plugin_pref_set_format_type(PurplePluginPref
*pref
, PurpleStringFormatType format
)
303 g_return_if_fail(pref
!= NULL
);
304 g_return_if_fail(pref
->type
== PURPLE_PLUGIN_PREF_STRING_FORMAT
);
306 pref
->format
= format
;
309 PurpleStringFormatType
310 purple_plugin_pref_get_format_type(PurplePluginPref
*pref
)
312 g_return_val_if_fail(pref
!= NULL
, 0);
314 if (pref
->type
!= PURPLE_PLUGIN_PREF_STRING_FORMAT
)
315 return PURPLE_STRING_FORMAT_TYPE_NONE
;