/** * Creates a list element with the specified data and inserts it last in a list. * * @param list The list to add the element to. * @param data The data to assign to the new element. * @return True if successful, false if out of memory. */ int list_append(struct list *list, void *data) { struct element *e = list_element_new(data); if(e == NULL) { return 0; } list_append_element(list, e); return 1; }
int list_insert_at(struct list *list, int index, void *data) { struct element *e = list_element_new(data); if(e == NULL) { return 0; } if(!list_insert_element_at(list, index, e)) { /* TODO: free_data should be per list instead, this is not clean... */ list_element_free(e, 0); return 0; } return 1; }
/** * Creates the head element and initializes a list. * * @param list The list to initialize. * @return True if successful, false if out of memory. */ int list_init(struct list *list) { memset(list, 0, sizeof(struct list)); /* Allocate a new head element. */ list->head = list_element_new(NULL); /* Out of memory? */ if(list->head == NULL) { return 0; } /* No more elements at the moment. */ list->head->next = list->head; list->head->prev = list->head; return 1; }
static void fill_wifi_list(GtkWidget *gtk_list, libin_wifi* pp) { //GtkWidget *gtk_list; GList *items; GList *copy; GtkWidget *listitem; GtkWidget *elementItem; GSList *group; GtkWidget *radio; gint i; //must initialize here for first use! items = NULL; copy = NULL; group = NULL; Element* element_content = NULL; for(i=1;i<=pp[i].NET_NUMBER;i++) {//.NET_NUMBER==0means the last?? listitem = gtk_list_item_new(); items = g_list_append(items, listitem); elementItem = list_element_new(pp[i].ESSID, IMG_FILE, (double)(100+pp[i].Singal_level)/100, &group); char *onState = "on"; char *offState = "off"; if(!strcmp("on",pp[i].Encryption_key)) {//if crypted elementItem = list_element_new(pp[i].ESSID, IMG_ENCRYPTED, (double)(100+pp[i].Singal_level)/100, &group); } /*else if(!strcmp("off",pp[i].Encryption_key)) { elementItem = list_element_new(pp[i].ESSID, IMG_FILE, (double)(100+pp[i].Singal_level)/100, &group); //elementItem = list_element_new(pp[i].ESSID, IMG_UNENCRYPTED, // (double)(100+pp[i].Singal_level)/100, &group); }*/ else { //elementItem = list_element_new(pp[i].ESSID, IMG_FILE, // (double)(100+pp[i].Singal_level)/100, &group); elementItem = list_element_new(pp[i].ESSID, NULL, (double)(100+pp[i].Singal_level)/100, &group); } gtk_container_add(GTK_CONTAINER(listitem), elementItem); gtk_widget_show_all(listitem); //gtk_container_add(GTK_CONTAINER(gtk_list), listitem); element_content = g_object_get_data (G_OBJECT (elementItem), "element_content"); g_object_set_data (G_OBJECT (element_content->radiobutton), "network", g_strdup (pp[i].ESSID)); g_object_set_data (G_OBJECT (element_content->radiobutton), "password", pp[i].Encryption_key); if(1 == i) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(element_content->radiobutton),TRUE); select_radio(GTK_TOGGLE_BUTTON(element_content->radiobutton), NULL); } } /*for(i = 0; i < 5; ++i) { listitem = gtk_list_item_new(); items = g_list_append(items, listitem); elementItem = list_element_new("name", IMG_FILE, 0.8, &group); //gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),TRUE); #if MY_DEBUG_OUT == 1 g_print("add element to listitem\n"); #endif gtk_container_add(GTK_CONTAINER(listitem), elementItem); #if MY_DEBUG_OUT == 1 g_print("add element to listitem ok\n"); #endif gtk_widget_show_all(listitem); }*/ copy = g_list_copy(items); g_list_free(items); items = NULL; gtk_list_append_items(GTK_LIST(gtk_list), copy); //return gtk_list; }