File indexing completed on 2024-05-05 04:48:42

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Ian Monroe <ian@monroe.nu>                                        *
0003  * Copyright (c) 2008 Seb Ruiz <ruiz@kde.org>                                           *
0004  * Copyright (c) 2008 Soren Harward <stharward@gmail.com>                               *
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 AMAROK_PLAYLISTACTIONS_H
0022 #define AMAROK_PLAYLISTACTIONS_H
0023 
0024 #include "amarok_export.h"
0025 #include "core/support/Debug.h"
0026 #include "core/playlists/Playlist.h"
0027 
0028 #include <QQueue>
0029 #include <QModelIndex>
0030 #include <QUrl>
0031 
0032 #include <phonon/Global>
0033 
0034 namespace Playlist
0035 {
0036     class Actions;
0037 }
0038 
0039 namespace The
0040 {
0041     AMAROK_EXPORT Playlist::Actions* playlistActions();
0042 }
0043 
0044 namespace Playlist
0045 {
0046 class TrackNavigator;
0047 
0048 /**
0049  * This class is a central hub between the playlist model stack, the playlist navigators,
0050  * and the track playback engine. It ties them together to provide simple "Play", "Play
0051  * Next", etc. commands to the GUI code.
0052  */
0053 
0054 class AMAROK_EXPORT Actions : public QObject
0055 {
0056     Q_OBJECT
0057 
0058 public:
0059 
0060     static Actions* instance();
0061     static void destroy();
0062 
0063 
0064     Meta::TrackPtr likelyNextTrack();
0065     Meta::TrackPtr likelyPrevTrack();
0066 
0067     /**
0068      * This is called by the engine before the current track ends. It
0069      * will figure out the next track and enqueue it. This won't
0070      * actually change the track. That happens in the engine when the
0071      * current track ends.
0072      */
0073     void requestNextTrack();
0074 
0075     /**
0076      * Figure out the next track, and start playing it immediately.
0077      */
0078     void requestUserNextTrack();
0079 
0080     /**
0081      * Figure out the previous track and start playing it immediately.
0082      */
0083     void requestPrevTrack();
0084 
0085     /**
0086      * Set next track from track id, but don't start playing immediately
0087      */
0088     void requestTrack( quint64 id );
0089 
0090     /**
0091      * Request that Amarok stops playback after playing certain track.
0092      * @param id playlist id of a track to stop playing after or 0 to disable
0093      *           stopping after some track. If not specified, enable stopping
0094      *           after currently playing track.
0095      */
0096     void stopAfterPlayingTrack( quint64 id = -1 );
0097 
0098     bool willStopAfterTrack( const quint64 id ) const;
0099 
0100     // This shouldn't be in Actions, it doesn't make sense
0101     int queuePosition( quint64 id );
0102 
0103     // nor should this, ideally this and queuePosition
0104     // should be in TrackNavigator and TrackNavigator
0105     // should be publicly accessible
0106     QQueue<quint64> queue();
0107 
0108     bool queueMoveUp( quint64 id );
0109     bool queueMoveDown( quint64 id );
0110     void dequeue( quint64 id );
0111 
0112 public Q_SLOTS:
0113     void play();
0114     void play( const int row );
0115     void play( const QModelIndex& index );
0116     void play( const quint64 id, bool now = true );
0117     void next();
0118     void back();
0119     void enableDynamicMode( bool enable );
0120 
0121     /** Changes the tracknavigator depending on the current configuration */
0122     void playlistModeChanged();
0123 
0124     void repopulateDynamicPlaylist();
0125 
0126     /**
0127       * Shuffles tracks (that are visible in the top model) at the bottom model level
0128       */
0129     void shuffle();
0130 
0131     /**
0132      * Adds a list of top playlist model rows to the queue.
0133      */
0134     void queue( const QList<int> &rows );
0135 
0136     /**
0137      * Adds a list of playlist item unique ids to the queue.
0138      */
0139     void queue( const QList<quint64> &ids );
0140 
0141     void dequeue( const QList<int> &rows );
0142     void restoreDefaultPlaylist();
0143 
0144     /**
0145      * Make sure that there are enough tracks in the current playlist
0146      * if it is dynamic and the user removed tracks.
0147      */
0148     void normalizeDynamicPlaylist();
0149 
0150 
0151     /**
0152     * Repaint the playlist.
0153     * Useful when triggering a change that will modify the visual appearance of one or more items in the playlist
0154     */
0155     void repaintPlaylist();
0156 
0157 Q_SIGNALS:
0158     void navigatorChanged();
0159 
0160 private Q_SLOTS:
0161     void slotTrackPlaying( Meta::TrackPtr engineTrack );
0162     void slotPlayingStopped( qint64 finalPosition, qint64 trackLength );
0163 
0164 private:
0165     Actions();
0166     ~Actions() override;
0167 
0168     void init();
0169 
0170     quint64 m_nextTrackCandidate;
0171     /**
0172      * Playlist id if a track where the playback should be stopped or 0 if playback
0173      * shouldn't be stopped after certain track
0174      */
0175     quint64 m_stopAfterPlayingTrackId;
0176     TrackNavigator* m_navigator;                //!< the strategy of what to do when a track finishes playing
0177     bool m_waitingForNextTrack;
0178 
0179     static Actions* s_instance; //!< instance variable
0180 };
0181 } // namespace Playlist
0182 
0183 #endif