Browse Source

Prevent items from being added twice

master
Markus Koch 3 years ago
parent
commit
304c75c4db
  1. 22
      client/src/cart_item.c
  2. 1
      client/src/cart_item.h
  3. 2
      client/src/main.c
  4. 28
      client/src/main_window.c
  5. 16
      client/src/scanner.c
  6. 1
      client/src/scanner.h

22
client/src/cart_item.c

@ -96,13 +96,16 @@ GtkWidget *yacos_cart_item_new(void)
void yacos_cart_item_set_id(YacosCartItem *self, yacos_tag_id tag_id)
{
gchar *id_str;
gchar *id_str2;
self->priv.tag_id = tag_id;
id_str = yacos_tag_id_to_str(tag_id);
gtk_label_set_text(GTK_LABEL(self->priv.label_id), id_str);
id_str2 = g_strdup_printf("#%s", id_str);
g_free(id_str);
gtk_label_set_text(GTK_LABEL(self->priv.label_id), id_str2);
g_free(id_str2);
}
static void yacos_cart_item_fetch_meta_cb (SoupSession *session, SoupMessage *msg, gpointer user_data)
@ -151,6 +154,11 @@ void yacos_cart_item_fetch_meta(YacosCartItem *self)
gchar *url;
gchar *id_str;
gtk_label_set_text(GTK_LABEL(self->priv.label_title), "Loading ...");
gtk_label_set_text(GTK_LABEL(self->priv.label_description), "");
gtk_label_set_text(GTK_LABEL(self->priv.label_comment), "");
id_str = yacos_tag_id_to_str(self->priv.tag_id);
url = g_strdup_printf("%s?meta&id=%s", self->priv.api.url_base, id_str);
@ -163,3 +171,13 @@ void yacos_cart_item_fetch_meta(YacosCartItem *self)
yacos_cart_item_fetch_meta_cb,
self);
}
void yacos_cart_item_fetch_image(YacosCartItem *self)
{
return;
}
yacos_tag_id yacos_cart_item_get_id(YacosCartItem *self)
{
return self->priv.tag_id;
}

1
client/src/cart_item.h

@ -16,6 +16,7 @@ GtkWidget *yacos_cart_item_new(void);
void yacos_cart_item_set_id(YacosCartItem *self, yacos_tag_id tag_id);
void yacos_cart_item_fetch_meta(YacosCartItem *self);
void yacos_cart_item_fetch_image(YacosCartItem *self);
yacos_tag_id yacos_cart_item_get_id(YacosCartItem *self);
G_END_DECLS

2
client/src/main.c

@ -30,7 +30,7 @@ static void activate(GtkApplication* app, gpointer user_data)
g_signal_connect(scanner, "newtag",
(GCallback) mainWindow_scan_tags, (*mainWindow));
mainWindow_scan_tags(scanner, *mainWindow); // TODO: For testing only
//mainWindow_scan_tags(scanner, *mainWindow); // TODO: For testing only
}

28
client/src/main_window.c

@ -29,8 +29,28 @@ void mainWindow_scan_tags(YacosScanner *scanner, struct mainWindow *mainWindow)
// TODO: For testing only
gtk_stack_set_visible_child(mainWindow->stack_main, mainWindow->page_cart.box);
GtkWidget *le = yacos_cart_item_new();
yacos_cart_item_set_id(YACOS_CART_ITEM(le), 123);
yacos_cart_item_fetch_meta(YACOS_CART_ITEM(le));
gtk_list_box_insert(mainWindow->page_cart.list, le, -1);
gtk_widget_show(le);
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;
stack_children = gtk_container_get_children(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;
}
}
if (found)
continue;
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);
}
}

16
client/src/scanner.c

@ -100,9 +100,9 @@ static int yacos_scanner_list(YacosScanner *self)
if (new_tags) {
for (l = self->detected_tags; l != NULL; l = l->next) {
g_warning("Found %x (%d)",
((struct yacos_scanner_tag*)l->data)->tag_id,
((struct yacos_scanner_tag*)l->data)->tag_type);
g_info("Found %X (%d)",
((struct yacos_scanner_tag*)l->data)->tag_id,
((struct yacos_scanner_tag*)l->data)->tag_type);
}
}
@ -152,8 +152,6 @@ static void yacos_scanner_init(YacosScanner *self)
{
self->detected_tags = NULL;
return; // TODO: Disabled during development
g_debug("Using libnfc %s", nfc_version());
nfc_init(&self->nfc_ctx);
if (!self->nfc_ctx) {
@ -177,5 +175,11 @@ YacosScanner *yacos_scanner_new(void)
// Free afterwards using g_free
gchar *yacos_tag_id_to_str(yacos_tag_id tag_id)
{
return g_strdup_printf("%d", tag_id);
return g_strdup_printf("%X", tag_id);
}
GList *yacos_scanner_get_present_tags(YacosScanner *scanner)
{
return scanner->detected_tags;
}

1
client/src/scanner.h

@ -25,6 +25,7 @@ struct yacos_scanner_tag {
};
gchar *yacos_tag_id_to_str(yacos_tag_id tag_id);
GList *yacos_scanner_get_present_tags(YacosScanner *scanner);
G_END_DECLS

Loading…
Cancel
Save