File indexing completed on 2024-05-19 04:49:50

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2008 Soren Harward <stharward@gmail.com>                               *
0004  * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org>                                        *
0005  * Copyright (c) 2010 Nanno Langstraat <langstr@gmail.com>                              *
0006  *                                                                                      *
0007  * This program is free software; you can redistribute it and/or modify it under        *
0008  * the terms of the GNU General Public License as published by the Free Software        *
0009  * Foundation; either version 2 of the License, or (at your option) version 3 or        *
0010  * any later version accepted by the membership of KDE e.V. (or its successor approved  *
0011  * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of  *
0012  * version 3 of the license.                                                            *
0013  *                                                                                      *
0014  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0015  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0016  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0017  *                                                                                      *
0018  * You should have received a copy of the GNU General Public License along with         *
0019  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0020  ****************************************************************************************/
0021 
0022 #define DEBUG_PREFIX "Playlist::RepeatAlbumNavigator"
0023 
0024 #include "RepeatAlbumNavigator.h"
0025 
0026 #include "core/support/Debug.h"
0027 #include "core/meta/Meta.h"
0028 
0029 
0030 Playlist::RepeatAlbumNavigator::RepeatAlbumNavigator()
0031 {
0032     loadFromSourceModel();
0033 }
0034 
0035 void
0036 Playlist::RepeatAlbumNavigator::planOne()
0037 {
0038     DEBUG_BLOCK
0039 
0040     if ( m_plannedItems.isEmpty() )
0041     {
0042         ItemList itemsInAlbum = m_itemsPerAlbum.value( currentAlbum() );    // May be default-constructed empty list.
0043 
0044         int currentRow = itemsInAlbum.indexOf( currentItem() );
0045         if ( currentRow != -1 )
0046         {
0047             int nextRow = (currentRow + 1) % itemsInAlbum.size();    // Circulate within same album
0048             m_plannedItems.append( itemsInAlbum.at( nextRow ) );
0049         }
0050         else    // This happens if 'currentItem() == 0'.
0051         {
0052             quint64 item = bestFallbackItem();
0053             if ( item )
0054                 m_plannedItems.append( item );
0055         }
0056     }
0057 }