playlist.h

00001  /*****************************************************************************
00002  *   Copyright (C) 2004 by Michael Schulze                                    *
00003  *   mike.s@genion.de                                                         *
00004  *                                                                            *
00005  *  The code contained in this file is free software; you can redistribute    *
00006  *  it and/or modify it under the terms of the GNU Lesser General Public      *
00007  *  License as published by the Free Software Foundation; either version      *
00008  *  2.1 of the License, or (at your option) any later version.                *
00009  *                                                                            *
00010  *  This file is distributed in the hope that it will be useful,              *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00013  *  Lesser General Public License for more details.                           *
00014  *                                                                            *
00015  *  You should have received a copy of the GNU Lesser General Public          *
00016  *  License along with this code; if not, write to the Free Software          *
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *
00018  *                                                                            *
00019  *  iTunes and iPod are trademarks of Apple                                   *
00020  *                                                                            *
00021  *  This product is not supported/written/published by Apple!                 *
00022  *****************************************************************************/
00023 #ifndef ITUNESDBPLAYLIST_H
00024 #define ITUNESDBPLAYLIST_H
00025 
00026 #include <qlist.h>
00027 
00028 #include "utils.h"
00029 #include "listitem.h"
00030 #include "playlistitem.h"
00031 #include "smartplaylistrules.h"
00032 
00033 namespace itunesdb {
00034 
00054 class Playlist : public ListItem
00055 {
00056     friend class ItunesDBParser;
00057     friend class ItunesDBWriter;
00058 
00059 public:
00060     enum Sortorder {
00061         SORTORDER_MANUAL = 1,
00062         SORTORDER_TITLE = 3,
00063         SORTORDER_ALBUM = 4,
00064         SORTORDER_ARTIST = 5,
00065         SORTORDER_BITRATE = 6,
00066         SORTORDER_GENRE = 7,
00067         SORTORDER_FILETYPE = 8,
00068         SORTORDER_TIME_MODIFIED = 9,
00069         SORTORDER_TRACK_NR = 10,
00070         SORTORDER_SIZE = 11,
00071         SORTORDER_TIME = 12,
00072         SORTORDER_YEAR = 13,
00073         SORTORDER_SAMPLERATE = 14,
00074         SORTORDER_COMMENT = 15,
00075         SORTORDER_TIME_ADDED = 16,
00076         SORTORDER_EQUALIZER = 17,
00077         SORTORDER_COMPOSER = 18,
00078         SORTORDER_PLAYCOUNT = 20,
00079         SORTORDER_TIME_PLAYED = 21,
00080         SORTORDER_CD_NR = 22,
00081         SORTORDER_RATING = 23,
00082         SORTORDER_RELEASE_DATE = 24,
00083         SORTORDER_BPM = 25,
00084         SORTORDER_GROUPING = 26,
00085         SORTORDER_CATEGORY = 27,
00086         SORTORDER_DESCRIPTION = 28
00087     } ItdbPlaylistSortOrder;
00088 
00089     class TrackList_T : public QList<PlaylistItem> {
00090         typedef QTPOD_SHARED_PTR_IMPL_DEF<PlaylistItemComparator> ComparatorPtr;
00091         ComparatorPtr m_comparator;
00092     public:
00093         TrackList_T();
00094         ~TrackList_T();
00095         void setComparator( PlaylistItemComparator * comparator );
00096         virtual int compareItems( QPtrCollection::Item s1, QPtrCollection::Item s2 );
00097     };
00098 
00099     class ConstIterator {
00100     protected:
00101         const TrackList_T& m_list;
00102         TrackList_T::const_iterator m_next;
00103         TrackList_T::const_iterator m_current;
00104         friend class itunesdb::Playlist;
00105         void setPos( TrackList_T::iterator pos ) {
00106             m_next = pos;
00107             m_current = pos;
00108         }
00109         ConstIterator(const TrackList_T& list)
00110             : m_list(list), m_next( m_list.begin() ), m_current( m_next ) {}
00111     public:
00112         bool hasNext() {
00113             return m_next != m_list.end();
00114         }
00115         bool atEnd() {
00116             return m_current != m_list.end();
00117         }
00118         const PlaylistItem * current() {
00119             return *m_current;
00120         }
00121         const PlaylistItem * next() {
00122             if ( hasNext() ) {
00123                 m_current = m_next++;
00124                 return *m_current;
00125             } else {
00126                 return NULL;
00127             }
00128         }
00129     };
00130 
00131     class Iterator {
00132     protected:
00133         TrackList_T& m_list;
00134         TrackList_T::iterator m_next;
00135         TrackList_T::iterator m_current;
00136         friend class itunesdb::Playlist;
00137         void setPos( TrackList_T::iterator pos ) {
00138             m_next = pos;
00139             m_current = pos;
00140         }
00141         Iterator(TrackList_T& list)
00142             : m_list(list), m_next( m_list.begin() ), m_current( m_next ) {}
00143     public:
00144         bool hasNext() {
00145             return m_next != m_list.end();
00146         }
00147         bool atEnd() {
00148             return m_current == m_list.end();
00149         }
00150         PlaylistItem * current() {
00151             return *m_current;
00152         }
00153         PlaylistItem * next() {
00154             if ( hasNext() ) {
00155                 m_current = m_next++;
00156                 return *m_current;
00157             } else {
00158                 return NULL;
00159             }
00160         }
00161     };
00162 
00163     Playlist();
00164     virtual ~Playlist();
00165 
00170     const QString& getTitle() const;
00171 
00176     void setTitle( const QString& newtitle);
00177 
00182     Sortorder getSortOrder() const;
00183 
00184 
00188     bool contains( Q_UINT32 trackID ) const;
00189 
00201     int addPlaylistItem( Q_UINT32 trackid, int position = -1 );
00202 
00209     Q_UINT32 removeTrackAt( Iterator& pos );
00210 
00216     Q_UINT32 removeTrackAt( uint pos );
00217 
00222     bool removeAll( Q_UINT32 trackid );
00223 
00229     virtual Q_UINT32 getTrackIDAt( uint pos );
00230 
00237     virtual Iterator getTrackIDs();
00238 
00243     virtual ConstIterator getTrackIDs() const;
00244 
00249     virtual uint getNumTracks() const;
00250 
00255     Q_UINT64 getID() const { return m_id; }
00256 
00261     void setID( Q_UINT64 id );
00262 
00266     void sort();
00267 
00272     void clear();
00273 
00277     virtual bool isHidden() const { return hidden; }
00278 
00282     SmartPlaylistRuleSet& enableSmartPlaylist();
00283 
00287     bool isSmartPlaylist() const;
00288 
00293     void discardSmartPlaylistData();
00294 
00300     SmartPlaylistRuleSet * getSmartPlaylistRules() const;
00301 
00305     bool isPodcastList() const { return mIsPodcast; }
00306 
00310     template <class JavaLikeTrackIterator>
00311         void addAll( JavaLikeTrackIterator trackIter ) {
00312             bool changed = false;
00313             while ( trackIter.hasNext() ) {
00314                 addPlaylistItem( trackIter.next()->getID() );
00315                 changed = true;
00316             }
00317             if ( changed ) {
00318                 setDirty();
00319             }
00320         }
00321 
00325     template <class CPPStyleTrackIterator>
00326         void addAll( CPPStyleTrackIterator trackIter, CPPStyleTrackIterator end ) {
00327             bool changed = false;
00328             for ( ; trackIter != end; trackIter++ ) {
00329                 addPlaylistItem( (*trackIter)->getID() );
00330                 changed = true;
00331             }
00332             if ( changed ) {
00333                 setDirty();
00334             }
00335         }
00336 
00337 protected:
00338 
00339     Playlist( const Playlist& );
00340 
00344     virtual PlaylistItem * createNewItem( Q_UINT32 trackid );
00345 
00346     virtual QDataStream & readFromStream( QDataStream & instream, bool * ok = NULL );
00347 
00348     virtual QDataStream & writeToStream ( QDataStream & outstream, bool isMainlist );
00349 
00353     virtual void doneAddingData();
00354 
00358     virtual int addPlaylistItem( PlaylistItem * item );
00359 
00360     virtual SmartPlaylistRuleSet * createNewSplRuleSet();
00361 
00362     void fillSplHeaderBuffer( QByteArray& buffer ) const;
00363 
00364     void fillSplRulesBuffer( QByteArray& buffer ) const;
00365 
00366     virtual void readNonStringMHOD( QDataStream& stream, Q_UINT32 type, Q_UINT32 blocklen );
00367     virtual uint writeNonStringMHODs( QDataStream& outstream ) const;
00368 
00369     void writeData( QByteArray& data, bool isMainlist) const;
00370     void writeTitle( QDataStream& stream ) const;
00371     void writeLongPlaylist( QDataStream& stream ) const;
00372     void writeTracks( QDataStream& stream ) const;
00373 
00374     TrackList_T m_tracklist;
00375     Q_UINT32 hidden;
00376     Q_UINT32 timeStamp;     // some timestamp
00377     Q_UINT64 m_id;          // playlist ID
00378     Q_UINT32 unk3;
00379     Q_UINT16 mIsPodcast;    // podcast flag
00380     Sortorder m_order;
00381 
00382     SmartPlaylistRuleSet * mSplRuleSet;
00383 
00384 };
00385 
00386 }
00387 
00388 #endif

Generated on Tue Dec 12 16:39:27 2006 for libqtpod.kdevelop by  doxygen 1.5.1