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

Media: Wrap a medialibrary Media instead of a QFileInfo

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