Album.h 4.43 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
#include <sqlite3.h>
28
#include <mutex>
29

30
31
#include "IMediaLibrary.h"

32
#include "database/DatabaseHelpers.h"
33
#include "IAlbum.h"
34
#include "utils/Cache.h"
35

36
class Album;
37
38
class AlbumTrack;
class Artist;
39
class Media;
40

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

51
class Album : public IAlbum, public DatabaseHelpers<Album, policy::AlbumTable>
52
53
{
    public:
54
        Album( DBConnection dbConnection, sqlite::Row& row );
55
        Album( const std::string& title );
56
        Album( const Artist* artist );
57

58
59
        virtual unsigned int id() const override;
        virtual const std::string& title() const override;
60
61
62
63
64
65
66
67
68
69
70
        virtual unsigned int releaseYear() const override;
        /**
         * @brief setReleaseYear Updates the release year
         * @param date The desired date.
         * @param force If force is true, the date will be applied no matter what.
         *              If force is false, the date will be applied if it never was
         *              applied before. Otherwise, setReleaseYear() will restore the release
         *              date to 0.
         * @return
         */
        bool setReleaseYear( unsigned int date, bool force );
71
72
        virtual const std::string& shortSummary() const override;
        bool setShortSummary( const std::string& summary );
73
74
        virtual const std::string& artworkMrl() const override;
        bool setArtworkMrl( const std::string& artworkMrl );
75
        virtual std::vector<MediaPtr> tracks() const override;
76
        virtual std::vector<std::shared_ptr<IMedia>> tracks( GenrePtr genre ) const override;
77
78
79
80
81
82
        ///
        /// \brief cachedTracks Returns a cached list of tracks
        /// This has no warranty of ordering, validity, or anything else.
        /// \return An unordered-list of this album's tracks
        ///
        std::vector<MediaPtr> cachedTracks() const;
83
84
        ///
        /// \brief addTrack Add a track to the album.
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
85
        /// This will modify the media, but *not* save it.
86
87
88
        /// The media will be added to the tracks cache.
        ///
        std::shared_ptr<AlbumTrack> addTrack( std::shared_ptr<Media> media, unsigned int trackNb, unsigned int discNumber);
89
        unsigned int nbTracks() const override;
90

91
92
        virtual ArtistPtr albumArtist() const override;
        bool setAlbumArtist( Artist* artist );
93
        virtual std::vector<ArtistPtr> artists() const override;
94
        bool addArtist( std::shared_ptr<Artist> artist );
95
        bool removeArtist( Artist* artist );
96

97
        static bool createTable( DBConnection dbConnection );
98
        static bool createTriggers( DBConnection dbConnection );
99
        static std::shared_ptr<Album> create(DBConnection dbConnection, const std::string& title );
100
        static std::shared_ptr<Album> createUnknownAlbum( DBConnection dbConnection, const Artist* artist );
101
102

    protected:
103
        DBConnection m_dbConnection;
104
        unsigned int m_id;
105
        std::string m_title;
106
        unsigned int m_artistId;
107
        unsigned int m_releaseYear;
108
        std::string m_shortSummary;
109
        std::string m_artworkMrl;
110
        unsigned int m_nbTracks;
111
        bool m_isPresent;
112

113
114
        mutable Cache<std::vector<MediaPtr>> m_tracks;

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
115
        friend struct policy::AlbumTable;
116
117
118
};

#endif // ALBUM_H