summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlliver Schinagl <o.schinagl@ultimaker.com>2015-05-27 14:51:36 (GMT)
committerOlliver Schinagl <o.schinagl@ultimaker.com>2015-05-27 14:51:36 (GMT)
commitd4f3f1550cf51a629be8d979beb74490874f9d21 (patch)
tree514792bb41fba2baa007204161a88ebe9bfdbcf6
parentd9dab117ed43398ad4265f191e0306f7dd076a16 (diff)
downloadeulogium-d4f3f1550cf51a629be8d979beb74490874f9d21.zip
eulogium-d4f3f1550cf51a629be8d979beb74490874f9d21.tar.gz
eulogium-d4f3f1550cf51a629be8d979beb74490874f9d21.tar.bz2
Use macro for time calculation, those magic values look too horrible
Signed-off-by: Olliver Schinagl <o.schinagl@ultimaker.com>
-rw-r--r--src/eulogium.c35
1 files changed, 21 insertions, 14 deletions
diff --git a/src/eulogium.c b/src/eulogium.c
index 254cf0a..8812849 100644
--- a/src/eulogium.c
+++ b/src/eulogium.c
@@ -18,6 +18,14 @@
#define COPYRIGHT "Copyright © 2015 Olliver Schinagl <o.schinagl@ultimaker.com> and various contributors (see AUTHORS)."
+#define SECOND 1UL
+#define MINUTE (60UL * SECOND)
+#define HOUR (60UL * MINUTE)
+#define DAY (24UL * HOUR)
+#define WEEK (7UL * DAY)
+#define MONTH (4UL * WEEK)
+#define YEAR (52UL * WEEK)
+
static void _on_print_abort_ret(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED);
static void _cb_content_prev_set(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
static void _print_abort_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED);
@@ -575,7 +583,6 @@ static Eina_Bool _timer_progress_data_update_cb(void *data)
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;
@@ -584,32 +591,32 @@ static Eina_Bool _timer_progress_data_update_cb(void *data)
str = "Time left: %d second%s";
time = eulogium->print.time;
}
- if (eulogium->print.time > 60) {
+ if (eulogium->print.time > MINUTE) {
str = "Time left: %d minute%s";
- time = eulogium->print.time / 60;
+ time = eulogium->print.time / MINUTE;
}
- if (eulogium->print.time > 3600) {
+ if (eulogium->print.time > HOUR) {
str = "Time left: %d hour%s";
- time = eulogium->print.time / 3600;
+ time = eulogium->print.time / HOUR;
}
- if (eulogium->print.time > 86400) {
+ if (eulogium->print.time > DAY) {
str = "Time left: %d day%s";
- time = eulogium->print.time / 86400;
+ time = eulogium->print.time / DAY;
}
- if (eulogium->print.time > 604800) {
+ if (eulogium->print.time > WEEK) {
str = "Time left: %d week%s";
- time = eulogium->print.time / 604800;
+ time = eulogium->print.time / WEEK;
}
- if (eulogium->print.time > 2592000) {
+ if (eulogium->print.time > MONTH) {
str = "Time left: %d month%s";
- time = eulogium->print.time / 2592000;
+ time = eulogium->print.time / MONTH;
}
- if (eulogium->print.time > 31536000) {
+ if (eulogium->print.time > YEAR) {
str = "Time left: %d year%s";
- time = eulogium->print.time / 31536000;
+ time = eulogium->print.time / YEAR;
}
- snprintf(buf, sizeof(buf), str, (int)eulogium->print.time, (time < 1) ? "s" : "");
+ snprintf(buf, sizeof(buf), str, (int)eulogium->print.time, (time > 1) ? "s" : ""); /* TODO: This won't work with in10 */
elm_object_text_set(eulogium->time, buf);
eulogium->print.time = time;
}