xref: /haiku/src/apps/mediaplayer/playlist/Playlist.h (revision c0936b5a0384bc6fe654d296ee54222a0f45d2b6)
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 
100 	static	void				AppendToPlaylistRecursive(const entry_ref& ref,
101 									Playlist* playlist);
102 	static	void				AppendPlaylistToPlaylist(const entry_ref& ref,
103 									Playlist* playlist);
104 	static	void				AppendQueryToPlaylist(const entry_ref& ref,
105 									Playlist* playlist);
106 
107 			void				NotifyImportFailed();
108 
109 	static	bool				ExtraMediaExists(Playlist* playlist,
110 									PlaylistItem* item);
111 
112 private:
113 								Playlist(const Playlist& other);
114 			Playlist&			operator=(const Playlist& other);
115 									// unimplemented
116 
117 	static	bool				_ExtraMediaExists(Playlist* playlist,
118 									const entry_ref& ref);
119 	static	bool				_ExtraMediaExists(Playlist* playlist,
120 									BUrl url);
121 	static	bool 				_IsImageFile(const BString& mimeString);
122 	static	bool 				_IsMediaFile(const BString& mimeString);
123 	static	bool				_IsTextPlaylist(const BString& mimeString);
124 	static	bool				_IsBinaryPlaylist(const BString& mimeString);
125 	static	bool				_IsPlaylist(const BString& mimeString);
126 	static	bool				_IsQuery(const BString& mimeString);
127 	static	BString				_MIMEString(const entry_ref* ref);
128 	static	void				_BindExtraMedia(PlaylistItem* item);
129 	static	void				_BindExtraMedia(FilePlaylistItem* fileItem,
130 									const BEntry& entry);
131 
132 	static	BString				_GetExceptExtension(const BString& path);
133 
134 			void				_NotifyItemAdded(PlaylistItem*,
135 									int32 index) const;
136 			void				_NotifyItemRemoved(int32 index) const;
137 			void				_NotifyItemsSorted() const;
138 			void				_NotifyCurrentItemChanged(int32 newIndex,
139 									bool play) const;
140 			void				_NotifyImportFailed() const;
141 
142 private:
143 			BList				fItems;
144 			BList				fListeners;
145 
146 			int32				fCurrentIndex;
147 };
148 
149 #endif
150