comparison src/accountopt.c @ 8570:1a62ab7225f3

[gaim-migrate @ 9318] This is what you've been waiting for, the infamous status rewrite! It's amazing, all the stuff it can do, and... oh wait, no, this is just basic core support for the list account option, which doesn't even have UI support yet. Sorry everyone. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 03 Apr 2004 03:30:57 +0000
parents fa6395637e2c
children 61930cadca7c
comparison
equal deleted inserted replaced
8569:ee13d1befabe 8570:1a62ab7225f3
28 gaim_account_option_new(GaimPrefType type, const char *text, 28 gaim_account_option_new(GaimPrefType type, const char *text,
29 const char *pref_name) 29 const char *pref_name)
30 { 30 {
31 GaimAccountOption *option; 31 GaimAccountOption *option;
32 32
33 g_return_val_if_fail(type == GAIM_PREF_BOOLEAN || 33 g_return_val_if_fail(type != GAIM_PREF_NONE, NULL);
34 type == GAIM_PREF_INT || 34 g_return_val_if_fail(text != NULL, NULL);
35 type == GAIM_PREF_STRING, 35 g_return_val_if_fail(pref_name != NULL, NULL);
36 NULL);
37 g_return_val_if_fail(text != NULL, NULL);
38 g_return_val_if_fail(pref_name != NULL, NULL);
39 36
40 option = g_new0(GaimAccountOption, 1); 37 option = g_new0(GaimAccountOption, 1);
41 38
42 option->type = type; 39 option->type = type;
43 option->text = g_strdup(text); 40 option->text = g_strdup(text);
93 option->default_value.string = g_strdup(default_value); 90 option->default_value.string = g_strdup(default_value);
94 91
95 return option; 92 return option;
96 } 93 }
97 94
95 GaimAccountOption *
96 gaim_account_option_list_new(const char *text, const char *pref_name,
97 GList *list)
98 {
99 GaimAccountOption *option;
100
101 option = gaim_account_option_new(GAIM_PREF_STRING_LIST, text, pref_name);
102
103 if (option == NULL)
104 return NULL;
105
106 option->default_value.list = list;
107
108 return option;
109 }
110
98 void 111 void
99 gaim_account_option_destroy(GaimAccountOption *option) 112 gaim_account_option_destroy(GaimAccountOption *option)
100 { 113 {
101 g_return_if_fail(option != NULL); 114 g_return_if_fail(option != NULL);
102 115
104 g_free(option->text); 117 g_free(option->text);
105 118
106 if (option->pref_name != NULL) 119 if (option->pref_name != NULL)
107 g_free(option->pref_name); 120 g_free(option->pref_name);
108 121
109 if (option->type == GAIM_PREF_STRING && 122 if (option->type == GAIM_PREF_STRING)
110 option->default_value.string != NULL) { 123 {
111 124 if (option->default_value.string != NULL)
112 g_free(option->default_value.string); 125 g_free(option->default_value.string);
126 }
127 else if (option->type == GAIM_PREF_STRING_LIST)
128 {
129 if (option->default_value.list != NULL)
130 {
131 g_list_foreach(option->default_value.list, (GFunc)g_free, NULL);
132 g_list_free(option->default_value.list);
133 }
113 } 134 }
114 135
115 g_free(option); 136 g_free(option);
116 } 137 }
117 138
145 g_free(option->default_value.string); 166 g_free(option->default_value.string);
146 167
147 option->default_value.string = (value == NULL ? NULL : g_strdup(value)); 168 option->default_value.string = (value == NULL ? NULL : g_strdup(value));
148 } 169 }
149 170
171 void
172 gaim_account_option_set_list(GaimAccountOption *option, GList *values)
173 {
174 g_return_if_fail(option != NULL);
175 g_return_if_fail(option->type == GAIM_PREF_STRING_LIST);
176
177 if (option->default_value.list != NULL)
178 {
179 g_list_foreach(option->default_value.list, (GFunc)g_free, NULL);
180 g_list_free(option->default_value.list);
181 }
182
183 option->default_value.list = values;
184 }
185
186 void
187 gaim_account_option_add_list_item(GaimAccountOption *option,
188 const char *key, const char *value)
189 {
190 g_return_if_fail(option != NULL);
191 g_return_if_fail(key != NULL);
192 g_return_if_fail(value != NULL);
193 g_return_if_fail(option->type == GAIM_PREF_STRING_LIST);
194
195 option->default_value.list = g_list_append(option->default_value.list,
196 g_strdup(key));
197 option->default_value.list = g_list_append(option->default_value.list,
198 g_strdup(value));
199 }
200
150 GaimPrefType 201 GaimPrefType
151 gaim_account_option_get_type(const GaimAccountOption *option) 202 gaim_account_option_get_type(const GaimAccountOption *option)
152 { 203 {
153 g_return_val_if_fail(option != NULL, GAIM_PREF_NONE); 204 g_return_val_if_fail(option != NULL, GAIM_PREF_NONE);
154 205
196 g_return_val_if_fail(option->type == GAIM_PREF_STRING, NULL); 247 g_return_val_if_fail(option->type == GAIM_PREF_STRING, NULL);
197 248
198 return option->default_value.string; 249 return option->default_value.string;
199 } 250 }
200 251
201 252 const GList *
253 gaim_account_option_get_list(const GaimAccountOption *option)
254 {
255 g_return_val_if_fail(option != NULL, NULL);
256 g_return_val_if_fail(option->type == GAIM_PREF_STRING_LIST, NULL);
257
258 return option->default_value.list;
259 }
260
261 /**************************************************************************
262 * Account User Split API
263 **************************************************************************/
202 GaimAccountUserSplit * 264 GaimAccountUserSplit *
203 gaim_account_user_split_new(const char *text, const char *default_value, 265 gaim_account_user_split_new(const char *text, const char *default_value,
204 char sep) 266 char sep)
205 { 267 {
206 GaimAccountUserSplit *split; 268 GaimAccountUserSplit *split;