From 916a02017333ac32b8058d3c397eeb4ec85b742b Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 15 Aug 2012 22:44:21 +0200 Subject: Song: add function song_dup_detached() Initial support for "detached" songs that come from the database, but are private copies. --- src/Song.cxx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/Song.cxx') diff --git a/src/Song.cxx b/src/Song.cxx index 3dfdc0c74..2ef690fb0 100644 --- a/src/Song.cxx +++ b/src/Song.cxx @@ -29,6 +29,8 @@ extern "C" { #include +struct directory detached_root; + static struct song * song_alloc(const char *uri, struct directory *parent) { @@ -76,6 +78,27 @@ song_replace_uri(struct song *old_song, const char *uri) return new_song; } +struct song * +song_dup_detached(const struct song *src) +{ + assert(src != nullptr); + + struct song *song; + if (song_in_database(src)) { + char *uri = song_get_uri(src); + song = song_alloc(uri, &detached_root); + g_free(uri); + } else + song = song_alloc(src->uri, nullptr); + + song->tag = tag_dup(src->tag); + song->mtime = src->mtime; + song->start_ms = src->start_ms; + song->end_ms = src->end_ms; + + return song; +} + void song_free(struct song *song) { @@ -107,6 +130,19 @@ song_equals(const struct song *a, const struct song *b) assert(a != nullptr); assert(b != nullptr); + if (a->parent != nullptr && b->parent != nullptr && + !directory_equals(*a->parent, *b->parent) && + (a->parent == &detached_root || b->parent == &detached_root)) { + /* must compare the full URI if one of the objects is + "detached" */ + char *au = song_get_uri(a); + char *bu = song_get_uri(b); + const bool result = strcmp(au, bu) == 0; + g_free(bu); + g_free(au); + return result; + } + return directory_is_same(a->parent, b->parent) && strcmp(a->uri, b->uri) == 0; } -- cgit v1.2.3