From 6b5bb2352491f6101498444a7414350ae95e49fe Mon Sep 17 00:00:00 2001 From: Marcel Hollerbach Date: Fri, 20 Jan 2017 00:52:55 +0100 Subject: [PATCH] extra: refactor those calls into the util they are also helpfull for other selectors --- src/bin/extra_private.h | 12 +++ src/bin/extra_theme_selector.c | 137 ++++----------------------------- src/bin/extra_util.c | 114 +++++++++++++++++++++++++++ 3 files changed, 141 insertions(+), 122 deletions(-) diff --git a/src/bin/extra_private.h b/src/bin/extra_private.h index 1a6a7bf..4b3c980 100644 --- a/src/bin/extra_private.h +++ b/src/bin/extra_private.h @@ -11,9 +11,21 @@ typedef struct { extern Ui _ui; Evas_Object* extra_theme_selector_create(void); +Evas_Object* extra_background_selector_create(void); + 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 struct { + Extra_ui_preview_get *preview_get; + Extra_ui_preview_download *preview_download; +} Extra_Ui_Small_Preview_Accessor; + +Evas_Object* extra_ui_small_preview_new(Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par, void *data); +void extra_ui_fullscreen_preview(char *path); #endif diff --git a/src/bin/extra_theme_selector.c b/src/bin/extra_theme_selector.c index 88e27c3..a173d07 100644 --- a/src/bin/extra_theme_selector.c +++ b/src/bin/extra_theme_selector.c @@ -3,66 +3,30 @@ #include "extra_private.h" #include "../lib/extra.h" -typedef struct { - Evas_Object *image; - Evas_Object *progress; - Extra_Progress p; - Extra_Theme *theme; -} Small_Preview; - static Evas_Object *_selector; static void _fill_gengrid(void); -static Evas_Object* extra_theme_small_preview_new(Evas_Object *par, Extra_Theme *theme); + static Evas_Object* extra_theme_small_new(Evas_Object *par, Extra_Theme *theme); static Elm_Gengrid_Item_Class *_item_class_basic; -static void -_delete_inwin(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) -{ - Evas_Event_Mouse_Up *ev = event_info; +static Extra_Ui_Small_Preview_Accessor acc = { + ((Extra_ui_preview_get*) extra_theme_preview_get), + ((Extra_ui_preview_download*) extra_theme_preview_download), +}; - if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; - - evas_object_del(data); - - ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; -} - -static void -_extra_win_fullscreen_preview(Extra_Theme *theme) -{ - Evas_Object *win, *image; - char *path; - - path = extra_theme_preview_get(theme); - - if (!path) return; - - win = elm_win_util_standard_add("Extra - Screenshot", "Extra - Screenshot"); - elm_win_fullscreen_set(win, EINA_TRUE); - evas_object_size_hint_weight_set(win, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(win, EVAS_HINT_FILL, EVAS_HINT_FILL); - - image = elm_image_add(win); - evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_UP, _delete_inwin, win); - evas_object_size_hint_weight_set(image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(image, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_image_file_set(image, path, NULL); - evas_object_show(image); - - elm_object_content_set(win, image); - - evas_object_show(win); - -} static void _fullscreen_picture(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - _extra_win_fullscreen_preview(data); + char *path; + + path = extra_theme_preview_get(data); + if (!path) return; + + extra_ui_fullscreen_preview(path); } static void @@ -177,7 +141,7 @@ _popup_theme(Evas_Object *win, Extra_Theme *theme) elm_object_text_set(install, "Set as default"); } - o = extra_theme_small_preview_new(inwin, theme); + o = extra_ui_small_preview_new(acc, inwin, theme); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_UP, _fullscreen_picture, theme); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -269,31 +233,6 @@ extra_theme_selector_create(void) //==== Small preview - -static void -_small_preview_progress_cb(void *data, double progress) -{ - Small_Preview *p = data; - - elm_progressbar_value_set(p->progress, progress); -} - -static void -_small_preview_done_cb(void *data) -{ - Small_Preview *p = data; - char *preview; - - preview = extra_theme_preview_get(p->theme); - if (preview) - { - elm_image_file_set(p->image , preview, NULL); - evas_object_show(p->image); - free(preview); - } - evas_object_hide(p->progress); -} - static Evas_Object* _icon_add(Evas_Object *obj, const char *name, const char *desc) { @@ -309,13 +248,14 @@ _icon_add(Evas_Object *obj, const char *name, const char *desc) return ret; } + static Evas_Object* extra_theme_small_new(Evas_Object *par, Extra_Theme *theme) { Evas_Object *table, *o; int counter = 0; - table = extra_theme_small_preview_new(par, theme); + table = extra_ui_small_preview_new(acc, par, theme); //for available states: downloaded, set as default, new-version available if (extra_theme_installed(theme)) @@ -341,51 +281,4 @@ extra_theme_small_new(Evas_Object *par, Extra_Theme *theme) counter ++; } return table; -} -static Evas_Object* -extra_theme_small_preview_new(Evas_Object *par, Extra_Theme *theme) -{ - Evas_Object *table; - Small_Preview *small; - char *preview; - - small = calloc(1, sizeof(Small_Preview)); - - small->theme = theme; - - table = elm_table_add(par); - 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); - - - small->image = elm_image_add(table); - evas_object_size_hint_weight_set(small->image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(small->image, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_table_pack(table, small->image, 0, 0, 4, 3); - evas_object_show(small->image); - - small->progress = elm_progressbar_add(table); - evas_object_size_hint_weight_set(small->progress, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(small->progress, EVAS_HINT_FILL, 0.0); - elm_table_pack(table, small->progress, 0, 2, 4, 1); - - elm_progressbar_value_set(small->progress, 0.0); - - preview = extra_theme_preview_get(theme); - if (preview) - { - elm_image_file_set(small->image, preview, NULL); - free(preview); - } - else - { - small->p.data = small; - small->p.done_cb = _small_preview_done_cb; - small->p.progress_cb = _small_preview_progress_cb; - extra_theme_preview_download(&small->p, theme); - evas_object_hide(small->image); - evas_object_show(small->progress); - } - return table; -} +} \ No newline at end of file diff --git a/src/bin/extra_util.c b/src/bin/extra_util.c index 132cfac..f146c83 100644 --- a/src/bin/extra_util.c +++ b/src/bin/extra_util.c @@ -128,4 +128,118 @@ extra_ui_progress_popup_show(const char *title, Extra_Done_Cb done, void *data) evas_object_show(ui->popup); return &ui->progress; +} + +typedef struct { + Evas_Object *image; + Evas_Object *progress; + Extra_Progress p; + void *data; + Extra_Ui_Small_Preview_Accessor acc; +} Small_Preview; + +static void +_small_preview_progress_cb(void *data, double progress) +{ + Small_Preview *p = data; + + elm_progressbar_value_set(p->progress, progress); +} + +static void +_small_preview_done_cb(void *data) +{ + Small_Preview *p = data; + char *preview; + + preview = p->acc.preview_get(p->data); + if (preview) + { + elm_image_file_set(p->image , preview, NULL); + evas_object_show(p->image); + free(preview); + } + evas_object_hide(p->progress); +} + +Evas_Object* +extra_ui_small_preview_new(Extra_Ui_Small_Preview_Accessor acc, Evas_Object *par, void *data) +{ + Evas_Object *table; + Small_Preview *small; + char *preview; + + small = calloc(1, sizeof(Small_Preview)); + + small->acc = acc; + small->data = data; + table = elm_table_add(par); + 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); + + + small->image = elm_image_add(table); + evas_object_size_hint_weight_set(small->image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(small->image, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_table_pack(table, small->image, 0, 0, 4, 3); + evas_object_show(small->image); + + small->progress = elm_progressbar_add(table); + evas_object_size_hint_weight_set(small->progress, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(small->progress, EVAS_HINT_FILL, 0.0); + elm_table_pack(table, small->progress, 0, 2, 4, 1); + + elm_progressbar_value_set(small->progress, 0.0); + + preview = acc.preview_get(data); + if (preview) + { + elm_image_file_set(small->image, preview, NULL); + free(preview); + } + else + { + 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); + evas_object_hide(small->image); + evas_object_show(small->progress); + } + return table; +} + +static void +_delete_inwin(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) +{ + Evas_Event_Mouse_Up *ev = event_info; + + if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return; + + evas_object_del(data); + + ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; +} + +void +extra_ui_fullscreen_preview(char *path) +{ + Evas_Object *win, *image; + + win = elm_win_util_standard_add("Extra - Screenshot", "Extra - Screenshot"); + elm_win_fullscreen_set(win, EINA_TRUE); + evas_object_size_hint_weight_set(win, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(win, EVAS_HINT_FILL, EVAS_HINT_FILL); + + image = elm_image_add(win); + evas_object_event_callback_add(image, EVAS_CALLBACK_MOUSE_UP, _delete_inwin, win); + evas_object_size_hint_weight_set(image, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(image, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_image_file_set(image, path, NULL); + evas_object_show(image); + + elm_object_content_set(win, image); + + evas_object_show(win); } \ No newline at end of file