Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
d6038874
Commit
d6038874
authored
Oct 21, 2015
by
Hugo Beauzée-Luyssen
Browse files
AlbumTrack: Re-expose an artist property
parent
dd8bca5d
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/IAlbumTrack.h
View file @
d6038874
...
...
@@ -33,6 +33,15 @@ class IAlbumTrack
virtual
~
IAlbumTrack
()
{}
virtual
unsigned
int
id
()
const
=
0
;
/**
* @brief artist Returns the artist, as tagger in the media.
* This can be different from the associated media's artist.
* For instance, in case of a featuring, Media::artist() might return
* "Artist 1", while IAlbumTrack::artist() might return something like
* "Artist 1 featuring Artist 2 and also artist 3 and a whole bunch of people"
* @return
*/
virtual
const
std
::
string
&
artist
()
const
=
0
;
virtual
const
std
::
string
&
genre
()
=
0
;
virtual
unsigned
int
trackNumber
()
=
0
;
virtual
std
::
shared_ptr
<
IAlbum
>
album
()
=
0
;
...
...
src/AlbumTrack.cpp
View file @
d6038874
...
...
@@ -36,6 +36,7 @@ AlbumTrack::AlbumTrack(DBConnection dbConnection, sqlite::Row& row )
{
row
>>
m_id
>>
m_mediaId
>>
m_artist
>>
m_genre
>>
m_trackNumber
>>
m_albumId
;
...
...
@@ -56,11 +57,29 @@ unsigned int AlbumTrack::id() const
return
m_id
;
}
const
std
::
string
&
AlbumTrack
::
artist
()
const
{
return
m_artist
;
}
bool
AlbumTrack
::
setArtist
(
const
std
::
string
&
artist
)
{
static
const
std
::
string
req
=
"UPDATE "
+
policy
::
AlbumTrackTable
::
Name
+
" SET artist = ? WHERE id_track = ?"
;
if
(
artist
==
m_artist
)
return
true
;
if
(
sqlite
::
Tools
::
executeUpdate
(
m_dbConnection
,
req
,
artist
,
m_id
)
==
false
)
return
false
;
m_artist
=
artist
;
return
true
;
}
bool
AlbumTrack
::
createTable
(
DBConnection
dbConnection
)
{
static
const
std
::
string
req
=
"CREATE TABLE IF NOT EXISTS "
+
policy
::
AlbumTrackTable
::
Name
+
"("
"id_track INTEGER PRIMARY KEY AUTOINCREMENT,"
"media_id INTEGER,"
"artist TEXT,"
"genre TEXT,"
"track_number UNSIGNED INTEGER,"
"album_id UNSIGNED INTEGER NOT NULL,"
...
...
src/AlbumTrack.h
View file @
d6038874
...
...
@@ -53,6 +53,8 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
AlbumTrack
(
Media
*
media
,
unsigned
int
trackNumber
,
unsigned
int
albumId
);
virtual
unsigned
int
id
()
const
override
;
virtual
const
std
::
string
&
artist
()
const
override
;
bool
setArtist
(
const
std
::
string
&
artist
);
virtual
const
std
::
string
&
genre
()
override
;
bool
setGenre
(
const
std
::
string
&
genre
);
virtual
unsigned
int
trackNumber
()
override
;
...
...
@@ -66,6 +68,7 @@ class AlbumTrack : public IAlbumTrack, public Cache<AlbumTrack, IAlbumTrack, pol
DBConnection
m_dbConnection
;
unsigned
int
m_id
;
unsigned
int
m_mediaId
;
std
::
string
m_artist
;
std
::
string
m_genre
;
unsigned
int
m_trackNumber
;
unsigned
int
m_albumId
;
...
...
test/AlbumTrackTests.cpp
View file @
d6038874
...
...
@@ -25,9 +25,27 @@
#include
"Album.h"
#include
"AlbumTrack.h"
#include
"Artist.h"
#include
"Media.h"
class
AlbumTracks
:
public
Tests
{
};
TEST_F
(
AlbumTracks
,
Artist
)
{
auto
album
=
ml
->
createAlbum
(
"album"
);
auto
f
=
ml
->
addFile
(
"track1.mp3"
,
nullptr
);
auto
track
=
album
->
addTrack
(
f
,
1
);
ASSERT_EQ
(
track
->
artist
(),
""
);
track
->
setArtist
(
"artist"
);
ASSERT_EQ
(
track
->
artist
(),
"artist"
);
Reload
();
// Don't reuse the "track" and "f" variable, their type differ
auto
file
=
ml
->
file
(
"track1.mp3"
);
auto
albumTrack
=
file
->
albumTrack
();
ASSERT_EQ
(
albumTrack
->
artist
(),
"artist"
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment