comparison src/pluginpref.c @ 8713:7024b595b6ae

[gaim-migrate @ 9467] " Expansion from my original protocol prefs to plugin prefs. Things are handled a bit different in this iteration of it, but I have already modified msn and jabber to use it, and included an example plugin to show how to use it. It will also generate pages with doxygen. The example plugin doesn't not contain any translatable strings seeing as we're in the string freeze. And it's an example, whats the point of translating it..? Also, I tweaked the documentation for 2 functions in gtkprefs, gaim_gtk_prefs_dropdown and gaim_gtk_prefs_dropdown_from_list. Nothing major in that, just made it say that the list should be a list of pairs label/value. Also there's 5 new files that will need to be added to cvs: src/pluginpref.h src/pluginpref.c src/gtkpluginpref.h src/gtkpluginpref.c plugins/pluginpref_example.c the tarball already has them structured correctly and contains the diff" --Gary Kramlich - amc_grim and the german translator pointed out that sean missed the novell file for POTFILES.in committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Mon, 19 Apr 2004 21:12:45 +0000
parents
children 6c0fae7a4f1a
comparison
equal deleted inserted replaced
8712:a4ff6e79c5fc 8713:7024b595b6ae
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;
61 GList *l, *ll;
62
63 g_return_if_fail(frame);
64
65 for(l = frame->prefs; l != NULL; l = ll) {
66 ll = l->next;
67
68 pref = (GaimPluginPref *)l->data;
69 gaim_plugin_pref_destroy(pref);
70
71 g_list_free_1(l);
72 }
73
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
82 frame->prefs = g_list_append(frame->prefs, (gpointer)pref);
83 }
84
85 GList *
86 gaim_plugin_pref_frame_get_prefs(GaimPluginPrefFrame *frame) {
87 return frame->prefs;
88 }
89
90 GaimPluginPref *
91 gaim_plugin_pref_new() {
92 GaimPluginPref *pref;
93
94 pref = g_new0(GaimPluginPref, 1);
95
96 return pref;
97 }
98
99 GaimPluginPref *
100 gaim_plugin_pref_new_with_name(char *name) {
101 GaimPluginPref *pref;
102
103 g_return_val_if_fail(name, NULL);
104
105 pref = g_new0(GaimPluginPref, 1);
106 pref->name = g_strdup(name);
107
108 return pref;
109 }
110
111 GaimPluginPref *
112 gaim_plugin_pref_new_with_label(char *label) {
113 GaimPluginPref *pref;
114
115 g_return_val_if_fail(label, NULL);
116
117 pref = g_new0(GaimPluginPref, 1);
118 pref->label = g_strdup(label);
119
120 return pref;
121 }
122
123 GaimPluginPref *
124 gaim_plugin_pref_new_with_name_and_label(char *name, char *label) {
125 GaimPluginPref *pref;
126
127 g_return_val_if_fail(name, NULL);
128 g_return_val_if_fail(label, NULL);
129
130 pref = g_new0(GaimPluginPref, 1);
131 pref->name = g_strdup(name);
132 pref->label = g_strdup(label);
133
134 return pref;
135 }
136
137 void
138 gaim_plugin_pref_destroy(GaimPluginPref *pref) {
139 GList *l, *ll;
140
141 g_return_if_fail(pref);
142
143 if(pref->name)
144 g_free(pref->name);
145
146 if(pref->label)
147 g_free(pref->label);
148
149 l = pref->choices;
150 while(l) {
151 ll = l->next;
152
153 g_free(l->data);
154 g_list_free_1(l);
155
156 l = l->next;
157 }
158
159 g_free(pref);
160 }
161
162 void
163 gaim_plugin_pref_set_name(GaimPluginPref *pref, char *name) {
164 g_return_if_fail(pref);
165 g_return_if_fail(name);
166
167 if(pref->name)
168 g_free(pref->name);
169
170 pref->name = g_strdup(name);
171 }
172
173 char *
174 gaim_plugin_pref_get_name(GaimPluginPref *pref) {
175 g_return_val_if_fail(pref, NULL);
176
177 return pref->name;
178 }
179
180 void
181 gaim_plugin_pref_set_label(GaimPluginPref *pref, char *label) {
182 g_return_if_fail(pref);
183 g_return_if_fail(label);
184
185 if(pref->label)
186 g_free(pref->label);
187
188 pref->label = g_strdup(label);
189 }
190
191 char *
192 gaim_plugin_pref_get_label(GaimPluginPref *pref) {
193 g_return_val_if_fail(pref, NULL);
194
195 return pref->label;
196 }
197
198 void
199 gaim_plugin_pref_set_bounds(GaimPluginPref *pref, int min, int max) {
200 int tmp;
201
202 g_return_if_fail(pref);
203 g_return_if_fail(pref->name);
204
205 if(gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) {
206 gaim_debug(GAIM_DEBUG_INFO, "pluginpref",
207 "gaim_plugin_pref_set_bounds: %s is not an integer pref\n",
208 pref->name);
209 return;
210 }
211
212 if(min > max) {
213 tmp = min;
214 min = max;
215 max = tmp;
216 }
217
218 pref->min = min;
219 pref->max = max;
220 }
221
222 void gaim_plugin_pref_get_bounds(GaimPluginPref *pref, int *min, int *max) {
223 g_return_if_fail(pref);
224 g_return_if_fail(pref->name);
225
226 if(gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) {
227 gaim_debug(GAIM_DEBUG_INFO, "pluginpref",
228 "gaim_plugin_pref_get_bounds: %s is not an integer pref\n",
229 pref->name);
230 return;
231 }
232
233 *min = pref->min;
234 *max = pref->max;
235 }
236
237 void
238 gaim_plugin_pref_set_type(GaimPluginPref *pref, GaimPluginPrefType type) {
239 g_return_if_fail(pref);
240
241 pref->type = type;
242 }
243
244 GaimPluginPrefType
245 gaim_plugin_pref_get_type(GaimPluginPref *pref) {
246 g_return_val_if_fail(pref, GAIM_PLUGIN_PREF_NONE);
247
248 return pref->type;
249 }
250
251 void
252 gaim_plugin_pref_add_choice(GaimPluginPref *pref, char *label, gpointer choice) {
253 g_return_if_fail(pref);
254 g_return_if_fail(label);
255 g_return_if_fail(choice);
256
257 pref->choices = g_list_append(pref->choices, label);
258 pref->choices = g_list_append(pref->choices, choice);
259 }
260
261 gpointer
262 gaim_plugin_pref_get_choice(GaimPluginPref *pref, unsigned int index) {
263 g_return_val_if_fail(pref, NULL);
264
265 if(index > g_list_length(pref->choices))
266 return NULL;
267
268 return g_list_nth_data(pref->choices, index);
269 }
270
271 GList *
272 gaim_plugin_pref_get_choices(GaimPluginPref *pref) {
273 g_return_val_if_fail(pref, NULL);
274
275 return pref->choices;
276 }
277
278 void
279 gaim_plugin_pref_set_max_length(GaimPluginPref *pref, unsigned int max_length) {
280 g_return_if_fail(pref);
281
282 pref->max_length = max_length;
283 }
284
285 unsigned int
286 gaim_plugin_pref_get_max_length(GaimPluginPref *pref) {
287 g_return_val_if_fail(pref, 0);
288
289 return pref->max_length;
290 }