Yet Another Check-Out System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

89 lines
3.0 KiB

#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->state = STATE_COLLECT;
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"));
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"));
gtk_builder_connect_signals(builder, NULL);
g_object_unref(G_OBJECT(builder));
return mainWindow;
}
void mainWindow_scan_tags(YacosScanner *scanner, struct mainWindow *mainWindow)
{
// TODO: Currently slow AF! And dirty. Pls rewrite (yea yea I know you won't...)
GtkWidget *le;
GList *l;
struct yacos_scanner_tag *tag = NULL;
struct yacos_scanner_tag *id = NULL;
GList *stack_children;
GList *ll;
gboolean found = 0;
/* 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 */
}
} else { /* (Only) items were added, make sure we show the cart */
gtk_stack_set_visible_child(mainWindow->stack_main, mainWindow->page_cart.box);
}
}
}
void mainWindow_set_yacos_api(struct mainWindow *mainWindow, YacosApi *api)
{
mainWindow->api = api;
}