diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index 9bc1fe2..bcbc91c 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -55,7 +55,7 @@ Evas_Object *ephoto_window_add(const char *path); void ephoto_title_set(Ephoto *ephoto, const char *title); void ephoto_thumb_size_set(Ephoto *ephoto, int size); Evas_Object *ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, - const char *path); + Ephoto_Entry *entry); void ephoto_thumb_path_set(Evas_Object *obj, const char *path); void ephoto_directory_set(Ephoto *ephoto, const char *path, Elm_Object_Item *expanded, Eina_Bool dirs_only, Eina_Bool thumbs_only); @@ -107,6 +107,7 @@ 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_dirs_only_set(Ephoto *ephoto, Eina_Bool dirs_only); +void ephoto_thumb_browser_resort(Ephoto *ephoto, Ephoto_Entry *entry); /* smart callbacks called: "selected" - an item in the thumb browser is * selected. The selected Ephoto_Entry is passed as event_info argument. */ @@ -202,7 +203,8 @@ enum _Ephoto_Sort EPHOTO_SORT_ALPHABETICAL_ASCENDING, EPHOTO_SORT_ALPHABETICAL_DESCENDING, EPHOTO_SORT_MODTIME_ASCENDING, - EPHOTO_SORT_MODTIME_DESCENDING + EPHOTO_SORT_MODTIME_DESCENDING, + EPHOTO_SORT_SIMILARITY }; enum _Ephoto_Ipc_Domain @@ -308,6 +310,7 @@ struct _Ephoto_Entry const char *path; const char *basename; const char *label; + char *sort_id; double size; Ephoto *ephoto; Eio_Monitor *monitor; @@ -319,6 +322,7 @@ struct _Ephoto_Entry Eina_Bool is_link; Eina_Bool no_delete; Evas_Object *genlist; + Evas_Object *thumb; }; struct _Ephoto_Event_Entry_Create diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index 50c212e..91d2acb 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -991,6 +991,18 @@ ephoto_thumb_size_set(Ephoto *ephoto, int size) ecore_timer_add(0.1, _thumb_gen_size_changed_timer_cb, ephoto); } +static void +_thumb_gen(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) +{ + Ephoto_Entry *entry = data; + const char *id = e_thumb_sort_id_get(entry->thumb); + + if (id) + entry->sort_id = strdup(id); + e_thumb_icon_end(entry->thumb); + ephoto_thumb_browser_insert(entry->ephoto, entry); +} + static void _thumb_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED) @@ -1002,9 +1014,10 @@ _thumb_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, } Evas_Object * -ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, const char *path) +ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, Ephoto_Entry *entry) { Evas_Object *o; + const char *path = entry->path; if (path) { @@ -1022,7 +1035,10 @@ ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, const char *path) o = e_thumb_icon_add(parent); e_thumb_icon_file_set(o, path, NULL); e_thumb_icon_size_set(o, ephoto->thumb_gen_size, - ephoto->thumb_gen_size); + ephoto->thumb_gen_size); + evas_object_smart_callback_add(o, "e_thumb_gen", + _thumb_gen, entry); + entry->thumb = o; e_thumb_icon_begin(o); } } @@ -1032,11 +1048,17 @@ ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent, const char *path) e_thumb_icon_file_set(o, path, NULL); e_thumb_icon_size_set(o, ephoto->thumb_gen_size, ephoto->thumb_gen_size); + evas_object_smart_callback_add(o, "e_thumb_gen", + _thumb_gen, entry); + entry->thumb = o; e_thumb_icon_begin(o); } } else - o = e_thumb_icon_add(parent); + { + o = e_thumb_icon_add(parent); + entry->thumb = o; + } if (!o) return NULL; @@ -1137,6 +1159,7 @@ ephoto_entry_free(Ephoto *ephoto, Ephoto_Entry *entry) node); } } + free(entry->sort_id); eina_stringshare_del(entry->path); eina_stringshare_del(entry->label); if (entry->monitor) diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c index 4894870..7ae6d85 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -273,20 +273,15 @@ _thumb_item_text_get(void *data, Evas_Object *obj EINA_UNUSED, } static Evas_Object * -_thumb_file_icon_get(void *data, Evas_Object *obj, +_thumb_file_icon_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part) { Ephoto_Entry *e = data; - Evas_Object *thumb = NULL; + Evas_Object *thumb = e->thumb; if (strcmp(part, "elm.swallow.icon")) return NULL; - if (e) - { - thumb = ephoto_thumb_add(e->ephoto, obj, e->path); - evas_object_show(thumb); - } return thumb; } @@ -373,6 +368,24 @@ _entry_cmp_grid_mod_desc(const void *pa, const void *pb) } } +static int +_entry_cmp_grid_similarity(const void *pa, const void *pb) +{ + const Ephoto_Entry *a, *b; + char *ida, *idb; + + a = elm_object_item_data_get(pa); + b = elm_object_item_data_get(pb); + + ida = a->sort_id; + idb = b->sort_id; + + if (!ida || !idb) + return 0; + + return strcmp(ida, idb); +} + static void _sort_alpha_asc(void *data, Evas_Object *obj, void *event_data EINA_UNUSED) @@ -445,6 +458,24 @@ _sort_mod_desc(void *data, Evas_Object *obj EINA_UNUSED, NULL, tb->dirs_only, tb->thumbs_only); } +static void +_sort_similarity(void *data, Evas_Object *obj EINA_UNUSED, + void *eent_data EINA_UNUSED) +{ + Ephoto_Thumb_Browser *tb = data; + Evas_Object *ic; + + tb->sort = EPHOTO_SORT_SIMILARITY; + tb->thumbs_only = 1; + tb->dirs_only = 0; + ic = elm_icon_add(obj); + elm_icon_standard_set(ic, "view-sort-ascending"); + elm_object_part_content_set(obj, "icon", ic); + evas_object_show(ic); + ephoto_directory_set(tb->ephoto, tb->ephoto->config->directory, + NULL, tb->dirs_only, tb->thumbs_only); +} + static void _zoom_in(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) @@ -1027,9 +1058,7 @@ _ephoto_thumb_search_go(void *data, Evas_Object *obj EINA_UNUSED, elm_box_unpack(tb->gridbox, tb->original_grid); evas_object_hide(tb->original_grid); - elm_theme_extension_add(NULL, PACKAGE_DATA_DIR "/themes/ephoto.edj"); tb->grid = elm_gengrid_add(tb->gridbox); - elm_object_style_set(tb->grid, "noclip"); evas_object_size_hint_weight_set(tb->grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(tb->grid, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -1059,46 +1088,18 @@ _ephoto_thumb_search_go(void *data, Evas_Object *obj EINA_UNUSED, tb->totsize = 0; EINA_LIST_FOREACH(results, l, o) { - const Elm_Gengrid_Item_Class *ic = NULL; Ephoto_Entry *entry = NULL, *e = NULL; + Evas_Object *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); - if (tb->sort == EPHOTO_SORT_ALPHABETICAL_ASCENDING) - e->item = - elm_gengrid_item_sorted_insert(tb->grid, ic, e, - _entry_cmp_grid_alpha_asc, NULL, NULL); - else if (tb->sort == EPHOTO_SORT_ALPHABETICAL_DESCENDING) - e->item = - elm_gengrid_item_sorted_insert(tb->grid, ic, e, - _entry_cmp_grid_alpha_desc, NULL, NULL); - else if (tb->sort == EPHOTO_SORT_MODTIME_ASCENDING) - e->item = - elm_gengrid_item_sorted_insert(tb->grid, ic, e, - _entry_cmp_grid_mod_asc, NULL, NULL); - else if (tb->sort == EPHOTO_SORT_MODTIME_DESCENDING) - e->item = - elm_gengrid_item_sorted_insert(tb->grid, ic, e, - _entry_cmp_grid_mod_desc, NULL, NULL); - if (e->item) - { - Eina_File *f; - elm_object_item_data_set(e->item, e); - tb->totimages++; - f = eina_file_open(e->path, EINA_FALSE); - tb->totsize += (double) eina_file_size_get(f); - eina_file_close(f); - tb->searchentries = eina_list_append(tb->searchentries, e); - } - else - { - ephoto_entry_free(tb->ephoto, e); - } + + thumb = ephoto_thumb_add(tb->ephoto, tb->grid, e); + evas_object_show(thumb); + tb->searchentries = eina_list_append(tb->searchentries, e); } tb->entries = tb->searchentries; - ephoto_thumb_browser_update_info_label(tb->ephoto); eina_list_free(results); } else @@ -1234,9 +1235,7 @@ _ephoto_thumb_view_add(Ephoto_Thumb_Browser *tb) EVAS_HINT_FILL); evas_object_show(tb->gridbox); - elm_theme_extension_add(NULL, PACKAGE_DATA_DIR "/themes/ephoto.edj"); tb->grid = elm_gengrid_add(tb->gridbox); - elm_object_style_set(tb->grid, "noclip"); evas_object_size_hint_weight_set(tb->grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(tb->grid, EVAS_HINT_FILL, EVAS_HINT_FILL); @@ -1297,33 +1296,10 @@ _todo_items_process(void *data) return EINA_TRUE; else if (!entry->is_dir && !entry->item) { - const Elm_Gengrid_Item_Class *ic; + Evas_Object *thumb; - ic = &_ephoto_thumb_file_class; - if (tb->sort == EPHOTO_SORT_ALPHABETICAL_ASCENDING) - entry->item = - elm_gengrid_item_sorted_insert(tb->grid, ic, entry, - _entry_cmp_grid_alpha_asc, NULL, NULL); - else if (tb->sort == EPHOTO_SORT_ALPHABETICAL_DESCENDING) - entry->item = - elm_gengrid_item_sorted_insert(tb->grid, ic, entry, - _entry_cmp_grid_alpha_desc, NULL, NULL); - else if (tb->sort == EPHOTO_SORT_MODTIME_ASCENDING) - entry->item = - elm_gengrid_item_sorted_insert(tb->grid, ic, entry, - _entry_cmp_grid_mod_asc, NULL, NULL); - else if (tb->sort == EPHOTO_SORT_MODTIME_DESCENDING) - entry->item = - elm_gengrid_item_sorted_insert(tb->grid, ic, entry, - _entry_cmp_grid_mod_desc, NULL, NULL); - if (entry->item) - { - elm_object_item_data_set(entry->item, entry); - } - else - { - ephoto_entry_free(tb->ephoto, entry); - } + thumb = ephoto_thumb_add(entry->ephoto, tb->grid, entry); + evas_object_show(thumb); } tb->animator.processed++; } @@ -1728,8 +1704,8 @@ _ephoto_main_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, free(tb); } - /*Ephoto Thumb Browser Public Functions*/ + void ephoto_thumb_browser_dirs_only_set(Ephoto *ephoto, Eina_Bool dirs_only) { @@ -1812,6 +1788,10 @@ ephoto_thumb_browser_insert(Ephoto *ephoto, Ephoto_Entry *entry) entry->item = elm_gengrid_item_sorted_insert(tb->grid, ic, entry, _entry_cmp_grid_mod_desc, NULL, NULL); + else if (tb->sort == EPHOTO_SORT_SIMILARITY) + entry->item = + elm_gengrid_item_sorted_insert(tb->grid, ic, entry, + _entry_cmp_grid_similarity, NULL, NULL); if (entry->item) { elm_object_item_data_set(entry->item, entry); @@ -1937,6 +1917,8 @@ ephoto_thumb_browser_show_controls(Ephoto *ephoto) "view-sort-ascending", ELM_ICON_STANDARD, _sort_mod_asc, tb); elm_hoversel_item_add(hover, _("Modification Time Descending"), "view-sort-descending", ELM_ICON_STANDARD, _sort_mod_desc, tb); + elm_hoversel_item_add(hover, _("Image Similarity"), + "view-sort-ascending", ELM_ICON_STANDARD, _sort_similarity, tb); elm_object_text_set(hover, _("Sort")); ic = elm_icon_add(hover); evas_object_size_hint_min_set(ic, 20*elm_config_scale_get(),