AlbumTrack.h 3.54 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

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 int64_t AlbumTrack::*const PrimaryKey;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
48
49
50
};
}

51
class AlbumTrack : public medialibrary::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, int64_t mediaId, unsigned int trackNumber, int64_t albumId, unsigned int discNumber);
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
56

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

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

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
74
    private:
75
        MediaLibraryPtr m_ml;
76
77
78
79
        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
80
        unsigned int m_trackNumber;
81
        int64_t m_albumId;
82
        unsigned int m_discNumber;
83
        bool m_isPresent;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
84

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

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

#endif // ALBUMTRACK_H