xref: /haiku/src/apps/mediaplayer/playlist/Playlist.h (revision c2f0a314a012bea8e4ebb35b8ce9e1a85c798727)
1 /*
2  * Playlist.h - Media Player for the Haiku Operating System
3  *
4  * Copyright (C) 2006 Marcus Overhagen 	<marcus@overhagen.de>
5  * Copyright (C) 2007-2009 Stephan Aßmus <superstippi@gmx.de> (MIT ok)
6  * Copyright (C) 2008-2009 Fredrik Modéen <[FirstName]@[LastName].se> (MIT ok)
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * version 2 as published by the Free Software Foundation.
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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20  *
21  */
22 #ifndef __PLAYLIST_H
23 #define __PLAYLIST_H
24 
25 #include <List.h>
26 #include <Locker.h>
27 
28 #include "PlaylistItem.h"
29 
30 class BDataIO;
31 class BMessage;
32 class BString;
33 struct entry_ref;
34 
35 
36 // special append index values
37 #define APPEND_INDEX_REPLACE_PLAYLIST	-1
38 #define APPEND_INDEX_APPEND_LAST		-2
39 
40 extern const uint32 kPlaylistMagicBytes;
41 extern const char* kTextPlaylistMimeString;
42 extern const char* kBinaryPlaylistMimeString;
43 
44 
45 class Playlist : public BLocker {
46 public:
47 	class Listener {
48 	public:
49 								Listener();
50 		virtual					~Listener();
51 
52 		virtual	void			ItemAdded(PlaylistItem* item, int32 index);
53 		virtual	void			ItemRemoved(int32 index);
54 
55 		virtual	void			ItemsSorted();
56 
57 		virtual	void			CurrentItemChanged(int32 newIndex);
58 
59 		virtual	void			ImportFailed();
60 	};
61 
62 public:
63 								Playlist();
64 								~Playlist();
65 			// archiving
66 			status_t			Unarchive(const BMessage* archive);
67 			status_t			Archive(BMessage* into) const;
68 
69 			status_t			Unflatten(BDataIO* stream);
70 			status_t			Flatten(BDataIO* stream) const;
71 
72 
73 			// list functionality
74 			void				MakeEmpty(bool deleteItems = true);
75 			int32				CountItems() const;
76 			bool				IsEmpty() const;
77 
78 			void				Sort();
79 
80 			bool				AddItem(PlaylistItem* item);
81 			bool				AddItem(PlaylistItem* item, int32 index);
82 			PlaylistItem*		RemoveItem(int32 index,
83 									bool careAboutCurrentIndex = true);
84 
85 			bool				AdoptPlaylist(Playlist& other);
86 			bool				AdoptPlaylist(Playlist& other, int32 index);
87 
88 			int32				IndexOf(PlaylistItem* item) const;
89 			PlaylistItem*		ItemAt(int32 index) const;
90 			PlaylistItem*		ItemAtFast(int32 index) const;
91 
92 			// navigating current ref
93 			bool				SetCurrentItemIndex(int32 index);
94 			int32				CurrentItemIndex() const;
95 
96 			void				GetSkipInfo(bool* canSkipPrevious,
97 									bool* canSkipNext) const;
98 
99 			// listener support
100 			bool				AddListener(Listener* listener);
101 			void				RemoveListener(Listener* listener);
102 
103 			// support functions
104 			void				AppendRefs(const BMessage* refsReceivedMessage,
105 									int32 appendIndex
106 										= APPEND_INDEX_REPLACE_PLAYLIST);
107 	static	void				AppendToPlaylistRecursive(const entry_ref& ref,
108 									Playlist* playlist);
109 	static	void				AppendPlaylistToPlaylist(const entry_ref& ref,
110 									Playlist* playlist);
111 	static	void				AppendQueryToPlaylist(const entry_ref& ref,
112 									Playlist* playlist);
113 
114 			void				NotifyImportFailed();
115 
116 private:
117 								Playlist(const Playlist& other);
118 			Playlist&			operator=(const Playlist& other);
119 									// unimplemented
120 
121 	static	bool 				_IsMediaFile(const BString& mimeString);
122 	static	bool				_IsTextPlaylist(const BString& mimeString);
123 	static	bool				_IsBinaryPlaylist(const BString& mimeString);
124 	static	bool				_IsPlaylist(const BString& mimeString);
125 	static	bool				_IsQuery(const BString& mimeString);
126 	static	BString				_MIMEString(const entry_ref* ref);
127 
128 			void				_NotifyItemAdded(PlaylistItem*,
129 									int32 index) const;
130 			void				_NotifyItemRemoved(int32 index) const;
131 			void				_NotifyItemsSorted() const;
132 			void				_NotifyCurrentItemChanged(int32 newIndex) const;
133 			void				_NotifyImportFailed() const;
134 
135 private:
136 			BList				fItems;
137 			BList				fListeners;
138 
139 			int32				fCurrentIndex;
140 };
141 
142 #endif
143