Sun, 16 May 2004 05:52:00 +0000
[gaim-migrate @ 9717]
Eradicate Show numbers in groups.
| 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 | g_return_if_fail(pref); | |
| 143 | ||
| 8745 | 144 | if(pref->name) { |
| 8713 | 145 | g_free(pref->name); |
| 8745 | 146 | pref->name = NULL; |
| 147 | } | |
| 8713 | 148 | |
| 8745 | 149 | if(pref->label) { |
| 150 | g_free(pref->label); | |
| 151 | pref->label = NULL; | |
| 152 | } | |
| 8713 | 153 | |
| 8745 | 154 | if(pref->choices) { |
| 155 | g_list_free(pref->choices); | |
| 156 | pref->choices = NULL; | |
| 8713 | 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 | GList * | |
| 262 | gaim_plugin_pref_get_choices(GaimPluginPref *pref) { | |
| 263 | g_return_val_if_fail(pref, NULL); | |
| 264 | ||
| 265 | return pref->choices; | |
| 266 | } | |
| 267 | ||
| 268 | void | |
| 269 | gaim_plugin_pref_set_max_length(GaimPluginPref *pref, unsigned int max_length) { | |
| 270 | g_return_if_fail(pref); | |
| 271 | ||
| 272 | pref->max_length = max_length; | |
| 273 | } | |
| 274 | ||
| 275 | unsigned int | |
| 276 | gaim_plugin_pref_get_max_length(GaimPluginPref *pref) { | |
| 277 | g_return_val_if_fail(pref, 0); | |
| 278 | ||
| 279 | return pref->max_length; | |
| 280 | } |