Mercurial > pidgin
diff src/prefs.c @ 5561:d67b5b4e1323
[gaim-migrate @ 5962]
prefs just keeps getting cooler and cool
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Fri, 30 May 2003 04:05:48 +0000 |
| parents | 51699de873af |
| children | fb4f7bd7525c |
line wrap: on
line diff
--- a/src/prefs.c Fri May 30 03:25:39 2003 +0000 +++ b/src/prefs.c Fri May 30 04:05:48 2003 +0000 @@ -51,6 +51,7 @@ gboolean boolean; int integer; char *string; + GList *stringlist; } value; GSList *callbacks; struct gaim_pref *parent; @@ -201,6 +202,14 @@ g_free(pref->value.string); pref->value.string = NULL; break; + case GAIM_PREF_STRING_LIST: + { + GList *tmp; + for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) + g_free(tmp->data); + + g_list_free(pref->value.stringlist); + } break; case GAIM_PREF_NONE: break; } @@ -276,6 +285,18 @@ pref->value.string = g_strdup(value); } +void gaim_prefs_add_string_list(const char *name, GList *value) { + struct gaim_pref *pref = add_pref(GAIM_PREF_STRING_LIST, name); + GList *tmp; + + if(!pref) + return; + + for(tmp = value; tmp; tmp = tmp->next) + pref->value.stringlist = g_list_append(pref->value.stringlist, + g_strdup(tmp->data)); +} + void remove_pref(struct gaim_pref *pref) { char *name; @@ -389,6 +410,25 @@ } } +void gaim_prefs_set_string_list(const char *name, GList *value) { + struct gaim_pref *pref = find_pref(name); + if(pref) { + GList *tmp; + for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) + g_free(tmp->data); + + g_list_free(pref->value.stringlist); + pref->value.stringlist = NULL; + + for(tmp = value; tmp; tmp = tmp->next) + pref->value.stringlist = g_list_append(pref->value.stringlist, + g_strdup(tmp->data)); + + } else { + gaim_prefs_add_string_list(name, value); + } +} + gpointer gaim_prefs_get_generic(const char *name) { struct gaim_pref *pref = find_pref(name); @@ -424,6 +464,19 @@ return pref->value.string; } +GList *gaim_prefs_get_string_list(const char *name) { + struct gaim_pref *pref = find_pref(name); + GList *ret = NULL, *tmp; + + g_return_val_if_fail(pref != NULL, NULL); + g_return_val_if_fail(pref->type == GAIM_PREF_STRING_LIST, NULL); + + for(tmp = pref->value.stringlist; tmp; tmp = tmp->next) + ret = g_list_append(ret, g_strdup(tmp->data)); + + return ret; +} + guint gaim_prefs_connect_callback(const char *name, GaimPrefCallback func, gpointer data) { struct gaim_pref *pref = find_pref(name); @@ -504,13 +557,28 @@ fprintf(f, " type='string' value='%s'", esc); g_free(esc); break; + case GAIM_PREF_STRING_LIST: + fprintf(f, " type='stringlist'"); + break; } - if(pref->first_child) { + if(pref->first_child || pref->type == GAIM_PREF_STRING_LIST) { fprintf(f, ">\n"); for(tmp = pref->first_child; tmp; tmp = tmp->sibling) gaim_prefs_write(f, tmp, depth+1); + + if(pref->type == GAIM_PREF_STRING_LIST) { + GList *tmp2; + for(tmp2 = pref->value.stringlist; tmp2; tmp2 = tmp2->next) { + for(i=0; i<depth+1; i++) + fprintf(f, "\t"); + esc = g_markup_escape_text(tmp2->data, -1); + fprintf(f, "<item value='%s' />\n", esc); + g_free(esc); + } + } + for(i=0; i<depth; i++) fprintf(f, "\t"); fprintf(f, "</pref>\n"); @@ -576,7 +644,7 @@ GString *pref_name_full; GList *tmp; - if(strcmp(element_name, "pref")) + if(strcmp(element_name, "pref") && strcmp(element_name, "item")) return; for(i = 0; attribute_names[i]; i++) { @@ -589,6 +657,8 @@ pref_type = GAIM_PREF_INT; else if(!strcmp(attribute_values[i], "string")) pref_type = GAIM_PREF_STRING; + else if(!strcmp(attribute_values[i], "stringlist")) + pref_type = GAIM_PREF_STRING_LIST; else return; } else if(!strcmp(attribute_names[i], "value")) { @@ -596,8 +666,16 @@ } } - if(!pref_name || !strcmp(pref_name, "/")) + if(!strcmp(element_name, "item")) { + struct gaim_pref *pref = find_pref(prefs_stack->data); + if(pref) { + pref->value.stringlist = g_list_append(pref->value.stringlist, + g_strdup(pref_value)); + } return; + } else if(!pref_name || !strcmp(pref_name, "/")) { + return; + } pref_name_full = g_string_new(pref_name); @@ -620,6 +698,8 @@ case GAIM_PREF_STRING: gaim_prefs_set_string(pref_name_full->str, pref_value); break; + case GAIM_PREF_STRING_LIST: + break; } prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name));
