tag.h 4.13 KB
Newer Older
1
/***************************************************************************
2
                          id3tag.h  -  description
3
4
5
                             -------------------
    begin                : Sun Feb 17 2002
    copyright            : (C) 2002 by Scott Wheeler
6
    email                : wheeler@kde.org
7
***************************************************************************/
8
9
10
11
12
13
14
15
16
17
18
19
20

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef TAG_H
#define TAG_H

21
#include <kfilemetainfo.h>
22

23
24
25
#include <qstring.h>
#include <qdatetime.h>
#include <qfileinfo.h>
26

27
28
#include "genre.h"

29
30
31
32
33
34
35
36
37
38
/**
 * This class is an abstract base class for concrete Tag classes.  It provides
 * an API and a creation method to hide the differences between these.
 *
 * There are two parts here:  (1) those that are appropriately tag data, such as
 * the artist name or year recorded and (2) data that is not "tag" data but can 
 * benefit from the same abstraction mechanism used by the tag class.  This 
 * includes the track length and bitrate at the moment.
 */

39
class Tag
40
{
41
public:
42
43
44
45
46
    /**
     * All Tag objects should be instantiated through this method.  It determines
     * the appropriate concrete subclass and instantiates that.  It's servering
     * as a mini-factory; a full blown abstract factory is an overkill here.
     */
47
    static Tag *createTag(const QString &file, bool ignoreCache = false);
48
    virtual ~Tag();
49

50
    virtual void save() = 0;
51
    virtual bool hasTag() const = 0;
52

53
54
55
56
57
58
59
60
61
    virtual QString track() const = 0;
    virtual QString artist() const = 0;
    virtual QString album() const = 0;
    virtual Genre genre() const = 0;
    virtual int trackNumber() const = 0;
    virtual QString trackNumberString() const = 0;
    virtual int year() const = 0;
    virtual QString yearString() const = 0;
    virtual QString comment() const = 0;
62

63
64
65
66
67
68
69
    virtual void setTrack(const QString &value) = 0;
    virtual void setArtist(const QString &value) = 0;
    virtual void setAlbum(const QString &value) = 0;
    virtual void setGenre(const Genre &value) = 0;
    virtual void setTrackNumber(int value) = 0;
    virtual void setYear(int value) = 0;
    virtual void setComment(const QString &value) = 0;
70
71
72
73
74

    virtual QString bitrateString() const = 0;
    virtual QString lengthString() const = 0;
    virtual int seconds() const = 0;

75
76
77
78
79
80
81
    /**
     * Check to see if the item is up to date.  This defaults to true and should
     * be reimplemented inf Tag types that are not directly mapped to the file
     * system (specifically cached tags).
     */
    virtual bool current() const { return true; }

82
83
84
    // These functions are inlined because they are used on startup -- the most
    // performance critical section of JuK.

85
    inline QString absFilePath() const { return m_fileName; }
86
    inline QDateTime lastModified() const { return m_lastModified; }
87
88
    inline bool fileExists() const { return m_info.exists() && m_info.isFile(); }
    inline QFileInfo fileInfo() const { return m_info; }
89
90
91
92
93
94
95
96
97
    
protected:
    /**
     * The constructor is procetected since this is an abstract class and as
     * such it should not be instantiated directly.  createTag() should be
     * used to instantiate a concrete subclass of Tag that can be manipulated
     * though the public API.
     */
    Tag(const QString &file);
98

99
100
101
    static QString readBitrate(const KFileMetaInfo &metaInfo);
    static QString readLength(const KFileMetaInfo &metaInfo);
    static int readSeconds(const KFileMetaInfo &metaInfo);
102
103
    
private:
104
105
    QFileInfo m_info;
    QString m_fileName;
106
    QDateTime m_lastModified;
107
108
};

109
110
QDataStream &operator<<(QDataStream &s, const Tag &t);

111
#endif