How do I check if a value already exists in a GtkListStore to avoid duplicates? Dynamically I get values from a database according to a users data input, but if the user types the same or similar word to a previously typed word, it can return the same result, making it so there are not any duplicates values into my GtkListStore.
Here’s the function that I’m using currently to add the values into GtkListStore:
static inline void update_c_list(struct al_t *new_list, size_t new_list_size)
{
struct al_t *l = new_list;
GtkTreeIter iter;
size_t i = 0;
for(; i < new_list_size; i++,l++) {
if(/* magic to avoid double goes here */) {
gtk_list_store_append(completionmodel, &iter);
gtk_list_store_set(completionmodel,
&iter, C_NAME, l->name,
C_NICK, FOO_STRING(l->foo),
C_EMAIL, BAA_STRING(l->baa), -1);
}
}
gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(completionmodel));
}
You need to iterate the list and find if same data exists in it.
In your
update_c_list()function you need to: