diff options
author | Max Kellermann <max@duempel.org> | 2012-08-15 22:44:21 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-08-15 23:07:24 +0200 |
commit | 916a02017333ac32b8058d3c397eeb4ec85b742b (patch) | |
tree | d68e24237cf924eb7c077407cb415968010e2cac /src/Song.cxx | |
parent | c2e4fe983da690907316dac9cd1838fc713dec1b (diff) | |
download | mpd-916a02017333ac32b8058d3c397eeb4ec85b742b.tar.gz mpd-916a02017333ac32b8058d3c397eeb4ec85b742b.tar.xz mpd-916a02017333ac32b8058d3c397eeb4ec85b742b.zip |
Song: add function song_dup_detached()
Initial support for "detached" songs that come from the database, but
are private copies.
Diffstat (limited to '')
-rw-r--r-- | src/Song.cxx | 36 |
1 files changed, 36 insertions, 0 deletions
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 <assert.h> +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; } |