AlbumTrack.h 3.1 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.
 *****************************************************************************/

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
23
24
25
26
27
28
29
#ifndef ALBUMTRACK_H
#define ALBUMTRACK_H

#include <sqlite3.h>
#include <string>

#include "IAlbumTrack.h"
30
#include "IMediaLibrary.h"
31
#include "database/DatabaseHelpers.h"
32
#include "utils/Cache.h"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
33
34

class Album;
35
class AlbumTrack;
36
class Artist;
37
class Media;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
38

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

49
class AlbumTrack : public IAlbumTrack, public DatabaseHelpers<AlbumTrack, policy::AlbumTrackTable>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
50
51
{
    public:
52
        AlbumTrack( DBConnection dbConnection, sqlite::Row& row );
53
        AlbumTrack( unsigned int mediaId, unsigned int trackNumber, unsigned int albumId , unsigned int discNumber);
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
54

55
        virtual unsigned int id() const override;
56
57
        virtual ArtistPtr artist() const override;
        bool setArtist( std::shared_ptr<Artist> artist );
58
59
60
        virtual const std::string& genre() override;
        bool setGenre( const std::string& genre );
        virtual unsigned int trackNumber() override;
61
62
        virtual unsigned int releaseYear() const override;
        bool setReleaseYear( unsigned int year );
63
        virtual unsigned int discNumber() const override;
64
        virtual std::shared_ptr<IAlbum> album() override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
65

66
        static bool createTable( DBConnection dbConnection );
67
68
        static std::shared_ptr<AlbumTrack> create( DBConnection dbConnection, unsigned int albumId,
                                     unsigned int mediaId, unsigned int trackNb , unsigned int discNumber );
69

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
70
    private:
71
        DBConnection m_dbConnection;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
72
        unsigned int m_id;
73
        unsigned int m_mediaId;
74
        unsigned int m_artistId;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
75
76
77
        std::string m_genre;
        unsigned int m_trackNumber;
        unsigned int m_albumId;
78
        unsigned int m_releaseYear;
79
        unsigned int m_discNumber;
80
        bool m_isPresent;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
81

82
        std::weak_ptr<Album> m_album;
83
        mutable Cache<std::shared_ptr<Artist>> m_artist;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
84

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
85
        friend struct policy::AlbumTrackTable;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
86
87
88
};

#endif // ALBUMTRACK_H