File indexing completed on 2023-05-30 09:13:31

0001 /**
0002  * Copyright (C) 2002-2004 Scott Wheeler <wheeler@kde.org>
0003  * Copyright (C) 2009 Michael Pyne <mpyne@kde.org>
0004  *
0005  * This program is free software; you can redistribute it and/or modify it under
0006  * the terms of the GNU General Public License as published by the Free Software
0007  * Foundation; either version 2 of the License, or (at your option) any later
0008  * version.
0009  *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU General Public License along with
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.
0016  */
0017 
0018 #ifndef TAG_H
0019 #define TAG_H
0020 
0021 #include <QDateTime>
0022 
0023 namespace TagLib { class File; }
0024 
0025 class CacheDataStream;
0026 
0027 /*!
0028  * This should really be called "metadata" and may at some point be titled as
0029  * such.  Right now it's mostly a Qt wrapper around TagLib.
0030  */
0031 
0032 class Tag
0033 {
0034     friend class FileHandle;
0035 public:
0036     Tag(const QString &fileName);
0037     /**
0038      * Create an empty tag.  Used in FileHandle for cache restoration.
0039      */
0040     Tag(const QString &fileName, bool);
0041 
0042     bool save() const;
0043 
0044     QString title() const { return m_title; }
0045     QString artist() const { return m_artist; }
0046     QString album() const { return m_album; }
0047     QString genre() const { return m_genre; }
0048     int track() const { return m_track; }
0049     int year() const { return m_year; }
0050     QString comment() const { return m_comment; }
0051 
0052     QString fileName() const { return m_fileName; }
0053 
0054     void setTitle(const QString &value) { m_title = value; }
0055     void setArtist(const QString &value) { m_artist = value; }
0056     void setAlbum(const QString &value) { m_album = value; }
0057     void setGenre(const QString &value) { m_genre = value; }
0058     void setTrack(int value) { m_track = value; }
0059     void setYear(int value) { m_year = value; }
0060     void setComment(const QString &value) { m_comment = value; }
0061 
0062     void setFileName(const QString &value) { m_fileName = value; }
0063 
0064     int seconds() const { return m_seconds; }
0065     int bitrate() const { return m_bitrate; }
0066 
0067     bool isValid() const { return m_isValid; }
0068 
0069     /**
0070      * As a convenience, since producing a length string from a number of second
0071      * isn't a one liner, provide the length in string form.
0072      */
0073     QString lengthString() const { return m_lengthString; }
0074 
0075     /**
0076      * Convenience function to return a concise string describing the track,
0077      * usually in the form Artist - Title.
0078      */
0079     QString playingString() const;
0080 
0081     CacheDataStream &read(CacheDataStream &s);
0082 
0083 private:
0084     void setup(TagLib::File *file);
0085     void minimizeMemoryUsage();
0086 
0087     QString m_fileName;
0088     QString m_title;
0089     QString m_artist;
0090     QString m_album;
0091     QString m_genre;
0092     QString m_comment;
0093     int m_track;
0094     int m_year;
0095     int m_seconds;
0096     int m_bitrate;
0097     QDateTime m_modificationTime;
0098     QString m_lengthString;
0099     bool m_isValid;
0100 };
0101 
0102 QDataStream &operator<<(QDataStream &s, const Tag &t);
0103 CacheDataStream &operator>>(CacheDataStream &s, Tag &t);
0104 
0105 #endif
0106 
0107 // vim: set et sw=4 tw=0 sta: