From 74e3678941097e1dbdebb49a462b08984078eda1 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Fri, 8 May 2015 13:40:29 +0200 Subject: Add progress update timer for print-progress While we poll the remaining time with griffin.printer, griffin.printer doesn't know this yet, so results are untested and may not work. Signed-off-by: Olliver Schinagl --- src/eulogium.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/eulogium.h | 4 +++ 2 files changed, 93 insertions(+) diff --git a/src/eulogium.c b/src/eulogium.c index 12f4450..7b291c5 100644 --- a/src/eulogium.c +++ b/src/eulogium.c @@ -453,11 +453,100 @@ Evas_Object *eulogium_split_screen(Evas_Object *parent, Evas_Object *top, Evas_O return table; } +static void _on_get_progress_ret(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED) +{ + const char *errname, *errmsg; + struct eulogium_data *eulogium = data; + + if (eldbus_message_error_get(msg, &errname, &errmsg)) { + EINA_LOG_ERR("%s %s", errname, errmsg); + return; + } + if (!eldbus_message_arguments_get(msg, "d", &eulogium->print.progress)) { + EINA_LOG_ERR("Failed to get print progress."); + return; + } +} + +static Eina_Bool _timer_progress_data_update_cb(void *data) +{ + struct eulogium_data *eulogium = data; + static enum printer_status status = -1; + static double progress = 0; + static double time = -1; + + eldbus_proxy_call(eulogium->dbus.proxy[HARMA], "getProgress", _on_get_progress_ret, eulogium, -1, ""); + + if (eulogium->printer.status != status) { + elm_object_text_set(eulogium->status, griffin_print_status[eulogium->printer.status]); + status = eulogium->printer.status; + } + if (eulogium->print.progress != progress) { + elm_progressbar_value_set(eulogium->progress, eulogium->print.progress); + progress = eulogium->print.progress; + } + if (eulogium->print.name_changed == EINA_TRUE) { + elm_object_text_set(eulogium->name, eulogium->print.name); + eulogium->print.name_changed = EINA_FALSE; + } + if (eulogium->print.time != time) { + char buf[255], *str; + uint_fast32_t time = 0; + + /* XXX: this is just quick n dirty, time.h should have better stuff for this */ + if (eulogium->print.time < 1) { + str = "Print time unknown"; + time = 0; + } + if (eulogium->print.time > 0) { + str = "Time left: %d second%s"; + time = eulogium->print.time; + } + if (eulogium->print.time > 60) { + str = "Time left: %d minute%s"; + time = eulogium->print.time / 60; + } + if (eulogium->print.time > 3600) { + str = "Time left: %d hour%s"; + time = eulogium->print.time / 3600; + } + if (eulogium->print.time > 86400) { + str = "Time left: %d day%s"; + time = eulogium->print.time / 86400; + } + if (eulogium->print.time > 604800) { + str = "Time left: %d week%s"; + time = eulogium->print.time / 604800; + } + if (eulogium->print.time > 2592000) { + str = "Time left: %d month%s"; + time = eulogium->print.time / 2592000; + } + if (eulogium->print.time > 31536000) { + str = "Time left: %d year%s"; + time = eulogium->print.time / 31536000; + } + + snprintf(buf, sizeof(buf), str, (int)eulogium->print.time, (time < 1) ? "s" : ""); + elm_object_text_set(eulogium->time, buf); + eulogium->print.time = time; + } + + return ECORE_CALLBACK_RENEW; +} + Evas_Object *eulogium_print_progress(struct eulogium_data *eulogium) { Evas_Object *_top, *_bottom; Evas_Object *obj; + eulogium->progress_data_refresh = ecore_timer_add(1.0, _timer_progress_data_update_cb, eulogium); + if (!eulogium->progress_data_refresh) { /* TODO make define for the timeout */ + EINA_LOG_ERR("Unable to create progress update timer"); + /* TODO Probably pop generic error here */ + return NULL; + } + _top = elm_box_add(eulogium->navi); evas_object_size_hint_weight_set(_top, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(_top, EVAS_HINT_FILL, EVAS_HINT_FILL); diff --git a/src/eulogium.h b/src/eulogium.h index 833e712..cae6200 100644 --- a/src/eulogium.h +++ b/src/eulogium.h @@ -56,6 +56,7 @@ struct print_data { double progress; char *file; char *name; + Eina_Bool name_changed; char *flags; enum file_type type; double material; @@ -76,8 +77,11 @@ struct dbus_data { struct eulogium_data { Evas_Object *navi; + Evas_Object *time; + Evas_Object *name; Evas_Object *status; Evas_Object *progress; + Ecore_Timer *progress_data_refresh; struct printer_data printer; struct print_data print; struct dbus_data dbus; -- cgit v0.12