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 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * version 2 as published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19 * 20 */ 21 #ifndef __PLAYLIST_H 22 #define __PLAYLIST_H 23 24 #include <Entry.h> 25 #include <List.h> 26 #include <Locker.h> 27 28 class BMessage; 29 30 class Playlist : public BLocker { 31 public: 32 class Listener { 33 public: 34 Listener(); 35 virtual ~Listener(); 36 37 virtual void RefAdded(const entry_ref& ref, int32 index); 38 virtual void RefRemoved(int32 index); 39 40 virtual void RefsSorted(); 41 42 virtual void CurrentRefChanged(int32 newIndex); 43 }; 44 45 public: 46 Playlist(); 47 ~Playlist(); 48 49 // list functionality 50 void MakeEmpty(); 51 int32 CountItems() const; 52 53 void Sort(); 54 55 bool AddRef(const entry_ref& ref); 56 bool AddRef(const entry_ref& ref, int32 index); 57 entry_ref RemoveRef(int32 index, 58 bool careAboutCurrentIndex = true); 59 60 bool AdoptPlaylist(Playlist& other); 61 bool AdoptPlaylist(Playlist& other, int32 index); 62 63 int32 IndexOf(const entry_ref& ref) const; 64 status_t GetRefAt(int32 index, entry_ref* ref) const; 65 // bool HasRef(const entry_ref& ref) const; 66 67 // navigating current ref 68 void SetCurrentRefIndex(int32 index); 69 int32 CurrentRefIndex() const; 70 71 void GetSkipInfo(bool* canSkipPrevious, 72 bool* canSkipNext) const; 73 74 // listener support 75 bool AddListener(Listener* listener); 76 void RemoveListener(Listener* listener); 77 78 // support functions 79 void AppendRefs(const BMessage* refsReceivedMessage, 80 int32 appendIndex = -1); 81 static void AppendToPlaylistRecursive(const entry_ref& ref, 82 Playlist* playlist); 83 84 private: 85 static int playlist_cmp(const void* p1, const void* p2); 86 87 void _NotifyRefAdded(const entry_ref& ref, 88 int32 index) const; 89 void _NotifyRefRemoved(int32 index) const; 90 void _NotifyRefsSorted() const; 91 void _NotifyCurrentRefChanged(int32 newIndex) const; 92 93 private: 94 BList fRefs; 95 BList fListeners; 96 97 int32 fCurrentIndex; 98 }; 99 100 #endif 101