From 4828fe95a4b5065c2d88da1ad1a223843dee23bf Mon Sep 17 00:00:00 2001 From: Stephen 'Okra' Houston Date: Mon, 26 Jun 2017 12:28:24 -0500 Subject: [PATCH] Ephoto: Give the user the option to choose between cropped thumbnails and aspect based thumbnails. --- src/bin/ephoto.h | 5 ++++- src/bin/ephoto_config.c | 18 +++++++++++++++--- src/bin/ephoto_main.c | 2 +- src/bin/ephoto_thumb.c | 7 +++++-- src/bin/ephoto_thumb_browser.c | 30 ++++++++++++++++++++++++++++-- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index a3edc90..857c03a 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -103,6 +103,7 @@ void ephoto_thumb_browser_update_info_label(Ephoto *ephoto); void ephoto_thumb_browser_slideshow(Evas_Object *obj); void ephoto_thumb_browser_paste(Ephoto *ephoto, Elm_Object_Item *item); void ephoto_thumb_browser_clear(Ephoto *ephoto); +void ephoto_thumb_browser_recalc(Ephoto *ephoto); void ephoto_thumb_browser_dirs_only_set(Ephoto *ephoto, Eina_Bool dirs_only); /* smart callbacks called: "selected" - an item in the thumb browser is * selected. The selected Ephoto_Entry is passed as event_info argument. */ @@ -116,7 +117,7 @@ void ephoto_directory_browser_clear(Ephoto *ephoto); /*thumbnailing functions taken from enlightenment*/ int e_thumb_init(void); int e_thumb_shutdown(void); -Evas_Object *e_thumb_icon_add(Evas *evas); +Evas_Object *e_thumb_icon_add(Evas *evas, Eina_Bool aspect); void e_thumb_icon_file_set(Evas_Object *obj, const char *file, const char *key); void e_thumb_icon_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h); void e_thumb_icon_begin(Evas_Object *obj); @@ -228,6 +229,7 @@ struct _Ephoto_Config Eina_Bool smooth; Eina_Bool firstrun; Eina_Bool folders; + Eina_Bool thumbnail_aspect; Evas_Object *slide_time; Evas_Object *slide_trans; Evas_Object *open_dir; @@ -237,6 +239,7 @@ struct _Ephoto_Config Evas_Object *smooth_scale; Evas_Object *slide_move; Evas_Object *show_folders; + Evas_Object *thumb_aspect; }; struct _Ephoto diff --git a/src/bin/ephoto_config.c b/src/bin/ephoto_config.c index 6b4b645..962f4dd 100644 --- a/src/bin/ephoto_config.c +++ b/src/bin/ephoto_config.c @@ -43,6 +43,7 @@ _config_save_cb(void *data, Evas_Object *obj EINA_UNUSED, ephoto->config->movess = elm_check_state_get(ephoto->config->slide_move); ephoto->config->smooth = elm_check_state_get(ephoto->config->smooth_scale); ephoto->config->folders = elm_check_state_get(ephoto->config->show_folders); + ephoto->config->thumbnail_aspect = elm_check_state_get(ephoto->config->thumb_aspect); if (elm_spinner_value_get(ephoto->config->slide_time) > 0) ephoto->config->slideshow_timeout = elm_spinner_value_get(ephoto->config->slide_time); @@ -52,6 +53,7 @@ _config_save_cb(void *data, Evas_Object *obj EINA_UNUSED, evas_object_del(popup); elm_object_focus_set(ephoto->pager, EINA_TRUE); + ephoto_thumb_browser_recalc(ephoto); } static void @@ -110,10 +112,18 @@ _config_general(Ephoto *ephoto, Evas_Object *parent) evas_object_show(check); ephoto->config->smooth_scale = check; + check = elm_check_add(table); + elm_object_text_set(check, _("Keep Aspect on Thumbnails")); + EPHOTO_FILL(check); + elm_check_state_set(check, ephoto->config->thumbnail_aspect); + elm_table_pack(table, check, 0, 4, 1, 1); + evas_object_show(check); + ephoto->config->thumb_aspect = check; + label = elm_label_add(table); elm_object_text_set(label, _("Top Level Directory")); EPHOTO_ALIGN(label, 0.5, 0.5); - elm_table_pack(table, label, 0, 4, 1, 1); + elm_table_pack(table, label, 0, 5, 1, 1); evas_object_show(label); hoversel = elm_hoversel_add(table); @@ -130,7 +140,7 @@ _config_general(Ephoto *ephoto, Evas_Object *parent) evas_object_data_set(hoversel, "ephoto", ephoto); EPHOTO_WEIGHT(hoversel, EVAS_HINT_EXPAND, EVAS_HINT_FILL); EPHOTO_FILL(hoversel); - elm_table_pack(table, hoversel, 0, 5, 1, 1); + elm_table_pack(table, hoversel, 0, 6, 1, 1); evas_object_show(hoversel); ephoto->config->open_dir = hoversel; @@ -143,7 +153,7 @@ _config_general(Ephoto *ephoto, Evas_Object *parent) ELM_SCROLLER_POLICY_OFF); EPHOTO_EXPAND(entry); EPHOTO_FILL(entry); - elm_table_pack(table, entry, 0, 6, 1, 1); + elm_table_pack(table, entry, 0, 7, 1, 1); evas_object_show(entry); ephoto->config->open_dir_custom = entry; } @@ -772,6 +782,7 @@ ephoto_config_init(Ephoto *ephoto) C_VAL(D, T, smooth, EET_T_INT); C_VAL(D, T, firstrun, EET_T_INT); C_VAL(D, T, folders, EET_T_INT); + C_VAL(D, T, thumbnail_aspect, EET_T_INT); switch (_ephoto_config_load(ephoto)) { case 0: @@ -791,6 +802,7 @@ ephoto_config_init(Ephoto *ephoto) ephoto->config->smooth = 1; ephoto->config->firstrun = 1; ephoto->config->folders = 1; + ephoto->config->thumbnail_aspect = 0; break; default: diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index 703e9eb..8c6c66e 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -1128,7 +1128,7 @@ ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, Ephoto_Entry *entry) } if (!o) { - o = e_thumb_icon_add(parent); + o = e_thumb_icon_add(parent, ephoto->config->thumbnail_aspect); evas_object_smart_callback_add(o, "e_thumb_gen", _thumb_gen_cb, entry); e_thumb_icon_file_set(o, entry->path, NULL); e_thumb_icon_size_set(o, ephoto->thumb_gen_size, diff --git a/src/bin/ephoto_thumb.c b/src/bin/ephoto_thumb.c index 0c4e7b8..ac901ee 100644 --- a/src/bin/ephoto_thumb.c +++ b/src/bin/ephoto_thumb.c @@ -77,13 +77,16 @@ _thumb_preloaded(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUS } Evas_Object * -e_thumb_icon_add(Evas *evas) +e_thumb_icon_add(Evas *evas, Eina_Bool aspect) { Evas_Object *obj; E_Thumb *eth; obj = elm_icon_add(evas); - elm_image_fill_outside_set(obj, EINA_TRUE); + if (aspect) + elm_image_fill_outside_set(obj, EINA_FALSE); + else + elm_image_fill_outside_set(obj, EINA_TRUE); evas_object_smart_callback_add(obj, "preloaded", _thumb_preloaded, obj); _objid++; eth = calloc(1, sizeof(E_Thumb)); diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c index 26f3131..bdfab34 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -1218,7 +1218,12 @@ _ephoto_thumb_search_go(void *data, Evas_Object *obj EINA_UNUSED, const Elm_Gengrid_Item_Class *ic = NULL; Ephoto_Entry *entry = NULL, *e = NULL; + if (tb->ephoto->config->thumbnail_aspect) + _ephoto_thumb_file_class.item_style = "default"; + else + _ephoto_thumb_file_class.item_style = "thumb"; ic = &_ephoto_thumb_file_class; + entry = elm_object_item_data_get(o); e = ephoto_entry_new(tb->ephoto, entry->path, entry->label, EINA_FILE_REG); @@ -1455,7 +1460,12 @@ _todo_items_process(void *data) entry->gengrid = tb->grid; - ic = &_ephoto_thumb_file_class; + if (tb->ephoto->config->thumbnail_aspect) + _ephoto_thumb_file_class.item_style = "default"; + else + _ephoto_thumb_file_class.item_style = "thumb"; + ic = &_ephoto_thumb_file_class; + if (tb->sort == EPHOTO_SORT_ALPHABETICAL_ASCENDING) entry->item = elm_gengrid_item_sorted_insert(tb->grid, ic, entry, @@ -1500,6 +1510,11 @@ _ephoto_thumb_populate_start(void *data, int type EINA_UNUSED, if (tb->dirs_only) return ECORE_CALLBACK_PASS_ON; + if (tb->ephoto->config->thumbnail_aspect) + _ephoto_thumb_file_class.item_style = "default"; + else + _ephoto_thumb_file_class.item_style = "thumb"; + tb->animator.processed = 0; tb->animator.count = 0; if (eina_list_count(tb->ephoto->selentries)) @@ -1889,6 +1904,14 @@ ephoto_thumb_browser_clear(Ephoto *ephoto) elm_gengrid_clear(tb->grid); } +void +ephoto_thumb_browser_recalc(Ephoto *ephoto) +{ + ephoto_thumb_browser_clear(ephoto); + ephoto_directory_set(ephoto, ephoto->config->directory, + NULL, 0, 1); +} + void ephoto_thumb_browser_paste(Ephoto *ephoto, Elm_Object_Item *item) { @@ -2113,7 +2136,10 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent) tb = calloc(1, sizeof(Ephoto_Thumb_Browser)); EINA_SAFETY_ON_NULL_GOTO(tb, error); - _ephoto_thumb_file_class.item_style = "thumb"; + if (ephoto->config->thumbnail_aspect) + _ephoto_thumb_file_class.item_style = "default"; + else + _ephoto_thumb_file_class.item_style = "thumb"; _ephoto_thumb_file_class.func.text_get = _thumb_item_text_get; _ephoto_thumb_file_class.func.content_get = _thumb_file_icon_get; _ephoto_thumb_file_class.func.state_get = NULL;