1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/****************************************************************************************
* Copyright (c) 2010 Sergey Ivanov <123kash@gmail.com> *
* *
* 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/>. *
****************************************************************************************/
#ifndef TAGHELPER_H
#define TAGHELPER_H
#define MIN_COVER_SIZE 1024 // Minimum size for an embedded cover to be loaded
#include "MetaValues.h"
#include "FileType.h"
#include "amarokshared_export.h"
#include <fileref.h>
#include <tag.h>
#include <id3v1tag.h>
namespace Meta
{
namespace Tag
{
class AMAROKSHARED_EXPORT TagHelper
{
public:
enum UIDType
{
UIDInvalid = 0,
UIDAFT = 3
};
enum FMPS
{
FMPSPlayCount = 0,
FMPSRating = 1,
FMPSScore = 2
};
TagHelper( TagLib::Tag *tag, Amarok::FileType fileType );
explicit TagHelper( TagLib::ID3v1::Tag *tag, Amarok::FileType fileType );
virtual ~TagHelper();
/**
* Read all supported tags from file.
*/
virtual Meta::FieldHash tags() const;
/**
* Write changed metadata to file.
* Return true if something written.
*/
virtual bool setTags( const Meta::FieldHash &changes );
/**
* Render tags. Used in UID generator.
*/
virtual TagLib::ByteVector render() const;
/**
* Check If file contains embedded cover.
*/
virtual bool hasEmbeddedCover() const;
/**
* Read embedded cover from file.
*/
virtual QImage embeddedCover() const;
/**
* Add or update cover in file. Will be set as FrontCover.
* Return true If something written.
*/
virtual bool setEmbeddedCover( const QImage &cover );
/**
* Return file type.
*/
Amarok::FileType fileType() const;
/**
* Returns combination of:
* title, album, artist, genre and comment fields.
* Used to encoding detection.
*/
QByteArray testString() const;
protected:
/**
* Split UID url.
* @return Pair of uid type and uid. Uid type can be used to
* get field name where to write It (owner in case of ID3v2).
*/
QPair< UIDType, QString > splitUID( const QString &uidUrl ) const;
/**
* Check If @arg uid correct UID for specified @arg type.
*/
bool isValidUID( const QString &uid, const UIDType type ) const;
/**
* Returns field name for Meta::val* value.
*/
TagLib::String fieldName( const qint64 field ) const;
/**
* Returns Meta::val* value corresponds to field name.
*/
qint64 fieldName( const TagLib::String &field ) const;
/**
* Split DiscNr field on Disc number and Disc count.
*/
QPair< int, int > splitDiscNr( const QString &value ) const;
/**
* Returns field name for specified UID type.
*/
TagLib::String uidFieldName( const UIDType type ) const;
/**
* Returns field name for specified FMPS value.
*/
TagLib::String fmpsFieldName( const FMPS field ) const;
QHash< quint64, TagLib::String > m_fieldMap;
QHash< FMPS, TagLib::String > m_fmpsFieldMap;
QHash< UIDType, TagLib::String > m_uidFieldMap;
private:
TagLib::Tag *m_tag;
Amarok::FileType m_fileType;
};
/**
* Returns TagHelper for specified @arg fileref.
* @arg forceCreation If true: selector will force tag creation.
* @return TagHelper or NULL if file doesn't have tags.
* Should be deleted by user after use.
*/
AMAROKSHARED_EXPORT TagHelper *selectHelper( const TagLib::FileRef &fileref, bool forceCreation = false );
}
}
#endif // TAGHELPER_H
|