Commit 394e27b1 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactoring: Media are now mostly changed in Clip

the MediaLibrary contains all of the media, but only gives access to the Clip, created upon the medias.
Cleaned metadata process: the clip doesn't appear inside of the mediaLibrary until the metadata process has been completed.
Removed junk/useless code
parent 02218698
......@@ -24,6 +24,8 @@
* This file contains the Clip class implementation.
*/
#include <QtDebug>
#include "Clip.h"
Clip::Clip( Media* parent ) : m_parent( parent ), m_begin( 0.0f ), m_end( 1.0f )
......@@ -73,8 +75,10 @@ qint64 Clip::getLength() const
void Clip::computeLength()
{
qDebug() << "Begin:" << m_begin << "End:" << m_end << "Parent length" << m_parent->getLength();
qint64 nbMs = (qint64)( ( m_end - m_begin ) * (float)m_parent->getLength() );
m_length = (nbMs / 1000) * FPS;
qDebug() << "Computing length. nbMs:" << nbMs << "m_length:" << m_length;
}
const QUuid& Clip::getUuid() const
......
......@@ -33,24 +33,14 @@ Library::Library()
{
}
Media* Library::getMedia( const QUuid& uuid )
Media* Library::getMedia( const QUuid& uuid )
{
QMutexLocker locker( &m_mutex );
QHash<QUuid, Media*>::iterator it = m_medias.find( uuid );
if ( it == m_medias.end() )
return NULL;
return *it;
return getElementByUuid( m_medias, uuid );
}
Media* Library::getMedia( const QString& path )
Clip* Library::getClip( const QUuid& uuid )
{
QMutexLocker locker( &m_mutex );
QHash<QUuid, Media*>::iterator it;
QHash<QUuid, Media*>::iterator ite = m_medias.end();
for ( it = m_medias.begin(); it != ite; ++it )
if ( ((Media*)it.value())->getFileInfo()->absoluteFilePath() == path )
return it.value();
return NULL;
return getElementByUuid( m_clips, uuid );
}
void Library::removingMediaAsked( const QUuid& uuid )
......@@ -66,6 +56,13 @@ void Library::removingMediaAsked( const QUuid& uuid )
m_medias.erase( it );
}
void Library::metaDataComputed( Media* media )
{
Clip* clip = new Clip( media );
m_clips[clip->getUuid()] = clip;
emit newClipLoaded( clip );
}
void Library::newMediaLoadingAsked( const QString& filePath )
{
//Is this necessary ??
......@@ -80,6 +77,7 @@ void Library::newMediaLoadingAsked( const QString& filePath )
QFileInfo* fInfo = new QFileInfo( filePath );
media = new Media( fInfo );
m_medias[media->getUuid()] = media;
connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ), Qt::DirectConnection );
emit newMediaLoaded( media );
delete fInfo;
}
......@@ -37,6 +37,7 @@
#include <QMutexLocker>
#include "Media.h"
#include "Clip.h"
#include "Singleton.hpp"
class Library : public QObject, public Singleton<Library>
......@@ -45,18 +46,31 @@ class Library : public QObject, public Singleton<Library>
Q_DISABLE_COPY( Library );
public:
Media* getMedia( const QUuid& uuid );
Media* getMedia( const QString& path );
Clip* getClip( const QUuid& uudi );
private:
Library();
QHash<QUuid, Media*> m_medias;
QHash<QUuid, Clip*> m_clips;
QMutex m_mutex;
template <typename T>
T getElementByUuid( const QHash<QUuid, T>& container , const QUuid& uuid )
{
typename QHash<QUuid, T>::const_iterator it = container.find( uuid );
if ( it == container.end() )
return NULL;
return *it;
}
public slots:
void newMediaLoadingAsked( const QString& filePath );
void removingMediaAsked( const QUuid& uuid );
private slots:
void metaDataComputed( Media* );
signals:
void newClipLoaded( Clip* );
void newMediaLoaded( Media* );
void mediaRemoved( const QUuid& );
......
......@@ -106,7 +106,6 @@ void Media::setSnapshot( QPixmap* snapshot )
if ( m_snapshot != NULL )
delete m_snapshot;
m_snapshot = snapshot;
emit snapshotChanged();
}
const QPixmap& Media::getSnapshot() const
......@@ -226,3 +225,10 @@ bool Media::matchMetaTag( const QString& tag ) const
return false;
// m_metaTags.contains( tag, Qt::CaseInsensitive );
}
void Media::emitMetaDataComputed()
{
qDebug() << "Emmiting";
emit metaDataComputed();
emit metaDataComputed( this );
}
......@@ -129,6 +129,7 @@ public:
const QStringList& getMetaTags() const;
void setMetaTags( const QStringList& tags );
bool matchMetaTag( const QString& tag ) const;
void emitMetaDataComputed();
private:
void setFileType();
......@@ -152,7 +153,8 @@ protected:
QStringList m_metaTags;
signals:
void snapshotChanged();
void metaDataComputed();
void metaDataComputed( Media* );
};
#endif // CLIP_H__
......@@ -25,8 +25,6 @@
#include <QUrl>
#include "LibraryWidget.h"
QList<ListViewMediaItem*>* LibraryWidget::m_medias = NULL;
LibraryWidget::LibraryWidget( QWidget *parent ) : QWidget( parent ), m_firstDirectoryBrowsing(true)
{
m_ui.setupUi( this );
......@@ -40,8 +38,7 @@ LibraryWidget::LibraryWidget( QWidget *parent ) : QWidget( parent ), m_firstDire
// *Always* force the selection of the first tab
m_ui.LibraryTabs->setCurrentIndex( 0 );
if ( LibraryWidget::m_medias == NULL )
LibraryWidget::m_medias = new QList<ListViewMediaItem*>();
m_clips = new QList<ListViewMediaItem*>;
connect( m_ui.filterInput, SIGNAL( textChanged( QString ) ), this, SLOT( updateFilter( QString ) ) );
connect( m_ui.clearFilterButton, SIGNAL( clicked() ), m_ui.filterInput, SLOT( clear() ) );
connect( m_ui.LibraryTabs, SIGNAL( currentChanged( int ) ), this, SLOT( tabChanged( int ) ) );
......@@ -49,22 +46,19 @@ LibraryWidget::LibraryWidget( QWidget *parent ) : QWidget( parent ), m_firstDire
LibraryWidget::~LibraryWidget()
{
if ( LibraryWidget::m_medias )
{
while ( !LibraryWidget::m_medias->isEmpty() )
delete LibraryWidget::m_medias->takeLast();
delete LibraryWidget::m_medias;
}
while ( m_clips->isEmpty() == false )
delete m_clips->takeLast();
delete m_clips;
}
ListViewMediaItem* LibraryWidget::addMedia( Media* media )
ListViewMediaItem* LibraryWidget::addClip( Clip* clip )
{
Media::FileType fileType = media->getFileType();
ListViewMediaItem* item = new ListViewMediaItem( media, fileType );
Media::FileType fileType = clip->getParent()->getFileType();
ListViewMediaItem* item = new ListViewMediaItem( clip, fileType );
//TODO: replace this :
//emit listViewMediaAdded( item->getClip() );
m_medias->append( item );
m_clips->append( item );
switch ( fileType )
{
case Media::Audio:
......@@ -88,9 +82,9 @@ void LibraryWidget::mediaRemoved( const QUuid& uuid )
void LibraryWidget::removeMedia( const QUuid& uuid )
{
ListViewMediaItem* item;
foreach (item, *m_medias)
foreach (item, *m_clips)
{
if ( item->getMedia()->getUuid() == uuid )
if ( item->getClip()->getUuid() == uuid )
{
switch( item->getFileType() )
{
......@@ -104,7 +98,7 @@ void LibraryWidget::removeMedia( const QUuid& uuid )
this->m_ui.listWidgetVideo->removeItemWidget( item );
break;
}
m_medias->removeOne( item );
m_clips->removeOne( item );
delete item;
}
}
......@@ -124,11 +118,11 @@ void LibraryWidget::removeMedia( const QUuid& uuid )
// return item;
//}
void LibraryWidget::newMediaLoaded( Media* media )
void LibraryWidget::newClipLoaded( Clip* clip )
{
//From here, the clip is const.
addMedia( media );
m_ui.LibraryTabs->setCurrentIndex( (int) media->getFileType() );
addClip( clip );
m_ui.LibraryTabs->setCurrentIndex( (int) clip->getParent()->getFileType() );
}
void LibraryWidget::insertNewMediasFromFileDialog( QString title, QString filter, Media::FileType fileType )
......@@ -188,7 +182,7 @@ void LibraryWidget::on_pushButtonRemoveMedia_clicked()
ListViewMediaItem* item = ( ListViewMediaItem* ) mediaList->currentItem();
if ( !item ) return;
// removeMedia( item );
emit removingMediaAsked( item->getMedia()->getUuid() );
emit removingMediaAsked( item->getClip()->getParent()->getUuid() );
}
void LibraryWidget::changeEvent( QEvent *e )
......@@ -238,7 +232,7 @@ void LibraryWidget::updateFilter( const QString& filter )
ListViewMediaItem* item = static_cast<ListViewMediaItem*>( mediaList->item( i ) );
if ( item != NULL )
{
item->setHidden( !(item->getMedia()->matchMetaTag( filter )) );
item->setHidden( !(item->getClip()->getParent()->matchMetaTag( filter )) );
}
}
}
......
......@@ -48,7 +48,7 @@ public:
explicit LibraryWidget( QWidget *parent = 0 );
virtual ~LibraryWidget();
ListViewMediaItem* addMedia( Media* clip );
ListViewMediaItem* addClip( Clip* clip );
void removeMedia( const QUuid& uuid );
int getIndex( ListViewMediaItem* media );
const MediaListWidget* getVideoListWidget() const;
......@@ -64,13 +64,13 @@ private:
void insertNewMediasFromFileDialog( QString title, QString filter, Media::FileType fileType );
Ui::LibraryWidget m_ui;
static QList<ListViewMediaItem*>* m_medias;
QList<ListViewMediaItem*>* m_clips;
QString m_lastDirectoryBrowsed;
bool m_firstDirectoryBrowsing;
public slots:
void newMediaLoaded( Media* );
void newClipLoaded( Clip* );
void mediaRemoved( const QUuid& );
void updateFilter( const QString& );
......
......@@ -27,14 +27,14 @@
#define MAX_NAME_LENGTH 10
ListViewMediaItem::ListViewMediaItem( Media* media, Media::FileType fType, QListWidget* parent, int type ) :
QListWidgetItem( parent, type ), m_media ( media )
ListViewMediaItem::ListViewMediaItem( Clip* clip, Media::FileType fType, QListWidget* parent, int type ) :
QListWidgetItem( parent, type ), m_clip ( clip )
{
m_fileType = fType;
setIcon( QIcon( ":/images/images/vlmc.png") );
m_truncatedName = media->getFileInfo()->baseName();
m_truncatedName = clip->getParent()->getFileInfo()->baseName();
if ( m_truncatedName.length() > MAX_NAME_LENGTH )
{
m_truncatedName.truncate( MAX_NAME_LENGTH - 3 );
......@@ -42,29 +42,22 @@ ListViewMediaItem::ListViewMediaItem( Media* media, Media::FileType fType, QList
}
setText( m_truncatedName );
connect( media, SIGNAL( snapshotChanged() ), this, SLOT( snapshotChanged() ) );
}
ListViewMediaItem::~ListViewMediaItem()
{
setIcon( QIcon( m_clip->getParent()->getSnapshot() ) );
QTime length;
length = length.addSecs( m_clip->getLength() / 1000 );
setToolTip( "Filename: " + m_clip->getParent()->getFileInfo()->fileName() + "\n" +
"Length: " + length.toString() );
}
void ListViewMediaItem::snapshotChanged()
ListViewMediaItem::~ListViewMediaItem()
{
setIcon( QIcon( m_media->getSnapshot() ) );
//this is a nasty patch for the moment :
//TODO: fix this !!!!
QTime length;
length = length.addSecs( m_media->getLength() / 1000 );
setToolTip( "Filename: " + m_media->getFileInfo()->fileName() + "\n" +
"Length: " + length.toString() );
}
Media* ListViewMediaItem::getMedia()
Clip* ListViewMediaItem::getClip()
{
return m_media;
return m_clip;
}
......
......@@ -47,7 +47,7 @@ public:
* \param parent parent widget
* \param type
*/
ListViewMediaItem( Media* media, Media::FileType fType, QListWidget* parent = 0, int type = Type );
ListViewMediaItem( Clip* media, Media::FileType fType, QListWidget* parent = 0, int type = Type );
/**
* \brief Destructor
......@@ -60,7 +60,7 @@ public:
*/
Media::FileType getFileType() const { return m_fileType; }
Media* getMedia();
Clip* getClip();
//void setInputMedia( InputMedia* inputMedia ) { m_inputMedia = inputMedia; }
......@@ -68,20 +68,18 @@ private:
/**
* \brief fileType member
*/
Media::FileType m_fileType;
Media::FileType m_fileType;
/**
* \Instance of the InputMedia
*/
Media* m_media;
Clip* m_clip;
/**
* The truncated name of the media
*/
QString m_truncatedName;
QString m_truncatedName;
private slots:
void snapshotChanged();
};
#endif /* !LISTVIEWMEDIAITEM_H */
......@@ -106,9 +106,9 @@ void MainWindow::setupLibrary()
SLOT( newMediaLoadingAsked( const QString& ) ) );
connect( library,
SIGNAL( newMediaLoaded( Media* ) ),
SIGNAL( newClipLoaded( Clip* ) ),
libraryWidget,
SLOT( newMediaLoaded( Media* ) ) );
SLOT( newClipLoaded( Clip* ) ) );
connect( libraryWidget,
SIGNAL( removingMediaAsked( const QUuid& ) ),
......@@ -261,6 +261,6 @@ void MainWindow::registerWidgetInViewMenu( QDockWidget* widget )
void MainWindow::mediaListItemDoubleClicked( QListWidgetItem* qItem )
{
ListViewMediaItem* item = static_cast<ListViewMediaItem*>( qItem );
MediaProperty* mp = new MediaProperty( item->getMedia(), this );
MediaProperty* mp = new MediaProperty( item->getClip()->getParent(), this );
mp->show();
}
......@@ -63,11 +63,10 @@ void MediaListWidget::mousePressEvent( QMouseEvent* event )
ListViewMediaItem* item = static_cast<ListViewMediaItem*>( currentItem() );
if ( item == NULL )
return ;
if ( item->getMedia() != m_lastClicked )
if ( item->getClip() != m_lastClicked )
{
m_lastClicked = item->getMedia();
//TODO: change this piece of ....
emit selectedClipChanged( new Clip( m_lastClicked ) );
m_lastClicked = item->getClip();
emit selectedClipChanged( m_lastClicked );
}
}
......@@ -83,10 +82,10 @@ void MediaListWidget::mouseMoveEvent( QMouseEvent* event )
ListViewMediaItem* item = static_cast<ListViewMediaItem*>( currentItem() );
QMimeData* mimeData = new QMimeData;
mimeData->setData( "vlmc/uuid", item->getMedia()->getUuid().toString().toAscii() );
mimeData->setData( "vlmc/uuid", item->getClip()->getUuid().toString().toAscii() );
QDrag* drag = new QDrag( this );
drag->setMimeData( mimeData );
const QPixmap& dragPixmap = static_cast<ListViewMediaItem*>( currentItem() )->getMedia()->getSnapshot();
const QPixmap& dragPixmap = static_cast<ListViewMediaItem*>( currentItem() )->getClip()->getParent()->getSnapshot();
drag->setPixmap( dragPixmap.scaled( 100, 100, Qt::KeepAspectRatio ) );
drag->exec( Qt::CopyAction | Qt::MoveAction, Qt::CopyAction );
}
......
......@@ -48,7 +48,7 @@ private:
Media::FileType m_Type;
QPoint m_dragStartPos;
QSvgRenderer* m_svgRenderer;
Media* m_lastClicked;
Clip* m_lastClicked;
signals:
void selectedClipChanged( Clip* newClip );
......
......@@ -133,15 +133,15 @@ void TracksView::dragEnterEvent( QDragEnterEvent* event )
event->acceptProposedAction();
QUuid uuid = QUuid( QString( event->mimeData()->data( "vlmc/uuid" ) ) );
Media* media = Library::getInstance()->getMedia( uuid );
if ( !media ) return;
Clip* clip = Library::getInstance()->getClip( uuid );
if ( !clip ) return;
qreal mappedXPos = ( mapToScene( event->pos() ).x() + 0.5 );
if ( m_dragItem ) delete m_dragItem;
m_dragItem = new GraphicsMovieItem( new Clip( media ) );
m_dragItem->setWidth( ( int ) ( ( (double)media->getLength() / 1000 ) *
( (media->getFps() > 0) ? media->getFps() : m_fps) ) );
m_dragItem = new GraphicsMovieItem( clip );
m_dragItem->setWidth( ( int ) ( ( (double)clip->getLength() / 1000 ) *
( (clip->getParent()->getFps() > 0) ? clip->getParent()->getFps() : m_fps) ) );
m_dragItem->setHeight( tracksHeight() );
m_dragItem->setPos( mappedXPos, 0 );
m_dragItem->setParentItem( m_layout->itemAt( 0 )->graphicsItem() );
......
......@@ -74,8 +74,7 @@ void MetaDataWorker::computeImageMetaData()
void MetaDataWorker::getMetaData()
{
m_mediaIsPlaying = false;
//TODO: restore this when VLC1.1 comes out.
m_lengthHasChanged = false;
m_lengthHasChanged = false;
m_currentMedia->setLength( m_mediaPlayer->getLength() );
m_currentMedia->setWidth( m_mediaPlayer->getWidth() );
......@@ -122,9 +121,10 @@ void MetaDataWorker::setSnapshot()
disconnect( m_mediaPlayer, SIGNAL( snapshotTaken() ), this, SLOT( setSnapshot() ) );
m_currentMedia->emitMetaDataComputed();
//CHECKME:
//This is synchrone, but it may become asynchrone in the future...
m_mediaPlayer->stop();
//startAudioDataParsing();
delete this;
......
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