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

@ -124,91 +124,105 @@
</packing>
</child>
<child>
<object class="GtkStack" id="stack_loading_confirmation">
<object class="GtkBox" id="box_processing">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<property name="orientation">vertical</property>
<property name="homogeneous">True</property>
<child>
<object class="GtkBox">
<object class="GtkStack" id="stack_loading_confirmation">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="transition_type">crossfade</property>
<child>
<object class="GtkSpinner">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkSpinner">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="active">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Please wait while we process your order...</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Please wait while we process your order...</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-apply</property>
<property name="icon_size">6</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Order processed successfully!</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Thank you!</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="name">page0</property>
<property name="title" translatable="yes">page0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-apply</property>
<property name="icon_size">3</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Order processed successfully!</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Thank you!</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">page1</property>
<property name="position">1</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
@ -218,6 +232,9 @@
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<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");
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"));
@ -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.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));
@ -27,34 +33,53 @@ struct mainWindow *mainWindow_new(GtkApplication *app)
void mainWindow_scan_tags(YacosScanner *scanner, struct mainWindow *mainWindow)
{
// 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;
GList *l;
yacos_tag_id tag_id;
struct yacos_scanner_tag *tag = NULL;
struct yacos_scanner_tag *id = NULL;
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;
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_id) {
found = 1;
break;
/* 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);
}
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_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);
}
}

View File

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