PageRenderTime 83ms CodeModel.GetById 41ms app.highlight 12ms RepoModel.GetById 28ms app.codeStats 0ms

/src/libtomahawk/playlist/QueueView.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 110 lines | 73 code | 20 blank | 17 comment | 5 complexity | 1d77524931f506bcb8bafa6194d9bce5 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *
  5 *   Tomahawk is free software: you can redistribute it and/or modify
  6 *   it under the terms of the GNU General Public License as published by
  7 *   the Free Software Foundation, either version 3 of the License, or
  8 *   (at your option) any later version.
  9 *
 10 *   Tomahawk is distributed in the hope that it will be useful,
 11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13 *   GNU General Public License for more details.
 14 *
 15 *   You should have received a copy of the GNU General Public License
 16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19#include "QueueView.h"
 20
 21#include "playlist/TrackView.h"
 22#include "playlist/ContextView.h"
 23#include "playlist/PlaylistModel.h"
 24#include "playlist/QueueProxyModel.h"
 25#include "playlist/TrackItemDelegate.h"
 26#include "utils/Logger.h"
 27#include "Pipeline.h"
 28#include "Source.h"
 29#include "SourceList.h"
 30#include "TomahawkSettings.h"
 31#include "utils/TomahawkUtilsGui.h"
 32
 33using namespace Tomahawk;
 34
 35
 36QueueView::QueueView( QWidget* parent )
 37    : PlaylistViewPage( parent )
 38{
 39    view()->setCaption( tr( "Queue Details" ) );
 40
 41    view()->trackView()->setProxyModel( new QueueProxyModel( view()->trackView() ) );
 42    view()->trackView()->proxyModel()->setStyle( PlayableProxyModel::SingleColumn );
 43    view()->trackView()->setHeaderHidden( true );
 44    view()->trackView()->setUniformRowHeights( false );
 45
 46    PlaylistModel* queueModel = new PlaylistModel( view()->trackView() );
 47    queueModel->setAcceptPlayableQueriesOnly( true );
 48    queueModel->setReadOnly( false );
 49    queueModel->setTitle( tr( "Queue" ) );
 50    setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::Queue ) );
 51
 52    view()->trackView()->setPlayableModel( queueModel );
 53    view()->setEmptyTip( tr( "The queue is currently empty. Drop something to enqueue it!" ) );
 54
 55    TrackItemDelegate* delegate = new TrackItemDelegate( TrackItemDelegate::LovedTracks, view()->trackView(), view()->trackView()->proxyModel() );
 56    view()->trackView()->setPlaylistItemDelegate( delegate );
 57
 58    if ( Pipeline::instance()->isRunning() && SourceList::instance()->isReady() )
 59    {
 60        restoreState();
 61    }
 62    else
 63    {
 64        connect( SourceList::instance(), SIGNAL( ready() ), SLOT( restoreState() ) );
 65        connect( Pipeline::instance(), SIGNAL( running() ), SLOT( restoreState() ) );
 66    }
 67}
 68
 69
 70QueueView::~QueueView()
 71{
 72    tDebug( LOGVERBOSE ) << Q_FUNC_INFO;
 73    saveState();
 74}
 75
 76
 77void
 78QueueView::restoreState()
 79{
 80    if ( !Pipeline::instance()->isRunning() || !SourceList::instance()->isReady() )
 81        return;
 82
 83    QVariantList vl = TomahawkSettings::instance()->queueState().toList();
 84    QList< query_ptr > ql;
 85
 86    foreach ( const QVariant& v, vl )
 87    {
 88        QVariantMap map = v.toMap();
 89        query_ptr q = Query::get( map["artist"].toString(), map["track"].toString(), map["album"].toString() );
 90        ql << q;
 91    }
 92
 93    if ( !ql.isEmpty() )
 94    {
 95        view()->trackView()->model()->appendQueries( ql );
 96    }
 97}
 98
 99
100void
101QueueView::saveState()
102{
103    QVariantList vl;
104    foreach ( const query_ptr& query, view()->trackView()->model()->queries() )
105    {
106        vl << query->toVariant();
107    }
108
109    TomahawkSettings::instance()->setQueueState( vl );
110}