Library.cpp 3.66 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"
34 35
#include "SettingsManager.h"
#include "Workspace.h"
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
36

37
#include <QtDebug>
38 39 40 41 42
#include <QDomElement>
#include <QHash>
#include <QUuid>

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

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

50 51 52
    //Add a virtual media, which represents all the clip.
    //This avoid emitting projectLoaded(); before all the clip are actually loaded.
    m_nbMediaToLoad = 1;
53 54
    QDomElement media = medias.firstChild().toElement();
    while ( media.isNull() == false )
55
    {
56
        if ( media.hasAttribute( "mrl" ) == true )
57
        {
58
            QString mrl = media.attribute( "mrl" );
59 60 61 62 63 64 65 66

            //If in workspace: compute the path in workspace
            if ( mrl.startsWith( Workspace::workspacePrefix ) == true )
            {
                QString     projectPath = VLMC_PROJECT_GET_STRING( "general/ProjectDir" );
                mrl = projectPath + '/' + mrl.mid( Workspace::workspacePrefix.length() );
            }
            Media*  m = addMedia( mrl );
67 68
            connect( m, SIGNAL( metaDataComputed( const Media* ) ),
                     this, SLOT( mediaLoaded( const Media* ) ), Qt::QueuedConnection );
69
            m_medias[mrl] = m;
70
            m_nbMediaToLoad.fetchAndAddAcquire( 1 );
71
        }
72
        media = media.nextSibling().toElement();
73
    }
74 75 76 77
    const QDomElement   clips = doc.firstChildElement( "clips" );
    if ( clips.isNull() == true )
        return ;
    load( clips, this );
78
    mediaLoaded( NULL );
79
}
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

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();
97
}
98 99 100 101

void
Library::mediaLoaded( const Media* media )
{
102 103 104 105 106
    if ( media != NULL )
    {
        disconnect( media, SIGNAL( metaDataComputed( const Media* ) ),
                 this, SLOT( mediaLoaded( const Media* ) ) );
    }
107
    m_nbMediaToLoad.fetchAndAddAcquire( -1 );
108 109 110
    if ( m_nbMediaToLoad == 0 )
        emit projectLoaded();
}
111