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