discomfitor pushed a commit to branch master. http://git.enlightenment.org/apps/empc.git/commit/?id=e8509d5935b79ef7387caeb4f7bc0377e265b366
commit e8509d5935b79ef7387caeb4f7bc0377e265b366 Author: Mike Blumenkrantz <[email protected]> Date: Fri Jun 17 12:08:21 2016 -0400 refactor/simplify apm updating, fix some corner cases when renaming files --- src/modules/auto_playlist_manager.c | 115 ++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 51 deletions(-) diff --git a/src/modules/auto_playlist_manager.c b/src/modules/auto_playlist_manager.c index 152bc10..ed5ef9f 100644 --- a/src/modules/auto_playlist_manager.c +++ b/src/modules/auto_playlist_manager.c @@ -198,10 +198,54 @@ info_cb(Eldbus_Proxy *proxy EINA_UNUSED, void *data, Eldbus_Pending *pending EIN free(data); } +static Eina_Bool +run_adds_for_header(Elm_Object_Item *item, Eina_List *todo) +{ + const char *file; + const Eina_List *sub, *lll; + Eina_List *l; + Elm_Object_Item *subi; + int ret = 0, last_pos = 0; + Eina_Bool updated = EINA_FALSE; + + sub = elm_genlist_item_subitems_get(item); + if (eina_list_count(sub) < 2) //just one song, ignore + return EINA_FALSE; + + EINA_LIST_REVERSE_FOREACH(todo, l, file) + { + Eina_Bool update_success = EINA_FALSE; + /* insert items starting at the end of the subitems to ensure placement */ + EINA_LIST_REVERSE_FOREACH(sub, lll, subi) + { + Empd_Empdd_Song *ss = elm_object_item_data_get(subi); + + last_pos = ss->song_pos; + /* find item that goes before this one and place this after */ + ret = strcmp(ss->uri, file); + if (!ret) break; //already exists here...what the actual fuck + if (ret > 0) continue; + post_add(1, file); + empd_empdd_add_id_list_call(empd_proxy, file, ss->song_pos + 1); + update_success = EINA_TRUE; + } + /* song goes before any existing songs */ + if (ret && (!update_success)) + { + empd_empdd_add_id_list_call(empd_proxy, file, last_pos); + updated = EINA_TRUE; + } + updated |= update_success; + } + + return !!updated; +} + static void run_adds(void) { char *file; + Eina_List *todo = NULL; last_queue_length = empd_queue_length; while (adds) @@ -228,76 +272,45 @@ run_adds(void) adds = eina_list_remove_list(adds, adds); return; } + adds = eina_list_remove_list(adds, adds); + + + /* create list of all items in directory to update at once */ + todo = eina_list_append(todo, file); + EINA_LIST_FOREACH_SAFE(adds, i, ii, b) + { + if (!is_same_path(file, a, b, NULL)) break; + eina_list_move_list(&todo, &adds, i); + } /* check for existing pieces of album in list */ a++; it = eina_hash_iterator_data_new(empd_current_queue_headers); EINA_ITERATOR_FOREACH(it, i) { - const Eina_List *sub; Empd_Empdd_Song *so; item = eina_list_data_get(i); so = elm_object_item_data_get(item); if (!is_same_path(file, a, so->uri, NULL)) continue; - /* from the same directory: a match */ + /* run updates for related headers */ EINA_LIST_REVERSE_FOREACH(i, ii, item) - { - const Eina_List *lll; - Elm_Object_Item *subi; - - sub = elm_genlist_item_subitems_get(item); - if (eina_list_count(sub) < 2) //just one song, ignore - continue; - EINA_LIST_REVERSE_FOREACH(sub, lll, subi) - { - Empd_Empdd_Song *ss = elm_object_item_data_get(subi); - int ret, pos = 1; - - /* find item that goes before this one and place this after */ - ret = strcmp(ss->uri, file); - if (!ret) break; //already exists here...what the actual fuck - if (ret > 0) continue; - post_add(1, file); - empd_empdd_add_id_list_call(empd_proxy, file, ss->song_pos + 1); - done = EINA_TRUE; - while (eina_list_next(adds)) - { - char *f2; - - pos++; - f2 = eina_list_data_get(eina_list_next(adds)); - if (!is_same_path(file, a, f2, NULL)) break; - empd_empdd_add_id_list_call(empd_proxy, file, ss->song_pos + pos); - post_add(1, f2); - adds = eina_list_remove_list(adds, eina_list_next(adds)); - free(f2); - } - break; - } - } + done |= run_adds_for_header(item, todo); break; } - if (!done) + if (done) + E_FREE_LIST(todo, free); + else { - char *f2; - - /* sequentially append all songs from matching directory structure */ - empd_empdd_add_list_call(empd_proxy, file); - post_add(0, file); - while (eina_list_next(adds)) + EINA_LIST_FREE(todo, file) { - f2 = eina_list_data_get(eina_list_next(adds)); - if (!is_same_path(file, a, f2, NULL)) break; - empd_empdd_add_list_call(empd_proxy, f2); - post_add(0, f2); - adds = eina_list_remove_list(adds, eina_list_next(adds)); - free(f2); + /* sequentially append all songs from matching directory structure */ + empd_empdd_add_list_call(empd_proxy, file); + post_add(0, file); + free(file); } } - adds = eina_list_remove_list(adds, adds); - free(file); } } --
