summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2016-06-17 12:08:21 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2016-06-17 12:08:21 -0400
commite8509d5935b79ef7387caeb4f7bc0377e265b366 (patch)
treea82d13573d9263114289430b990a3fe3a7793f80
parent8cfc6f6553ec991b67084039f7d259dc17d08a18 (diff)
refactor/simplify apm updating, fix some corner cases when renaming files
-rw-r--r--src/modules/auto_playlist_manager.c115
1 files 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
198 free(data); 198 free(data);
199} 199}
200 200
201static Eina_Bool
202run_adds_for_header(Elm_Object_Item *item, Eina_List *todo)
203{
204 const char *file;
205 const Eina_List *sub, *lll;
206 Eina_List *l;
207 Elm_Object_Item *subi;
208 int ret = 0, last_pos = 0;
209 Eina_Bool updated = EINA_FALSE;
210
211 sub = elm_genlist_item_subitems_get(item);
212 if (eina_list_count(sub) < 2) //just one song, ignore
213 return EINA_FALSE;
214
215 EINA_LIST_REVERSE_FOREACH(todo, l, file)
216 {
217 Eina_Bool update_success = EINA_FALSE;
218 /* insert items starting at the end of the subitems to ensure placement */
219 EINA_LIST_REVERSE_FOREACH(sub, lll, subi)
220 {
221 Empd_Empdd_Song *ss = elm_object_item_data_get(subi);
222
223 last_pos = ss->song_pos;
224 /* find item that goes before this one and place this after */
225 ret = strcmp(ss->uri, file);
226 if (!ret) break; //already exists here...what the actual fuck
227 if (ret > 0) continue;
228 post_add(1, file);
229 empd_empdd_add_id_list_call(empd_proxy, file, ss->song_pos + 1);
230 update_success = EINA_TRUE;
231 }
232 /* song goes before any existing songs */
233 if (ret && (!update_success))
234 {
235 empd_empdd_add_id_list_call(empd_proxy, file, last_pos);
236 updated = EINA_TRUE;
237 }
238 updated |= update_success;
239 }
240
241 return !!updated;
242}
243
201static void 244static void
202run_adds(void) 245run_adds(void)
203{ 246{
204 char *file; 247 char *file;
248 Eina_List *todo = NULL;
205 249
206 last_queue_length = empd_queue_length; 250 last_queue_length = empd_queue_length;
207 while (adds) 251 while (adds)
@@ -228,76 +272,45 @@ run_adds(void)
228 adds = eina_list_remove_list(adds, adds); 272 adds = eina_list_remove_list(adds, adds);
229 return; 273 return;
230 } 274 }
275 adds = eina_list_remove_list(adds, adds);
276
277
278 /* create list of all items in directory to update at once */
279 todo = eina_list_append(todo, file);
280 EINA_LIST_FOREACH_SAFE(adds, i, ii, b)
281 {
282 if (!is_same_path(file, a, b, NULL)) break;
283 eina_list_move_list(&todo, &adds, i);
284 }
231 285
232 /* check for existing pieces of album in list */ 286 /* check for existing pieces of album in list */
233 a++; 287 a++;
234 it = eina_hash_iterator_data_new(empd_current_queue_headers); 288 it = eina_hash_iterator_data_new(empd_current_queue_headers);
235 EINA_ITERATOR_FOREACH(it, i) 289 EINA_ITERATOR_FOREACH(it, i)
236 { 290 {
237 const Eina_List *sub;
238 Empd_Empdd_Song *so; 291 Empd_Empdd_Song *so;
239 292
240 item = eina_list_data_get(i); 293 item = eina_list_data_get(i);
241 so = elm_object_item_data_get(item); 294 so = elm_object_item_data_get(item);
242 if (!is_same_path(file, a, so->uri, NULL)) continue; 295 if (!is_same_path(file, a, so->uri, NULL)) continue;
243 296
244 /* from the same directory: a match */ 297 /* run updates for related headers */
245 EINA_LIST_REVERSE_FOREACH(i, ii, item) 298 EINA_LIST_REVERSE_FOREACH(i, ii, item)
246 { 299 done |= run_adds_for_header(item, todo);
247 const Eina_List *lll;
248 Elm_Object_Item *subi;
249
250 sub = elm_genlist_item_subitems_get(item);
251 if (eina_list_count(sub) < 2) //just one song, ignore
252 continue;
253 EINA_LIST_REVERSE_FOREACH(sub, lll, subi)
254 {
255 Empd_Empdd_Song *ss = elm_object_item_data_get(subi);
256 int ret, pos = 1;
257
258 /* find item that goes before this one and place this after */
259 ret = strcmp(ss->uri, file);
260 if (!ret) break; //already exists here...what the actual fuck
261 if (ret > 0) continue;
262 post_add(1, file);
263 empd_empdd_add_id_list_call(empd_proxy, file, ss->song_pos + 1);
264 done = EINA_TRUE;
265 while (eina_list_next(adds))
266 {
267 char *f2;
268
269 pos++;
270 f2 = eina_list_data_get(eina_list_next(adds));
271 if (!is_same_path(file, a, f2, NULL)) break;
272 empd_empdd_add_id_list_call(empd_proxy, file, ss->song_pos + pos);
273 post_add(1, f2);
274 adds = eina_list_remove_list(adds, eina_list_next(adds));
275 free(f2);
276 }
277 break;
278 }
279 }
280 break; 300 break;
281 } 301 }
282 if (!done) 302 if (done)
303 E_FREE_LIST(todo, free);
304 else
283 { 305 {
284 char *f2; 306 EINA_LIST_FREE(todo, file)
285
286 /* sequentially append all songs from matching directory structure */
287 empd_empdd_add_list_call(empd_proxy, file);
288 post_add(0, file);
289 while (eina_list_next(adds))
290 { 307 {
291 f2 = eina_list_data_get(eina_list_next(adds)); 308 /* sequentially append all songs from matching directory structure */
292 if (!is_same_path(file, a, f2, NULL)) break; 309 empd_empdd_add_list_call(empd_proxy, file);
293 empd_empdd_add_list_call(empd_proxy, f2); 310 post_add(0, file);
294 post_add(0, f2); 311 free(file);
295 adds = eina_list_remove_list(adds, eina_list_next(adds));
296 free(f2);
297 } 312 }
298 } 313 }
299 adds = eina_list_remove_list(adds, adds);
300 free(file);
301 } 314 }
302} 315}
303 316