Artist.h 2.88 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"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
26 27 28 29
#include "IArtist.h"
#include "IMediaLibrary.h"

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

namespace policy
{
struct ArtistTable
{
    static const std::string Name;
38
    static const std::string PrimaryKeyColumn;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
39 40 41 42
    static unsigned int Artist::*const PrimaryKey;
};
}

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

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

    static bool createTable( DBConnection dbConnection );
64
    static bool createTriggers( DBConnection dbConnection );
65
    static bool createDefaultArtists( DBConnection dbConnection );
66 67
    static std::shared_ptr<Artist> create( MediaLibraryPtr ml, const std::string& name );
    static std::vector<ArtistPtr> search( MediaLibraryPtr ml, const std::string& name );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
68 69

private:
70
    MediaLibraryPtr m_ml;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
71 72 73
    unsigned int m_id;
    std::string m_name;
    std::string m_shortBio;
74
    std::string m_artworkMrl;
75
    unsigned int m_nbAlbums;
76
    bool m_isPresent;
77
    std::string m_mbId;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
78 79 80

    friend struct policy::ArtistTable;
};