Commit cafe9d50 authored by Thomas Boquet's avatar Thomas Boquet

Refactoring Import

Import refactoring stared, not over yet
parents 2636c6cf daf161ad
......@@ -21,30 +21,102 @@
*****************************************************************************/
#include <QHash>
#include <QDomElement>
#include <QDomNamedNodeMap>
#include <QDomNodeList>
#include <QtDebug>
#include <QTextStream>
#include "SettingsManager.h"
int SettingsManager::createNewSettings()
SettingsManager::SettingsManager( QObject* parent )
: QObject( parent )
{
this->m_settings.append(new SettingsContainer());
return this->m_settings.size() - 1;
}
SettingsManager::SettingsManager( QObject* parent )
: QObject( parent )
SettingsManager::~SettingsManager()
{
}
SettingsManager::~SettingsManager()
void SettingsManager::setValues( QHash<QString, QVariant> values )
{
QHash<QString, QVariant>::iterator it = values.begin();
QHash<QString, QVariant>::iterator end = values.end();
m_lock.lockForWrite();
for ( ; it != end; ++it )
m_data.insert( it.key(), it.value() );
m_lock.unlock();
return ;
}
void SettingsManager::saveSettings( QDomDocument& xmlfile, int index )
void SettingsManager::setValue( const QString& key, QVariant& value )
{
Q_UNUSED( xmlfile )
SettingsContainer* settings = m_settings[index];
settings->lock.lockForRead();
m_lock.lockForWrite();
m_data.insert( key, value );
m_lock.unlock();
return ;
}
//SAVE SETTINGS TO DomDocument
settings->lock.unlock();
const QVariant SettingsManager::getValue( const QString& key ) const
{
m_lock.lockForRead();
QVariant value = m_data[key];
m_lock.unlock();
return value;
}
void SettingsManager::saveSettings( QDomDocument& xmlfile, QDomElement& root )
{
m_lock.lockForRead();
//SAVE SETTINGS TO DomDocument
QHash<QString, QVariant>::iterator it = m_data.begin();
QHash<QString, QVariant>::iterator end = m_data.end();
QDomElement settingsNode = xmlfile.createElement( "settings" );
for ( ; it != end; ++it )
{
QDomElement elem = xmlfile.createElement( it.key() );
elem.setAttribute( "value", it.value().toString() );
settingsNode.appendChild( elem );
}
m_lock.unlock();
//DEBUG
{
QTextStream stream( stdout );
stream << settingsNode;
}
root.appendChild( settingsNode );
}
void SettingsManager::loadSettings( const QDomElement& settings )
{
qDebug() << "Loading settings";
if ( settings.isNull() == true || settings.tagName() != "settings" )
{
qWarning() << "Invalid settings node";
return ;
}
//Loading all the settings
m_lock.lockForWrite();
QDomNodeList list = settings.childNodes();
int nbChild = list.size();
for ( int idx = 0; idx < nbChild; ++idx )
{
QDomNamedNodeMap attrMap = list.at( idx ).attributes();
if ( attrMap.count() > 1 )
{
qWarning() << "Invalid number of attributes for" << list.at( idx ).nodeName();
return ;
}
m_data.insert( list.at( idx ).toElement().tagName(),
QVariant( attrMap.item( 0 ).nodeValue() ));
}
m_lock.unlock();
emit settingsLoaded();
}
......@@ -33,31 +33,29 @@
#include "QSingleton.hpp"
struct SettingsContainer
{
QReadWriteLock lock;
QHash<QString, QVariant> settings;
};
class SettingsManager : public QObject, public QSingleton<SettingsManager>
{
//Q_OBJECT
//
friend class QSingleton<SettingsManager>;
public:
int createNewSettings();
void setValues( QHash<QString, QVariant>, int index );
void setValue( const QString& key, QVariant& value, int index );
QVariant& getValue( const QString& key );
private:
SettingsManager( QObject* parent = 0 );
Q_OBJECT
Q_DISABLE_COPY( SettingsManager )
friend class QSingleton<SettingsManager>;
public:
void setValues( QHash<QString, QVariant> );
void setValue( const QString& key, QVariant& value );
const QVariant getValue( const QString& key ) const;
void saveSettings( QDomDocument& xmlfile, QDomElement& root );
void loadSettings( const QDomElement& settings );
private:
SettingsManager( QObject* parent = 0 );
~SettingsManager();
QVector<SettingsContainer*> m_settings;
QHash<QString, QVariant> m_data;
mutable QReadWriteLock m_lock;
public slots:
void saveSettings( QDomDocument& xmlfile, int index );
signals:
void settingsLoaded();
};
......
......@@ -21,6 +21,7 @@
*****************************************************************************/
#include "AudioProjectPreferences.h"
#include "SettingsManager.h"
#include "QDebug"
......@@ -32,13 +33,17 @@
AudioProjectPreferences::~AudioProjectPreferences() { }
bool AudioProjectPreferences::load()
void AudioProjectPreferences::load()
{
qDebug() << "Loading AudioProjectPreferences values";
return true;
qDebug() << "Loading preferences : Audio";
int sampleRate = SettingsManager::getInstance()->getValue( "AudioSampleRate" ).toInt();
m_ui.SampleRate->setValue( sampleRate );
return ;
}
void AudioProjectPreferences::save( QHash<QString, QVariant>& settings )
{
settings.insert( "AudioSampleRate", m_ui.SampleRate->value() );
settings.insert( "AudioSampleRate", m_ui.SampleRate->value() );
return ;
}
......@@ -34,7 +34,7 @@ class AudioProjectPreferences : public PreferenceWidget
public:
AudioProjectPreferences( QWidget *parent = 0 );
~AudioProjectPreferences();
bool load();
void load();
void save( QHash<QString, QVariant>& settings );
private:
Ui::AudioProjectPreferences m_ui;
......
......@@ -73,6 +73,7 @@ void Import::setUIMetaData( QUuid uuid )
m_ui->durationValueLabel->setText( duration.toString( "hh:mm:ss" ) );
//Filename || title
m_ui->nameValueLabel->setText( m_mediaList[uuid]->getFileInfo()->fileName() );
m_ui->nameValueLabel->setWordWrap( true );
setWindowTitle( m_mediaList[uuid]->getFileInfo()->fileName() + " " + tr( "properties" ) );
//Resolution
m_ui->resolutionValueLabel->setText( QString::number( m_mediaList[uuid]->getWidth() )
......@@ -110,10 +111,16 @@ void Import::changeEvent( QEvent *e )
void Import::clipViewRequested( QWidget* sender, QMouseEvent* ev )
{
MediaCellView* cell = qobject_cast<MediaCellView*>(sender->parent());
ImportMediaListController* clipListView = m_importBrowser->getClipListView();
if ( cell == NULL )
return;
m_importBrowser->getClipListView()->cleanAll();
clipListView->cleanAll();
Media* media = m_mediaList[cell->uuid()];
delete clipListView;
clipListView = new ImportMediaListController(m_importBrowser->getStackViewController());
m_importBrowser->getClipListView()->addClipsFromMedia( media );
m_importBrowser->getStackViewController()->pushViewController( m_importBrowser->getClipListView() );
}
#include "ImportController.h"
#include "ui_ImportController.h"
#include "ClipRenderer.h"
ImportController::ImportController(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::ImportController)
{
m_ui->setupUi(this);
m_model = new ImportModel();
m_preview = new PreviewWidget( new ClipRenderer, m_ui->previewContainer );
m_stackNav = new StackViewController( m_ui->stackViewContainer, false );
m_mediaListController = new ImportMediaListController( m_stackNav );
m_tag = new TagWidget( m_ui->tagContainer, 6 );
m_filesModel = new QDirModel();
m_stackNav->pushViewController( m_mediaListController );
QStringList filters;
//Video
filters << "*.mov" << "*.avi" << "*.mkv" << "*.mpg" << "*.mpeg" << "*.wmv" << "*.mp4";
//Audio
filters << "*.mp3" << "*.oga" << "*.flac" << "*.aac" << "*.wav";
//Picture
filters << "*.gif" << "*.png" << "*.jpg";
m_filesModel->setFilter( QDir::AllDirs | QDir::Files | QDir::Readable | QDir::NoDotAndDotDot );
m_filesModel->sort( 2, Qt::AscendingOrder );
m_filesModel->sort( 0, Qt::AscendingOrder );
m_filesModel->setNameFilters( filters );
m_ui->treeView->setModel( m_filesModel );
m_ui->treeView->setRootIndex( m_filesModel->index( QDir::rootPath() ) );
m_ui->treeView->setCurrentIndex( m_filesModel->index( QDir::homePath() ) );
m_ui->treeView->setExpanded( m_ui->treeView->currentIndex() , true );
m_ui->treeView->setColumnHidden( 1, true );
m_ui->treeView->setColumnHidden( 2, true );
m_ui->treeView->setColumnHidden( 3, true );
m_ui->forwardButton->setEnabled( false );
m_fsWatcher = new QFileSystemWatcher();
m_fsWatcher->addPath( QDir::homePath() );
m_currentlyWatchedDir = QDir::homePath();
connect( m_fsWatcher, SIGNAL( directoryChanged( QString ) ), m_filesModel, SLOT( refresh() ) );
connect( m_ui->treeView, SIGNAL( clicked( QModelIndex ) ), this, SLOT( treeViewClicked( QModelIndex ) ) );
connect( m_ui->treeView, SIGNAL( doubleClicked( QModelIndex ) ), this, SLOT( treeViewDoubleClicked( QModelIndex ) ) );
connect( m_ui->forwardButton, SIGNAL( clicked() ), this, SLOT( forwardButtonClicked() ) );
connect( m_model, SIGNAL( newMediaLoaded( Media* ) ), this, SLOT( newMediaLoaded( Media* ) ) );
}
ImportController::~ImportController()
{
delete m_ui;
delete m_model;
delete m_stackNav;
delete m_tag;
}
void ImportController::changeEvent( QEvent *e )
{
QDialog::changeEvent( e );
switch ( e->type() ) {
case QEvent::LanguageChange:
m_ui->retranslateUi( this );
break;
default:
break;
}
}
void ImportController::newMediaLoaded( Media* media )
{
Q_UNUSED( media );
qDebug() << media->getFileName();
}
void ImportController::updateMediaRequested( Media* media )
{
Q_UNUSED( media );
}
void ImportController::forwardButtonClicked()
{
m_model->loadFile(m_filesModel->fileInfo( m_ui->treeView->selectionModel()->currentIndex() ).filePath());
}
void ImportController::treeViewClicked( const QModelIndex& index )
{
if ( m_filesModel->isDir( index ) )
{
m_fsWatcher->removePath( m_currentlyWatchedDir );
m_currentlyWatchedDir = m_filesModel->filePath( index );
m_fsWatcher->addPath( m_filesModel->filePath( index ) );
}
m_ui->forwardButton->setEnabled( true );
}
void ImportController::treeViewDoubleClicked( const QModelIndex& index )
{
if ( !m_filesModel->isDir( index ) )
forwardButtonClicked();
}
#ifndef IMPORTCONTROLLER_H
#define IMPORTCONTROLLER_H
#include <QDialog>
#include <QDirModel>
#include <QFileSystemWatcher>
#include "Media.h"
#include "Clip.h"
#include "ImportModel.h"
#include "PreviewWidget.h"
#include "StackViewController.h"
#include "TagWidget.h"
#include "ImportMediaListController.h"
namespace Ui {
class ImportController;
}
class ImportController : public QDialog {
Q_OBJECT
public:
ImportController(QWidget *parent = 0);
~ImportController();
protected:
void changeEvent(QEvent *e);
private:
Ui::ImportController* m_ui;
PreviewWidget* m_preview;
ImportModel* m_model;
StackViewController* m_stackNav;
TagWidget* m_tag;
ImportMediaListController* m_mediaListController;
QDirModel* m_filesModel;
QFileSystemWatcher* m_fsWatcher;
QString m_currentlyWatchedDir;
public slots:
void newMediaLoaded( Media* media );
void updateMediaRequested( Media* media );
private slots:
void forwardButtonClicked();
void treeViewClicked( const QModelIndex& index );
void treeViewDoubleClicked( const QModelIndex& index);
};
#endif // IMPORTCONTROLLER_H
#include <QDebug>
#include <QDir>
#include "ImportModel.h"
ImportModel::ImportModel()
{
m_medias = new QHash<QUuid, Media*>();
}
ImportModel::~ImportModel()
{
QUuid id;
foreach ( id, m_medias->keys() )
delete m_medias->value( id );
}
const Media* ImportModel::getMedia( const QUuid& mediaId ) const
{
return m_medias->value( mediaId );
}
const Clip* ImportModel::getClip( const QUuid& mediaId, const QUuid& clipId ) const
{
Media* media = m_medias->value( mediaId );
if ( !media )
return NULL;
return media->clip( clipId );
}
void ImportModel::cutMedia( const QUuid& mediaId, int frame )
{
Q_UNUSED( mediaId );
Q_UNUSED( frame );
}
void ImportModel::cutClip( const QUuid& mediaId, const QUuid& clipId, int frame )
{
Q_UNUSED( mediaId );
Q_UNUSED( clipId );
Q_UNUSED( frame );
}
void ImportModel::metaDataComputed( Media* media )
{
qDebug() << "Meta computed";
emit newMediaLoaded( media );
}
void ImportModel::loadMedia( Media* media )
{
if ( !m_medias->contains( media->getUuid() ) )
{
m_medias->insert( media->getUuid(), media );
//emit mediaAdded( media, m_mediaList->getCell( media->getUuid() ) );
connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ) );
m_metaDataWorker = new MetaDataWorker( media );
m_metaDataWorker->start();
}
else
delete media;
}
void ImportModel::loadFile( const QFileInfo& fileInfo )
{
Media* media;
if ( !fileInfo.isDir() )
{
media = new Media( fileInfo.filePath() );
loadMedia( media );
}
else
{
QDir dir = QDir( fileInfo.filePath() );
for( int i = 0; i < dir.count() ; i++)
{
QFileInfo info = QFileInfo(dir.filePath( dir[i] ) );
//qDebug() << info.filePath();
if ( info.isDir() )
continue ;
//qDebug() << "not a dir [" << info.fileName() << "]";
media = new Media( info.filePath() );
loadMedia( media );
}
}
}
void ImportModel::removeMedia( const QUuid& mediaId)
{
m_medias->remove( mediaId );
}
void ImportModel::removeClip( const QUuid& mediaId, const QUuid& clipId )
{
if ( ! m_medias->contains( mediaId ) )
return ;
m_medias->value( mediaId )->removeClip( clipId );
}
#ifndef IMPORTMODEL_H
#define IMPORTMODEL_H
#include <QObject>
#include <QHash>
#include "Media.h"
#include "Clip.h"
#include "MetaDataWorker.h"
class ImportModel : public QObject
{
Q_OBJECT
public:
ImportModel();
~ImportModel();
const Media* getMedia( const QUuid& mediaId ) const;
const Clip* getClip( const QUuid& mediaId, const QUuid& clipId ) const;
void cutMedia( const QUuid& mediaId, int frame );
void cutClip( const QUuid& mediaId, const QUuid& clipId, int frame );
void loadFile( const QFileInfo& fileInfo );
void removeMedia( const QUuid& mediaId );
void removeClip( const QUuid& mediaId, const QUuid& clipId );
signals:
void newMediaLoaded( Media* media );
void updateMediaRequested( Media* media );
private:
QHash<QUuid, Media*>* m_medias;
MetaDataWorker* m_metaDataWorker;
void loadMedia( Media* media );
private slots:
void metaDataComputed( Media* media );
};
#endif // IMPORTMODEL_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportController</class>
<widget class="QDialog" name="ImportController">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>888</width>
<height>661</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeView" name="treeView"/>
</item>
<item>
<widget class="QPushButton" name="forwardButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset>
<normaloff>:/images/forward</normaloff>:/images/forward</iconset>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="stackViewContainer" native="true">
<property name="minimumSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="baseSize">
<size>
<width>250</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QWidget" name="previewContainer" native="true">
<property name="minimumSize">
<size>
<width>328</width>
<height>340</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>340</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Media Properties</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="nameValueLabel">
<property name="text">
<string>unnamed</string>
</property>
</widget>
</item>
<item row="1" column="0">