static void new_alias (gpointer data, PurpleRequestFields *fields) { GtkTreeIter iter; GList *aliases; const char *alias; alias = purple_request_fields_get_string (fields, "alias"); aliases = purple_prefs_get_string_list ( "/plugins/gtk/autoprofile/components/logstat/aliases"); aliases = g_list_append (aliases, strdup (alias)); purple_prefs_set_string_list ( "/plugins/gtk/autoprofile/components/logstat/aliases", aliases); free_string_list (aliases); gtk_list_store_insert (alias_list, &iter, 0); gtk_list_store_set (alias_list, &iter, 0, alias, -1); }
static void alias_delete (GtkButton *button, gpointer data) { GtkTreeSelection *selection; GtkTreeIter iter; char *alias; GList *aliases, *aliases_start, *new_aliases; selection = gtk_tree_view_get_selection ( GTK_TREE_VIEW (alias_view)); if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) return; gtk_tree_model_get (GTK_TREE_MODEL (alias_list), &iter, 0, &alias, -1); gtk_list_store_remove (alias_list, &iter); aliases = purple_prefs_get_string_list ( "/plugins/gtk/autoprofile/components/logstat/aliases"); aliases_start = aliases; new_aliases = NULL; while (aliases) { if (strcmp ((char *)aliases->data, alias)) { new_aliases = g_list_append (new_aliases, aliases->data); } aliases = aliases->next; } purple_prefs_set_string_list ( "/plugins/gtk/autoprofile/components/logstat/aliases", new_aliases); free_string_list (aliases_start); g_list_free (new_aliases); free (alias); }
static void prefs_start_element_handler (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error) { PurplePrefType pref_type = PURPLE_PREF_NONE; int i; const char *pref_name = NULL, *pref_value = NULL; GString *pref_name_full; GList *tmp; if(!purple_strequal(element_name, "pref") && !purple_strequal(element_name, "item")) return; for(i = 0; attribute_names[i]; i++) { if(purple_strequal(attribute_names[i], "name")) { pref_name = attribute_values[i]; } else if(purple_strequal(attribute_names[i], "type")) { if(purple_strequal(attribute_values[i], "bool")) pref_type = PURPLE_PREF_BOOLEAN; else if(purple_strequal(attribute_values[i], "int")) pref_type = PURPLE_PREF_INT; else if(purple_strequal(attribute_values[i], "string")) pref_type = PURPLE_PREF_STRING; else if(purple_strequal(attribute_values[i], "stringlist")) pref_type = PURPLE_PREF_STRING_LIST; else if(purple_strequal(attribute_values[i], "path")) pref_type = PURPLE_PREF_PATH; else if(purple_strequal(attribute_values[i], "pathlist")) pref_type = PURPLE_PREF_PATH_LIST; else return; } else if(purple_strequal(attribute_names[i], "value")) { pref_value = attribute_values[i]; } } if(purple_strequal(element_name, "item")) { struct purple_pref *pref; pref_name_full = g_string_new(""); for(tmp = prefs_stack; tmp; tmp = tmp->next) { pref_name_full = g_string_prepend(pref_name_full, tmp->data); pref_name_full = g_string_prepend_c(pref_name_full, '/'); } pref = find_pref(pref_name_full->str); if(pref) { if(pref->type == PURPLE_PREF_STRING_LIST) { pref->value.stringlist = g_list_append(pref->value.stringlist, g_strdup(pref_value)); } else if(pref->type == PURPLE_PREF_PATH_LIST) { pref->value.stringlist = g_list_append(pref->value.stringlist, g_filename_from_utf8(pref_value, -1, NULL, NULL, NULL)); } } g_string_free(pref_name_full, TRUE); } else { char *decoded; if(!pref_name || purple_strequal(pref_name, "/")) return; pref_name_full = g_string_new(pref_name); for(tmp = prefs_stack; tmp; tmp = tmp->next) { pref_name_full = g_string_prepend_c(pref_name_full, '/'); pref_name_full = g_string_prepend(pref_name_full, tmp->data); } pref_name_full = g_string_prepend_c(pref_name_full, '/'); switch(pref_type) { case PURPLE_PREF_NONE: purple_prefs_add_none(pref_name_full->str); break; case PURPLE_PREF_BOOLEAN: purple_prefs_set_bool(pref_name_full->str, atoi(pref_value)); break; case PURPLE_PREF_INT: purple_prefs_set_int(pref_name_full->str, atoi(pref_value)); break; case PURPLE_PREF_STRING: purple_prefs_set_string(pref_name_full->str, pref_value); break; case PURPLE_PREF_STRING_LIST: purple_prefs_set_string_list(pref_name_full->str, NULL); break; case PURPLE_PREF_PATH: if (pref_value) { decoded = g_filename_from_utf8(pref_value, -1, NULL, NULL, NULL); purple_prefs_set_path(pref_name_full->str, decoded); g_free(decoded); } else { purple_prefs_set_path(pref_name_full->str, NULL); } break; case PURPLE_PREF_PATH_LIST: purple_prefs_set_path_list(pref_name_full->str, NULL); break; } prefs_stack = g_list_prepend(prefs_stack, g_strdup(pref_name)); g_string_free(pref_name_full, TRUE); } }
static void purple_prefs_rename_node(struct purple_pref *oldpref, struct purple_pref *newpref) { struct purple_pref *child, *next; char *oldname, *newname; /* if we're a parent, rename the kids first */ for(child = oldpref->first_child; child != NULL; child = next) { struct purple_pref *newchild; next = child->sibling; for(newchild = newpref->first_child; newchild != NULL; newchild = newchild->sibling) { if(purple_strequal(child->name, newchild->name)) { purple_prefs_rename_node(child, newchild); break; } } if(newchild == NULL) { /* no rename happened, we weren't able to find the new pref */ char *tmpname = pref_full_name(child); purple_debug_error("prefs", "Unable to find rename pref for %s\n", tmpname); g_free(tmpname); } } oldname = pref_full_name(oldpref); newname = pref_full_name(newpref); if (oldpref->type != newpref->type) { purple_debug_error("prefs", "Unable to rename %s to %s: differing types\n", oldname, newname); g_free(oldname); g_free(newname); return; } purple_debug_info("prefs", "Renaming %s to %s\n", oldname, newname); g_free(oldname); switch(oldpref->type) { case PURPLE_PREF_NONE: break; case PURPLE_PREF_BOOLEAN: purple_prefs_set_bool(newname, oldpref->value.boolean); break; case PURPLE_PREF_INT: purple_prefs_set_int(newname, oldpref->value.integer); break; case PURPLE_PREF_STRING: purple_prefs_set_string(newname, oldpref->value.string); break; case PURPLE_PREF_STRING_LIST: purple_prefs_set_string_list(newname, oldpref->value.stringlist); break; case PURPLE_PREF_PATH: purple_prefs_set_path(newname, oldpref->value.string); break; case PURPLE_PREF_PATH_LIST: purple_prefs_set_path_list(newname, oldpref->value.stringlist); break; } g_free(newname); remove_pref(oldpref); }