Album.h 3.06 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
 *
 * Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

23 24 25
#ifndef ALBUM_H
#define ALBUM_H

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
26
#include <memory>
27 28
#include <sqlite3.h>

29 30
#include "IMediaLibrary.h"

31
#include "database/Cache.h"
32 33
#include "IAlbum.h"

34
class Album;
35 36
class AlbumTrack;
class Artist;
37
class Media;
38

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
39 40 41 42 43 44
namespace policy
{
struct AlbumTable
{
    static const std::string Name;
    static const std::string CacheColumn;
45
    static unsigned int Album::*const PrimaryKey;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
46 47 48 49
};
}

class Album : public IAlbum, public Cache<Album, IAlbum, policy::AlbumTable>
50
{
51 52
    private:
        typedef Cache<Album, IAlbum, policy::AlbumTable> _Cache;
53
    public:
54
        Album( DBConnection dbConnection, sqlite3_stmt* stmt );
55
        Album( const std::string& title );
56

57 58 59 60 61 62 63 64 65
        virtual unsigned int id() const override;
        virtual const std::string& title() const override;
        virtual time_t releaseDate() const override;
        bool setReleaseDate( time_t date );
        virtual const std::string& shortSummary() const override;
        bool setShortSummary( const std::string& summary );
        virtual const std::string& artworkUrl() const override;
        bool setArtworkUrl( const std::string& artworkUrl );
        virtual time_t lastSyncDate() const override;
66 67
        virtual std::vector<AlbumTrackPtr> tracks() const override;
        std::shared_ptr<AlbumTrack> addTrack( std::shared_ptr<Media> media, unsigned int trackNb );
68 69

        virtual std::vector<ArtistPtr> artists() const override;
70
        bool addArtist( std::shared_ptr<Artist> artist );
71

72
        bool destroy();
73

74
        static bool createTable( DBConnection dbConnection );
75
        static std::shared_ptr<Album> create(DBConnection dbConnection, const std::string& title );
76 77

    protected:
78
        DBConnection m_dbConnection;
79
        unsigned int m_id;
80
        std::string m_title;
81
        unsigned int m_releaseDate;
82 83 84 85
        std::string m_shortSummary;
        std::string m_artworkUrl;
        time_t m_lastSyncDate;

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
86
        friend class Cache<Album, IAlbum, policy::AlbumTable>;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
87
        friend struct policy::AlbumTable;
88 89 90
};

#endif // ALBUM_H