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 "Helper/Singleton.h"
36 #include "Helper/Settings/SayonaraClass.h"
37 #include "Helper/Playlist/PlaylistFwd.h"
38 #include "Helper/Library/LibraryNamespaces.h"
39 
40 
41 class PlayManager;
42 class DatabaseConnector;
43 class CustomPlaylist;
44 class MetaData;
45 class MetaDataList;
46 
47 namespace SP
48 {
49  template<typename T>
50  class Set;
51 }
52 
57 class PlaylistHandler : public QObject, protected SayonaraClass
58 {
59  Q_OBJECT
60 
61  SINGLETON_QOBJECT(PlaylistHandler)
62 
63 public:
64 
68  enum class PlaylistIndex : quint8
69  {
70  Current=0,
71  Active
72  };
73 
74 
75 signals:
80  void sig_playlist_created(PlaylistPtr pl);
81 
87  void sig_cur_track_idx_changed(int track_idx, int playlist_idx);
88 
93  void sig_new_playlist_added(PlaylistPtr pl);
94 
99  void sig_playlist_name_changed(int idx);
100 
104  void sig_saved_playlists_changed();
105 
106 
107  void sig_playlist_idx_changed(int idx);
108 
109  void sig_track_deletion_requested(const MetaDataList& v_md, Library::TrackDeletionMode deletion_mode);
110 
111 
112 public:
113 
118  void clear_playlist(int pl_idx);
119 
124  void play_next(const MetaDataList& v_md);
125 
132  void insert_tracks(const MetaDataList& v_md, int idx, int pl_idx);
133 
134 
140  void append_tracks(const MetaDataList& v_md, int pl_idx);
141 
148  void move_rows(const SP::Set<int>& indexes, int tgt_idx, int pl_idx);
149 
150 
156  void remove_rows(const SP::Set<int>& indexes, int pl_idx);
157 
158 
164  void change_track(int track_idx, int pl_idx);
165 
170  int get_active_idx_of_cur_track() const;
171 
172 
177  int get_active_idx() const;
178 
179  int get_current_idx() const;
180  void set_current_idx(int pl_idx);
181 
182 
188  PlaylistConstPtr get_playlist_at(int pl_idx) const;
189 
190 
195  void delete_playlist(int pl_idx);
196 
201  void close_playlist(int pl_idx);
202 
203 
208  void reset_playlist(int pl_idx);
209 
214  QString request_new_playlist_name() const;
215 
219  void save_all_playlists();
220 
226  PlaylistDBInterface::SaveAsAnswer save_playlist(int pl_idx);
227 
228 
236  PlaylistDBInterface::SaveAsAnswer save_playlist_as(int pl_idx, const QString& name, bool force_override);
237 
238 
245  PlaylistDBInterface::SaveAsAnswer rename_playlist(int pl_idx, const QString& name);
246 
247 
253  void save_playlist_to_file(const QString& filename, bool relative);
254 
255 
256 public slots:
257 
262  int load_old_playlists();
263 
264 
273  int create_playlist(const MetaDataList& v_md, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
274 
284  int create_playlist(const QStringList& path_list, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
285 
295  int create_playlist(const QString& dir, const QString& name=QString(), bool temporary=true, Playlist::Type type=Playlist::Type::Std);
296 
302  int create_playlist(const CustomPlaylist& pl);
303 
304 
310  int create_empty_playlist(const QString& name);
311 
312 
313  void delete_tracks(const SP::Set<int>& rows, Library::TrackDeletionMode deletion_mode);
314 
315 
316 private slots:
317 
321  void played();
322 
326  void paused();
327 
331  void stopped();
332 
336  void previous();
337 
341  void next();
342 
343 
347  void playstate_changed(PlayState state);
348 
349  void www_track_finished(const MetaData& md);
350 
351 
352 
353 private:
354 
355  DatabaseConnector* _db=nullptr;
356  PlayManager* _play_manager=nullptr;
357  QList<PlaylistPtr> _playlists;
358 
359  int _active_playlist_idx;
360  int _current_playlist_idx;
361 
362 
363  // adds a new playlist, creates it, if name is not in the list of playlists. If name already exists,
364  // this function returns the index
365  int add_new_playlist(const QString& name, bool editable, Playlist::Type type=Playlist::Type::Std);
366 
367  // raw creation of playlists
368  PlaylistPtr new_playlist(Playlist::Type type, int idx, QString name="");
369 
370 
376  int exists(const QString& name) const;
377 
378 
384  PlaylistPtr get_active();
385 
392  PlaylistPtr get_playlist(int pl_idx, PlaylistPtr fallback) const;
393 
394 
400  void emit_cur_track_changed();
401 
406  void set_active_idx(int pl_idx);
407 };
408 
409 #endif /* PLAYLISTHANDLER_H_ */
TrackDeletionMode
The TrackDeletionMode enum.
Definition: LibraryNamespaces.h:35
The MetaDataList class.
Definition: AbstractPlaylist.h:34
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:29
The MetaData class MetaDataHelper.
Definition: MetaData.h:55
Definition: DatabaseConnector.h:38
Definition: MetaDataList.h:39
PlaylistIndex
The PlaylistIndex enum.
Definition: PlaylistHandler.h:68
Global handler for current playback state (Singleton)
Definition: PlayManager.h:37
Set namespace defines the setting: Which key and which type.
Definition: SettingKey.h:200
std::shared_ptr< AbstractPlaylist > PlaylistPtr
PlaylistPtr Playlist Pointer (only used internally)
Definition: PlaylistFwd.h:27
std::shared_ptr< const AbstractPlaylist > PlaylistConstPtr
PlaylistConstPtr read only Playlist Pointer.
Definition: PlaylistFwd.h:41
Global handler for playlists.
Definition: PlaylistHandler.h:57
The CustomPlaylist class.
Definition: CustomPlaylist.h:31
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition: AbstractPlaylist.h:37
PlayState
The PlayState enum.
Definition: PlayState.h:30