xref: /haiku/src/apps/mediaplayer/playlist/PlaylistItem.h (revision 95c9effd68127df2dce202d5e254a7c86560010a)
1 /*
2  * Copyright 2009-2010 Stephan Aßmus <superstippi@gmx.de>
3  * All rights reserved. Distributed under the terms of the MIT license.
4  */
5 #ifndef PLAYLIST_ITEM_H
6 #define PLAYLIST_ITEM_H
7 
8 
9 #include <Archivable.h>
10 #include <List.h>
11 #include <NodeInfo.h>
12 #include <Referenceable.h>
13 #include <String.h>
14 
15 
16 class BBitmap;
17 class BMessage;
18 class TrackSupplier;
19 
20 
21 class PlaylistItem : public BArchivable, public BReferenceable {
22 public:
23 	class Listener {
24 	public:
25 						Listener();
26 		virtual			~Listener();
27 
28 		virtual	void	ItemChanged(const PlaylistItem* item);
29 	};
30 
31 public:
32 								PlaylistItem();
33 	virtual						~PlaylistItem();
34 
35 	virtual	PlaylistItem*		Clone() const = 0;
36 
37 	// archiving
38 	virtual	status_t			Archive(BMessage* into,
39 									bool deep = true) const = 0;
40 
41 	// attributes
42 	typedef enum {
43 		ATTR_STRING_NAME			= 'name',
44 		ATTR_STRING_KEYWORDS		= 'kwrd',
45 
46 		ATTR_STRING_ARTIST			= 'arst',
47 		ATTR_STRING_AUTHOR			= 'auth',
48 		ATTR_STRING_ALBUM			= 'albm',
49 		ATTR_STRING_TITLE			= 'titl',
50 		ATTR_STRING_AUDIO_BITRATE	= 'abtr',
51 		ATTR_STRING_VIDEO_BITRATE	= 'vbtr',
52 
53 		ATTR_INT32_TRACK			= 'trck',
54 		ATTR_INT32_YEAR				= 'year',
55 		ATTR_INT32_RATING			= 'rtng',
56 
57 		ATTR_INT64_DURATION			= 'drtn'
58 	} Attribute;
59 
60 	virtual	status_t			SetAttribute(const Attribute& attribute,
61 									const BString& string) = 0;
62 	virtual	status_t			GetAttribute(const Attribute& attribute,
63 									BString& string) const = 0;
64 
65 	virtual	status_t			SetAttribute(const Attribute& attribute,
66 									const int32& value) = 0;
67 	virtual	status_t			GetAttribute(const Attribute& attribute,
68 									int32& value) const = 0;
69 
70 	virtual	status_t			SetAttribute(const Attribute& attribute,
71 									const int64& value) = 0;
72 	virtual	status_t			GetAttribute(const Attribute& attribute,
73 									int64& value) const = 0;
74 
75 	// convenience access to attributes
76 			BString				Name() const;
77 			BString				Author() const;
78 			BString				Album() const;
79 			BString				Title() const;
80 
81 			int32				TrackNumber() const;
82 
83 			bigtime_t			Duration();
84 
85 	// methods
86 	virtual	BString				LocationURI() const = 0;
87 	virtual	status_t			GetIcon(BBitmap* bitmap,
88 									icon_size iconSize) const = 0;
89 
90 	virtual	status_t			MoveIntoTrash() = 0;
91 	virtual	status_t			RestoreFromTrash() = 0;
92 
93 	// Create and return the TrackSupplier if it doesn't exist,
94 	// this object is used for media playback.
95 			TrackSupplier*		GetTrackSupplier();
96 	// Delete and reset the TrackSupplier
97 			void				ReleaseTrackSupplier();
98 	// Return whether the supplier has been initialized
99 			bool				HasTrackSupplier() const;
100 
101 			void				SetPlaybackFailed();
102 			bool				PlaybackFailed() const
103 									{ return fPlaybackFailed; }
104 
105 	// listener support
106 			bool				AddListener(Listener* listener);
107 			void				RemoveListener(Listener* listener);
108 
109 protected:
110 			void				_NotifyListeners() const;
111 	virtual	bigtime_t			_CalculateDuration();
112 	virtual	TrackSupplier*		_CreateTrackSupplier() const = 0;
113 
114 private:
115 			BList				fListeners;
116 			bool				fPlaybackFailed;
117 			TrackSupplier*		fTrackSupplier;
118 };
119 
120 typedef BReference<PlaylistItem> PlaylistItemRef;
121 
122 #endif // PLAYLIST_ITEM_H
123