PageRenderTime 103ms CodeModel.GetById 60ms app.highlight 14ms RepoModel.GetById 27ms app.codeStats 0ms

/src/libtomahawk/playlist/playlistview.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 162 lines | 111 code | 33 blank | 18 comment | 16 complexity | de6f86c3dc9e219626115acd244c18ad MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#include "PlaylistView.h"
 21
 22#include <QKeyEvent>
 23
 24#include "ViewManager.h"
 25#include "utils/Logger.h"
 26#include "PlaylistUpdaterInterface.h"
 27#include "Source.h"
 28
 29using namespace Tomahawk;
 30
 31
 32PlaylistView::PlaylistView( QWidget* parent )
 33    : TrackView( parent )
 34    , m_model( 0 )
 35{
 36    connect( contextMenu(), SIGNAL( triggered( int ) ), SLOT( onMenuTriggered( int ) ) );
 37}
 38
 39
 40PlaylistView::~PlaylistView()
 41{
 42    qDebug() << Q_FUNC_INFO;
 43}
 44
 45
 46void
 47PlaylistView::setModel( QAbstractItemModel* model )
 48{
 49    Q_UNUSED( model );
 50    qDebug() << "Explicitly use setPlaylistModel instead";
 51    Q_ASSERT( false );
 52}
 53
 54
 55void
 56PlaylistView::setPlaylistModel( PlaylistModel* model )
 57{
 58    m_model = model;
 59
 60    TrackView::setPlayableModel( m_model );
 61    setColumnHidden( PlayableModel::Age, true ); // Hide age column per default
 62    setColumnHidden( PlayableModel::Filesize, true ); // Hide filesize column per default
 63    setColumnHidden( PlayableModel::Composer, true ); // Hide composer column per default
 64
 65    connect( m_model, SIGNAL( playlistDeleted() ), SLOT( onDeleted() ) );
 66    connect( m_model, SIGNAL( playlistChanged() ), SLOT( onChanged() ) );
 67
 68    emit modelChanged();
 69}
 70
 71
 72void
 73PlaylistView::keyPressEvent( QKeyEvent* event )
 74{
 75    TrackView::keyPressEvent( event );
 76}
 77
 78
 79bool
 80PlaylistView::eventFilter( QObject* obj, QEvent* event )
 81{
 82    if ( event->type() == QEvent::DragEnter )
 83    {
 84        QDragEnterEvent* e = static_cast<QDragEnterEvent*>(event);
 85        dragEnterEvent( e );
 86        return true;
 87    }
 88    if ( event->type() == QEvent::DragMove )
 89    {
 90        QDragMoveEvent* e = static_cast<QDragMoveEvent*>(event);
 91        dragMoveEvent( e );
 92        return true;
 93    }
 94    if ( event->type() == QEvent::DragLeave )
 95    {
 96        QDragLeaveEvent* e = static_cast<QDragLeaveEvent*>(event);
 97        dragLeaveEvent( e );
 98        return true;
 99    }
100    if ( event->type() == QEvent::Drop )
101    {
102        QDropEvent* e = static_cast<QDropEvent*>(event);
103        dropEvent( e );
104        return true;
105    }
106
107    return QObject::eventFilter( obj, event );
108}
109
110
111QList<PlaylistUpdaterInterface*>
112PlaylistView::updaters() const
113{
114    if ( !m_model->playlist().isNull() )
115        return m_model->playlist()->updaters();
116
117    return QList<PlaylistUpdaterInterface*>();
118}
119
120
121void
122PlaylistView::onDeleted()
123{
124    emit destroyed( widget() );
125}
126
127
128void
129PlaylistView::onChanged()
130{
131    if ( m_model )
132    {
133        if ( m_model->isReadOnly() )
134            setEmptyTip( tr( "This playlist is currently empty." ) );
135        else
136            setEmptyTip( tr( "This playlist is currently empty. Add some tracks to it and enjoy the music!" ) );
137        m_model->finishLoading();
138
139        setGuid( proxyModel()->guid() );
140
141        if ( !m_model->playlist().isNull() && ViewManager::instance()->currentPage() == this )
142            emit nameChanged( m_model->playlist()->title() );
143    }
144}
145
146
147bool
148PlaylistView::isTemporaryPage() const
149{
150    return ( m_model && m_model->isTemporary() );
151}
152
153
154void
155PlaylistView::onMenuTriggered( int action )
156{
157    switch ( action )
158    {
159        default:
160            break;
161    }
162}