tag.h 3.13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/**
 * Copyright (C) 2002-2004 Scott Wheeler <wheeler@kde.org>
 * Copyright (C) 2009 Michael Pyne <mpyne@kde.org>
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */
17 18 19 20

#ifndef TAG_H
#define TAG_H

21
#include <QDateTime>
22

23 24
namespace TagLib { class File; }

25 26
class CacheDataStream;

27 28 29
/*!
 * This should really be called "metadata" and may at some point be titled as
 * such.  Right now it's mostly a Qt wrapper around TagLib.
30 31
 */

32
class Tag
33
{
34
    friend class FileHandle;
35
public:
36
    Tag(const QString &fileName);
37 38 39 40
    /**
     * Create an empty tag.  Used in FileHandle for cache restoration.
     */
    Tag(const QString &fileName, bool);
41

42
    bool save() const;
43

44
    QString title() const { return m_title; }
45 46 47
    QString artist() const { return m_artist; }
    QString album() const { return m_album; }
    QString genre() const { return m_genre; }
48
    int track() const { return m_track; }
49 50 51
    int year() const { return m_year; }
    QString comment() const { return m_comment; }

52 53
    QString fileName() const { return m_fileName; }

54
    void setTitle(const QString &value) { m_title = value; }
55 56 57
    void setArtist(const QString &value) { m_artist = value; }
    void setAlbum(const QString &value) { m_album = value; }
    void setGenre(const QString &value) { m_genre = value; }
58
    void setTrack(int value) { m_track = value; }
59 60 61
    void setYear(int value) { m_year = value; }
    void setComment(const QString &value) { m_comment = value; }

62 63
    void setFileName(const QString &value) { m_fileName = value; }

64
    int seconds() const { return m_seconds; }
65 66
    int bitrate() const { return m_bitrate; }

67 68
    bool isValid() const { return m_isValid; }

69 70
    /**
     * As a convenience, since producing a length string from a number of second
71
     * isn't a one liner, provide the length in string form.
72 73
     */
    QString lengthString() const { return m_lengthString; }
74 75 76 77 78 79 80

    /**
     * Convenience function to return a concise string describing the track,
     * usually in the form Artist - Title.
     */
    QString playingString() const;

81
    CacheDataStream &read(CacheDataStream &s);
82 83

private:
84
    void setup(TagLib::File *file);
85
    void minimizeMemoryUsage();
86

87
    QString m_fileName;
88 89 90 91 92 93 94 95 96
    QString m_title;
    QString m_artist;
    QString m_album;
    QString m_genre;
    QString m_comment;
    int m_track;
    int m_year;
    int m_seconds;
    int m_bitrate;
97
    QDateTime m_modificationTime;
98
    QString m_lengthString;
99
    bool m_isValid;
100 101
};

Scott Wheeler's avatar
Scott Wheeler committed
102
QDataStream &operator<<(QDataStream &s, const Tag &t);
103
CacheDataStream &operator>>(CacheDataStream &s, Tag &t);
104

105
#endif
106 107

// vim: set et sw=4 tw=0 sta: