Commit 9985532a authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen

MetaDataManager is back again.

Removed warning, cleaner code, yoohoo !
parent 953f29bc
......@@ -48,7 +48,7 @@ void Clip::loadMedia( const QString& mrl )
m_vlcMedia = new LibVLCpp::Media( m_instance, mrl );
}
void Clip::setupMedia()
void Clip::flushParameters()
{
//Flushing the args into the media :
QString param;
......@@ -65,6 +65,7 @@ void Clip::setSnapshot( QPixmap* snapshot )
{
//TODO: check for mem leaks.
m_snapshot = snapshot;
emit snapshotChanged();
}
const QPixmap& Clip::getSnapshot() const
......
......@@ -27,21 +27,24 @@
#include <QString>
#include <QPixmap>
#include <QUuid>
#include <QObject>
#include "VLCMedia.h"
/**
* Represents a basic container for media informations.
*/
class Clip
class Clip : public QObject
{
Q_OBJECT
public:
Clip( const QString& mrl );
virtual ~Clip();
void loadMedia( const QString& mrl );
void addParam( const QString& param );
void setupMedia();
void flushParameters();
LibVLCpp::Media* getVLCMedia() { return m_vlcMedia; }
void setSnapshot( QPixmap* snapshot );
......@@ -57,6 +60,9 @@ protected:
QList<QString> m_parameters;
QPixmap* m_snapshot;
QUuid m_uuid;
signals:
void snapshotChanged();
};
#endif // MEDIA_H
#include "MetaDataManager.h"
MetaDataManager::MetaDataManager( LibraryWidget* libraryWidget ) : m_libraryWidget( libraryWidget ), m_renderWidget( NULL )
MetaDataManager::MetaDataManager() : m_renderWidget( NULL )
{
m_mediaPlayer = new LibVLCpp::MediaPlayer();
connect( m_libraryWidget, SIGNAL( listViewMediaAdded( ListViewMediaItem* ) ), this, SLOT( listViewMediaAdded( ListViewMediaItem* ) ) );
connect( LibraryWidget::getInstance(), SIGNAL( listViewMediaAdded( Clip* ) ), this, SLOT( listViewMediaAdded( Clip* ) ) );
m_tmpSnapshotFilename = new char[512];
m_renderWidget = new QWidget();
m_mediaPlayer->setDrawable( m_renderWidget->winId() );
}
MetaDataManager::~MetaDataManager()
......@@ -17,33 +18,31 @@ MetaDataManager::~MetaDataManager()
delete[] m_tmpSnapshotFilename;
}
void MetaDataManager::listViewMediaAdded( ListViewMediaItem* item )
void MetaDataManager::listViewMediaAdded( Clip* item )
{
m_mediaList.append( item );
//TODO: relaunch the thread after refactoring
// if ( !isRunning() )
// start();
if ( !isRunning() )
start();
}
void MetaDataManager::run()
{
m_nextMedia = true;
// if ( !m_renderWidget )
m_mediaPlayer->setDrawable( m_renderWidget->winId() );
while ( !m_mediaList.isEmpty() )
{
if ( m_nextMedia )
{
m_nextMedia = false;
m_currentMediaItem = m_mediaList.front();
m_currentClip = m_mediaList.front();
m_mediaList.pop_front();
//TODO: launch (play) the media and connect the MediaPlayer "playing" signal to the renderSnapshot slot.
m_currentClip->flushParameters();
m_mediaPlayer->setMedia( m_currentClip->getVLCMedia() );
m_mediaPlayer->play();
connect( m_mediaPlayer, SIGNAL( playing() ), this, SLOT( renderSnapshot() ) );
}
usleep( 100 );
}
......@@ -53,6 +52,10 @@ void MetaDataManager::run()
void MetaDataManager::renderSnapshot()
{
//TODO: set the position to 1/3 of the video length
m_mediaPlayer->setTime( m_mediaPlayer->getTime() / 3 );
//FIXME: add a signal / slot for time changed.
sleep(1);
QTemporaryFile tmp;
tmp.setAutoRemove( false );
......@@ -62,7 +65,6 @@ void MetaDataManager::renderSnapshot()
connect( m_mediaPlayer, SIGNAL( snapshotTaken() ), this, SLOT( setSnapshotInIcon() ) );
sleep(1);
//The slot should be triggered in this methode
m_mediaPlayer->takeSnapshot( m_tmpSnapshotFilename, 32, 32 );
//Snapshot slot should has been called (but maybe not in next version...)
......@@ -70,7 +72,7 @@ void MetaDataManager::renderSnapshot()
void MetaDataManager::setSnapshotInIcon()
{
//TODO: Set the media icon from the snapshot.
m_currentClip->setSnapshot( new QPixmap( m_tmpSnapshotFilename ) );
m_nextMedia = true;
disconnect( this, SLOT( setSnapshotInIcon() ) );
m_mediaPlayer->stop();
......
......@@ -4,7 +4,8 @@
#include <QList>
#include <QTemporaryFile>
#include <QThread>
#include "gui/LibraryWidget.h"
#include "Clip.h"
#include "LibraryWidget.h"
#include "VLCMediaPlayer.h"
class MetaDataManager : public QThread
......@@ -13,27 +14,27 @@ class MetaDataManager : public QThread
Q_DISABLE_COPY( MetaDataManager )
public:
MetaDataManager( LibraryWidget* libraryWidget );
MetaDataManager();
~MetaDataManager();
private:
virtual void run();
private:
LibraryWidget* m_libraryWidget;
LibVLCpp::MediaPlayer* m_mediaPlayer;
QWidget* m_renderWidget;
// TODO: THREAD SAFING
QList<ListViewMediaItem*> m_mediaList;
QList<Clip*> m_mediaList;
// Thread component
bool m_nextMedia;
ListViewMediaItem* m_currentMediaItem;
Clip* m_currentClip;
//FIXME: Won't work in asynchrone mode
char* m_tmpSnapshotFilename;
private slots:
void listViewMediaAdded( ListViewMediaItem* );
void listViewMediaAdded( Clip* );
void renderSnapshot();
void setSnapshotInIcon();
};
......
......@@ -56,7 +56,7 @@ LibraryWidget::~LibraryWidget()
ListViewMediaItem* LibraryWidget::addMedia( QFileInfo* fileInfo, ListViewMediaItem::fType fileType )
{
ListViewMediaItem* item = new ListViewMediaItem( fileInfo, fileType );
emit listViewMediaAdded( item );
emit listViewMediaAdded( item->getClip() );
m_medias->append( item );
m_mediaHash[item->getClip()->getUuid()] = item->getClip();
switch ( fileType )
......
......@@ -81,7 +81,7 @@ private slots:
void on_pushButtonRemoveMedia_clicked();
signals:
void listViewMediaAdded(ListViewMediaItem* item);
void listViewMediaAdded(Clip* clip);
};
#endif /* !LIBRARYWIDGET_H */
......@@ -36,6 +36,7 @@ ListViewMediaItem::ListViewMediaItem( QFileInfo* fInfo, ListViewMediaItem::fType
m_renderWidget = new QWidget();
m_clip = new Clip( "file://" + fInfo->absoluteFilePath() );
connect( m_clip, SIGNAL( snapshotChanged() ), this, SLOT( snapshotChanged() ) );
}
ListViewMediaItem::~ListViewMediaItem()
......@@ -45,3 +46,8 @@ ListViewMediaItem::~ListViewMediaItem()
if ( m_clip != NULL )
delete m_clip;
}
void ListViewMediaItem::snapshotChanged()
{
setIcon( QIcon( m_clip->getSnapshot() ) );
}
......@@ -108,16 +108,10 @@ private:
*/
QWidget* m_renderWidget;
/**
* \brief The current media snapshot
*/
//FIXME: this should probably be in the media itself
//QPixmap* m_currentMediaSnapshot;
public slots:
// void setSnapshot();
// void takeSnapshot();
// void seek();
private slots:
void snapshotChanged();
};
#endif /* !LISTVIEWMEDIAITEM_H */
......@@ -83,7 +83,7 @@ void MainWindow::m_initializeDockWidgets( void )
QDockWidget::AllDockWidgetFeatures,
Qt::TopDockWidgetArea );
m_metaDataManager = new MetaDataManager( libraryWidget );
m_metaDataManager = new MetaDataManager();
}
//Private slots definition
......
......@@ -75,7 +75,7 @@ void PreviewWidget::dropEvent( QDropEvent* event )
Clip* clip = LibraryWidget::getInstance()->getClip( event->mimeData()->text() );
m_mediaPlayer->setMedia( clip->getVLCMedia() );
clip->setupMedia();
clip->flushParameters();
m_mediaPlayer->setDrawable( m_ui->clipRenderWidget->winId() );
//FIXME Connecting endReached to pause to change icon of playpause button
......
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