File indexing completed on 2024-05-12 16:18:07

0001 /***************************************************************************
0002  *   Copyright (C) 2010 Ralf Engels <ralf-engels@gmx.de>                   *
0003  *                                                                         *
0004  *   This program is free software; you can redistribute it and/or modify  *
0005  *   it under the terms of the GNU General Public License as published by  *
0006  *   the Free Software Foundation; either version 2 of the License, or     *
0007  *   (at your option) any later version.                                   *
0008  *                                                                         *
0009  *   This program is distributed in the hope that it will be useful,       *
0010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0012  *   GNU General Public License for more details.                          *
0013  *                                                                         *
0014  *   You should have received a copy of the GNU General Public License     *
0015  *   along with this program; if not, write to the                         *
0016  *   Free Software Foundation, Inc.,                                       *
0017  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
0018  ***************************************************************************/
0019 
0020 #ifndef COLLECTIONSCANNER_TRACK_H
0021 #define COLLECTIONSCANNER_TRACK_H
0022 
0023 #include "FileType.h"
0024 #include "MetaReplayGain.h"
0025 #include "amarokshared_export.h"
0026 
0027 #include <QString>
0028 #include <QDateTime>
0029 #include <QXmlStreamReader>
0030 #include <QXmlStreamWriter>
0031 
0032 namespace CollectionScanner
0033 {
0034 
0035 class Directory;
0036 
0037 /**
0038    @class Track
0039    @short Represents a scanned track
0040    An empty QString or a negative int means that the value is unset.
0041  */
0042 class AMAROKSHARED_EXPORT Track
0043 {
0044 public:
0045     /** Reads a track from the given path */
0046     Track( const QString &path, Directory* directory );
0047 
0048     /** Tries to parse the track from the xml stream */
0049     Track( QXmlStreamReader *reader, Directory* directory );
0050 
0051     /** Writes the contents of this object to an xml stream.
0052         Only the content is written and no enclosing directory tags.
0053         This is done to make it mirror the constructor which does not read those
0054         tags either.
0055      */
0056     void toXml( QXmlStreamWriter *writer ) const;
0057 
0058     /** Returns true if this track is really a song. */
0059     bool isValid() const;
0060 
0061     /** Returns the directory this track was found in. */
0062     Directory* directory() const;
0063 
0064     QString uniqueid() const;
0065 
0066     /** The absolute path to the file.
0067         Because of symbolic links the path could be outside the original scanning directories.
0068      */
0069     QString path() const;
0070 
0071     /** Returns the relative path at the point of scanning */
0072     QString rpath() const;
0073 
0074     Amarok::FileType filetype() const;
0075     QString title() const;
0076     QString artist() const;
0077     QString albumArtist() const;
0078     QString album() const;
0079     // if !isCompilation && !isNoCompilation then it's undefined
0080     bool isCompilation() const;
0081     bool isNoCompilation() const;
0082     bool hasCover() const;
0083     QString comment() const;
0084     QString genre() const;
0085     int year() const;
0086     int disc() const;
0087     int track() const;
0088     int bpm() const;
0089     int bitrate() const;
0090     qint64 length() const;
0091     int samplerate() const;
0092     qint64 filesize() const;
0093     QDateTime modified() const;
0094 
0095     QString composer() const;
0096 
0097     qreal replayGain( Meta::ReplayGainTag mode ) const;
0098 
0099     /** Rating is a value from 0.0 to 10.0 inclusive */
0100     qreal rating() const;
0101 
0102     /** Score is a value from 0.0 to 100.0 inclusive */
0103     qreal score() const;
0104 
0105     int playcount() const;
0106 
0107     /** Enable or disable the charset detector.
0108        TODO: taglib should do that by itself.
0109      */
0110     static void setUseCharsetDetector( bool value );
0111 
0112 private:
0113     Q_DISABLE_COPY(Track)
0114 
0115     void write( QXmlStreamWriter *writer, const QString &tag, const QString &str ) const;
0116     bool m_valid;
0117 
0118     Directory* m_directory;
0119 
0120     QString m_uniqueid;
0121 
0122     QString m_path;
0123     QString m_rpath;
0124 
0125     Amarok::FileType m_filetype;
0126     QString m_title;
0127     QString m_artist;
0128     QString m_albumArtist;
0129     QString m_album;
0130     bool m_compilation;
0131     bool m_noCompilation;
0132     bool m_hasCover;
0133     QString m_comment;
0134     QString m_genre;
0135     int m_year;
0136     int m_disc;
0137     int m_track;
0138     qreal m_bpm;
0139     int m_bitrate;
0140     qint64 m_length;
0141     int m_samplerate;
0142     qint64 m_filesize;
0143     QDateTime m_modified;
0144 
0145     qreal m_trackGain;
0146     qreal m_trackPeakGain;
0147     qreal m_albumGain;
0148     qreal m_albumPeakGain;
0149 
0150     QString m_composer;
0151 
0152     qreal m_rating;
0153     qreal m_score;
0154     int m_playcount;
0155 
0156     static bool s_useCharsetDetector;
0157 };
0158 
0159 }
0160 
0161 #endif // COLLECTIONSCANNER_TRACK_H