From 2dfd1b47338d44fb1aa86a36008b8ff7886f289a Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Tue, 31 Jan 2017 21:03:48 +0100 Subject: [PATCH] extra: stop spreading error messages about progressbars this is done by stopping emitting the progress callbacks. --- src/bin/extra_private.h | 2 +- src/bin/extra_util.c | 16 +++++++- src/lib/extra.c | 78 +++++++++++++++++++++++++++++--------- src/lib/extra.h | 11 ++++-- src/lib/extra_api_helper.c | 30 ++++++++------- src/lib/extra_private.h | 7 +++- 6 files changed, 105 insertions(+), 39 deletions(-) diff --git a/src/bin/extra_private.h b/src/bin/extra_private.h index 5869ca3..4e52522 100644 --- a/src/bin/extra_private.h +++ b/src/bin/extra_private.h @@ -19,7 +19,7 @@ void extra_ui_theme_ask_for_default(Extra_Theme *theme); Extra_Progress* extra_ui_progress_popup_show(const char *title, Extra_Done_Cb done, void *data); typedef char *(Extra_ui_preview_get)(void *obj); -typedef char *(Extra_ui_preview_download)(Extra_Progress *progress, void *obj); +typedef Extra_Request *(Extra_ui_preview_download)(Extra_Progress *progress, void *obj); typedef struct { Extra_ui_preview_get *preview_get; diff --git a/src/bin/extra_util.c b/src/bin/extra_util.c index 5c6a1d0..c6a90a6 100644 --- a/src/bin/extra_util.c +++ b/src/bin/extra_util.c @@ -136,6 +136,7 @@ typedef struct { Extra_Progress p; void *data; Extra_Ui_Small_Preview_Accessor acc; + Extra_Request *req; } Small_Preview; static void @@ -166,6 +167,18 @@ _small_preview_done_cb(void *data) evas_object_hide(p->progress); } +static void +_small_preview_deleted(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Small_Preview *small; + + small = data; + + extra_request_mute(small->req); + + free(small); +} + Evas_Object* extra_ui_small_preview_new(Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par, void *data) { @@ -178,6 +191,7 @@ extra_ui_small_preview_new(Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par small->acc = acc; small->data = data; table = elm_table_add(par); + evas_object_event_callback_add(table, EVAS_CALLBACK_DEL, _small_preview_deleted, small); evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(table, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(table); @@ -216,7 +230,7 @@ extra_ui_small_preview_new(Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par small->p.data = small; small->p.done_cb = _small_preview_done_cb; small->p.progress_cb = _small_preview_progress_cb; - acc.preview_download(&small->p, data); + small->req = acc.preview_download(&small->p, data); evas_object_hide(small->image); evas_object_show(small->progress); } diff --git a/src/lib/extra.c b/src/lib/extra.c index 337a031..bd0b771 100644 --- a/src/lib/extra.c +++ b/src/lib/extra.c @@ -27,8 +27,8 @@ void _extra_theme_cache_load(); typedef struct { Extra_Theme theme; - char preview_state; //indicates if some downloads are in progress - char main_state; //indicates if some downloads are in progress + Extra_Request *preview; + Extra_Request *main; } Extra_Theme_Private; typedef struct { @@ -84,8 +84,8 @@ _fill_themes(Eina_Strbuf *buf) typedef struct { Extra_Background background; - char preview_state; //indicates if some downloads are in progress - char main_state; //indicates if some downloads are in progress + Extra_Request *preview; + Extra_Request *main; } Extra_Background_Private; typedef struct { @@ -395,7 +395,7 @@ extra_theme_preview_get(Extra_Theme *theme) Extra_Theme_Private *priv = ((Extra_Theme_Private*) theme); //download is in progress do not return the path - if (priv->preview_state & EXTRA_STATE_DOWNLOAD_IN_PROGRESS) return NULL; + if (priv->preview) return NULL; local = _extra_preview_local_generate("themes", theme->id, theme->version); if (!ecore_file_exists(local)) @@ -407,19 +407,26 @@ extra_theme_preview_get(Extra_Theme *theme) return local; } -EAPI void +EAPI Extra_Request* extra_theme_preview_download(Extra_Progress *progress, Extra_Theme *theme) { char *remote, *dst; Extra_Theme_Private *priv = ((Extra_Theme_Private*) theme); + if (priv->preview) + { + priv->preview->progress = *progress; + } + remote = _extra_preview_remote_generate("themes", theme->id); dst = _extra_preview_local_generate("themes", theme->id, theme->version); - extra_file_download(progress, remote, dst, &priv->preview_state); + extra_file_download(progress, remote, dst, &priv->preview); free(remote); free(dst); + + return priv->preview; } EAPI char * @@ -440,22 +447,30 @@ extra_theme_download_url_get(Extra_Theme *theme) return url; } -EAPI void +EAPI Extra_Request* extra_theme_download(Extra_Progress *progress, Extra_Theme *theme) { char *path, *urlstr = NULL; Extra_Theme_Private *priv = ((Extra_Theme_Private*) theme); - EINA_SAFETY_ON_NULL_RETURN(progress); - EINA_SAFETY_ON_NULL_RETURN(theme); + EINA_SAFETY_ON_NULL_RETURN_VAL(progress, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(theme, NULL); + + if (priv->main) + { + priv->main->progress = *progress; + return priv->main; + } urlstr = extra_theme_download_url_get(theme); path = extra_theme_install_path_get(theme); - extra_file_download(progress, urlstr, path, &priv->main_state); + extra_file_download(progress, urlstr, path, &priv->main); free(urlstr); free(path); + + return priv->main; } void @@ -656,31 +671,40 @@ extra_background_installed(Extra_Background *background) return exists; } -EAPI void +EAPI Extra_Request* extra_background_download(Extra_Progress *progress, Extra_Background *background) { char *path, *urlstr = NULL; Extra_Background_Private *priv = ((Extra_Background_Private*) background); - EINA_SAFETY_ON_NULL_RETURN(progress); - EINA_SAFETY_ON_NULL_RETURN(background); + EINA_SAFETY_ON_NULL_RETURN_VAL(progress, NULL); + EINA_SAFETY_ON_NULL_RETURN_VAL(background, NULL); + + if (priv->main) + { + memcpy(&priv->preview->progress, progress, sizeof(Extra_Progress)); + return priv->main; + } urlstr = extra_background_download_url_get(background); path = extra_background_install_path_get(background); - extra_file_download(progress, urlstr, path, &priv->main_state); + extra_file_download(progress, urlstr, path, &priv->main); free(urlstr); free(path); + + return priv->main; } + EAPI char* extra_background_preview_get(Extra_Background *background) { char *local; Extra_Background_Private *priv = (Extra_Background_Private*) background; - if (priv->preview_state & EXTRA_STATE_DOWNLOAD_IN_PROGRESS) return NULL; + if (priv->preview) return NULL; local = _extra_preview_local_generate("backgrounds", background->id, background->version); if (!ecore_file_exists(local)) @@ -692,19 +716,27 @@ extra_background_preview_get(Extra_Background *background) return local; } -EAPI void +EAPI Extra_Request* extra_background_preview_download(Extra_Progress *progress, Extra_Background *background) { char *remote, *local; Extra_Background_Private *priv = (Extra_Background_Private*) background; + if (priv->preview) + { + memcpy(&priv->preview->progress, progress, sizeof(Extra_Progress)); + return priv->preview; + } + remote = _extra_preview_remote_generate("backgrounds", background->id); local = _extra_preview_local_generate("backgrounds", background->id, background->version); - extra_file_download(progress, remote, local, &priv->preview_state); + extra_file_download(progress, remote, local, &priv->preview); free(local); free(remote); + + return priv->preview; } EAPI void @@ -718,3 +750,13 @@ extra_background_delete(Extra_Background *b) free(path); } + +EAPI void +extra_request_mute(Extra_Request *req) +{ + if(!req) return; + + req->progress.data = NULL; + req->progress.progress_cb = NULL; + req->progress.done_cb = NULL; +} diff --git a/src/lib/extra.h b/src/lib/extra.h index 7111d64..2bcbbcb 100644 --- a/src/lib/extra.h +++ b/src/lib/extra.h @@ -65,6 +65,8 @@ typedef struct _Extra_Progress void *data; } Extra_Progress; +typedef struct _Extra_Request Extra_Request; + /** * @brief Init / shutdown functions. * @defgroup Init Init / Shutdown @@ -151,7 +153,7 @@ EAPI Eina_Bool extra_theme_installed(Extra_Theme *theme); EAPI char *extra_theme_install_path_get(Extra_Theme *theme); EAPI char *extra_theme_preview_get(Extra_Theme *theme); -EAPI void extra_theme_preview_download(Extra_Progress *progress, Extra_Theme *theme); +EAPI Extra_Request* extra_theme_preview_download(Extra_Progress *progress, Extra_Theme *theme); EAPI char *extra_theme_download_url_get(Extra_Theme *theme); @@ -160,7 +162,7 @@ EAPI char *extra_theme_download_url_get(Extra_Theme *theme); * * @ingroup Themes */ -EAPI void extra_theme_download(Extra_Progress *progress, Extra_Theme *theme); +EAPI Extra_Request* extra_theme_download(Extra_Progress *progress, Extra_Theme *theme); /** * @brief Set the theme as default and restart e @@ -180,12 +182,13 @@ EAPI Eina_List* extra_backgrounds_list(void); EAPI Extra_Background* extra_background_get(const char *id); EAPI Eina_Bool extra_background_installed(Extra_Background *b); -EAPI void extra_background_download(Extra_Progress *progress, Extra_Background *b); +EAPI Extra_Request* extra_background_download(Extra_Progress *progress, Extra_Background *b); EAPI void extra_background_delete(Extra_Background *b); EAPI char* extra_background_preview_get(Extra_Background *background); -EAPI void extra_background_preview_download(Extra_Progress *progress, Extra_Background *background); +EAPI Extra_Request* extra_background_preview_download(Extra_Progress *progress, Extra_Background *background); +EAPI void extra_request_mute(Extra_Request *req); #ifdef __cplusplus } diff --git a/src/lib/extra_api_helper.c b/src/lib/extra_api_helper.c index 96ebd61..b99da27 100644 --- a/src/lib/extra_api_helper.c +++ b/src/lib/extra_api_helper.c @@ -192,8 +192,8 @@ extra_json_to_list(Extra_Json_To_List_Template *tmp, Eina_Strbuf *buf) } typedef struct { - char *state; - Extra_Progress *progress; + Extra_Request req; + Extra_Request **clean_up; } Extra_Download_Job; static void @@ -201,13 +201,15 @@ _download_complete_cb(void *data, const char *file EINA_UNUSED, int status EINA_ { Extra_Download_Job *job = data; - *(job->state) &= (~EXTRA_STATE_DOWNLOAD_IN_PROGRESS); - if (status != 200) ecore_file_remove(file); - if (job->progress->done_cb) - job->progress->done_cb(job->progress->data); + *job->clean_up = NULL; + + if (job->req.progress.done_cb) + job->req.progress.done_cb(job->req.progress.data); + + free(job); } static int @@ -221,18 +223,17 @@ _download_progress_cb(void *data EINA_UNUSED, const char *file EINA_UNUSED, if (dlnow > 0.f) percent = ((double)(double)dlnow / (double)dltotal); - if (job->progress->progress_cb) - job->progress->progress_cb(job->progress->data, percent); + if (job->req.progress.progress_cb) + job->req.progress.progress_cb(job->req.progress.data, percent); return ECORE_FILE_PROGRESS_CONTINUE; } void -extra_file_download(Extra_Progress *progress, const char *from, const char *to, char* state) +extra_file_download(Extra_Progress *progress, const char *from, const char *to, Extra_Request **req) { Extra_Download_Job *job; - if (*state & EXTRA_STATE_DOWNLOAD_IN_PROGRESS) return; if (ecore_file_exists(to)) { //TODO better check the header and handle that sanely @@ -240,9 +241,10 @@ extra_file_download(Extra_Progress *progress, const char *from, const char *to, } job = calloc(1, sizeof(Extra_Download_Job)); - job->progress = progress; - job->state = state; - *state |= EXTRA_STATE_DOWNLOAD_IN_PROGRESS; + job->req.progress = *progress; + job->clean_up = req; ecore_file_download(from, to, _download_complete_cb, _download_progress_cb, job, NULL); - } \ No newline at end of file + + *req = &job->req; + } diff --git a/src/lib/extra_private.h b/src/lib/extra_private.h index 83baf27..9412489 100644 --- a/src/lib/extra_private.h +++ b/src/lib/extra_private.h @@ -38,6 +38,11 @@ typedef struct { size_t tuples_size; } Extra_Json_To_List_Template; +struct _Extra_Request +{ + Extra_Progress progress; +}; + #define EXTRA_STATE_DOWNLOAD_IN_PROGRESS 2 @@ -54,6 +59,6 @@ Extra_Json_To_List_Template v = { \ Eina_List* extra_json_to_list(Extra_Json_To_List_Template *tmp, Eina_Strbuf *buf); void extra_json_list_part_free(Extra_Json_To_List_Template *tmp, void *data); -void extra_file_download(Extra_Progress *progress, const char *from, const char *to, char* state); +void extra_file_download(Extra_Progress *progress, const char *from, const char *to, Extra_Request **req); #endif