Media.h 5.04 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
25
#ifndef FILE_H
#define FILE_H

Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
26

27
28
#include <sqlite3.h>

29
#include "IMedia.h"
30
#include "File.h"
31
#include "database/DatabaseHelpers.h"
32
#include "utils/Cache.h"
33

34
class Album;
35
class Folder;
36
37
38
class ShowEpisode;
class AlbumTrack;

39
class Media;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
40
41
42

namespace policy
{
43
struct MediaTable
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
44
45
{
    static const std::string Name;
46
    static const std::string PrimaryKeyColumn;
47
    static unsigned int Media::*const PrimaryKey;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
48
49
50
};
}

51
class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
52
53
{
    public:
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
54
55
56
57
        // Those should be private, however the standard states that the expression
        // ::new (pv) T(std::forward(args)...)
        // shall be well-formed, and private constructor would prevent that.
        // There might be a way with a user-defined allocator, but we'll see that later...
58
        Media( DBConnection dbConnection , sqlite::Row& row );
59
        Media( const std::string &title, Type type);
60

61
        static std::shared_ptr<Media> create( DBConnection dbConnection, Type type, const fs::IFile* file );
62
        static bool createTable( DBConnection connection );
63
        static bool createTriggers( DBConnection connection );
64

65
        virtual unsigned int id() const override;
66
        virtual Type type() override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
67
        virtual SubType subType() const override;
68
        void setType( Type type );
69
        virtual const std::string& title() const override;
70
        void setTitle( const std::string& title );
71
72
        virtual AlbumTrackPtr albumTrack() const override;
        void setAlbumTrack( AlbumTrackPtr albumTrack );
73
        virtual int64_t duration() const override;
74
        void setDuration( int64_t duration);
75
76
        virtual ShowEpisodePtr showEpisode() const override;
        void setShowEpisode( ShowEpisodePtr episode );
77
78
        virtual bool addLabel( LabelPtr label ) override;
        virtual bool removeLabel( LabelPtr label ) override;
79
        virtual std::vector<LabelPtr> labels() override;
80
        virtual int playCount() const  override;
81
        virtual void increasePlayCount() override;
82
83
84
85
        virtual float progress() const override;
        virtual void setProgress( float progress ) override;
        virtual int rating() const override;
        virtual void setRating( int rating ) override;
86
        virtual const std::vector<FilePtr>& files() const override;
87
        virtual MoviePtr movie() const override;
88
        void setMovie( MoviePtr movie );
89
        bool addVideoTrack( const std::string& codec, unsigned int width,
90
                                    unsigned int height, float fps );
91
        virtual std::vector<VideoTrackPtr> videoTracks() override;
92
93
        bool addAudioTrack(const std::string& codec, unsigned int bitrate, unsigned int sampleRate,
                           unsigned int nbChannels, const std::string& language, const std::string& desc );
94
        virtual std::vector<AudioTrackPtr> audioTracks() override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
95
        virtual const std::string& thumbnail() override;
96
        virtual unsigned int insertionDate() const override;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
97
        void setThumbnail( const std::string& thumbnail );
98
        bool save();
99

100
        std::shared_ptr<File> addFile(const fs::IFile& fileFs, Folder& parentFolder, fs::IDirectory& parentFolderFs , IFile::Type type);
101
        void removeFile( File& file );
102

103
104
105
106
        static std::vector<MediaPtr> search( DBConnection dbConn, const std::string& title );


private:
107
        DBConnection m_dbConnection;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
108

109
110
111
        // DB fields:
        unsigned int m_id;
        Type m_type;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
112
        SubType m_subType;
113
        int64_t m_duration;
114
        unsigned int m_playCount;
115
116
        float m_progress;
        int m_rating;
117
        unsigned int m_insertionDate;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
118
        std::string m_thumbnail;
119
        std::string m_title;
120
121

        // Auto fetched related properties
122
123
124
        mutable Cache<AlbumTrackPtr> m_albumTrack;
        mutable Cache<ShowEpisodePtr> m_showEpisode;
        mutable Cache<MoviePtr> m_movie;
125
        mutable Cache<std::vector<FilePtr>> m_files;
126
        bool m_changed;
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
127

128
        friend struct policy::MediaTable;
129
130
131
};

#endif // FILE_H