Thumbnail.h 2.78 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 23 24 25 26 27 28 29 30 31
/*****************************************************************************
 * Media Library
 *****************************************************************************
 * Copyright (C) 2015-2018 Hugo Beauzée-Luyssen, Videolabs, VideoLAN
 *
 * 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

#include "database/DatabaseHelpers.h"

namespace medialibrary
{

class Thumbnail;

32 33 34
template <typename T>
class Cache;

35
class Thumbnail : public DatabaseHelpers<Thumbnail>
36 37
{
public:
38 39 40 41 42 43 44
    struct Table
    {
        static const std::string Name;
        static const std::string PrimaryKeyColumn;
        static int64_t Thumbnail::*const PrimaryKey;
    };

45 46 47 48 49 50 51 52 53 54 55 56 57 58
    enum class Origin : uint8_t
    {
        Artist,
        AlbumArtist,
        Album,
        Media,
        UserProvided,
    };

    Thumbnail( MediaLibraryPtr ml, sqlite::Row& row );
    Thumbnail( MediaLibraryPtr ml, std::string mrl, Origin origin );

    int64_t id() const;
    const std::string& mrl() const;
59
    bool update( std::string mrl, Origin origin );
60 61
    Origin origin() const;

62 63 64 65 66 67 68 69 70
    /**
     * @brief setMrlFromPrimaryKey Helper to set the thumbnail mrl based on a
     * thumbnail ID.
     * @param thumbnail The cached thumbnail entity. The value can be uncached
     * in which case it will be fetched and cached.
     * @param thumbnailId The thumbnail primary key
     */
    static bool setMrlFromPrimaryKey( MediaLibraryPtr ml,
                                      Cache<std::shared_ptr<Thumbnail>>& thumbnail,
71 72
                                      int64_t thumbnailId, std::string mrl,
                                      Origin origin );
73

74 75 76
    static void createTable( sqlite::Connection* dbConnection );
    static std::shared_ptr<Thumbnail> create( MediaLibraryPtr ml, std::string mrl,
                                              Origin origin );
77 78 79

    static const std::string EmptyMrl;

80 81 82 83 84 85
private:
    MediaLibraryPtr m_ml;
    int64_t m_id;
    std::string m_mrl;
    Origin m_origin;

86
    friend Thumbnail::Table;
87 88 89
};

}