File indexing completed on 2024-05-19 04:49:50
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Ian Monroe <ian@monroe.nu> * 0003 * Copyright (c) 2008 Soren Harward <stharward@gmail.com> * 0004 * Copyright (c) 2009 Téo Mrnjavac <teo@kde.org> * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify it under * 0007 * the terms of the GNU General Public License as published by the Free Software * 0008 * Foundation; either version 2 of the License, or (at your option) version 3 or * 0009 * any later version accepted by the membership of KDE e.V. (or its successor approved * 0010 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 0011 * version 3 of the license. * 0012 * * 0013 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0014 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0015 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0016 * * 0017 * You should have received a copy of the GNU General Public License along with * 0018 * this program. If not, see <http://www.gnu.org/licenses/>. * 0019 ****************************************************************************************/ 0020 0021 #ifndef TRACKNAVIGATOR_H 0022 #define TRACKNAVIGATOR_H 0023 0024 #include "playlist/proxymodels/AbstractModel.h" 0025 0026 #include <QObject> 0027 #include <QQueue> 0028 0029 namespace Playlist 0030 { 0031 typedef QList<quint64> ItemList; // A convenient typedef! 0032 0033 /** 0034 * An abstract class which defines what should be done after a track 0035 * finishes playing. The Playlist::Model will have an object of the 0036 * currently active strategy. It is the "strategy" pattern from the Design 0037 * Patterns book. In Amarok 1.x, the Playlist became very confusing due to 0038 * random mode and dynamic playlists requiring complicated nested if 0039 * statements. This should prevent that. 0040 */ 0041 class TrackNavigator : public QObject 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 TrackNavigator(); 0047 ~TrackNavigator() override { } 0048 0049 /** 0050 * what is the next track at this moment. It could change before the 0051 * track really plays (you need to catch playlist changes); does NOT 0052 * affect the navigators queue. 0053 */ 0054 virtual quint64 likelyNextTrack() = 0; 0055 0056 /** 0057 * what is the last track at this moment. It could change before the 0058 * track really plays (you need to catch playlist changes); does NOT 0059 * affect the navigators queue. 0060 */ 0061 virtual quint64 likelyLastTrack() = 0; 0062 0063 /** 0064 * The engine will finish the current track in a couple of seconds, 0065 * and would like to know what the next track should be. 0066 */ 0067 virtual quint64 requestNextTrack() = 0; 0068 0069 /** 0070 * The user triggers the next-track action. 0071 */ 0072 virtual quint64 requestUserNextTrack() = 0; 0073 0074 /** 0075 * The user triggers the previous-track action. 0076 */ 0077 virtual quint64 requestLastTrack() = 0; 0078 0079 /** 0080 * Find the position of the id in the queue 0081 * @return the position, or -1 if non in queue 0082 */ 0083 int queuePosition( const quint64 id ) const; 0084 0085 /** 0086 * Getter for the internal queue. 0087 * @return the tracks queued. 0088 */ 0089 QQueue<quint64> queue(); 0090 0091 public Q_SLOTS: 0092 /** 0093 * Queues the specified id and schedules it to be played. 0094 */ 0095 virtual void queueIds( const QList<quint64> &ids ); 0096 0097 /** 0098 * Dequeue the specified id from the queue list 0099 */ 0100 virtual void dequeueId( const quint64 id ); 0101 0102 /** 0103 * Play the track one position earlier. 0104 */ 0105 bool queueMoveUp( const quint64 id ); 0106 0107 /** 0108 * Play the track one position later. 0109 */ 0110 bool queueMoveDown( const quint64 id ); 0111 0112 private Q_SLOTS: 0113 void slotModelReset(); 0114 void slotRowsAboutToBeRemoved( const QModelIndex &parent, int start, int end ); 0115 0116 protected: 0117 /** 0118 * Choose the most reasonable fallback item in case a navigator wants to play 0119 * something, but doesn't have a good choice itself. 0120 */ 0121 quint64 bestFallbackItem(); 0122 0123 // Holds the list of tracks to be played next. General 0124 // workflow should dictate that the TrackAdvancer should 0125 // respect the queue list as an override to what the Advancer 0126 // implementation would normally return as the next track. 0127 // TODO: a history queue to allow requestLastTrack() to work 0128 // properly? 0129 // Static queue so that all navigators share the same queue 0130 QQueue<quint64> m_queue; 0131 0132 AbstractModel *m_model; 0133 }; 0134 } 0135 0136 #endif