Playlist.h 3.7 KB
Newer Older
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*****************************************************************************
 * 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.
 *****************************************************************************/

#pragma once

25
#include "medialibrary/IPlaylist.h"
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
26 27 28 29 30

#include "database/SqliteTools.h"
#include "database/DatabaseHelpers.h"
#include "utils/Cache.h"

31 32 33
namespace medialibrary
{

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
34
class Playlist;
35
class File;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
36 37 38 39 40 41 42

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

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

53
    static std::shared_ptr<Playlist> create( MediaLibraryPtr ml, const std::string& name );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
54

55
    virtual int64_t id() const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
56 57
    virtual const std::string& name() const override;
    virtual bool setName( const std::string& name ) override;
58
    virtual unsigned int creationDate() const override;
59
    virtual const std::string& artworkMrl() const override;
60
    virtual Query<IMedia> media() const override;
61 62
    virtual Query<IMedia> searchMedia( const std::string& pattern,
                                       const QueryParameters* params ) const override;
63 64
    virtual bool append( const IMedia& media ) override;
    virtual bool add( const IMedia& media, unsigned int position ) override;
65 66
    virtual bool append( int64_t mediaId ) override;
    virtual bool add( const int64_t mediaId, unsigned int position ) override;
67 68
    virtual bool move( int64_t mediaId, unsigned int position ) override;
    virtual bool remove( int64_t mediaId ) override;
69 70 71
    std::shared_ptr<File> addFile( const fs::IFile& fileFs, int64_t parentFolderId,
                                   bool isFolderFsRemovable );

72 73
    static void createTable( sqlite::Connection* dbConn );
    static void createTriggers( sqlite::Connection* dbConn );
74
    static Query<IPlaylist> search( MediaLibraryPtr ml, const std::string& name,
75 76
                                    const QueryParameters* params );
    static Query<IPlaylist> listAll( MediaLibraryPtr ml, const QueryParameters* params );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
77

78 79 80 81 82
    /**
     * @brief deleteAllExternal Delete all external playlists, ie. all playlist
     *                          that were parsed from playlist files.
     * Playlist manually added by the user are untouched
     */
83
    static void clearExternalPlaylistContent( MediaLibraryPtr ml );
84

85
private:
86
    static std::string sortRequest( const QueryParameters* params );
87
    void curateNullMediaID() const;
88

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
89
private:
90
    MediaLibraryPtr m_ml;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
91

92
    int64_t m_id;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
93
    std::string m_name;
94
    int64_t m_fileId;
95
    unsigned int m_creationDate;
96
    std::string m_artworkMrl;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
97

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
98
    friend policy::PlaylistTable;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
99
};
100 101

}