Commit 19b72513 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

Refactored MediaListView

parent d6b8c557
......@@ -68,6 +68,7 @@ SET(VLMC_SRCS
Gui/wizard/VideoPage.cpp
Gui/wizard/WelcomePage.cpp
Library/Library.cpp
Library/MediaContainer.cpp
LibVLCpp/VLCInstance.cpp
LibVLCpp/VLCMedia.cpp
LibVLCpp/VLCMediaPlayer.cpp
......@@ -157,6 +158,7 @@ SET (VLMC_HDRS
Gui/wizard/WelcomePage.h
Gui/WorkflowFileRendererDialog.h
Library/Library.h
Library/MediaContainer.h
LibVLCpp/VLCInstance.h
LibVLCpp/VLCMediaPlayer.h
Media/Clip.h
......
......@@ -235,8 +235,9 @@ void MainWindow::setupLibrary()
Qt::AllDockWidgetAreas,
QDockWidget::AllDockWidgetFeatures,
Qt::LeftDockWidgetArea );
connect( mediaLibraryWidget, SIGNAL( clipSelected(QUuid) ),
m_clipPreview->getGenericRenderer(), SLOT( setClip( QUuid ) ) );
connect( mediaLibraryWidget, SIGNAL( clipSelected( Clip* ) ),
qobject_cast<const ClipRenderer*>( m_clipPreview->getGenericRenderer() ),
SLOT( setClip( Clip* ) ) );
connect( Library::getInstance(), SIGNAL( mediaRemoved( const QUuid& ) ),
m_clipPreview->getGenericRenderer(), SLOT( mediaUnloaded( QUuid ) ) );
......
......@@ -46,7 +46,8 @@ ImportController::ImportController(QWidget *parent) :
m_ui->setupUi(this);
m_preview = new PreviewWidget( new ClipRenderer, m_ui->previewContainer );
m_stackNav = new StackViewController( m_ui->stackViewContainer, false );
m_mediaListController = new MediaListViewController( m_stackNav );
m_temporaryMedias = new MediaContainer;
m_mediaListController = new MediaListViewController( m_stackNav, m_temporaryMedias );
m_tag = new TagWidget( m_ui->tagContainer, 6 );
m_filesModel = new QFileSystemModel( this );
m_stackNav->pushViewController( m_mediaListController );
......@@ -86,19 +87,15 @@ ImportController::ImportController(QWidget *parent) :
connect( m_ui->forwardButton, SIGNAL( clicked() ),
this, SLOT( forwardButtonClicked() ) );
connect( m_mediaListController, SIGNAL( mediaSelected( const QUuid& ) ),
connect( m_mediaListController, SIGNAL( clipSelected( Clip* ) ),
qobject_cast<const ClipRenderer*>( m_preview->getGenericRenderer() ),
SLOT( setClip( const QUuid& ) ) );
connect( this, SIGNAL( mediaSelected( Media* ) ),
m_tag, SLOT( mediaSelected( Media* ) ) );
SLOT( setClip( Clip* ) ) );
connect( m_mediaListController, SIGNAL( clipSelected( Clip* ) ),
this, SLOT( mediaSelection( Clip* ) ) );
connect( m_mediaListController, SIGNAL( mediaSelected( const QUuid& ) ),
this, SLOT( mediaSelection( const QUuid& ) ) );
connect( m_mediaListController, SIGNAL( mediaDeleted( const QUuid& ) ),
connect( m_mediaListController, SIGNAL( clipDeleted( const QUuid& ) ),
this, SLOT( mediaDeletion( const QUuid& ) ) );
connect( m_mediaListController, SIGNAL( showClipListAsked( const QUuid& ) ),
this, SLOT( showClipList( const QUuid& ) ) );
connect( m_stackNav, SIGNAL( previousButtonPushed() ),
this, SLOT( restoreContext() ) );
......@@ -129,15 +126,17 @@ ImportController::changeEvent( QEvent *e )
}
void
ImportController::mediaSelection( const QUuid& uuid )
ImportController::mediaSelection( Clip* clip )
{
const QUuid& uuid = clip->uuid();
if ( m_currentUuid == uuid )
return ;
setUIMetaData( m_temporaryMedias[uuid] );
Media* media = m_temporaryMedias->media( uuid );
setUIMetaData( media->baseClip() );
m_preview->stop();
m_currentUuid = uuid;
emit mediaSelected( m_temporaryMedias[uuid] );
m_tag->mediaSelected( media );
emit clipSelected( media->baseClip() );
}
void
......@@ -145,13 +144,8 @@ ImportController::clipSelection( const QUuid& uuid )
{
if ( uuid == m_currentUuid )
return ;
Clip* clip;
Clip* clip = m_temporaryMedias->clip( uuid );
foreach( Media* media, m_temporaryMedias.values() )
{
if ( ( clip = media->clip( uuid ) ) != NULL )
break;
}
if ( clip == NULL )
return ;
setUIMetaData( clip );
......@@ -160,23 +154,23 @@ ImportController::clipSelection( const QUuid& uuid )
}
void
ImportController::setUIMetaData( Media* media )
ImportController::setUIMetaData( Clip* clip )
{
if ( media != NULL )
if ( clip != NULL )
{
//Duration
QTime duration;
duration = duration.addMSecs( media->lengthMS() );
duration = duration.addSecs( clip->lengthSecond() );
m_ui->durationValueLabel->setText( duration.toString( "hh:mm:ss" ) );
//Filename || title
m_ui->nameValueLabel->setText( media->fileInfo()->fileName() );
m_ui->nameValueLabel->setText( clip->getParent()->fileInfo()->fileName() );
m_ui->nameValueLabel->setWordWrap( true );
setWindowTitle( media->fileInfo()->fileName() + " " + tr( "properties" ) );
setWindowTitle( clip->getParent()->fileInfo()->fileName() + " " + tr( "properties" ) );
//Resolution
m_ui->resolutionValueLabel->setText( QString::number( media->width() )
+ " x " + QString::number( media->height() ) );
m_ui->resolutionValueLabel->setText( QString::number( clip->getParent()->width() )
+ " x " + QString::number( clip->getParent()->height() ) );
//FPS
m_ui->fpsValueLabel->setText( QString::number( media->fps() ) );
m_ui->fpsValueLabel->setText( QString::number( clip->getParent()->fps() ) );
}
else
{
......@@ -187,39 +181,20 @@ ImportController::setUIMetaData( Media* media )
}
}
void
ImportController::setUIMetaData( Clip* clip )
{
QTime time;
qint64 length = clip->lengthSecond();
time = time.addSecs( length );
m_ui->durationValueLabel->setText( time.toString( "hh:mm:ss" ) );
m_ui->nameValueLabel->setText( clip->getParent()->fileInfo()->fileName() );
m_ui->nameValueLabel->setWordWrap( true );
setWindowTitle( clip->getParent()->fileInfo()->fileName() + " " +
tr( "properties" ) );
m_ui->resolutionValueLabel->setText( QString::number( clip->getParent()->width() )
+ " x " + QString::number( clip->getParent()->height() ) );
m_ui->fpsValueLabel->setText( QString::number( clip->getParent()->fps() ) );
}
void
ImportController::importMedia( const QString &filePath )
{
++m_nbMediaToLoad;
m_ui->progressBar->setMaximum( m_nbMediaToLoad );
foreach ( Media* media, m_temporaryMedias.values() )
if ( media->fileInfo()->filePath() == filePath )
return ;
if ( Library::getInstance()->mediaAlreadyLoaded( filePath ) == true )
if ( m_temporaryMedias->mediaAlreadyLoaded( filePath ) == true ||
Library::getInstance()->mediaAlreadyLoaded( filePath ) == true )
return ;
Media* media = new Media( filePath );
connect( media, SIGNAL( snapshotComputed( const Media* ) ),
this, SLOT( mediaLoaded() ) );
m_temporaryMedias[media->baseClip()->uuid()] = media;
m_temporaryMedias->addMedia( media );
MetaDataManager::getInstance()->computeMediaMetadata( media );
m_mediaListController->newMediaLoaded( media );
}
void
......@@ -282,7 +257,7 @@ ImportController::reject()
{
m_preview->stop();
m_mediaListController->clear();
deleteTemporaryMedias();
m_temporaryMedias->clear();
collapseAllButCurrentPath();
done( Rejected );
}
......@@ -293,20 +268,12 @@ ImportController::accept()
m_mediaListController->clear();
m_preview->stop();
collapseAllButCurrentPath();
foreach ( Media* media, m_temporaryMedias.values() )
foreach ( Media* media, m_temporaryMedias->medias().values() )
Library::getInstance()->addMedia( media );
m_temporaryMedias.clear();
m_temporaryMedias->removeAll();
done( Accepted );
}
void
ImportController::deleteTemporaryMedias()
{
foreach ( Media* media, m_temporaryMedias.values() )
delete media;
m_temporaryMedias.clear();
}
void
ImportController::collapseAllButCurrentPath()
{
......@@ -325,12 +292,11 @@ ImportController::collapseAllButCurrentPath()
void
ImportController::mediaDeletion( const QUuid& uuid )
{
if ( m_temporaryMedias.contains( uuid ) == true )
delete m_temporaryMedias.take( uuid );
m_temporaryMedias->deleteMedia( uuid );
if ( uuid == m_currentUuid )
{
setUIMetaData( static_cast<Media*>( 0 ) );
setUIMetaData( NULL );
m_currentUuid = QUuid();
m_preview->stop();
}
......@@ -339,29 +305,23 @@ ImportController::mediaDeletion( const QUuid& uuid )
void
ImportController::clipDeletion( const QUuid& uuid )
{
foreach( Media* media, m_temporaryMedias.values() )
{
if ( media != NULL && media->clip( uuid ) )
media->removeClip( uuid );
}
m_temporaryMedias->removeClip( uuid );
}
void
ImportController::showClipList( const QUuid& uuid )
{
if ( m_temporaryMedias.contains( uuid ) == false )
return ;
Media* media = m_temporaryMedias[uuid];
if ( media->clipsCount() == 0 )
Media* media = m_temporaryMedias->media( uuid );
if ( media == NULL || media->clipsCount() == 0 )
return ;
m_clipListController = new MediaListViewController( m_stackNav );
m_clipListController = new MediaListViewController( m_stackNav, m_temporaryMedias );
connect( m_clipListController, SIGNAL( clipSelected( const QUuid& ) ),
this, SLOT( clipSelection( const QUuid& ) ) );
connect( m_clipListController, SIGNAL( clipDeleted( const QUuid& ) ),
this, SLOT( clipDeletion( const QUuid& ) ) );
foreach ( Clip* clip, media->clips().values() )
m_clipListController->newClipAdded( clip );
m_clipListController->addClip( clip );
if ( !m_currentUuid.isNull() )
m_savedUuid = m_currentUuid;
m_stackNav->pushViewController( m_clipListController );
......
......@@ -39,9 +39,10 @@
#include <QDialog>
#include <QFileSystemModel>
#include <QFileSystemWatcher>
#include <QProgressDialog>
class MediaContainer;
namespace Ui
{
class ImportController;
......@@ -58,8 +59,7 @@ class ImportController : public QDialog
public:
ImportController(QWidget *parent = 0);
~ImportController();
void setUIMetaData( Media* media );
void setUIMetaData( Clip* clip );
void setUIMetaData( Clip *clip );
protected:
void changeEvent( QEvent *e );
......@@ -68,7 +68,6 @@ class ImportController : public QDialog
void saveCurrentPath();
void restoreCurrentPath();
void collapseAllButCurrentPath();
void deleteTemporaryMedias();
void importMedia( const QString &filePath );
void importDir( const QString &path );
Ui::ImportController* m_ui;
......@@ -81,14 +80,14 @@ class ImportController : public QDialog
QString m_currentlyWatchedDir;
QUuid m_currentUuid;
QUuid m_savedUuid;
QHash< QUuid, Media*> m_temporaryMedias;
MediaContainer *m_temporaryMedias;
quint32 m_nbMediaToLoad;
quint32 m_nbMediaLoaded;
public slots:
void accept();
void reject();
void mediaSelection( const QUuid& uuid );
void mediaSelection( Clip* clip );
void clipSelection( const QUuid& uuid );
void mediaDeletion( const QUuid& uuid );
void clipDeletion( const QUuid& uuid );
......@@ -104,7 +103,6 @@ class ImportController : public QDialog
void hideErrors();
signals:
void mediaSelected( Media* );
void clipSelected( Clip* );
};
......
......@@ -117,7 +117,7 @@ void MediaCellView::mouseDoubleClickEvent( QMouseEvent* event )
{
ClipProperty* cp = new ClipProperty( m_clip, this );
cp->setModal( true );
cp->show();
cp->exec();
delete cp;
}
}
......
......@@ -29,11 +29,12 @@
MediaLibraryWidget::MediaLibraryWidget( QWidget* parent ) : QWidget( parent )
{
m_nav = new StackViewController( this );
MediaListViewController* list = new MediaListViewController( m_nav );
Library* library = Library::getInstance();
m_nav = new StackViewController( this );
MediaListViewController* list = new MediaListViewController( m_nav, library );
//Media
connect( list, SIGNAL( clipSelected( const QUuid& ) ), this, SIGNAL( clipSelected( const QUuid& ) ) );
connect( list, SIGNAL( clipSelected( Clip* ) ), this, SIGNAL( clipSelected( Clip* ) ) );
connect( list, SIGNAL( clipDeleted( const QUuid& ) ), library, SLOT( removingMediaAsked( const QUuid& ) ) );
connect( library, SIGNAL( mediaRemoved( QUuid ) ), list, SLOT( mediaRemoved( const QUuid& ) ) );
connect( m_nav, SIGNAL( importRequired() ), this, SIGNAL( importRequired() ) );
......
......@@ -45,7 +45,7 @@ private:
StackViewController* m_nav;
signals:
void clipSelected( const QUuid& );
void clipSelected( Clip* );
void importRequired();
void addClipToViewController( Clip* clip );
};
......
......@@ -23,11 +23,15 @@
#include "MediaListViewController.h"
#include "Clip.h"
#include "MediaContainer.h"
MediaListViewController::MediaListViewController( StackViewController* nav ) :
ListViewController( nav ), m_nav( nav ), m_clipsListView( 0 )
MediaListViewController::MediaListViewController( StackViewController* nav, MediaContainer* mc ) :
ListViewController( nav ),
m_nav( nav ),
m_clipsListView( 0 ),
m_mediaContainer( mc )
{
connect( Library::getInstance(), SIGNAL( newMediaLoaded( Media* ) ),
connect( mc, SIGNAL( newMediaLoaded( Media* ) ),
this, SLOT( newMediaLoaded( Media* ) ) );
m_cells = new QHash<QUuid, QWidget*>();
connect( m_nav, SIGNAL( previousButtonPushed() ), this, SLOT( restoreContext() ) );
......@@ -71,7 +75,7 @@ void MediaListViewController::cellSelection( const QUuid& uuid )
p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
m_cells->value( uuid )->setPalette( p );
m_currentUuid = uuid;
emit clipSelected( uuid );
emit clipSelected( m_mediaContainer->clip( uuid ) );
}
}
......@@ -96,12 +100,12 @@ void MediaListViewController::showClipList( const QUuid& uuid )
{
if ( !m_cells->contains( uuid ) )
return ;
if ( Library::getInstance()->media( uuid ) == NULL ||
Library::getInstance()->media( uuid )-> clipsCount() == 0 )
if ( m_mediaContainer->media( uuid ) == NULL ||
m_mediaContainer->media( uuid )-> clipsCount() == 0 )
return ;
m_lastUuidClipListAsked = uuid;
m_clipsListView = new MediaListViewController( m_nav );
m_clipsListView->newMediaLoaded( Library::getInstance()->media( uuid ) );
m_clipsListView = new MediaListViewController( m_nav, Library::getInstance() );
m_clipsListView->newMediaLoaded( m_mediaContainer->media( uuid ) );
connect( m_clipsListView, SIGNAL( clipSelected( const QUuid& ) ),
this, SLOT( clipSelection( const QUuid& ) ) );
m_nav->pushViewController( m_clipsListView );
......@@ -123,6 +127,12 @@ void MediaListViewController::newClipAdded( Clip* clip )
}
}
void
MediaListViewController::addClip( Clip *clip )
{
newClipAdded( clip );
}
void MediaListViewController::restoreContext()
{
MediaCellView* cell = qobject_cast<MediaCellView*>( m_cells->value( m_lastUuidClipListAsked, 0 ) );
......
......@@ -29,13 +29,16 @@
#include "Library.h"
#include "Media.h"
class MediaContainer;
class MediaListViewController : public ListViewController
{
Q_OBJECT
public:
MediaListViewController( StackViewController* nav );
MediaListViewController( StackViewController* nav, MediaContainer* mc );
virtual ~MediaListViewController();
void addClip( Clip* clip );
private:
StackViewController* m_nav;
......@@ -43,19 +46,21 @@ private:
QHash<QUuid, QWidget*>* m_cells;
MediaListViewController* m_clipsListView;
QUuid m_lastUuidClipListAsked;
MediaContainer* m_mediaContainer;
public slots:
void newMediaLoaded( Media* media );
void cellSelection( const QUuid& uuid );
void mediaRemoved( const QUuid& uuid );
void showClipList( const QUuid& uuid );
void newClipAdded( Clip* clip );
void clear();
private slots:
void restoreContext();
void newClipAdded( Clip* clip );
void mediaRemoved( const QUuid& uuid );
void newMediaLoaded( Media* media );
signals:
void clipSelected( const QUuid& );
void clipSelected( Clip* );
void clipDeleted( const QUuid& );
};
#endif // MEDIALISTVIEWCONTROLLER_H
......@@ -32,108 +32,11 @@
#include "Media.h"
#include "MetaDataManager.h"
#include <QDebug>
#include <QDir>
#include <QtDebug>
#include <QDomElement>
#include <QHash>
#include <QMessageBox>
#include <QProgressDialog>
#include <QUuid>
Library::Library()
{
}
Media*
Library::media( const QUuid& uuid )
{
QHash<QUuid, Media*>::const_iterator it = m_medias.find( uuid );
if ( it == m_medias.end() )
return NULL;
return *it;
}
Clip*
Library::clip( const QUuid& uuid )
{
Media* m = media( uuid );
if ( m != NULL )
return m->baseClip();
foreach( m, m_medias.values() )
{
if ( m != NULL && m->clips().contains( uuid ) )
return m->clip( uuid );
}
return NULL;
}
Clip*
Library::clip( const QUuid& mediaUuid, const QUuid& clipUuid )
{
if ( m_medias.contains( mediaUuid ) )
{
if ( m_medias.value( mediaUuid )->clips().contains( clipUuid ) )
return m_medias.value( mediaUuid )->clip( clipUuid );
else
m_medias.value( mediaUuid )->baseClip();
}
return NULL;
}
void
Library::removingMediaAsked( const QUuid& uuid )
{
deleteMedia( uuid );
emit mediaRemoved( uuid );
}
void
Library::deleteMedia( const QUuid& uuid )
{
if ( m_medias.contains( uuid ) )
delete m_medias.take( uuid );
}
bool
Library::addMedia( const QFileInfo& fileInfo, const QString& uuid )
{
if ( QFile::exists( fileInfo.absoluteFilePath() ) == false )
return false;
Media* media = new Media( fileInfo.filePath(), uuid );
foreach( Media* it, m_medias.values() )
{
if ( it->fileInfo()->filePath() == media->fileInfo()->filePath() )
{
delete media;
return false;
}
}
MetaDataManager::getInstance()->computeMediaMetadata( media );
addMedia( media );
return true;
}
void
Library::addMedia( Media *media )
{
m_medias[media->baseClip()->uuid()] = media;
emit newMediaLoaded( media );
}
bool
Library::mediaAlreadyLoaded( const QFileInfo& fileInfo )
{
foreach( Media* media, m_medias.values() )
{
if ( media->fileInfo()->filePath() == fileInfo.filePath() )
return true;
}
return false;
}
void
Library::loadProject( const QDomElement& medias )
{
......@@ -269,31 +172,3 @@ Library::saveProject( QDomDocument& doc, QDomElement& rootNode )
}
rootNode.appendChild( medias );
}
void
Library::clear()
{
QHash<QUuid, Media*>::iterator it = m_medias.begin();
QHash<QUuid, Media*>::iterator end = m_medias.end();
while ( it != end )
{
emit mediaRemoved( it.key() );
delete it.value();
++it;
}
m_medias.clear();
}
void
Library::removeClip( const QUuid& mediaId, const QUuid& clipId )
{
Media* med = 0;
if ( m_medias.contains( mediaId ) )
med = m_medias[mediaId];
else
return;
if ( med->clips().contains( clipId ) )
med->removeClip( clipId );
}
......@@ -31,6 +31,7 @@
#define LIBRARY_H
#include "Singleton.hpp"
#include "MediaContainer.h"
#include <QHash>
#include <QObject>
......@@ -51,90 +52,16 @@ class Media;
* \class Library
* \brief Library Object that handles medias
*/
class Library : public QObject, public Singleton<Library>
class Library : public MediaContainer, public Singleton<Library>
{
Q_OBJECT
Q_DISABLE_COPY( Library );
public:
/**
* \brief returns the media that match the unique identifier
* \param uuid the unique identifier of the media
* \return a pointer to the required media, or NULL if no medias matches
* \sa clip( const QUuid& uuid )
*/
Media* media( const QUuid& uuid );
/**
* \brief returns the clip that match the unique identifier
* \param uuid the unique identifier of the media
* \return a pointer to the required clip, or NULL if no clips matches
* \sa media( const QUuid& uuid )
*/
Clip* clip( const QUuid& uuid );
/**
* \brief returns the clip that match the unique identifier
* \param mediaUuid the unique identifier of the media
* \param clipUuid the unique identifier of the clip
* \return a pointer to the required clip, or NULL if no clips matches
* \sa media( const QUuid& uuid )
*/
Clip* clip( const QUuid& mediaUuid, const QUuid& clipUuid );
/**
* \brief Add a file to the media library
*
* This method will also handle metadata parsing. Right now, this is only meant to be
* used when loading a project.
* \param fileInfo the file info of the media
* \return true if the media was successfully loaded. false otherwise.
* \sa addClip( Clip* clip )
* \sa media( const QUuid& uuid)
* \sa clip( const QUuid& uuid )
*/
bool addMedia( const QFileInfo& fileInfo, const QString& uuid = QString() );
/**
* \brief Add an already preparsed media.
*
* \param media The media to add to the library
*/
void addMedia( Media *media );
/**
* \brief Check if a file has already been loaded into library.
* \param fileInfo The file infos
* \return true if the file is already loaded, false otherwhise
*/
bool mediaAlreadyLoaded( const QFileInfo& fileInfo );
private:
/**
* \brief Library Object Constructor
*/
Library();
/**
* \brief This method is used to load a media directly from it's
* path, with a specified UUID.
* It shouldn't used for something else that loading a project file
* \param path The path of the media file
* \param uuid The uuid you want for the new media
*/
/**
* \brief The List of medias loaded into the library
*/
QHash<QUuid, Media*> m_medias;
Library(){}
virtual ~Library(){}
public slots:
/**
* \brief This slot must be called when you want a media to be removed from library
* \param uuid The uuid of the media to be removed
*/
void removingMediaAsked( const QUuid& uuid );
/**
* \brief Delete the media when it's ready
* \param uuid the unique identifier of the media to delete
*/
void deleteMedia( const QUuid& uuid );
/**
* \brief
*/
......@@ -143,34 +70,13 @@ public slots:
* \brief
*/
void saveProject( QDomDocument& doc, QDomElement& rootNode );
/**
* \brief Clear the library (remove all the loaded media and delete them)
*/
void clear();
/**
* \brief Remove a clip from a media
*/
void removeClip( const QUuid& mediaId, const QUuid& clipId );
signals:
/**
* \brief This signal should be emitted to tell a new media have been added
* \param media The newly added media
*/
void newMediaLoaded( Media* );
/**
* \brief This signal should be emiteted when a media has been removed
* \param uuid The removed media uuid
*/
void mediaRemoved( const QUuid& );
/**
* \brief
*/
void projectLoaded();
/**
* \brief
*/
void updateMediaRequested( const QUuid& uuid );
friend class Singleton<Library>;
};