Commit 28613300 authored by Christophe Courtaut's avatar Christophe Courtaut

Cleaning up the media Library code

parent 27b56328
......@@ -3,7 +3,8 @@
*****************************************************************************
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Ludovic Fauvet <etix@l0cal.com>
* Authors: Clement CHAVANCE <chavance.c@gmail.com>
* Christophe Courtaut <christophe.courtaut@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -23,64 +24,101 @@
#include <QDir>
#include "LibraryWidget.h"
QList<ListViewMediaItem*>* LibraryWidget::m_medias = NULL;
LibraryWidget::LibraryWidget( QWidget *parent ) : QWidget( parent )
{
m_ui.setupUi( this );
if ( LibraryWidget::m_medias == NULL )
LibraryWidget::m_medias = new QList<ListViewMediaItem*>();
}
void LibraryWidget::on_pushButtonAddMedia_clicked()
ListViewMediaItem* LibraryWidget::addMedia( QFileInfo* fileInfo, ListViewMediaItem::fType fileType )
{
QFileInfo* fileInfo = NULL;
QListWidgetItem* item;
qDebug() << m_ui.LibraryTabs->currentIndex();
switch( m_ui.LibraryTabs->currentIndex() )
ListViewMediaItem* item = new ListViewMediaItem( fileInfo, fileType );
m_medias->append( item );
switch ( fileType )
{
case 0:
fileInfo = new QFileInfo( QFileDialog::getOpenFileName(
this,
tr( "Open Audios" ),
QDir::homePath(),
tr( "Audio Files (*.mp3 *.oga *.flac *.aac *.wav)" ) ) );
m_ui.listWidgetAudio->addItem( new ListViewMediaItem( fileInfo ) );
case ListViewMediaItem::Audio:
m_ui.listWidgetAudio->addItem( item );
break;
case 1:
fileInfo = new QFileInfo( QFileDialog::getOpenFileName(
this,
tr( "Open Videos" ),
QDir::homePath(),
tr( "Video Files (*.mov *.avi *.mkv)" ) ) );
m_ui.listWidgetVideo->addItem( new ListViewMediaItem( fileInfo ) );
break;
case 2:
fileInfo = new QFileInfo( QFileDialog::getOpenFileName(
this,
tr( "Open Images" ),
QDir::homePath(),
tr( "Video Files (*.gif *.png *.jpg)" ) ) );
m_ui.listWidgetImage->addItem( new ListViewMediaItem( fileInfo ) );
case ListViewMediaItem::Video:
m_ui.listWidgetVideo->addItem( item );
break;
default:
case ListViewMediaItem::Image:
m_ui.listWidgetImage->addItem( item );
break;
}
m_ui.listWidgetAll->addItem( new ListViewMediaItem( fileInfo ) );
return item;
}
void LibraryWidget::on_LibraryTabs_currentChanged( int index )
bool LibraryWidget::removeMedia(ListViewMediaItem* item)
{
if ( index == 3 )
if ( m_medias->contains( item ) )
{
m_ui.pushButtonAddMedia->setEnabled( false );
m_ui.pushButtonRemoveMedia->setEnabled( false );
switch( item->fileType )
{
case ListViewMediaItem::Audio:
this->m_ui.listWidgetAudio->removeItemWidget( item );
break;
case ListViewMediaItem::Image:
this->m_ui.listWidgetImage->removeItemWidget( item );
break;
case ListViewMediaItem::Video:
this->m_ui.listWidgetVideo->removeItemWidget( item );
break;
}
return m_medias->removeOne( item );
}
else
return false;
}
ListViewMediaItem* LibraryWidget::insertNewMediaFromFileDialog( QString title, QString filter, ListViewMediaItem::fType fileType )
{
QString fileName = QFileDialog::getOpenFileName( this, title, QDir::homePath(), filter);
if ( fileName == "" )
return NULL;
QFileInfo* fileInfo = new QFileInfo( fileName );
ListViewMediaItem* item = this->addMedia( fileInfo, fileType );
return item;
}
void LibraryWidget::on_pushButtonAddMedia_clicked()
{
switch( m_ui.LibraryTabs->currentIndex() )
{
m_ui.pushButtonAddMedia->setEnabled( true );
m_ui.pushButtonRemoveMedia->setEnabled( true );
case 0:
insertNewMediaFromFileDialog( tr( "Open Audios" ),
tr( "Audio Files (*.mp3 *.oga *.flac *.aac *.wav)" ),
ListViewMediaItem::Audio);
break;
case 1:
insertNewMediaFromFileDialog( tr( "Open Videos" ),
tr( "Video Files (*.mov *.avi *.mkv)" ),
ListViewMediaItem::Video );
break;
case 2:
insertNewMediaFromFileDialog( tr( "Open Images" ),
tr( "Images Files (*.gif *.png *.jpg)" ),
ListViewMediaItem::Image);
break;
}
}
ListViewMediaItem::ListViewMediaItem( QFileInfo* fInfo, QListWidget* parent, int type ) : QListWidgetItem( parent, type )
ListViewMediaItem::ListViewMediaItem( QFileInfo* fInfo, ListViewMediaItem::fType fType, QListWidget* parent, int type ) : QListWidgetItem( parent, type )
{
fileInfo = fInfo;
fileType = fType;
setText( fileInfo->baseName() );
}
void ListViewMediaItem::mousePressEvent( QMouseEvent* event )
{
}
void LibraryWidget::on_pushButtonRemoveMedia_clicked()
{
QListWidget* mediaList = ( QListWidget* )(this->m_ui.LibraryTabs->currentWidget()->children().back());
ListViewMediaItem* item = ( ListViewMediaItem* ) mediaList->currentItem();
this->removeMedia( item );
}
......@@ -4,6 +4,7 @@
* Copyright (C) 2008-2009 the VLMC team
*
* Authors: Clement CHAVANCE <chavance.c@gmail.com>
* Christophe Courtaut <christophe.courtaut@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -29,8 +30,27 @@
#include <QMessageBox>
#include <QFileDialog>
#include <QtDebug>
#include <QMimeData>
#include <QDrag>
#include <QList>
#include "ui_LibraryWidget.h"
class ListViewMediaItem : public QListWidgetItem
{
public:
enum fType
{
Audio,
Video,
Image
};
ListViewMediaItem( QFileInfo* fileInfo, ListViewMediaItem::fType fType, QListWidget* parent = 0, int type = Type );
QFileInfo* fileInfo;
ListViewMediaItem::fType fileType;
protected:
void mousePressEvent( QMouseEvent* event );
};
class LibraryWidget : public QWidget
{
......@@ -38,21 +58,20 @@ class LibraryWidget : public QWidget
public:
explicit LibraryWidget( QWidget *parent = 0 );
ListViewMediaItem* addMedia( QFileInfo* fileInfo, ListViewMediaItem::fType fileType );
bool removeMedia( ListViewMediaItem* item );
int getIndex( ListViewMediaItem* media );
private:
QFileInfoList videoList;
Ui::LibraryWidget m_ui;
QString getNewMediaFileName( QString title, QString filter, ListViewMediaItem::fType );
ListViewMediaItem* insertNewMediaFromFileDialog(QString title, QString filter, ListViewMediaItem::fType fileType);
Ui::LibraryWidget m_ui;
static QList<ListViewMediaItem*>* m_medias;
private slots:
void on_LibraryTabs_currentChanged( int index );
void on_pushButtonAddMedia_clicked();
void on_pushButtonRemoveMedia_clicked();
};
class ListViewMediaItem : public QListWidgetItem
{
public:
ListViewMediaItem( QFileInfo* fileInfo, QListWidget* parent = 0, int type = Type);
QFileInfo* fileInfo;
};
#endif /* !LIBRARYWIDGET_H */
......@@ -41,6 +41,15 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DropOnly</enum>
</property>
</widget>
</item>
</layout>
......@@ -52,6 +61,18 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidgetVideo">
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropOverwriteMode">
<bool>false</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DropOnly</enum>
</property>
<property name="uniformItemSizes">
<bool>true</bool>
</property>
......@@ -65,17 +86,17 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QListWidget" name="listWidgetImage"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabAll">
<attribute name="title">
<string>All</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QListWidget" name="listWidgetAll"/>
<widget class="QListWidget" name="listWidgetImage">
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DropOnly</enum>
</property>
</widget>
</item>
</layout>
</widget>
......
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