summaryrefslogtreecommitdiffstats
path: root/src/eulogium.c
diff options
context:
space:
mode:
authorOlliver Schinagl <o.schinagl@ultimaker.com>2015-05-08 11:40:29 (GMT)
committerOlliver Schinagl <o.schinagl@ultimaker.com>2015-05-08 11:44:45 (GMT)
commit74e3678941097e1dbdebb49a462b08984078eda1 (patch)
tree3e101f515da45b9fa73a81ae3602a582713551b2 /src/eulogium.c
parent208e499dda9d68cb7dcccdeb4630ca471099361e (diff)
downloadeulogium-74e3678941097e1dbdebb49a462b08984078eda1.zip
eulogium-74e3678941097e1dbdebb49a462b08984078eda1.tar.gz
eulogium-74e3678941097e1dbdebb49a462b08984078eda1.tar.bz2
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 <o.schinagl@ultimaker.com>
Diffstat (limited to '')
-rw-r--r--src/eulogium.c89
1 files changed, 89 insertions, 0 deletions
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);