okra pushed a commit to branch master.

http://git.enlightenment.org/apps/ephoto.git/commit/?id=c927875f63779fbd3fc4855acc7ed3271b54ca06

commit c927875f63779fbd3fc4855acc7ed3271b54ca06
Author: Stephen Houston <stephen@lenovo.fedora>
Date:   Mon Aug 15 22:30:58 2016 -0500

    Ephoto: Remember similarity sorting on dir change.
---
 src/bin/ephoto_main.c          |  79 +++++++++++++++++-----
 src/bin/ephoto_thumb_browser.c | 149 +++++------------------------------------
 2 files changed, 80 insertions(+), 148 deletions(-)

diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c
index 3e36348..9180fc0 100644
--- a/src/bin/ephoto_main.c
+++ b/src/bin/ephoto_main.c
@@ -723,6 +723,11 @@ ephoto_entries_cmp(const void *pa, const void *pb)
              return -1;
            else
              return i * -1;
+        case EPHOTO_SORT_SIMILARITY:
+           if (!a->sort_id || !b->sort_id)
+             return 0;
+           else
+             return strcmp(a->sort_id, b->sort_id);
         default:
            return i;
      }
@@ -746,23 +751,26 @@ _ephoto_populate_main(void *data, Eio_File *handler 
EINA_UNUSED,
      e->parent = ed->expanded;
    else
      {
-       if (!ed->ephoto->entries)
-          ed->ephoto->entries = eina_list_append(ed->ephoto->entries, e);
-       else
-         {
-            int near_cmp;
-            Eina_List *near_node =
-                eina_list_search_sorted_near_list(ed->ephoto->entries,
-                ephoto_entries_cmp, e, &near_cmp);
-
-            if (near_cmp < 0)
-               ed->ephoto->entries =
-                   eina_list_append_relative_list(ed->ephoto->entries, e,
-                   near_node);
+        if (ed->ephoto->sort != EPHOTO_SORT_SIMILARITY)
+          {
+            if (!ed->ephoto->entries)
+              ed->ephoto->entries = eina_list_append(ed->ephoto->entries, e);
             else
-               ed->ephoto->entries =
-                   eina_list_prepend_relative_list(ed->ephoto->entries, e,
-                   near_node);
+              {
+                 int near_cmp;
+                 Eina_List *near_node =
+                     eina_list_search_sorted_near_list(ed->ephoto->entries,
+                          ephoto_entries_cmp, e, &near_cmp);
+
+                 if (near_cmp < 0)
+                   ed->ephoto->entries =
+                       eina_list_append_relative_list(ed->ephoto->entries, e,
+                           near_node);
+                 else
+                   ed->ephoto->entries =
+                       eina_list_prepend_relative_list(ed->ephoto->entries, e,
+                           near_node);
+               }
          }
        e->parent = NULL;
      }
@@ -940,6 +948,7 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, 
Evas_Object *expanded,
 {
    Ephoto_Dir_Data *ed;
    Ecore_Event_Handler *handler;
+   Evas_Object *o;
 
    ed = malloc(sizeof(Ephoto_Dir_Data));
    ed->ephoto = ephoto;
@@ -950,6 +959,9 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, 
Evas_Object *expanded,
    if (!ecore_file_can_read(path))
      return;
 
+   EINA_LIST_FREE(ed->ephoto->thumbs, o)
+     evas_object_del(o);
+
    ephoto_title_set(ephoto, NULL);
    eina_stringshare_replace(&ephoto->config->directory,
        ecore_file_realpath(path));
@@ -1028,11 +1040,21 @@ _thumb_gen_cb(void *data, Evas_Object *obj EINA_UNUSED,
 {
    Ephoto_Entry *entry = data;
    const char *id;
+   char *dir;
 
    if (!entry)
      return;
-
+   if (!entry->thumb)
+     return;
+   dir = ecore_file_dir_get(entry->path);
+   if (strcmp(dir, entry->ephoto->config->directory))
+     {
+        evas_object_del(entry->thumb);
+        return;
+     }
+   free(dir);
    id = e_thumb_sort_id_get(entry->thumb);
+   evas_object_smart_callback_del(entry->thumb, "e_thumb_gen", _thumb_gen_cb);
    e_thumb_icon_end(entry->thumb);
    if (!id || entry->sort_id)
      return;
@@ -1041,6 +1063,29 @@ _thumb_gen_cb(void *data, Evas_Object *obj EINA_UNUSED,
      eina_stringshare_replace(&entry->sort_id, id);
    else
      entry->sort_id = eina_stringshare_add(id);
+
+   if (entry->ephoto->sort == EPHOTO_SORT_SIMILARITY)
+     {
+        ephoto_thumb_browser_insert(entry->ephoto, entry);
+        if (!entry->ephoto->entries)
+          entry->ephoto->entries = eina_list_append(entry->ephoto->entries, 
entry);
+        else
+          {
+             int near_cmp;
+             Eina_List *near_node =
+                 eina_list_search_sorted_near_list(entry->ephoto->entries,
+                 ephoto_entries_cmp, entry, &near_cmp);
+
+             if (near_cmp < 0)
+                entry->ephoto->entries =
+                    eina_list_append_relative_list(entry->ephoto->entries, 
entry,
+                    near_node);
+             else
+                entry->ephoto->entries =
+                    eina_list_prepend_relative_list(entry->ephoto->entries, 
entry,
+                    near_node);
+          }
+     }
 }
 
 static void
diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c
index 780b020..63c5084 100644
--- a/src/bin/ephoto_thumb_browser.c
+++ b/src/bin/ephoto_thumb_browser.c
@@ -466,134 +466,23 @@ _sort_mod_desc(void *data, Evas_Object *obj EINA_UNUSED,
        NULL, tb->dirs_only, tb->thumbs_only);
 }
 
-static Eina_Bool
-_similarity_items_process(void *data)
-{
-   Ephoto_Thumb_Browser *tb = data;
-   Ephoto_Entry *entry;
-   int i = 0;
-
-   if ((tb->animator.processed == tb->animator.count))
-     {
-        Evas_Object *popup = evas_object_data_get(tb->grid, "popup");
-        Eina_List *similar = NULL;
-        Elm_Object_Item *it;
-
-        if (tb->animator.count == 0)
-          return EINA_TRUE;
-        tb->animator.todo_items = NULL;
-        tb->processing = 0;
-        if (popup)
-          {
-             evas_object_del(popup);
-             evas_object_data_del(popup, "popup");
-          } 
-        it = elm_gengrid_first_item_get(tb->grid);
-        while(it)
-          {
-             Ephoto_Entry *e = elm_object_item_data_get(it);
-             similar = eina_list_append(similar, e);
-             it = elm_gengrid_item_next_get(it);
-          }
-        if (tb->searching)
-          {
-             if (eina_list_count(tb->searchentries))
-               eina_list_free(tb->searchentries);
-             tb->searchentries = eina_list_clone(similar);
-          }
-        else
-          {
-             if (eina_list_count(tb->entries))
-               eina_list_free(tb->entries);
-             if (eina_list_count(tb->ephoto->entries))
-               eina_list_free(tb->ephoto->entries);
-             tb->entries = eina_list_clone(similar);
-             tb->ephoto->entries = eina_list_clone(similar);
-          }
-        if (eina_list_count(similar))
-          eina_list_free(similar);
-        return EINA_FALSE;
-     }
-   tb->animator.todo_items = NULL;
-   tb->processing = 1;
-   EINA_LIST_FREE(tb->todo_items, entry)
-   {
-      i++;
-      if (i > TODO_ITEM_MIN_BATCH)
-         return EINA_TRUE;
-      const Elm_Gengrid_Item_Class *ic;
-
-      ic = &_ephoto_thumb_file_class;
-      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);
-        }
-      else
-        {
-           ephoto_entry_free(tb->ephoto, entry);
-        }
-      tb->animator.processed++;
-   }
-   return EINA_TRUE;
-}
-
 static void
 _sort_similarity(void *data, Evas_Object *obj EINA_UNUSED,
     void *event_data EINA_UNUSED)
 {
    Ephoto_Thumb_Browser *tb = data;
-   Evas_Object *popup, *box, *label, *pb, *ic;
+   Evas_Object *ic;
 
    tb->sort = EPHOTO_SORT_SIMILARITY;
+   tb->ephoto->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_thumb_browser_clear(tb->ephoto);
-
-   tb->todo_items = eina_list_clone(tb->entries);
-   tb->animator.count = eina_list_count(tb->todo_items);
-   tb->animator.processed = 0;
-   if (!tb->animator.todo_items)
-      tb->animator.todo_items = ecore_animator_add(_similarity_items_process, 
tb);
-
-   popup = elm_popup_add(tb->ephoto->win);
-   elm_object_part_text_set(popup, "title,text", _("Sorting"));
-   elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
-
-   box = elm_box_add(popup);
-   elm_box_horizontal_set(box, EINA_FALSE);
-   evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   evas_object_show(box);
-
-   label = elm_label_add(box);
-   elm_object_text_set(label, _("Sorting Images By Similarity"));
-   evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-   evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   elm_box_pack_end(box, label);
-   evas_object_show(label);
-
-   pb = elm_progressbar_add(box);
-   evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, 0.0);
-   evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
-   elm_object_style_set(pb, "wheel");
-   elm_progressbar_pulse_set(pb, EINA_TRUE);
-   elm_box_pack_end(box, pb);
-   evas_object_show(pb);
-   elm_progressbar_pulse(pb, EINA_TRUE);
-
-   evas_object_data_set(tb->grid, "popup", popup);
-   elm_object_part_content_set(popup, "default", box);
-   evas_object_show(popup);
+   ephoto_directory_set(tb->ephoto, tb->ephoto->config->directory,
+       NULL, tb->dirs_only, tb->thumbs_only);
 }
 
 static void
@@ -1231,7 +1120,11 @@ _ephoto_thumb_search_go(void *data, Evas_Object *obj 
EINA_UNUSED,
                e->item =
                    elm_gengrid_item_sorted_insert(tb->grid, ic, e,
                    _entry_cmp_grid_mod_desc, NULL, NULL);
-              if (e->item)
+             else if (tb->sort == EPHOTO_SORT_SIMILARITY)
+               e->item =
+                   elm_gengrid_item_sorted_insert(tb->grid, ic, e,
+                   _entry_cmp_grid_similarity, NULL, NULL);
+             if (e->item)
                {
                   Eina_File *f;
                   elm_object_item_data_set(e->item, e);
@@ -1465,11 +1358,15 @@ _todo_items_process(void *data)
              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->thumb =
+                 ephoto_thumb_add(entry->ephoto, tb->grid, entry);
+                
           if (entry->item)
             {
                elm_object_item_data_set(entry->item, entry);
              }
-           else
+           else if (tb->sort != EPHOTO_SORT_SIMILARITY)
             {
                ephoto_entry_free(tb->ephoto, entry);
             }
@@ -1488,20 +1385,6 @@ _ephoto_thumb_populate_start(void *data, int type 
EINA_UNUSED,
    if (tb->dirs_only)
      return ECORE_CALLBACK_PASS_ON;
 
-   if (tb->sort == EPHOTO_SORT_SIMILARITY)
-     {
-        Evas_Object *ic;
-
-        tb->sort = EPHOTO_SORT_ALPHABETICAL_ASCENDING;
-
-        ic = elm_icon_add(tb->hover);
-        elm_icon_standard_set(ic, "view-sort-ascending");
-        elm_object_part_content_set(tb->hover, "icon", ic);
-        evas_object_show(ic);
-
-        elm_object_text_set(tb->hover, _("Sort"));
-     }
-
    elm_object_item_disabled_set(tb->similarity, EINA_TRUE);
    tb->animator.processed = 0;
    tb->animator.count = 0;
@@ -1976,6 +1859,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);

-- 


Reply via email to