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 Stephan Aßmus <superstippi@gmx.de> 6 * Copyright (C) 2008 Fredrik Modéen <fredrik@modeen.se> (I have no problem changing my things to MIT) 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 <Entry.h> 26 #include <List.h> 27 #include <Locker.h> 28 29 class BMessage; 30 class BString; 31 32 33 class Playlist : public BLocker { 34 public: 35 class Listener { 36 public: 37 Listener(); 38 virtual ~Listener(); 39 40 virtual void RefAdded(const entry_ref& ref, int32 index); 41 virtual void RefRemoved(int32 index); 42 43 virtual void RefsSorted(); 44 45 virtual void CurrentRefChanged(int32 newIndex); 46 }; 47 48 public: 49 Playlist(); 50 ~Playlist(); 51 // archiving 52 status_t UnArchive(const BMessage* archive); 53 status_t Archive(BMessage* into) const; 54 55 56 // list functionality 57 void MakeEmpty(); 58 int32 CountItems() const; 59 60 void Sort(); 61 62 bool AddRef(const entry_ref& ref); 63 bool AddRef(const entry_ref& ref, int32 index); 64 entry_ref RemoveRef(int32 index, 65 bool careAboutCurrentIndex = true); 66 67 bool AdoptPlaylist(Playlist& other); 68 bool AdoptPlaylist(Playlist& other, int32 index); 69 70 int32 IndexOf(const entry_ref& ref) const; 71 status_t GetRefAt(int32 index, entry_ref* ref) const; 72 // bool HasRef(const entry_ref& ref) const; 73 74 // navigating current ref 75 bool SetCurrentRefIndex(int32 index); 76 int32 CurrentRefIndex() const; 77 78 void GetSkipInfo(bool* canSkipPrevious, 79 bool* canSkipNext) const; 80 81 // listener support 82 bool AddListener(Listener* listener); 83 void RemoveListener(Listener* listener); 84 85 // support functions 86 void AppendRefs(const BMessage* refsReceivedMessage, 87 int32 appendIndex = -1); 88 static void AppendToPlaylistRecursive(const entry_ref& ref, 89 Playlist* playlist); 90 91 private: 92 static int playlist_cmp(const void* p1, const void* p2); 93 static bool _IsMediaFile(const BString& mimeString); 94 static bool _IsPlaylist(const BString& mimeString); 95 static BString _MIMEString(const entry_ref* entry); 96 static void _AddPlayListFileToPlayList(const entry_ref& ref, 97 Playlist* playlist); 98 void _NotifyRefAdded(const entry_ref& ref, 99 int32 index) const; 100 void _NotifyRefRemoved(int32 index) const; 101 void _NotifyRefsSorted() const; 102 void _NotifyCurrentRefChanged(int32 newIndex) const; 103 104 private: 105 BList fRefs; 106 BList fListeners; 107 108 int32 fCurrentIndex; 109 }; 110 111 #endif 112