2010-05-09 02:10:26 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-05-09 02:10:26 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLAYLISTBACKEND_H
|
|
|
|
#define PLAYLISTBACKEND_H
|
|
|
|
|
2010-08-03 20:57:17 +02:00
|
|
|
#include <QFuture>
|
2011-01-19 16:36:40 +01:00
|
|
|
#include <QHash>
|
2010-05-09 02:10:26 +02:00
|
|
|
#include <QList>
|
2011-01-19 16:36:40 +01:00
|
|
|
#include <QMutex>
|
2010-08-03 20:57:17 +02:00
|
|
|
#include <QObject>
|
2010-05-09 02:10:26 +02:00
|
|
|
|
|
|
|
#include "playlistitem.h"
|
2010-11-20 21:30:21 +01:00
|
|
|
#include "smartplaylists/generator_fwd.h"
|
2010-05-09 02:10:26 +02:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
class Application;
|
2010-05-09 02:10:26 +02:00
|
|
|
class Database;
|
|
|
|
|
|
|
|
class PlaylistBackend : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2012-02-12 14:41:50 +01:00
|
|
|
Q_INVOKABLE PlaylistBackend(Application* app, QObject* parent = 0);
|
2010-05-09 02:10:26 +02:00
|
|
|
|
|
|
|
struct Playlist {
|
2012-10-31 07:04:22 +01:00
|
|
|
Playlist()
|
|
|
|
: id(-1),
|
2013-05-11 23:17:54 +02:00
|
|
|
favorite(false),
|
2012-10-31 07:04:22 +01:00
|
|
|
last_played(0) {
|
|
|
|
}
|
|
|
|
|
2010-05-09 02:10:26 +02:00
|
|
|
int id;
|
|
|
|
QString name;
|
2012-10-31 07:04:22 +01:00
|
|
|
QString ui_path;
|
2013-05-11 23:17:54 +02:00
|
|
|
bool favorite;
|
2010-05-21 00:30:55 +02:00
|
|
|
int last_played;
|
2010-11-20 21:30:21 +01:00
|
|
|
QString dynamic_type;
|
2010-11-27 20:11:36 +01:00
|
|
|
QString dynamic_backend;
|
2010-11-20 21:30:21 +01:00
|
|
|
QByteArray dynamic_data;
|
2011-04-28 19:50:45 +02:00
|
|
|
|
|
|
|
// Special playlists have different behaviour, eg. the "spotify-search"
|
|
|
|
// type has a spotify search box at the top, replacing the ordinary filter.
|
|
|
|
QString special_type;
|
2010-05-09 02:10:26 +02:00
|
|
|
};
|
|
|
|
typedef QList<Playlist> PlaylistList;
|
2010-10-16 17:22:14 +02:00
|
|
|
typedef QFuture<PlaylistItemPtr> PlaylistItemFuture;
|
2010-05-09 02:10:26 +02:00
|
|
|
|
2011-04-27 00:06:58 +02:00
|
|
|
static const int kSongTableJoins;
|
|
|
|
|
2013-05-11 23:59:51 +02:00
|
|
|
PlaylistList GetAllPlaylists();
|
2012-10-31 07:04:22 +01:00
|
|
|
PlaylistList GetAllOpenPlaylists();
|
2013-05-11 23:17:54 +02:00
|
|
|
PlaylistList GetAllFavoritePlaylists();
|
2011-05-29 14:55:18 +02:00
|
|
|
PlaylistBackend::Playlist GetPlaylist(int id);
|
2010-08-03 21:40:54 +02:00
|
|
|
PlaylistItemFuture GetPlaylistItems(int playlist);
|
2013-05-23 20:09:35 +02:00
|
|
|
QFuture<Song> GetPlaylistSongs(int playlist);
|
2011-03-18 22:54:22 +01:00
|
|
|
|
2010-05-21 12:37:24 +02:00
|
|
|
void SetPlaylistOrder(const QList<int>& ids);
|
2012-10-31 07:04:22 +01:00
|
|
|
void SetPlaylistUiPath(int id, const QString& path);
|
2010-05-09 02:10:26 +02:00
|
|
|
|
2011-04-28 19:50:45 +02:00
|
|
|
int CreatePlaylist(const QString& name, const QString& special_type);
|
2011-03-18 22:54:22 +01:00
|
|
|
void SavePlaylistAsync(int playlist, const PlaylistItemList& items,
|
|
|
|
int last_played, smart_playlists::GeneratorPtr dynamic);
|
2010-05-20 23:21:55 +02:00
|
|
|
void RenamePlaylist(int id, const QString& new_name);
|
2013-05-11 23:17:54 +02:00
|
|
|
void FavoritePlaylist(int id, bool is_favorite);
|
2011-03-18 22:54:22 +01:00
|
|
|
void RemovePlaylist(int id);
|
2010-05-20 23:21:55 +02:00
|
|
|
|
2014-01-24 13:54:38 +01:00
|
|
|
Application* app() const { return app_; }
|
|
|
|
|
2010-05-09 02:10:26 +02:00
|
|
|
public slots:
|
2010-11-20 21:30:21 +01:00
|
|
|
void SavePlaylist(int playlist, const PlaylistItemList& items,
|
|
|
|
int last_played, smart_playlists::GeneratorPtr dynamic);
|
2010-05-09 02:10:26 +02:00
|
|
|
|
|
|
|
private:
|
2011-01-19 16:36:40 +01:00
|
|
|
struct NewSongFromQueryState {
|
|
|
|
QHash<QString, SongList> cached_cues_;
|
|
|
|
QMutex mutex_;
|
|
|
|
};
|
|
|
|
|
2013-05-23 20:09:35 +02:00
|
|
|
QList<SqlRow> GetPlaylistRows(int playlist);
|
|
|
|
|
|
|
|
Song NewSongFromQuery(const SqlRow& row, boost::shared_ptr<NewSongFromQueryState> state);
|
|
|
|
PlaylistItemPtr NewPlaylistItemFromQuery(const SqlRow& row, boost::shared_ptr<NewSongFromQueryState> state);
|
2011-01-19 16:36:40 +01:00
|
|
|
PlaylistItemPtr RestoreCueData(PlaylistItemPtr item, boost::shared_ptr<NewSongFromQueryState> state);
|
|
|
|
|
2013-05-11 23:17:54 +02:00
|
|
|
enum GetPlaylistsFlags {
|
|
|
|
GetPlaylists_OpenInUi = 1,
|
|
|
|
GetPlaylists_Favorite = 2,
|
|
|
|
GetPlaylists_All = GetPlaylists_OpenInUi | GetPlaylists_Favorite
|
|
|
|
};
|
|
|
|
PlaylistList GetPlaylists(GetPlaylistsFlags flags);
|
2012-10-31 07:04:22 +01:00
|
|
|
|
2012-02-12 14:41:50 +01:00
|
|
|
Application* app_;
|
|
|
|
Database* db_;
|
2010-05-09 02:10:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYLISTBACKEND_H
|