diff options
Diffstat (limited to 'src/ui_wizards.c')
-rw-r--r-- | src/ui_wizards.c | 373 |
1 files changed, 373 insertions, 0 deletions
diff --git a/src/ui_wizards.c b/src/ui_wizards.c new file mode 100644 index 0000000..5ef0b3b --- /dev/null +++ b/src/ui_wizards.c @@ -0,0 +1,373 @@ +/* + * functions, callbacks and data types for wizards + * + * Copyright (c) 2015 Ultimaker B.V. + * Author: Olliver Schinagl <o.schinagl@ultimaker.com> + * + * SPDX-License-Identifier: AGPL-3.0+ + */ + +#include <Elementary.h> +#include <stdint.h> + +#include "eulogium.h" +#include "gettext.h" +#include "procedures.h" +#include "ui_wizards.h" + +struct _wizard_next_cb_data { + Evas_Object *navi; + struct wizard_data *wizard; + uint_fast8_t pagenum; + Eina_Bool pageindex; + uint_fast32_t nr; /* XXX passed now as number, replace with 'extrusion-train'-object later */ +}; + +static void _wizard_next_cb(void *data, Evas_Object *eo EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *content; + Evas_Object *navi = ((struct _wizard_next_cb_data *)data)->navi; + uint_fast8_t pagenum = ((struct _wizard_next_cb_data *)data)->pagenum; + Eina_Bool pageindex = ((struct _wizard_next_cb_data *)data)->pageindex; + uint_fast32_t nr = ((struct _wizard_next_cb_data *)data)->nr; + struct wizard_data *wizard = ((struct _wizard_next_cb_data *)data)->wizard; + + if (pagenum >= wizard->count) { + Elm_Object_Item *item; + + item = elm_naviframe_bottom_item_get(navi); + if (item) + elm_naviframe_item_pop_to(item); + } else { + wizard->screens[pagenum].nr = nr; + content = wizard_add(navi, wizard, pagenum, pageindex); + ui_stack_push(navi, content, PAGE_WIZARD); + } + free(data); +} + +static void _wizard_skip_cb(void *data, Evas_Object *eo EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Evas_Object *navi = ((struct _wizard_next_cb_data *)data)->navi; + + ui_stack_page_invalidate(navi, PAGE_WIZARD); + ui_stack_pop(navi); +} + +static void _wizard_next_del(void *data, Evas *e EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info EINA_UNUSED) +{ + struct _wizard_next_cb_data *wizard_next_cb_data = data; + + //free(wizard_next_cb_data); /* XXX double free?! */ +} + +static Eina_Bool _wizard_progress_update(void *data, int type EINA_UNUSED, void *event_info) +{ + Evas_Object *widget = data; + struct print_data *progress = event_info; + + printf("\n\n\n%f\n", progress->value); + printf("%d\n", progress->time); + printf("%d\n\n\n", progress->total_time); + + return ECORE_CALLBACK_PASS_ON; +} + +static void _wizard_widget_del(void *data, Evas *e EINA_UNUSED, Evas_Object *eo EINA_UNUSED, void *event_info EINA_UNUSED) +{ +// Evas_Object *widget = data; + Ecore_Event_Handler *handler = data; +// struct _wizard_data *wizard = data; + +// handler = evas_object_data_get(widget, "handler"); + + if (handler) + ecore_event_handler_del(handler); + +// free(screen); +} + +Evas_Object *wizard_add(Evas_Object *navi, struct wizard_data *wizard, uint_fast8_t pagenum, Eina_Bool pageindex) +{ + Evas_Object *obj; + Evas_Object *_top, *_bottom; + Evas_Object *widget; + Ecore_Event_Handler *handler = NULL; + + _top = elm_box_add(navi); + evas_object_show(_top); + + if (wizard->count == 0) { + EINA_LOG_WARN("Tut tut, we can't have 0 wizard screens!\n"); + return NULL; + } + + if (pagenum >= wizard->count) + pagenum = wizard->count - 1; + + if (pageindex || wizard->title) { + char buf[30]; + Evas_Object *box; + + box = elm_box_add(_top); + elm_box_horizontal_set(box, EINA_TRUE); + evas_object_size_hint_weight_set(box, 0.0, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(box, EVAS_HINT_FILL, 0.0); + evas_object_show(box); + + if (wizard->title) { + obj = elm_label_add(box); + elm_object_text_set(obj, _(wizard->title)); /* optionally do the same as the index, but left */ + elm_object_style_set(obj, "title"); + evas_object_show(obj); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_start(box, obj); + } + if (pageindex) { + obj = elm_label_add(box); + snprintf(buf, sizeof(buf), "<align=right>%d/%d</align>", pagenum + 1, wizard->count); + elm_object_text_set(obj, buf); + elm_object_style_set(obj, "title"); + evas_object_show(obj); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, obj); + } + + elm_box_pack_end(_top, box); + } + + if (wizard->screens[pagenum].text) { + obj = elm_label_add(_top); + elm_object_text_set(obj, _(wizard->screens[pagenum].text)); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(obj, 0.5, 0.5); + evas_object_show(obj); + elm_box_pack_end(_top, obj); + } + + switch (wizard->screens[pagenum].type) { + case WIZARD_PROGRESS: + widget = elm_progressbar_add(_top); + elm_progressbar_pulse_set(widget, EINA_TRUE); + elm_progressbar_pulse(widget, EINA_TRUE); + elm_progressbar_horizontal_set(widget, EINA_TRUE); + elm_progressbar_unit_format_set(widget, "%1.0f%%"); + evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(widget); + elm_box_pack_end(_top, widget); + //handler = ecore_event_handler_add(event, _wizard_progress_update, widget); + evas_object_data_set(widget, "handler", handler); + break; + case WIZARD_END: /* fall through */ + default: + break; + } + if (handler) + evas_object_event_callback_add(widget, EVAS_CALLBACK_DEL, _wizard_widget_del, handler); + + if (wizard->screens[pagenum].func) + wizard->screens[pagenum].func(wizard->screens[pagenum].nr); + + _bottom = elm_box_add(navi); + elm_box_horizontal_set(_bottom, EINA_TRUE); + evas_object_show(_bottom); + + if (!wizard->screens[pagenum].prev_button.label && !wizard->screens[pagenum].next_button.label) + EINA_LOG_ERR("Both buttons empty, need to add an empty button here"); + if (wizard->screens[pagenum].prev_button.label) { + struct _wizard_next_cb_data *wizard_next_cb_data; + + wizard_next_cb_data = malloc(sizeof(struct _wizard_next_cb_data)); + wizard_next_cb_data->navi = navi; + wizard_next_cb_data->wizard = wizard; + wizard_next_cb_data->pagenum = pagenum + 1; + wizard_next_cb_data->pageindex = EINA_TRUE; + wizard_next_cb_data->nr = wizard->screens[pagenum].prev_button.cb.nr; + + obj = elm_button_add(_bottom); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_text_set(obj, _(wizard->screens[pagenum].prev_button.label)); + evas_object_smart_callback_add(obj, "clicked", wizard->screens[pagenum].prev_button.cb.func, wizard_next_cb_data); + evas_object_show(obj); + elm_box_pack_end(_bottom, obj); + + evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _wizard_next_del, wizard_next_cb_data); + } + if (wizard->screens[pagenum].next_button.label) { + struct _wizard_next_cb_data *wizard_next_cb_data; + + wizard_next_cb_data = malloc(sizeof(struct _wizard_next_cb_data)); + wizard_next_cb_data->navi = navi; + wizard_next_cb_data->wizard = wizard; + wizard_next_cb_data->pagenum = pagenum + 1; + wizard_next_cb_data->pageindex = EINA_TRUE; + wizard_next_cb_data->nr = wizard->screens[pagenum].next_button.cb.nr; + + obj = elm_button_add(_bottom); + evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_size_hint_weight_set(obj, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_text_set(obj, _(wizard->screens[pagenum].next_button.label)); + evas_object_smart_callback_add(obj, "clicked", wizard->screens[pagenum].next_button.cb.func, wizard_next_cb_data); + evas_object_show(obj); + elm_box_pack_end(_bottom, obj); + + evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _wizard_next_del, wizard_next_cb_data); + } + + return eulogium_split_screen(navi, _top, _bottom); +} + +void __wizard_count(struct wizard_data *wizard) +{ + while (wizard->screens[wizard->count].type != WIZARD_END) + wizard->count++; +} + +void wizard_init(struct wizard_data *wizard) +{ + __wizard_count(wizard); +} + +void wizard_init_all(void) +{ + wizard_init(&material_load); + wizard_init(&material_unload); +} + +struct wizard_data material_load = { + .count = 0, + .title = N_("Insert Material"), + .screens = { + { + .type = WIZARD_NONE, + .func = NULL, + .text = N_("To insert material<br>we need to do stuff"), + .prev_button = { + .label = N_("Skip Wiz."), + .cb = { + .func = _wizard_skip_cb, + }, + }, + .next_button = { + .label = N_("Continue"), + .cb = { + .func = _wizard_next_cb, + }, + }, + }, { + .type = WIZARD_NONE, + .func = NULL, + .text = N_("Choose a nozzle<br>to insert<br>material into"), + .prev_button = { + .label = N_("Left"), + .cb = { + .func = _wizard_next_cb, + }, + }, + .next_button = { + .label = N_("Right"), + .cb = { + .func = _wizard_next_cb, + }, + }, + }, { + .type = WIZARD_PROGRESS, + .func = NULL, + .text = N_("Heating nozzle<br>for insertion."), + .prev_button = { + .label = N_("Abort Wiz."), + .cb = { + .func = _wizard_skip_cb, + }, + }, + .next_button = { + .label = NULL, + }, + }, { + .type = WIZARD_NONE, + .func = NULL, + .text = N_("Material has<br>been inserted."), + .prev_button = { + .label = NULL, + }, + .next_button = { + .label = N_("Continue"), + .cb = { + .func = _wizard_next_cb, + }, + }, + }, { .type = WIZARD_END, }, /* sentinel */ + }, +}; + +struct wizard_data material_unload = { + .count = 0, + .title = N_("Remove Material"), + .proc_key = PROC_MATERIAL_UNLOAD, + .screens = { + { + .type = WIZARD_NONE, + //.func = &_wizard_procedure_start, + .text = N_("To remove material<br>we need to do stuff"), + .prev_button = { + .label = N_("Skip Wiz."), + .cb = { + .func = _wizard_skip_cb, + }, + }, + .next_button = { + .label = N_("Continue"), + .cb = { + .func = _wizard_next_cb, + }, + }, + }, { + .type = WIZARD_NONE, + //.func = &_wizard_procedure_message, + .text = N_("Choose a nozzle<br>to remove<br>material from"), + .prev_button = { + .label = N_("Left"), + .cb = { + .func = _wizard_next_cb, + .nr = 0, + }, + }, + .next_button = { + .label = N_("Right"), + .cb = { + .func = _wizard_next_cb, + .nr = 1, + }, + }, + }, { + .type = WIZARD_PROGRESS, + //.func = &_wizard_procedure_message, + .text = N_("Heating nozzle<br>for removal."), + .prev_button = { + .label = N_("Skip Wiz."), + .cb = { + .func = _wizard_skip_cb, + }, + }, + .next_button = { + .label = NULL, + }, + }, { + .type = WIZARD_NONE, + .func = NULL, + .text = N_("Material has<br>been removed."), + .prev_button = { + .label = NULL, + }, + .next_button = { + .label = N_("Continue"), + .cb = { + .func = _wizard_next_cb, + }, + }, + }, { .type = WIZARD_END, }, /* sentinel */ + }, +}; |