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