| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2007 Bart Cerneels <[email protected]> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify it under * |
| 5 |
* the terms of the GNU General Public License as published by the Free Software * |
| 6 |
* Foundation; either version 2 of the License, or (at your option) any later * |
| 7 |
* version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 10 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 11 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 12 |
* * |
| 13 |
* You should have received a copy of the GNU General Public License along with * |
| 14 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 15 |
****************************************************************************************/ |
| 16 |
|
| 17 |
#ifndef PLAYLISTFILEPROVIDER_H |
| 18 |
#define PLAYLISTFILEPROVIDER_H |
| 19 |
|
| 20 |
#include "core/playlists/PlaylistFormat.h" |
| 21 |
#include "core/playlists/PlaylistProvider.h" |
| 22 |
#include "core-impl/playlists/providers/user/UserPlaylistProvider.h" |
| 23 |
#include "core-impl/playlists/types/file/PlaylistFileSupport.h" |
| 24 |
|
| 25 |
#include <KConfigGroup> |
| 26 |
|
| 27 |
class QTimer; |
| 28 |
|
| 29 |
namespace Playlists { |
| 30 |
/** |
| 31 |
@author Bart Cerneels <[email protected]> |
| 32 |
*/ |
| 33 |
class PlaylistFileProvider : public Playlists::UserPlaylistProvider |
| 34 |
{ |
| 35 |
Q_OBJECT |
| 36 |
|
| 37 |
public: |
| 38 |
PlaylistFileProvider(); |
| 39 |
~PlaylistFileProvider() override; |
| 40 |
|
| 41 |
QString prettyName() const override; |
| 42 |
QIcon icon() const override; |
| 43 |
|
| 44 |
int category() const override { return Playlists::UserPlaylist; } |
| 45 |
|
| 46 |
int playlistCount() const override; |
| 47 |
Playlists::PlaylistList playlists() override; |
| 48 |
|
| 49 |
/** |
| 50 |
* Returns a Playlists::PlaylistPtr to the new playlist, NULL if something failed. |
| 51 |
* @param tracks Tracks being added to that new playlist. |
| 52 |
* @param name File name of the new playlist. If no extension is being given we |
| 53 |
* default to xspf. '/' and '\' are being replaced by '-'. |
| 54 |
*/ |
| 55 |
Playlists::PlaylistPtr save( const Meta::TrackList &tracks, |
| 56 |
const QString &name = QString() ) override; |
| 57 |
|
| 58 |
virtual bool import( const QUrl &path ); |
| 59 |
|
| 60 |
bool isWritable() override { return true; } |
| 61 |
void renamePlaylist(Playlists::PlaylistPtr playlist, const QString &newName ) override; |
| 62 |
bool deletePlaylists( const Playlists::PlaylistList &playlists ) override; |
| 63 |
|
| 64 |
/* PlaylistFileProvider methods */ |
| 65 |
/** Schedules a PlaylistFile to be saved on the next iteration of the mainloop. |
| 66 |
* Each playlist will be scheduled and saved only once. |
| 67 |
*/ |
| 68 |
void saveLater( Playlists::PlaylistFilePtr playlist ); |
| 69 |
|
| 70 |
private Q_SLOTS: |
| 71 |
void loadPlaylists(); |
| 72 |
void slotSaveLater(); |
| 73 |
|
| 74 |
private: |
| 75 |
bool deletePlaylistFiles( Playlists::PlaylistFileList playlistFiles ); |
| 76 |
KConfigGroup loadedPlaylistsConfig() const; |
| 77 |
|
| 78 |
bool m_playlistsLoaded; |
| 79 |
QList<QUrl> m_urlsToLoad; |
| 80 |
Playlists::PlaylistFileList m_playlists; |
| 81 |
QMultiMap<QString, Playlists::PlaylistPtr> m_groupMap; |
| 82 |
|
| 83 |
QTimer *m_saveLaterTimer; |
| 84 |
QList<Playlists::PlaylistFilePtr> m_saveLaterPlaylists; |
| 85 |
}; |
| 86 |
|
| 87 |
} //namespace Playlists |
| 88 |
|
| 89 |
#endif |