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 AppendM3uToPlaylist(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 114 private: 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 _IsM3u(const entry_ref& ref); 129 static bool _IsQuery(const BString& mimeString); 130 static BString _MIMEString(const entry_ref* ref); 131 static void _BindExtraMedia(PlaylistItem* item); 132 static void _BindExtraMedia(FilePlaylistItem* fileItem, 133 const BEntry& entry); 134 135 static BString _GetExceptExtension(const BString& path); 136 137 void _NotifyItemAdded(PlaylistItem*, 138 int32 index) const; 139 void _NotifyItemRemoved(int32 index) const; 140 void _NotifyItemsSorted() const; 141 void _NotifyCurrentItemChanged(int32 newIndex, 142 bool play) const; 143 void _NotifyImportFailed() const; 144 145 private: 146 BList fItems; 147 BList fListeners; 148 149 int32 fCurrentIndex; 150 }; 151 152 #endif 153