Artist.h 4.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.
 *****************************************************************************/

23 24
#pragma once

25
#include "database/DatabaseHelpers.h"
26 27
#include "medialibrary/IArtist.h"
#include "medialibrary/IMediaLibrary.h"
28
#include "utils/Cache.h"
29
#include "Thumbnail.h"
30

31 32 33
namespace medialibrary
{

34
class Artist;
35
class Album;
36
class Media;
37

38
class Artist : public IArtist, public DatabaseHelpers<Artist>
39 40
{
public:
41 42 43 44 45 46
    struct Table
    {
        static const std::string Name;
        static const std::string PrimaryKeyColumn;
        static int64_t Artist::*const PrimaryKey;
    };
47 48
    Artist( MediaLibraryPtr ml, sqlite::Row& row );
    Artist( MediaLibraryPtr ml, const std::string& name );
49

50
    virtual int64_t id() const override;
51
    virtual const std::string& name() const override;
52
    virtual const std::string& shortBio() const override;
53
    bool setShortBio( const std::string& shortBio );
54
    virtual Query<IAlbum> albums( const QueryParameters* params ) const override;
55 56
    virtual Query<IAlbum> searchAlbums( const std::string& pattern,
                                        const QueryParameters* params = nullptr ) const override;
57
    virtual Query<IMedia> tracks( const QueryParameters* params ) const override;
58 59
    virtual Query<IMedia> searchTracks( const std::string& pattern,
                                        const QueryParameters* params = nullptr ) const override;
60
    bool addMedia( Media& tracks );
61
    virtual const std::string& artworkMrl() const override;
62
    std::shared_ptr<Thumbnail> thumbnail();
63
    bool setArtworkMrl( const std::string& artworkMrl, Thumbnail::Origin origin );
64
    bool updateNbAlbum( int increment );
65
    bool updateNbTrack( int increment );
66
    std::shared_ptr<Album> unknownAlbum();
67 68
    virtual const std::string& musicBrainzId() const override;
    bool setMusicBrainzId( const std::string& musicBrainzId );
69 70
    virtual unsigned int nbAlbums() const override;
    virtual unsigned int nbTracks() const override;
71

72
    static void createTable( sqlite::Connection* dbConnection );
73
    static void createTriggers( sqlite::Connection* dbConnection, uint32_t dbModelVersion );
74
    static bool createDefaultArtists( sqlite::Connection* dbConnection );
75
    static std::shared_ptr<Artist> create( MediaLibraryPtr ml, const std::string& name );
76
    static Query<IArtist> search( MediaLibraryPtr ml, const std::string& name,
77
                                           const QueryParameters* params );
78
    static Query<IArtist> listAll( MediaLibraryPtr ml, bool includeAll,
79
                                   const QueryParameters* params );
80 81
    static Query<IArtist> searchByGenre( MediaLibraryPtr ml, const std::string& pattern,
                                         const QueryParameters* params, int64_t genreId );
82

83
private:
84
    static std::string sortRequest( const QueryParameters* params );
85

86
private:
87
    MediaLibraryPtr m_ml;
88
    int64_t m_id;
89
    const std::string m_name;
90
    std::string m_shortBio;
91
    int64_t m_thumbnailId;
92
    unsigned int m_nbAlbums;
93
    unsigned int m_nbTracks;
94
    std::string m_mbId;
95
    bool m_isPresent;
96

97 98
    mutable Cache<std::shared_ptr<Thumbnail>> m_thumbnail;

99
    friend struct Artist::Table;
100
};
101 102

}