comparison src/accountopt.c @ 5639:408fef845144

[gaim-migrate @ 6051] Forgot to add these files. Oops. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 01 Jun 2003 19:34:26 +0000
parents
children c52a97f3739e
comparison
equal deleted inserted replaced
5638:0bdfa28c678e 5639:408fef845144
1 /**
2 * @file accountopt.c Account Options API
3 * @ingroup core
4 *
5 * gaim
6 *
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 #include "accountopt.h"
24
25 GaimAccountOption *
26 gaim_account_option_new(GaimPrefType type, const char *text,
27 const char *pref_name)
28 {
29 GaimAccountOption *option;
30
31 g_return_val_if_fail(type == GAIM_PREF_BOOLEAN ||
32 type == GAIM_PREF_INT ||
33 type == GAIM_PREF_STRING,
34 NULL);
35 g_return_val_if_fail(text != NULL, NULL);
36 g_return_val_if_fail(pref_name != NULL, NULL);
37
38 option = g_new0(GaimAccountOption, 1);
39
40 option->type = type;
41 option->text = g_strdup(text);
42 option->pref_name = g_strdup(pref_name);
43
44 return option;
45 }
46
47 GaimAccountOption *
48 gaim_account_option_bool_new(const char *text, const char *pref_name,
49 gboolean default_value)
50 {
51 GaimAccountOption *option;
52
53 option = gaim_account_option_new(GAIM_PREF_BOOLEAN, text, pref_name);
54
55 if (option == NULL)
56 return NULL;
57
58 option->default_value.boolean = default_value;
59
60 return option;
61 }
62
63 GaimAccountOption *
64 gaim_account_option_int_new(const char *text, const char *pref_name,
65 int default_value)
66 {
67 GaimAccountOption *option;
68
69 option = gaim_account_option_new(GAIM_PREF_INT, text, pref_name);
70
71 if (option == NULL)
72 return NULL;
73
74 option->default_value.integer = default_value;
75
76 return option;
77 }
78
79 GaimAccountOption *
80 gaim_account_option_string_new(const char *text, const char *pref_name,
81 const char *default_value)
82 {
83 GaimAccountOption *option;
84
85 option = gaim_account_option_new(GAIM_PREF_STRING, text, pref_name);
86
87 if (option == NULL)
88 return NULL;
89
90 if (default_value != NULL)
91 option->default_value.string = g_strdup(default_value);
92
93 return option;
94 }
95
96 void
97 gaim_account_option_destroy(GaimAccountOption *option)
98 {
99 g_return_if_fail(option != NULL);
100
101 if (option->text != NULL)
102 g_free(option->text);
103
104 if (option->pref_name != NULL)
105 g_free(option->pref_name);
106
107 if (option->type == GAIM_PREF_STRING &&
108 option->default_value.string != NULL) {
109
110 g_free(option->default_value.string);
111 }
112
113 g_free(option);
114 }
115
116 void
117 gaim_account_option_set_default_bool(GaimAccountOption *option,
118 gboolean value)
119 {
120 g_return_if_fail(option != NULL);
121 g_return_if_fail(option->type == GAIM_PREF_BOOLEAN);
122
123 option->default_value.boolean = value;
124 }
125
126 void
127 gaim_account_option_set_default_int(GaimAccountOption *option, int value)
128 {
129 g_return_if_fail(option != NULL);
130 g_return_if_fail(option->type == GAIM_PREF_INT);
131
132 option->default_value.integer = value;
133 }
134
135 void
136 gaim_account_option_set_default_string(GaimAccountOption *option,
137 const char *value)
138 {
139 g_return_if_fail(option != NULL);
140 g_return_if_fail(option->type == GAIM_PREF_STRING);
141
142 if (option->default_value.string != NULL)
143 g_free(option->default_value.string);
144
145 option->default_value.string = (value == NULL ? NULL : g_strdup(value));
146 }
147
148 GaimPrefType
149 gaim_account_option_get_type(const GaimAccountOption *option)
150 {
151 g_return_val_if_fail(option != NULL, GAIM_PREF_NONE);
152
153 return option->type;
154 }
155
156 const char *
157 gaim_account_option_get_text(const GaimAccountOption *option)
158 {
159 g_return_val_if_fail(option != NULL, NULL);
160
161 return option->text;
162 }
163
164 gboolean
165 gaim_account_option_get_default_bool(const GaimAccountOption *option)
166 {
167 g_return_val_if_fail(option != NULL, FALSE);
168 g_return_val_if_fail(option->type != GAIM_PREF_BOOLEAN, FALSE);
169
170 return option->default_value.boolean;
171 }
172
173 int
174 gaim_account_option_get_default_int(const GaimAccountOption *option)
175 {
176 g_return_val_if_fail(option != NULL, -1);
177 g_return_val_if_fail(option->type != GAIM_PREF_INT, -1);
178
179 return option->default_value.integer;
180 }
181
182 const char *
183 gaim_account_option_get_default_string(const GaimAccountOption *option)
184 {
185 g_return_val_if_fail(option != NULL, NULL);
186 g_return_val_if_fail(option->type != GAIM_PREF_STRING, NULL);
187
188 return option->default_value.string;
189 }
190
191
192 GaimAccountUserSplit *
193 gaim_account_user_split_new(const char *text, const char *default_value,
194 char sep)
195 {
196 GaimAccountUserSplit *split;
197
198 g_return_val_if_fail(text != NULL, NULL);
199 g_return_val_if_fail(sep != 0, NULL);
200
201 split = g_new0(GaimAccountUserSplit, 1);
202
203 split->text = g_strdup(text);
204 split->field_sep = sep;
205 split->default_value = (default_value == NULL
206 ? NULL : g_strdup(default_value));
207
208 return split;
209 }
210
211 void
212 gaim_account_user_split_destroy(GaimAccountUserSplit *split)
213 {
214 g_return_if_fail(split != NULL);
215
216 if (split->text != NULL)
217 g_free(split->text);
218
219 if (split->default_value != NULL)
220 g_free(split->default_value);
221
222 g_free(split);
223 }
224
225 const char *
226 gaim_account_split_get_default_value(const GaimAccountUserSplit *split)
227 {
228 g_return_val_if_fail(split != NULL, NULL);
229
230 return split->default_value;
231 }
232
233 char
234 gaim_account_split_get_separator(const GaimAccountUserSplit *split)
235 {
236 g_return_val_if_fail(split != NULL, 0);
237
238 return split->field_sep;
239 }