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

Library: Use medialibrary's ID to uniquely identify a media

MRL can't be assumed to be constant over time, while the media library
will recognize a media that changes location (in some conditions) and
keep the same ID assigned to it
parent 0b2fe49e
......@@ -94,11 +94,9 @@ void
Library::addMedia( Media* media )
{
setCleanState( false );
if ( m_media.contains( media->mrl() ) )
if ( m_media.contains( media->id() ) )
return;
//FIXME: This doesn't play well with a mountpoint change, we'd rather use the ML's media ID
// or an UUID that maps 1:1 to the ML media ID
m_media[media->mrl()] = media;
m_media[media->id()] = media;
}
bool
......@@ -115,7 +113,6 @@ Library::addClip( Clip *clip )
}
}
setCleanState( false );
m_media[clip->media()->mrl()] = clip->media();
return true;
}
......@@ -126,9 +123,9 @@ Library::isInCleanState() const
}
Media*
Library::media(const QString& mrl)
Library::media( qint64 mediaId )
{
return m_media.value( mrl );
return m_media.value( mediaId );
}
Clip*
......
......@@ -53,7 +53,7 @@ public:
virtual void addMedia( Media* media );
virtual bool addClip( Clip *clip );
bool isInCleanState() const;
Media* media( const QString& mrl );
Media* media( qint64 mediaId );
/**
* @brief clip returns an existing clip
* @param uuid the clip's UUID
......@@ -71,7 +71,7 @@ private:
bool m_cleanState;
Settings* m_settings;
QHash<QString, Media*> m_media;
QHash<qint64, Media*> m_media;
/**
* @brief m_clips contains all the clips loaded in the library, without any
* subclip hierarchy
......
......@@ -341,8 +341,8 @@ Clip::fromVariant( const QVariant& v )
return nullptr;
}
auto mediaMrl = m["media"].toString();
if ( mediaMrl.isEmpty() == true )
auto mediaId = m["media"].toLongLong();
if ( mediaId == 0 )
{
vlmcWarning() << "Refusing to load an invalid root clip with no base media";
return nullptr;
......@@ -355,7 +355,7 @@ Clip::fromVariant( const QVariant& v )
return nullptr;
}
auto media = Core::instance()->library()->media( mediaMrl );
auto media = Core::instance()->library()->media( mediaId );
auto clip = new Clip( media, 0, -1, uuid );
clip->loadVariant( m );
......
......@@ -109,6 +109,12 @@ Media::title() const
return QString::fromStdString( m_mlMedia->title() );
}
qint64
Media::id() const
{
return m_mlMedia->id();
}
void
Media::setBaseClip( Clip *clip )
{
......
......@@ -86,6 +86,7 @@ public:
QString mrl() const;
FileType fileType() const;
QString title() const;
qint64 id() const;
Clip* baseClip() { return m_baseClip; }
const Clip* baseClip() const { return m_baseClip; }
......
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