Library.cpp 3.27 KB
Newer Older
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
1 2 3
/*****************************************************************************
 * Library.cpp: Multimedia library
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * 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
  * It can load and unload Clips (Clip.h/Clip.cpp)
28 29
  */

30
#include "Clip.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
31
#include "Library.h"
Ludovic Fauvet's avatar
Ludovic Fauvet committed
32
#include "Media.h"
33
#include "MetaDataManager.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
34

35
#include <QtDebug>
36 37 38 39 40
#include <QDomElement>
#include <QHash>
#include <QUuid>

void
41
Library::loadProject( const QDomElement& doc )
42
{
43 44 45
    const QDomElement   medias = doc.firstChildElement( "medias" );

    if ( medias.isNull() == true )
46 47
        return ;

48 49 50
    //Add a virtual media, which represents all the clip.
    //This avoid emitting projectLoaded(); before all the clip are actually loaded.
    m_nbMediaToLoad = 1;
51 52
    QDomElement media = medias.firstChild().toElement();
    while ( media.isNull() == false )
53
    {
54
        if ( media.hasAttribute( "mrl" ) == true )
55
        {
56 57
            QString mrl = media.attribute( "mrl" );
            Media* m = addMedia( mrl );
58 59
            connect( m, SIGNAL( metaDataComputed( const Media* ) ),
                     this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
60
            m_medias[mrl] = m;
61
            m_nbMediaToLoad.fetchAndAddAcquire( 1 );
62
        }
63
        media = media.nextSibling().toElement();
64
    }
65 66 67 68
    const QDomElement   clips = doc.firstChildElement( "clips" );
    if ( clips.isNull() == true )
        return ;
    load( clips, this );
69
    mediaLoaded( NULL );
70
}
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

void
Library::saveProject( QXmlStreamWriter& project )
{
    QHash<QUuid, Clip*>::const_iterator     it = m_clips.begin();
    QHash<QUuid, Clip*>::const_iterator     end = m_clips.end();

    project.writeStartElement( "medias" );
    while ( it != end )
    {
        it.value()->getMedia()->save( project );
        ++it;
    }
    project.writeEndElement();
    project.writeStartElement( "clips" );
    save( project );
    project.writeEndElement();
88
}
89 90 91 92

void
Library::mediaLoaded( const Media* media )
{
93 94 95 96 97
    if ( media != NULL )
    {
        disconnect( media, SIGNAL( metaDataComputed( const Media* ) ),
                 this, SLOT( mediaLoaded( const Media* ) ) );
    }
98
    m_nbMediaToLoad.fetchAndAddAcquire( -1 );
99 100 101
    if ( m_nbMediaToLoad == 0 )
        emit projectLoaded();
}
102