Sayonara Player
PlaylistHandler.h
1 /* Playlist.h */
2 
3 /* Copyright (C) 2011-2017 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: Lucio Carreras
27  */
28 
29 #ifndef PLAYLISTHANDLER_H_
30 #define PLAYLISTHANDLER_H_
31 
32 #include "PlaylistDBInterface.h"
33 #include "Components/PlayManager/PlayState.h"
34 
35 #include "Utils/Pimpl.h"
36 #include "Utils/Singleton.h"
37 #include "Utils/Settings/SayonaraClass.h"
38 #include "Utils/Playlist/PlaylistFwd.h"
39 #include "Utils/Library/LibraryNamespaces.h"
40 
41 #include <QStringList>
42 
43 class CustomPlaylist;
44 class MetaData;
45 class MetaDataList;
46 
47 namespace SP
48 {
49  template<typename T>
50  class Set;
51 }
52 
53 namespace Playlist
54 {
59  class Handler :
60  public QObject,
61  public SayonaraClass
62  {
63  Q_OBJECT
64  PIMPL(Handler)
65  SINGLETON_QOBJECT(Handler)
66 
67  public:
68 
72  enum class PlaylistIndex : uint8_t
73  {
74  Current=0,
75  Active
76  };
77 
78 
79  signals:
85 
91  void sig_current_track_changed(int track_idx, int playlist_idx);
92 
98 
103  void sig_playlist_name_changed(int idx);
104 
109 
110 
111  void sig_current_playlist_changed(int idx);
112 
113  void sig_track_deletion_requested(const MetaDataList& v_md, Library::TrackDeletionMode deletion_mode);
114 
115 
116  public:
117 
118  void shutdown();
119 
124  void clear_playlist(int pl_idx);
125 
130  void play_next(const MetaDataList& v_md);
131 
138  void insert_tracks(const MetaDataList& v_md, int idx, int pl_idx);
139 
140 
146  void append_tracks(const MetaDataList& v_md, int pl_idx);
147 
154  void move_rows(const IndexSet& indexes, int tgt_idx, int pl_idx);
155 
156 
162  void remove_rows(const IndexSet& indexes, int pl_idx);
163 
164 
170  void change_track(int track_idx, int pl_idx);
171 
172 
177  int active_index() const;
178  PlaylistConstPtr active_playlist() const;
179 
180 
181  int current_index() const;
182  void set_current_index(int pl_idx);
183 
184 
190  PlaylistConstPtr playlist(int pl_idx) const;
191 
192 
197  void delete_playlist(int pl_idx);
198 
203  int close_playlist(int pl_idx);
204 
205 
210  void reset_playlist(int pl_idx);
211 
216  QString request_new_playlist_name() const;
217 
218 
224  DBInterface::SaveAsAnswer save_playlist(int pl_idx);
225 
226 
234  DBInterface::SaveAsAnswer save_playlist_as(int pl_idx, const QString& name, bool force_override);
235 
236 
243  DBInterface::SaveAsAnswer rename_playlist(int pl_idx, const QString& name);
244 
245 
251  void save_playlist_to_file(int pl_idx, const QString& filename, bool relative);
252 
253 
254 
263  int create_playlist(const MetaDataList& v_md, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
264 
273  int create_playlist(const QStringList& path_list, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
274 
284  int create_playlist(const QString& dir, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
285 
286 
292  int create_playlist(const CustomPlaylist& pl);
293 
294 
300  int create_empty_playlist(bool override_current=false);
301 
302  int create_empty_playlist(const QString& name);
303 
304 
305  void delete_tracks(int pl_idx, const IndexSet& rows, Library::TrackDeletionMode deletion_mode);
306 
307  public slots:
312  int load_old_playlists();
313 
314 
315  private slots:
316 
320  void played();
321 
325  void paused();
326 
330  void stopped();
331 
335  void previous();
336 
340  void next();
341 
342  void wake_up();
343 
344 
348  void playstate_changed(PlayState state);
349 
350  void www_track_finished(const MetaData& md);
351 
352 
353 
354  private:
355  // adds a new playlist, creates it, if name is not in the list of playlists. If name already exists,
356  // this function returns the index
357  int add_new_playlist(const QString& name, bool editable, Playlist::Type type=Playlist::Type::Std);
358 
359  // raw creation of playlists
360  PlaylistPtr new_playlist(Playlist::Type type, int idx, QString name="");
361 
362 
368  int exists(const QString& name) const;
369 
370 
376  PlaylistPtr active_playlist();
377 
384  PlaylistPtr playlist(int pl_idx, PlaylistPtr fallback) const;
385 
386 
392  void emit_cur_track_changed();
393 
398  void set_active_idx(int pl_idx);
399  };
400 }
401 
402 #endif /* PLAYLISTHANDLER_H_ */
void insert_tracks(const MetaDataList &v_md, int idx, int pl_idx)
insert tracks into a playlist at a given index
DBInterface::SaveAsAnswer rename_playlist(int pl_idx, const QString &name)
rename playlist
void save_playlist_to_file(int pl_idx, const QString &filename, bool relative)
save a playlist to file
void sig_current_track_changed(int track_idx, int playlist_idx)
emitted when current track index has changed
int create_empty_playlist(bool override_current=false)
create a new empty playlist
void delete_playlist(int pl_idx)
delete the given playlist from database
Global handler for playlists.
Definition: PlaylistHandler.h:59
TrackDeletionMode
The TrackDeletionMode enum.
Definition: LibraryNamespaces.h:35
Definition: AbstractPlaylist.h:35
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:29
void remove_rows(const IndexSet &indexes, int pl_idx)
remove rows from playlist
PlayState
The PlayState enum.
Definition: PlayState.h:28
The MetaData class.
Definition: MetaData.h:48
int close_playlist(int pl_idx)
close playlist
int active_index() const
get active playlist index
The MetaDataList class.
Definition: MetaDataList.h:38
void play_next(const MetaDataList &v_md)
insert tracks to active playlist after current playback position
void sig_playlist_name_changed(int idx)
emitted when playlist name has changed
void sig_playlist_created(PlaylistPtr pl)
emitted when new playlist has been created
PlaylistIndex
The PlaylistIndex enum.
Definition: PlaylistHandler.h:72
int load_old_playlists()
load playlists of last session from database
Set namespace defines the setting: Which key and which type.
Definition: SettingKey.h:230
DBInterface::SaveAsAnswer save_playlist_as(int pl_idx, const QString &name, bool force_override)
Save playlist under new name.
PlaylistConstPtr playlist(int pl_idx) const
get specific playlist at given index
void change_track(int track_idx, int pl_idx)
change the track in a given playlist
std::shared_ptr< const Playlist::Base > PlaylistConstPtr
PlaylistConstPtr read only Playlist Pointer.
Definition: PlaylistFwd.h:45
void append_tracks(const MetaDataList &v_md, int pl_idx)
append tracks at a given playlist index
void clear_playlist(int pl_idx)
clears the current visible playlist
void sig_new_playlist_added(PlaylistPtr pl)
emitted when new playlist has been added
int create_playlist(const MetaDataList &v_md, const QString &name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std)
create a new playlist
The CustomPlaylist class.
Definition: CustomPlaylist.h:31
QString request_new_playlist_name() const
Request a new name for the playlist (usually new %1 is returned)
void reset_playlist(int pl_idx)
reload playlist from db
void sig_saved_playlists_changed()
emitted when saved playlists have changed
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:38
std::shared_ptr< Playlist::Base > PlaylistPtr
PlaylistPtr Playlist Pointer (only used internally)
Definition: PlaylistFwd.h:38
Definition: AbstractPlaylist.h:44
DBInterface::SaveAsAnswer save_playlist(int pl_idx)
save playlist to database, overwrite old one
void move_rows(const IndexSet &indexes, int tgt_idx, int pl_idx)
move rows within playlist