xref: /haiku/src/apps/mediaplayer/playlist/Playlist.h (revision 8eafd6cd04e4d540cbad2ef07f9eb58a297a3b30)
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  * Released under the terms of the MIT license.
9  */
10 #ifndef __PLAYLIST_H
11 #define __PLAYLIST_H
12 
13 #include <List.h>
14 #include <Locker.h>
15 #include <Url.h>
16 
17 #include "FilePlaylistItem.h"
18 #include "PlaylistItem.h"
19 #include "UrlPlaylistItem.h"
20 
21 class BDataIO;
22 class BMessage;
23 class BString;
24 struct entry_ref;
25 
26 
27 // special append index values
28 #define APPEND_INDEX_REPLACE_PLAYLIST	-1
29 #define APPEND_INDEX_APPEND_LAST		-2
30 
31 extern const uint32 kPlaylistMagicBytes;
32 extern const char* kTextPlaylistMimeString;
33 extern const char* kBinaryPlaylistMimeString;
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, bool play);
49 
50 		virtual	void			ImportFailed();
51 	};
52 
53 public:
54 								Playlist();
55 								~Playlist();
56 			// archiving
57 			status_t			Unarchive(const BMessage* archive);
58 			status_t			Archive(BMessage* into) const;
59 
60 			status_t			Unflatten(BDataIO* stream);
61 			status_t			Flatten(BDataIO* stream) const;
62 
63 
64 			// list functionality
65 			void				MakeEmpty(bool deleteItems = true);
66 			int32				CountItems() const;
67 			bool				IsEmpty() const;
68 
69 			void				Sort();
70 
71 			bool				AddItem(PlaylistItem* item);
72 			bool				AddItem(PlaylistItem* item, int32 index);
73 			PlaylistItem*		RemoveItem(int32 index,
74 									bool careAboutCurrentIndex = true);
75 
76 			bool				AdoptPlaylist(Playlist& other);
77 			bool				AdoptPlaylist(Playlist& other, int32 index);
78 
79 			int32				IndexOf(PlaylistItem* item) const;
80 			PlaylistItem*		ItemAt(int32 index) const;
81 			PlaylistItem*		ItemAtFast(int32 index) const;
82 
83 			// navigating current ref
84 			bool				SetCurrentItemIndex(int32 index,
85 									bool notify = true);
86 			int32				CurrentItemIndex() const;
87 
88 			void				GetSkipInfo(bool* canSkipPrevious,
89 									bool* canSkipNext) const;
90 
91 			// listener support
92 			bool				AddListener(Listener* listener);
93 			void				RemoveListener(Listener* listener);
94 
95 			// support functions
96 			void				AppendItems(const BMessage* refsReceivedMessage,
97 									int32 appendIndex
98 										= APPEND_INDEX_REPLACE_PLAYLIST,
99 									bool sortItems = false);
100 
101 	static	void				AppendToPlaylistRecursive(const entry_ref& ref,
102 									Playlist* playlist);
103 	static	void				AppendPlaylistToPlaylist(const entry_ref& ref,
104 									Playlist* playlist);
105 	static	void				AppendM3uToPlaylist(const entry_ref& ref,
106 									Playlist* playlist);
107 	static	void				AppendQueryToPlaylist(const entry_ref& ref,
108 									Playlist* playlist);
109 
110 			void				NotifyImportFailed();
111 
112 	static	bool				ExtraMediaExists(Playlist* playlist,
113 									PlaylistItem* item);
114 
115 private:
116 								Playlist(const Playlist& other);
117 			Playlist&			operator=(const Playlist& other);
118 									// unimplemented
119 
120 	static	bool				_ExtraMediaExists(Playlist* playlist,
121 									const entry_ref& ref);
122 	static	bool				_ExtraMediaExists(Playlist* playlist,
123 									BUrl url);
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				_IsM3u(const entry_ref& ref);
130 	static	bool				_IsQuery(const BString& mimeString);
131 	static	BString				_MIMEString(const entry_ref* ref);
132 	static	void				_BindExtraMedia(PlaylistItem* item);
133 	static	void				_BindExtraMedia(FilePlaylistItem* fileItem,
134 									const BEntry& entry);
135 
136 	static	BString				_GetExceptExtension(const BString& path);
137 
138 			void				_NotifyItemAdded(PlaylistItem*,
139 									int32 index) const;
140 			void				_NotifyItemRemoved(int32 index) const;
141 			void				_NotifyItemsSorted() const;
142 			void				_NotifyCurrentItemChanged(int32 newIndex,
143 									bool play) const;
144 			void				_NotifyImportFailed() const;
145 
146 private:
147 			BList				fItems;
148 			BList				fListeners;
149 
150 			int32				fCurrentIndex;
151 };
152 
153 #endif
154