AlbumTrack.h 3.64 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
31
#include "medialibrary/IAlbumTrack.h"
#include "medialibrary/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
36
37
namespace medialibrary
{

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

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
44
45
46
47
48
namespace policy
{
struct AlbumTrackTable
{
    static const std::string Name;
49
    static const std::string PrimaryKeyColumn;
50
    static int64_t AlbumTrack::*const PrimaryKey;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
51
52
53
};
}

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

61
        virtual int64_t id() const override;
62
        virtual ArtistPtr artist() const override;
63
        bool setArtist( std::shared_ptr<Artist> artist );
64
        virtual GenrePtr genre() override;
65
        bool setGenre( std::shared_ptr<Genre> genre );
66
        virtual unsigned int trackNumber() override;
67
        virtual unsigned int discNumber() const override;
68
69
        virtual std::shared_ptr<IAlbum> album() override;
        virtual std::shared_ptr<IMedia> media() override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
70

71
        static void createTable( sqlite::Connection* dbConnection );
72
        static std::shared_ptr<AlbumTrack> create(MediaLibraryPtr ml, int64_t albumId,
73
74
75
                                    std::shared_ptr<Media> media, unsigned int trackNb,
                                    unsigned int discNumber, int64_t artistId, int64_t genreId,
                                    int64_t duration );
76
77
        static AlbumTrackPtr fromMedia( MediaLibraryPtr ml, int64_t mediaId );
        static std::vector<MediaPtr> fromGenre( MediaLibraryPtr ml, int64_t genreId, SortingCriteria sort, bool desc );
78
        static std::vector<MediaPtr> search( sqlite::Connection* dbConn, const std::string& title );
79

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
80
    private:
81
        MediaLibraryPtr m_ml;
82
83
84
85
        int64_t m_id;
        int64_t m_mediaId;
        int64_t m_artistId;
        int64_t m_genreId;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
86
        unsigned int m_trackNumber;
87
        int64_t m_albumId;
88
        unsigned int m_discNumber;
89
        bool m_isPresent;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
90

91
        mutable Cache<std::weak_ptr<Album>> m_album;
92
        mutable Cache<std::shared_ptr<Artist>> m_artist;
93
        mutable Cache<std::shared_ptr<Genre>> m_genre;
94
        mutable Cache<std::weak_ptr<Media>> m_media;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
95

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
96
        friend struct policy::AlbumTrackTable;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
97
98
};

99
100
}

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
101
#endif // ALBUMTRACK_H