Mercurial > pidgin.yaz
comparison src/pluginpref.c @ 14035:8bda65b88e49
[gaim-migrate @ 16638]
A bunch of small changes. Mostly remove "if not null" checks before
calling g_free, g_list_free, g_slist_free and g_strdup. Also use
g_list_foreach() to call g_free to free strings in an array. And
some whitespace changes here and there.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Sat, 05 Aug 2006 08:27:39 +0000 |
| parents | 16f6d6f8afc7 |
| children |
comparison
equal
deleted
inserted
replaced
| 14034:0839a7b71325 | 14035:8bda65b88e49 |
|---|---|
| 28 #include "debug.h" | 28 #include "debug.h" |
| 29 #include "internal.h" | 29 #include "internal.h" |
| 30 #include "pluginpref.h" | 30 #include "pluginpref.h" |
| 31 #include "prefs.h" | 31 #include "prefs.h" |
| 32 | 32 |
| 33 struct _GaimPluginPrefFrame { | 33 struct _GaimPluginPrefFrame |
| 34 { | |
| 34 GList *prefs; | 35 GList *prefs; |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 struct _GaimPluginPref { | 38 struct _GaimPluginPref |
| 39 { | |
| 38 char *name; | 40 char *name; |
| 39 char *label; | 41 char *label; |
| 40 | 42 |
| 41 GaimPluginPrefType type; | 43 GaimPluginPrefType type; |
| 42 | 44 |
| 47 gboolean masked; | 49 gboolean masked; |
| 48 GaimStringFormatType format; | 50 GaimStringFormatType format; |
| 49 }; | 51 }; |
| 50 | 52 |
| 51 GaimPluginPrefFrame * | 53 GaimPluginPrefFrame * |
| 52 gaim_plugin_pref_frame_new() { | 54 gaim_plugin_pref_frame_new() |
| 55 { | |
| 53 GaimPluginPrefFrame *frame; | 56 GaimPluginPrefFrame *frame; |
| 54 | 57 |
| 55 frame = g_new0(GaimPluginPrefFrame, 1); | 58 frame = g_new0(GaimPluginPrefFrame, 1); |
| 56 | 59 |
| 57 return frame; | 60 return frame; |
| 58 } | 61 } |
| 59 | 62 |
| 60 void | 63 void |
| 61 gaim_plugin_pref_frame_destroy(GaimPluginPrefFrame *frame) { | 64 gaim_plugin_pref_frame_destroy(GaimPluginPrefFrame *frame) |
| 65 { | |
| 66 g_return_if_fail(frame != NULL); | |
| 67 | |
| 68 g_list_foreach(frame->prefs, (GFunc)gaim_plugin_pref_destroy, NULL); | |
| 69 g_list_free(frame->prefs); | |
| 70 g_free(frame); | |
| 71 } | |
| 72 | |
| 73 void | |
| 74 gaim_plugin_pref_frame_add(GaimPluginPrefFrame *frame, GaimPluginPref *pref) | |
| 75 { | |
| 76 g_return_if_fail(frame != NULL); | |
| 77 g_return_if_fail(pref != NULL); | |
| 78 | |
| 79 frame->prefs = g_list_append(frame->prefs, pref); | |
| 80 } | |
| 81 | |
| 82 GList * | |
| 83 gaim_plugin_pref_frame_get_prefs(GaimPluginPrefFrame *frame) | |
| 84 { | |
| 85 g_return_val_if_fail(frame != NULL, NULL); | |
| 86 g_return_val_if_fail(frame->prefs != NULL, NULL); | |
| 87 | |
| 88 return frame->prefs; | |
| 89 } | |
| 90 | |
| 91 GaimPluginPref * | |
| 92 gaim_plugin_pref_new() | |
| 93 { | |
| 62 GaimPluginPref *pref; | 94 GaimPluginPref *pref; |
| 63 GList *l; | 95 |
| 64 | 96 pref = g_new0(GaimPluginPref, 1); |
| 65 g_return_if_fail(frame); | 97 |
| 66 | 98 return pref; |
| 67 for(l = frame->prefs; l != NULL; l = l->next) { | |
| 68 pref = (GaimPluginPref *)l->data; | |
| 69 gaim_plugin_pref_destroy(pref); | |
| 70 } | |
| 71 | |
| 72 g_list_free(frame->prefs); | |
| 73 frame->prefs = NULL; | |
| 74 | |
| 75 g_free(frame); | |
| 76 frame = NULL; | |
| 77 } | |
| 78 | |
| 79 void | |
| 80 gaim_plugin_pref_frame_add(GaimPluginPrefFrame *frame, GaimPluginPref *pref) { | |
| 81 g_return_if_fail(frame); | |
| 82 g_return_if_fail(pref); | |
| 83 | |
| 84 frame->prefs = g_list_append(frame->prefs, pref); | |
| 85 } | |
| 86 | |
| 87 GList * | |
| 88 gaim_plugin_pref_frame_get_prefs(GaimPluginPrefFrame *frame) { | |
| 89 g_return_val_if_fail(frame, NULL); | |
| 90 g_return_val_if_fail(frame->prefs, NULL); | |
| 91 | |
| 92 return frame->prefs; | |
| 93 } | 99 } |
| 94 | 100 |
| 95 GaimPluginPref * | 101 GaimPluginPref * |
| 96 gaim_plugin_pref_new() { | 102 gaim_plugin_pref_new_with_name(const char *name) |
| 103 { | |
| 97 GaimPluginPref *pref; | 104 GaimPluginPref *pref; |
| 98 | 105 |
| 99 pref = g_new0(GaimPluginPref, 1); | 106 g_return_val_if_fail(name != NULL, NULL); |
| 100 | |
| 101 return pref; | |
| 102 } | |
| 103 | |
| 104 GaimPluginPref * | |
| 105 gaim_plugin_pref_new_with_name(const char *name) { | |
| 106 GaimPluginPref *pref; | |
| 107 | |
| 108 g_return_val_if_fail(name, NULL); | |
| 109 | 107 |
| 110 pref = g_new0(GaimPluginPref, 1); | 108 pref = g_new0(GaimPluginPref, 1); |
| 111 pref->name = g_strdup(name); | 109 pref->name = g_strdup(name); |
| 112 | 110 |
| 113 return pref; | 111 return pref; |
| 114 } | 112 } |
| 115 | 113 |
| 116 GaimPluginPref * | 114 GaimPluginPref * |
| 117 gaim_plugin_pref_new_with_label(const char *label) { | 115 gaim_plugin_pref_new_with_label(const char *label) |
| 116 { | |
| 118 GaimPluginPref *pref; | 117 GaimPluginPref *pref; |
| 119 | 118 |
| 120 g_return_val_if_fail(label, NULL); | 119 g_return_val_if_fail(label != NULL, NULL); |
| 121 | 120 |
| 122 pref = g_new0(GaimPluginPref, 1); | 121 pref = g_new0(GaimPluginPref, 1); |
| 123 pref->label = g_strdup(label); | 122 pref->label = g_strdup(label); |
| 124 | 123 |
| 125 return pref; | 124 return pref; |
| 126 } | 125 } |
| 127 | 126 |
| 128 GaimPluginPref * | 127 GaimPluginPref * |
| 129 gaim_plugin_pref_new_with_name_and_label(const char *name, const char *label) { | 128 gaim_plugin_pref_new_with_name_and_label(const char *name, const char *label) |
| 129 { | |
| 130 GaimPluginPref *pref; | 130 GaimPluginPref *pref; |
| 131 | 131 |
| 132 g_return_val_if_fail(name, NULL); | 132 g_return_val_if_fail(name != NULL, NULL); |
| 133 g_return_val_if_fail(label, NULL); | 133 g_return_val_if_fail(label != NULL, NULL); |
| 134 | 134 |
| 135 pref = g_new0(GaimPluginPref, 1); | 135 pref = g_new0(GaimPluginPref, 1); |
| 136 pref->name = g_strdup(name); | 136 pref->name = g_strdup(name); |
| 137 pref->label = g_strdup(label); | 137 pref->label = g_strdup(label); |
| 138 | 138 |
| 139 return pref; | 139 return pref; |
| 140 } | 140 } |
| 141 | 141 |
| 142 void | 142 void |
| 143 gaim_plugin_pref_destroy(GaimPluginPref *pref) { | 143 gaim_plugin_pref_destroy(GaimPluginPref *pref) |
| 144 g_return_if_fail(pref); | 144 { |
| 145 | 145 g_return_if_fail(pref != NULL); |
| 146 if(pref->name) { | 146 |
| 147 g_free(pref->name); | 147 g_free(pref->name); |
| 148 pref->name = NULL; | 148 g_free(pref->label); |
| 149 } | 149 g_list_free(pref->choices); |
| 150 | |
| 151 if(pref->label) { | |
| 152 g_free(pref->label); | |
| 153 pref->label = NULL; | |
| 154 } | |
| 155 | |
| 156 if(pref->choices) { | |
| 157 g_list_free(pref->choices); | |
| 158 pref->choices = NULL; | |
| 159 } | |
| 160 | |
| 161 g_free(pref); | 150 g_free(pref); |
| 162 } | 151 } |
| 163 | 152 |
| 164 void | 153 void |
| 165 gaim_plugin_pref_set_name(GaimPluginPref *pref, const char *name) { | 154 gaim_plugin_pref_set_name(GaimPluginPref *pref, const char *name) |
| 166 g_return_if_fail(pref); | 155 { |
| 167 g_return_if_fail(name); | 156 g_return_if_fail(pref != NULL); |
| 168 | 157 g_return_if_fail(name != NULL); |
| 169 if(pref->name) | 158 |
| 170 g_free(pref->name); | 159 g_free(pref->name); |
| 171 | |
| 172 pref->name = g_strdup(name); | 160 pref->name = g_strdup(name); |
| 173 } | 161 } |
| 174 | 162 |
| 175 const char * | 163 const char * |
| 176 gaim_plugin_pref_get_name(GaimPluginPref *pref) { | 164 gaim_plugin_pref_get_name(GaimPluginPref *pref) |
| 177 g_return_val_if_fail(pref, NULL); | 165 { |
| 166 g_return_val_if_fail(pref != NULL, NULL); | |
| 178 | 167 |
| 179 return pref->name; | 168 return pref->name; |
| 180 } | 169 } |
| 181 | 170 |
| 182 void | 171 void |
| 183 gaim_plugin_pref_set_label(GaimPluginPref *pref, const char *label) { | 172 gaim_plugin_pref_set_label(GaimPluginPref *pref, const char *label) |
| 184 g_return_if_fail(pref); | 173 { |
| 185 g_return_if_fail(label); | 174 g_return_if_fail(pref != NULL); |
| 186 | 175 g_return_if_fail(label != NULL); |
| 187 if(pref->label) | 176 |
| 188 g_free(pref->label); | 177 g_free(pref->label); |
| 189 | |
| 190 pref->label = g_strdup(label); | 178 pref->label = g_strdup(label); |
| 191 } | 179 } |
| 192 | 180 |
| 193 const char * | 181 const char * |
| 194 gaim_plugin_pref_get_label(GaimPluginPref *pref) { | 182 gaim_plugin_pref_get_label(GaimPluginPref *pref) |
| 195 g_return_val_if_fail(pref, NULL); | 183 { |
| 184 g_return_val_if_fail(pref != NULL, NULL); | |
| 196 | 185 |
| 197 return pref->label; | 186 return pref->label; |
| 198 } | 187 } |
| 199 | 188 |
| 200 void | 189 void |
| 201 gaim_plugin_pref_set_bounds(GaimPluginPref *pref, int min, int max) { | 190 gaim_plugin_pref_set_bounds(GaimPluginPref *pref, int min, int max) |
| 191 { | |
| 202 int tmp; | 192 int tmp; |
| 203 | 193 |
| 204 g_return_if_fail(pref); | 194 g_return_if_fail(pref != NULL); |
| 205 g_return_if_fail(pref->name); | 195 g_return_if_fail(pref->name != NULL); |
| 206 | 196 |
| 207 if(gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) { | 197 if (gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) |
| 208 gaim_debug(GAIM_DEBUG_INFO, "pluginpref", | 198 { |
| 199 gaim_debug_info("pluginpref", | |
| 209 "gaim_plugin_pref_set_bounds: %s is not an integer pref\n", | 200 "gaim_plugin_pref_set_bounds: %s is not an integer pref\n", |
| 210 pref->name); | 201 pref->name); |
| 211 return; | 202 return; |
| 212 } | 203 } |
| 213 | 204 |
| 214 if(min > max) { | 205 if (min > max) |
| 206 { | |
| 215 tmp = min; | 207 tmp = min; |
| 216 min = max; | 208 min = max; |
| 217 max = tmp; | 209 max = tmp; |
| 218 } | 210 } |
| 219 | 211 |
| 220 pref->min = min; | 212 pref->min = min; |
| 221 pref->max = max; | 213 pref->max = max; |
| 222 } | 214 } |
| 223 | 215 |
| 224 void gaim_plugin_pref_get_bounds(GaimPluginPref *pref, int *min, int *max) { | 216 void gaim_plugin_pref_get_bounds(GaimPluginPref *pref, int *min, int *max) |
| 225 g_return_if_fail(pref); | 217 { |
| 226 g_return_if_fail(pref->name); | 218 g_return_if_fail(pref != NULL); |
| 227 | 219 g_return_if_fail(pref->name != NULL); |
| 228 if(gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) { | 220 |
| 221 if (gaim_prefs_get_type(pref->name) != GAIM_PREF_INT) | |
| 222 { | |
| 229 gaim_debug(GAIM_DEBUG_INFO, "pluginpref", | 223 gaim_debug(GAIM_DEBUG_INFO, "pluginpref", |
| 230 "gaim_plugin_pref_get_bounds: %s is not an integer pref\n", | 224 "gaim_plugin_pref_get_bounds: %s is not an integer pref\n", |
| 231 pref->name); | 225 pref->name); |
| 232 return; | 226 return; |
| 233 } | 227 } |
| 235 *min = pref->min; | 229 *min = pref->min; |
| 236 *max = pref->max; | 230 *max = pref->max; |
| 237 } | 231 } |
| 238 | 232 |
| 239 void | 233 void |
| 240 gaim_plugin_pref_set_type(GaimPluginPref *pref, GaimPluginPrefType type) { | 234 gaim_plugin_pref_set_type(GaimPluginPref *pref, GaimPluginPrefType type) |
| 241 g_return_if_fail(pref); | 235 { |
| 236 g_return_if_fail(pref != NULL); | |
| 242 | 237 |
| 243 pref->type = type; | 238 pref->type = type; |
| 244 } | 239 } |
| 245 | 240 |
| 246 GaimPluginPrefType | 241 GaimPluginPrefType |
| 247 gaim_plugin_pref_get_type(GaimPluginPref *pref) { | 242 gaim_plugin_pref_get_type(GaimPluginPref *pref) |
| 248 g_return_val_if_fail(pref, GAIM_PLUGIN_PREF_NONE); | 243 { |
| 244 g_return_val_if_fail(pref != NULL, GAIM_PLUGIN_PREF_NONE); | |
| 249 | 245 |
| 250 return pref->type; | 246 return pref->type; |
| 251 } | 247 } |
| 252 | 248 |
| 253 void | 249 void |
| 254 gaim_plugin_pref_add_choice(GaimPluginPref *pref, const char *label, gpointer choice) { | 250 gaim_plugin_pref_add_choice(GaimPluginPref *pref, const char *label, gpointer choice) |
| 255 g_return_if_fail(pref); | 251 { |
| 256 g_return_if_fail(label); | 252 g_return_if_fail(pref != NULL); |
| 253 g_return_if_fail(label != NULL); | |
| 257 g_return_if_fail(choice || gaim_prefs_get_type(pref->name) == GAIM_PREF_INT); | 254 g_return_if_fail(choice || gaim_prefs_get_type(pref->name) == GAIM_PREF_INT); |
| 258 | 255 |
| 259 pref->choices = g_list_append(pref->choices, (gpointer)label); | 256 pref->choices = g_list_append(pref->choices, (gpointer)label); |
| 260 pref->choices = g_list_append(pref->choices, choice); | 257 pref->choices = g_list_append(pref->choices, choice); |
| 261 } | 258 } |
| 262 | 259 |
| 263 GList * | 260 GList * |
| 264 gaim_plugin_pref_get_choices(GaimPluginPref *pref) { | 261 gaim_plugin_pref_get_choices(GaimPluginPref *pref) |
| 265 g_return_val_if_fail(pref, NULL); | 262 { |
| 263 g_return_val_if_fail(pref != NULL, NULL); | |
| 266 | 264 |
| 267 return pref->choices; | 265 return pref->choices; |
| 268 } | 266 } |
| 269 | 267 |
| 270 void | 268 void |
| 271 gaim_plugin_pref_set_max_length(GaimPluginPref *pref, unsigned int max_length) { | 269 gaim_plugin_pref_set_max_length(GaimPluginPref *pref, unsigned int max_length) |
| 272 g_return_if_fail(pref); | 270 { |
| 271 g_return_if_fail(pref != NULL); | |
| 273 | 272 |
| 274 pref->max_length = max_length; | 273 pref->max_length = max_length; |
| 275 } | 274 } |
| 276 | 275 |
| 277 unsigned int | 276 unsigned int |
| 278 gaim_plugin_pref_get_max_length(GaimPluginPref *pref) { | 277 gaim_plugin_pref_get_max_length(GaimPluginPref *pref) |
| 279 g_return_val_if_fail(pref, 0); | 278 { |
| 279 g_return_val_if_fail(pref != NULL, 0); | |
| 280 | 280 |
| 281 return pref->max_length; | 281 return pref->max_length; |
| 282 } | 282 } |
| 283 | 283 |
| 284 void | 284 void |
| 285 gaim_plugin_pref_set_masked(GaimPluginPref *pref, gboolean masked) { | 285 gaim_plugin_pref_set_masked(GaimPluginPref *pref, gboolean masked) |
| 286 g_return_if_fail(pref); | 286 { |
| 287 g_return_if_fail(pref != NULL); | |
| 287 | 288 |
| 288 pref->masked = masked; | 289 pref->masked = masked; |
| 289 } | 290 } |
| 290 | 291 |
| 291 gboolean | 292 gboolean |
| 292 gaim_plugin_pref_get_masked(GaimPluginPref *pref) { | 293 gaim_plugin_pref_get_masked(GaimPluginPref *pref) |
| 293 g_return_val_if_fail(pref, FALSE); | 294 { |
| 295 g_return_val_if_fail(pref != NULL, FALSE); | |
| 294 | 296 |
| 295 return pref->masked; | 297 return pref->masked; |
| 296 } | 298 } |
| 297 | 299 |
| 298 void | 300 void |
| 299 gaim_plugin_pref_set_format_type(GaimPluginPref *pref, GaimStringFormatType format) | 301 gaim_plugin_pref_set_format_type(GaimPluginPref *pref, GaimStringFormatType format) |
| 300 { | 302 { |
| 301 g_return_if_fail(pref); | 303 g_return_if_fail(pref != NULL); |
| 302 g_return_if_fail(pref->type == GAIM_PLUGIN_PREF_STRING_FORMAT); | 304 g_return_if_fail(pref->type == GAIM_PLUGIN_PREF_STRING_FORMAT); |
| 303 | 305 |
| 304 pref->format = format; | 306 pref->format = format; |
| 305 } | 307 } |
| 306 | 308 |
| 307 GaimStringFormatType | 309 GaimStringFormatType |
| 308 gaim_plugin_pref_get_format_type(GaimPluginPref *pref) | 310 gaim_plugin_pref_get_format_type(GaimPluginPref *pref) |
| 309 { | 311 { |
| 310 g_return_val_if_fail(pref, 0); | 312 g_return_val_if_fail(pref != NULL, 0); |
| 311 | 313 |
| 312 if (pref->type != GAIM_PLUGIN_PREF_STRING_FORMAT) | 314 if (pref->type != GAIM_PLUGIN_PREF_STRING_FORMAT) |
| 313 return GAIM_STRING_FORMAT_TYPE_NONE; | 315 return GAIM_STRING_FORMAT_TYPE_NONE; |
| 314 | 316 |
| 315 return pref->format; | 317 return pref->format; |
| 316 } | 318 } |
| 317 | 319 |
