MediaListViewController.cpp 5.49 KB
Newer Older
1 2 3
/*****************************************************************************
 * MediaLibraryWidget.h
 *****************************************************************************
Ludovic Fauvet's avatar
Ludovic Fauvet committed
4
 * Copyright (C) 2008-2010 VideoLAN
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 * Authors: Thomas Boquet <thomas.boquet@gmail.com>
 *
 * 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.
 *****************************************************************************/

Thomas Boquet's avatar
Thomas Boquet committed
23 24
#include "MediaListViewController.h"

Thomas Boquet's avatar
Thomas Boquet committed
25 26
#include <QDebug>

Thomas Boquet's avatar
Thomas Boquet committed
27
MediaListViewController::MediaListViewController( StackViewController* nav ) :
28
        ListViewController( nav ), m_nav( nav ), m_clipsListView( 0 )
Thomas Boquet's avatar
Thomas Boquet committed
29
{
30 31
    connect( Library::getInstance(), SIGNAL( newMediaLoaded( Media* ) ),
             this, SLOT( newMediaLoaded( Media* ) ) );
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
32
    m_cells = new QHash<QUuid, QWidget*>();
33
    connect( m_nav, SIGNAL( previousButtonPushed() ), this, SLOT( restoreContext() ) );
Thomas Boquet's avatar
Thomas Boquet committed
34 35 36 37
}

MediaListViewController::~MediaListViewController()
{
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
38
    delete m_cells;
Thomas Boquet's avatar
Thomas Boquet committed
39
}
40

41
void        MediaListViewController::newMediaLoaded( Media* media )
Thomas Boquet's avatar
Thomas Boquet committed
42
{
43
    MediaCellView* cell = new MediaCellView( media->uuid() );
Thomas Boquet's avatar
Thomas Boquet committed
44

45 46 47
    connect( cell, SIGNAL ( cellSelected( QUuid ) ),
             this, SLOT ( cellSelection( QUuid ) ) );
    connect( cell, SIGNAL ( cellDeleted( QUuid ) ),
48
             this, SIGNAL( mediaDeleted( QUuid ) ) );
49 50
    connect( cell, SIGNAL( arrowClicked( const QUuid& ) ),
             this, SLOT( showClipList( const QUuid& ) ) );
51 52
    connect( media, SIGNAL( snapshotComputed( const Media* ) ),
             this, SLOT( updateCell( const Media* ) ) );
53 54
    connect( media, SIGNAL( clipAdded( Clip* ) ),
             this, SLOT( newClipAdded(Clip*) ) );
55
    cell->setNbClips( media->clipsCount() );
56 57 58
    cell->setThumbnail( media->snapshot() );
    cell->setTitle( media->fileName() );
    cell->setLength( media->lengthMS() );
59 60
    if ( media->baseClip() != NULL )
        cell->setEnabled(true);
Thomas Boquet's avatar
Thomas Boquet committed
61
    addCell(cell);
62
    m_cells->insert( media->uuid(), cell );
Thomas Boquet's avatar
Thomas Boquet committed
63
}
Thomas Boquet's avatar
Thomas Boquet committed
64

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
65 66 67 68 69
void    MediaListViewController::cellSelection( const QUuid& uuid )
{
    if ( m_currentUuid == uuid )
        return;

70 71 72
    if ( m_cells->contains( uuid ) )
    {
        if ( !m_currentUuid.isNull() && m_cells->contains( m_currentUuid ) )
73 74 75 76
        {
            QWidget* cell = m_cells->value( m_currentUuid );
            cell->setPalette( m_cells->value( uuid )->palette() );
        }
77 78 79 80
        QPalette p = m_cells->value( uuid )->palette();
        p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
        m_cells->value( uuid )->setPalette( p );
        m_currentUuid = uuid;
81
        emit mediaSelected( Library::getInstance()->media( uuid ) );
82
    }
83 84 85 86
}

void    MediaListViewController::mediaRemoved( const QUuid& uuid )
{
87 88
    QWidget* cell = m_cells->value( uuid );
    removeCell( cell );
89 90
    m_cells->remove( uuid );
    m_currentUuid = QUuid();
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
91
}
92

93
void    MediaListViewController::updateCell( const Media* media )
94
{
95
    MediaCellView* cell = qobject_cast<MediaCellView*>( m_cells->value( media->uuid(), NULL ) );
96
    if ( cell != NULL )
97
    {
98
        cell->setNbClips( media->clipsCount() );
99 100
        cell->setLength( media->lengthMS() );
        cell->setThumbnail( media->snapshot() );
101 102
        cell->setEnabled(true);
    }
103
}
104 105 106

void    MediaListViewController::showClipList( const QUuid& uuid )
{
Clement CHAVANCE's avatar
Clement CHAVANCE committed
107 108
    if ( !m_cells->contains( uuid ) )
        return ;
109
    if ( Library::getInstance()->media( uuid ) == NULL ||
110
         Library::getInstance()->media( uuid )-> clipsCount() == 0 )
111
        return ;
112 113 114 115 116
    m_lastUuidClipListAsked = uuid;
    m_clipsListView = new ClipListViewController( m_nav, uuid );
    m_clipsListView->addClipsFromMedia( Library::getInstance()->media( uuid ) );
    connect( m_clipsListView, SIGNAL( clipSelected( const QUuid& ) ),
            this, SLOT( clipSelection( const QUuid& ) ) );
117 118 119
    m_nav->pushViewController( m_clipsListView );
}

120 121 122 123
void    MediaListViewController::newClipAdded( Clip* clip )
{
    if ( clip->getParent() == 0 )
        return ;
124
    const QUuid& uuid = clip->getParent()->uuid();
125 126 127

    if ( m_cells->contains( uuid ) )
    {
128
        MediaCellView*  cell = qobject_cast<MediaCellView*>( m_cells->value( uuid, 0 ) );
129
        if ( cell != 0 )
130
        {
131
            cell->incrementClipCount();
132
        }
133 134 135
    }
}

136 137
void    MediaListViewController::restoreContext()
{
138 139
    if ( m_clipsListView->getNbDeletion() != 0 )
    {
140
        if ( m_cells->contains( m_lastUuidClipListAsked ) )
141
        {
142
            MediaCellView*  cell = qobject_cast<MediaCellView*>( m_cells->value( m_lastUuidClipListAsked, 0 ) );
143
            if ( cell != 0 )
144
            {
145
                cell->decrementClipCount( m_clipsListView->getNbDeletion() );
146 147
                m_clipsListView->resetNbDeletion();
            }
148 149
        }
    }
150
    delete m_clipsListView;
151
}
152 153 154 155 156 157

void
MediaListViewController::clipSelection( const QUuid& uuid )
{
    Clip* clip;
    if ( ( clip = Library::getInstance()->clip( m_currentUuid, uuid ) ) != 0 )
158
    {
159
        emit clipSelected( clip );
160
    }
161
}