ImportModel.cpp 3.42 KB
Newer Older
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*****************************************************************************
 * ImportModel.cpp
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Geoffroy Lacarriere <geoffroylaca@gmail.com>
 *          Thomas Boquet <thomas.boquet@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

Thomas Boquet's avatar
Thomas Boquet committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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 );
}

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
42
Media*    ImportModel::getMedia( const QUuid& mediaId ) const
Thomas Boquet's avatar
Thomas Boquet committed
43
44
45
46
{
    return m_medias->value( mediaId );
}

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
47
Clip*     ImportModel::getClip( const QUuid& mediaId, const QUuid& clipId ) const
Thomas Boquet's avatar
Thomas Boquet committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{
    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 )
{
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
72
    emit updateMediaRequested( media );
Thomas Boquet's avatar
Thomas Boquet committed
73
74
75
76
}

void            ImportModel::loadMedia( Media* media )
{
77
78
79
80
    m_medias->insert( media->getUuid(), media );
    emit newMediaLoaded( media );
    connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ) );
    m_metaDataWorker = new MetaDataWorker( media );
81
    m_metaDataWorker->compute();
82
83
84
85
86
87
88
89
90
}

bool        ImportModel::mediaAlreadyLoaded( const QFileInfo& fileInfo )
{
    QUuid id;
    foreach(id, m_medias->keys())
        if ( m_medias->value( id )->getFileInfo()->filePath() == fileInfo.filePath() )
            return true;
    return false;
Thomas Boquet's avatar
Thomas Boquet committed
91
92
93
94
95
96
97
98
}

void            ImportModel::loadFile( const QFileInfo& fileInfo )
{
    Media* media;

    if ( !fileInfo.isDir() )
    {
99
100
101
102
103
        if ( !mediaAlreadyLoaded( fileInfo ) )
        {
           media = new Media( fileInfo.filePath() );
           loadMedia( media );
        }
Thomas Boquet's avatar
Thomas Boquet committed
104
105
106
107
    }
    else
    {
        QDir dir = QDir( fileInfo.filePath() );
108
109
110
111
112
        QFileInfoList list = dir.entryInfoList( m_filters );
        QFileInfo file;

        foreach( file, list )
            loadFile( file );
Thomas Boquet's avatar
Thomas Boquet committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    }
}

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 );
}