Commit 316eb5d6 authored by Hugo Beauzee-Luyssen's avatar Hugo Beauzee-Luyssen Committed by Ludovic Fauvet

Cleaned extension/filetype complete mess.

Extension are now stored in a specific place. FileType is now really
used in the GUI, and not hardcoded.
parent b91cd5fe
......@@ -29,17 +29,20 @@
#include <QtDebug>
#include "Media.h"
QPixmap* Media::defaultSnapshot = NULL;
Media::Media( const QString& mrl )
: m_vlcMedia( NULL ), m_mrl( mrl ), m_snapshot( NULL ), m_length( 0 ),
m_width( 0 ), m_height( 0 )
{
m_vlcMedia = new LibVLCpp::Media( mrl );
m_uuid = QUuid::createUuid();
//We avoid creating a fileInfo from the mrl since it can be "fake://" for invmem.
m_fileInfo = NULL;
}
QPixmap* Media::defaultSnapshot = NULL;
const QString Media::VideoExtensions = "*.mov *.avi *.mkv *.mpg *.mpeg *.wmv *.mp4";
const QString Media::ImageExtensions = "*.gif *.png *.jpg";
const QString Media::AudioExtensions = "*.mp3 *.oga *.flac *.aac *.wav";
//Media::Media( const QString& mrl )
// : m_vlcMedia( NULL ), m_mrl( mrl ), m_snapshot( NULL ), m_length( 0 ),
// m_width( 0 ), m_height( 0 )
//{
// m_vlcMedia = new LibVLCpp::Media( mrl );
// m_uuid = QUuid::createUuid();
// //We avoid creating a fileInfo from the mrl since it can be "fake://" for invmem.
// m_fileInfo = NULL;
//}
Media::Media( const QFileInfo* fileInfo)
: m_vlcMedia( NULL ), m_snapshot( NULL ), m_length( 0 ),
......@@ -49,6 +52,7 @@ Media::Media( const QFileInfo* fileInfo)
m_vlcMedia = new LibVLCpp::Media( m_mrl );
m_uuid = QUuid::createUuid();
m_fileInfo = new QFileInfo( *fileInfo );
setFileType();
}
Media::~Media()
......@@ -59,6 +63,19 @@ Media::~Media()
}
}
void Media::setFileType()
{
QString filter = "*." + m_fileInfo->suffix();
if ( Media::VideoExtensions.contains( filter ) )
m_fileType = Media::Video;
else if ( Media::AudioExtensions.contains( filter ) )
m_fileType = Media::Audio;
else if ( Media::ImageExtensions.contains( filter ) )
m_fileType = Media::Image;
else
qDebug() << "What the hell is this extension ? And how did you loaded it ?!";
}
void Media::loadMedia( const QString& mrl )
{
if ( m_vlcMedia )
......
......@@ -70,7 +70,7 @@ public:
Image
};
Media( const QFileInfo* fileInfo );
Media( const QString& mrl );
// Media( const QString& mrl );
virtual ~Media();
void loadMedia( const QString& mrl );
......@@ -105,6 +105,9 @@ public:
const QUuid& getUuid() const;
FileType getFileType() const;
static const QString VideoExtensions;
static const QString AudioExtensions;
static const QString ImageExtensions;
void initAudioData( void* datas, unsigned int* freq, unsigned int* nbChannels, unsigned int* fourCCFormat, unsigned int* frameSize );
void addAudioFrame( void* datas, unsigned char* buffer, size_t buffSize, unsigned int nbSample );
......@@ -113,6 +116,9 @@ public:
QVector<int*> getAudioFrameList() { return m_audioData.frameList; }
unsigned int getAudioNbSample() { return m_audioData.nbSample; }
private:
void setFileType();
protected:
static QPixmap* defaultSnapshot;
......
......@@ -54,9 +54,11 @@ LibraryWidget::~LibraryWidget()
}
}
ListViewMediaItem* LibraryWidget::addMedia( const Media* media, Media::FileType fileType )
ListViewMediaItem* LibraryWidget::addMedia( const Media* media )
{
Media::FileType fileType = media->getFileType();
ListViewMediaItem* item = new ListViewMediaItem( media, fileType );
//TODO: replace this :
//emit listViewMediaAdded( item->getClip() );
m_medias->append( item );
......@@ -122,7 +124,7 @@ void LibraryWidget::removeMedia( const QUuid& uuid )
void LibraryWidget::newMediaLoaded( Media* media )
{
//From here, the clip is const.
addMedia( media, Media::Video );
addMedia( media );
m_ui.LibraryTabs->setCurrentIndex( 1 );
}
......@@ -160,17 +162,17 @@ void LibraryWidget::on_pushButtonAddMedia_clicked()
{
case 0:
insertNewMediasFromFileDialog( tr( "Open Audios" ),
tr( "Audio Files" ) + " (*.mp3 *.oga *.flac *.aac *.wav)" ,
tr( "Audio Files" ) + " (" + Media::AudioExtensions + ")" ,
Media::Audio );
break;
case 1:
insertNewMediasFromFileDialog( tr( "Open Videos" ),
tr( "Video Files" ) + " (*.mov *.avi *.mkv *.mpg *.mpeg *.wmv *.mp4)" ,
tr( "Video Files" ) + " (" + Media::VideoExtensions + ")" ,
Media::Video );
break;
case 2:
insertNewMediasFromFileDialog( tr( "Open Images" ),
tr( "Images Files" ) + " (*.gif *.png *.jpg)" ,
tr( "Images Files" ) + " (" + Media::ImageExtensions + ")" ,
Media::Image );
break;
}
......
......@@ -48,7 +48,7 @@ public:
explicit LibraryWidget( QWidget *parent = 0 );
virtual ~LibraryWidget();
ListViewMediaItem* addMedia( const Media* clip, Media::FileType fileType );
ListViewMediaItem* addMedia( const Media* clip );
void removeMedia( const QUuid& uuid );
int getIndex( ListViewMediaItem* media );
......
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