1 /*************************************************************************** 2 * Copyright (C) 2010 Ralf Engels <ralf-engels@gmx.de> * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the * 16 * Free Software Foundation, Inc., * 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 18 ***************************************************************************/ 19 20 #ifndef COLLECTIONSCANNER_TRACK_H 21 #define COLLECTIONSCANNER_TRACK_H 22 23 #include "FileType.h" 24 #include "MetaReplayGain.h" 25 #include "amarokshared_export.h" 26 27 #include <QString> 28 #include <QDateTime> 29 #include <QXmlStreamReader> 30 #include <QXmlStreamWriter> 31 32 namespace CollectionScanner 33 { 34 35 class Directory; 36 37 /** 38 @class Track 39 @short Represents a scanned track 40 An empty QString or a negative int means that the value is unset. 41 */ 42 class AMAROKSHARED_EXPORT Track 43 { 44 public: 45 /** Reads a track from the given path */ 46 Track( const QString &path, Directory* directory ); 47 48 /** Tries to parse the track from the xml stream */ 49 Track( QXmlStreamReader *reader, Directory* directory ); 50 51 /** Writes the contents of this object to an xml stream. 52 Only the content is written and no enclosing directory tags. 53 This is done to make it mirror the constructor which does not read those 54 tags either. 55 */ 56 void toXml( QXmlStreamWriter *writer ) const; 57 58 /** Returns true if this track is really a song. */ 59 bool isValid() const; 60 61 /** Returns the directory this track was found in. */ 62 Directory* directory() const; 63 64 QString uniqueid() const; 65 66 /** The absolute path to the file. 67 Because of symbolic links the path could be outside the original scanning directories. 68 */ 69 QString path() const; 70 71 /** Returns the relative path at the point of scanning */ 72 QString rpath() const; 73 74 Amarok::FileType filetype() const; 75 QString title() const; 76 QString artist() const; 77 QString albumArtist() const; 78 QString album() const; 79 // if !isCompilation && !isNoCompilation then it's undefined 80 bool isCompilation() const; 81 bool isNoCompilation() const; 82 bool hasCover() const; 83 QString comment() const; 84 QString genre() const; 85 int year() const; 86 int disc() const; 87 int track() const; 88 int bpm() const; 89 int bitrate() const; 90 qint64 length() const; 91 int samplerate() const; 92 qint64 filesize() const; 93 QDateTime modified() const; 94 95 QString composer() const; 96 97 qreal replayGain( Meta::ReplayGainTag mode ) const; 98 99 /** Rating is a value from 0.0 to 10.0 inclusive */ 100 qreal rating() const; 101 102 /** Score is a value from 0.0 to 100.0 inclusive */ 103 qreal score() const; 104 105 int playcount() const; 106 107 /** Enable or disable the charset detector. 108 TODO: taglib should do that by itself. 109 */ 110 static void setUseCharsetDetector( bool value ); 111 112 private: 113 Q_DISABLE_COPY(Track) 114 115 void write( QXmlStreamWriter *writer, const QString &tag, const QString &str ) const; 116 bool m_valid; 117 118 Directory* m_directory; 119 120 QString m_uniqueid; 121 122 QString m_path; 123 QString m_rpath; 124 125 Amarok::FileType m_filetype; 126 QString m_title; 127 QString m_artist; 128 QString m_albumArtist; 129 QString m_album; 130 bool m_compilation; 131 bool m_noCompilation; 132 bool m_hasCover; 133 QString m_comment; 134 QString m_genre; 135 int m_year; 136 int m_disc; 137 int m_track; 138 qreal m_bpm; 139 int m_bitrate; 140 qint64 m_length; 141 int m_samplerate; 142 qint64 m_filesize; 143 QDateTime m_modified; 144 145 qreal m_trackGain; 146 qreal m_trackPeakGain; 147 qreal m_albumGain; 148 qreal m_albumPeakGain; 149 150 QString m_composer; 151 152 qreal m_rating; 153 qreal m_score; 154 int m_playcount; 155 156 static bool s_useCharsetDetector; 157 }; 158 159 } 160 161 #endif // COLLECTIONSCANNER_TRACK_H 162