extra: implement image caching
this just downloads the images to a cache location
This commit is contained in:
parent
524fd6169b
commit
7175cb317b
|
@ -36,7 +36,7 @@ typedef struct {
|
|||
|
||||
static Elm_Genlist_Item_Class _theme_class;
|
||||
|
||||
static Extra_Progress _sync_progress, _install_progress;
|
||||
static Extra_Progress _sync_progress, _install_progress, _preview_progress;
|
||||
|
||||
static Extra_Theme *_selected_theme;
|
||||
|
||||
|
@ -133,10 +133,31 @@ _extra_win_ask_for_default(Extra_Theme *theme)
|
|||
evas_object_show(ui.ask_popup);
|
||||
}
|
||||
|
||||
static void
|
||||
_download_progress_cb(double progress)
|
||||
{
|
||||
elm_progressbar_value_set(ui.theme_ui.progress, progress);
|
||||
}
|
||||
|
||||
static void
|
||||
_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);
|
||||
|
||||
evas_object_hide(ui.theme_ui.progress);
|
||||
}
|
||||
|
||||
static void
|
||||
extra_win_show(Extra_Theme *theme)
|
||||
{
|
||||
char title[1024], author[1024];
|
||||
char *preview;
|
||||
|
||||
_selected_theme = theme;
|
||||
|
||||
if (!theme) return;
|
||||
|
@ -150,8 +171,21 @@ extra_win_show(Extra_Theme *theme)
|
|||
elm_object_text_set(ui.theme_ui.description, theme->description);
|
||||
|
||||
elm_progressbar_value_set(ui.theme_ui.progress, 0.0);
|
||||
elm_image_file_set(ui.theme_ui.screenshot, extra_theme_preview_url_get(_selected_theme), NULL);
|
||||
evas_object_show(ui.theme_ui.progress);
|
||||
|
||||
preview = extra_theme_preview_get(_selected_theme);
|
||||
if (preview)
|
||||
{
|
||||
elm_image_file_set(ui.theme_ui.screenshot, preview, NULL);
|
||||
free(preview);
|
||||
}
|
||||
else
|
||||
{
|
||||
_preview_progress.progress_cb = _download_progress_cb;
|
||||
_preview_progress.done_cb = _download_done;
|
||||
extra_theme_preview_download(&_preview_progress, _selected_theme);
|
||||
evas_object_hide(ui.theme_ui.screenshot);
|
||||
evas_object_show(ui.theme_ui.progress);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -278,20 +312,6 @@ _extra_win_install_click_cb(void *data EINA_UNUSED,
|
|||
|
||||
}
|
||||
|
||||
static void
|
||||
_download_progress_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
Elm_Photocam_Progress *prog = event_info;
|
||||
|
||||
if (prog->total > 0)
|
||||
elm_progressbar_value_set(ui.theme_ui.progress, prog->now / prog->total);
|
||||
}
|
||||
|
||||
static void
|
||||
_download_done(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
|
||||
{
|
||||
evas_object_hide(ui.theme_ui.progress);
|
||||
}
|
||||
|
||||
static Evas_Object *
|
||||
extra_win_setup(void)
|
||||
|
@ -366,8 +386,6 @@ extra_win_setup(void)
|
|||
ui.theme_ui.install = install;
|
||||
|
||||
ui.theme_ui.screenshot = elm_image_add(table);
|
||||
evas_object_smart_callback_add(ui.theme_ui.screenshot, "download,progress", _download_progress_cb, NULL);
|
||||
evas_object_smart_callback_add(ui.theme_ui.screenshot, "download,done", _download_done, NULL);
|
||||
evas_object_size_hint_weight_set(ui.theme_ui.screenshot, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(ui.theme_ui.screenshot, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_table_pack(table, ui.theme_ui.screenshot, 0, 1, 4, 2);
|
||||
|
|
102
src/lib/extra.c
102
src/lib/extra.c
|
@ -326,34 +326,6 @@ extra_theme_install_path_get(Extra_Theme *theme)
|
|||
return path;
|
||||
}
|
||||
|
||||
EAPI char *
|
||||
extra_theme_preview_url_get(Extra_Theme *theme)
|
||||
{
|
||||
const char *pattern = "http://" HOSTNAME "/themes/preview/%s.png";
|
||||
char *url;
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(theme, NULL);
|
||||
|
||||
url = malloc((strlen(pattern) + strlen(theme->id) - 1) * sizeof(char));
|
||||
sprintf(url, pattern, theme->id);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
EAPI char *
|
||||
extra_theme_download_url_get(Extra_Theme *theme)
|
||||
{
|
||||
const char *pattern = "http://" HOSTNAME "/themes/%s-%d.edj";
|
||||
char *url;
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(theme, NULL);
|
||||
|
||||
url = malloc((strlen(pattern) + strlen(theme->id) - 1 + (int)(log10(theme->version))) * sizeof(char));
|
||||
sprintf(url, pattern, theme->id, theme->version);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
static void
|
||||
_download_complete_cb(void *data, const char *file EINA_UNUSED, int status EINA_UNUSED)
|
||||
{
|
||||
|
@ -380,6 +352,80 @@ _download_progress_cb(void *data EINA_UNUSED, const char *file EINA_UNUSED,
|
|||
return ECORE_FILE_PROGRESS_CONTINUE;
|
||||
}
|
||||
|
||||
static char *
|
||||
_extra_theme_preview_remote_generate(Extra_Theme *theme)
|
||||
{
|
||||
const char *pattern = "http://" HOSTNAME "/themes/preview/%s.png";
|
||||
char *url;
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(theme, NULL);
|
||||
|
||||
url = malloc((strlen(pattern) + strlen(theme->id) - 1) * sizeof(char));
|
||||
sprintf(url, pattern, theme->id);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
static char *
|
||||
_extra_theme_preview_local_generate(Extra_Theme *theme)
|
||||
{
|
||||
Eina_Strbuf *local_preview;
|
||||
char *tmp;
|
||||
|
||||
local_preview = eina_strbuf_new();
|
||||
|
||||
eina_strbuf_append(local_preview, efreet_cache_home_get());
|
||||
eina_strbuf_append_printf(local_preview, "/%s/%s-%d.png", PACKAGE_NAME, theme->id, theme->version);
|
||||
tmp = eina_strbuf_string_steal(local_preview);
|
||||
eina_strbuf_free(local_preview);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
EAPI char*
|
||||
extra_theme_preview_get(Extra_Theme *theme)
|
||||
{
|
||||
char *local;
|
||||
|
||||
local = _extra_theme_preview_local_generate(theme);
|
||||
if (!ecore_file_exists(local))
|
||||
{
|
||||
free(local);
|
||||
local = NULL;
|
||||
}
|
||||
|
||||
return local;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
extra_theme_preview_download(Extra_Progress *progress, Extra_Theme *theme)
|
||||
{
|
||||
char *remote, *dst;
|
||||
|
||||
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);
|
||||
|
||||
free(remote);
|
||||
free(dst);
|
||||
}
|
||||
|
||||
EAPI char *
|
||||
extra_theme_download_url_get(Extra_Theme *theme)
|
||||
{
|
||||
const char *pattern = "http://" HOSTNAME "/themes/%s-%d.edj";
|
||||
char *url;
|
||||
|
||||
EINA_SAFETY_ON_NULL_RETURN_VAL(theme, NULL);
|
||||
|
||||
url = malloc((strlen(pattern) + strlen(theme->id) - 1 + (int)(log10(theme->version))) * sizeof(char));
|
||||
sprintf(url, pattern, theme->id, theme->version);
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
EAPI void
|
||||
extra_theme_download(Extra_Progress *progress, Extra_Theme *theme)
|
||||
{
|
||||
|
|
|
@ -138,7 +138,8 @@ EAPI Eina_Bool extra_theme_installed(Extra_Theme *theme);
|
|||
|
||||
EAPI char *extra_theme_install_path_get(Extra_Theme *theme);
|
||||
|
||||
EAPI char *extra_theme_preview_url_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 char *extra_theme_download_url_get(Extra_Theme *theme);
|
||||
|
||||
|
|
Loading…
Reference in New Issue