History.h 2.14 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
/*****************************************************************************
 * 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

#include "Types.h"
#include "database/DatabaseHelpers.h"
#include "medialibrary/IHistoryEntry.h"

#include <vector>
#include <string>

namespace medialibrary
{

class History;
class Media;

namespace policy
{
struct HistoryTable
{
    static const std::string Name;
    static const std::string PrimaryKeyColumn;
    static int64_t History::* const PrimaryKey;
};
}

48
class History : public IHistoryEntry, public DatabaseHelpers<History, policy::HistoryTable, cachepolicy::Uncached<History>>
49 50 51 52
{
public:
    History( MediaLibraryPtr ml, sqlite::Row& row );
    static bool createTable( DBConnection dbConnection );
53
    static bool insert( DBConnection dbConn, int64_t mediaId );
54 55 56
    static std::vector<HistoryPtr> fetch( MediaLibraryPtr ml );
    static bool clearStreams( MediaLibraryPtr ml );

57
    virtual MediaPtr media() const override;
58 59
    virtual unsigned int insertionDate() const override;

60
    static constexpr unsigned int MaxEntries = 20u;
61 62

private:
63 64
    MediaPtr m_media;
    int64_t m_mediaId;
65 66 67 68 69 70
    unsigned int m_date;

    friend policy::HistoryTable;
};

}