2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
|
|
|
* This file was part of Clementine.
|
|
|
|
* Copyright 2010, David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PLAYLISTBACKEND_H
|
|
|
|
#define PLAYLISTBACKEND_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QMutex>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QHash>
|
|
|
|
#include <QList>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QSet>
|
|
|
|
#include <QString>
|
|
|
|
#include <QSqlQuery>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2023-07-21 05:55:24 +02:00
|
|
|
#include "core/shared_ptr.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "core/song.h"
|
2021-09-09 21:45:46 +02:00
|
|
|
#include "core/sqlquery.h"
|
2022-05-13 18:15:04 +02:00
|
|
|
#include "core/sqlrow.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "playlistitem.h"
|
2020-09-17 17:50:17 +02:00
|
|
|
#include "smartplaylists/playlistgenerator.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-07-24 19:16:51 +02:00
|
|
|
class QThread;
|
2018-02-27 18:06:05 +01:00
|
|
|
class Application;
|
|
|
|
class Database;
|
|
|
|
|
|
|
|
class PlaylistBackend : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2020-06-15 21:55:05 +02:00
|
|
|
Q_INVOKABLE explicit PlaylistBackend(Application *app, QObject *parent = nullptr);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
struct Playlist {
|
|
|
|
Playlist() : id(-1), favorite(false), last_played(0) {}
|
|
|
|
|
|
|
|
int id;
|
|
|
|
QString name;
|
|
|
|
QString ui_path;
|
|
|
|
bool favorite;
|
|
|
|
int last_played;
|
|
|
|
QString special_type;
|
2020-09-17 17:50:17 +02:00
|
|
|
PlaylistGenerator::Type dynamic_type;
|
|
|
|
QString dynamic_backend;
|
|
|
|
QByteArray dynamic_data;
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
2022-10-13 22:39:31 +02:00
|
|
|
using PlaylistList = QList<Playlist>;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
static const int kSongTableJoins;
|
|
|
|
|
2019-07-24 19:16:51 +02:00
|
|
|
void Close();
|
|
|
|
void ExitAsync();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
PlaylistList GetAllPlaylists();
|
|
|
|
PlaylistList GetAllOpenPlaylists();
|
|
|
|
PlaylistList GetAllFavoritePlaylists();
|
2021-09-09 21:45:46 +02:00
|
|
|
PlaylistBackend::Playlist GetPlaylist(const int id);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2023-02-18 14:09:27 +01:00
|
|
|
PlaylistItemPtrList GetPlaylistItems(const int playlist);
|
2021-09-19 15:41:36 +02:00
|
|
|
SongList GetPlaylistSongs(const int playlist);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void SetPlaylistOrder(const QList<int> &ids);
|
2021-09-09 21:45:46 +02:00
|
|
|
void SetPlaylistUiPath(const int id, const QString &path);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
int CreatePlaylist(const QString &name, const QString &special_type);
|
2023-02-18 14:09:27 +01:00
|
|
|
void SavePlaylistAsync(const int playlist, const PlaylistItemPtrList &items, const int last_played, PlaylistGeneratorPtr dynamic);
|
2021-09-09 21:45:46 +02:00
|
|
|
void RenamePlaylist(const int id, const QString &new_name);
|
|
|
|
void FavoritePlaylist(const int id, bool is_favorite);
|
|
|
|
void RemovePlaylist(const int id);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
Application *app() const { return app_; }
|
|
|
|
|
|
|
|
public slots:
|
2019-07-24 19:16:51 +02:00
|
|
|
void Exit();
|
2023-02-18 14:09:27 +01:00
|
|
|
void SavePlaylist(const int playlist, const PlaylistItemPtrList &items, const int last_played, PlaylistGeneratorPtr dynamic);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-07-11 09:49:38 +02:00
|
|
|
signals:
|
2019-07-24 19:16:51 +02:00
|
|
|
void ExitFinished();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
private:
|
|
|
|
struct NewSongFromQueryState {
|
|
|
|
QHash<QString, SongList> cached_cues_;
|
|
|
|
QMutex mutex_;
|
|
|
|
};
|
|
|
|
|
2023-07-21 05:55:24 +02:00
|
|
|
Song NewSongFromQuery(const SqlRow &row, SharedPtr<NewSongFromQueryState> state);
|
|
|
|
PlaylistItemPtr NewPlaylistItemFromQuery(const SqlRow &row, SharedPtr<NewSongFromQueryState> state);
|
|
|
|
PlaylistItemPtr RestoreCueData(PlaylistItemPtr item, SharedPtr<NewSongFromQueryState> state);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
enum GetPlaylistsFlags {
|
|
|
|
GetPlaylists_OpenInUi = 1,
|
|
|
|
GetPlaylists_Favorite = 2,
|
|
|
|
GetPlaylists_All = GetPlaylists_OpenInUi | GetPlaylists_Favorite
|
|
|
|
};
|
2021-09-09 21:45:46 +02:00
|
|
|
PlaylistList GetPlaylists(const GetPlaylistsFlags flags);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
Application *app_;
|
2023-07-21 05:55:24 +02:00
|
|
|
SharedPtr<Database> db_;
|
2019-07-24 19:16:51 +02:00
|
|
|
QThread *original_thread_;
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PLAYLISTBACKEND_H
|