MediaContainer.h 5.15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*****************************************************************************
 * MediaContainer.h: Implements the library basics
 *****************************************************************************
 * Copyright (C) 2008-2010 VideoLAN
 *
 * 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.
 *****************************************************************************/

#ifndef MEDIACONTAINER_H
#define MEDIACONTAINER_H

#include <QHash>
#include <QObject>
#include <QUuid>
29
#include <QXmlStreamWriter>
30 31 32 33

class   Media;
class   Clip;
class   QFileInfo;
34
class   QDomElement;
35 36 37 38 39 40

class   MediaContainer : public QObject
{
    Q_OBJECT

public:
41
    MediaContainer( Clip* parent = NULL );
42
    ~MediaContainer();
43 44 45 46 47 48
    /**
     *  \brief  returns the clip that match the unique identifier
     *  \param  uuid    the unique identifier of the media
     *  \return a pointer to the required clip, or NULL if no clips matches
     */
    Clip*   clip( const QUuid& uuid );
49

50 51 52 53 54 55 56 57 58
    /**
     *  \brief  returns the clip that match the unique identifier
     *
     *  The identifier may be a full id (ie the full path, starting at the root clip)
     *  \param  uuid    the unique identifier of the media
     *  \return a pointer to the required clip, or NULL if no clips matches
     */
    Clip*   clip( const QString& uuid );

59
    /**
60 61 62 63 64
     *  \brief  Add an already preparsed media.
     *
     *  This will emit the newClipLoaded signal.
     *
     *  \param  media   The media to add to the library
65
     */
66
    virtual void        addMedia( Media *media );
67 68 69 70

    /**
     *  \brief  Add a file to the media library
     *
71
     *  This method will also handle metadata parsing.
72
     *  \param  fileInfo    the file info of the media
73 74
     *  \return             The newly create media if the media was successfully loaded.
     *                      NULL otherwise.
75 76 77 78
     *  \sa     addClip( Clip* clip )
     *  \sa     media( const QUuid& uuid)
     *  \sa     clip( const QUuid& uuid )
     */
79
    virtual Media       *addMedia( const QFileInfo& fileInfo );
80 81 82 83 84
    /**
     *  \brief  Check if a file has already been loaded into library.
     *  \param  fileInfo    The file infos
     *  \return true if the file is already loaded, false otherwhise
     */
85
    bool        mediaAlreadyLoaded( const QFileInfo& fileInfo );
86 87 88
    /**
     *  \brief  Add a clip.
     *
89 90
     *  The method will first check for an identic clip existence.
     *  This will emit the newClipLoaded signal if the Clip is added.
91 92
     *
     *  \param  clip    The clip to be added.
93
     *  \return true if the Clip has been added.
94
     */
95
    virtual bool    addClip( Clip* clip );
96

97 98 99 100 101 102 103 104 105 106
    /**
     *  \brief  Save the contained media to the given XML stream
     *
     *  This will save all contained clip. If a clip contained subclips, they will be saved
     *  too, and so on.
     *
     *  \param  project     The QXmlStreamWriter to write into.
     */
    void        save( QXmlStreamWriter& project );

107 108
    void        load( const QDomElement& root, MediaContainer *parent );

109
    /**
110
     *  \return All the loaded Clip
111
     */
112 113 114 115 116
    const QHash<QUuid, Clip*>   &clips() const;

    Clip*       getParent();

    quint32     count() const;
117 118 119 120 121

protected:
    /**
     *  \brief The List of medias loaded into the library
     */
122 123
    QHash<QUuid, Clip*>     m_clips;

124 125 126 127 128 129 130
    /**
     *  \brief  Used when loading a project.
     *
     *  This should not have an associated getter.
     */
    QHash<QString, Media*>  m_medias;

131
    Clip*                   m_parent;
132 133 134

public slots:
    /**
135 136
     *  \brief  Removes a Clip from the container and delete it
     *
137
     *  \param  uuid    The clip to remove's uuid.
138
     */
139
    void    deleteClip( const QUuid& uuid );
140
    /**
141 142
     *  \brief  Clear the library (remove all the loaded Clip, delete their subclips, and
     *          delete them)
143 144 145
     */
    void    clear();
    /**
146 147
     *  \brief      Remove all the medias from the container, but doesn't clean nor
     *              delete them.
148
     */
149
    void    removeAll();
150 151 152

signals:
    /**
153 154
     *  \brief          This signal should be emitted to tell a new Clip have been added
     *  \param Clip     The newly added clip
155
     */
156
    void    newClipLoaded( Clip* );
157
    /**
158
     *  \brief This signal should be emiteted when a Clip has been removed
159 160
     *  This signal pass a QUuid as the clip may be deleted when the signal reaches its
     *  slot.
161
     *  \param uuid The removed clip uuid
162
     */
163
    void    clipRemoved( const QUuid& );
164 165 166
};

#endif // MEDIACONTAINER_H