Artist.h 3.08 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
#pragma once

25
#include "database/DatabaseHelpers.h"
26 27
#include "medialibrary/IArtist.h"
#include "medialibrary/IMediaLibrary.h"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
28

29 30 31
namespace medialibrary
{

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
32
class Artist;
33
class Album;
34
class Media;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
35 36 37 38 39 40

namespace policy
{
struct ArtistTable
{
    static const std::string Name;
41
    static const std::string PrimaryKeyColumn;
42
    static int64_t Artist::*const PrimaryKey;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
43 44 45
};
}

46
class Artist : public IArtist, public DatabaseHelpers<Artist, policy::ArtistTable>
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
47 48
{
public:
49 50
    Artist( MediaLibraryPtr ml, sqlite::Row& row );
    Artist( MediaLibraryPtr ml, const std::string& name );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
51

52
    virtual int64_t id() const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
53 54
    virtual const std::string &name() const override;
    virtual const std::string& shortBio() const override;
55
    bool setShortBio( const std::string& shortBio );
56 57
    virtual std::vector<AlbumPtr> albums( SortingCriteria sort, bool desc ) const override;
    virtual std::vector<MediaPtr> media(SortingCriteria sort, bool desc) const override;
58
    bool addMedia( Media& media );
59 60
    virtual const std::string& artworkMrl() const override;
    bool setArtworkMrl( const std::string& artworkMrl );
61
    bool updateNbAlbum( int increment );
62
    std::shared_ptr<Album> unknownAlbum();
63 64
    virtual const std::string& musicBrainzId() const override;
    bool setMusicBrainzId( const std::string& musicBrainzId );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
65 66

    static bool createTable( DBConnection dbConnection );
67
    static bool createTriggers( DBConnection dbConnection );
68
    static bool createDefaultArtists( DBConnection dbConnection );
69
    static std::shared_ptr<Artist> create( MediaLibraryPtr ml, const std::string& name );
70 71
    static std::vector<ArtistPtr> search( MediaLibraryPtr ml, const std::string& name );
    static std::vector<ArtistPtr> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
72 73

private:
74
    MediaLibraryPtr m_ml;
75
    int64_t m_id;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
76 77
    std::string m_name;
    std::string m_shortBio;
78
    std::string m_artworkMrl;
79
    unsigned int m_nbAlbums;
80
    bool m_isPresent;
81
    std::string m_mbId;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
82 83 84

    friend struct policy::ArtistTable;
};
85 86

}