Album.h 3.03 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

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

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

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

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

71
        virtual bool destroy();
72

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

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

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

#endif // ALBUM_H