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