| 1 |
/**************************************************************************************** |
| 2 |
* Copyright (c) 2007 Ian Monroe <[email protected]> * |
| 3 |
* Copyright (c) 2008 Soren Harward <[email protected]> * |
| 4 |
* Copyright (c) 2009 Téo Mrnjavac <[email protected]> * |
| 5 |
* * |
| 6 |
* This program is free software; you can redistribute it and/or modify it under * |
| 7 |
* the terms of the GNU General Public License as published by the Free Software * |
| 8 |
* Foundation; either version 2 of the License, or (at your option) version 3 or * |
| 9 |
* any later version accepted by the membership of KDE e.V. (or its successor approved * |
| 10 |
* by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * |
| 11 |
* version 3 of the license. * |
| 12 |
* * |
| 13 |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY * |
| 14 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * |
| 15 |
* PARTICULAR PURPOSE. See the GNU General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU General Public License along with * |
| 18 |
* this program. If not, see <http://www.gnu.org/licenses/>. * |
| 19 |
****************************************************************************************/ |
| 20 |
|
| 21 |
#ifndef TRACKNAVIGATOR_H |
| 22 |
#define TRACKNAVIGATOR_H |
| 23 |
|
| 24 |
#include "playlist/proxymodels/AbstractModel.h" |
| 25 |
|
| 26 |
#include <QObject> |
| 27 |
#include <QQueue> |
| 28 |
|
| 29 |
namespace Playlist |
| 30 |
{ |
| 31 |
typedef QList<quint64> ItemList; // A convenient typedef! |
| 32 |
|
| 33 |
/** |
| 34 |
* An abstract class which defines what should be done after a track |
| 35 |
* finishes playing. The Playlist::Model will have an object of the |
| 36 |
* currently active strategy. It is the "strategy" pattern from the Design |
| 37 |
* Patterns book. In Amarok 1.x, the Playlist became very confusing due to |
| 38 |
* random mode and dynamic playlists requiring complicated nested if |
| 39 |
* statements. This should prevent that. |
| 40 |
*/ |
| 41 |
class TrackNavigator : public QObject |
| 42 |
{ |
| 43 |
Q_OBJECT |
| 44 |
|
| 45 |
public: |
| 46 |
TrackNavigator(); |
| 47 |
~TrackNavigator() override { } |
| 48 |
|
| 49 |
/** |
| 50 |
* what is the next track at this moment. It could change before the |
| 51 |
* track really plays (you need to catch playlist changes); does NOT |
| 52 |
* affect the navigators queue. |
| 53 |
*/ |
| 54 |
virtual quint64 likelyNextTrack() = 0; |
| 55 |
|
| 56 |
/** |
| 57 |
* what is the last track at this moment. It could change before the |
| 58 |
* track really plays (you need to catch playlist changes); does NOT |
| 59 |
* affect the navigators queue. |
| 60 |
*/ |
| 61 |
virtual quint64 likelyLastTrack() = 0; |
| 62 |
|
| 63 |
/** |
| 64 |
* The engine will finish the current track in a couple of seconds, |
| 65 |
* and would like to know what the next track should be. |
| 66 |
*/ |
| 67 |
virtual quint64 requestNextTrack() = 0; |
| 68 |
|
| 69 |
/** |
| 70 |
* The user triggers the next-track action. |
| 71 |
*/ |
| 72 |
virtual quint64 requestUserNextTrack() = 0; |
| 73 |
|
| 74 |
/** |
| 75 |
* The user triggers the previous-track action. |
| 76 |
*/ |
| 77 |
virtual quint64 requestLastTrack() = 0; |
| 78 |
|
| 79 |
/** |
| 80 |
* Find the position of the id in the queue |
| 81 |
* @return the position, or -1 if non in queue |
| 82 |
*/ |
| 83 |
int queuePosition( const quint64 id ) const; |
| 84 |
|
| 85 |
/** |
| 86 |
* Getter for the internal queue. |
| 87 |
* @return the tracks queued. |
| 88 |
*/ |
| 89 |
QQueue<quint64> queue(); |
| 90 |
|
| 91 |
public Q_SLOTS: |
| 92 |
/** |
| 93 |
* Queues the specified id and schedules it to be played. |
| 94 |
*/ |
| 95 |
virtual void queueIds( const QList<quint64> &ids ); |
| 96 |
|
| 97 |
/** |
| 98 |
* Dequeue the specified id from the queue list |
| 99 |
*/ |
| 100 |
virtual void dequeueId( const quint64 id ); |
| 101 |
|
| 102 |
/** |
| 103 |
* Play the track one position earlier. |
| 104 |
*/ |
| 105 |
bool queueMoveUp( const quint64 id ); |
| 106 |
|
| 107 |
/** |
| 108 |
* Play the track one position later. |
| 109 |
*/ |
| 110 |
bool queueMoveDown( const quint64 id ); |
| 111 |
|
| 112 |
/** |
| 113 |
* Move the track in specific queue position. |
| 114 |
*/ |
| 115 |
bool queueMoveTo( const quint64 id, const int pos ); |
| 116 |
|
| 117 |
private Q_SLOTS: |
| 118 |
void slotModelReset(); |
| 119 |
void slotRowsAboutToBeRemoved( const QModelIndex &parent, int start, int end ); |
| 120 |
|
| 121 |
protected: |
| 122 |
/** |
| 123 |
* Choose the most reasonable fallback item in case a navigator wants to play |
| 124 |
* something, but doesn't have a good choice itself. |
| 125 |
*/ |
| 126 |
quint64 bestFallbackItem(); |
| 127 |
|
| 128 |
// Holds the list of tracks to be played next. General |
| 129 |
// workflow should dictate that the TrackAdvancer should |
| 130 |
// respect the queue list as an override to what the Advancer |
| 131 |
// implementation would normally return as the next track. |
| 132 |
// TODO: a history queue to allow requestLastTrack() to work |
| 133 |
// properly? |
| 134 |
// Static queue so that all navigators share the same queue |
| 135 |
QQueue<quint64> m_queue; |
| 136 |
|
| 137 |
AbstractModel *m_model; |
| 138 |
}; |
| 139 |
} |
| 140 |
|
| 141 |
#endif |