Commit d1d4edaf authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Media: Rename "name()" to "title()"

parent d64468fb
......@@ -45,7 +45,7 @@ class IMedia
virtual unsigned int id() const = 0;
virtual Type type() = 0;
virtual const std::string& name() = 0;
virtual const std::string& title() = 0;
virtual AlbumTrackPtr albumTrack() = 0;
/**
* @brief duration Returns the file duration in ms
......
......@@ -57,10 +57,10 @@ Media::Media( DBConnection dbConnection, sqlite3_stmt* stmt )
m_lastModificationDate = sqlite::Traits<unsigned int>::Load( stmt, 8 );
m_snapshot = sqlite::Traits<std::string>::Load( stmt, 9 );
m_isParsed = sqlite::Traits<bool>::Load( stmt, 10 );
m_name = sqlite::Traits<std::string>::Load( stmt, 11 );
m_title = sqlite::Traits<std::string>::Load( stmt, 11 );
}
Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& name, Type type )
Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& title, Type type )
: m_id( 0 )
, m_type( type )
, m_duration( -1 )
......@@ -71,7 +71,7 @@ Media::Media( const fs::IFile* file, unsigned int folderId, const std::string& n
, m_folderId( folderId )
, m_lastModificationDate( file->lastModificationDate() )
, m_isParsed( false )
, m_name( name )
, m_title( title )
{
}
......@@ -79,11 +79,11 @@ std::shared_ptr<Media> Media::create( DBConnection dbConnection, Type type, cons
{
auto self = std::make_shared<Media>( file, folderId, file->name(), type );
static const std::string req = "INSERT INTO " + policy::MediaTable::Name +
"(type, mrl, folder_id, last_modification_date, name) VALUES(?, ?, ?, ?, ?)";
"(type, mrl, folder_id, last_modification_date, title) VALUES(?, ?, ?, ?, ?)";
using type_t = std::underlying_type<Type>::type;
if ( _Cache::insert( dbConnection, self, req, static_cast<type_t>( type ), self->m_mrl, sqlite::ForeignKey( folderId ),
self->m_lastModificationDate, self->m_name ) == false )
self->m_lastModificationDate, self->m_title) == false )
return nullptr;
self->m_dbConnection = dbConnection;
return self;
......@@ -304,18 +304,18 @@ bool Media::setType( Type type )
return true;
}
const std::string &Media::name()
const std::string &Media::title()
{
return m_name;
return m_title;
}
bool Media::setName( const std::string &name )
bool Media::setTitle( const std::string &title )
{
static const std::string req = "UPDATE " + policy::MediaTable::Name
+ " SET name = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, name, m_id ) == false )
+ " SET title = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_dbConnection, req, title, m_id ) == false )
return false;
m_name = name;
m_title = title;
return true;
}
......@@ -333,7 +333,7 @@ bool Media::createTable( DBConnection connection )
"last_modification_date UNSIGNED INTEGER,"
"snapshot TEXT,"
"parsed BOOLEAN,"
"name TEXT,"
"title TEXT,"
"FOREIGN KEY (show_episode_id) REFERENCES " + policy::ShowEpisodeTable::Name
+ "(id_episode) ON DELETE CASCADE,"
"FOREIGN KEY (movie_id) REFERENCES " + policy::MovieTable::Name
......
......@@ -62,7 +62,7 @@ class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, pol
// shall be well-formed, and private constructor would prevent that.
// There might be a way with a user-defined allocator, but we'll see that later...
Media(DBConnection dbConnection , sqlite3_stmt* stmt);
Media(const fs::IFile* file, unsigned int folderId, const std::string &name, Type type);
Media(const fs::IFile* file, unsigned int folderId, const std::string &title, Type type);
static std::shared_ptr<Media> create(DBConnection dbConnection, Type type, const fs::IFile* file , unsigned int folderId);
static bool createTable( DBConnection connection );
......@@ -70,8 +70,8 @@ class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, pol
virtual unsigned int id() const override;
virtual Type type() override;
bool setType( Type type );
virtual const std::string& name() override;
bool setName( const std::string& name );
virtual const std::string& title() override;
bool setTitle( const std::string& title );
virtual AlbumTrackPtr albumTrack() override;
bool setAlbumTrack( AlbumTrackPtr albumTrack );
bool addArtist( ArtistPtr artist );
......@@ -119,7 +119,7 @@ class Media : public IMedia, public Cache<Media, IMedia, policy::MediaTable, pol
unsigned int m_lastModificationDate;
std::string m_snapshot;
bool m_isParsed;
std::string m_name;
std::string m_title;
// Auto fetched related properties
Album* m_album;
......
......@@ -237,7 +237,7 @@ std::shared_ptr<AlbumTrack> VLCMetadataService::handleTrack(std::shared_ptr<Albu
title = "Track #";
title += trackNbStr;
}
media->setName( title );
media->setTitle( title );
unsigned int trackNb = std::stoi( trackNbStr );
auto track = std::static_pointer_cast<AlbumTrack>( album->addTrack( media, trackNb ) );
if ( track == nullptr )
......
......@@ -96,19 +96,20 @@ TEST_F( VLCMetadataServices, ParseAudio )
TEST_F( VLCMetadataServices, ParseAlbum )
{
std::unique_lock<std::mutex> lock( cb->mutex );
auto file = ml->addFile( "mr-zebra.mp3", nullptr );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return file->albumTrack() != nullptr;
} );
ASSERT_TRUE( res );
{
std::unique_lock<std::mutex> lock( cb->mutex );
auto file = ml->addFile( "mr-zebra.mp3", nullptr );
bool res = cb->waitCond.wait_for( lock, std::chrono::seconds( 5 ), [&]{
return file->albumTrack() != nullptr;
} );
ASSERT_TRUE( res );
}
Reload();
file = std::static_pointer_cast<Media>( ml->file( "mr-zebra.mp3" ) );
auto file = ml->file( "mr-zebra.mp3" );
auto track = file->albumTrack();
ASSERT_NE( track, nullptr );
ASSERT_EQ( file->name(), "Mr. Zebra" );
ASSERT_EQ( file->title(), "Mr. Zebra" );
ASSERT_EQ( track->genre(), "Rock" );
auto artists = file->artists();
ASSERT_EQ( artists.size(), 1u );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment