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 
34 #include "Components/PlayManager/PlayState.h"
35 
36 #include "Utils/Pimpl.h"
37 #include "Utils/Singleton.h"
38 #include "Utils/Settings/SayonaraClass.h"
39 #include "Utils/Playlist/PlaylistFwd.h"
40 #include "Utils/Library/LibraryNamespaces.h"
41 
42 class CustomPlaylist;
43 
44 namespace Playlist
45 {
50  class Handler :
51  public QObject,
52  public SayonaraClass
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:
75 
81  void sig_current_track_changed(int track_idx, int playlist_idx);
82 
88 
93  void sig_playlist_name_changed(int idx);
94 
99 
100 
101  void sig_current_playlist_changed(int idx);
102 
103  void sig_track_deletion_requested(const MetaDataList& v_md, Library::TrackDeletionMode deletion_mode);
104 
105 
106  public:
107 
108  void shutdown();
109 
114  void clear_playlist(int pl_idx);
115 
120  void play_next(const MetaDataList& v_md);
121 
128  void insert_tracks(const MetaDataList& v_md, int idx, int pl_idx);
129 
130 
136  void append_tracks(const MetaDataList& v_md, int pl_idx);
137 
144  void move_rows(const IndexSet& indexes, int tgt_idx, int pl_idx);
145 
146 
152  void remove_rows(const IndexSet& indexes, int pl_idx);
153 
154 
160  void change_track(int track_idx, int pl_idx);
161 
162 
167  int active_index() const;
168  PlaylistConstPtr active_playlist() const;
169 
170 
171  int current_index() const;
172  void set_current_index(int pl_idx);
173 
174 
180  PlaylistConstPtr playlist(int pl_idx) const;
181 
182 
187  void delete_playlist(int pl_idx);
188 
193  int close_playlist(int pl_idx);
194 
195 
200  void reset_playlist(int pl_idx);
201 
206  QString request_new_playlist_name() const;
207 
208 
214  DBInterface::SaveAsAnswer save_playlist(int pl_idx);
215 
216 
224  DBInterface::SaveAsAnswer save_playlist_as(int pl_idx, const QString& name, bool force_override);
225 
226 
233  DBInterface::SaveAsAnswer rename_playlist(int pl_idx, const QString& name);
234 
235 
241  void save_playlist_to_file(int pl_idx, const QString& filename, bool relative);
242 
243 
244 
253  int create_playlist(const MetaDataList& v_md, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
254 
263  int create_playlist(const QStringList& path_list, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
264 
274  int create_playlist(const QString& dir, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
275 
276 
282  int create_playlist(const CustomPlaylist& pl);
283 
284 
290  int create_empty_playlist(bool override_current=false);
291 
292  int create_empty_playlist(const QString& name);
293 
294 
295  void delete_tracks(int pl_idx, const IndexSet& rows, Library::TrackDeletionMode deletion_mode);
296 
297  public slots:
302  int load_old_playlists();
303 
304 
305  private slots:
306 
310  void played();
311 
315  void paused();
316 
320  void stopped();
321 
325  void previous();
326 
330  void next();
331 
332  void wake_up();
333 
334 
338  void playstate_changed(PlayState state);
339 
340  void www_track_finished(const MetaData& md);
341 
342 
343 
344  private:
345  // adds a new playlist, creates it, if name is not in the list of playlists. If name already exists,
346  // this function returns the index
347  int add_new_playlist(const QString& name, bool editable, Playlist::Type type=Playlist::Type::Std);
348 
349  // raw creation of playlists
350  PlaylistPtr new_playlist(Playlist::Type type, int idx, QString name="");
351 
352 
358  int exists(const QString& name) const;
359 
360 
366  PlaylistPtr active_playlist();
367 
374  PlaylistPtr playlist(int pl_idx, PlaylistPtr fallback) const;
375 
376 
382  void emit_cur_track_changed();
383 
388  void set_active_idx(int pl_idx);
389  };
390 }
391 
392 #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:50
TrackDeletionMode
The TrackDeletionMode enum.
Definition: LibraryNamespaces.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:44
int close_playlist(int pl_idx)
close playlist
int active_index() const
get active playlist index
The MetaDataList class.
Definition: MetaDataList.h:37
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:63
int load_old_playlists()
load playlists of last session from database
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
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: Set.h:35
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
std::shared_ptr< Playlist::Base > PlaylistPtr
PlaylistPtr Playlist Pointer (only used internally)
Definition: PlaylistFwd.h:38
Definition: AbstractPlaylist.h:33
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