File indexing completed on 2024-05-05 04:48:43

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Ian Monroe <ian@monroe.nu>                                        *
0003  * Copyright (c) 2008 Soren Harward <stharward@gmail.com>                               *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) version 3 or        *
0008  * any later version accepted by the membership of KDE e.V. (or its successor approved  *
0009  * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of  *
0010  * version 3 of the license.                                                            *
0011  *                                                                                      *
0012  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0013  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0014  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0015  *                                                                                      *
0016  * You should have received a copy of the GNU General Public License along with         *
0017  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0018  ****************************************************************************************/
0019 
0020 #define DEBUG_PREFIX "Playlist::Item"
0021 
0022 #include "PlaylistItem.h"
0023 
0024 #include "core/capabilities/SourceInfoCapability.h"
0025 #include "core/meta/Meta.h"
0026 
0027 #include <QRandomGenerator>
0028 
0029 #include <QSet>
0030 
0031 Playlist::Item::Item()
0032     : m_state ( Invalid )
0033     , m_id ( 0 )
0034 {
0035 }
0036 
0037 Playlist::Item::Item( const Meta::TrackPtr &track )
0038         : m_track( track ), m_state( NewlyAdded )
0039 {
0040     m_id = ( static_cast<quint64>( QRandomGenerator::global()->generate() ) << 32 ) | static_cast<quint64>( QRandomGenerator::global()->generate() );
0041 }
0042 
0043 Playlist::Item::~Item()
0044 {
0045 }
0046 
0047 const Meta::TrackPtr &
0048 Playlist::Item::track() const
0049 {
0050     return m_track;
0051 }
0052 
0053 // Does the same thing as:
0054 //     foreach( quint64 val, set )
0055 //         target.removeAll( val )
0056 // but with O(n * log n) performance instead of O(n^2) if 'target' and 'set' are similar-sized.
0057 void
0058 Playlist::Item::listRemove( QList<quint64> &target, QSet<quint64> &removeSet )
0059 {
0060     QMutableListIterator<quint64> iter( target );
0061     while ( iter.hasNext() )
0062         if ( removeSet.contains( iter.next() ) )
0063             iter.remove();
0064 }