listitem.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 
00024 #ifndef ITUNESDBLISTITEM_H
00025 #define ITUNESDBLISTITEM_H
00026 
00027 #include <qglobal.h>
00028 #include <qpair.h>
00029 #include <qstring.h>
00030 
00031 #include <map>
00032 #include <vector>
00033 
00034 namespace itunesdb {
00035 
00036 /**
00037  * MHOD Property types. 
00038  */
00039 enum ItemProperty {
00040   MHOD_TITLE = 1,
00041   MHOD_PATH = 2,
00042   MHOD_ALBUM = 3,
00043   MHOD_ARTIST = 4,
00044   MHOD_GENRE = 5,
00045   MHOD_FDESC = 6,
00046   MHOD_EQ_SETTING = 7,
00047   MHOD_COMMENT = 8,
00048   MHOD_CATEGORY = 9,
00049   MHOD_COMPOSER = 12,
00050   MHOD_GROUPING = 13,
00051   MHOD_DESCRIPTION_TEXT = 14,
00052   MHOD_PODCAST_ENCLOSURE_URL = 15,
00053   MHOD_PODCAST_RSS_URL = 16,
00054   MHOD_CHAPTER_DATA = 17,
00055   MHOD_SUBTITLE = 18,
00056   MHOD_TVSHOW = 19,
00057   MHOD_TVEPISODE = 20,
00058   MHOD_TVNETWORK = 21,
00059   MHOD_ALBUMARTIST = 22,
00060   MHOD_ARTIST_FOR_SORT = 23,
00061   MHOD_KEYWORDS = 24,
00062   MHOD_TITLE_FOR_SORT = 27, // TODO
00063   MHOD_ALBUM_FOR_SORT = 28, // TODO
00064   MHOD_ALBUMARTIST_FOR_SORT = 29,   // TODO
00065   MHOD_COMPOSER_FOR_SORT = 30,  // TODO
00066   MHOD_SMART_PLAYLIST_INFO = 50,
00067   MHOD_SMART_PLAYLIST_IRULES = 51,
00068   MHOD_LIBRARY_PLAYLIST_INDEX = 52,
00069   MHOD_PLAYLIST = 100
00070 };
00071 
00072 /**
00073  * Possible item types
00074  */
00075 enum {
00076   ITEMTYPE_NONE = 0,
00077   ITEMTYPE_TRACK = 1,
00078   ITEMTYPE_PLAYLISTITEM = 2,
00079   ITEMTYPE_PLAYLIST = 3
00080 };    // known implementors
00081 
00082 typedef QPair<Q_UINT32,QByteArray> MHODPair;
00083 
00084 /**
00085 Describes a list item in iTunesDB. Possible known subtypes at the moment are playlist, playlistitem and track
00086 
00087 @author Michael Schulze
00088 */
00089 class ListItem {
00090 
00091     friend class ItunesDBParser;
00092 
00093 public:
00094 
00095     class LessThanStringPropertyComparator {
00096         ItemProperty mm_propertyToCompare;
00097     public:
00098         LessThanStringPropertyComparator( ItemProperty propertyToCompare )
00099             : mm_propertyToCompare( propertyToCompare ) {}
00100         bool operator() ( ListItem* item1, ListItem* item2 ) {
00101             return item1->getItemProperty( mm_propertyToCompare ).localeAwareCompare( item2->getItemProperty( mm_propertyToCompare ) ) < 0;
00102         }
00103     };
00104 
00105     virtual ~ListItem();
00106 
00107     /**
00108      * returns the type ofthis item
00109      * possible values from the known implementors are ITEMTYPE_PLAYLIST, ITEMTYPE_PLAYLISTITEM
00110      * and ITEMTYPE_TRACK
00111      */
00112     int getType() const;
00113 
00114     /**
00115      * sets a given itunesDB item property
00116      * @param data value for the property to be set
00117      * @param field propertyID of the property to be set
00118      */
00119     void setItemProperty(const QString& data, ItemProperty field);
00120 
00121     /**
00122      * Returns true if the given field is set with a non empty value.
00123      * @param field PropertyID of the property to be checked.
00124      * @return true if the given field is set with a non empty value.
00125      */
00126     bool containsItemProperty( ItemProperty field ) const;
00127 
00128     /**
00129      * Returns the value for the given property.
00130      * @param field PropertyID of the property to be returned.
00131      * @return the value for the given property.
00132      */
00133     const QString& getItemProperty( ItemProperty field) const;
00134 
00135     /**
00136      * Returns the number of properties.
00137      */
00138     uint getNumComponents() const;
00139 
00140     /**
00141      * Returns the number of String properties.
00142      */
00143     uint getNumStringComponents() const;
00144 
00145     /**
00146      * This method may be overridden for consistency checks after all properties have been read.
00147      */
00148     virtual void doneAddingData();
00149 
00150     /**
00151      * Returns true if this database item is out of sync with the database. This is true
00152      * if/when the item got changed and did not get saved back to the database yet.
00153      */
00154     virtual bool isDirty() const;
00155 
00156 protected:
00157     typedef std::map<Q_UINT32,QString> PropertyMap;
00158 
00159     PropertyMap m_properties;
00160 
00161     ListItem();
00162     ListItem( int type);
00163 
00164     const QByteArray * getDumpedMHOD( Q_UINT32 type ) const;
00165 
00166     virtual void readMHOD( QDataStream& stream, Q_UINT32 type, Q_UINT32 blocklen );
00167     Q_UINT32 writeMHODsToStream ( QDataStream & outstream ) const;
00168 
00169     virtual void readNonStringMHOD( QDataStream& stream, Q_UINT32 type, Q_UINT32 blocklen );
00170     virtual uint writeNonStringMHODs( QDataStream& outstream ) const;
00171 
00172     typedef std::vector<MHODPair> DumpedMHODs;
00173     DumpedMHODs m_dumpedMHODs;
00174 
00175     int m_itemType;
00176 
00177     virtual void setDirty( bool dirtyFlag = true );
00178 
00179 private:
00180     bool m_dirty;
00181 };
00182 
00183 }
00184 
00185 #endif

Generated on Wed Dec 19 00:15:19 2007 for libqtpod by  doxygen 1.5.0