Library.cpp 2.64 KB
Newer Older
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************
 * Library.cpp: Multimedia library
 *****************************************************************************
 * Copyright (C) 2008-2009 the VLMC team
 *
 * Authors: Hugo Beauzee-Luyssen <hugo@vlmc.org>
 *
 * 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.
 *****************************************************************************/

23 24 25
/** \file
  * This file the library contains class implementation.
  * It's the the backend part of the Library widget of vlmc.
26
  * It can load and unload Medias (Medias.h/Media.cpp)
27 28
  */

Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
29 30 31 32 33 34 35
#include <QtDebug>
#include "Library.h"

Library::Library()
{
}

36
Media*          Library::getMedia( const QUuid& uuid )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
37
{
38
    return getElementByUuid( m_medias, uuid );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
39 40
}

41
Clip*           Library::getClip( const QUuid& uuid )
42
{
43
    return getElementByUuid( m_clips, uuid );
44 45
}

46
void        Library::removingMediaAsked( const QUuid& uuid )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
47
{
48
    QMutexLocker locker( &m_mutex );
49 50
    QHash<QUuid, Media*>::iterator   it = m_medias.find( uuid );
    if ( it == m_medias.end() )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
51
        return ;
52
    emit mediaRemoved( uuid );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
53 54 55
    //TODO: this is obviously a memleak, but at the moment, the library depends on the clip to work,
    //and won't be abble to remove the ListViewMediaItem without it.
    //delete *it;
56
    m_medias.erase( it );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
57 58
}

59 60
void        Library::metaDataComputed( Media* media )
{
61
    Clip* clip = new Clip( media );
62 63 64 65
    m_clips[clip->getUuid()] = clip;
    emit newClipLoaded( clip );
}

66
void        Library::newMediaLoadingAsked( const QString& filePath )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
67
{
68
    //Is this necessary ??
69
    QMutexLocker locker( &m_mutex );
70 71
    Media*   media;
    foreach ( media, m_medias )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
72
    {
73
        if ( media->getFileInfo()->absoluteFilePath() == filePath )
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
74 75
            return ;
    }
76
    media = new Media( filePath );
77
    m_medias[media->getUuid()] = media;
78
    connect( media, SIGNAL( metaDataComputed( Media* ) ), this, SLOT( metaDataComputed( Media* ) ), Qt::DirectConnection );
79
    emit newMediaLoaded( media );
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
80
}