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

Remove MediaContainer class

parent 2b5ace6a
......@@ -19,7 +19,6 @@ vlmc_SOURCES = \
src/Library/Library.cpp \
src/Library/MediaLibrary.cpp \
src/Library/MediaLibraryModel.cpp \
src/Library/MediaContainer.cpp \
src/Main/Core.cpp \
src/Main/main.cpp \
src/Media/Clip.cpp \
......@@ -93,7 +92,6 @@ vlmc_SOURCES += \
src/Backend/IMultiTrack.h \
src/Main/Core.h \
src/Library/Library.h \
src/Library/MediaContainer.h \
src/Library/MediaLibrary.h \
src/Library/MediaLibraryModel.h \
src/Workflow/Helper.h \
......@@ -120,7 +118,6 @@ nodist_vlmc_SOURCES = \
src/Services/AbstractSharingService.moc.cpp \
src/Workflow/MainWorkflow.moc.cpp \
src/Project/RecentProjects.moc.cpp \
src/Library/MediaContainer.moc.cpp \
src/Commands/Commands.moc.cpp \
src/Renderer/ClipRenderer.moc.cpp \
src/Project/Project.moc.cpp \
......
/*****************************************************************************
* MediaContainer.cpp: Implements the library basics
*****************************************************************************
* Copyright (C) 2008-2016 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <QHash>
#include <QUuid>
#include "Library.h"
#include "MediaContainer.h"
#include "Media/Clip.h"
#include "Media/Media.h"
#include "EffectsEngine/EffectHelper.h"
#include "Settings/Settings.h"
#include "Tools/VlmcDebug.h"
#include "Project/Workspace.h"
MediaContainer::MediaContainer( Clip* parent /*= nullptr*/ ) : m_parent( parent )
{
}
MediaContainer::~MediaContainer()
{
foreach ( Clip* c, m_clips.values() )
delete c;
m_clips.clear();
}
Clip*
MediaContainer::clip( const QUuid& uuid )
{
return clip( uuid.toString() );
}
Clip*
MediaContainer::clip( const QString &uuid )
{
for ( const auto& clip : m_clips )
if ( clip->uuid().toString() == uuid )
return clip;
else
{
auto c = clip->mediaContainer()->clip( uuid );
if ( c != nullptr )
return c;
}
return nullptr;
}
void
MediaContainer::addMedia( Media *media )
{
m_clips[media->baseClip()->uuid()] = media->baseClip();
emit newClipLoaded( media->baseClip() );
}
Media*
MediaContainer::addMedia( const QFileInfo& fileInfo )
{
if ( QFile::exists( fileInfo.absoluteFilePath() ) == false )
{
vlmcCritical() << "Can't add" << fileInfo.absoluteFilePath() << ": File not found";
return nullptr;
}
foreach( Clip* it, m_clips.values() )
{
if ( (*it->media()->fileInfo()) == fileInfo )
{
vlmcWarning() << "Ignoring aleady imported media" << fileInfo.absolutePath();
return nullptr;
}
}
Media* media = new Media( fileInfo.filePath() );
return media;
}
bool
MediaContainer::mediaAlreadyLoaded( const QFileInfo& fileInfo )
{
foreach( Clip* clip, m_clips.values() )
{
if ( clip->media()->fileInfo()->filePath() == fileInfo.filePath() )
return true;
}
return false;
}
bool
MediaContainer::addClip( Clip* clip )
{
foreach ( Clip* c, m_clips.values() )
{
if ( clip->uuid() == c->uuid() ||
( clip->media()->fileInfo() == c->media()->fileInfo() &&
( clip->begin() == c->begin() && clip->end() == c->end() ) ) )
{
vlmcWarning() << "Clip already loaded.";
return false;
}
}
m_clips[clip->uuid()] = clip;
emit newClipLoaded( clip );
return true;
}
void
MediaContainer::clear()
{
QHash<QUuid, Clip*>::iterator it = m_clips.begin();
QHash<QUuid, Clip*>::iterator end = m_clips.end();
while ( it != end )
{
emit clipRemoved( it.key() );
it.value()->clear();
it.value()->deleteLater();
++it;
}
m_clips.clear();
}
void
MediaContainer::removeAll()
{
QHash<QUuid, Clip*>::iterator it = m_clips.begin();
QHash<QUuid, Clip*>::iterator end = m_clips.end();
while ( it != end )
{
emit clipRemoved( it.key() );
++it;
}
m_clips.clear();
}
void
MediaContainer::deleteClip( const QUuid &uuid )
{
QHash<QUuid, Clip*>::iterator it = m_clips.find( uuid );
if ( it != m_clips.end() )
{
Clip* clip = it.value();
m_clips.remove( uuid );
emit clipRemoved( uuid );
// don't use delete as the clip may be used in the slot that'll handle clipRemoved signal.
clip->deleteLater();
}
}
const QHash<QUuid, Clip*>&
MediaContainer::clips() const
{
return m_clips;
}
void
MediaContainer::reloadAllClips()
{
for ( auto *c: m_clips )
emit newClipLoaded( c );
}
Clip*
MediaContainer::getParent()
{
return m_parent;
}
quint32
MediaContainer::count() const
{
return m_clips.size();
}
/*****************************************************************************
* MediaContainer.h: Implements the library basics
*****************************************************************************
* Copyright (C) 2008-2016 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 General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU 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.
*****************************************************************************/
#ifndef MEDIACONTAINER_H
#define MEDIACONTAINER_H
#include <QHash>
#include <QObject>
#include <QUuid>
class Media;
class Clip;
class QFileInfo;
class MediaContainer : public QObject
{
Q_OBJECT
public:
MediaContainer( Clip* parent = nullptr );
~MediaContainer();
/**
* \brief returns the clip that match the unique identifier
* \param uuid the unique identifier of the media
* \return a pointer to the required clip, or nullptr if no clips matches
*/
Clip* clip( const QUuid& uuid );
/**
* \brief returns the clip that match the unique identifier
*
* The identifier may be a full id (ie the full path, starting at the root clip)
* \param uuid the unique identifier of the media
* \return a pointer to the required clip, or nullptr if no clips matches
*/
Clip* clip( const QString& uuid );
/**
* \brief Add an already preparsed media.
*
* This will emit the newClipLoaded signal.
*
* \param media The media to add to the library
*/
virtual void addMedia( Media *media );
/**
* \brief Add a file to the media library
*
* This method will also handle metadata parsing.
* \param fileInfo the file info of the media
* \return The newly create media if the media was successfully loaded.
* nullptr otherwise.
* \sa addClip( Clip* clip )
* \sa media( const QUuid& uuid)
* \sa clip( const QUuid& uuid )
*/
virtual Media *addMedia( const QFileInfo& fileInfo );
/**
* \brief Check if a file has already been loaded into library.
* \param fileInfo The file infos
* \return true if the file is already loaded, false otherwhise
*/
bool mediaAlreadyLoaded( const QFileInfo& fileInfo );
/**
* \brief Add a clip.
*
* The method will first check for an identic clip existence.
* This will emit the newClipLoaded signal if the Clip is added.
*
* \param clip The clip to be added.
* \return true if the Clip has been added.
*/
virtual bool addClip( Clip* clip );
/**
* \return All the loaded Clip
*/
const QHash<QUuid, Clip*> &clips() const;
/**
* \breif Emit newClipLoaded from all clips
*/
void reloadAllClips();
Clip* getParent();
quint32 count() const;
protected:
/**
* \brief The List of medias loaded into the library
*/
QHash<QUuid, Clip*> m_clips;
/**
* \brief Used when loading a project.
*
* This should not have an associated getter.
*/
QHash<QString, Media*> m_medias;
Clip* m_parent;
public slots:
/**
* \brief Removes a Clip from the container and delete it
*
* \param uuid The clip to remove's uuid.
*/
void deleteClip( const QUuid& uuid );
/**
* \brief Clear the library (remove all the loaded Clip, delete their subclips, and
* delete them)
*/
void clear();
/**
* \brief Remove all the medias from the container, but doesn't clean nor
* delete them.
*/
void removeAll();
signals:
/**
* \brief This signal should be emitted to tell a new Clip have been added
* \param Clip The newly added clip
*/
void newClipLoaded( Clip* );
/**
* \brief This signal should be emiteted when a Clip has been removed
* This signal pass a QUuid as the clip may be deleted when the signal reaches its
* slot.
* \param uuid The removed clip uuid
*/
void clipRemoved( const QUuid& );
};
#endif // MEDIACONTAINER_H
......@@ -53,7 +53,6 @@ class IInput;
}
class Settings;
class MediaContainer;
#include <QObject>
#include <QUuid>
......
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