Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
ffa40a28
Commit
ffa40a28
authored
May 23, 2014
by
Hugo Beauzée-Luyssen
Browse files
Handle assigning an album track to a file
parent
87e2b32a
Changes
6
Hide whitespace changes
Inline
Side-by-side
include/IFile.h
View file @
ffa40a28
...
...
@@ -25,7 +25,8 @@ class IFile
virtual
~
IFile
()
{}
virtual
unsigned
int
id
()
const
=
0
;
virtual
std
::
shared_ptr
<
IAlbumTrack
>
albumTrack
()
=
0
;
virtual
AlbumTrackPtr
albumTrack
()
=
0
;
virtual
bool
setAlbumTrack
(
AlbumTrackPtr
albumTrack
)
=
0
;
virtual
unsigned
int
duration
()
const
=
0
;
virtual
std
::
shared_ptr
<
IShowEpisode
>
showEpisode
()
=
0
;
virtual
int
playCount
()
const
=
0
;
...
...
src/File.cpp
View file @
ffa40a28
...
...
@@ -50,7 +50,7 @@ FilePtr File::create( sqlite3* dbConnection, const std::string& mrl )
return
self
;
}
std
::
shared_ptr
<
I
AlbumTrack
>
File
::
albumTrack
()
AlbumTrack
Ptr
File
::
albumTrack
()
{
if
(
m_albumTrack
==
nullptr
&&
m_albumTrackId
!=
0
)
{
...
...
@@ -59,6 +59,17 @@ std::shared_ptr<IAlbumTrack> File::albumTrack()
return
m_albumTrack
;
}
bool
File
::
setAlbumTrack
(
AlbumTrackPtr
albumTrack
)
{
static
const
std
::
string
req
=
"UPDATE "
+
policy
::
FileTable
::
Name
+
" SET album_track_id = ? "
"WHERE id_file = ?"
;
if
(
SqliteTools
::
executeUpdate
(
m_dbConnection
,
req
,
albumTrack
->
id
(),
m_id
)
==
false
)
return
false
;
m_albumTrackId
=
albumTrack
->
id
();
m_albumTrack
=
albumTrack
;
return
true
;
}
unsigned
int
File
::
duration
()
const
{
return
m_duration
;
...
...
src/File.h
View file @
ffa40a28
...
...
@@ -46,7 +46,8 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
static
bool
createTable
(
sqlite3
*
connection
);
virtual
unsigned
int
id
()
const
;
virtual
std
::
shared_ptr
<
IAlbumTrack
>
albumTrack
();
virtual
AlbumTrackPtr
albumTrack
();
virtual
bool
setAlbumTrack
(
AlbumTrackPtr
albumTrack
);
virtual
unsigned
int
duration
()
const
;
virtual
std
::
shared_ptr
<
IShowEpisode
>
showEpisode
();
virtual
bool
addLabel
(
LabelPtr
label
);
...
...
@@ -69,7 +70,7 @@ class File : public IFile, public Cache<File, IFile, policy::FileTable, policy::
// Auto fetched related properties
Album
*
m_album
;
std
::
shared_ptr
<
AlbumTrack
>
m_albumTrack
;
AlbumTrack
Ptr
m_albumTrack
;
std
::
shared_ptr
<
ShowEpisode
>
m_showEpisode
;
friend
class
Cache
<
File
,
IFile
,
policy
::
FileTable
,
policy
::
FileCache
>
;
...
...
src/Label.cpp
View file @
ffa40a28
...
...
@@ -29,7 +29,6 @@ unsigned int Label::id() const
return
m_id
;
}
const
std
::
string
&
Label
::
name
()
{
return
m_name
;
...
...
src/SqliteTools.h
View file @
ffa40a28
...
...
@@ -90,10 +90,13 @@ class SqliteTools
return
sqlite3_changes
(
dbConnection
)
>
0
;
}
/**
* This is meant to be used for "write only" requests, as the statement is not
* exposed to the caller.
*/
template
<
typename
...
Args
>
static
bool
executeUpdate
(
sqlite3
*
dbConnection
,
const
std
::
string
&
req
,
const
Args
&
...
args
)
{
// The code would be exactly the same, do not freak out because it call delete :)
return
executeDelete
(
dbConnection
,
req
,
args
...
);
}
template
<
typename
...
Args
>
static
bool
executeRequest
(
sqlite3
*
dbConnection
,
const
std
::
string
&
req
,
const
Args
&
...
args
)
{
...
...
test/Albums.cpp
View file @
ffa40a28
...
...
@@ -2,6 +2,7 @@
#include "IAlbum.h"
#include "IAlbumTrack.h"
#include "IFile.h"
#include "IMediaLibrary.h"
class
Albums
:
public
testing
::
Test
...
...
@@ -70,3 +71,24 @@ TEST_F( Albums, AddTrack )
ASSERT_EQ
(
tracks
.
size
(),
1u
);
ASSERT_EQ
(
tracks
[
0
]
->
title
(),
track
->
title
()
);
}
TEST_F
(
Albums
,
AssignTrack
)
{
auto
f
=
ml
->
addFile
(
"file"
);
auto
a
=
ml
->
createAlbum
(
"album"
);
auto
t
=
a
->
addTrack
(
"track"
,
1
);
ASSERT_EQ
(
f
->
albumTrack
(),
nullptr
);
bool
res
=
f
->
setAlbumTrack
(
t
);
ASSERT_TRUE
(
res
);
ASSERT_NE
(
f
->
albumTrack
(),
nullptr
);
ASSERT_EQ
(
f
->
albumTrack
(),
t
);
delete
ml
;
SetUp
();
f
=
ml
->
file
(
"file"
);
t
=
f
->
albumTrack
();
ASSERT_NE
(
t
,
nullptr
);
ASSERT_EQ
(
t
->
title
(),
"track"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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