xref: /haiku/src/apps/mediaplayer/playlist/Playlist.h (revision 6e927a5fc080cb934e7584454f472cacf4c3e361)
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 Stephan Aßmus <superstippi@gmx.de>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * version 2 as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19  *
20  */
21 #ifndef __PLAYLIST_H
22 #define __PLAYLIST_H
23 
24 #include <Entry.h>
25 #include <List.h>
26 #include <Locker.h>
27 
28 class BMessage;
29 class BString;
30 
31 
32 class Playlist : public BLocker {
33 public:
34 	class Listener {
35 	public:
36 						Listener();
37 		virtual			~Listener();
38 
39 		virtual	void	RefAdded(const entry_ref& ref, int32 index);
40 		virtual	void	RefRemoved(int32 index);
41 
42 		virtual	void	RefsSorted();
43 
44 		virtual	void	CurrentRefChanged(int32 newIndex);
45 	};
46 
47 public:
48 								Playlist();
49 								~Playlist();
50 
51 			// list functionality
52 			void				MakeEmpty();
53 			int32				CountItems() const;
54 
55 			void				Sort();
56 
57 			bool				AddRef(const entry_ref& ref);
58 			bool				AddRef(const entry_ref& ref, int32 index);
59 			entry_ref			RemoveRef(int32 index,
60 									bool careAboutCurrentIndex = true);
61 
62 			bool				AdoptPlaylist(Playlist& other);
63 			bool				AdoptPlaylist(Playlist& other, int32 index);
64 
65 			int32				IndexOf(const entry_ref& ref) const;
66 			status_t			GetRefAt(int32 index, entry_ref* ref) const;
67 		//	bool				HasRef(const entry_ref& ref) const;
68 
69 			// navigating current ref
70 			void				SetCurrentRefIndex(int32 index);
71 			int32				CurrentRefIndex() const;
72 
73 			void				GetSkipInfo(bool* canSkipPrevious,
74 									bool* canSkipNext) const;
75 
76 			// listener support
77 			bool				AddListener(Listener* listener);
78 			void				RemoveListener(Listener* listener);
79 
80 			// support functions
81 			void				AppendRefs(const BMessage* refsReceivedMessage,
82 									int32 appendIndex = -1);
83 	static	void				AppendToPlaylistRecursive(const entry_ref& ref,
84 									Playlist* playlist);
85 
86 private:
87 			static int			playlist_cmp(const void* p1, const void* p2);
88 			static bool 		_IsMediaFile(const BString& mimeString);
89 			static bool			_IsPlaylist(const BString& mimeString);
90 			static BString		_MIMEString(const entry_ref* entry);
91 
92 			void				_NotifyRefAdded(const entry_ref& ref,
93 									int32 index) const;
94 			void				_NotifyRefRemoved(int32 index) const;
95 			void				_NotifyRefsSorted() const;
96 			void				_NotifyCurrentRefChanged(int32 newIndex) const;
97 
98 private:
99 			BList				fRefs;
100 			BList				fListeners;
101 
102 			int32				fCurrentIndex;
103 };
104 
105 #endif
106