Commit f44f6ae3 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Remove IFolder interface

There is no point in exposing directories to the outside world
parent eef512c2
/*****************************************************************************
* 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 <vector>
class IFolder
{
public:
virtual ~IFolder() = default;
virtual unsigned int id() const = 0;
virtual const std::string& path() const = 0;
// This will only returns the files in this immediate folder
virtual std::vector<MediaPtr> files() = 0;
virtual std::vector<FolderPtr> folders() = 0;
virtual unsigned int lastModificationDate() = 0;
virtual FolderPtr parent() = 0;
};
......@@ -90,9 +90,6 @@ class IMediaLibrary
*/
virtual void setFsFactory( std::shared_ptr<factory::IFileSystem> fsFactory ) = 0;
/// Adds a folder and all the files it contains
virtual FolderPtr folder( const std::string& path ) = 0;
virtual LabelPtr createLabel( const std::string& label ) = 0;
virtual bool deleteLabel( LabelPtr label ) = 0;
virtual std::vector<MediaPtr> audioFiles() = 0;
......
......@@ -42,7 +42,6 @@ class IArtist;
class SqliteConnection;
typedef std::shared_ptr<IMedia> MediaPtr;
typedef std::shared_ptr<IFolder> FolderPtr;
typedef std::shared_ptr<ILabel> LabelPtr;
typedef std::shared_ptr<IAlbum> AlbumPtr;
typedef std::shared_ptr<IAlbumTrack> AlbumTrackPtr;
......
......@@ -23,7 +23,6 @@ list(APPEND HEADERS_LIST
${CMAKE_SOURCE_DIR}/include/IAlbum.h
${CMAKE_SOURCE_DIR}/include/IAlbumTrack.h
${CMAKE_SOURCE_DIR}/include/IMedia.h
${CMAKE_SOURCE_DIR}/include/IFolder.h
${CMAKE_SOURCE_DIR}/include/IMediaLibrary.h
${CMAKE_SOURCE_DIR}/include/ILabel.h
${CMAKE_SOURCE_DIR}/include/IAudioTrack.h
......
......@@ -124,14 +124,14 @@ std::vector<MediaPtr> Folder::files()
return Media::fetchAll<IMedia>( m_dbConection, req, m_id );
}
std::vector<FolderPtr> Folder::folders()
std::vector<std::shared_ptr<Folder> > Folder::folders()
{
static const std::string req = "SELECT * FROM " + policy::FolderTable::Name +
" WHERE id_parent = ? AND is_blacklisted IS NULL";
return fetchAll<IFolder>( m_dbConection, req, m_id );
return fetchAll<Folder>( m_dbConection, req, m_id );
}
FolderPtr Folder::parent()
std::shared_ptr<Folder> Folder::parent()
{
return fetch( m_dbConection, m_parent );
}
......
......@@ -23,7 +23,6 @@
#pragma once
#include "database/DatabaseHelpers.h"
#include "IFolder.h"
#include <sqlite3.h>
......@@ -46,7 +45,7 @@ struct FolderTable
}
class Folder : public IFolder, public DatabaseHelpers<Folder, policy::FolderTable>
class Folder : public DatabaseHelpers<Folder, policy::FolderTable>
{
public:
Folder( DBConnection dbConnection, sqlite::Row& row );
......@@ -58,12 +57,12 @@ public:
static std::shared_ptr<Folder> fromPath( DBConnection conn, const std::string& path );
virtual unsigned int id() const override;
virtual const std::string& path() const override;
virtual std::vector<MediaPtr> files() override;
virtual std::vector<FolderPtr> folders() override;
virtual FolderPtr parent() override;
virtual unsigned int lastModificationDate() override;
unsigned int id() const;
const std::string& path() const;
std::vector<MediaPtr> files();
std::vector<std::shared_ptr<Folder>> folders();
std::shared_ptr<Folder> parent();
unsigned int lastModificationDate();
bool setLastModificationDate(unsigned int lastModificationDate);
unsigned int deviceId() const;
bool isPresent() const;
......
......@@ -231,7 +231,7 @@ std::shared_ptr<Media> MediaLibrary::addFile( const std::string& path, Folder* p
return fptr;
}
FolderPtr MediaLibrary::folder( const std::string& path )
std::shared_ptr<Folder> MediaLibrary::folder( const std::string& path )
{
return Folder::fromPath( m_dbConnection.get(), path );
}
......@@ -241,7 +241,7 @@ bool MediaLibrary::deleteFile( const Media* file )
return Media::destroy( m_dbConnection.get(), file->id() );
}
bool MediaLibrary::deleteFolder( FolderPtr folder )
bool MediaLibrary::deleteFolder( const Folder* folder )
{
if ( Folder::destroy( m_dbConnection.get(), folder->id() ) == false )
return false;
......
......@@ -57,8 +57,8 @@ class MediaLibrary : public IMediaLibrary
std::shared_ptr<Media> addFile(const std::string& path, Folder* parentFolder);
virtual bool deleteFile(const Media* file );
virtual FolderPtr folder( const std::string& path ) override;
bool deleteFolder( FolderPtr folder );
std::shared_ptr<Folder> folder( const std::string& path );
bool deleteFolder( const Folder* folder );
std::shared_ptr<Device> device( const std::string& uuid );
std::shared_ptr<Device> addDevice( const std::string& uuid, bool isRemovable );
......
......@@ -83,7 +83,7 @@ void FsDiscoverer::reload()
if ( folder == nullptr )
{
LOG_INFO( "Removing folder ", f->path() );
m_ml->deleteFolder( f );
m_ml->deleteFolder( f.get() );
continue;
}
if ( folder->lastModificationDate() == f->lastModificationDate() )
......@@ -137,7 +137,7 @@ bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, Folder* parentFolder
if ( subFolder == nullptr )
continue;
auto it = std::find_if( begin( subFoldersInDB ), end( subFoldersInDB ), [subFolderPath](const std::shared_ptr<IFolder>& f) {
auto it = std::find_if( begin( subFoldersInDB ), end( subFoldersInDB ), [subFolderPath](const std::shared_ptr<Folder>& f) {
return f->path() == subFolderPath;
});
// We don't know this folder, it's a new one
......@@ -177,7 +177,7 @@ bool FsDiscoverer::checkSubfolders( fs::IDirectory* folder, Folder* parentFolder
for ( auto f : subFoldersInDB )
{
LOG_INFO( "Folder ", f->path(), " not found in FS, deleting it" );
m_ml->deleteFolder( f );
m_ml->deleteFolder( f.get() );
}
return true;
}
......
......@@ -23,7 +23,7 @@
#include "Tests.h"
#include "Media.h"
#include "IFolder.h"
#include "Folder.h"
#include "IMediaLibrary.h"
#include "utils/Filename.h"
#include "mocks/FileSystem.h"
......@@ -84,7 +84,7 @@ TEST_F( Folders, Delete )
auto filePath = files[0]->mrl();
ml->deleteFolder( f );
ml->deleteFolder( f.get() );
f = ml->folder( folderPath );
ASSERT_EQ( nullptr, f );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment