Sayonara Player
PlaylistHandler.h
1 /* Playlist.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 
22 /*
23  * Playlist.h
24  *
25  * Created on: Apr 6, 2011
26  * Author: Michael Lugmair (Lucio Carreras)
27  */
28 
29 #ifndef PLAYLISTHANDLER_H_
30 #define PLAYLISTHANDLER_H_
31 
32 #include "PlaylistDBInterface.h"
33 
34 #include "Components/PlayManager/PlayState.h"
35 
36 #include "Utils/Pimpl.h"
37 #include "Utils/Singleton.h"
38 #include "Utils/Playlist/PlaylistFwd.h"
39 #include "Utils/Library/LibraryNamespaces.h"
40 
41 #include <QObject>
42 
43 class CustomPlaylist;
44 
45 namespace Playlist
46 {
51  class Handler :
52  public QObject
53  {
54  Q_OBJECT
55  PIMPL(Handler)
56  SINGLETON_QOBJECT(Handler)
57 
58  public:
59 
63  enum class PlaylistIndex : uint8_t
64  {
65  Current=0,
66  Active
67  };
68 
69  signals:
74  void sigPlaylistCreated(PlaylistPtr pl);
75 
81  void sigCurrentTrackChanged(int trackIndex, int playlist_idx);
82 
87  void sigNewPlaylistAdded(PlaylistPtr pl);
88 
93  void sigPlaylistNameChanged(int idx);
94 
99  void sigCurrentPlaylistChanged(int idx);
100  void sigActivePlaylistChanged(int idx);
101 
107  void sigTrackDeletionRequested(const MetaDataList& tracks, Library::TrackDeletionMode deletion_mode);
108 
109  void sigFindTrackRequested(TrackID trackId);
110 
111 
112  public:
113 
118  void shutdown();
119 
124  void clearPlaylist(int playlistIndex);
125 
130  void playNext(const MetaDataList& tracks);
131  void playNext(const QStringList& paths);
132 
139  void insertTracks(const MetaDataList& tracks, int idx, int playlistIndex);
140  void insertTracks(const QStringList& paths, int idx, int playlistIndex);
141 
142 
148  void appendTracks(const MetaDataList& tracks, int playlistIndex);
149  void appendTracks(const QStringList& paths, int playlistIndex);
150 
157  void moveRows(const IndexSet& indexes, int tgt_idx, int playlistIndex);
158 
159 
165  void removeRows(const IndexSet& indexes, int playlistIndex);
166 
167 
173  void changeTrack(int trackIndex, int playlistIndex);
174 
175 
180  int activeIndex() const;
181  PlaylistConstPtr activePlaylist() const;
182 
183 
184  int current_index() const;
185  void set_current_index(int playlistIndex);
186 
191  int count() const;
192 
193 
199  PlaylistConstPtr playlist(int playlistIndex) const;
200 
201 
206  void deletePlaylist(int playlistIndex);
207 
212  int closePlaylist(int playlistIndex);
213 
214 
219  void resetPlaylist(int playlistIndex);
220 
228  QString requestNewPlaylistName(const QString& prefix=QString()) const;
229 
230 
236  Util::SaveAsAnswer savePlaylist(int playlistIndex);
237 
238 
246  Util::SaveAsAnswer savePlaylistAs(int playlistIndex, const QString& name, bool forceOverride);
247 
248 
255  Util::SaveAsAnswer renamePlaylist(int playlistIndex, const QString& name);
256 
257 
263  void savePlaylistToFile(int playlistIndex, const QString& filename, bool relative);
264 
273  int createPlaylist(const MetaDataList& tracks, const QString& name=QString(), bool temporary=true);
274 
283  int createPlaylist(const QStringList& path_list, const QString& name=QString(), bool temporary=true);
284 
294  int createPlaylist(const QString& dir, const QString& name=QString(), bool temporary=true);
295 
296 
302  int createPlaylist(const CustomPlaylist& pl);
303 
304 
310  int createEmptyPlaylist(bool overrideCurrent=false);
311  int createEmptyPlaylist(const QString& name);
312 
313 
314  void deleteTracks(int playlistIndex, const IndexSet& rows, Library::TrackDeletionMode deletion_mode);
315 
316  public slots:
321  int loadOldPlaylists();
322 
323 
324  private slots:
325 
329  void played();
330 
334  void stopped();
335 
339  void previous();
340 
344  void next();
345 
346  void wakeUp();
347 
348 
352  void playstateChanged(PlayState state);
353 
354  void wwwTrackFinished(const MetaData& md);
355 
356  void currentTrackChanged(int index);
357  void playlistStopped();
358 
359  void playlistRenamed(int id, const QString& oldName, const QString& newName);
360  void playlistDeleted(int id);
361 
366  void filescannerProgressChanged(const QString& current_file);
367  void filesScanned();
368 
369  private:
377  int addNewPlaylist(const QString& name, bool editable);
378 
386  PlaylistPtr newPlaylist(QString name);
387 
388 
394  int exists(const QString& name) const;
395 
396 
402  PlaylistPtr activePlaylist();
403 
410  PlaylistPtr playlist(int playlistIndex, PlaylistPtr fallback) const;
411 
412 
418  void emitCurrentTrackChanged();
419 
424  void setActiveIndex(int playlist_index);
425 
434  void createFilescanner(int playlist_index, const QStringList& paths, int target_row_idx);
435  };
436 }
437 
438 #endif /* PLAYLISTHANDLER_H_ */
void sigPlaylistNameChanged(int idx)
emitted when playlist name has changed
void appendTracks(const MetaDataList &tracks, int playlistIndex)
append tracks at a given playlist index
Global handler for playlists.
Definition: PlaylistHandler.h:51
void moveRows(const IndexSet &indexes, int tgt_idx, int playlistIndex)
move rows within playlist
void sigPlaylistCreated(PlaylistPtr pl)
emitted when new playlist has been created
void removeRows(const IndexSet &indexes, int playlistIndex)
remove rows from playlist
PlayState
The PlayState enum.
Definition: PlayState.h:28
int createEmptyPlaylist(bool overrideCurrent=false)
create a new empty playlist
The MetaData class.
Definition: MetaData.h:45
void resetPlaylist(int playlistIndex)
reload playlist from db
void savePlaylistToFile(int playlistIndex, const QString &filename, bool relative)
save a playlist to file
void insertTracks(const MetaDataList &tracks, int idx, int playlistIndex)
insert tracks into a playlist at a given index
int count() const
Returns number of playlists.
The MetaDataList class.
Definition: MetaDataList.h:35
void shutdown()
Call this before the program stops. Singletons and Destructors don't work out so well.
void sigCurrentTrackChanged(int trackIndex, int playlist_idx)
emitted when current track index has changed
PlaylistIndex
The PlaylistIndex enum.
Definition: PlaylistHandler.h:63
int loadOldPlaylists()
load playlists of last session from database
int activeIndex() const
get active playlist index
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:35
void changeTrack(int trackIndex, int playlistIndex)
change the track in a given playlist
TrackDeletionMode
The TrackDeletionMode enum.
Definition: LibraryNamespaces.h:36
Util::SaveAsAnswer savePlaylistAs(int playlistIndex, const QString &name, bool forceOverride)
Save playlist under new name.
QString requestNewPlaylistName(const QString &prefix=QString()) const
Request a new name for the playlist (usually New %1 is returned). If the prefix differs,...
Util::SaveAsAnswer renamePlaylist(int playlistIndex, const QString &name)
rename playlist
void playNext(const MetaDataList &tracks)
insert tracks to active playlist after current playback position
void deletePlaylist(int playlistIndex)
delete the given playlist from database
Util::SaveAsAnswer savePlaylist(int playlistIndex)
save playlist to database, overwrite old one
The CustomPlaylist class.
Definition: CustomPlaylist.h:31
int closePlaylist(int playlistIndex)
close playlist
PlaylistConstPtr playlist(int playlistIndex) const
get specific playlist at given index
void sigNewPlaylistAdded(PlaylistPtr pl)
emitted when new playlist has been added
void clearPlaylist(int playlistIndex)
clears the current visible playlist
int createPlaylist(const MetaDataList &tracks, const QString &name=QString(), bool temporary=true)
create a new playlist
void sigTrackDeletionRequested(const MetaDataList &tracks, Library::TrackDeletionMode deletion_mode)
emitted when a track deletion was triggered over the Ui
void sigCurrentPlaylistChanged(int idx)
emitted when tracks were added/removed or have changed