xref: /haiku/src/apps/mediaplayer/playlist/Playlist.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
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 class Playlist : public BLocker {
37 public:
38 	class Listener {
39 	public:
40 						Listener();
41 		virtual			~Listener();
42 
43 		virtual	void	ItemAdded(PlaylistItem* item, int32 index);
44 		virtual	void	ItemRemoved(int32 index);
45 
46 		virtual	void	ItemsSorted();
47 
48 		virtual	void	CurrentItemChanged(int32 newIndex);
49 	};
50 
51 public:
52 								Playlist();
53 								~Playlist();
54 			// archiving
55 			status_t			Unarchive(const BMessage* archive);
56 			status_t			Archive(BMessage* into) const;
57 
58 			status_t			Unflatten(BDataIO* stream);
59 			status_t			Flatten(BDataIO* stream) const;
60 
61 
62 			// list functionality
63 			void				MakeEmpty(bool deleteItems = true);
64 			int32				CountItems() const;
65 
66 			void				Sort();
67 
68 			bool				AddItem(PlaylistItem* item);
69 			bool				AddItem(PlaylistItem* item, int32 index);
70 			PlaylistItem*		RemoveItem(int32 index,
71 									bool careAboutCurrentIndex = true);
72 
73 			bool				AdoptPlaylist(Playlist& other);
74 			bool				AdoptPlaylist(Playlist& other, int32 index);
75 
76 			int32				IndexOf(PlaylistItem* item) const;
77 			PlaylistItem*		ItemAt(int32 index) const;
78 			PlaylistItem*		ItemAtFast(int32 index) const;
79 
80 			// navigating current ref
81 			bool				SetCurrentItemIndex(int32 index);
82 			int32				CurrentItemIndex() const;
83 
84 			void				GetSkipInfo(bool* canSkipPrevious,
85 									bool* canSkipNext) const;
86 
87 			// listener support
88 			bool				AddListener(Listener* listener);
89 			void				RemoveListener(Listener* listener);
90 
91 			// support functions
92 			void				AppendRefs(const BMessage* refsReceivedMessage,
93 									int32 appendIndex = -1);
94 	static	void				AppendToPlaylistRecursive(const entry_ref& ref,
95 									Playlist* playlist);
96 	static	void				AppendPlaylistToPlaylist(const entry_ref& ref,
97 									Playlist* playlist);
98 
99 private:
100 	static	bool 				_IsMediaFile(const BString& mimeString);
101 	static	bool				_IsTextPlaylist(const BString& mimeString);
102 	static	bool				_IsBinaryPlaylist(const BString& mimeString);
103 	static	bool				_IsPlaylist(const BString& mimeString);
104 	static	BString				_MIMEString(const entry_ref* ref);
105 
106 			void				_NotifyItemAdded(PlaylistItem*,
107 									int32 index) const;
108 			void				_NotifyItemRemoved(int32 index) const;
109 			void				_NotifyItemsSorted() const;
110 			void				_NotifyCurrentItemChanged(int32 newIndex) const;
111 
112 private:
113 			BList				fItems;
114 			BList				fListeners;
115 
116 			int32				fCurrentIndex;
117 };
118 
119 #endif
120