yacos/client/src/main_window.c

58 lines
1.8 KiB
C
Raw Normal View History

2019-07-20 23:50:50 +02:00
#include "main_window.h"
struct mainWindow *mainWindow_new(GtkApplication *app)
{
GtkBuilder *builder;
struct mainWindow *mainWindow;
builder = gtk_builder_new_from_resource("/net/notsyncing/yacos/glade/mainWindow.glade");
mainWindow = malloc(sizeof(struct mainWindow));
mainWindow->main_window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window"));
mainWindow->stack_main = GTK_STACK(gtk_builder_get_object(builder, "stack_main"));
mainWindow->page_intro.box = GTK_WIDGET(gtk_builder_get_object(builder, "box_intro"));
mainWindow->page_cart.box = GTK_WIDGET(gtk_builder_get_object(builder, "box_cart"));
mainWindow->page_cart.list = GTK_LIST_BOX(gtk_builder_get_object(builder, "list_main"));
gtk_builder_connect_signals(builder, NULL);
g_object_unref(G_OBJECT(builder));
return mainWindow;
}
2019-07-24 20:22:10 +02:00
void mainWindow_scan_tags(YacosScanner *scanner, struct mainWindow *mainWindow)
{
2019-07-24 21:25:53 +02:00
// TODO: Currently slow AF! And dirty. Pls rewrite (yea yea I know you won't...)
2019-07-24 20:22:10 +02:00
gtk_stack_set_visible_child(mainWindow->stack_main, mainWindow->page_cart.box);
2019-07-24 21:25:53 +02:00
GtkWidget *le;
2019-07-24 21:19:26 +02:00
GList *l;
yacos_tag_id tag_id;
GList *stack_children;
GList *ll;
gboolean found = 0;
for (l = yacos_scanner_get_present_tags(scanner); l != NULL; l = l->next) {
tag_id = ((struct yacos_scanner_tag*) l->data)->tag_id;
2019-07-24 21:25:53 +02:00
stack_children = gtk_container_get_children(GTK_CONTAINER(mainWindow->page_cart.list));
2019-07-24 21:19:26 +02:00
for (ll = stack_children; ll != NULL; ll = ll->next) {
if (yacos_cart_item_get_id(((YacosCartItem *) ll->data)) == tag_id) {
found = 1;
break;
}
}
if (found)
continue;
2019-07-24 21:25:53 +02:00
le = yacos_cart_item_new();
2019-07-24 21:19:26 +02:00
yacos_cart_item_set_id(YACOS_CART_ITEM(le), tag_id);
yacos_cart_item_fetch_meta(YACOS_CART_ITEM(le));
yacos_cart_item_fetch_image(YACOS_CART_ITEM(le));
gtk_list_box_insert(mainWindow->page_cart.list, le, -1);
gtk_widget_show(le);
}
2019-07-24 20:22:10 +02:00
}