Add handler for invalid tags

This commit is contained in:
Markus Koch 2019-07-26 20:47:54 +02:00
parent 51f7fc0394
commit 70fdfa7709
2 changed files with 17 additions and 3 deletions

View File

@ -16,6 +16,8 @@ typedef struct _YacosCartItemPriv {
yacos_tag_id tag_id;
yacos_cart_item_status status;
struct api {
gchar *url_base;
gchar *token;
@ -101,6 +103,7 @@ void yacos_cart_item_set_id(YacosCartItem *self, yacos_tag_id tag_id)
gchar *id_str;
gchar *id_str2;
self->priv.status = YACOS_CART_ITEM_STATUS_PENDING;
self->priv.tag_id = tag_id;
id_str = yacos_tag_id_to_str(tag_id);
@ -117,10 +120,15 @@ static void yacos_cart_item_fetch_meta_cb (SoupSession *session, SoupMessage *ms
const char *temp;
JsonParser *parser;
JsonReader *reader;
const static GdkRGBA color_error = {.red = 1.0, .green = 0.0, .blue = 0.0, .alpha = 1.0};
if (msg->status_code != 200) {
// TODO: Make this somewhat error tolerant
g_error("Received error code %d from server.", msg->status_code);
g_warning("Received error code %d from server.", msg->status_code);
gtk_label_set_text(GTK_LABEL(self->priv.label_title), "Unknown article");
gtk_widget_override_color(self->priv.label_title, GTK_STATE_FLAG_NORMAL, &color_error);
gtk_label_set_text(GTK_LABEL(self->priv.label_description), "This article will be ignored on checkout.");
gtk_label_set_text(GTK_LABEL(self->priv.label_comment), "If you think this is an error, please contact a member of staff.");
self->priv.status = YACOS_CART_ITEM_STATUS_INVALID;
return;
}
@ -149,6 +157,8 @@ static void yacos_cart_item_fetch_meta_cb (SoupSession *session, SoupMessage *ms
g_object_unref (reader);
g_object_unref (parser);
self->priv.status = YACOS_CART_ITEM_STATUS_VALID;
}
void yacos_cart_item_fetch_meta(YacosCartItem *self)

View File

@ -10,7 +10,11 @@ G_DECLARE_FINAL_TYPE(YacosCartItem, yacos_cart_item, YACOS, CART_ITEM, GtkListBo
#define TYPE_YACOS_CART_ITEM (yacos_cart_item_get_type())
typedef enum _yacos_cart_item_status {
YACOS_CART_ITEM_STATUS_PENDING = 0,
YACOS_CART_ITEM_STATUS_VALID,
YACOS_CART_ITEM_STATUS_INVALID
} yacos_cart_item_status;
GtkWidget *yacos_cart_item_new(void);
void yacos_cart_item_set_id(YacosCartItem *self, yacos_tag_id tag_id);