2021-07-31 13:06:17 +00:00
|
|
|
/*
|
|
|
|
* Sailfin: a Jellyfin client written using Qt
|
core: Split PlaybackManager up into smaller parts
The PlaybackManager was a giant class that handled UI bindings, fetching
stream URLS, playback logic.
It now has been split up into:
- ViewModel::PlaybackManager, which handles UI interfacing and allowing
to swap out the Model::Playback implementation on the fly.
- Model::PlaybackManager, which is an interface for what a
PlaybackManager must do, handling queues/playlists, and controlling a
player.
- Model::LocalPlaybackManager, which is an Model::PlaybackManager
implementation for playing back Jellyfin media within the application.
- Model::PlaybackReporter, which reports the current playback state to
the Jellyfin server, for keeping track of played items.
- Model::Player, which handles playing back media from an URL and
the usual play/pause et cetera.
In a future commit, this would allow for introducing a
Model::RemoteJellyfinPlaybackManager, to control other Jellyfin
instances.
2022-01-05 20:24:52 +00:00
|
|
|
* Copyright (C) 2021-2022 Chris Josten and the Sailfin Contributors.
|
2021-07-31 13:06:17 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2021-05-21 13:46:30 +00:00
|
|
|
#ifndef JELLYFIN_MODEL_PLAYLIST_H
|
|
|
|
#define JELLYFIN_MODEL_PLAYLIST_H
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
#include <QObject>
|
2021-05-21 13:46:30 +00:00
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QString>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QVector>
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
#include "../viewmodel/itemmodel.h"
|
|
|
|
#include "item.h"
|
2021-05-21 13:46:30 +00:00
|
|
|
|
|
|
|
namespace Jellyfin {
|
|
|
|
namespace Model {
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
class Shuffle;
|
2021-05-21 13:46:30 +00:00
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
/**
|
|
|
|
* @brief Model of a playlist, a list of items that can be played.
|
|
|
|
*
|
|
|
|
* This tries to take the managing what items to play away from the PlaybackManager,
|
|
|
|
* which now only will be informed about the current and next item to play.
|
|
|
|
*
|
|
|
|
* The playlist has actually two list, one named list and the other named queue. When
|
|
|
|
* playing, the queue has priority over the list and will not be affected by the
|
|
|
|
* shuffle mode. After all items of the queue are played, the items in the list are played.
|
|
|
|
* Items in the list may be shuffled.
|
|
|
|
*/
|
|
|
|
class Playlist : public QObject {
|
|
|
|
Q_OBJECT
|
2021-05-21 13:46:30 +00:00
|
|
|
public:
|
2021-07-31 13:06:17 +00:00
|
|
|
explicit Playlist(QObject *parent = nullptr);
|
2021-05-21 13:46:30 +00:00
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
/// Returns the current item in the queue
|
|
|
|
QSharedPointer<Item> currentItem();
|
|
|
|
QSharedPointer<Item> nextItem();
|
2021-08-21 20:01:13 +00:00
|
|
|
/**
|
|
|
|
* @return the current index of the playing item if it is in the list. If playing from the queue,
|
|
|
|
* returns -1.
|
|
|
|
*/
|
|
|
|
int currentItemIndexInList() const;
|
2021-05-21 13:46:30 +00:00
|
|
|
|
2021-08-30 23:29:51 +00:00
|
|
|
bool hasPrevious();
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
/**
|
|
|
|
* @brief Determine the previous item to be played.
|
|
|
|
*/
|
|
|
|
void previous();
|
2021-05-21 13:46:30 +00:00
|
|
|
|
2021-08-30 23:29:51 +00:00
|
|
|
bool hasNext();
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
/**
|
|
|
|
* @brief Determine the next item to be played.
|
|
|
|
*/
|
|
|
|
void next();
|
|
|
|
|
2021-08-21 20:01:13 +00:00
|
|
|
int queueSize() { return m_queue.size(); };
|
2021-07-31 13:06:17 +00:00
|
|
|
int listSize() const { return m_list.size(); };
|
|
|
|
int totalSize() const { return m_queue.size() + m_list.size(); }
|
|
|
|
|
2021-08-21 20:01:13 +00:00
|
|
|
/**
|
|
|
|
* @brief Returns the item at the given index of the currently selected playlist, excluding the queue.
|
|
|
|
* @param index
|
|
|
|
* @return The given item.
|
|
|
|
*/
|
2021-07-31 13:06:17 +00:00
|
|
|
QSharedPointer<const Item> listAt(int index) const;
|
2021-08-21 20:01:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the item at the given index of the currently queue, excluding the playlist.
|
|
|
|
* @param index
|
|
|
|
* @return The given item.
|
|
|
|
*/
|
|
|
|
QSharedPointer<const Item> queueAt(int index) const;
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
/**
|
2021-08-21 20:01:13 +00:00
|
|
|
* @brief Removes all the items from the playlist, but not from the queue.
|
2021-07-31 13:06:17 +00:00
|
|
|
*/
|
|
|
|
void clearList();
|
|
|
|
|
|
|
|
/**
|
core: Split PlaybackManager up into smaller parts
The PlaybackManager was a giant class that handled UI bindings, fetching
stream URLS, playback logic.
It now has been split up into:
- ViewModel::PlaybackManager, which handles UI interfacing and allowing
to swap out the Model::Playback implementation on the fly.
- Model::PlaybackManager, which is an interface for what a
PlaybackManager must do, handling queues/playlists, and controlling a
player.
- Model::LocalPlaybackManager, which is an Model::PlaybackManager
implementation for playing back Jellyfin media within the application.
- Model::PlaybackReporter, which reports the current playback state to
the Jellyfin server, for keeping track of played items.
- Model::Player, which handles playing back media from an URL and
the usual play/pause et cetera.
In a future commit, this would allow for introducing a
Model::RemoteJellyfinPlaybackManager, to control other Jellyfin
instances.
2022-01-05 20:24:52 +00:00
|
|
|
* @brief Appends all items from the given item list to this list
|
2021-07-31 13:06:17 +00:00
|
|
|
*/
|
core: Split PlaybackManager up into smaller parts
The PlaybackManager was a giant class that handled UI bindings, fetching
stream URLS, playback logic.
It now has been split up into:
- ViewModel::PlaybackManager, which handles UI interfacing and allowing
to swap out the Model::Playback implementation on the fly.
- Model::PlaybackManager, which is an interface for what a
PlaybackManager must do, handling queues/playlists, and controlling a
player.
- Model::LocalPlaybackManager, which is an Model::PlaybackManager
implementation for playing back Jellyfin media within the application.
- Model::PlaybackReporter, which reports the current playback state to
the Jellyfin server, for keeping track of played items.
- Model::Player, which handles playing back media from an URL and
the usual play/pause et cetera.
In a future commit, this would allow for introducing a
Model::RemoteJellyfinPlaybackManager, to control other Jellyfin
instances.
2022-01-05 20:24:52 +00:00
|
|
|
void appendToList(const QList<QSharedPointer<Item>> &model);
|
2021-07-31 13:06:17 +00:00
|
|
|
|
2021-09-09 03:57:41 +00:00
|
|
|
/**
|
|
|
|
* @brief appendToList Appends a single item to the current list
|
|
|
|
* @param item The item to append
|
|
|
|
*/
|
|
|
|
void appendToList(QSharedPointer<Model::Item> item);
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
/**
|
|
|
|
* @brief Start playing this playlist
|
|
|
|
* @param index The index to start from.
|
|
|
|
*/
|
|
|
|
void play(int index = 0);
|
2021-08-21 20:01:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief playingFromQueue
|
|
|
|
* @return True if the currently played item comes from the queue.
|
|
|
|
*/
|
|
|
|
bool playingFromQueue() const;
|
|
|
|
|
2021-07-31 13:06:17 +00:00
|
|
|
signals:
|
2021-08-21 20:01:13 +00:00
|
|
|
void beforeListCleared();
|
2021-07-31 13:06:17 +00:00
|
|
|
void listCleared();
|
2021-08-21 20:01:13 +00:00
|
|
|
void beforeItemsAddedToQueue(int index, int count);
|
|
|
|
void beforeItemsAddedToList(int index, int count);
|
|
|
|
void itemsAddedToQueue();
|
|
|
|
void itemsAddedToList();
|
|
|
|
void beforeItemsRemovedFromQueue(int index, int count);
|
|
|
|
void beforeItemsRemovedFromList(int index, int count);
|
|
|
|
void itemsRemovedFromQueue();
|
|
|
|
void itemsRemovedFromList();
|
2021-07-31 13:06:17 +00:00
|
|
|
void listReshuffled();
|
2021-08-21 20:01:13 +00:00
|
|
|
void currentItemChanged();
|
2021-05-21 13:46:30 +00:00
|
|
|
private:
|
2021-07-31 13:06:17 +00:00
|
|
|
void reshuffle();
|
|
|
|
|
|
|
|
QSharedPointer<Item> m_currentItem;
|
|
|
|
bool m_currentItemFromQueue = false;
|
|
|
|
QSharedPointer<Item> m_nextItem;
|
|
|
|
bool m_nextItemFromQueue = false;
|
|
|
|
|
|
|
|
/// list of the items in the queue
|
|
|
|
QVector<QSharedPointer<Item>> m_queue;
|
|
|
|
/// list of the items in the playlist
|
|
|
|
QVector<QSharedPointer<Item>> m_list;
|
|
|
|
/// The current position in the playlist
|
|
|
|
int m_pos = 0;
|
|
|
|
|
|
|
|
/// Algorithm for shuffling the playlist.
|
|
|
|
Shuffle *m_shuffler;
|
2021-05-21 13:46:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // JELLYFIN_MODEL_PLAYLIST_H
|