diff --git a/src/e_mod_main.c b/src/e_mod_main.c index 3e4bd73..90433e1 100644 --- a/src/e_mod_main.c +++ b/src/e_mod_main.c @@ -45,6 +45,7 @@ struct _Instance Ecore_Event_Handler *url_data_handler; Ecore_Event_Handler *url_complete_handler; + const char *update_time; struct { int temp; @@ -195,6 +196,8 @@ _gc_shutdown(E_Gadcon_Client *gcc) if (inst->area) eina_stringshare_del(inst->area); eina_strbuf_free(inst->buffer); + if (inst->update_time) + eina_stringshare_del(inst->update_time); inst->url = NULL; forecasts_config->instances = @@ -558,6 +561,20 @@ _forecasts_url_complete(void *data, int type EINA_UNUSED, void *event) return EINA_FALSE; } +static void +_timestamp_local(const char *timestamp, char *buf, size_t len) +{ + struct tm tm_in; + struct tm *tm_out; + time_t t; + + memset(&tm_in, 0, sizeof(struct tm)); + strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ", &tm_in); + t = mktime(&tm_in); + tm_out = localtime(&t); + strftime(buf, len - 1, "%Y-%m-%d %H:%M:%S", tm_out); +} + static struct tm * _timestamp_time(const char *timestamp) { @@ -567,9 +584,7 @@ _timestamp_time(const char *timestamp) memset(&tm_in, 0, sizeof(struct tm)); strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ", &tm_in); - t = mktime(&tm_in); - tm_out = localtime(&t); return tm_out; @@ -621,6 +636,13 @@ _forecasts_parse(void *data) if (!o_root) goto error; json_object *o_properties = json_object_object_get(o_root, "properties"); if (!o_properties) goto error; + json_object *o_meta = json_object_object_get(o_properties, "meta"); + if (!o_meta) goto error; + json_object *o_updated = json_object_object_get(o_meta, "updated_at"); + if (!o_updated) goto error; + timestamp = json_object_get_string(o_updated); + if (!timestamp) goto error; + eina_stringshare_replace(&inst->update_time, timestamp); json_object *o_timeseries = json_object_object_get(o_properties, "timeseries"); if (!o_timeseries) goto error; if (json_object_get_type(o_timeseries) != json_type_array) goto error; @@ -899,7 +921,7 @@ _forecasts_popup_content_create(Instance *inst) { Evas_Object *base, *bx, *hbx, *fr, *tb, *lb; Evas_Object *rec, *ic, *im; - char buf[4096]; + char buf[2048], tmp[2048]; int row = 0; Evas_Coord w, h; @@ -941,7 +963,13 @@ _forecasts_popup_content_create(Instance *inst) if (h > 160) h = 160; im = e_widget_image_add_from_object(e_comp->evas, ic, w, h); evas_object_show(im); - elm_table_pack(tb, im, 0, row++, 2, 1); + elm_table_pack(tb, im, 0, row, 2, 1); + + _timestamp_local(inst->update_time, tmp, sizeof(tmp)); + snprintf(buf, sizeof(buf), D_("Updated: %s"), tmp); + lb = _lb_add(base, buf); + evas_object_size_hint_align_set(lb, 1.0, 0.0); + elm_table_pack(tb, lb, 0, row++, 2, 1); snprintf(buf, sizeof(buf), "%s", inst->location); lb = _lb_add(base, buf);