Mercurial > pidgin.yaz
annotate src/accountopt.c @ 7062:86ed8b2aa665
[gaim-migrate @ 7626]
g_show_info_text() is gone! Mwahahaha.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 30 Sep 2003 06:43:17 +0000 |
parents | e30bedfb99db |
children | fa6395637e2c |
rev | line source |
---|---|
5639 | 1 /** |
2 * @file accountopt.c Account Options API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
6902
e30bedfb99db
[gaim-migrate @ 7449]
Christian Hammond <chipx86@chipx86.com>
parents:
5663
diff
changeset
|
8 * |
5639 | 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; | |
6902
e30bedfb99db
[gaim-migrate @ 7449]
Christian Hammond <chipx86@chipx86.com>
parents:
5663
diff
changeset
|
52 |
5639 | 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; | |
6902
e30bedfb99db
[gaim-migrate @ 7449]
Christian Hammond <chipx86@chipx86.com>
parents:
5663
diff
changeset
|
68 |
5639 | 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; | |
6902
e30bedfb99db
[gaim-migrate @ 7449]
Christian Hammond <chipx86@chipx86.com>
parents:
5663
diff
changeset
|
84 |
5639 | 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 | |
5660
1709a545a7bd
[gaim-migrate @ 6074]
Christian Hammond <chipx86@chipx86.com>
parents:
5654
diff
changeset
|
164 const char * |
1709a545a7bd
[gaim-migrate @ 6074]
Christian Hammond <chipx86@chipx86.com>
parents:
5654
diff
changeset
|
165 gaim_account_option_get_setting(const GaimAccountOption *option) |
1709a545a7bd
[gaim-migrate @ 6074]
Christian Hammond <chipx86@chipx86.com>
parents:
5654
diff
changeset
|
166 { |
1709a545a7bd
[gaim-migrate @ 6074]
Christian Hammond <chipx86@chipx86.com>
parents:
5654
diff
changeset
|
167 g_return_val_if_fail(option != NULL, NULL); |
1709a545a7bd
[gaim-migrate @ 6074]
Christian Hammond <chipx86@chipx86.com>
parents:
5654
diff
changeset
|
168 |
1709a545a7bd
[gaim-migrate @ 6074]
Christian Hammond <chipx86@chipx86.com>
parents:
5654
diff
changeset
|
169 return option->pref_name; |
1709a545a7bd
[gaim-migrate @ 6074]
Christian Hammond <chipx86@chipx86.com>
parents:
5654
diff
changeset
|
170 } |
1709a545a7bd
[gaim-migrate @ 6074]
Christian Hammond <chipx86@chipx86.com>
parents:
5654
diff
changeset
|
171 |
5639 | 172 gboolean |
173 gaim_account_option_get_default_bool(const GaimAccountOption *option) | |
174 { | |
175 g_return_val_if_fail(option != NULL, FALSE); | |
5663
e9551e7d6f01
[gaim-migrate @ 6077]
Christian Hammond <chipx86@chipx86.com>
parents:
5660
diff
changeset
|
176 g_return_val_if_fail(option->type == GAIM_PREF_BOOLEAN, FALSE); |
5639 | 177 |
178 return option->default_value.boolean; | |
179 } | |
180 | |
181 int | |
182 gaim_account_option_get_default_int(const GaimAccountOption *option) | |
183 { | |
184 g_return_val_if_fail(option != NULL, -1); | |
5663
e9551e7d6f01
[gaim-migrate @ 6077]
Christian Hammond <chipx86@chipx86.com>
parents:
5660
diff
changeset
|
185 g_return_val_if_fail(option->type == GAIM_PREF_INT, -1); |
5639 | 186 |
187 return option->default_value.integer; | |
188 } | |
189 | |
190 const char * | |
191 gaim_account_option_get_default_string(const GaimAccountOption *option) | |
192 { | |
193 g_return_val_if_fail(option != NULL, NULL); | |
5663
e9551e7d6f01
[gaim-migrate @ 6077]
Christian Hammond <chipx86@chipx86.com>
parents:
5660
diff
changeset
|
194 g_return_val_if_fail(option->type == GAIM_PREF_STRING, NULL); |
5639 | 195 |
196 return option->default_value.string; | |
197 } | |
198 | |
199 | |
200 GaimAccountUserSplit * | |
201 gaim_account_user_split_new(const char *text, const char *default_value, | |
202 char sep) | |
203 { | |
204 GaimAccountUserSplit *split; | |
205 | |
206 g_return_val_if_fail(text != NULL, NULL); | |
207 g_return_val_if_fail(sep != 0, NULL); | |
208 | |
209 split = g_new0(GaimAccountUserSplit, 1); | |
210 | |
211 split->text = g_strdup(text); | |
212 split->field_sep = sep; | |
213 split->default_value = (default_value == NULL | |
214 ? NULL : g_strdup(default_value)); | |
215 | |
216 return split; | |
217 } | |
218 | |
219 void | |
220 gaim_account_user_split_destroy(GaimAccountUserSplit *split) | |
221 { | |
222 g_return_if_fail(split != NULL); | |
223 | |
224 if (split->text != NULL) | |
225 g_free(split->text); | |
226 | |
227 if (split->default_value != NULL) | |
228 g_free(split->default_value); | |
229 | |
230 g_free(split); | |
231 } | |
232 | |
233 const char * | |
5654
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
234 gaim_account_user_split_get_text(const GaimAccountUserSplit *split) |
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
235 { |
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
236 g_return_val_if_fail(split != NULL, NULL); |
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
237 |
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
238 return split->text; |
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
239 } |
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
240 |
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
241 const char * |
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
242 gaim_account_user_split_get_default_value(const GaimAccountUserSplit *split) |
5639 | 243 { |
244 g_return_val_if_fail(split != NULL, NULL); | |
245 | |
246 return split->default_value; | |
247 } | |
248 | |
249 char | |
5654
c52a97f3739e
[gaim-migrate @ 6068]
Christian Hammond <chipx86@chipx86.com>
parents:
5639
diff
changeset
|
250 gaim_account_user_split_get_separator(const GaimAccountUserSplit *split) |
5639 | 251 { |
252 g_return_val_if_fail(split != NULL, 0); | |
253 | |
254 return split->field_sep; | |
255 } |