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

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Bart Cerneels <bart.cerneels@kde.org>                             *
0003  * Copyright (c) 2011 Lucas Lira Gomes <x8lucas8x@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) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef SYNCEDPLAYLIST_H
0019 #define SYNCEDPLAYLIST_H
0020 
0021 #include "core/playlists/Playlist.h"
0022 
0023 /** A synchronized playlist that will try to get the attached slaves into the same state as the
0024   * master. The first playlist attached (through constructor) is the master.
0025   */
0026 class SyncedPlaylist : public Playlists::Playlist, public Playlists::PlaylistObserver
0027 {
0028     public:
0029         explicit SyncedPlaylist( const Playlists::PlaylistPtr &playlist );
0030         ~SyncedPlaylist() override {}
0031 
0032         //Playlists::Playlist methods
0033         QUrl uidUrl() const override;
0034         QString name() const override;
0035         QString prettyName() const override;
0036         Playlists::PlaylistProvider *provider() const override;
0037         void setName( const QString &name ) override { Q_UNUSED( name ); }
0038 
0039         Meta::TrackList tracks() override;
0040         int trackCount() const override;
0041 
0042         void addTrack( const Meta::TrackPtr &track, int position = -1 ) override;
0043         void removeTrack( int position ) override;
0044 
0045         //PlaylistObserver methods
0046         void metadataChanged( const Playlists::PlaylistPtr &playlist ) override;
0047         void tracksLoaded( Playlists::PlaylistPtr) override;
0048         void trackAdded( const Playlists::PlaylistPtr &playlist, const Meta::TrackPtr &track,
0049                                  int position ) override;
0050         void trackRemoved( const Playlists::PlaylistPtr &playlist, int position ) override;
0051 
0052         //SyncedPlaylist methods
0053         /** returns true when there is no active playlist associated with it anymore. */
0054         virtual bool isEmpty() const;
0055         virtual void addPlaylist( Playlists::PlaylistPtr playlist );
0056 
0057         virtual bool syncNeeded() const;
0058         virtual void doSync() const;
0059 
0060         virtual void removePlaylistsFrom( Playlists::PlaylistProvider *provider );
0061 
0062         virtual Playlists::PlaylistList playlists() const { return m_playlists; }
0063 
0064         virtual Playlists::PlaylistPtr master() const;
0065         virtual Playlists::PlaylistList slaves() const;
0066 
0067     protected:
0068         SyncedPlaylist() {}
0069 
0070     private:
0071         Playlists::PlaylistList m_playlists;
0072 };
0073 
0074 typedef AmarokSharedPointer<SyncedPlaylist> SyncedPlaylistPtr;
0075 typedef QList<SyncedPlaylistPtr> SyncedPlaylistList;
0076 
0077 Q_DECLARE_METATYPE( SyncedPlaylistPtr )
0078 Q_DECLARE_METATYPE( SyncedPlaylistList )
0079 
0080 #endif // SYNCEDPLAYLIST_H