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 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * version 2 as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 #ifndef __PLAYLIST_H 23 #define __PLAYLIST_H 24 25 #include <List.h> 26 #include <Locker.h> 27 28 #include "PlaylistItem.h" 29 30 class BDataIO; 31 class BMessage; 32 class BString; 33 struct entry_ref; 34 35 36 // special append index values 37 #define APPEND_INDEX_REPLACE_PLAYLIST -1 38 #define APPEND_INDEX_APPEND_LAST -2 39 40 extern const uint32 kPlaylistMagicBytes; 41 extern const char* kTextPlaylistMimeString; 42 extern const char* kBinaryPlaylistMimeString; 43 44 45 class Playlist : public BLocker { 46 public: 47 class Listener { 48 public: 49 Listener(); 50 virtual ~Listener(); 51 52 virtual void ItemAdded(PlaylistItem* item, int32 index); 53 virtual void ItemRemoved(int32 index); 54 55 virtual void ItemsSorted(); 56 57 virtual void CurrentItemChanged(int32 newIndex); 58 }; 59 60 public: 61 Playlist(); 62 ~Playlist(); 63 // archiving 64 status_t Unarchive(const BMessage* archive); 65 status_t Archive(BMessage* into) const; 66 67 status_t Unflatten(BDataIO* stream); 68 status_t Flatten(BDataIO* stream) const; 69 70 71 // list functionality 72 void MakeEmpty(bool deleteItems = true); 73 int32 CountItems() const; 74 75 void Sort(); 76 77 bool AddItem(PlaylistItem* item); 78 bool AddItem(PlaylistItem* item, int32 index); 79 PlaylistItem* RemoveItem(int32 index, 80 bool careAboutCurrentIndex = true); 81 82 bool AdoptPlaylist(Playlist& other); 83 bool AdoptPlaylist(Playlist& other, int32 index); 84 85 int32 IndexOf(PlaylistItem* item) const; 86 PlaylistItem* ItemAt(int32 index) const; 87 PlaylistItem* ItemAtFast(int32 index) const; 88 89 // navigating current ref 90 bool SetCurrentItemIndex(int32 index); 91 int32 CurrentItemIndex() const; 92 93 void GetSkipInfo(bool* canSkipPrevious, 94 bool* canSkipNext) const; 95 96 // listener support 97 bool AddListener(Listener* listener); 98 void RemoveListener(Listener* listener); 99 100 // support functions 101 void AppendRefs(const BMessage* refsReceivedMessage, 102 int32 appendIndex 103 = APPEND_INDEX_REPLACE_PLAYLIST); 104 static void AppendToPlaylistRecursive(const entry_ref& ref, 105 Playlist* playlist); 106 static void AppendPlaylistToPlaylist(const entry_ref& ref, 107 Playlist* playlist); 108 109 private: 110 Playlist(const Playlist& other); 111 Playlist& operator=(const Playlist& other); 112 // unimplemented 113 114 static bool _IsMediaFile(const BString& mimeString); 115 static bool _IsTextPlaylist(const BString& mimeString); 116 static bool _IsBinaryPlaylist(const BString& mimeString); 117 static bool _IsPlaylist(const BString& mimeString); 118 static BString _MIMEString(const entry_ref* ref); 119 120 void _NotifyItemAdded(PlaylistItem*, 121 int32 index) const; 122 void _NotifyItemRemoved(int32 index) const; 123 void _NotifyItemsSorted() const; 124 void _NotifyCurrentItemChanged(int32 newIndex) const; 125 126 private: 127 BList fItems; 128 BList fListeners; 129 130 int32 fCurrentIndex; 131 }; 132 133 #endif 134