Separate ID and goods tags

This commit is contained in:
Markus Koch 2019-12-13 16:16:23 +01:00
parent 333e4fc03e
commit 22eafba241
3 changed files with 142 additions and 92 deletions

View File

@ -123,6 +123,12 @@
<property name="position">1</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkBox" id="box_processing">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child> <child>
<object class="GtkStack" id="stack_loading_confirmation"> <object class="GtkStack" id="stack_loading_confirmation">
<property name="visible">True</property> <property name="visible">True</property>
@ -137,6 +143,7 @@
<object class="GtkSpinner"> <object class="GtkSpinner">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="active">True</property>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
@ -172,7 +179,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="stock">gtk-apply</property> <property name="stock">gtk-apply</property>
<property name="icon_size">3</property> <property name="icon_size">6</property>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
@ -212,12 +219,22 @@
</packing> </packing>
</child> </child>
</object> </object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
<packing> <packing>
<property name="name">page0</property> <property name="name">page0</property>
<property name="title" translatable="yes">page0</property> <property name="title" translatable="yes">page0</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<placeholder/>
</child>
</object> </object>
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>

View File

@ -8,6 +8,9 @@ struct mainWindow *mainWindow_new(GtkApplication *app)
builder = gtk_builder_new_from_resource("/net/notsyncing/yacos/glade/mainWindow.glade"); builder = gtk_builder_new_from_resource("/net/notsyncing/yacos/glade/mainWindow.glade");
mainWindow = malloc(sizeof(struct mainWindow)); mainWindow = malloc(sizeof(struct mainWindow));
mainWindow->state = STATE_COLLECT;
mainWindow->main_window = GTK_WIDGET(gtk_builder_get_object(builder, "main_window")); 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->stack_main = GTK_STACK(gtk_builder_get_object(builder, "stack_main"));
@ -17,6 +20,9 @@ struct mainWindow *mainWindow_new(GtkApplication *app)
mainWindow->page_cart.box = GTK_WIDGET(gtk_builder_get_object(builder, "box_cart")); 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_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); gtk_builder_connect_signals(builder, NULL);
g_object_unref(G_OBJECT(builder)); g_object_unref(G_OBJECT(builder));
@ -27,20 +33,26 @@ struct mainWindow *mainWindow_new(GtkApplication *app)
void mainWindow_scan_tags(YacosScanner *scanner, struct mainWindow *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...) // TODO: Currently slow AF! And dirty. Pls rewrite (yea yea I know you won't...)
gtk_stack_set_visible_child(mainWindow->stack_main, mainWindow->page_cart.box);
GtkWidget *le; GtkWidget *le;
GList *l; GList *l;
yacos_tag_id tag_id; struct yacos_scanner_tag *tag = NULL;
struct yacos_scanner_tag *id = NULL;
GList *stack_children; GList *stack_children;
GList *ll; GList *ll;
gboolean found = 0; 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) { for (l = yacos_scanner_get_present_tags(scanner); l != NULL; l = l->next) {
tag_id = ((struct yacos_scanner_tag*) l->data)->tag_id; 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)); stack_children = gtk_container_get_children(GTK_CONTAINER(mainWindow->page_cart.list));
for (ll = stack_children; ll != NULL; ll = ll->next) { for (ll = stack_children; ll != NULL; ll = ll->next) {
if (yacos_cart_item_get_id(((YacosCartItem *) ll->data)) == tag_id) { if (yacos_cart_item_get_id(((YacosCartItem *) ll->data)) == tag->tag_id) {
found = 1; found = 1;
break; break;
} }
@ -50,12 +62,25 @@ void mainWindow_scan_tags(YacosScanner *scanner, struct mainWindow *mainWindow)
le = yacos_cart_item_new(); le = yacos_cart_item_new();
yacos_cart_item_set_yacos_api(YACOS_CART_ITEM(le), yacos_cart_item_set_yacos_api(YACOS_CART_ITEM(le),
mainWindow->api); mainWindow->api);
yacos_cart_item_set_id(YACOS_CART_ITEM(le), tag_id); 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_meta(YACOS_CART_ITEM(le));
yacos_cart_item_fetch_image(YACOS_CART_ITEM(le)); yacos_cart_item_fetch_image(YACOS_CART_ITEM(le));
gtk_list_box_insert(mainWindow->page_cart.list, le, -1); gtk_list_box_insert(mainWindow->page_cart.list, le, -1);
gtk_widget_show(le); 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) void mainWindow_set_yacos_api(struct mainWindow *mainWindow, YacosApi *api)

View File

@ -6,7 +6,11 @@
#include "cart_item.h" #include "cart_item.h"
#include "yacos_api.h" #include "yacos_api.h"
enum yacos_state {STATE_COLLECT, STATE_PROCESS, STATE_REVIEW};
struct mainWindow { struct mainWindow {
enum yacos_state state;
GtkWidget *main_window; GtkWidget *main_window;
YacosApi *api; YacosApi *api;
@ -21,6 +25,10 @@ struct mainWindow {
GtkListBox *list; GtkListBox *list;
} page_cart; } page_cart;
struct page_processing {
GtkWidget *box;
GtkStack *stack_loading_confirmation;
} page_processing;
}; };
struct mainWindow *mainWindow_new(); struct mainWindow *mainWindow_new();