8713
|
1 /**
|
|
2 * gaim
|
|
3 *
|
|
4 * Gaim 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
|
|
6 * source distribution.
|
|
7 *
|
|
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.
|
|
12 *
|
|
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.
|
|
17 *
|
|
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22 #ifdef HAVE_CONFIG_H
|
|
23 # include <config.h>
|
|
24 #endif
|
|
25
|
|
26 #include <glib.h>
|
|
27
|
|
28 #include "debug.h"
|
|
29 #include "internal.h"
|
|
30 #include "pluginpref.h"
|
|
31 #include "prefs.h"
|
|
32
|
|
33 struct _GaimPluginPrefFrame {
|
|
34 GList *prefs;
|
|
35 };
|
|
36
|
|
37 struct _GaimPluginPref {
|
|
38 char *name;
|
|
39 char *label;
|
|
40
|
|
41 GaimPluginPrefType type;
|
|
42
|
|
43 int min;
|
|
44 int max;
|
|
45 GList *choices;
|
|
46 unsigned int max_length;
|
|
47 };
|
|
48
|
|
49 GaimPluginPrefFrame *
|
|
50 gaim_plugin_pref_frame_new() {
|
|
51 GaimPluginPrefFrame *frame;
|
|
52
|
|
53 frame = g_new0(GaimPluginPrefFrame, 1);
|
|
54
|
|
55 return frame;
|
|
56 }
|
|
57
|
|
58 void
|
|
59 gaim_plugin_pref_frame_destroy(GaimPluginPrefFrame *frame) {
|
|
60 GaimPluginPref *pref;
|
8745
|
61 GList *l;
|
8713
|
62
|
|
63 g_return_if_fail(frame);
|
|
64
|
8745
|
65 for(l = frame->prefs; l != NULL; l = l->next) {
|
8713
|
66 pref = (GaimPluginPref *)l->data;
|
|
67 gaim_plugin_pref_destroy(pref);
|
|
68 }
|
|
69
|
8745
|
70 g_list_free(frame->prefs);
|
|
71 frame->prefs = NULL;
|
|
72
|
|
73 g_free(frame);
|
8713
|
74 frame = NULL;
|
|
75 }
|
|
76
|
|
77 void
|
|
78 gaim_plugin_pref_frame_add(GaimPluginPrefFrame *frame, GaimPluginPref *pref) {
|
|
79 g_return_if_fail(frame);
|
|
80 g_return_if_fail(pref);
|
|
81
|
8745
|
82 frame->prefs = g_list_append(frame->prefs, pref);
|
8713
|
83 }
|
|
84
|
|
85 GList *
|
|
86 gaim_plugin_pref_frame_get_prefs(GaimPluginPrefFrame *frame) {
|
8745
|
87 g_return_val_if_fail(frame, NULL);
|
|
88 g_return_val_if_fail(frame->prefs, NULL);
|
|
89
|
8713
|
90 return frame->prefs;
|
|
91 }
|
|
92
|
|
93 GaimPluginPref *
|
|
94 gaim_plugin_pref_new() {
|
|
95 GaimPluginPref *pref;
|
|
96
|
|
97 pref = g_new0(GaimPluginPref, 1);
|
|
98
|
|
99 return pref;
|
|
100 }
|
|
101
|
|
102 GaimPluginPref *
|
|
103 gaim_plugin_pref_new_with_name(char *name) {
|
|
104 GaimPluginPref *pref;
|
|
105
|
|
106 g_return_val_if_fail(name, NULL);
|
|
107
|
|
108 pref = g_new0(GaimPluginPref, 1);
|
|
109 pref->name = g_strdup(name);
|
|
110
|
|
111 return pref;
|
|
112 }
|
|
113
|
|
114 GaimPluginPref *
|
|
115 gaim_plugin_pref_new_with_label(char *label) {
|
|
116 GaimPluginPref *pref;
|
|
117
|
|
118 g_return_val_if_fail(label, NULL);
|
|
119
|
|
120 pref = g_new0(GaimPluginPref, 1);
|
|
121 pref->label = g_strdup(label);
|
|
122
|
|
123 return pref;
|
|
124 }
|
|
125
|
|
126 GaimPluginPref *
|
|
127 gaim_plugin_pref_new_with_name_and_label(char *name, char *label) {
|
|
128 GaimPluginPref *pref;
|
|
129
|
|
130 g_return_val_if_fail(name, NULL);
|
|
131 g_return_val_if_fail(label, NULL);
|
|
132
|
|
133 pref = g_new0(GaimPluginPref, 1);
|
|
134 pref->name = g_strdup(name);
|
|
135 pref->label = g_strdup(label);
|
|
136
|
|
137 return pref;
|
|
138 }
|
|
139
|
|
140 void
|
|
141 gaim_plugin_pref_destroy(GaimPluginPref *pref) {
|
|
142 GList *l, *ll;
|
|
143
|
|
144 g_return_if_fail(pref);
|
|
145
|
8745
|
146 if(pref->name) {
|
8713
|
147 g_free(pref->name);
|
8745
|
148 pref->name = NULL;
|
|
149 }
|
8713
|
150
|
8745
|
151 if(pref->label) {
|
|
152 g_free(pref->label);
|
|
153 pref->label = NULL;
|
|
154 }
|
8713
|
155
|
8745
|
156 if(pref->choices) {
|
|
157 g_list_free(pref->choices);
|
|
158 pref->choices = NULL;
|
8713
|
159 }
|
|
160
|
|
161 g_free(pref);
|
|
162 }
|
|
163
|
|
164 void
|
|
165 gaim_plugin_pref_set_name(GaimPluginPref *pref, char *name) {
|
|
166 g_return_if_fail(pref);
|
|
167 g_return_if_fail(name);
|
|
168
|
|
169 if(pref->name)
|
|
170 g_free(pref->name);
|
|
171
|
|
172 pref->name = g_strdup(name);
|
|
173 }
|
|
174
|
|
175 char *
|
|
176 gaim_plugin_pref_get_name(GaimPluginPref *pref) {
|
|
177 g_return_val_if_fail(pref, NULL);
|
|
178
|
|
179 return pref->name;
|
|
180 }
|
|
181
|
|
182 void
|
|
183 gaim_plugin_pref_set_label(GaimPluginPref *pref, char *label) {
|
|
184 g_return_if_fail(pref);
|
|
185 g_return_if_fail(label);
|
|
186
|
|
187 if(pref->label)
|
|
188 g_free(pref->label);
|
|
189
|
|
190 pref->label = g_strdup(label);
|
|
191 }
|
|
192
|
|
193 char *
|
|
194 gaim_plugin_pref_get_label(GaimPluginPref *pref) {
|
|
195 g_return_val_if_fail(pref, NULL);
|
|
196
|
|
197 return pref->label;
|
|
198 }
|
|
199
|
|
200 void
|
|
201 gaim_plugin_pref_set_bounds(GaimPluginPref *pref, int min, int max) {
|
|
202 int tmp;
|
|
203
|
|
204 g_return_if_fail(pref);
|
|
205 g_return_if_fail(pref->name);
|
|
206
|
|
207 if(gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) {
|
|
208 gaim_debug(GAIM_DEBUG_INFO, "pluginpref",
|
|
209 "gaim_plugin_pref_set_bounds: %s is not an integer pref\n",
|
|
210 pref->name);
|
|
211 return;
|
|
212 }
|
|
213
|
|
214 if(min > max) {
|
|
215 tmp = min;
|
|
216 min = max;
|
|
217 max = tmp;
|
|
218 }
|
|
219
|
|
220 pref->min = min;
|
|
221 pref->max = max;
|
|
222 }
|
|
223
|
|
224 void gaim_plugin_pref_get_bounds(GaimPluginPref *pref, int *min, int *max) {
|
|
225 g_return_if_fail(pref);
|
|
226 g_return_if_fail(pref->name);
|
|
227
|
|
228 if(gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) {
|
|
229 gaim_debug(GAIM_DEBUG_INFO, "pluginpref",
|
|
230 "gaim_plugin_pref_get_bounds: %s is not an integer pref\n",
|
|
231 pref->name);
|
|
232 return;
|
|
233 }
|
|
234
|
|
235 *min = pref->min;
|
|
236 *max = pref->max;
|
|
237 }
|
|
238
|
|
239 void
|
|
240 gaim_plugin_pref_set_type(GaimPluginPref *pref, GaimPluginPrefType type) {
|
|
241 g_return_if_fail(pref);
|
|
242
|
|
243 pref->type = type;
|
|
244 }
|
|
245
|
|
246 GaimPluginPrefType
|
|
247 gaim_plugin_pref_get_type(GaimPluginPref *pref) {
|
|
248 g_return_val_if_fail(pref, GAIM_PLUGIN_PREF_NONE);
|
|
249
|
|
250 return pref->type;
|
|
251 }
|
|
252
|
|
253 void
|
|
254 gaim_plugin_pref_add_choice(GaimPluginPref *pref, char *label, gpointer choice) {
|
|
255 g_return_if_fail(pref);
|
|
256 g_return_if_fail(label);
|
|
257 g_return_if_fail(choice);
|
|
258
|
|
259 pref->choices = g_list_append(pref->choices, label);
|
|
260 pref->choices = g_list_append(pref->choices, choice);
|
|
261 }
|
|
262
|
|
263 GList *
|
|
264 gaim_plugin_pref_get_choices(GaimPluginPref *pref) {
|
|
265 g_return_val_if_fail(pref, NULL);
|
|
266
|
|
267 return pref->choices;
|
|
268 }
|
|
269
|
|
270 void
|
|
271 gaim_plugin_pref_set_max_length(GaimPluginPref *pref, unsigned int max_length) {
|
|
272 g_return_if_fail(pref);
|
|
273
|
|
274 pref->max_length = max_length;
|
|
275 }
|
|
276
|
|
277 unsigned int
|
|
278 gaim_plugin_pref_get_max_length(GaimPluginPref *pref) {
|
|
279 g_return_val_if_fail(pref, 0);
|
|
280
|
|
281 return pref->max_length;
|
|
282 }
|