Library.cpp 3.09 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
#include <QDomElement>
#include <QHash>
#include <QUuid>
39
#include <QXmlStreamWriter>
40 41

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

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

49
    m_nbMediaToLoad = 0;
50 51
    QDomElement media = medias.firstChild().toElement();
    while ( media.isNull() == false )
52
    {
53
        if ( media.hasAttribute( "mrl" ) == true )
54
        {
55 56
            QString mrl = media.attribute( "mrl" );
            Media* m = addMedia( mrl );
57 58
            connect( m, SIGNAL( metaDataComputed( const Media* ) ),
                     this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
59
            m_medias[mrl] = m;
60
            m_nbMediaToLoad.fetchAndAddAcquire( 1 );
61
        }
62
        media = media.nextSibling().toElement();
63
    }
64 65 66 67 68
    const QDomElement   clips = doc.firstChildElement( "clips" );
    if ( clips.isNull() == true )
        return ;
    load( clips, this );
}
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

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();
86
}
87 88 89 90 91 92

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