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

Library: Use QSharedPointer to store Media

parent c169ff5f
......@@ -72,7 +72,7 @@ TagWidget::clipSelected( Clip* clip )
else
static_cast<QPushButton*>(m_buttonList[i])->setChecked( false );
}
connect( clip->media(), SIGNAL( metaDataComputed( const Media* ) ),
connect( clip->media().data(), SIGNAL( metaDataComputed( const Media* ) ),
this, SLOT( setMetaTags() ) );
connect( clip, SIGNAL( destroyed() ), this, SLOT( clipDestroyed() ) );
}
......
......@@ -96,7 +96,7 @@ void
ClipMetadataDisplayer::setWatchedClip( const Clip *clip )
{
if ( m_watchedMedia )
disconnect( m_watchedMedia );
disconnect( m_watchedMedia.data() );
if ( m_watchedClip )
disconnect( m_watchedClip );
......
......@@ -51,7 +51,7 @@ class ClipMetadataDisplayer : public QWidget
private:
Ui::ClipMetadataDisplayer *m_ui;
const Clip *m_watchedClip;
const Media *m_watchedMedia;
QSharedPointer<const Media> m_watchedMedia;
private slots:
void metadataUpdated();
......
......@@ -91,7 +91,7 @@ Library::~Library()
}
void
Library::addMedia( Media* media )
Library::addMedia( QSharedPointer<Media> media )
{
setCleanState( false );
if ( m_media.contains( media->id() ) )
......@@ -122,7 +122,7 @@ Library::isInCleanState() const
return m_cleanState;
}
Media*
QSharedPointer<Media>
Library::media( qint64 mediaId )
{
return m_media.value( mediaId );
......
......@@ -32,6 +32,7 @@
#include <QObject>
#include <QHash>
#include <QSharedPointer>
class Clip;
class Media;
......@@ -50,10 +51,10 @@ class Library : public QObject
public:
Library( Settings* projectSettings );
virtual ~Library();
virtual void addMedia( Media* media );
virtual void addMedia( QSharedPointer<Media> media );
virtual bool addClip( Clip *clip );
bool isInCleanState() const;
Media* media( qint64 mediaId );
QSharedPointer<Media> media( qint64 mediaId );
/**
* @brief clip returns an existing clip
* @param uuid the clip's UUID
......@@ -71,7 +72,7 @@ private:
bool m_cleanState;
Settings* m_settings;
QHash<qint64, Media*> m_media;
QHash<qint64, QSharedPointer<Media>> m_media;
/**
* @brief m_clips contains all the clips loaded in the library, without any
* subclip hierarchy
......
......@@ -39,7 +39,7 @@
#include "Tools/VlmcDebug.h"
#include <QVariant>
Clip::Clip( Media *media, qint64 begin /*= 0*/, qint64 end /*= Backend::IInput::EndOfMedia */, const QString& uuid /*= QString()*/ ) :
Clip::Clip( QSharedPointer<Media> media, qint64 begin /*= 0*/, qint64 end /*= Backend::IInput::EndOfMedia */, const QString& uuid /*= QString()*/ ) :
Workflow::Helper( uuid ),
m_media( media ),
m_input( std::move( m_media->input()->cut( begin, end ) ) ),
......@@ -78,17 +78,15 @@ Clip::Clip( Clip *parent, qint64 begin /*= -1*/, qint64 end /*= -2*/,
Clip::~Clip()
{
emit unloaded( this );
if ( isRootClip() == true )
delete m_media;
}
Media*
QSharedPointer<Media>
Clip::media()
{
return m_media;
}
const Media*
QSharedPointer<const Media>
Clip::media() const
{
return m_media;
......
......@@ -31,6 +31,7 @@
#include "Workflow/Helper.h"
#include <QHash>
#include <QSharedPointer>
#include <QStringList>
#include <QUuid>
#include <QXmlStreamWriter>
......@@ -63,7 +64,7 @@ class Clip : public Workflow::Helper
* the end of the parent will be used.
* \param uuid A unique identifier. If not given, one will be generated.
*/
Clip( Media *parent, qint64 begin = 0, qint64 end = Backend::IInput::EndOfMedia, const QString &uuid = QStringLiteral() );
Clip( QSharedPointer<Media> parent, qint64 begin = 0, qint64 end = Backend::IInput::EndOfMedia, const QString &uuid = QStringLiteral() );
/**
* \brief Clones a Clip, potentially with a new begin and end.
*
......@@ -84,8 +85,8 @@ class Clip : public Workflow::Helper
/**
\return Returns the Media that the clip was basep uppon.
*/
Media* media();
const Media* media() const;
QSharedPointer<Media> media();
QSharedPointer<const Media> media() const;
Clip *parent();
const Clip *parent() const;
......@@ -151,8 +152,8 @@ class Clip : public Workflow::Helper
void loadVariant(const QVariantMap& v );
private:
Media* m_media;
std::unique_ptr<Backend::IInput> m_input;
QSharedPointer<Media> m_media;
std::unique_ptr<Backend::IInput> m_input;
QStringList m_metaTags;
QString m_notes;
......
......@@ -140,14 +140,16 @@ Media::input() const
return m_input.get();
}
Media* Media::fromVariant( const QVariant& v )
QSharedPointer<Media>
Media::fromVariant( const QVariant& v )
{
bool ok = false;
auto mediaId = v.toLongLong( &ok );
if ( ok == false )
return nullptr;
return QSharedPointer<Media>{};
auto mlMedia = Core::instance()->mediaLibrary()->media( mediaId );
return new Media( mlMedia );
//FIXME: Is QSharedPointer exception safe in case its constructor throws an exception?
return QSharedPointer<Media>( new Media( mlMedia ) );
}
#ifdef HAVE_GUI
......
......@@ -97,7 +97,7 @@ public:
Backend::IInput* input();
const Backend::IInput* input() const;
static Media* fromVariant( const QVariant& v );
static QSharedPointer<Media> fromVariant( const QVariant& v );
#ifdef HAVE_GUI
// This has to be called from the GUI thread.
......
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