Library.cpp 6.11 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 41
#include <QDomElement>
#include <QHash>
#include <QUuid>

void
Library::loadProject( const QDomElement& medias )
42 43 44 45 46 47 48 49 50 51
{
    if ( medias.isNull() == true || medias.tagName() != "medias" )
    {
        qWarning() << "Invalid medias node";
        return ;
    }

    QDomElement elem = medias.firstChild().toElement();
    while ( elem.isNull() == false )
    {
52
        QList<QDomElement>  clipList;
53 54 55 56 57 58 59 60 61 62 63
        QDomElement mediaProperty = elem.firstChild().toElement();
        QString     path;
        QString     uuid;

        while ( mediaProperty.isNull() == false )
        {
            QString tagName = mediaProperty.tagName();
            if ( tagName == "path" )
                path = mediaProperty.text();
            else if ( tagName == "uuid" )
                uuid = mediaProperty.text();
64 65 66 67 68 69 70 71 72
            else if ( tagName == "clips" )
            {
                QDomElement clip = mediaProperty.firstChild().toElement();
                while ( clip.isNull() == false )
                {
                    clipList.push_back( clip );
                    clip = clip.nextSibling().toElement();
                }
            }
73 74 75 76
            else
                qWarning() << "Unknown field" << tagName;
            mediaProperty = mediaProperty.nextSibling().toElement();
        }
77 78 79
        //FIXME: This is verry redondant...
        if ( mediaAlreadyLoaded( path ) == true )
        {
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
80 81
            QHash<QUuid, Clip*>::iterator   it = m_clips.begin();
            QHash<QUuid, Clip*>::iterator   end = m_clips.end();
82 83 84

            for ( ; it != end; ++it )
            {
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
85
                if ( it.value()->getMedia()->fileInfo()->absoluteFilePath() == path )
86
                {
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
87 88 89 90
                    Clip*   clip = it.value();
                    clip->setUuid( QUuid( uuid ) );
                    m_clips.erase( it );
                    m_clips[clip->uuid()] = clip;
91 92 93 94 95 96
                    break ;
                }
            }
        }
        else
        {
97 98 99 100 101
            if ( addMedia( path, uuid ) == false )
            {
                elem = elem.nextSibling().toElement();
                continue ;
            }
102
        }
103 104 105 106 107 108 109 110 111 112 113 114
        if ( clipList.size() != 0 )
        {
            foreach( QDomElement clip, clipList )
            {
                QString parentUuid = clip.attribute( "parentUuid", "");
                if ( parentUuid != "" && parentUuid == uuid )
                {
                    QString beg = clip.attribute( "begin", "" );
                    QString end = clip.attribute( "end", "" );
                    QString clipUuid = clip.attribute( "uuid", "" );
                    if ( beg != "" && end != "" && uuid != "" )
                    {
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
115 116 117 118 119
                        if ( m_clips.contains( uuid ) == false )
                            continue ;
                        Clip* parentClip = m_clips[QUuid( uuid )];
                        Clip* clip = new Clip( parentClip, beg.toInt(), end.toInt(), QUuid( clipUuid ) );
                        parentClip->addSubclip( clip );
120 121 122 123
                    }
                }
            }
        }
124 125
        elem = elem.nextSibling().toElement();
    }
126
    emit projectLoaded();
127 128
}

129 130
void
Library::saveProject( QDomDocument& doc, QDomElement& rootNode )
131
{
Hugo Beauzee-Luyssen's avatar
Hugo Beauzee-Luyssen committed
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
//    QHash<QUuid, Media*>::iterator          it = m_clips.begin();
//    QHash<QUuid, Media*>::iterator          end = m_clips.end();
//
//    QDomElement medias = doc.createElement( "medias" );
//
//    for ( ; it != end; ++it )
//    {
//        QDomElement media = doc.createElement( "media" );
//
//        medias.appendChild( media );
//        QDomElement mrl = doc.createElement( "path" );
//
//        QDomCharacterData text;
//        text = doc.createTextNode( it.value()->fileInfo()->absoluteFilePath() );
//
//        QDomElement uuid = doc.createElement( "uuid" );
//        QDomCharacterData text2 = doc.createTextNode( it.value()->baseClip()->uuid().toString() );
//
//        mrl.appendChild( text );
//        uuid.appendChild( text2 );
//
//        media.appendChild( mrl );
//        media.appendChild( uuid );
//        //Creating the clip branch
//        if ( it.value()->clipsCount() != 0 )
//        {
//            QDomElement clips = doc.createElement( "clips" );
//            foreach( Clip* c, it.value()->clips().values() )
//            {
//                QDomElement clip = doc.createElement( "clip" );
//                clip.setAttribute( "begin", c->begin() );
//                clip.setAttribute( "end", c->end() );
//                clip.setAttribute( "uuid", c->uuid() );
//                clip.setAttribute( "parentUuid", c->getMedia()->baseClip()->uuid() );
//                clips.appendChild( clip );
//            }
//            media.appendChild( clips );
//        }
//    }
//    rootNode.appendChild( medias );
    #warning "FIXME: Project saving";
173
}