MediaListViewController.cpp 4.83 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->baseClip() );
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( clipAdded( Clip* ) ),
             this, SLOT( newClipAdded(Clip*) ) );
53
    cell->setNbClips( media->clipsCount() );
Thomas Boquet's avatar
Thomas Boquet committed
54
    addCell(cell);
55
    m_cells->insert( media->baseClip()->uuid(), cell );
Thomas Boquet's avatar
Thomas Boquet committed
56
}
Thomas Boquet's avatar
Thomas Boquet committed
57

Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
58 59 60 61 62
void    MediaListViewController::cellSelection( const QUuid& uuid )
{
    if ( m_currentUuid == uuid )
        return;

63 64 65
    if ( m_cells->contains( uuid ) )
    {
        if ( !m_currentUuid.isNull() && m_cells->contains( m_currentUuid ) )
66 67 68 69
        {
            QWidget* cell = m_cells->value( m_currentUuid );
            cell->setPalette( m_cells->value( uuid )->palette() );
        }
70 71 72 73
        QPalette p = m_cells->value( uuid )->palette();
        p.setColor( QPalette::Window, QColor( Qt::darkBlue ) );
        m_cells->value( uuid )->setPalette( p );
        m_currentUuid = uuid;
74
        emit mediaSelected( Library::getInstance()->media( uuid ) );
75
    }
76 77 78 79
}

void    MediaListViewController::mediaRemoved( const QUuid& uuid )
{
80 81
    QWidget* cell = m_cells->value( uuid );
    removeCell( cell );
82 83
    m_cells->remove( uuid );
    m_currentUuid = QUuid();
Geoffroy Lacarriere's avatar
Geoffroy Lacarriere committed
84
}
85

86 87
void    MediaListViewController::showClipList( const QUuid& uuid )
{
Clement CHAVANCE's avatar
Clement CHAVANCE committed
88 89
    if ( !m_cells->contains( uuid ) )
        return ;
90
    if ( Library::getInstance()->media( uuid ) == NULL ||
91
         Library::getInstance()->media( uuid )-> clipsCount() == 0 )
92
        return ;
93 94 95 96 97
    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& ) ) );
98 99 100
    m_nav->pushViewController( m_clipsListView );
}

101 102 103 104
void    MediaListViewController::newClipAdded( Clip* clip )
{
    if ( clip->getParent() == 0 )
        return ;
105
    const QUuid& uuid = clip->getParent()->baseClip()->uuid();
106 107 108

    if ( m_cells->contains( uuid ) )
    {
109
        MediaCellView*  cell = qobject_cast<MediaCellView*>( m_cells->value( uuid, 0 ) );
110
        if ( cell != 0 )
111
        {
112
            cell->incrementClipCount();
113
        }
114 115 116
    }
}

117 118
void    MediaListViewController::restoreContext()
{
119 120
    if ( m_clipsListView->getNbDeletion() != 0 )
    {
121
        if ( m_cells->contains( m_lastUuidClipListAsked ) )
122
        {
123
            MediaCellView*  cell = qobject_cast<MediaCellView*>( m_cells->value( m_lastUuidClipListAsked, 0 ) );
124
            if ( cell != 0 )
125
            {
126
                cell->decrementClipCount( m_clipsListView->getNbDeletion() );
127 128
                m_clipsListView->resetNbDeletion();
            }
129 130
        }
    }
131
    delete m_clipsListView;
132
}
133 134 135 136 137 138

void
MediaListViewController::clipSelection( const QUuid& uuid )
{
    Clip* clip;
    if ( ( clip = Library::getInstance()->clip( m_currentUuid, uuid ) ) != 0 )
139
    {
140
        emit clipSelected( clip );
141
    }
142
}