2 * @file accountopt.c Account Options API
8 * Purple is the legal property of its developers, whose names are too numerous
9 * to list here. Please refer to the COPYRIGHT file distributed with this
10 * source distribution.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
28 #include "accountopt.h"
32 purple_account_option_new(PurplePrefType type
, const char *text
,
33 const char *pref_name
)
35 PurpleAccountOption
*option
;
37 g_return_val_if_fail(type
!= PURPLE_PREF_NONE
, NULL
);
38 g_return_val_if_fail(text
!= NULL
, NULL
);
39 g_return_val_if_fail(pref_name
!= NULL
, NULL
);
41 option
= g_new0(PurpleAccountOption
, 1);
44 option
->text
= g_strdup(text
);
45 option
->pref_name
= g_strdup(pref_name
);
51 purple_account_option_bool_new(const char *text
, const char *pref_name
,
52 gboolean default_value
)
54 PurpleAccountOption
*option
;
56 option
= purple_account_option_new(PURPLE_PREF_BOOLEAN
, text
, pref_name
);
61 option
->default_value
.boolean
= default_value
;
67 purple_account_option_int_new(const char *text
, const char *pref_name
,
70 PurpleAccountOption
*option
;
72 option
= purple_account_option_new(PURPLE_PREF_INT
, text
, pref_name
);
77 option
->default_value
.integer
= default_value
;
83 purple_account_option_string_new(const char *text
, const char *pref_name
,
84 const char *default_value
)
86 PurpleAccountOption
*option
;
88 option
= purple_account_option_new(PURPLE_PREF_STRING
, text
, pref_name
);
93 option
->default_value
.string
= g_strdup(default_value
);
99 purple_account_option_list_new(const char *text
, const char *pref_name
,
102 PurpleAccountOption
*option
;
104 option
= purple_account_option_new(PURPLE_PREF_STRING_LIST
, text
, pref_name
);
109 option
->default_value
.list
= list
;
115 purple_account_option_list_free(gpointer data
, gpointer user_data
)
117 PurpleKeyValuePair
*kvp
= data
;
125 purple_account_option_destroy(PurpleAccountOption
*option
)
127 g_return_if_fail(option
!= NULL
);
129 g_free(option
->text
);
130 g_free(option
->pref_name
);
132 if (option
->type
== PURPLE_PREF_STRING
)
134 g_free(option
->default_value
.string
);
136 else if (option
->type
== PURPLE_PREF_STRING_LIST
)
138 if (option
->default_value
.list
!= NULL
)
140 g_list_foreach(option
->default_value
.list
, purple_account_option_list_free
, NULL
);
141 g_list_free(option
->default_value
.list
);
149 purple_account_option_set_default_bool(PurpleAccountOption
*option
,
152 g_return_if_fail(option
!= NULL
);
153 g_return_if_fail(option
->type
== PURPLE_PREF_BOOLEAN
);
155 option
->default_value
.boolean
= value
;
159 purple_account_option_set_default_int(PurpleAccountOption
*option
, int value
)
161 g_return_if_fail(option
!= NULL
);
162 g_return_if_fail(option
->type
== PURPLE_PREF_INT
);
164 option
->default_value
.integer
= value
;
168 purple_account_option_set_default_string(PurpleAccountOption
*option
,
171 g_return_if_fail(option
!= NULL
);
172 g_return_if_fail(option
->type
== PURPLE_PREF_STRING
);
174 g_free(option
->default_value
.string
);
175 option
->default_value
.string
= g_strdup(value
);
179 purple_account_option_set_masked(PurpleAccountOption
*option
, gboolean masked
)
181 g_return_if_fail(option
!= NULL
);
182 g_return_if_fail(option
->type
== PURPLE_PREF_STRING
);
184 option
->masked
= masked
;
189 purple_account_option_set_list(PurpleAccountOption
*option
, GList
*values
)
191 g_return_if_fail(option
!= NULL
);
192 g_return_if_fail(option
->type
== PURPLE_PREF_STRING_LIST
);
194 if (option
->default_value
.list
!= NULL
)
196 g_list_foreach(option
->default_value
.list
, purple_account_option_list_free
, NULL
);
197 g_list_free(option
->default_value
.list
);
200 option
->default_value
.list
= values
;
204 purple_account_option_add_list_item(PurpleAccountOption
*option
,
205 const char *key
, const char *value
)
207 PurpleKeyValuePair
*kvp
;
209 g_return_if_fail(option
!= NULL
);
210 g_return_if_fail(key
!= NULL
);
211 g_return_if_fail(value
!= NULL
);
212 g_return_if_fail(option
->type
== PURPLE_PREF_STRING_LIST
);
214 kvp
= g_new0(PurpleKeyValuePair
, 1);
215 kvp
->key
= g_strdup(key
);
216 kvp
->value
= g_strdup(value
);
218 option
->default_value
.list
= g_list_append(option
->default_value
.list
,
223 purple_account_option_get_type(const PurpleAccountOption
*option
)
225 g_return_val_if_fail(option
!= NULL
, PURPLE_PREF_NONE
);
231 purple_account_option_get_text(const PurpleAccountOption
*option
)
233 g_return_val_if_fail(option
!= NULL
, NULL
);
239 purple_account_option_get_setting(const PurpleAccountOption
*option
)
241 g_return_val_if_fail(option
!= NULL
, NULL
);
243 return option
->pref_name
;
247 purple_account_option_get_default_bool(const PurpleAccountOption
*option
)
249 g_return_val_if_fail(option
!= NULL
, FALSE
);
250 g_return_val_if_fail(option
->type
== PURPLE_PREF_BOOLEAN
, FALSE
);
252 return option
->default_value
.boolean
;
256 purple_account_option_get_default_int(const PurpleAccountOption
*option
)
258 g_return_val_if_fail(option
!= NULL
, -1);
259 g_return_val_if_fail(option
->type
== PURPLE_PREF_INT
, -1);
261 return option
->default_value
.integer
;
265 purple_account_option_get_default_string(const PurpleAccountOption
*option
)
267 g_return_val_if_fail(option
!= NULL
, NULL
);
268 g_return_val_if_fail(option
->type
== PURPLE_PREF_STRING
, NULL
);
270 return option
->default_value
.string
;
274 purple_account_option_get_default_list_value(const PurpleAccountOption
*option
)
276 PurpleKeyValuePair
*kvp
;
278 g_return_val_if_fail(option
!= NULL
, NULL
);
279 g_return_val_if_fail(option
->type
== PURPLE_PREF_STRING_LIST
, NULL
);
281 if (option
->default_value
.list
== NULL
)
284 kvp
= option
->default_value
.list
->data
;
286 return (kvp
? kvp
->value
: NULL
);
290 purple_account_option_get_masked(const PurpleAccountOption
*option
)
292 g_return_val_if_fail(option
!= NULL
, FALSE
);
293 g_return_val_if_fail(option
->type
== PURPLE_PREF_STRING
, FALSE
);
295 return option
->masked
;
299 purple_account_option_get_list(const PurpleAccountOption
*option
)
301 g_return_val_if_fail(option
!= NULL
, NULL
);
302 g_return_val_if_fail(option
->type
== PURPLE_PREF_STRING_LIST
, NULL
);
304 return option
->default_value
.list
;
307 /**************************************************************************
308 * Account User Split API
309 **************************************************************************/
310 PurpleAccountUserSplit
*
311 purple_account_user_split_new(const char *text
, const char *default_value
,
314 PurpleAccountUserSplit
*split
;
316 g_return_val_if_fail(text
!= NULL
, NULL
);
317 g_return_val_if_fail(sep
!= 0, NULL
);
319 split
= g_new0(PurpleAccountUserSplit
, 1);
321 split
->text
= g_strdup(text
);
322 split
->field_sep
= sep
;
323 split
->default_value
= g_strdup(default_value
);
324 split
->reverse
= TRUE
;
330 purple_account_user_split_destroy(PurpleAccountUserSplit
*split
)
332 g_return_if_fail(split
!= NULL
);
335 g_free(split
->default_value
);
340 purple_account_user_split_get_text(const PurpleAccountUserSplit
*split
)
342 g_return_val_if_fail(split
!= NULL
, NULL
);
348 purple_account_user_split_get_default_value(const PurpleAccountUserSplit
*split
)
350 g_return_val_if_fail(split
!= NULL
, NULL
);
352 return split
->default_value
;
356 purple_account_user_split_get_separator(const PurpleAccountUserSplit
*split
)
358 g_return_val_if_fail(split
!= NULL
, 0);
360 return split
->field_sep
;
364 purple_account_user_split_get_reverse(const PurpleAccountUserSplit
*split
)
366 g_return_val_if_fail(split
!= NULL
, FALSE
);
368 return split
->reverse
;
372 purple_account_user_split_set_reverse(PurpleAccountUserSplit
*split
, gboolean reverse
)
374 g_return_if_fail(split
!= NULL
);
376 split
->reverse
= reverse
;