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 extern const uint32 kPlaylistMagicBytes; 37 extern const char* kTextPlaylistMimeString; 38 extern const char* kBinaryPlaylistMimeString; 39 40 41 class Playlist : public BLocker { 42 public: 43 class Listener { 44 public: 45 Listener(); 46 virtual ~Listener(); 47 48 virtual void ItemAdded(PlaylistItem* item, int32 index); 49 virtual void ItemRemoved(int32 index); 50 51 virtual void ItemsSorted(); 52 53 virtual void CurrentItemChanged(int32 newIndex); 54 }; 55 56 public: 57 Playlist(); 58 ~Playlist(); 59 // archiving 60 status_t Unarchive(const BMessage* archive); 61 status_t Archive(BMessage* into) const; 62 63 status_t Unflatten(BDataIO* stream); 64 status_t Flatten(BDataIO* stream) const; 65 66 67 // list functionality 68 void MakeEmpty(bool deleteItems = true); 69 int32 CountItems() const; 70 71 void Sort(); 72 73 bool AddItem(PlaylistItem* item); 74 bool AddItem(PlaylistItem* item, int32 index); 75 PlaylistItem* RemoveItem(int32 index, 76 bool careAboutCurrentIndex = true); 77 78 bool AdoptPlaylist(Playlist& other); 79 bool AdoptPlaylist(Playlist& other, int32 index); 80 81 int32 IndexOf(PlaylistItem* item) const; 82 PlaylistItem* ItemAt(int32 index) const; 83 PlaylistItem* ItemAtFast(int32 index) const; 84 85 // navigating current ref 86 bool SetCurrentItemIndex(int32 index); 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 AppendRefs(const BMessage* refsReceivedMessage, 98 int32 appendIndex = -1); 99 static void AppendToPlaylistRecursive(const entry_ref& ref, 100 Playlist* playlist); 101 static void AppendPlaylistToPlaylist(const entry_ref& ref, 102 Playlist* playlist); 103 104 private: 105 Playlist(const Playlist& other); 106 Playlist& operator=(const Playlist& other); 107 // unimplemented 108 109 static bool _IsMediaFile(const BString& mimeString); 110 static bool _IsTextPlaylist(const BString& mimeString); 111 static bool _IsBinaryPlaylist(const BString& mimeString); 112 static bool _IsPlaylist(const BString& mimeString); 113 static BString _MIMEString(const entry_ref* ref); 114 115 void _NotifyItemAdded(PlaylistItem*, 116 int32 index) const; 117 void _NotifyItemRemoved(int32 index) const; 118 void _NotifyItemsSorted() const; 119 void _NotifyCurrentItemChanged(int32 newIndex) const; 120 121 private: 122 BList fItems; 123 BList fListeners; 124 125 int32 fCurrentIndex; 126 }; 127 128 #endif 129