Playlist.h 3.39 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
63
64
    virtual bool append( int64_t mediaId ) override;
    virtual bool add( int64_t mediaId, unsigned int position ) override;
    virtual bool move( int64_t mediaId, unsigned int position ) override;
    virtual bool remove( int64_t mediaId ) override;
65
66
67
    std::shared_ptr<File> addFile( const fs::IFile& fileFs, int64_t parentFolderId,
                                   bool isFolderFsRemovable );

68
69
    static void createTable( sqlite::Connection* dbConn );
    static void createTriggers( sqlite::Connection* dbConn );
70
    static Query<IPlaylist> search( MediaLibraryPtr ml, const std::string& name,
71
                                            SortingCriteria sort, bool desc );
72
    static Query<IPlaylist> listAll( MediaLibraryPtr ml, SortingCriteria sort, bool desc );
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
73

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

81
82
83
private:
    static std::string sortRequest( SortingCriteria sort, bool desc );

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
84
private:
85
    MediaLibraryPtr m_ml;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
86

87
    int64_t m_id;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
88
    std::string m_name;
89
    int64_t m_fileId;
90
    unsigned int m_creationDate;
91
    std::string m_artworkMrl;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
92

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
93
    friend policy::PlaylistTable;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
94
};
95
96

}