yacos/client/src/main_window.c

90 lines
3.0 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));
2019-12-13 16:16:23 +01:00
mainWindow->state = STATE_COLLECT;
2019-07-20 23:50:50 +02:00
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"));
2019-12-13 16:16:23 +01:00
mainWindow->page_processing.box = GTK_WIDGET(gtk_builder_get_object(builder, "box_processing"));
mainWindow->page_processing.stack_loading_confirmation = GTK_STACK(gtk_builder_get_object(builder, "stack_loading_confirmation"));
2019-07-20 23:50:50 +02:00
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...)
GtkWidget *le;
2019-07-24 21:19:26 +02:00
GList *l;
2019-12-13 16:16:23 +01:00
struct yacos_scanner_tag *tag = NULL;
struct yacos_scanner_tag *id = NULL;
2019-07-24 21:19:26 +02:00
GList *stack_children;
GList *ll;
gboolean found = 0;
2019-12-13 16:16:23 +01:00
/* Only process if we are currently interested in reading tags */
if (mainWindow->state == STATE_COLLECT) {
for (l = yacos_scanner_get_present_tags(scanner); l != NULL; l = l->next) {
tag = ((struct yacos_scanner_tag*) l->data);
if (tag->tag_type == TAG_TYPE_ID)
id = tag;
if (tag->tag_type != TAG_TYPE_ITEM)
continue;
stack_children = gtk_container_get_children(GTK_CONTAINER(mainWindow->page_cart.list));
for (ll = stack_children; ll != NULL; ll = ll->next) {
if (yacos_cart_item_get_id(((YacosCartItem *) ll->data)) == tag->tag_id) {
found = 1;
break;
}
}
if (found)
continue;
le = yacos_cart_item_new();
yacos_cart_item_set_yacos_api(YACOS_CART_ITEM(le),
mainWindow->api);
yacos_cart_item_set_id(YACOS_CART_ITEM(le), tag->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);
}
if (id) { /* A valid ID was presented */
stack_children = gtk_container_get_children(GTK_CONTAINER(mainWindow->page_cart.list));
if (stack_children) { /* Items in cart -> Go to check-out */
mainWindow->state = STATE_PROCESS;
gtk_stack_set_visible_child(mainWindow->stack_main, mainWindow->page_processing.box);
} else { /* No items in cart -> Go to check-in */
/* TODO */
2019-07-24 21:19:26 +02:00
}
2019-12-13 16:16:23 +01:00
} else { /* (Only) items were added, make sure we show the cart */
gtk_stack_set_visible_child(mainWindow->stack_main, mainWindow->page_cart.box);
2019-07-24 21:19:26 +02:00
}
}
2019-07-24 20:22:10 +02:00
}
2019-07-28 12:35:22 +02:00
void mainWindow_set_yacos_api(struct mainWindow *mainWindow, YacosApi *api)
{
mainWindow->api = api;
}