core/playlists/library: Add pl_library_update() function
This is called to find and add new tracks to the library. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
e1a722d04b
commit
11430f89cf
|
@ -5,6 +5,7 @@
|
||||||
#include <core/playlists/system.h>
|
#include <core/playlists/system.h>
|
||||||
#include <core/playlists/library.h>
|
#include <core/playlists/library.h>
|
||||||
#include <core/playlists/system.h>
|
#include <core/playlists/system.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
struct scan_data {
|
struct scan_data {
|
||||||
struct library *sd_library;
|
struct library *sd_library;
|
||||||
|
@ -113,6 +114,31 @@ out:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool __lib_pl_update(void *data)
|
||||||
|
{
|
||||||
|
struct playlist *playlist = (struct playlist *)data;
|
||||||
|
struct library *library = library_lookup(playlist->pl_name);
|
||||||
|
struct db_entry *dbe, *next;
|
||||||
|
gchar *path;
|
||||||
|
|
||||||
|
db_for_each(dbe, next, track_db_get()) {
|
||||||
|
if (TRACK(dbe)->tr_library != library)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
path = track_path(TRACK(dbe));
|
||||||
|
if (g_access(path, F_OK) < 0) {
|
||||||
|
pl_system_delete_track(TRACK(dbe));
|
||||||
|
queue_remove_all(&playlist->pl_queue, TRACK(dbe));
|
||||||
|
track_remove(TRACK(dbe));
|
||||||
|
}
|
||||||
|
g_free(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
track_db_commit();
|
||||||
|
__lib_pl_scan_dir_idle(library, library->li_path);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static struct queue *pl_library_get_queue(const gchar *name)
|
static struct queue *pl_library_get_queue(const gchar *name)
|
||||||
{
|
{
|
||||||
|
@ -157,6 +183,13 @@ static bool pl_library_add_rm(const gchar *name, struct track *track)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void pl_library_update(const gchar *name)
|
||||||
|
{
|
||||||
|
struct playlist *playlist = __lib_pl_lookup(name);
|
||||||
|
if (playlist)
|
||||||
|
idle_schedule(IDLE_SYNC, __lib_pl_update, playlist);
|
||||||
|
}
|
||||||
|
|
||||||
static void pl_library_set_flag(const gchar *name, enum queue_flags flag,
|
static void pl_library_set_flag(const gchar *name, enum queue_flags flag,
|
||||||
bool enabled)
|
bool enabled)
|
||||||
{
|
{
|
||||||
|
@ -181,6 +214,7 @@ struct playlist_type pl_library = {
|
||||||
.pl_delete = pl_library_delete,
|
.pl_delete = pl_library_delete,
|
||||||
.pl_add_track = pl_library_add_rm,
|
.pl_add_track = pl_library_add_rm,
|
||||||
.pl_remove_track = pl_library_add_rm,
|
.pl_remove_track = pl_library_add_rm,
|
||||||
|
.pl_update = pl_library_update,
|
||||||
.pl_set_flag = pl_library_set_flag,
|
.pl_set_flag = pl_library_set_flag,
|
||||||
.pl_sort = pl_library_sort,
|
.pl_sort = pl_library_sort,
|
||||||
};
|
};
|
||||||
|
@ -196,6 +230,7 @@ static bool __lib_pl_init(void *data)
|
||||||
LIBRARY(dbe)->li_playlist = playlist;
|
LIBRARY(dbe)->li_playlist = playlist;
|
||||||
|
|
||||||
idle_schedule(IDLE_SYNC, __lib_pl_load, playlist);
|
idle_schedule(IDLE_SYNC, __lib_pl_load, playlist);
|
||||||
|
pl_library_update(playlist->pl_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -77,6 +77,20 @@ void test_library()
|
||||||
pl_library.pl_sort("tests/Music", COMPARE_TRACK, false);
|
pl_library.pl_sort("tests/Music", COMPARE_TRACK, false);
|
||||||
test_equal(g_slist_length(playlist->pl_queue.q_sort), 3);
|
test_equal(g_slist_length(playlist->pl_queue.q_sort), 3);
|
||||||
|
|
||||||
|
g_rename("tests/Music/Hyrule Symphony/", "tests/Hyrule Symphony/");
|
||||||
|
pl_library.pl_update("tests/Music");
|
||||||
|
while (idle_run_task()) {}
|
||||||
|
test_equal(db_actual_size(track_db_get()), 48);
|
||||||
|
test_equal(track_db_get()->db_size, 35);
|
||||||
|
test_equal(queue_size(&playlist->pl_queue), 35);
|
||||||
|
|
||||||
|
g_rename("tests/Hyrule Symphony", "tests/Music/Hyrule Symphony/");
|
||||||
|
pl_library.pl_update("tests/Music");
|
||||||
|
while (idle_run_task()) {}
|
||||||
|
test_equal(db_actual_size(track_db_get()), 61);
|
||||||
|
test_equal(track_db_get()->db_size, 48);
|
||||||
|
test_equal(queue_size(&playlist->pl_queue), 48);
|
||||||
|
|
||||||
test_equal(pl_library.pl_delete("tests/Music"), (bool)true);
|
test_equal(pl_library.pl_delete("tests/Music"), (bool)true);
|
||||||
test_equal(pl_library.pl_delete("tests/Music"), (bool)false);
|
test_equal(pl_library.pl_delete("tests/Music"), (bool)false);
|
||||||
test_equal((void *)library_get(0), NULL);
|
test_equal((void *)library_get(0), NULL);
|
||||||
|
|
Loading…
Reference in New Issue