Folder.h 2.73 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
#pragma once

25
#include "database/DatabaseHelpers.h"
26 27 28 29 30
#include "IFolder.h"

#include <sqlite3.h>

class Folder;
31
class Device;
32

33 34 35 36 37
namespace fs
{
    class IDirectory;
}

38 39 40 41 42
namespace policy
{
struct FolderTable
{
    static const std::string Name;
43
    static const std::string PrimaryKeyColumn;
44 45
    static unsigned int Folder::*const PrimaryKey;
};
46

47 48
}

49
class Folder : public IFolder, public DatabaseHelpers<Folder, policy::FolderTable>
50 51
{
public:
52
    Folder( DBConnection dbConnection, sqlite::Row& row );
53
    Folder(const std::string& path, time_t lastModificationDate, unsigned int parent , unsigned int deviceId);
54 55

    static bool createTable( DBConnection connection );
56
    static std::shared_ptr<Folder> create(DBConnection connection, const std::string& path, time_t lastModificationDate, unsigned int parentId, Device& device );
57
    static bool blacklist( DBConnection connection, const std::string& path );
58

59 60
    static std::shared_ptr<Folder> fromPath( DBConnection conn, const std::string& path );

61
    virtual unsigned int id() const override;
62
    virtual const std::string& path() const override;
63
    virtual std::vector<MediaPtr> files() override;
64
    virtual std::vector<FolderPtr> folders() override;
65
    virtual FolderPtr parent() override;
66
    virtual unsigned int lastModificationDate() override;
67
    bool setLastModificationDate(unsigned int lastModificationDate);
68
    unsigned int deviceId() const;
69 70 71 72 73 74

private:
    DBConnection m_dbConection;

    unsigned int m_id;
    std::string m_path;
75
    unsigned int m_parent;
76
    unsigned int m_lastModificationDate;
77
    bool m_isBlacklisted;
78
    unsigned int m_deviceId;
79
    bool m_isPresent;
80

81
    friend struct policy::FolderTable;
82
};