ImportMediaListController.cpp 4.06 KB
Newer Older
1 2 3
/*****************************************************************************
 * ImportMediaListController.cpp
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7
 *
 * Authors: Geoffroy Lacarriere <geoffroylaca@gmail.com>
 *          Thomas Boquet <thomas.boquet@gmail.com>
8
 *          Clement CHAVANCE <chavance.c@gmail.com>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 *
 * 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.
 *****************************************************************************/

25
#include "ImportMediaListController.h"
26
#include "MediaCellView.h"
27

28 29
ImportMediaListController::ImportMediaListController( StackViewController* nav ) :
        ListViewController( nav ), m_nav( nav ), m_clipDeleted( 0 )
30
{
31
    m_mediaCellList = new QHash<QUuid, MediaCellView*>();
32 33 34 35 36 37 38
}

ImportMediaListController::~ImportMediaListController()
{
    delete m_mediaCellList;
}

39 40
void
ImportMediaListController::addMedia( Media* media )
41
{
42
    MediaCellView* cell = new MediaCellView( media->baseClip() );
43 44 45 46 47 48
    connect( cell, SIGNAL( cellSelected( const QUuid& ) ),
             this, SIGNAL( mediaSelected( const QUuid& ) ) );
    connect( cell, SIGNAL( cellDeleted( const QUuid& ) ),
             this, SIGNAL( mediaDeleted( const QUuid& ) ) );
    connect( cell, SIGNAL( arrowClicked( const QUuid& ) ),
             this, SIGNAL( showClipListAsked( const QUuid& ) ) );
49 50
    connect( media, SIGNAL( clipAdded(Clip*) ),
             this, SLOT( clipAdded( Clip* ) ) );
51 52 53

    addCell( cell );

54
    m_mediaCellList->insert( media->baseClip()->uuid(), cell );
55 56
}

57
MediaCellView*
58
ImportMediaListController::cell( QUuid uuid ) const
59
{
60 61 62 63 64
    if (m_mediaCellList->contains( uuid ) )
        return m_mediaCellList->value( uuid );
    return NULL;
}

65 66
bool
ImportMediaListController::contains( QUuid uuid )
67 68
{
    return m_mediaCellList->contains( uuid );
69
}
70

71 72
void
ImportMediaListController::removeMedia( const QUuid& uuid )
73
{
74
    const QUuid saveUuid = uuid;
75
    removeCell( m_mediaCellList->value( uuid ) );
76
    m_mediaCellList->remove( saveUuid );
77 78
}

79 80
void
ImportMediaListController::addClip( Clip* clip )
81
{
82
    MediaCellView* cell = new MediaCellView( clip );
83
    cell->containsClip();
84 85 86 87
    connect( cell, SIGNAL( cellSelected( const QUuid& ) ),
             this, SIGNAL( clipSelected( const QUuid& ) ) );
    connect( cell, SIGNAL( cellDeleted( const QUuid& ) ),
             this, SLOT( clipDeletion( const QUuid& ) ) );
88 89

    addCell( cell );
90
    m_mediaCellList->insert( clip->uuid(), cell );
91 92
}

93 94
void
ImportMediaListController::removeClip( const QUuid& uuid )
95 96 97 98 99
{
    removeCell( m_mediaCellList->value( uuid ) );
    m_mediaCellList->remove( uuid );
}

100 101
void
ImportMediaListController::cleanAll()
102
{
103
    foreach( MediaCellView* cell, m_mediaCellList->values() )
104
        removeCell( cell );
105 106 107
    m_mediaCellList->clear();
}

108 109
void
ImportMediaListController::addClipsFromMedia( Media* media )
110
{
111 112
    foreach( Clip* clip, media->clips().values() )
        addClip( clip );
113
}
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
114

115 116
void
ImportMediaListController::clipDeletion( const QUuid& uuid )
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
117
{
118
    m_clipDeleted += 1;
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
119 120 121
    emit clipDeleted( uuid );
}

122 123
void
ImportMediaListController::clipAdded( Clip* clip )
124 125 126
{
    if ( clip->getParent() == 0 )
        return ;
127
    const QUuid& uuid = clip->getParent()->baseClip()->uuid();
128 129 130 131
    if ( m_mediaCellList->contains( uuid ) )
        m_mediaCellList->value( uuid )->incrementClipCount();
}

132
const QHash<QUuid, MediaCellView*>*
133
ImportMediaListController::mediaCellList() const
134
{
135
    return m_mediaCellList;
136
}