ImportMediaListController.cpp 4.7 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->uuid() );
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
    cell->setTitle( media->fileName() );
    cell->setThumbnail( media->snapshot() );
54
55
    addCell( cell );

56
    m_mediaCellList->insert( media->uuid(), cell );
57
    if ( media->baseClip() == NULL )
58
59
        connect( media, SIGNAL( metaDataComputed( const Media* ) ),
                 cell, SLOT( enableCell() ) );
60
61
}

62
void
63
ImportMediaListController::metaDataComputed( const Media* media )
64
{
65
    m_mediaCellList->value( media->uuid() )->setThumbnail( media->snapshot() );
66
67
}

68
MediaCellView*
69
ImportMediaListController::cell( QUuid uuid ) const
70
{
71
72
73
74
75
    if (m_mediaCellList->contains( uuid ) )
        return m_mediaCellList->value( uuid );
    return NULL;
}

76
77
bool
ImportMediaListController::contains( QUuid uuid )
78
79
{
    return m_mediaCellList->contains( uuid );
80
}
81

82
83
void
ImportMediaListController::removeMedia( const QUuid& uuid )
84
{
85
    const QUuid saveUuid = uuid;
86
    removeCell( m_mediaCellList->value( uuid ) );
87
    m_mediaCellList->remove( saveUuid );
88
89
}

90
91
void
ImportMediaListController::addClip( Clip* clip )
92
{
93
    MediaCellView* cell = new MediaCellView( clip->uuid() );
94
    cell->containsClip();
95
96
97
98
    connect( cell, SIGNAL( cellSelected( const QUuid& ) ),
             this, SIGNAL( clipSelected( const QUuid& ) ) );
    connect( cell, SIGNAL( cellDeleted( const QUuid& ) ),
             this, SLOT( clipDeletion( const QUuid& ) ) );
99

100
101
102
103
    QString size;

    size.setNum( m_mediaCellList->size() + 1 );

104
105
    cell->setTitle( clip->getParent()->fileName() + "_" + size );
    cell->setThumbnail( clip->getParent()->snapshot() );
106
    cell->setLength( clip->lengthSecond(), false  );
107
    cell->setEnabled( true );
108
109
    addCell( cell );

110
    m_mediaCellList->insert( clip->uuid(), cell );
111
112
}

113
114
void
ImportMediaListController::removeClip( const QUuid& uuid )
115
116
117
118
119
{
    removeCell( m_mediaCellList->value( uuid ) );
    m_mediaCellList->remove( uuid );
}

120
121
void
ImportMediaListController::cleanAll()
122
{
123
    foreach( MediaCellView* cell, m_mediaCellList->values() )
124
        removeCell( cell );
125
126
127
    m_mediaCellList->clear();
}

128
129
void
ImportMediaListController::addClipsFromMedia( Media* media )
130
{
131
132
    foreach( Clip* clip, media->clips().values() )
        addClip( clip );
133
}
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
134

135
136
void
ImportMediaListController::clipDeletion( const QUuid& uuid )
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
137
{
138
    m_clipDeleted += 1;
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
139
140
141
    emit clipDeleted( uuid );
}

142
143
void
ImportMediaListController::clipAdded( Clip* clip )
144
145
146
{
    if ( clip->getParent() == 0 )
        return ;
147
    const QUuid& uuid = clip->getParent()->uuid();
148
149
150
151
    if ( m_mediaCellList->contains( uuid ) )
        m_mediaCellList->value( uuid )->incrementClipCount();
}

152
const QHash<QUuid, MediaCellView*>*
153
ImportMediaListController::mediaCellList() const
154
{
155
    return m_mediaCellList;
156
}