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

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
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 #ifndef PLAYLISTSSQLPLAYLIST_H
0018 #define PLAYLISTSSQLPLAYLIST_H
0019 
0020 #include "core/playlists/Playlist.h"
0021 
0022 
0023 namespace Playlists
0024 {
0025 class PlaylistProvider;
0026 class SqlPlaylist;
0027 typedef AmarokSharedPointer<SqlPlaylist> SqlPlaylistPtr;
0028 typedef QList<SqlPlaylistPtr> SqlPlaylistList;
0029 
0030 class SqlPlaylistGroup;
0031 typedef AmarokSharedPointer<SqlPlaylistGroup> SqlPlaylistGroupPtr;
0032 typedef QList<SqlPlaylistGroupPtr> SqlPlaylistGroupList;
0033 
0034 /**
0035     A playlist that saves and loads itself from the Amarok database
0036 
0037     @author Nikolaj Hald Nielsen <nhn@kde.org>
0038 */
0039 class SqlPlaylist : public Playlist
0040 {
0041     public:
0042         SqlPlaylist( const QString &name, const Meta::TrackList &tracks,
0043                 SqlPlaylistGroupPtr parent, PlaylistProvider *provider,
0044                 const QString &urlId = QString() );
0045         SqlPlaylist( const QStringList & resultRow, SqlPlaylistGroupPtr parent,
0046                      PlaylistProvider *provider );
0047 
0048         ~SqlPlaylist() override;
0049 
0050         /* Playlist virtual functions */
0051         QUrl uidUrl() const override;
0052         QString name() const override { return m_name; }
0053 
0054         PlaylistProvider *provider() const override { return m_provider; }
0055 
0056         void setName( const QString &name ) override;
0057 
0058         QStringList groups() override;
0059         void setGroups( const QStringList &groups ) override;
0060 
0061         int trackCount() const override;
0062         Meta::TrackList tracks() override;
0063         void triggerTrackLoad() override;
0064 
0065         void addTrack( const Meta::TrackPtr &track, int position = -1 ) override;
0066         void removeTrack( int position ) override;
0067 
0068         // SqlPlaylist-specific methods
0069         bool saveToDb( bool tracks = true );
0070         void removeFromDb();
0071 
0072     private:
0073         void loadTracks();
0074         void saveTracks();
0075 
0076         int m_dbId;
0077         SqlPlaylistGroupPtr m_parent;
0078         Meta::TrackList m_tracks;
0079         PlaylistProvider *m_provider;
0080         QString m_name;
0081         QString m_urlId;
0082 
0083         bool m_tracksLoaded;
0084 };
0085 
0086 }
0087 
0088 Q_DECLARE_METATYPE( Playlists::SqlPlaylistPtr )
0089 Q_DECLARE_METATYPE( Playlists::SqlPlaylistList )
0090 
0091 #endif