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

0001 /****************************************************************************************
0002  * Copyright (c) 2009 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #include "core/meta/Meta.h"
0018 #include "core/playlists/Playlist.h"
0019 #include "core/playlists/PlaylistProvider.h"
0020 
0021 using namespace Playlists;
0022 
0023 PlaylistObserver::PlaylistObserver()
0024     : m_playlistSubscriptionsMutex( QMutex::Recursive )  // prevent deadlocks
0025 {
0026 }
0027 
0028 PlaylistObserver::~PlaylistObserver()
0029 {
0030     QMutexLocker locker( &m_playlistSubscriptionsMutex );
0031     foreach( PlaylistPtr playlist, m_playlistSubscriptions )
0032     {
0033         playlist->unsubscribe( this );
0034     }
0035 }
0036 
0037 void
0038 PlaylistObserver::subscribeTo( PlaylistPtr playlist )
0039 {
0040     if( playlist )
0041     {
0042         QMutexLocker locker( &m_playlistSubscriptionsMutex );
0043         m_playlistSubscriptions.insert( playlist );
0044         playlist->subscribe( this );
0045     }
0046 }
0047 
0048 void
0049 PlaylistObserver::unsubscribeFrom( PlaylistPtr playlist )
0050 {
0051     if( playlist )
0052     {
0053         QMutexLocker locker( &m_playlistSubscriptionsMutex );
0054         m_playlistSubscriptions.remove( playlist );
0055         playlist->unsubscribe( this );
0056     }
0057 }
0058 
0059 void PlaylistObserver::metadataChanged( const PlaylistPtr &)
0060 {
0061 }
0062 
0063 void PlaylistObserver::trackAdded( const PlaylistPtr&, const Meta::TrackPtr&, int )
0064 {
0065 }
0066 
0067 void PlaylistObserver::trackRemoved( const PlaylistPtr&, int )
0068 {
0069 }
0070 
0071 void PlaylistObserver::tracksLoaded( PlaylistPtr )
0072 {
0073 }
0074 
0075 Playlist::Playlist()
0076     : m_observersMutex( QMutex::Recursive ) // prevent deadlocks
0077     , m_async( true )
0078 {
0079 }
0080 
0081 Playlist::~Playlist()
0082 {
0083 }
0084 
0085 void
0086 Playlist::setName( const QString & )
0087 {
0088 }
0089 
0090 void
0091 Playlist::triggerTrackLoad()
0092 {
0093     notifyObserversTracksLoaded();
0094 }
0095 
0096 void Playlist::addTrack( const Meta::TrackPtr&, int )
0097 {
0098 }
0099 
0100 void Playlist::removeTrack( int )
0101 {
0102 }
0103 
0104 void
0105 Playlist::syncTrackStatus( int, const Meta::TrackPtr &)
0106 {
0107 }
0108 
0109 QStringList
0110 Playlist::groups()
0111 {
0112     return QStringList();
0113 }
0114 
0115 void
0116 Playlist::setGroups( const QStringList & )
0117 {
0118 }
0119 
0120 void
0121 Playlist::notifyObserversMetadataChanged()
0122 {
0123     QMutexLocker locker( &m_observersMutex );
0124     foreach( PlaylistObserver *observer, m_observers )
0125     {
0126         if( m_observers.contains( observer ) ) // guard against observers removing themselves in destructors
0127             observer->metadataChanged( PlaylistPtr( this ) );
0128     }
0129 }
0130 
0131 void
0132 Playlist::notifyObserversTracksLoaded()
0133 {
0134     QMutexLocker locker( &m_observersMutex );
0135     foreach( PlaylistObserver *observer, m_observers )
0136     {
0137         if( m_observers.contains( observer ) ) // guard against observers removing themselves in destructors
0138             observer->tracksLoaded( PlaylistPtr( this ) );
0139     }
0140 }
0141 
0142 void
0143 Playlist::notifyObserversTrackAdded( const Meta::TrackPtr &track, int position )
0144 {
0145     Q_ASSERT( position >= 0 ); // notice bug 293295 early
0146     QMutexLocker locker( &m_observersMutex );
0147     foreach( PlaylistObserver *observer, m_observers )
0148     {
0149         if( m_observers.contains( observer ) ) // guard against observers removing themselves in destructors
0150             observer->trackAdded( PlaylistPtr( this ), track, position );
0151     }
0152 }
0153 
0154 void
0155 Playlist::notifyObserversTrackRemoved( int position )
0156 {
0157     QMutexLocker locker( &m_observersMutex );
0158     foreach( PlaylistObserver *observer, m_observers )
0159     {
0160         if( m_observers.contains( observer ) ) // guard against observers removing themselves in destructors
0161             observer->trackRemoved( PlaylistPtr( this ), position );
0162     }
0163 }
0164 
0165 void
0166 Playlist::subscribe( PlaylistObserver* observer )
0167 {
0168     if( observer )
0169     {
0170         QMutexLocker locker( &m_observersMutex );
0171         m_observers.insert( observer );
0172     }
0173 }
0174 
0175 void
0176 Playlist::unsubscribe( PlaylistObserver* observer )
0177 {
0178     QMutexLocker locker( &m_observersMutex );
0179     m_observers.remove( observer );
0180 }