xref: /haiku/src/apps/mediaplayer/playlist/Playlist.h (revision b46615c55ad2c8fe6de54412055a0713da3d610a)
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 "FilePlaylistItem.h"
29 #include "PlaylistItem.h"
30 
31 class BDataIO;
32 class BMessage;
33 class BString;
34 struct entry_ref;
35 
36 
37 // special append index values
38 #define APPEND_INDEX_REPLACE_PLAYLIST	-1
39 #define APPEND_INDEX_APPEND_LAST		-2
40 
41 extern const uint32 kPlaylistMagicBytes;
42 extern const char* kTextPlaylistMimeString;
43 extern const char* kBinaryPlaylistMimeString;
44 
45 
46 class Playlist : public BLocker {
47 public:
48 	class Listener {
49 	public:
50 								Listener();
51 		virtual					~Listener();
52 
53 		virtual	void			ItemAdded(PlaylistItem* item, int32 index);
54 		virtual	void			ItemRemoved(int32 index);
55 
56 		virtual	void			ItemsSorted();
57 
58 		virtual	void			CurrentItemChanged(int32 newIndex);
59 
60 		virtual	void			ImportFailed();
61 	};
62 
63 public:
64 								Playlist();
65 								~Playlist();
66 			// archiving
67 			status_t			Unarchive(const BMessage* archive);
68 			status_t			Archive(BMessage* into) const;
69 
70 			status_t			Unflatten(BDataIO* stream);
71 			status_t			Flatten(BDataIO* stream) const;
72 
73 
74 			// list functionality
75 			void				MakeEmpty(bool deleteItems = true);
76 			int32				CountItems() const;
77 			bool				IsEmpty() const;
78 
79 			void				Sort();
80 
81 			bool				AddItem(PlaylistItem* item);
82 			bool				AddItem(PlaylistItem* item, int32 index);
83 			PlaylistItem*		RemoveItem(int32 index,
84 									bool careAboutCurrentIndex = true);
85 
86 			bool				AdoptPlaylist(Playlist& other);
87 			bool				AdoptPlaylist(Playlist& other, int32 index);
88 
89 			int32				IndexOf(PlaylistItem* item) const;
90 			PlaylistItem*		ItemAt(int32 index) const;
91 			PlaylistItem*		ItemAtFast(int32 index) const;
92 
93 			// navigating current ref
94 			bool				SetCurrentItemIndex(int32 index);
95 			int32				CurrentItemIndex() const;
96 
97 			void				GetSkipInfo(bool* canSkipPrevious,
98 									bool* canSkipNext) const;
99 
100 			// listener support
101 			bool				AddListener(Listener* listener);
102 			void				RemoveListener(Listener* listener);
103 
104 			// support functions
105 			void				AppendRefs(const BMessage* refsReceivedMessage,
106 									int32 appendIndex
107 										= APPEND_INDEX_REPLACE_PLAYLIST);
108 	static	void				AppendToPlaylistRecursive(const entry_ref& ref,
109 									Playlist* playlist);
110 	static	void				AppendPlaylistToPlaylist(const entry_ref& ref,
111 									Playlist* playlist);
112 	static	void				AppendQueryToPlaylist(const entry_ref& ref,
113 									Playlist* playlist);
114 
115 			void				NotifyImportFailed();
116 
117 	static	bool				ExtraMediaExists(Playlist* playlist, const entry_ref& ref);
118 
119 private:
120 								Playlist(const Playlist& other);
121 			Playlist&			operator=(const Playlist& other);
122 									// unimplemented
123 
124 	static	bool 				_IsImageFile(const BString& mimeString);
125 	static	bool 				_IsMediaFile(const BString& mimeString);
126 	static	bool				_IsTextPlaylist(const BString& mimeString);
127 	static	bool				_IsBinaryPlaylist(const BString& mimeString);
128 	static	bool				_IsPlaylist(const BString& mimeString);
129 	static	bool				_IsQuery(const BString& mimeString);
130 	static	BString				_MIMEString(const entry_ref* ref);
131 	static	void				_BindExtraMedia(PlaylistItem* item);
132 	static	void				_BindExtraMedia(FilePlaylistItem* fileItem, const BEntry& entry);
133 	static	BString				_GetExceptExtension(const BString& path);
134 
135 			void				_NotifyItemAdded(PlaylistItem*,
136 									int32 index) const;
137 			void				_NotifyItemRemoved(int32 index) const;
138 			void				_NotifyItemsSorted() const;
139 			void				_NotifyCurrentItemChanged(int32 newIndex) const;
140 			void				_NotifyImportFailed() const;
141 
142 private:
143 			BList				fItems;
144 			BList				fListeners;
145 
146 			int32				fCurrentIndex;
147 };
148 
149 #endif
150