AlbumTrack.h 3.44 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
#ifndef ALBUMTRACK_H
#define ALBUMTRACK_H

#include <sqlite3.h>
#include <string>
28
#include <vector>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
29
30

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

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

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

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

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

68
        static bool createTable( DBConnection dbConnection );
69
        static std::shared_ptr<AlbumTrack> create( MediaLibraryPtr ml, unsigned int albumId,
70
                                     const Media& media, unsigned int trackNb , unsigned int discNumber );
71
72
        static AlbumTrackPtr fromMedia( MediaLibraryPtr ml, unsigned int mediaId );
        static std::vector<AlbumTrackPtr> fromGenre( MediaLibraryPtr ml, unsigned int genreId );
73
        static std::vector<MediaPtr> search(DBConnection dbConn, const std::string& title );
74

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
75
    private:
76
        MediaLibraryPtr m_ml;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
77
        unsigned int m_id;
78
        unsigned int m_mediaId;
79
        unsigned int m_artistId;
80
        unsigned int m_genreId;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
81
82
        unsigned int m_trackNumber;
        unsigned int m_albumId;
83
        unsigned int m_releaseYear;
84
        unsigned int m_discNumber;
85
        bool m_isPresent;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
86

87
        std::weak_ptr<Album> m_album;
88
        mutable Cache<std::shared_ptr<Artist>> m_artist;
89
        mutable Cache<std::shared_ptr<Genre>> m_genre;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
90

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
91
        friend struct policy::AlbumTrackTable;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
92
93
94
};

#endif // ALBUMTRACK_H