bu5hm4n pushed a commit to branch master. http://git.enlightenment.org/apps/extra.git/commit/?id=439e748db0aba0d34929e63f35b09c884f97f2c5
commit 439e748db0aba0d34929e63f35b09c884f97f2c5 Author: Marcel Hollerbach <[email protected]> Date: Mon Jan 9 22:02:07 2017 +0100 extra: make sure the downloads are only started once otherwise we could overwrite the image and invalidate it. --- src/bin/extra_main.c | 10 +++++--- src/lib/extra.c | 70 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/src/bin/extra_main.c b/src/bin/extra_main.c index bf105cd..8306cf1 100644 --- a/src/bin/extra_main.c +++ b/src/bin/extra_main.c @@ -145,10 +145,12 @@ _download_done(void) char *preview; preview = extra_theme_preview_get(_selected_theme); - elm_image_file_set(ui.theme_ui.screenshot, preview, NULL); - evas_object_show(ui.theme_ui.screenshot); - free(preview); - + if (preview) + { + elm_image_file_set(ui.theme_ui.screenshot, preview, NULL); + evas_object_show(ui.theme_ui.screenshot); + free(preview); + } evas_object_hide(ui.theme_ui.progress); } diff --git a/src/lib/extra.c b/src/lib/extra.c index 05c0eb3..d76fa2b 100644 --- a/src/lib/extra.c +++ b/src/lib/extra.c @@ -20,20 +20,35 @@ Eina_List *_theme_list; void _extra_theme_cache_load(); +#define PREVIEW_DOWNLOAD 1 +#define THEME_DOWNLOAD 2 + +typedef struct { + Extra_Theme theme; + char state; //indicates if some downloads are in progress +} Extra_Theme_Private; + +typedef struct { + Extra_Theme_Private *theme; + Extra_Progress *progress; + char nand_mask; //will be applied to the status char of the theme +} Extra_Download_Job; + + static void _extra_theme_add(Eina_Strbuf *id, Eina_Strbuf *name, Eina_Strbuf *author, Eina_Strbuf *description, int version) { - Extra_Theme *theme; + Extra_Theme_Private *theme; theme = malloc(sizeof(*theme)); - theme->id = sec_strdup(id); - theme->name = sec_strdup(name); - theme->author = sec_strdup(author); - theme->description = sec_strdup(description); - theme->version = version; - + theme->theme.id = sec_strdup(id); + theme->theme.name = sec_strdup(name); + theme->theme.author = sec_strdup(author); + theme->theme.description = sec_strdup(description); + theme->theme.version = version; + theme->state = 0; _theme_list = eina_list_append(_theme_list, theme); } @@ -329,10 +344,12 @@ extra_theme_install_path_get(Extra_Theme *theme) static void _download_complete_cb(void *data, const char *file EINA_UNUSED, int status EINA_UNUSED) { - Extra_Progress *progress = data; + Extra_Download_Job *job = data; - if (progress->done_cb) - progress->done_cb(); + job->theme->state &= (~job->nand_mask); + + if (job->progress->done_cb) + job->progress->done_cb(); } static int @@ -340,14 +357,14 @@ _download_progress_cb(void *data EINA_UNUSED, const char *file EINA_UNUSED, long int dltotal EINA_UNUSED, long int dlnow EINA_UNUSED, long int ultotal EINA_UNUSED, long int ulnow EINA_UNUSED) { - Extra_Progress *p = data; + Extra_Download_Job *job = data; double percent = 0.f; if (dlnow > 0.f) percent = ((double)(double)dlnow / (double)dltotal); - if (p->progress_cb) - p->progress_cb(percent); + if (job->progress->progress_cb) + job->progress->progress_cb(percent); return ECORE_FILE_PROGRESS_CONTINUE; } @@ -386,6 +403,10 @@ EAPI char* extra_theme_preview_get(Extra_Theme *theme) { char *local; + Extra_Theme_Private *priv = ((Extra_Theme_Private*) theme); + + //download is in progress do not return the path + if (priv->state & PREVIEW_DOWNLOAD) return NULL; local = _extra_theme_preview_local_generate(theme); if (!ecore_file_exists(local)) @@ -401,11 +422,21 @@ EAPI void extra_theme_preview_download(Extra_Progress *progress, Extra_Theme *theme) { char *remote, *dst; + Extra_Download_Job *job; + Extra_Theme_Private *priv = ((Extra_Theme_Private*) theme); + + if (priv->state & PREVIEW_DOWNLOAD) return; + + job = calloc(1, sizeof(Extra_Download_Job)); + job->progress = progress; + job->theme = priv; + job->nand_mask = PREVIEW_DOWNLOAD; + priv->state |= PREVIEW_DOWNLOAD; remote = _extra_theme_preview_remote_generate(theme); dst = _extra_theme_preview_local_generate(theme); - ecore_file_download(remote, dst, _download_complete_cb, _download_progress_cb, progress, NULL); + ecore_file_download(remote, dst, _download_complete_cb, _download_progress_cb, job, NULL); free(remote); free(dst); @@ -430,12 +461,21 @@ EAPI void extra_theme_download(Extra_Progress *progress, Extra_Theme *theme) { char *path, *urlstr = NULL; + Extra_Theme_Private *priv = ((Extra_Theme_Private*) theme); if (theme) { + if (priv->state & THEME_DOWNLOAD) return; + + Extra_Download_Job *job = calloc(1, sizeof(Extra_Download_Job)); + job->progress = progress; + job->theme = priv; + job->nand_mask = THEME_DOWNLOAD; + priv->state |= THEME_DOWNLOAD; + urlstr = extra_theme_download_url_get(theme); path = extra_theme_install_path_get(theme); - ecore_file_download(urlstr, path, _download_complete_cb, _download_progress_cb, progress, NULL); + ecore_file_download(urlstr, path, _download_complete_cb, _download_progress_cb, job, NULL); free(urlstr); free(path); } --
