Commit d3dcb03d authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Media: Wrap a medialibrary Media instead of a QFileInfo

parent 7ed6d983
...@@ -45,7 +45,7 @@ ClipProperty::ClipProperty( Clip* clip, QWidget *parent ) : ...@@ -45,7 +45,7 @@ ClipProperty::ClipProperty( Clip* clip, QWidget *parent ) :
connect( this, SIGNAL( accepted() ), this, SLOT( deleteLater() ) ); connect( this, SIGNAL( accepted() ), this, SLOT( deleteLater() ) );
connect( this, SIGNAL( rejected() ), this, SLOT( deleteLater() ) ); connect( this, SIGNAL( rejected() ), this, SLOT( deleteLater() ) );
setWindowTitle( m_clip->media()->fileInfo()->fileName() + " " + tr( "properties" ) ); setWindowTitle( m_clip->media()->title() + " " + tr( "properties" ) );
//Snapshot //Snapshot
ui->snapshotLabel->setPixmap( m_clip->media()->snapshot().scaled( 128, 128, Qt::KeepAspectRatio ) ); ui->snapshotLabel->setPixmap( m_clip->media()->snapshot().scaled( 128, 128, Qt::KeepAspectRatio ) );
//Metatags //Metatags
......
...@@ -55,7 +55,7 @@ ClipMetadataDisplayer::metadataUpdated() ...@@ -55,7 +55,7 @@ ClipMetadataDisplayer::metadataUpdated()
//Duration //Duration
m_ui->durationValueLabel->setText( duration.toString( "hh:mm:ss" ) ); m_ui->durationValueLabel->setText( duration.toString( "hh:mm:ss" ) );
//Filename || title //Filename || title
m_ui->nameValueLabel->setText( m_watchedMedia->fileInfo()->fileName() ); m_ui->nameValueLabel->setText( m_watchedMedia->title() );
//Resolution //Resolution
m_ui->resolutionValueLabel->setText( QString::number( input->width() ) m_ui->resolutionValueLabel->setText( QString::number( input->width() )
+ " x " + QString::number( input->height() ) ); + " x " + QString::number( input->height() ) );
...@@ -65,7 +65,7 @@ ClipMetadataDisplayer::metadataUpdated() ...@@ -65,7 +65,7 @@ ClipMetadataDisplayer::metadataUpdated()
m_ui->nbVideoTracksValueLabel->setText( QString::number( input->nbVideoTracks() ) ); m_ui->nbVideoTracksValueLabel->setText( QString::number( input->nbVideoTracks() ) );
m_ui->nbAudioTracksValueLabel->setText( QString::number( input->nbAudioTracks() ) ); m_ui->nbAudioTracksValueLabel->setText( QString::number( input->nbAudioTracks() ) );
//Path: //Path:
m_ui->pathValueLabel->setText( m_watchedMedia->fileInfo()->absoluteFilePath() ); m_ui->pathValueLabel->setText( m_watchedMedia->mrl() );
} }
void void
......
...@@ -94,9 +94,11 @@ void ...@@ -94,9 +94,11 @@ void
Library::addMedia( Media* media ) Library::addMedia( Media* media )
{ {
setCleanState( false ); setCleanState( false );
if ( m_media.contains( media->fileInfo()->absoluteFilePath() ) ) if ( m_media.contains( media->mrl() ) )
return; return;
m_media[media->fileInfo()->absoluteFilePath()] = media; //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;
} }
bool bool
...@@ -105,7 +107,7 @@ Library::addClip( Clip *clip ) ...@@ -105,7 +107,7 @@ Library::addClip( Clip *clip )
foreach ( Clip* c, m_clips.values() ) foreach ( Clip* c, m_clips.values() )
{ {
if ( clip->uuid() == c->uuid() || if ( clip->uuid() == c->uuid() ||
( clip->media()->fileInfo() == c->media()->fileInfo() && ( clip->media()->mrl() == c->media()->mrl() &&
( clip->begin() == c->begin() && clip->end() == c->end() ) ) ) ( clip->begin() == c->begin() && clip->end() == c->end() ) ) )
{ {
vlmcWarning() << "Clip already loaded."; vlmcWarning() << "Clip already loaded.";
...@@ -113,7 +115,7 @@ Library::addClip( Clip *clip ) ...@@ -113,7 +115,7 @@ Library::addClip( Clip *clip )
} }
} }
setCleanState( false ); setCleanState( false );
m_media[clip->media()->fileInfo()->absoluteFilePath()] = clip->media(); m_media[clip->media()->mrl()] = clip->media();
return true; return true;
} }
......
...@@ -50,6 +50,12 @@ MediaLibraryModel* MediaLibrary::model( MediaLibrary::MediaType type ) const ...@@ -50,6 +50,12 @@ MediaLibraryModel* MediaLibrary::model( MediaLibrary::MediaType type ) const
Q_UNREACHABLE(); Q_UNREACHABLE();
} }
medialibrary::MediaPtr
MediaLibrary::media( qint64 mediaId ) const
{
return m_ml->media( mediaId );
}
void void
MediaLibrary::mlDirsChanged( const QVariant& value ) MediaLibrary::mlDirsChanged( const QVariant& value )
{ {
......
...@@ -46,6 +46,7 @@ public: ...@@ -46,6 +46,7 @@ public:
explicit MediaLibrary( Settings* settings ); explicit MediaLibrary( Settings* settings );
MediaLibraryModel* model( MediaType type ) const; MediaLibraryModel* model( MediaType type ) const;
medialibrary::MediaPtr media( qint64 mediaId ) const;
signals: signals:
void progressUpdated( int percent ); void progressUpdated( int percent );
......
...@@ -33,16 +33,16 @@ ...@@ -33,16 +33,16 @@
#include <QUrl> #include <QUrl>
#include <QVariant> #include <QVariant>
#include <QFileInfo>
#include "Media.h" #include "Media.h"
#include "Clip.h" #include "Clip.h"
#include "Main/Core.h" #include "Main/Core.h"
#include "Library/Library.h" #include "Library/Library.h"
#include "Library/MediaLibrary.h"
#include "Tools/VlmcDebug.h" #include "Tools/VlmcDebug.h"
#include "Project/Workspace.h" #include "Project/Workspace.h"
#include "Backend/MLT/MLTInput.h"
const QString Media::VideoExtensions = "*.avi *.3gp *.amv *.asf *.divx *.dv *.flv *.gxf " const QString Media::VideoExtensions = "*.avi *.3gp *.amv *.asf *.divx *.dv *.flv *.gxf "
"*.iso *.m1v *.m2v *.m2t *.m2ts *.m4v *.mkv *.mov " "*.iso *.m1v *.m2v *.m2t *.m2ts *.m4v *.mkv *.mov "
...@@ -63,40 +63,50 @@ const QString Media::streamPrefix = "stream://"; ...@@ -63,40 +63,50 @@ const QString Media::streamPrefix = "stream://";
QPixmap* Media::defaultSnapshot = nullptr; QPixmap* Media::defaultSnapshot = nullptr;
#endif #endif
Media::Media(const QString &path ) Media::Media( medialibrary::MediaPtr media )
: m_input( nullptr ) : m_input( nullptr )
, m_fileInfo( nullptr ) , m_mlMedia( media )
, m_baseClip( nullptr ) , m_baseClip( nullptr )
{ {
setFilePath( path ); auto files = media->files();
} Q_ASSERT( files.size() > 0 );
for ( const auto& f : files )
Media::~Media() {
{ if ( f->type() == medialibrary::IFile::Type::Main )
delete m_fileInfo; {
m_mlFile = f;
break;
}
}
if ( m_mlFile == nullptr )
vlmcCritical() << "No file representing media", media->title(), "was found";
} }
const QFileInfo* QString
Media::fileInfo() const Media::mrl() const
{ {
return m_fileInfo; return QString::fromStdString( m_mlFile->mrl() );
} }
Media::FileType Media::FileType
Media::fileType() const Media::fileType() const
{ {
return m_fileType; switch ( m_mlMedia->type() )
} {
case medialibrary::IMedia::Type::VideoType:
void Media::setFileType(Media::FileType type) return Video;
{ case medialibrary::IMedia::Type::AudioType:
m_fileType = type; return Audio;
//FIXME: Unhandled Image type
default:
vlmcCritical() << "Unknown file type";
}
} }
const QString& QString
Media::fileName() const Media::title() const
{ {
return m_fileName; return QString::fromStdString( m_mlMedia->title() );
} }
void void
...@@ -109,7 +119,7 @@ Media::setBaseClip( Clip *clip ) ...@@ -109,7 +119,7 @@ Media::setBaseClip( Clip *clip )
QVariant QVariant
Media::toVariant() const Media::toVariant() const
{ {
return QVariant( m_fileInfo->absoluteFilePath() ); return QVariant( static_cast<qlonglong>( m_mlMedia->id() ) );
} }
Backend::IInput* Backend::IInput*
...@@ -126,19 +136,12 @@ Media::input() const ...@@ -126,19 +136,12 @@ Media::input() const
Media* Media::fromVariant( const QVariant& v ) Media* Media::fromVariant( const QVariant& v )
{ {
return new Media( QFileInfo( v.toString() ).absoluteFilePath() ); bool ok = false;
} auto mediaId = v.toLongLong( &ok );
if ( ok == false )
void return nullptr;
Media::setFilePath( const QString &filePath ) auto mlMedia = Core::instance()->mediaLibrary()->media( mediaId );
{ return new Media( mlMedia );
if ( m_fileInfo )
delete m_fileInfo;
m_fileInfo = new QFileInfo( filePath );
m_fileName = m_fileInfo->fileName();
m_mrl = "file:///" + QUrl::toPercentEncoding( filePath, "/" );
m_input.reset( new Backend::MLT::MLTInput( qPrintable( filePath ) ) );
} }
#ifdef HAVE_GUI #ifdef HAVE_GUI
......
...@@ -36,9 +36,13 @@ ...@@ -36,9 +36,13 @@
#include <QString> #include <QString>
#include <QObject> #include <QObject>
#include <QFileInfo>
#include <QXmlStreamWriter> #include <QXmlStreamWriter>
#include "Backend/MLT/MLTInput.h"
#include <medialibrary/IMedia.h>
#include <medialibrary/IFile.h>
#ifdef HAVE_GUI #ifdef HAVE_GUI
#include <QPixmap> #include <QPixmap>
#include <QImage> #include <QImage>
...@@ -77,20 +81,11 @@ public: ...@@ -77,20 +81,11 @@ public:
static const QString ImageExtensions; static const QString ImageExtensions;
static const QString streamPrefix; static const QString streamPrefix;
Media( const QString& path ); Media( medialibrary::MediaPtr media );
virtual ~Media();
const QFileInfo *fileInfo() const;
const QString &fileName() const;
/**
* \brief Set this media's path.
*
* \param path The media path. This should be an absolute path.
*/
void setFilePath( const QString& path );
QString mrl() const;
FileType fileType() const; FileType fileType() const;
void setFileType( FileType type ); QString title() const;
Clip* baseClip() { return m_baseClip; } Clip* baseClip() { return m_baseClip; }
const Clip* baseClip() const { return m_baseClip; } const Clip* baseClip() const { return m_baseClip; }
...@@ -109,10 +104,8 @@ public: ...@@ -109,10 +104,8 @@ public:
#endif #endif
protected: protected:
std::unique_ptr<Backend::IInput> m_input; std::unique_ptr<Backend::IInput> m_input;
QString m_mrl; medialibrary::MediaPtr m_mlMedia;
QFileInfo* m_fileInfo; medialibrary::FilePtr m_mlFile;
FileType m_fileType;
QString m_fileName;
Clip* m_baseClip; Clip* m_baseClip;
#ifdef HAVE_GUI #ifdef HAVE_GUI
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "Settings/Settings.h" #include "Settings/Settings.h"
#include "Tools/VlmcDebug.h" #include "Tools/VlmcDebug.h"
#include <QFileInfo>
const QString Workspace::workspacePrefix = "workspace://"; const QString Workspace::workspacePrefix = "workspace://";
Workspace::Workspace(Settings *settings) Workspace::Workspace(Settings *settings)
...@@ -66,5 +68,5 @@ Workspace::isInWorkspace( const QString &path ) ...@@ -66,5 +68,5 @@ Workspace::isInWorkspace( const QString &path )
bool bool
Workspace::isInWorkspace(const Media *media) Workspace::isInWorkspace(const Media *media)
{ {
return isInWorkspace( *(media->fileInfo() ) ); return isInWorkspace( media->mrl() );
} }
...@@ -50,7 +50,7 @@ WorkspaceWorker::run() ...@@ -50,7 +50,7 @@ WorkspaceWorker::run()
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
errno = 0; errno = 0;
if ( link( m_media->fileInfo()->absoluteFilePath().toUtf8().constData(), if ( link( m_media->mrl().toUtf8().constData(),
m_dest.toUtf8().constData() ) < 0 ) m_dest.toUtf8().constData() ) < 0 )
{ {
vlmcDebug() << "Can't create hard link:" << strerror(errno) << "falling back to" vlmcDebug() << "Can't create hard link:" << strerror(errno) << "falling back to"
...@@ -65,7 +65,7 @@ WorkspaceWorker::run() ...@@ -65,7 +65,7 @@ WorkspaceWorker::run()
if ( hardLinkOk == false ) if ( hardLinkOk == false )
{ {
QFile::copy( m_media->fileInfo()->absoluteFilePath(), m_dest ); QFile::copy( m_media->mrl(), m_dest );
vlmcDebug() << "Media copied to:" << m_dest; vlmcDebug() << "Media copied to:" << m_dest;
} }
emit copied( m_media, m_dest ); emit copied( m_media, m_dest );
......
...@@ -219,7 +219,7 @@ MainWorkflow::clipInfo( const QString& uuid ) ...@@ -219,7 +219,7 @@ MainWorkflow::clipInfo( const QString& uuid )
{ {
auto h = lClip->toVariant().toHash(); auto h = lClip->toVariant().toHash();
h["length"] = (qint64)( lClip->input()->length() ); h["length"] = (qint64)( lClip->input()->length() );
h["name"] = lClip->media()->fileName(); h["name"] = lClip->media()->title();
h["audio"] = lClip->formats().testFlag( Clip::Audio ); h["audio"] = lClip->formats().testFlag( Clip::Audio );
h["video"] = lClip->formats().testFlag( Clip::Video ); h["video"] = lClip->formats().testFlag( Clip::Video );
if ( lClip->isRootClip() == true ) if ( lClip->isRootClip() == true )
...@@ -236,7 +236,7 @@ MainWorkflow::clipInfo( const QString& uuid ) ...@@ -236,7 +236,7 @@ MainWorkflow::clipInfo( const QString& uuid )
auto h = clip->toVariant().toHash(); auto h = clip->toVariant().toHash();
h["length"] = (qint64)( clip->input()->length() ); h["length"] = (qint64)( clip->input()->length() );
h["name"] = clip->media()->fileName(); h["name"] = clip->media()->title();
h["audio"] = clip->formats().testFlag( Clip::Audio ); h["audio"] = clip->formats().testFlag( Clip::Audio );
h["video"] = clip->formats().testFlag( Clip::Video ); h["video"] = clip->formats().testFlag( Clip::Video );
h["position"] = m_sequenceWorkflow->position( uuid ); h["position"] = m_sequenceWorkflow->position( uuid );
...@@ -303,7 +303,7 @@ void ...@@ -303,7 +303,7 @@ void
MainWorkflow::takeThumbnail( const QString& uuid, quint32 pos ) MainWorkflow::takeThumbnail( const QString& uuid, quint32 pos )
{ {
auto clip = m_sequenceWorkflow->clip( uuid ); auto clip = m_sequenceWorkflow->clip( uuid );
auto worker = new ThumbnailWorker( uuid, clip->media()->fileInfo()->absoluteFilePath(), auto worker = new ThumbnailWorker( uuid, clip->media()->mrl(),
pos, clip->input()->width(), clip->input()->height() ); pos, clip->input()->width(), clip->input()->height() );
auto t = new QThread; auto t = new QThread;
worker->moveToThread( t ); worker->moveToThread( t );
......
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